#font #truetype #opentype #ttf #otf

fonterator

Load fonts as vector graphics in pure Rust

6 releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.0 May 13, 2019
0.3.0 Dec 9, 2018
0.2.1 Dec 8, 2018
0.2.0-pre0 Nov 25, 2018
0.1.0 May 25, 2018

#28 in Rendering

35 downloads per month
Used in 2 crates (1 directly)

MIT / BSL-1.0

3MB
1K SLoC

Fonterator

Fonterator is a pure Rust font loader. When you want to render text, fonterator gives you an iterator over footile PathOps, which you can easily pass right into footile.

Simple Example

In Cargo.toml,

[dependencies]
fonterator = "0.4.0"

In main.rs,

use fonterator::FontGroup;
use footile::{FillRule, Plotter, Raster, Rgba8};

fn main() {
    // Load the default FontGroup (font and fallbacks).
    let font = FontGroup::default();

    // Init rendering
    let mut p = Plotter::new(2048, 2048);
    let mut r = Raster::new(p.width(), p.height());

    // Render the text
    let mut path = font.render(
        "Héllö,\nWørłd!‽i", /*text*/
        (0.0, 0.0),         /*position*/
        (256.0, 256.0),     /*size*/
    );
    r.over(
        p.fill(&mut path, FillRule::NonZero),
        Rgba8::rgb(0, 0, 0), /*color*/
    );
    r.write_png("main.png").unwrap(); /*save as PNG*/
}

Features

  • Load TTF fonts and font collections.
  • Load some OTF fonts and font collections.
  • Automatic kerning and font layout.
  • Horizontal and vertical text layout.
  • Left-to-right and right-to-left text layout.
  • Use fallback fonts if a character is not available from one font.
  • Optional multilingual monospace (CJK is rendered exactly twice the width of Latin).

TODO

  • Support OpenType fonts that aren't TrueType (Supporting cubic bezier curves).
  • Support ligatures (‽,æ etc.).
  • Support other TrueType variants.

Links


Plop Grizzly

Dependencies