Skip to content

Commit 5cf057f

Browse files
committed
feat: dump style_name of font
1 parent 58a2e2c commit 5cf057f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fontkit"
3-
version = "0.2.0-beta.12"
3+
version = "0.2.0-beta.13"
44
edition = "2021"
55
authors = ["Zimon Dai <[email protected]>"]
66
description = "A simple library for font loading and indexing"

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct Name {
183183
pub struct Font {
184184
key: FontKey,
185185
names: Vec<Name>,
186+
style_names: Vec<Name>,
186187
face: ArcSwap<Option<StaticFace>>,
187188
path: Option<PathBuf>,
188189
}
@@ -215,12 +216,19 @@ impl Font {
215216
face_builder: |buf| Face::from_slice(buf, 0),
216217
}
217218
.try_build()?;
219+
let mut style_names = vec![];
218220
let names = face
219221
.borrow_face()
220222
.names()
221223
.into_iter()
222224
.filter_map(|name| {
223225
let id = name.name_id;
226+
if id == name_id::TYPOGRAPHIC_SUBFAMILY {
227+
style_names.push(Name {
228+
name: name.to_string()?,
229+
language_id: name.language_id,
230+
});
231+
}
224232
if id == name_id::FAMILY
225233
|| id == name_id::FULL_NAME
226234
|| id == name_id::POST_SCRIPT_NAME
@@ -271,6 +279,7 @@ impl Font {
271279
key,
272280
face: ArcSwap::new(Arc::new(Some(face))),
273281
path: None,
282+
style_names,
274283
};
275284
Ok(font)
276285
}
@@ -724,7 +733,8 @@ pub unsafe extern "C" fn list_all_font(fontkit: *mut FontKit) -> *const u8 {
724733
"stretch": Width::from(key.stretch as u16).to_string(),
725734
"italic": key.italic,
726735
"weight": key.weight,
727-
"family": key.family()
736+
"family": key.family(),
737+
"styleNames": font.style_names.clone()
728738
})
729739
})
730740
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)