Crate opentype [] [src]

A parser for OpenType fonts.

Example

extern crate opentype;
extern crate truetype;

use opentype::Font;
use truetype::{FontHeader, HorizontalHeader, NamingTable};

macro_rules! ok(($result:expr) => ($result.unwrap()));

let path = "SourceSerifPro-Regular.otf";
let mut reader = ok!(std::fs::File::open(path));
let font = ok!(Font::read(&mut reader));

let font_header: FontHeader = ok!(ok!(font.take(&mut reader)));
assert_eq!(font_header.units_per_em, 1000);

let horizontal_header: HorizontalHeader = ok!(ok!(font.take(&mut reader)));
assert_eq!(horizontal_header.ascender, 918);

let naming_table: NamingTable = ok!(ok!(font.take(&mut reader)));
match naming_table {
    NamingTable::Format0(ref table) => {
        let strings = ok!(table.strings());
        assert_eq!(&strings[1], "Source Serif Pro");
        assert_eq!(&strings[9], "Frank Grießhammer");
    },
    _ => unreachable!(),
}

Reexports

pub use glyph_positioning::GlyphPositioning;
pub use glyph_substitution::GlyphSubstitution;

Modules

glyph_definition

The glyph-definition table.

glyph_positioning

The glyph-positioning table.

glyph_substitution

The glyph-substitution table.

glyph_transformation

The common layout of glyph transformations.

Structs

File

A file.

Font

A font.

GlyphDefinition

A glyph-definition table.

Traits

Table

A font table.