Skip to content

Commit

Permalink
Merge pull request #1102 from Hoolean/extra-panose-param
Browse files Browse the repository at this point in the history
Support long parameter name for PANOSE, to match glyphsLib
  • Loading branch information
rsheeter authored Nov 7, 2024
2 parents 825bda4 + f5e25f3 commit 9b7a563
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 8 deletions.
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")) {
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
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;
}

0 comments on commit 9b7a563

Please sign in to comment.