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

must follow fvar axes order when building gvar GlyphDeltas #387

Merged
merged 1 commit into from
Aug 9, 2023
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
12 changes: 10 additions & 2 deletions fontbe/src/gvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,29 @@ impl Work<Context, AnyWorkId, Error> for GvarWork {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::GlyphOrder) | AnyWorkId::Be(WorkId::GvarFragment(..))
AnyWorkId::Fe(FeWorkId::StaticMetadata)
| AnyWorkId::Fe(FeWorkId::GlyphOrder)
| AnyWorkId::Be(WorkId::GvarFragment(..))
)
}))
}

/// Generate [gvar](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar)
fn exec(&self, context: &Context) -> Result<(), Error> {
// We built the gvar fragments alongside glyphs, now we need to glue them together into a gvar table
let static_metadata = context.ir.static_metadata.get();
let axis_order: Vec<_> = static_metadata
.variable_axes
.iter()
.map(|a| a.tag)
.collect();
let glyph_order = context.ir.glyph_order.get();

let variations: Vec<_> = make_variations(&glyph_order, |glyph_name| {
context
.gvar_fragments
.get(&WorkId::GvarFragment(glyph_name.clone()).into())
.to_deltas()
.to_deltas(&axis_order)
});
let gvar = Gvar::new(variations).map_err(Error::GvarError)?;

Expand Down
13 changes: 7 additions & 6 deletions fontbe/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub struct GvarFragment {
}

impl GvarFragment {
pub fn to_deltas(&self) -> Vec<GlyphDeltas> {
pub fn to_deltas(&self, axis_order: &[Tag]) -> Vec<GlyphDeltas> {
self.deltas
.iter()
.filter_map(|(region, deltas)| {
Expand All @@ -266,7 +266,7 @@ impl GvarFragment {
})
.collect();

let tuple_builder = TupleBuilder::new(region);
let tuple_builder = TupleBuilder::new(region, axis_order);
let (min, peak, max) = tuple_builder.build();
Some(GlyphDeltas::new(peak, deltas, Some((min, max))))
})
Expand Down Expand Up @@ -300,9 +300,10 @@ struct TupleBuilder {
}

impl TupleBuilder {
fn new(region: &VariationRegion) -> Self {
fn new(region: &VariationRegion, axis_order: &[Tag]) -> Self {
let mut builder = TupleBuilder::default();
for (tag, tent) in region.iter() {
for tag in axis_order {
let tent = region.get(tag).unwrap();
builder.axes.push(*tag);
builder.min.push(F2Dot14::from_f32(tent.min.to_f32()));
builder.peak.push(F2Dot14::from_f32(tent.peak.to_f32()));
Expand Down Expand Up @@ -642,7 +643,7 @@ mod tests {
vec![None, Some((1.0, 0.0).into()), None],
)],
}
.to_deltas();
.to_deltas(&[Tag::new(b"wght")]);
assert!(!deltas.is_empty(), "{deltas:?}");
}

Expand All @@ -652,7 +653,7 @@ mod tests {
glyph_name: "blah".into(),
deltas: vec![(non_default_region(), vec![None, None, None])],
}
.to_deltas();
.to_deltas(&[Tag::new(b"wght")]);
assert!(deltas.is_empty(), "{deltas:?}");
}
}
4 changes: 4 additions & 0 deletions fontir/src/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ impl VariationRegion {
pub fn is_default(&self) -> bool {
self.active_axes.is_empty()
}

pub fn get(&self, tag: &Tag) -> Option<&Tent> {
self.axis_tents.get(tag)
}
}

/// The min/peak/max of a masters influence.
Expand Down