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

ir notes #37

Merged
merged 4 commits into from
Nov 14, 2022
Merged

ir notes #37

merged 4 commits into from
Nov 14, 2022

Conversation

rsheeter
Copy link
Contributor

@rsheeter rsheeter commented Nov 12, 2022

text/2022-11-08-font-compiler-ir.md Show resolved Hide resolved

- Designspace file maps UFO(s) into design space
- UFO font has layers
- Layers have glyphs

Choose a reason for hiding this comment

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

(FWIW. UFO can be mapped to "Font has glyphs, glyphs have layers", which is what Fontra is doing.)

Copy link
Member

Choose a reason for hiding this comment

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

interesting, how does that work concretely? Does the UFO default layer's contents.plist file define the font's glyphs set and then the presence of given named glyph in the other non-default layers count as 'that glyph having that layer' (rather than the other way around)?
And how does this way of thinking of UFOs interact with designspace? I suppose you rely on mutliple DS source elements all pointing to the same UFO filename and having a layer attribute set to select where to source glyph definitions.

Choose a reason for hiding this comment

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

the presence of given named glyph in the other non-default layers count as 'that glyph having that layer'

Yes, that is the easy bit.

I'm not claiming it is trivial to do perfect round-tripping, and my implementation isn't even complete. It can still deal with multiple UFOs and multiple layers per UFO, and I maintain a mapping between "glyph layer identity" and "ufo source + layerName". It will become somewhat more complex once Fontra is able to create new glyph layers and sources that don't already exist in the DS system as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm realizing that I don't really understand what "layer" means in this context or what it maps to in the final binary?

Choose a reason for hiding this comment

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

Both in .glyphs and UFO/designspace, a glyph layer contains the master shape for a specific designspace location. Additionnally, such layers are used by designers as a scratch layer or a background layer, which will be ignored for the final binary.

Copy link

Choose a reason for hiding this comment

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

For a bare UFO, only the default layer matters to a compiler. For a Designspace, every default layer of every referenced UFO matters, plus the DS sources that reference a specific layer inside a UFO. All other layers have no meaning to the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you happen to have an example of a font using a DS source that references a specific layer lying around?

Choose a reason for hiding this comment

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

text/2022-11-08-font-compiler-ir.md Outdated Show resolved Hide resolved

enum Shape
Contour(Contour)
Component(Component)

Choose a reason for hiding this comment

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

In UFO you can indeed mix outlines with components. In retrospect I've found this needlessly complex. A model where you have a hard distinction between outlines and components as attributes of the glyph instance is much easier to work with. Something like:

struct GlyphInstance
  advance
  contours: Vec<Contour>
  components: Vec<Component>

Copy link
Member

Choose a reason for hiding this comment

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

i agree it's better/easier to work with to have two separate lists of contours and components instead of a single vector of either contour or components.
The respective ordering of contours/components shouldn't matter in the end because in the output binary format mixed glyphs are going to be decomposed and the order of contours does not change the rendering (winding direction does).
Having said that, there's one thing that may care about the ordering of contours/components, and that's truetype instructions that refer to glyph point indices, see unified-font-object/ufo-spec#169
Not sure if we care about representing those in the IR.

Choose a reason for hiding this comment

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

TT can't mix outlines and components, so I think that's a non-issue.

Copy link
Member

Choose a reason for hiding this comment

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

sure, in the binary TT file you can't mix, but in the source one may want to mix and at the same time also have truetype instructions that refer to point indices. Even so, a compiler's composite glyph decomposition procedure could take care of remapping those indices accordingly. Anyway, this was all just hypothetical, am not suggesting we should use that as an argument for a mixed Vector[Union[Contour,Component]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgive my density but I'm not quite grasping why it is better to have separate lists, particularly in Rust where the enum for this is very natural?

Copy link

@justvanrossum justvanrossum Nov 16, 2022

Choose a reason for hiding this comment

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

Observation 2: both defcon and ufoLib2 separate contours from components. These are the two most used libraries in Python-land to write UFO, and both can't round-trip arbitrarily mixed contours/component sequences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

important when interpolating

Apparently I momentarily forgot variations. Some say they are important.

both can't round-trip arbitrarily mixed contours/component sequences

This does feel like it's adding up to no significant benefit to mixing them together. I wonder why https://unifiedfontobject.org/versions/ufo3/glyphs/glif/#outline is the way it is then.

Choose a reason for hiding this comment

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

I wonder why https://unifiedfontobject.org/versions/ufo3/glyphs/glif/#outline is the way it is then

Legacy. Insights progressed since. UFO is from 2001, 2? Fontographer did it that way. There's probably more to be found along those lines...

(The .glyphs format also seems to be able to arbitrarily mix contours and component references, FWIW.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #40.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.glyphs format also seems to be able to arbitrarily mix contours and component references

If Glyphs gains COLRv1 support and leverages the order of mixed contours and components we might find ourselves merging them back together. However, that's speculative so I think it's OK if we don't worry about it for now.

@madig
Copy link

madig commented Nov 12, 2022

Bonus points if the IR could be reused by https://github.com/daltonmaag/Fontgardener, making fontgardens a serialization format.

@rsheeter
Copy link
Contributor Author

Merging because I think we have enough to be useful, will continue to update if additional comments, issues, or PRs flow in.

@rsheeter rsheeter merged commit 85f7500 into main Nov 14, 2022
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.

4 participants