#font #font-file #typography #typeface

opentype

The package provides a builder and parser of OpenType fonts

101 releases (37 breaking)

0.38.0 Aug 30, 2024
0.37.1 May 23, 2024
0.36.1 May 20, 2024
0.35.2 Feb 16, 2024
0.0.2 Nov 21, 2014

#49 in Rendering

Download history 22/week @ 2024-07-29 14/week @ 2024-08-05 71/week @ 2024-08-12 41/week @ 2024-08-19 210/week @ 2024-08-26 23/week @ 2024-09-02 39/week @ 2024-09-09 46/week @ 2024-09-16 51/week @ 2024-09-23 42/week @ 2024-09-30 31/week @ 2024-10-07 55/week @ 2024-10-14 21/week @ 2024-10-21 14/week @ 2024-10-28 26/week @ 2024-11-04 24/week @ 2024-11-11

110 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