SVG icon indicating copy to clipboard operation
SVG copied to clipboard

Adding "paint-order" attribute support paint order

Open burak1000 opened this issue 4 years ago • 2 comments

Hello I using this library but it's dont have paint order functionalty. it's necessary for the nicely stroked Text ( most of handwriting font etc.)

I made two little change on code solve this problem. and it's working nice.

https://github.com/vvvv/SVG/blob/691dfd6e9327e7276a7c057e330d0f418c06e282/Source/Basic%20Shapes/SvgVisualElement.cs#L213-L225

Replace this method with:

    protected internal virtual void RenderFillAndStroke(ISvgRenderer renderer)
    {
        // If this element needs smoothing enabled turn anti-aliasing on
        if (RequiresSmoothRendering)
            renderer.SmoothingMode = SmoothingMode.AntiAlias;

        if (this.PaintOrder=="fill")
        {
            RenderFill(renderer);
            RenderStroke(renderer);
        }
        else
        {
            RenderStroke(renderer);
            RenderFill(renderer);
        }

        // Reset the smoothing mode
        if (RequiresSmoothRendering && renderer.SmoothingMode == SmoothingMode.AntiAlias)
            renderer.SmoothingMode = SmoothingMode.Default;
    }

And add this attribute defination to Source/SvgElementStyle.cs

    /// <summary>
    /// Specifies paint order of the stroke and fill when rendering the object.
    /// this attribute can be "fill" or "stroke"
    /// </summary>
    [SvgAttribute("paint-order")]
    public virtual string PaintOrder
    {
        get { return GetAttribute("paint-order", false, "fill"); }
        set { Attributes["paint-order"] = value; IsPathDirty = true; }
    }

After this changes use can use it with:

        SvgDocument mdoc = SvgDocument.Open("C:\\myfile.svg");
        SvgText mtext = new SvgText("Burak");
        mtext.Fill = new SvgColourServer(Color.Yellow);
        mtext.Stroke = new SvgColourServer(Color.Black);
        mtext.StrokeWidth = 2;
        mtext.PaintOrder = "stroke"; // "stroke" or "fill"

        mdoc.Children.Add(mtext);
        Bitmap result = mdoc.Draw();

First Stroke: first stroke

First Fill: first fill

burak1000 avatar May 28 '20 17:05 burak1000

paint-order specification is here.

H1Gdev avatar Jun 01 '20 12:06 H1Gdev

Any progress on getting this merged in to an upcoming release?

jlchmura avatar Feb 08 '22 12:02 jlchmura