diff --git a/glyphs-reader/src/font.rs b/glyphs-reader/src/font.rs index d272978d..78933e00 100644 --- a/glyphs-reader/src/font.rs +++ b/glyphs-reader/src/font.rs @@ -1882,7 +1882,7 @@ impl UserToDesignMapping { fn new(from: &RawFont, instances: &[Instance]) -> Self { let from_axis_mapping = user_to_design_from_axis_mapping(from); let from_axis_location = user_to_design_from_axis_location(from); - let (result, add_instance_mappings) = match (from_axis_mapping, from_axis_location) { + let (result, incomplete_mapping) = match (from_axis_mapping, from_axis_location) { (Some(from_mapping), Some(..)) => { warn!("Axis Mapping *and* Axis Location are defined; using Axis Mapping"); (from_mapping, false) @@ -1892,10 +1892,10 @@ impl UserToDesignMapping { (None, None) => (BTreeMap::new(), true), }; let mut result = Self(result); - if add_instance_mappings { + if incomplete_mapping { result.add_instance_mappings_if_new(instances); + result.add_master_mappings_if_new(from); } - result.add_master_mappings_if_new(from); result } @@ -3622,4 +3622,18 @@ mod tests { } } } + + // We had a bug where if a master wasn't at a mapping point the Axis Mapping was modified + #[test] + fn ignore_masters_if_axis_mapping() { + let font = Font::load(&glyphs2_dir().join("MasterNotMapped.glyphs")).unwrap(); + let mapping = &font.axis_mappings.0.get("Weight").unwrap().0; + assert_eq!( + vec![ + (OrderedFloat(400_f64), OrderedFloat(40.0)), + (OrderedFloat(700_f64), OrderedFloat(70.0)) + ], + *mapping + ); + } } diff --git a/resources/testdata/glyphs2/MasterNotMapped.glyphs b/resources/testdata/glyphs2/MasterNotMapped.glyphs new file mode 100644 index 00000000..01bb86e3 --- /dev/null +++ b/resources/testdata/glyphs2/MasterNotMapped.glyphs @@ -0,0 +1,60 @@ +{ +customParameters = ( +{ +name = Axes; +value = ( +{ +Name = Weight; +Tag = wght; +} +); +}, +{ +name = "Axis Mappings"; +value = { +wght = { +400 = 40; +700 = 70; +}; +}; +} +); + +familyName = MnM; +fontMaster = ( +{ +id = regular; +weightValue = 40; +}, +{ +id = "medium"; +weightValue = 50; +}, +{ +id = "bold"; +weightValue = 70; +} +); + +glyphs = ( +{ +glyphname = space; +layers = ( +{ +layerId = regular; +width = 200; +}, +{ +layerId = medium; +width = 400; +}, +{ +layerId = "bold"; +width = 600; +} +); +unicode = 0020; +} +); +unitsPerEm = 1000; +}