#font #typography #typeface

opentype

The package provides a builder and parser of OpenType fonts

97 releases (34 breaking)

0.35.2 Feb 16, 2024
0.34.3 Feb 2, 2024
0.29.8 Oct 31, 2023
0.26.0 Jul 21, 2023
0.0.2 Nov 21, 2014

#41 in Rendering

Download history 48/week @ 2023-12-22 79/week @ 2023-12-29 146/week @ 2024-01-05 133/week @ 2024-01-12 39/week @ 2024-01-19 77/week @ 2024-01-26 193/week @ 2024-02-02 10/week @ 2024-02-09 841/week @ 2024-02-16 254/week @ 2024-02-23 134/week @ 2024-03-01 60/week @ 2024-03-08 82/week @ 2024-03-15 44/week @ 2024-03-22 101/week @ 2024-03-29 163/week @ 2024-04-05

402 downloads per month
Used in 7 crates (2 directly)

Apache-2.0/MIT

140KB
3.5K SLoC

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.

Dependencies

~235KB