Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose and fix mistranslation from python that can lead to bad avar #1180

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading