#font #truetype #opentype #ttf #otf

fonterator

Load fonts as vector graphics in pure Rust - based on RustType

1 unstable release

0.1.0 May 25, 2018

#68 in Rendering

Download history 14/week @ 2018-05-26 9/week @ 2018-06-02 6/week @ 2018-06-09 4/week @ 2018-06-16 6/week @ 2018-06-23 12/week @ 2018-06-30 3/week @ 2018-07-07 3/week @ 2018-07-14 4/week @ 2018-07-21 4/week @ 2018-07-28 9/week @ 2018-08-04 8/week @ 2018-08-11 4/week @ 2018-08-18

3 downloads per month
Used in 2 crates (0 directly)

MIT license

43KB
942 lines

Fonterator

Load fonts as vector graphics in pure Rust - based on RustType

Cargo / Documentation / Change Log

Features

fonterator's current features:

  • Load TTF fonts and font collections.
  • Load some OTF fonts and font collections.
  • Automatic kerning and font layout.

fonterator's planned features:

  • Support OpenType formatted fonts that are not just TrueType fonts (OpenType is a superset of TrueType). Notably there is no support yet for cubic Bezier curves used in glyphs.
  • Support ligatures of any kind (‽, etc.).
  • Support some less common TrueType sub-formats.
  • Support right-to-left and vertical text layout.

lib.rs:

Fonterator is a pure Rust alternative to libraries like FreeType based on RustType.

Getting Started

Add the following to your Cargo.toml:

[dependencies]
fonterator = "0.1.0"

To hit the ground running with Fonterator, look at the image.rs example supplied with the crate. It demonstrates loading a font file, rasterising an arbitrary string, and saving as an SVG. If you prefer to just look at the documentation, the entry point for loading fonts is FontCollection, from which you can access individual fonts, then their glyphs.

Unicode terminology

This crate uses terminology for computerised typography as specified by the Unicode standard. If you are not sure of the differences between a code point, a character, and a glyph, you may want to check the official Unicode glossary, or alternatively, here's my take on it from a practical perspective:

  • A character is what you would conventionally call a single symbol, independent of its appearance or representation in a particular font. Examples include a, A, ä, å, 1, *, Ω, etc.
  • A Unicode code point is the particular number that the Unicode standard associates with a particular character. Note however that code points also exist for things not conventionally thought of as characters by themselves, but can be combined to form characters, such as diacritics like accents. These "characters" are known in Unicode as "combining characters". E.g., a diaeresis (¨) has the code point U+0308. If this code point follows the code point U+0055 (the letter u), this sequence represents the character ü. Note that there is also a single codepoint for ü, U+00FC. This means that what visually looks like the same string can have multiple different Unicode representations. Some fonts will have glyphs (see below) for one sequence of codepoints, but not another that has the same meaning. To deal with this problem it is recommended to use Unicode normalisation, as provided by, for example, the unicode-normalization crate, to convert to code point sequences that work with the font in question. Typically a font is more likely to support a single code point vs. a sequence with the same meaning, so the best normalisation to use is "canonical recomposition", known as NFC in the normalisation crate.
  • A glyph is a particular font's shape to draw the character for a particular Unicode code point. This will have its own identifying number unique to the font, its ID.

Dependencies

~3.5MB
~119K SLoC