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

Fix handling of SVG table #776

Merged
merged 2 commits into from
Jun 10, 2024
Merged

Fix handling of SVG table #776

merged 2 commits into from
Jun 10, 2024

Conversation

LaurenzV
Copy link
Contributor

@LaurenzV LaurenzV commented Jun 8, 2024

Alright, so while debugging something with Noto Color Emoji in typst, I realized that the new Noto Color Emoji fonts ship with an SVG table in addition to COLR. And I did not realize that an SVG record can actually contain multiple glyphs (see here: https://learn.microsoft.com/en-us/typography/opentype/spec/svg#glyph-identifiers). I have no idea who thought it was a good idea to stuff hundreds of glyphs in a single SVG file, but yeah, this is the fix I came up with. 😅

This might not be the 100% correct approach (could glyphs for example appear in nested groups? How would we deal with transforms? etc. etc...) But I tested it manually and it works with Noto Color Emoji (and the test for Twitter Color Emoji also still pass), so I hope this is okay... I'm open for suggestions, though.

@khaledhosny
Copy link

khaledhosny commented Jun 9, 2024

I have no idea who thought it was a good idea to stuff hundreds of glyphs in a single SVG file, but yeah, this is the fix I came up with. 😅

It allows for big file size saving by reusing paths across glyphs, since SVG table neither has glyf composite glyphs nor CFF subroutines.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented Jun 9, 2024

Fair enough, that makes sense. 😄 But unfortunately that means that we have to parse the whole SVG file just to render a single glyph, but I guess there is no way around that.

@RazrFalcon
Copy link
Collaborator

Got it.

No idea what the spec means by rendering a glyph as a use. Do they mean that in case of

<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
  <defs>...</defs>
  <g fill="green">
    <g id="glyph14">...</g>
  </g>
</svg>

we should ignore the green fill? In which case our implementation is wrong and I don't think there is an easy way to implement this behavior in resvg.

@RazrFalcon RazrFalcon merged commit ba1be45 into linebender:master Jun 10, 2024
3 checks passed
@LaurenzV
Copy link
Contributor Author

Yeah I have no idea... But it's only a best-effort implementation after all.

@LaurenzV LaurenzV deleted the svg_fix branch June 11, 2024 08:23
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 this pull request may close these issues.

3 participants