#font #typography #typeface #opentype-font

opentype

The package provides a builder and parser of OpenType fonts

106 releases

0.39.1 May 14, 2025
0.38.4 May 14, 2025
0.38.1 Dec 20, 2024
0.38.0 Aug 30, 2024
0.0.2 Nov 21, 2014

#1 in #opentype-font

Download history 3/week @ 2025-07-29 10/week @ 2025-08-05 32/week @ 2025-08-12 123/week @ 2025-08-19 38/week @ 2025-08-26 55/week @ 2025-09-02 52/week @ 2025-09-09 113/week @ 2025-09-16 57/week @ 2025-09-23 20/week @ 2025-09-30 13/week @ 2025-10-07 12/week @ 2025-10-14 18/week @ 2025-10-21 1/week @ 2025-10-28 24/week @ 2025-11-04 10/week @ 2025-11-11

55 downloads per month
Used in 8 crates (3 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

~240KB