harfbuzz / uharfbuzz

A HarfBuzz Python binding
Apache License 2.0
68 stars 25 forks source link

Add convenience Font.from_file_path #125

Closed madig closed 2 years ago

madig commented 2 years ago

Because why not.

Can't easily test this locally because I don't have Cython handy. I think tox.ini is missing an isolated_build = true.

anthrotype commented 2 years ago

As for the new API itself, I'm not sure. uharfbuzz is quite low level and tries to mimic the harfbuzz API quite closely. But I suppose it doesn't hurt either. I'll leave it to @justvanrossum or @khaledhosny to decide

khaledhosny commented 2 years ago

I like to expose the HarfBuzz C API faithfully as it allows for writing performance code. I don’t mind higher level API, though, if it allows people to write badly performing code 🤷🏾

madig commented 2 years ago

What makes the method inefficient, except if you want to instantiate multiple Fonts from the same Blob or Face? Where would you do that?

khaledhosny commented 2 years ago

In font collections (TTC, dfont) you can create multiple faces from the same blob. Fonts you can either create and reuse one font per size/variation settings etc, or keep changing the same font possibly invalidating internal HarfBuzz caches everytime the font changes.

madig commented 2 years ago

Hm. So it helps to instantiate multiple Fonts explicitly from the same Face when you want to test VFs across the design space?

khaledhosny commented 2 years ago

Not only for testing. Supposed to want to use bold and regular in the same document and it is a variable font, you create two fonts with different variation settings, or you create one font and keep changing variation settings each time you want to switch weights.