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

[write-fonts] Add Glyph::Empty #759

Merged
merged 1 commit into from
Jan 24, 2024
Merged

[write-fonts] Add Glyph::Empty #759

merged 1 commit into from
Jan 24, 2024

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Jan 18, 2024

This is a cleaner way of representing the idea of a glyph with no outlines, but which should still be added to loca.

I played around with also adding this in read-fonts, but it doesn't really play well with codegen or parsing, there, because we expect a format enum to have a table for each variant, and in the empty case we have no data from which to parse a table.

JMM

Copy link
Collaborator

@rsheeter rsheeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please release and update fontc if necessary. This is probably considered a breaking change for the purpose of versioning, correct?

match self {
Glyph::Simple(glyph) => glyph.contours().is_empty(),
Glyph::Composite(glyph) => glyph.components().is_empty(),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still seems valid even in the presence of Empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only used to decide whether or not to write data into glyf. The Empty variant just writes no data, and so 'just works' (and when converting to the enum from an instance of SimpleGlyph, we turn an empty glyph into the Empty variant.

@@ -57,18 +59,11 @@ impl Glyph {
/// The bounding box for the glyph
pub fn bbox(&self) -> Bbox {
match self {
Glyph::Empty => todo!(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... this is a big footgun. Un-lgtm!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahaha oops. This is actually something to discuss, and maybe @dfrg has input? Basically the bounding box of an empty glyph is not (0,0), (0,0), because that implies that the point (0,0) is contained. I think for correctness this should probably return an Option? This has been a source of bugs in other geometry code I've written in the past.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning an option here makes sense. We can always unwrap_or_default if we want the all zero bbox for some reason.

Copy link
Collaborator

@rsheeter rsheeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the todo! in bbox

This is a cleaner way of representing the idea of a glyph with no
outlines, but which should still be added to loca.

I played around with also adding this in read-fonts, but it doesn't
really play well with codegen or parsing, there, because we expect a
format enum to have a table for each variant, and in the empty case we
have no data from which to parse a table.
Copy link
Member

@dfrg dfrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@cmyr cmyr merged commit eb2115a into main Jan 24, 2024
9 checks passed
@cmyr cmyr deleted the empty-glyph branch January 24, 2024 17:52
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.

Consider adding Glyph::Empty variant?
3 participants