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

Avalonia Svg Skia . Css does not apply when using Source rather than Path. #240

Open
MassKlaus opened this issue Sep 10, 2024 · 1 comment

Comments

@MassKlaus
Copy link

MassKlaus commented Sep 10, 2024

I am passing a string to an Svg Control but the specific CSS property doesn't seem be applied. The same Svg but passed through path is applied without issues.

Is this a feature not supported by the library?

  <Svg Width="75" Css=".st0{ fill:blue; }" Source="{Binding SvgData }" />

The svg in question in case the issue is with it. This is a test for now, The final result is meant to be a much larger taking multiple musical notes.

        <svg version="1.1" id="_x32_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
        	 width="800px" height="800px" viewBox="0 0 512 512"  xml:space="preserve">
        <style type="text/css">
        <![CDATA[
        	.st0{fill:red;}
        ]]>
        </style>
        <g>
        	<path class="st0" d="M340.078-0.004v311.078c-23.641-9.969-52.828-14.047-84.422-10.125
        		c-78.516,9.75-141.969,64.594-141.766,122.407c0.203,57.875,64,96.906,142.469,87.156c78.5-9.766,141.953-64.594,141.75-122.469
        		V-0.004H340.078z"/>
        </g>
        </svg>

I am using Avalonia.Svg.Skia 11.1.0.1

If I missed any information let me know!

@MassKlaus
Copy link
Author

I've went a bit deeper into it and noticed that the FromSvg(string svg) lacks a svgOptions which affects how this is loaded.

        /// <summary>
        /// Attempts to create an SVG document from the specified string data.
        /// </summary>
        /// <param name="svg">The SVG data.</param>
        public static T FromSvg<T>(string svg) where T : SvgDocument, new()
        {
            if (string.IsNullOrEmpty(svg))
            {
                throw new ArgumentNullException("svg");
            }

            using (var strReader = new StringReader(svg))
            {
                var reader = new SvgTextReader(strReader, null)
                {
                    XmlResolver = new SvgDtdResolver(),
                    WhitespaceHandling = WhitespaceHandling.Significant,
                    DtdProcessing = DisableDtdProcessing ? DtdProcessing.Ignore : DtdProcessing.Parse,
                };
                return Create<T>(reader);
            }
        }

Adding the Svg Options and going up the tree along with it could allow for a fix for this. I could make a PR if this is a wanted feature

@MassKlaus MassKlaus changed the title Avalonia Skia Controls. Css does not apply when using Source rather than Path. Avalonia Svg Skia . Css does not apply when using Source rather than Path. Sep 10, 2024
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

No branches or pull requests

1 participant