-
Notifications
You must be signed in to change notification settings - Fork 13
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
Postscript names for UFO sources #489
Conversation
Store postscript names in StaticMetadata of IR Postscript names taken from default master Empty default for Glyphs.app sources (for now)
Thanks!
duplicate as in the same key repeated more than once? does plist even allow that? Probably not as dict keys are unique. We should do whatever a normal plist parser does when encountering these, nothing more.
we should defer to that for a follow-up PR, it's ok to first implement writing the explicit postscriptNames; ufo2ft.postProcessor can make up AGLFN-compatible names from glyphs codepoints, we could implement that later.
that's useful sometimes for debugging, to have human-readable names instead of uniXXXX, so I would say yes we want that. preferably matching the fontmake's CLI flag name so it's already familiar to fontamake's users.
can be done in a follow-up PR. We can file an issue so we don't lose track of this temporary asymmetry between frontends
taking the one from the designspace.lib or, if that missing, the one from the default master UFO lib.plist should suffice. It's not our job to validate these IMO.
yeah, maybe, makes sense I have a meeting now, will come back to this later |
fontc/ufo2fontir/src/source.rs Line 478 in 6381929
it's fine in StaticMetadata, I think |
it looks like ufo2ft only looks for postscriptNames defined in the default master UFO lib.plist, that's the one it uses in its postProcessor when compiling a VF. I confused this with the other "skipExportGlyphs" key which ufo2ft attempts to find in the designspace.lib first. Maybe it should do that as well for postscriptNames.. Anyway matching current fontmake.py is fine for now. |
Golf code around about for readability (no nested Options)
Create type alias PostscriptNames
Duplicate as in the same value repeated more than once. There's currently no handling for this
Yeah this was how we were going to initially set out to implement it before we also realised it's not looked for in the DS in the Python stack. Maybe something to revise down the line, but probably out of scope for this PR I've pushed a couple of the basic suggested changes, and shall now look into adding the CLI flag and removing the double load-from-disk |
I don't think the python toolchain checks for this, does it? In any case, feel free to add or not add the additional check. To me it feels more like the job of a linter |
Hello all, and many thanks for the speedy review Cosimo :)
IIRC in ufo2ft we do some sanitisation of names and add a suffix to ensure uniqueness, although I cannot see a uniqueness requirement in the |
Thanks Harry. Indeed, looks like that dedup logic was deliberately added in ufo2ft to address some fonttools quirk: while the post spec may not require the names to be unique, it kind of defeats the purpose of having multiple glyphs mapped to the same postscript name if you use the name to identify a specific glyph or reverse-cmap, which is what AGLFN is primarily about. If cmap maps from unicode codepoint to glyph (ids), it's impossible for a given codepoint to map to more than one glyph at a time. I think it's rare that sources have duplicate postscript glyph names, and if they do it's usually by mistake, I don't see a use case for it besides wanting to make a deliberately broken font for testing purposes. But sure let's add the dedup logic |
also feel free to kick the can down the road and not do it in this PR (can file an issue) |
anyway, when decompiling post, fonttools seems to be able to deduplicate glyph names as needed: since we are not using fonttools to compile the binary font, we don't have this problem, so it's only about whether or not we think a valid post should contain unique names. Given the post spec does not enforce this requirement, I believe we should not either. |
while that's true, if you also think about alternate glyphs substituted for via GSUB, then indirectly it is possible to say that both glyph "A" and glyph "A.ss01" are mapped to 0x0041, and in fact AGL spec says one should drop the suffix after the period when mapping from glyph name to character string: https://github.com/adobe-type-tools/agl-specification#2-the-mapping yeah I think I have convinced myself that we do not need to do any checks for duplicates here |
now I do see it. If you don't care about the nice debug glyph names and being able to distinguish glyph "A" from "A.ss01" (e.g. when decompiling the font in a font editor) but only care about AGL compliance and reverse-cmapping of names to characters for old PDF distillers, then it may be beneficial to actually reuse postscript names for alternate glyphs that ultimately are mapped to the same unicode codepoint(s) such that the post table is as compact as needed. |
I've added a duplicate value check. I agree with Harry that this is often a mistake, so I'm erring on the side of being (hopefully) more helpful. Given that it's not strictly spec to have to have unique values, it's just a warning I've also added the Shall look at deduplicating the plist loads tomorrow, then onto tests! |
Loses some resolution in a very rare error (public.postscriptNames not being a dictionary)
Fix glyph_order signature in other test
Double negatives are the curse of programmers everywhere Add debug printing of bitflags in arg_default_matches_flags_default for ease of debugging Add Default::default() to params of StaticMetadata::new where needed
Okay, I think the PR is in a good state now. I've addressed the suggestions, and implemented tests. Let me know if there's anything further you'd like to see :) Once merged, I'll open any appropriate issues to track the deficiencies in the current implementation: not supporting glyphs sources, not matching fontmake's name generation, etc. |
fontc/src/args.rs
Outdated
let arg_default = Args::parse_from(vec!["program", "--source", "dont.care"]).flags(); | ||
let flags_default = Flags::default(); | ||
debug!("flags_default: {:#032b}", flags_default.bits()); | ||
debug!("args_default: {:#032b}", arg_default.bits()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of firing up the logger and writing to debug make the assert do what you want, either by altering the left/right values or by adding a custom panic string to show the {:#032b}
strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. Only downside is it means I can't align the values when they're printed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM subject to nits being fixed
Note corresponding fontmake flag for --no-postscript-names Move debug logs into assertion Change duplicate_values_check name Make filter expr one line Only check for postscript duplicate values when warn logs are enabled Don't duplicate code in tests (add Flags param to build_static_metadata)
All comments addressed, let me know if there's anything else! |
@@ -70,6 +72,7 @@ impl From<StaticMetadataSerdeRepr> for StaticMetadata { | |||
from.axes, | |||
from.named_instances, | |||
from.glyph_locations.into_iter().collect(), | |||
from.postscript_names, | |||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello again! A wee question, tangential to this PR: we noticed that misc
is serialised in StaticMetadata
→StaticMetadataSerdeRepr
but not deserialised in StaticMetadataSerdeRepr
→StaticMetadata
; do we populate it elsewhere, or could this be a bug? 🐛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a bug to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I sort this as part of this PR, or file this as a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically it's a separate issue, might be worth tackling it separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised as #499
After PR #489, fontc should use the same glyph postscript names as fontmake does, so we no longer need to pass the --no-production-names flag to compare the two sets of fonts
Related to: #248
Reads postscript names from the
lib.plist
of UFO sources, and then uses them when writing the post table.Compiling Oswald using its
Makefile
yields an identical post table to that of a fontc-compiled UFO-based Oswald.Tests not yet updated to account for the extra field on
StaticMetadata
, or extra parameter ofStaticMetadata::new
. Very much just a proof of concept to gather feedback and see if there are any changes wanted in our approach before updating tests. Naturally, tests should also be added for reading/writing these names.For discussion:
fontmake
do?fontmake
's--no-production-names
?glyphs2fontir
in this PR?Implementation notes/thoughts:
public.postscriptNames
across all masters?postscript_names
belong in the top-levelStaticMetadata
, or in misc (or context, likeGlyphOrder
)?GlyphName
orBox<str>
instead ofString
?Tangent (though tests will currently fail if run): https://matklad.github.io/2022/10/24/actions-permissions.html