-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make all Font fields non-optional #187
Conversation
Random thought: should I rename |
To make API more ergonomic.
7858e4e
to
bfe3f27
Compare
The original intention for norad was to match the spec as closely as possible, including in the naming of fields. Maybe let's just stick with that? It's a nice guideline or these sorts of questions. |
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.
I totally agree that this is an annoying part of the API, and in some instances (like groups/kerning) I think that treating empty collections as None
is reasonable, since empty collections here is meaningless.
I'm less sure about font_info; there is a distinction between no fontinfo and fontinfo that just happens to have default values (that have been chosen by norad, and have nothing to do with the spec).
So my gut feeling here is that for fontinfo we just have to accept that the API isn't great, and find other ways to work around this?
@@ -610,6 +610,11 @@ impl FontInfo { | |||
} | |||
} | |||
|
|||
/// Returns `false` if this FontInfo has any non-default value, and `true` otherwise. | |||
pub fn is_empty(&self) -> bool { |
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.
What if the fontinfo intentionally has values that just happen to all be default?
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.
Then the fontinfo.plist is not written out AFAIK :)
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.
that have been chosen by norad, and have nothing to do with the spec
Hm which ones? The values should assume the default values (None or something else) as laid out in https://unifiedfontobject.org/versions/ufo3/fontinfo.plist/.
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.
oops, thought i'd responded to this!
I was confused; in runebender I assign some default ppem/ascender/descender/xHeight/capHeight values if they're missing, and I was thinking of those defaults. If every field on font_info.plist is optional, that's not a concern.
@belluzj says:
Hm. I'll run some tests to see what ufoLib(2) and ufonormalizer do with empty kerning and groups files. I remember these problems and think that they are a bug in varLib... |
A quick test shows:
So I think this PR mirrors what defcon and ufoLib2 are doing. |
How about optionally supporting #4? |
Hm? What do you mean? |
If we currently support (1) in #187 (comment), would it be appropriate to add support for optionally removing all spec optional empty plist files at serialization in line with the ufonormalizer approach? I suppose it is also worth considering if/how a change in file structure should happen across the full I/O roundtrip. If you read in a kerning.plist without kerning data, do you write out a UFO dir without kerning.plist included? We might want to make this an optional file structure change if that is the plan. |
That's what should happen with this PR, IIUC? Norad always wipes the existing UFO in Lines 256 to 258 in bfe3f27
Yes; defcon, ufoLib2 and norad do just that by default. It makes sense to me, because it's a nicer API to start with an empty dict instead of a None, and then there is no meaningful diff between an empty plist and a non-existent one :) |
https://unifiedfontobject.org/versions/ufo3/kerning.plist/
I think this implies that no kerning.plist means an empty kerning dict. I can't find similar wording for groups but assume the same applies by analogy. |
If you're worried that several tools do several things and we should provide options, I found that all standard tools (defcon, ufoLib2, ufonormalizer) drop empty fontinfo, kerning and groups plist files. If a fontinfo is full of Nones, neither defcon nor ufoLib2 write it out. So, that's consistent with what this PR is doing. |
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.
I think this is a good simplification, sorry for the delay!
To make API more ergonomic.
Closes #159