[][src]Crate font_kit

font-kit provides a common interface to the various system font libraries and provides services such as finding fonts on the system, performing nearest-font matching, and rasterizing glyphs.

Synopsis

use euclid::{Point2D, Size2D};
use font_kit::canvas::{Canvas, Format, RasterizationOptions};
use font_kit::family_name::FamilyName;
use font_kit::hinting::HintingOptions;
use font_kit::properties::Properties;
use font_kit::source::SystemSource;

let font = SystemSource::new().select_best_match(&[FamilyName::SansSerif],
                                                 &Properties::new())
                              .unwrap()
                              .load()
                              .unwrap();
let glyph_id = font.glyph_for_char('A').unwrap();
let mut canvas = Canvas::new(&Size2D::new(32, 32), Format::A8);
font.rasterize_glyph(&mut canvas,
                     glyph_id,
                     32.0,
                     &Point2D::zero(),
                     HintingOptions::None,
                     RasterizationOptions::GrayscaleAa)
    .unwrap();

Backends

font-kit delegates to system libraries to perform tasks. It has two types of backends: a source and a loader. Sources are platform font databases; they allow lookup of installed fonts by name or attributes. Loaders are font loading libraries; they allow font files (TTF, OTF, etc.) to be loaded from a file on disk or from bytes in memory. Sources and loaders can be freely intermixed at runtime; fonts can be looked up via DirectWrite and rendered via FreeType, for example.

Available loaders:

Available sources:

On Windows and macOS, the FreeType loader and the Fontconfig source are not built by default. To build them, use the loader-freetype and source-fontconfig Cargo features respectively. If you want them to be the default, instead use the loader-freetype-default and source-fontconfig-default Cargo features respectively. Beware that source-fontconfig-default is rarely what you want on those two platforms!

Features

font-kit is capable of doing the following:

License

font-kit is licensed under the same terms as Rust itself.

Modules

canvas

An in-memory bitmap surface for glyph rasterization.

error

Various types of errors that font-kit can return.

family

Defines a set of faces that vary in weight, width or slope.

family_handle

Encapsulates the information needed to locate and open the fonts in a family.

family_name

A possible value for the font-family CSS property.

file_type

The type of a font file: either a single font or a TrueType/OpenType collection.

font

A font face loaded into memory.

handle

Encapsulates the information needed to locate and open a font.

hinting

Specifies how hinting (grid fitting) is to be performed (or not performed) for a glyph.

loader

Provides a common interface to the platform-specific API that loads, parses, and rasterizes fonts.

loaders

The different system services that can load and rasterize fonts.

metrics

Various metrics that apply to the entire font.

properties

Properties that specify which font in a family to use: e.g. style, weight, and stretchiness.

source

A database of installed fonts that can be queried.

sources

Various databases of installed fonts that can be queried.