dotnetprojects / SVGImage

A SVGImage Control for WPF
http://dotnetprojects.github.io/SVGImage/
MIT License
199 stars 41 forks source link

Keep transparent colors intact when overriding colors or offer an OverrideColor for Fill and Stroke separately #84

Closed lukas-kirschner closed 11 months ago

lukas-kirschner commented 11 months ago

Is your feature request related to a problem? Please describe. In my project, I am changing SVGImage stroke colors using the OverrideColor dependency property. However, when my SVGs consist of strokes without any fill color, both the fill color and the stroke is overridden by the OverrideColor. A temporary workaround is to change the stroke to a fill using the "Stroke to Path" feature of Inkscape. This solution is not optimal, because it discards information about the original stroke.

Describe the solution you'd like This might be fixed by either keeping transparent colors intact when overriding colors, or by offering a separate "OverrideFillColor" property that can be used to override the fill color.

lukas-kirschner commented 11 months ago

I tried to find the source of this bug and added a fill and stroke color override property to set both separately (see PR #85 ). I attached a minimal example SVG that renders incorrectly when setting either OverrideColor or OverrideFillColor - When overriding the fill color, the path at the bottom gets filled even though no fill color has been set for it.

Example

paulushub commented 11 months ago

I tried to find the source of this bug and added a fill and stroke color override property to set both separately

I do not know what the expected result is. This is a polyline path, and I do not expect it to be filled. However, setting the OverrideColor property forces a fill. 🙄 Some contributed PR are not well tested, that is why I added the develop branch and PR check list. Features like the OverrideColor are not part of the specifications and should be well-documented and tested.

The PathShape has a ClosedPath property, but I do not see how this is set or used - you can look into this. @jogibear9988 is no longer actively working on this project, and I am only contributing to keep it alive for those using it - I do not use it or C# in my current work.

lukas-kirschner commented 11 months ago

Thanks for your reply - Ok, I am going to write some unit tests and documentation for the properties and switch off the PR draft mode when I am done. I'll add some documentation for the new properties to the Docs folder. I tried to debug the issue, but had no luck so far. I suspect there are some shape properties in the renderer class that are discarded when the color is overridden... but I could not pinpoint the issue yet.

paulushub commented 11 months ago

I think this should fix the issue. If the result below is what you are expecting.

image

Attached are the fixed SVGRender.cs file and the updated SvgTestBox shown above, which I used to test the overridable properties (color and stroke width). If these work as you expect, then consider merging these sources with yours and updating your PR.

Updates.zip

lukas-kirschner commented 11 months ago

Great, thanks! I merged your changes and everything works perfectly 👍 I pushed everything to the PR and added an option for overriding stroke and fill color to the TestBox UI: 2023-12-18 13_55_23-Window