ttf-parser 0.5 - new library for working with TrueType fonts

ttf-parser is a library for parsing TrueType/OpenType fonts.
The new version has full support for variable fonts
(variable fonts) and the C API, so I decided to advertise it on lore.

Until recently, if there was a need to work with TrueType fonts, there were exactly two options: FreeType and stb_truetype. The first is a huge harvester, the second supports a fairly small number of functions.

ttf-parser is somewhere in the middle. It supports all the same TrueType tables (the TrueType format consists of many separate binary tables) as FreeType, but does not draw the glyphs themselves.

At the same time, ttf-parser contains many other significant differences:

  1. ttf-parser is written in Rust without using unsafe. FreeType and stb_truetype are written in C.
  2. ttf-parser is the only memory-safe implementation. Reading arbitrary memory is not possible. FreeType is constantly fixing vulnerabilities, and stb_truetype is basically not designed to read arbitrary fonts.
  3. ttf-parser is the only thread-safe implementation. All parsing methods are constant. The only exception is setting coordinates for variable fonts, but this function is reentrant. FreeType is basically single-threaded. stb_truetype - reentrant (you can use separate copies in different streams, but not one of many).
  4. ttf-parser is the only implementation that does not use heap allocation. This speeds up parsing and avoids OOM issues.
  5. Also, almost all arithmetic operations and casting of numeric types are checked (including statically).
  6. In the worst case, the library may throw an exception. In this case, in the C API, exceptions will be caught and the function will return an error, but will not crash.

And despite all the security guarantees, ttf-parser is also the fastest implementation. For example CFF2 parsing is 3.5 times faster than FreeType. Parsing glyf, meanwhile, is 10% slower than stb_truetype, but this is due to the fact that it does not support variable fonts, the implementation of which requires additional storage. information. More details in README.

Source: linux.org.ru

Add a comment