Skip to content

Commit

Permalink
Obey source OS/2 family class
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Jan 4, 2025
1 parent 45efcf7 commit 428bc01
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fontbe/src/os2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ impl Work<Context, AnyWorkId, Error> for Os2Work {
// https://github.com/googlefonts/ufo2ft/blob/main/Lib/ufo2ft/outlineCompiler.py#L705
us_break_char: Some(32),

s_family_class: static_metadata.misc.family_class.unwrap_or_default(),

// Avoid "field must be present for version 2" caused by default to None
us_default_char: Some(0),
us_max_context: Some(0),
Expand Down
7 changes: 7 additions & 0 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ mod tests {
);
}

#[test]
fn compile_obeys_family_class() {
let result = TestCompile::compile_source("fontinfo.designspace");
let os2 = result.font().os2().unwrap();
assert_eq!(1 << 8 | 2, os2.s_family_class());
}

#[test]
fn compile_variable_simple_glyph_with_implied_oncurves() {
let result = TestCompile::compile_source("glyphs3/Oswald-O.glyphs");
Expand Down
5 changes: 5 additions & 0 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ pub struct MiscMetadata {

pub created: Option<DateTime<Utc>>,

// <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#sfamilyclass>
pub family_class: Option<i16>,

pub panose: Option<Panose>,

// Allows source to explicitly control bits. <https://github.com/googlefonts/fontc/issues/1027>
Expand Down Expand Up @@ -494,6 +497,7 @@ impl StaticMetadata {
// <https://github.com/googlefonts/ufo2ft/blob/0d2688cd847d003b41104534d16973f72ef26c40/Lib/ufo2ft/fontInfoData.py#L365>
head_flags: 3,
created: None,
family_class: None,
panose: None,
unicode_range_bits: None,
codepage_range_bits: None,
Expand Down Expand Up @@ -1957,6 +1961,7 @@ mod tests {
head_flags: 42,
lowest_rec_ppm: 42,
created: None,
family_class: None,
panose: None,
unicode_range_bits: None,
codepage_range_bits: None,
Expand Down
5 changes: 5 additions & 0 deletions resources/testdata/FontInfo-Regular.ufo/fontinfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
<integer>-290</integer>
<key>openTypeHheaLineGap</key>
<integer>43</integer>
<key>openTypeOS2FamilyClass</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
</dict>
</plist>
5 changes: 5 additions & 0 deletions ufo2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,11 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
.map(|bit_indices| bit_indices.iter().map(|i| 1 << i).fold(0, |acc, e| acc | e))
.unwrap_or(static_metadata.misc.head_flags);

static_metadata.misc.family_class = font_info_at_default
.open_type_os2_family_class
.as_ref()
.map(|v| (v.class_id as i16) << 8 | v.subclass_id as i16);

static_metadata.misc.created =
try_parse_date(font_info_at_default.open_type_head_created.as_ref())
.or(static_metadata.misc.created);
Expand Down

0 comments on commit 428bc01

Please sign in to comment.