A high-level, safe, zero-allocation TrueType font parser.
unsafe
.cmap
) Character to glyph index mapping using [glyph_index()] method.
cmap
) Character variation to glyph index mapping using [glyphvariationindex()] method.glyf
) Glyph outlining using [outline_glyph()] method.hmtx
) Retrieving a glyph's horizontal metrics using [glyphhormetrics()] method.vmtx
) Retrieving a glyph's vertical metrics using [glyphvermetrics()] method.kern
) Retrieving a glyphs pair kerning using [glyphs_kerning()] method.maxp
) Retrieving a total number of glyphs using [numberofglyphs()] method.name
) Listing all name records using [names()] method.name
) Retrieving a font's family name using [family_name()] method.name
) Retrieving a font's PostScript name using [postscriptname()] method.post
) Retrieving a font's underline metrics name using [underline_metrics()] method.head
) Retrieving a font's units per EM value using [unitsperem()] method.hhea
) Retrieving a generic font info using: [ascender()], [descender()], [height()]
and [line_gap()] methods.CFF
) Glyph outlining using [outline_glyph()] method.OS/2
) Retrieving a font kind using [isregular()], [isitalic()],
[isbold()] and [isoblique()] methods.OS/2
) Retrieving a font's weight using [weight()] method.OS/2
) Retrieving a font's width using [width()] method.OS/2
) Retrieving a font's X height using [x_height()] method.OS/2
) Retrieving a font's strikeout metrics using [strikeout_metrics()] method.OS/2
) Retrieving a font's subscript metrics using [subscript_metrics()] method.OS/2
) Retrieving a font's superscript metrics using [superscript_metrics()] method.TrueType fonts designed for fast querying, so most of the methods are very fast. The main exception is glyph outlining. Glyphs can be stored using two different methods: using Glyph Data format and Compact Font Format (pdf). The first one is fairly simple which makes it faster to process. The second one is basically a tiny language with a stack-based VM, which makes it way harder to process. Currently, it takes 60% more time to outline all glyphs in SourceSansPro-Regular.otf (which uses CFF) rather than in SourceSansPro-Regular.ttf.
test outline_cff ... bench: 1,652,606 ns/iter (+/- 2,795)
test outline_glyf ... bench: 1,004,866 ns/iter (+/- 1,545)
Here is some methods benchmarks:
test outline_glyph_276_from_cff ... bench: 1,247 ns/iter (+/- 2)
test outline_glyph_276_from_glyf ... bench: 817 ns/iter (+/- 15)
test outline_glyph_8_from_cff ... bench: 521 ns/iter (+/- 2)
test family_name ... bench: 398 ns/iter (+/- 2)
test from_data_otf ... bench: 394 ns/iter (+/- 5)
test outline_glyph_8_from_glyf ... bench: 360 ns/iter (+/- 7)
test from_data_ttf ... bench: 96 ns/iter (+/- 3)
test glyph_index_u41 ... bench: 27 ns/iter (+/- 0)
test glyph_2_hor_metrics ... bench: 8 ns/iter (+/- 0)
family_name
is expensive, because it allocates a String
and the original data
is stored as UTF-16 BE.
Some methods are too fast, so we execute them 1000 times to get better measurements.
test x_height ... bench: 847 ns/iter (+/- 0)
test units_per_em ... bench: 564 ns/iter (+/- 2)
test strikeout_metrics ... bench: 564 ns/iter (+/- 0)
test width ... bench: 422 ns/iter (+/- 0)
test ascender ... bench: 279 ns/iter (+/- 1)
test subscript_metrics ... bench: 279 ns/iter (+/- 0)
unsafe
code.Rust >= 1.35
panic
a lot.Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.