Crate opentype

Source
Expand description

Builder and parser of OpenType fonts.

§Example

use opentype::truetype::tables::names::{Names, NameID};
use opentype::truetype::tables::{FontHeader, HorizontalHeader};
use opentype::File;

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

let path = "SourceSerifPro-Regular.otf";
let mut tape = ok!(std::fs::File::open(path));
let File { mut fonts } = ok!(File::read(&mut tape));

let font_header: FontHeader = ok!(ok!(fonts[0].take(&mut tape)));
assert_eq!(font_header.units_per_em, 1000);

let horizontal_header: HorizontalHeader = ok!(ok!(fonts[0].take(&mut tape)));
assert_eq!(horizontal_header.ascender, 918);

let names: Names = ok!(ok!(fonts[0].take(&mut tape)));
let names = names
    .iter()
    .map(|((_, _, _, name_id), value)| (name_id, value))
    .collect::<std::collections::HashMap<_, _>>();
assert_eq!(ok!(names[&NameID::FullFontName].as_ref()), "Source Serif Pro");
assert_eq!(ok!(names[&NameID::DesignerName].as_ref()), "Frank Grießhammer");

Re-exports§

pub extern crate postscript;
pub extern crate truetype;

Modules§

layout
The common layout tables.
tables
The primary tables.
tape
Types that can read and write.
value
Types that can be read and written.
variations
The common font-variations tables.
walue
Types that can be read and written given a parameter.

Structs§

File
A file.
Font
A font.

Traits§

Table
A type representing a font table.

Functions§

accept
Check if a tag is recognized.

Type Aliases§

Error
An error.
Result
A result.