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

Name type and related API changes #240

Merged
merged 2 commits into from
Jan 10, 2022
Merged

Name type and related API changes #240

merged 2 commits into from
Jan 10, 2022

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Jan 7, 2022

This adds a Name type, shared between glyphs and layers. This enforces the constraints on names documented in the spec and also hides the concrete type we use to represent names, leaving us free to change that in future.

This also attempts to standardize the various places where names are used in the API. With this patch, most API that takes a name (for retrieving a glyph or a layer, for instance) now just takes a &str. In places where we are creating a glyph, this is converted into a Name, and panics if the name is malformed. This is unlikely for the reasons outlined at #191 (comment). Methods that may panic in this way are all documented.

There are a few exceptions:

  • some methods that already return a NamingError will return NamingError::Invalid if the name is invalid, since it's easy enough and doesn't increase the user burden.
  • Component::new takes a Name directly, because we expect you to take the name from an existing glyph.

There are a few other little tweaks included in this patch, which were related to these changes and would have been annoying to extract.

Glyph and layer names cannot be arbitary strings. This adds a name
module and a Name type that handles validation.

This validation is always performed when loading a font. At runtime, we
expect the user to ensure that they are using a valid name, since
invalid names are generally hard to construct.
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

🗜 Bloat check ⚖️

Comparing 01b3613 against d1fd5b1

target old size new size difference
target/release/examples/load_save 1.88 MB 1.9 MB 19.63 KB (1.02%)
target/debug/examples/load_save 8.55 MB 8.57 MB 30.13 KB (0.34%)

src/layer.rs Show resolved Hide resolved
src/layer.rs Show resolved Hide resolved
src/font.rs Show resolved Hide resolved
@cmyr cmyr merged commit 6ba2ebc into master Jan 10, 2022
@cmyr cmyr deleted the name-type branch January 10, 2022 18:57
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.

2 participants