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

DomException when loading SVG file - doubts about the correctness of parsing the font-face rule #296

Open
Sarnapa opened this issue Nov 2, 2024 · 1 comment
Assignees

Comments

@Sarnapa
Copy link

Sarnapa commented Nov 2, 2024

Hi,

I have the following problem related to this simple code, which has the task of loading a given SVG file as an object of type DrawingGroup. I care that the texts contained in the given SVG file are not geometries.

Mentioned fragment of code:

var settings = new WpfDrawingSettings
{
IncludeRuntime = true,
TextAsGeometry = false
};

var converter = new FileSvgReader(settings);
return converter.Read(svgFilePath);

During its execution for the example SVG file, I got such an exception:

[DomException]
    Code: SyntaxErr
    Message: Style declaration ending bracket missing
    HelpLink: [null]
    Source: SharpVectors.Css

----------------------------------------------------------------------------------------------------------------------------------
Stack trace:
   at SharpVectors.Dom.Css.CssStyleDeclaration.ParseString(String cssText)
   at SharpVectors.Dom.Css.CssFontFaceRule.Parse(String& css, Object parent, Boolean readOnly, IList`1 replacedStrings, CssStyleSheetType origin)
   at SharpVectors.Dom.Css.CssRuleList.TryParse(String& css, Object parent, Boolean readOnly, IList`1 replacedStrings, CssStyleSheetType origin)
   at SharpVectors.Dom.Css.CssRuleList.Parse(String& css, Object parent, Boolean readOnly, IList`1 replacedStrings, CssStyleSheetType origin)
   at SharpVectors.Dom.Css.CssStyleSheet.get_CssRules()
   at SharpVectors.Dom.Svg.SvgDocument.GetFontUrl(CssStyleSheet cssSheet, IList`1 fontUrls, IDictionary`2 styledFontIds)
   at SharpVectors.Dom.Svg.SvgDocument.GetFontUrls()
   at SharpVectors.Dom.Svg.SvgDocument.OnLoaded()
   at SharpVectors.Dom.Css.CssXmlDocument.Load(XmlReader reader)
   at SharpVectors.Dom.Svg.SvgDocument.Load(String filename)
   at SharpVectors.Renderers.Utils.WpfSvgWindow.LoadDocument(Uri documentUri, WpfDrawingSettings drawingSettings)
   at SharpVectors.Converters.FileSvgReader.LoadFile(String fileName)

It looks to me that we have a problem here with loading custom fonts defined with the css rule font-face. I found only one such case in my file. I have included the definition of this font below:

<style type="text/css">
<![CDATA[@font-face{font-family:"MicrosoftSansSerif";src:url("data:application/font-woff;charset=utf-8;base64,<stream of bytes, which I had to shorten because the post was too long>")}]]>
</style>

It seems to me that the given font-face rule is well defined (according to what I write here). For that, I have doubts about the parsing in the method CssStyleDeclaration.ParseString(String cssText). Can you please analyze the correctness of this method?

Sample SVG file attached.
example

@paulushub paulushub self-assigned this Nov 2, 2024
@paulushub
Copy link
Contributor

@Sarnapa Sorry, you have hit a missing code. The embedded URL matching regular expression failed, and the else block was left empty for lack of use case.
You can see

I will now try to improve that code with your sample - sorry for the inconvenience.

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

2 participants