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

Support long parameter name for PANOSE, to match glyphsLib #1102

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ impl CustomParameters {
}

fn panose(&self) -> Option<&Vec<i64>> {
let Some(CustomParameterValue::Panose(values)) = self.get("panose") else {
return None;
};
Some(values)
match self.get("panose").or_else(|| self.get("openTypeOS2Panose")) {
rsheeter marked this conversation as resolved.
Show resolved Hide resolved
Some(CustomParameterValue::Panose(values)) => Some(values),
_ => None,
}
}
}

Expand Down Expand Up @@ -569,7 +569,9 @@ impl FromPlist for CustomParameters {
value =
Some(CustomParameterValue::CodepageRange(tokenizer.parse()?));
}
_ if name == Some(String::from("panose")) => {
_ if name == Some(String::from("panose"))
|| name == Some(String::from("openTypeOS2Panose")) =>
{
let Token::OpenParen = peek else {
return Err(Error::UnexpectedChar('('));
};
Expand Down
14 changes: 12 additions & 2 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,18 @@ mod tests {

#[test]
fn captures_panose() {
let expected: Option<Panose> = Some([2, 0, 5, 3, 6, 0, 0, 2, 0, 3].into());

// short parameter name
let (_, context) = build_static_metadata(glyphs3_dir().join("WghtVarPanose.glyphs"));
let expected: Panose = [2, 0, 5, 3, 6, 0, 0, 2, 0, 3].into();
assert_eq!(Some(expected), context.static_metadata.get().misc.panose);
assert_eq!(expected, context.static_metadata.get().misc.panose);

// long parameter name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make these separate tests instead of having one test that does three seperable checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good shout - I've split them now

let (_, context) = build_static_metadata(glyphs3_dir().join("WghtVarPanoseLong.glyphs"));
assert_eq!(expected, context.static_metadata.get().misc.panose);

// both parameters; value under short name should be preferred
let (_, context) = build_static_metadata(glyphs3_dir().join("WghtVarPanoseBoth.glyphs"));
assert_eq!(expected, context.static_metadata.get().misc.panose);
}
}
58 changes: 58 additions & 0 deletions resources/testdata/glyphs3/WghtVarPanoseBoth.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
.formatVersion = 3;
customParameters = (
{
name = panose;
value = (
2,
0,
5,
3,
6,
0,
0,
2,
0,
3
);
},
{
name = openTypeOS2Panose;
value = (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
);
}
);
familyName = WghtVar;
fontMaster = (
{
id = m01;
name = Regular;
}
);
glyphs = (
{
glyphname = space;
layers = (
{
layerId = m01;
width = 200;
}
);
unicode = 32;
}
);

unitsPerEm = 1234;
versionMajor = 42;
versionMinor = 42;
}
43 changes: 43 additions & 0 deletions resources/testdata/glyphs3/WghtVarPanoseLong.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
.formatVersion = 3;
customParameters = (
{
name = openTypeOS2Panose;
value = (
2,
0,
5,
3,
6,
0,
0,
2,
0,
3
);
}
);
familyName = WghtVar;
fontMaster = (
{
id = m01;
name = Regular;
}
);
glyphs = (
{
glyphname = space;
layers = (
{
layerId = m01;
width = 200;
}
);
unicode = 32;
}
);

unitsPerEm = 1234;
versionMajor = 42;
versionMinor = 42;
}
Loading