yeslogic / allsorts

Font parser, shaping engine, and subsetter implemented in Rust
https://yeslogic.com/blog/allsorts-rust-font-shaping-engine/
Apache License 2.0
706 stars 23 forks source link

Make Adjust::apply, Placement::combine_distance and Placement::combine_anchor public #36

Open fschutt opened 3 years ago

fschutt commented 3 years ago

In order to layout a text line from the Vec<gpos::Info> it would be nice to be able to calculate the glyph positions. The Adjust::apply, Placement::combine_distance and Placement::combine_anchor functions already do that, but they're not public functions, is this intentional?

wezm commented 3 years ago

These methods are internal and already run as part of gpos. They are used to update the placement field on gpos::Info as part of that process. I'll work on updating the shaping example to include positioning information.

We plan to roll positioning information into the the output of shape but haven't quite got there yet. I've been working on improving the API recently in preparation for a 0.5 release. You might like to check out the master branch of allsorts and the draft PR I have open on the allsorts-tools repo.

fschutt commented 3 years ago

Yeah I'm currently just calling .get_horizontal_advance on every glyph and adding the kerning on top. As I understand it, there can be only one glyph -> multiple codepoints, right? HarfBuzz has extra "clusters" (where one glyph can be made up of multiple parts), I'm not sure whether control over clusters is exposed in the API right now.

Thanks for doing the work of porting font shaping, btw, I've had lots of people with problems installing my crates since they rely on HarfBuzz and HarfBuzz doesn't always compile out of the box (since you need cmake to build it, etc.). Also I can now run my crate on wasm32, so that's a plus.

wezm commented 3 years ago

I'm currently just calling .get_horizontal_advance on every glyph and adding the kerning on top.

Yes that will get you a lot of the way there.

As I understand it, there can be only one glyph -> multiple codepoints, right?

Yes that's right.

HarfBuzz has extra "clusters" (where one glyph can be made up of multiple parts), I'm not sure whether control over clusters is exposed in the API right now.

We don't have the concept of clusters. What they allow (mapping shaping output back to input text) is another one of the things that we plan to get to eventually. https://github.com/yeslogic/allsorts/issues/31

Thanks for doing the work of porting font shaping, btw, I've had lots of people with problems installing my crates since they rely on HarfBuzz and HarfBuzz doesn't always compile out of the box (since you need cmake to build it, etc.). Also I can now run my crate on wasm32, so that's a plus.

This is really great to hear. Thanks for sharing 😀