• Stars
    star
    533
  • Rank 83,238 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A complete harfbuzz's shaping algorithm port to Rust

rustybuzz

Build Status Crates.io Documentation

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

Matches harfbuzz v2.7.1

Why?

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.

Conformance

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.

Also, Apple layout is largely untested, because we cannot include Apple fonts for legal reasons. harfbuzz uses macOS CI instances to test it, which is extremely painful and we do not do this for now.

Major changes

  • Subsetting removed.
  • TrueType parsing is completely handled by the ttf-parser. 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.
  • No automated Apple layout testing for legal reasons. We just cannot include Apple fonts. harfbuzz avoids this by running such tests only on CI, which is far from ideal.

Performance

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. In the mean time, rustybuzz contains only shaping. All of the TrueType parsing was moved to the ttf-parser. Subsetting was removed. Unicode code was 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 20 KLOC. While harfbuzz is around 80 KLOC.

Lines of code

As mentioned above, rustybuzz has around 20 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' src

Which gives us around 13 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.

Safety

The library is completely safe.

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

Alternatives

  • harfbuzz_rs - bindings to the actual harfbuzz library. As of v2 doesn't expose subsetting and glyph outlining, which harfbuzz supports.
  • allsorts - shaper and subsetter. As of v0.6 doesn't support variable fonts and Apple Advanced Typography. Relies on some unsafe code.
  • swash - Supports variable fonts, text layout and rendering. No subsetting. Relies on some unsafe code. As of v0.1.4 has zero tests.

License

rustybuzz is licensed under the MIT.

harfbuzz is licensed under the Old MIT

More Repositories

1

resvg

An SVG rendering library.
Rust
2,684
star
2

cargo-bloat

Find out what takes most of the space in your executable.
Rust
2,295
star
3

svgcleaner

svgcleaner could help you to clean up your SVG files from the unnecessary data.
Rust
1,621
star
4

tiny-skia

A tiny Skia subset ported to Rust
Rust
1,089
star
5

ttf-parser

A high-level, safe, zero-allocation TrueType font parser.
Rust
609
star
6

pico-args

An ultra simple CLI arguments parser.
Rust
560
star
7

roxmltree

Represent an XML document as a read-only tree.
Rust
428
star
8

svgcleaner-gui

GUI for svgcleaner.
C++
306
star
9

fontdb

A simple, in-memory font database with CSS-like queries.
Rust
136
star
10

xmlparser

A low-level, pull-based, zero-allocation XML 1.0 parser.
Rust
130
star
11

color-thief-rs

Grabs the dominant color or a representative color palette from an image.
Rust
75
star
12

svgtypes

A collection of parsers for SVG types.
Rust
67
star
13

rctree

A "DOM-like" tree implemented using reference counting
Rust
37
star
14

simplecss

A simple CSS 2.1 parser and selector
Rust
35
star
15

svgdom

Library to represent an SVG as a DOM.
Rust
31
star
16

ttf-explorer

A simple tool to explore a TrueType font content as a tree
C++
30
star
17

xmlwriter

A simple, streaming XML writer.
Rust
24
star
18

resvg-test-suite

resvg test suite
C++
23
star
19

svgparser

(DEPRECATED) Featureful, pull-based, zero-allocation SVG parser.
Rust
22
star
20

notes-on-svg-parsing

Notes on SVG parsing
21
star
21

barh

A simple horizontal bar chart generator.
Rust
9
star
22

strict-num

A collection of bounded numeric types.
Rust
8
star
23

unicode-vo

Unicode vertical orientation detection
Rust
6
star
24

unicode-ccc

Unicode Canonical Combining Class detection
Rust
4
star
25

unicode-bidi-mirroring

Unicode Bidi Mirroring property detection
Rust
3
star
26

RazrFalcon

2
star
27

stb_truetype_meson

C
1
star