From 428bc0168f25309e11e6f515cb9a88b78863e392 Mon Sep 17 00:00:00 2001 From: Rod S Date: Sat, 4 Jan 2025 21:10:19 +0100 Subject: [PATCH] Obey source OS/2 family class --- fontbe/src/os2.rs | 2 ++ fontc/src/lib.rs | 7 +++++++ fontir/src/ir.rs | 5 +++++ resources/testdata/FontInfo-Regular.ufo/fontinfo.plist | 5 +++++ ufo2fontir/src/source.rs | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/fontbe/src/os2.rs b/fontbe/src/os2.rs index 37965e129..6ac6fcfef 100644 --- a/fontbe/src/os2.rs +++ b/fontbe/src/os2.rs @@ -566,6 +566,8 @@ impl Work 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), diff --git a/fontc/src/lib.rs b/fontc/src/lib.rs index 487269e67..1d2d2cc3b 100644 --- a/fontc/src/lib.rs +++ b/fontc/src/lib.rs @@ -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"); diff --git a/fontir/src/ir.rs b/fontir/src/ir.rs index 5f27dd9b0..e1c709e88 100644 --- a/fontir/src/ir.rs +++ b/fontir/src/ir.rs @@ -129,6 +129,9 @@ pub struct MiscMetadata { pub created: Option>, + // + pub family_class: Option, + pub panose: Option, // Allows source to explicitly control bits. @@ -494,6 +497,7 @@ impl StaticMetadata { // head_flags: 3, created: None, + family_class: None, panose: None, unicode_range_bits: None, codepage_range_bits: None, @@ -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, diff --git a/resources/testdata/FontInfo-Regular.ufo/fontinfo.plist b/resources/testdata/FontInfo-Regular.ufo/fontinfo.plist index e75e8de16..28c32a4c6 100644 --- a/resources/testdata/FontInfo-Regular.ufo/fontinfo.plist +++ b/resources/testdata/FontInfo-Regular.ufo/fontinfo.plist @@ -34,5 +34,10 @@ -290 openTypeHheaLineGap 43 + openTypeOS2FamilyClass + + 1 + 2 + diff --git a/ufo2fontir/src/source.rs b/ufo2fontir/src/source.rs index 55de154d4..a3db7988a 100644 --- a/ufo2fontir/src/source.rs +++ b/ufo2fontir/src/source.rs @@ -869,6 +869,11 @@ impl Work 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);