#text #shaping #opentype #truetype


A complete harfbuzz shaping algorithm port to Rust

5 releases (3 breaking)

0.4.0 Jun 27, 2021
0.3.0 Dec 5, 2020
0.2.0 Jul 25, 2020
0.1.1 Jul 4, 2020
0.1.0 Jul 4, 2020

#46 in Text processing

Download history 2122/week @ 2021-07-04 2776/week @ 2021-07-11 2307/week @ 2021-07-18 2520/week @ 2021-07-25 2385/week @ 2021-08-01 4023/week @ 2021-08-08 2992/week @ 2021-08-15 2304/week @ 2021-08-22 2549/week @ 2021-08-29 3293/week @ 2021-09-05 4141/week @ 2021-09-12 3666/week @ 2021-09-19 3896/week @ 2021-09-26 4118/week @ 2021-10-03 3869/week @ 2021-10-10 3623/week @ 2021-10-17

9,367 downloads per month
Used in 30 crates (5 directly)

MIT license

25K SLoC


Build Status Crates.io Documentation

rustybuzz is a complete harfbuzz's shaping algorithm port to Rust.

Matches harfbuzz v2.7.1


Because you can add rustybuzz = "*" to your project and it just works. No need for a C++ compiler. No need to configure anything. No need to link to system libraries.


rustybuzz passes 98% of harfbuzz tests (1764 to be more precise). So it's mostly identical, but there are still some tiny edge-cases which are not implemented yet or cannot be implemented at all.

Major changes

  • Subsetting removed.
  • TrueType parsing has been implemented from scratch, mostly on the ttf-parser side. And while the parsing algorithm is very different, it's not better or worse, just different.
  • Malformed fonts will cause an error. HarfBuzz uses fallback/dummy shaper in this case.
  • No font size property. Shaping is always using UnitsPerEm. You should scale the result manually.
  • Most of the TrueType and Unicode handling code was moved into separate crates.
  • rustybuzz doesn't interact with any system libraries and must produce exactly the same results on all OS'es and targets.
  • mort table is not supported, since it's deprecated by Apple.
  • No Arabic fallback shaper, since it requires subsetting.
  • No graphite library support.


At the moment, performance isn't that great. We're 1.5-2x slower than harfbuzz. Also, rustybuzz doesn't support shaping plan caching at the moment.

See benches/README.md for details.

Notes about the port

rustybuzz is not a faithful port.

harfbuzz can roughly be split into 6 parts: shaping, subsetting, TrueType parsing, Unicode routines, custom containers and utilities (harfbuzz doesn't use C++ std) and glue for system/3rd party libraries. While rustybuzz contains only shaping and some TrueType parsing. Most of the TrueType parsing was moved to the ttf-parser. Subseting was removed. Unicode code mostly moved to external crates. We don't need custom containers because Rust's std is good enough. And we do not use any non Rust libraries, so no glue code either.

In the end, we still have around 23 KLOC. While harfbuzz is around 80 KLOC.

Lines of code

As mentioned above, rustybuzz has around 23 KLOC. But this is not strictly true, because there are a lot of auto-generated data tables.

You can find the "real" code size using:

tokei --exclude unicode_norm.rs --exclude complex/vowel_constraints.rs \
      --exclude '*_machine.rs' --exclude '*_table.rs'

Which gives us around 16 KLOC, which is still a lot.

Future work

Since the port is finished, there is not much to do other than syncing it with a new harfbuzz releases. But there are still a lot of room for performance optimizations and refactoring.

Also, despite the fact that harfbuzz has a vast test suite, there are still a lot of things left to test.


The library is completely safe.

We do have one unsafe to cast between two POD structures. But except that, there are no unsafe in this library and in most of its dependencies (excluding bytemuck).


rustybuzz is licensed under the MIT.

harfbuzz is licensed under the Old MIT