Skip to content

Commit

Permalink
[chore] Update write-fonts to 0.21.0
Browse files Browse the repository at this point in the history
This involves a breaking change to the VariationStoreBuilder, which in
turn requires us to tweak the FeatureProvider trait in fea-rs, but
overall fairly painless.
  • Loading branch information
cmyr committed Dec 16, 2023
1 parent b7234e9 commit a252b0f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ clap = { version = "4.0.32", features = ["derive"] }
rayon = "1.6"

# fontations etc
write-fonts = { version = "0.19.0", features = ["serde", "read"] }
skrifa = "0.14.0"
write-fonts = { version = "0.21.0", features = ["serde", "read"] }
skrifa = "0.15.0"
norad = "0.12"

# dev dependencies
Expand Down
6 changes: 5 additions & 1 deletion fea-rs/src/compile/compile_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> {

// the var store builder is required so that variable metrics/anchors
// in the GPOS table can be collected into an ItemVariationStore
let mut ivs = VariationStoreBuilder::new();
let axis_count = self
.variation_info
.map(|info| info.axis_count())
.unwrap_or_default();
let mut ivs = VariationStoreBuilder::new(axis_count);

let (mut gsub, mut gpos) = self.lookups.build(&self.features, &mut ivs);
if !ivs.is_empty() {
Expand Down
11 changes: 11 additions & 0 deletions fea-rs/src/compile/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub trait VariationInfo {
/// The error type
type Error: std::error::Error;

/// The number of axes in the fvar table
fn axis_count(&self) -> u16;

/// If the tag is an axis in this font, it's fvar index and it's [`Axis`] data.
fn axis(&self, axis_tag: Tag) -> Option<(usize, &Axis)>;

Expand Down Expand Up @@ -52,6 +55,10 @@ pub struct NopVariationInfo;
impl VariationInfo for NopVariationInfo {
type Error = NopError;

fn axis_count(&self) -> u16 {
0
}

fn axis(&self, _: Tag) -> Option<(usize, &Axis)> {
None
}
Expand Down Expand Up @@ -201,6 +208,10 @@ impl VariationInfo for MockVariationInfo {
) -> Result<(i16, Vec<(VariationRegion, i16)>), Self::Error> {
Ok(Default::default())
}

fn axis_count(&self) -> u16 {
self.axes.len().try_into().unwrap()
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ impl<'a> VariationInfo for FeaVariationInfo<'a> {

Ok((default_value, fears_deltas))
}

fn axis_count(&self) -> u16 {
self.axes.len().try_into().unwrap()
}
}

impl FeatureWork {
Expand Down
5 changes: 3 additions & 2 deletions fontbe/src/hvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl Work<Context, AnyWorkId, Error> for HvarWork {
let static_metadata = context.ir.static_metadata.get();
let var_model = &static_metadata.variation_model;
let glyph_order = context.ir.glyph_order.get();
let axis_count = var_model.axes().count().try_into().unwrap();

let mut glyph_width_deltas = AdvanceWidthDeltas::new(var_model.clone());
for name in glyph_order.iter() {
Expand All @@ -177,7 +178,7 @@ impl Work<Context, AnyWorkId, Error> for HvarWork {
// indices (a single ItemVariationData, outer index 0, inner index => gid).
let mut var_idxes = Vec::new();
let direct_store = if glyph_width_deltas.is_single_model() {
let mut direct_builder = VariationStoreBuilder::new_with_implicit_indices();
let mut direct_builder = VariationStoreBuilder::new_with_implicit_indices(axis_count);
for deltas in glyph_width_deltas.iter() {
var_idxes.push(direct_builder.add_deltas(deltas.clone()));
}
Expand All @@ -194,7 +195,7 @@ impl Work<Context, AnyWorkId, Error> for HvarWork {
};

// also build an indirect VariationStore with a DeltaSetIndexMap to map gid => varidx
let mut indirect_builder = VariationStoreBuilder::new();
let mut indirect_builder = VariationStoreBuilder::new(axis_count);
for deltas in glyph_width_deltas.iter() {
var_idxes.push(indirect_builder.add_deltas(deltas.clone()));
}
Expand Down
2 changes: 1 addition & 1 deletion layout-normalizer/src/gpos/pairpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod tests {
}

fn build_exactly_one_subtable(self) -> PairPos {
let mut varstore = VariationStoreBuilder::new();
let mut varstore = VariationStoreBuilder::new(0);
let subs = self.build(&mut varstore);
assert_eq!(subs.len(), 1);
subs.into_iter().next().unwrap()
Expand Down

0 comments on commit a252b0f

Please sign in to comment.