Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics.SmoothingMode resets to Default when RequiresSmoothRendering is true #882

Closed
ds1709 opened this issue Jul 31, 2021 · 0 comments · Fixed by #883
Closed

Graphics.SmoothingMode resets to Default when RequiresSmoothRendering is true #882

ds1709 opened this issue Jul 31, 2021 · 0 comments · Fixed by #883

Comments

@ds1709
Copy link
Contributor

ds1709 commented Jul 31, 2021

Description

Graphics.SmoothingMode resets to Default when RequiresSmoothRendering is true.

Example data

var g = Graphics.FromHwnd(IntPtr.Zero);
var renderer = SvgRenderer.FromGraphics(g);
var visualElement = new SvgLine { ShapeRendering = SvgShapeRendering.Auto };

g.SmoothingMode = SmoothingMode.AntiAlias; // Initializing SmoothingMode for Graphics.

visualElement.RenderElement(renderer); // Calling rendering.

Assert.That(g.SmoothingMode, Is.EqualTo(SmoothingMode.AntiAlias)); // Fail, coz actual is Default.

Used Versions

3.2.3

Solution

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

        RenderFill(renderer);
        RenderStroke(renderer);
    }
    finally
    {
        // Reset the smoothing mode
        if (RequiresSmoothRendering && renderer.SmoothingMode == SmoothingMode.AntiAlias)
            renderer.SmoothingMode = smoothingMode;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant