Skip to content

Commit

Permalink
Prefer default master panose
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Dec 3, 2024
1 parent c1ebad0 commit d72657c
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 11 deletions.
1 change: 1 addition & 0 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ impl RawCustomParameters {
_ => log::warn!("unknown custom parameter '{name}'"),
}
}
eprintln!("panose {:?}\npanose_old {:?}", panose, panose_old);
params.panose = panose.or(panose_old);
params.virtual_masters = Some(virtual_masters).filter(|x| !x.is_empty());
Ok(params)
Expand Down
31 changes: 20 additions & 11 deletions glyphs2fontir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use fontir::{
error::{BadGlyph, BadGlyphKind, BadSource, Error},
ir::{
self, AnchorBuilder, GdefCategories, GlobalMetric, GlobalMetrics, GlyphInstance,
GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance, MetaTableValues,
NameBuilder, NameKey, NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID,
GlyphOrder, KernGroup, KernSide, KerningGroups, KerningInstance, NameBuilder, NameKey,
NamedInstance, StaticMetadata, DEFAULT_VENDOR_ID,
},
orchestration::{Context, IrWork, WorkId},
source::{Input, Source},
Expand Down Expand Up @@ -468,7 +468,13 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
.as_ref()
.map(|bits| bits.iter().copied().collect());

if let Some(raw_panose) = font.custom_parameters.panose.as_ref() {
if let Some(raw_panose) = font
.default_master()
.custom_parameters
.panose
.as_ref()
.or(font.custom_parameters.panose.as_ref())
{
let mut bytes = [0u8; 10];
bytes
.iter_mut()
Expand Down Expand Up @@ -496,13 +502,6 @@ impl Work<Context, WorkId, Error> for StaticMetadataWork {
})
.or(static_metadata.misc.created);

if let Some(meta_table) = &font.custom_parameters.meta_table {
static_metadata.misc.meta_table = Some(MetaTableValues {
dlng: meta_table.dlng.clone(),
slng: meta_table.slng.clone(),
});
}

context.static_metadata.set(static_metadata);

let glyph_order = font
Expand Down Expand Up @@ -1051,7 +1050,7 @@ mod tests {
};
use glyphs_reader::{glyphdata::Category, Font};
use indexmap::IndexSet;
use ir::test_helpers::Round2;
use ir::{test_helpers::Round2, Panose};
use write_fonts::types::{NameId, Tag};

use crate::source::names;
Expand Down Expand Up @@ -1965,4 +1964,14 @@ mod tests {
let static_metadata = context.static_metadata.get();
assert_eq!(Tag::new(b"RGHT"), static_metadata.misc.vendor_id);
}

#[test]
fn prefer_default_master_panose() {
let (_, context) = build_static_metadata(glyphs3_dir().join("MultiplePanose.glyphs"));
let static_metadata = context.static_metadata.get();
assert_eq!(
Some(Panose::from([2u8, 3, 4, 5, 6, 7, 8, 9, 10, 11])),
static_metadata.misc.panose
);
}
}
99 changes: 99 additions & 0 deletions resources/testdata/glyphs3/MultiplePanose.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
.formatVersion = 3;
axes = (
{
name = Weight;
tag = wght;
}
);

customParameters = (
{
name = panose;
value = (
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
);
}
);

familyName = FamilyName;
fontMaster = (
{
axesValues = (
400
);
id = m01;
name = Regular;
customParameters = (
{
name = panose;
value = (
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
);
}
);
},

{
axesValues = (
700
);
id = "E09E0C54-128D-4FEA-B209-1B70BEFE300B";
name = Bold;
customParameters = (
{
name = panose;
value = (
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
);
}
);
}
);

glyphs = (
{
glyphname = space;
layers = (
{
layerId = m01;
width = 200;
},
{
layerId = "E09E0C54-128D-4FEA-B209-1B70BEFE300B";
width = 600;
}
);
unicode = 32;
}
);
unitsPerEm = 1000;
versionMajor = 1;
}

0 comments on commit d72657c

Please sign in to comment.