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

[glyf] Attempt to drop empty components from composite glyphs. #289

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

jfkthame
Copy link
Collaborator

@jfkthame jfkthame commented Oct 4, 2024

This is because such components cause DirectWrite to fail to render the composite at all, even though an empty component should (presumably) have no visible effect.

Reported in the context of pdf.js at mozilla/pdf.js#18848, but experimentation indicates that Windows/DWrite fails to paint such glyphs in other contexts as well -- e.g. when using Character Map to view an installed font.

(I don't think there's any real use case for such components, and their presence is probably an anomaly/artifact of a particular font creation/subsetting/embedding workflow. Still, if OTS can fix them up, this will best serve end users.)

The current patch discards empty components from composite glyphs unless the empty glyph is the last component. In that case, we can't just skip it, because the preceding component (which will now be last) has the MORE_COMPONENTS flag, and that's no longer true. I have not seen cases in the wild where this issue affects the final component, but it's presumably possible (and testing indicates that DirectWrite would fail in that case too), so this would be a good followup enhancement. Currently the code just issues a warning if such a case occurs.

This is because such components cause DirectWrite to fail to render the composite
at all, even though an empty component should (presumably) have no visible effect.

Reported in the context of pdf.js at mozilla/pdf.js#18848,
but experimentation indicates that Windows/DWrite fails to paint such glyphs in other
contexts as well -- e.g. when using Character Map to view an installed font.

(I don't think there's any real use case for such components, and their presence is
probably an anomaly/artifact of a particular font creation/subsetting/embedding
workflow. Still, if OTS can fix them up, this will best serve end users.)

The current patch discards empty components from composite glyphs *unless* the
empty glyph is the last component. In that case, we can't just skip it, because
the preceding component (which will now be last) has the MORE_COMPONENTS flag,
and that's no longer true. I have not seen cases in the wild where this issue
affects the final component, but it's presumably possible (and testing indicates
that DirectWrite would fail in that case too), so this would be a good followup
enhancement. Currently the code just issues a warning if such a case occurs.
This attempts to handle composite-glyph fixup more thoroughly, including the
ability to drop the last component of a composite.

Includes a couple of test fonts (derived from the pdf.js issue) that hit the
new codepath.
@jfkthame
Copy link
Collaborator Author

jfkthame commented Oct 7, 2024

With the second commit here, the limitation mentioned in #289 (comment) (unable to drop the last component of the composite) is no longer true; we handle this case, fixing up component flags as needed.

@tvsinh
Copy link

tvsinh commented Oct 8, 2024

This could be a useful patch for many end users.

@jfkthame jfkthame requested a review from khaledhosny October 9, 2024 10:18
@khaledhosny khaledhosny merged commit 5daecc9 into khaledhosny:main Oct 9, 2024
5 checks passed
@khaledhosny
Copy link
Owner

Thanks!

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