[][src]Crate 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.2.0"

In main.rs,

extern crate fonterator;
extern crate footile;
 
use fonterator::Font;
use footile::{FillRule, Plotter, Raster, Rgba8};
 
const FONT: &[u8] = include_bytes!("../font/LiberationSans-Regular.ttf");
 
fn main() {
    // This only succeeds if collection consists of one font
    let font = Font::new(FONT).expect("Failed to load font!");
 
    // Init rendering
    let mut p = Plotter::new(2048, 2048);
    let mut r = Raster::new(p.width(), p.height());
 
    // Render the text
    let path = font.render(
        "Héllö,\nWørłd!", /*text*/
        (0.0, 0.0),       /*position*/
        (256.0, 256.0),   /*size*/
    );
    r.over(
        p.fill(path, FillRule::NonZero),
        Rgba8::rgb(0, 0, 0), /*color*/
    );
    r.write_png("main.png").unwrap(); /*save as PNG*/
}

Structs

Font

A single font. This may or may not own the font data.

FontCollection

A collection of fonts read straight from a font file's data. The data in the collection is not validated. This structure may or may not own the font data.

PathIterator

An iterator created by Font for PathOps.

Enums

Error

The type for errors returned by Fonterator.

PathOp

Path operation.

SharedBytes

SharedBytes handles the lifetime of font data used in Fonterator. The data is either a shared reference to externally owned data, or managed by reference counting. SharedBytes can be conveniently used with From and Into, and dereferences to the contained bytes.