A high-level, safe, zero-allocation TrueType font parser.
no_std
compatible.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 glyph's horizontal metrics using [glyphhoradvance()] and [glyphhorside_bearing()] methods.vmtx
) Retrieving glyph's vertical metrics using [glyphveradvance()] and [glyphverside_bearing()] methods.kern
) Retrieving glyphs pair kerning using [glyphs_kerning()] method.maxp
) Retrieving total number of glyphs using [numberofglyphs()] method.name
) Listing all name records using [names()] method.name
) Retrieving font's family name using [family_name()] method.name
) Retrieving font's PostScript name using [postscriptname()] method.post
) Retrieving font's underline metrics using [underline_metrics()] method.post
) Retrieving glyph's name using [glyph_name()] method.head
) Retrieving font's units per EM value using [unitsperem()] method.hhea
) Retrieving generic font info using: [ascender()], [descender()], [height()]
and [line_gap()] methods.CFF
) Glyph outlining using [outline_glyph()] method.OS/2
) Retrieving font's kind using [isregular()], [isitalic()],
[isbold()] and [isoblique()] methods.OS/2
) Retrieving font's weight using [weight()] method.OS/2
) Retrieving font's width using [width()] method.OS/2
) Retrieving font's X height using [x_height()] method.OS/2
) Retrieving font's strikeout metrics using [strikeout_metrics()] method.OS/2
) Retrieving font's subscript metrics using [subscript_metrics()] method.OS/2
) Retrieving font's superscript metrics using [superscript_metrics()] method.GDEF
) Retrieving glyph's class using [glyph_class()] method.GDEF
) Retrieving glyph's mark attachment class using [glyphmarkattachment_class()] method.GDEF
) Checking that glyph is a mark using [ismarkglyph()] method.VORG
) Retrieving glyph's vertical origin using [glyphyorigin()] method.ttf-parser
is designed to parse well-formed fonts, so it does not have an Error
enum.
It doesn't mean that it will crash or panic on malformed fonts, only that the
error handling will boil down to Option::None
. So you will not get a detailed cause of an error.
By doing so we can simplify an API quite a lot since otherwise, we will have to use
Result<Option<T>, Error>
.
Some methods may print warnings, when the logging
feature is enabled.
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.
test outline_cff ... bench: 1,298,871 ns/iter (+/- 11,846)
test outline_glyf ... bench: 837,958 ns/iter (+/- 6,261)
Here is some methods benchmarks:
test outline_glyph_276_from_cff ... bench: 1,041 ns/iter (+/- 71)
test outline_glyph_276_from_glyf ... bench: 674 ns/iter (+/- 15)
test from_data_otf_cff ... bench: 403 ns/iter (+/- 3)
test outline_glyph_8_from_cff ... bench: 339 ns/iter (+/- 44)
test outline_glyph_8_from_glyf ... bench: 295 ns/iter (+/- 16)
test glyph_name_276 ... bench: 214 ns/iter (+/- 1)
test from_data_ttf ... bench: 169 ns/iter (+/- 3)
test family_name ... bench: 155 ns/iter (+/- 5)
test glyph_index_u41 ... bench: 16 ns/iter (+/- 0)
test glyph_name_8 ... bench: 1 ns/iter (+/- 0)
test underline_metrics ... bench: 0.5 ns/iter (+/- 0)
test units_per_em ... bench: 0.5 ns/iter (+/- 0)
test strikeout_metrics ... bench: 0.5 ns/iter (+/- 0)
test x_height ... bench: 0.4 ns/iter (+/- 0)
test ascender ... bench: 0.2 ns/iter (+/- 0)
test hor_advance ... bench: 0.2 ns/iter (+/- 0)
test hor_side_bearing ... bench: 0.2 ns/iter (+/- 0)
test subscript_metrics ... bench: 0.2 ns/iter (+/- 0)
test width ... bench: 0.2 ns/iter (+/- 0)
family_name
is expensive, because it allocates a String
and the original data
is stored as UTF-16 BE.
glyph_name_8
is faster that glyph_name_276
, because for glyph indexes lower than 258
we are using predefined names, so no parsing is involved.
panic
a lot.ttf-parser
, but supports less features.
Still an alpha. Isn't allocation free.(revised on 2019-09-24)
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.