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

WIP: Implement de- and serialization for all fontinfo attributes #16

Merged
merged 40 commits into from
Dec 3, 2019
Merged

WIP: Implement de- and serialization for all fontinfo attributes #16

merged 40 commits into from
Dec 3, 2019

Conversation

madig
Copy link
Collaborator

@madig madig commented Nov 6, 2019

According to serde-rs/serde#1301 and serde-rs/serde#1444, easily de/serializing things with custom functions inside containers like Option is not possible, so you have to handle everything around it. Since fontinfo is quite expansive with more custom stuff (and de/serialization) to come, maybe it should move to its own module mid-term.

@madig madig changed the title Implement deserializing styleMapStyleName into enum Implement deserialization for all fontinfo attributes Nov 7, 2019
@madig madig changed the title Implement deserialization for all fontinfo attributes WIP: Implement deserialization for all fontinfo attributes Nov 7, 2019
@madig
Copy link
Collaborator Author

madig commented Nov 7, 2019

Todo:

  • Move to font_info.rs file.
  • Implement validation for all fields
  • Implement serialization?

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

This looks good. I think it's probably worth moving to a separate file as part of this PR? But I think that validation and serialization make sense to to separately.

src/ufo.rs Outdated Show resolved Hide resolved
@madig
Copy link
Collaborator Author

madig commented Nov 7, 2019

I think I have to properly organize de/serializer code now. Also, need to parse guidelines into existing glyph::Guideline.

@cmyr
Copy link
Member

cmyr commented Nov 8, 2019

Okay, just ping me when you think this is ready!

@madig
Copy link
Collaborator Author

madig commented Nov 24, 2019

So, now all possible fields actually get deserialized in the test. What's needed next is custom types (e.g. OS2Panose, OS2FamilyClass, the WOFF dir attributes that should be an enum, etc.) plus custom de/serializers to perform validation. The glyph::Guideline type should be reused for fontinfo and might need more extensive custom de/serialization. Not sure what to do about standard types that need validation, like the WOFF list attributes where the spec demands they contain at least one item.

@madig
Copy link
Collaborator Author

madig commented Nov 24, 2019

Do Identifiers need their own ::new and stuff? The UFO spec has an example algorithm.

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2019

Not sure I need all the Visitors? Maybe doing the work in just deserialize would be enough.

@cmyr
Copy link
Member

cmyr commented Nov 25, 2019

Identifiers are annoying, I'm not sure how best to handle them. Probably yes, we should have a newtype and store them a s a string, but we should validate them on creation.

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2019

Same for e.g. openTypeOS2VendorID:

Four character identifier for the creator of the font. Corresponds to the OpenType OS/2 table achVendID field.

OS/2 spec, tag spec:

Array of four uint8s (length = 32 bits) used to identify a table, design-variation axis, script, language system, feature, or baseline
[...]
A Tag value is a uint8 array. Each byte within the array must have a value in the range 0x20 to 0x7E. This corresponds to the range of values of Unicode Basic Latin characters in UTF-8 encoding, which is the same as the printable ASCII characters. As a result, a Tag value can be re-interpreted as a four-character sequence, which is conventionally how they are referred to. Formally, however, the value is a byte array. When re-interpreted as characters, the Tag value is case sensitive. It must have one to four non-space characters, padded with trailing spaces (byte value 0x20). A space character cannot be followed by a non-space character.

So maybe both Tag and Identifier should be newtypes with a ::new and/or ::from_string or something.

This reminds me that my Identifier verification is wrong.

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2019

Hrm. There's some small stuff that needs validation, like various postscript* list attributes have a length limit. I think it is much less work to implement a is_valid function on FontInfo that is run before serialization and after deserialization?

@cmyr
Copy link
Member

cmyr commented Nov 25, 2019

Yea, I think a validation function is totally reasonable.

@madig
Copy link
Collaborator Author

madig commented Nov 25, 2019

Went through the spec again at http://unifiedfontobject.org/versions/ufo3/fontinfo.plist/ and found some type discrepancies. Also changed some Todo comments, the spec does not mandate checks for some attributes. The spec is also somewhat lenient with types, declaring lots of stuff Integer when the OT spec specifies int16, etc. I am thinking about introducing some type aliases like Integer = i32, NonNegativeInteger = u32, just to be very spec-spirit compliant? http://unifiedfontobject.org/versions/ufo3/conventions/ does not define limits.

@cmyr
Copy link
Member

cmyr commented Nov 25, 2019

I'm happy either way with the aliases.

@madig
Copy link
Collaborator Author

madig commented Nov 26, 2019

I was just informed that the UFO spec is going to grow a minor version soon, 3.1, so that the glyph element can grow a verticalOrigin attribute in advance element.

@anthrotype
Copy link
Collaborator

@anthrotype
Copy link
Collaborator

the UFO spec is going to grow a minor version soon, 3.1

also the GLIF <glyph> element will have a corresponding additional formatMinor attribute.

@madig
Copy link
Collaborator Author

madig commented Nov 28, 2019

note to self:

@madig madig changed the title WIP: Implement deserialization for all fontinfo attributes WIP: Implement de- and serialization for all fontinfo attributes Dec 1, 2019
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Okay some general thoughts but overall this looks good, thanks so much for taking it on!

I think it's worth merging this soon as a checkpoint, and then we can build out better error handling etc from there.

src/shared_types.rs Outdated Show resolved Hide resolved
src/shared_types.rs Outdated Show resolved Hide resolved
src/shared_types.rs Outdated Show resolved Hide resolved
src/fontinfo.rs Outdated Show resolved Hide resolved
src/fontinfo.rs Show resolved Hide resolved
src/fontinfo.rs Show resolved Hide resolved
return Err(Error::FontInfoError);
}

if !(v[0..4].parse::<u16>().is_ok()
Copy link
Member

Choose a reason for hiding this comment

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

for all these parse errors we could do something like, x.parse::<u8>().map_err(|_| Error::FontInfoError)?

@cmyr
Copy link
Member

cmyr commented Dec 3, 2019

oh, one other suggestion here: run cargo clippy on this patch, and see what suggestions it comes up with.

@madig
Copy link
Collaborator Author

madig commented Dec 3, 2019

That was a lot of lints. Fixed them all.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Okay, I haven't gone over all the latest changes closely, but I trust between you and clippy they make sense. I think this is a good time to get this merged, and then we can build from here.

I've added you as a collaborator to this repo; feel free to press the big green merge button when you think it's ready!

@madig
Copy link
Collaborator Author

madig commented Dec 3, 2019

Edit: duh, needed to accept the invite.

@madig madig merged commit 51e3332 into linebender:master Dec 3, 2019
@madig madig deleted the styleMapStyleName-into-enum branch December 3, 2019 23:47
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