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

LayerSet + other layer-related tweaks #106

Merged
merged 2 commits into from
Apr 18, 2021
Merged

LayerSet + other layer-related tweaks #106

merged 2 commits into from
Apr 18, 2021

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Apr 15, 2021

This adds a LayerSet type that enforces various constraints on
layers.

Among other things, this means that:

  • Layer names are now also stored as Arc
  • There is no more LayerInfo type
  • there is now always a default layer
  • the default layer cannot be removed
  • new layers can be added

This also introduces a few other breaking api changes; for instance
I'm removing Font::get_default_layer(&self) -> Option<&Layer>
in favour of Font::default_layer(&self) -> &Layer.

In addition it moves the "compute a file name from a user provided name"
logic into a new util module.

This was motivated by my experiments with python bindings,
but I think this is generally useful independent of that work
and so I'm PRing it separately.

@madig I caught a few issues here thanks to your tests! 🎉

This takes the previous default_file_name_for_glyph_name
function out of the glyph module and moves it to a new
`util` module; it then adapts it to also work for layer names.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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

madig commented Apr 15, 2021

The idea of putting the default layer permanently into [0] is interesting. I'd love to fuzz the API to see if there is a weird corner case that unhinges it! Maybe needs a debug_assert in default_layer(_mut) etc. to ensure it is never dethroned?

@madig
Copy link
Collaborator

madig commented Apr 15, 2021

Also, the extra effort in normalizer to fish out the layers to delete is... unfortunate.

src/layer.rs Outdated Show resolved Hide resolved
src/layer.rs Outdated Show resolved Hide resolved
@cmyr
Copy link
Member Author

cmyr commented Apr 16, 2021

Thanks for the feedback, I agree with everything.

I also agree it's somewhat a shame that the normalizer example is more verbose now, but I don't really know what an alternative API would be that lets us maintain our guarantees. 🤔

@github-actions
Copy link

🗜 Bloat check ⚖️

Comparing 56fde0a against 06c42a2

target old size new size difference
target/release/examples/open_ufo 1.77 MB 1.76 MB -14.33 KB (-0.79%)
target/debug/examples/open_ufo 7.15 MB 7.18 MB 31.83 KB (0.43%)

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@madig
Copy link
Collaborator

madig commented Apr 16, 2021

We could have a retain method that silently skips the default layer 🤔

@cmyr
Copy link
Member Author

cmyr commented Apr 16, 2021

We could have a retain method that silently skips the default layer 🤔

Let's see what some more real-world use cases are, and then we can try and come up with an API that addresses them?

This adds a LayerSet type that enforces various constraints on
layers.

Among other things, this means that:

- Layer names are now also stored as Arc<str>
- There is no more LayerInfo type
- there is now always a default layer
- the default layer cannot be removed
- new layers can be added

This also introduces a few other breaking api changes; for instance
I'm removing `Font::get_default_layer(&self) -> Option<&Layer>`
in favour of `Font::default_layer(&self) -> &Layer`.

This was motivated by my experiments with python bindings,
but I think this is generally useful independent of that work
and so I'm PRing it separately.
@github-actions
Copy link

🗜 Bloat check ⚖️

Comparing ddb3757 against 06c42a2

target old size new size difference
target/release/examples/open_ufo 1.77 MB 1.76 MB -14.33 KB (-0.79%)
target/debug/examples/open_ufo 7.15 MB 7.18 MB 31.5 KB (0.43%)

@cmyr cmyr merged commit 79311e2 into master Apr 18, 2021
@cmyr cmyr deleted the layerset branch April 18, 2021 15:14
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.

Ensure default layer is always present Add Ufo::new_layer(name) method
2 participants