-
Notifications
You must be signed in to change notification settings - Fork 25
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
Custom types for the meta table #1244
base: main
Are you sure you want to change the base?
Conversation
122c333
to
c6096cf
Compare
This commit adds the code necessary to read and write the `meta` table, including its codegen definition, manual extras to handle the variable length data fields, and plumbing to surface it within `read-fonts` and `write-fonts`. Where possible, this commit borrows liberally from the implementation of other tables, especially `name` (for its handling of variable length data). This is an early implementation, and as such requires manual and automated testing. Additionally, there is an implementation of the FontWrite trait for &[u8] that may be redundant.
This adds types and the required impls that can represent the expected contents of the 'meta' table. This has to be handwritten, because the 'meta' table contains different payloads depending on the included tag for each record. I think having these as real types will provide a significantly better API though, and avoid us writing invalid data. The actual implementations for these types are very spartan; eventually I imagine having parsing & constructing code for the ScriptLangTag struct that ensures it conforms to the spec.
write-fonts/src/tables/meta.rs
Outdated
} | ||
}; | ||
|
||
let len: u32 = len.try_into().unwrap(); |
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 don't love the unwrap, is this common in write-fonts? Should file an issue to make write_into fallible and remove that?
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.
By design FontWrite
is infallible; we do all the error checking in an earlier validation pass.
In generated code, we do add a check that an array's length can be represented by the type that stores the length, but I didn't bother hand-writing that here, given that any single font table's length must be representable in 32 bits or else its offset cannot be stored in the root table directory.
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.
Maybe we should comment as much and do an infallible production of len?
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 tests to prove it works
This is based on #1237; I think it makes sense to use custom types for the actual data in this table, but I wouldn't have been able to explain what to do without trying it first, so here we are.
(also this needs tests)