Expand description
Parser for OpenType fonts.
Example
use opentype::File;
use opentype::truetype::{FontHeader, HorizontalHeader};
use opentype::truetype::naming_table::{NameID, NamingTable};
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 naming_table: NamingTable = ok!(ok!(fonts[0].take(&mut tape)));
let names = naming_table
.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;
pub use glyph_definition::GlyphDefinition;
pub use glyph_positioning::GlyphPositioning;
pub use glyph_substitution::GlyphSubstitution;
Modules
- The compact file format of version 2.0.
- The common layout tables.
Structs
- A file.
- A font.
Traits
- A type representing a font table.
- A type that can read.
- A type that can be read.
- A type that can be read given a parameter.
Functions
- Check if a tag is recognized.
Type Definitions
- An error.
- A result.