Skip to content

Commit

Permalink
Merge pull request #1180 from googlefonts/loc
Browse files Browse the repository at this point in the history
Expose and fix mistranslation from python that can lead to bad avar
  • Loading branch information
cmyr authored Dec 6, 2024
2 parents 1088897 + 3910135 commit 680dc0d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
20 changes: 17 additions & 3 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
);
}
}
60 changes: 60 additions & 0 deletions resources/testdata/glyphs2/MasterNotMapped.glyphs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 680dc0d

Please sign in to comment.