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 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
16 changes: 11 additions & 5 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,14 @@ impl CustomParameters {
}

fn panose(&self) -> Option<&Vec<i64>> {
let Some(CustomParameterValue::Panose(values)) = self.get("panose") else {
return None;
};
Some(values)
// PANOSE custom parameter is accessible under a short name and a long name:
// https://github.com/googlefonts/glyphsLib/blob/050ef62c/Lib/glyphsLib/builder/custom_params.py#L322-L323
// ...with the value under the short name taking precendence:
// https://github.com/googlefonts/glyphsLib/blob/050ef62c/Lib/glyphsLib/builder/custom_params.py#L258-L269
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 +573,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
29 changes: 26 additions & 3 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ mod tests {
};
use glyphs_reader::{glyphdata::Category, Font};
use indexmap::IndexSet;
use ir::{test_helpers::Round2, Panose};
use ir::test_helpers::Round2;
use write_fonts::types::{NameId, Tag};

use crate::source::names;
Expand Down Expand Up @@ -1966,8 +1966,31 @@ mod tests {

#[test]
fn captures_panose() {
// 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!(
Some([2, 0, 5, 3, 6, 0, 0, 2, 0, 3].into()),
context.static_metadata.get().misc.panose
);
}

#[test]
fn captures_panose_long() {
// 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!(
Some([2, 0, 5, 3, 6, 0, 0, 2, 0, 3].into()),
context.static_metadata.get().misc.panose
);
}

#[test]
fn captures_panose_precedence() {
// both parameters; value under short name should be preferred
let (_, context) = build_static_metadata(glyphs3_dir().join("WghtVarPanoseBoth.glyphs"));
assert_eq!(
Some([2, 0, 5, 3, 6, 0, 0, 2, 0, 3].into()),
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