opentype

Crates.ioopentype
lib.rsopentype
version0.38.0
sourcesrc
created_at2014-11-20 21:42:35.706157
updated_at2024-08-30 13:12:33.305112
descriptionThe package provides a builder and parser of OpenType fonts.
homepagehttps://github.com/bodoni/opentype
repositoryhttps://github.com/bodoni/opentype
max_upload_size
id163
size158,260
Owners (github:buoyantio:owners)

documentation

https://docs.rs/opentype

README

OpenType Package Documentation Build

The package provides a builder and parser of OpenType fonts. It might be helpful to have a look at a higher-level abstraction called font, which internally relies on this package.

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");

Contribution

Your contribution is highly appreciated. Do not hesitate to open an issue or a pull request. Note that any contribution submitted for inclusion in the project will be licensed according to the terms given in LICENSE.md.

Commit count: 603

cargo fmt