100个版本 (36个破坏性更新)
0.37.1 | 2024年5月23日 |
---|---|
0.36.1 | 2024年5月20日 |
0.35.2 | 2024年2月16日 |
0.29.8 | 2023年10月31日 |
0.0.2 | 2014年11月21日 |
#35 in 渲染
每月107次下载
在 7 个crate中使用 (2个直接使用)
140KB
3.5K SLoC
OpenType

该包提供了OpenType字体的构建器和解析器。查看高级抽象,例如font
可能有所帮助,该抽象内部依赖于本包。
示例
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");
贡献
您的贡献将受到高度赞赏。请勿犹豫,提出问题或发起拉取请求。请注意,提交给项目以供包含的贡献将根据LICENSE.md中给出的条款进行许可。
依赖项
~235KB