From d72657ccda9b307dad658a1f31715d2302b109df Mon Sep 17 00:00:00 2001 From: rsheeter Date: Tue, 3 Dec 2024 11:27:15 -0800 Subject: [PATCH] Prefer default master panose --- glyphs-reader/src/font.rs | 1 + glyphs2fontir/src/source.rs | 31 +++--- .../testdata/glyphs3/MultiplePanose.glyphs | 99 +++++++++++++++++++ 3 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 resources/testdata/glyphs3/MultiplePanose.glyphs diff --git a/glyphs-reader/src/font.rs b/glyphs-reader/src/font.rs index 7cd5c6c7..536242c8 100644 --- a/glyphs-reader/src/font.rs +++ b/glyphs-reader/src/font.rs @@ -668,6 +668,7 @@ impl RawCustomParameters { _ => log::warn!("unknown custom parameter '{name}'"), } } + eprintln!("panose {:?}\npanose_old {:?}", panose, panose_old); params.panose = panose.or(panose_old); params.virtual_masters = Some(virtual_masters).filter(|x| !x.is_empty()); Ok(params) diff --git a/glyphs2fontir/src/source.rs b/glyphs2fontir/src/source.rs index b983dabb..0fe9a378 100644 --- a/glyphs2fontir/src/source.rs +++ b/glyphs2fontir/src/source.rs @@ -18,8 +18,8 @@ use fontir::{ error::{BadGlyph, BadGlyphKind, BadSource, Error}, ir::{ self, AnchorBuilder, GdefCategories, GlobalMetric, GlobalMetrics, GlyphInstance, - GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance, MetaTableValues, - NameBuilder, NameKey, NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID, + GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance, NameBuilder, NameKey, + NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID, }, orchestration::{Context, IrWork, WorkId}, source::{Input, Source}, @@ -468,7 +468,13 @@ impl Work for StaticMetadataWork { .as_ref() .map(|bits| bits.iter().copied().collect()); - if let Some(raw_panose) = font.custom_parameters.panose.as_ref() { + if let Some(raw_panose) = font + .default_master() + .custom_parameters + .panose + .as_ref() + .or(font.custom_parameters.panose.as_ref()) + { let mut bytes = [0u8; 10]; bytes .iter_mut() @@ -496,13 +502,6 @@ impl Work for StaticMetadataWork { }) .or(static_metadata.misc.created); - if let Some(meta_table) = &font.custom_parameters.meta_table { - static_metadata.misc.meta_table = Some(MetaTableValues { - dlng: meta_table.dlng.clone(), - slng: meta_table.slng.clone(), - }); - } - context.static_metadata.set(static_metadata); let glyph_order = font @@ -1051,7 +1050,7 @@ mod tests { }; use glyphs_reader::{glyphdata::Category, Font}; use indexmap::IndexSet; - use ir::test_helpers::Round2; + use ir::{test_helpers::Round2, Panose}; use write_fonts::types::{NameId, Tag}; use crate::source::names; @@ -1965,4 +1964,14 @@ mod tests { let static_metadata = context.static_metadata.get(); assert_eq!(Tag::new(b"RGHT"), static_metadata.misc.vendor_id); } + + #[test] + fn prefer_default_master_panose() { + let (_, context) = build_static_metadata(glyphs3_dir().join("MultiplePanose.glyphs")); + let static_metadata = context.static_metadata.get(); + assert_eq!( + Some(Panose::from([2u8, 3, 4, 5, 6, 7, 8, 9, 10, 11])), + static_metadata.misc.panose + ); + } } diff --git a/resources/testdata/glyphs3/MultiplePanose.glyphs b/resources/testdata/glyphs3/MultiplePanose.glyphs new file mode 100644 index 00000000..ae937f03 --- /dev/null +++ b/resources/testdata/glyphs3/MultiplePanose.glyphs @@ -0,0 +1,99 @@ +{ +.formatVersion = 3; +axes = ( +{ +name = Weight; +tag = wght; +} +); + +customParameters = ( +{ +name = panose; +value = ( +1, +2, +3, +4, +5, +6, +7, +8, +9, +10 +); +} +); + +familyName = FamilyName; +fontMaster = ( +{ +axesValues = ( +400 +); +id = m01; +name = Regular; +customParameters = ( +{ +name = panose; +value = ( +2, +3, +4, +5, +6, +7, +8, +9, +10, +11 +); +} +); +}, + +{ +axesValues = ( +700 +); +id = "E09E0C54-128D-4FEA-B209-1B70BEFE300B"; +name = Bold; +customParameters = ( +{ +name = panose; +value = ( +3, +4, +5, +6, +7, +8, +9, +10, +11, +12 +); +} +); +} +); + +glyphs = ( +{ +glyphname = space; +layers = ( +{ +layerId = m01; +width = 200; +}, +{ +layerId = "E09E0C54-128D-4FEA-B209-1B70BEFE300B"; +width = 600; +} +); +unicode = 32; +} +); +unitsPerEm = 1000; +versionMajor = 1; +}