#font #opentype #typeface #typography

opentype

The package provides a parser for OpenType fonts

67 releases (23 breaking)

new 0.24.14 Mar 27, 2023
0.24.10 Feb 22, 2023
0.24.1 Dec 29, 2022
0.19.1 Nov 24, 2022
0.0.2 Nov 21, 2014

#16 in Rendering

Download history 127/week @ 2022-12-05 264/week @ 2022-12-12 180/week @ 2022-12-19 172/week @ 2022-12-26 99/week @ 2023-01-02 252/week @ 2023-01-09 92/week @ 2023-01-16 101/week @ 2023-01-23 237/week @ 2023-01-30 346/week @ 2023-02-06 249/week @ 2023-02-13 291/week @ 2023-02-20 181/week @ 2023-02-27 127/week @ 2023-03-06 42/week @ 2023-03-13 195/week @ 2023-03-20

547 downloads per month
Used in 6 crates (2 directly)

Apache-2.0/MIT

130KB
3K SLoC

OpenType Package Documentation Build

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

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

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

~215KB