diff --git a/Cargo.toml b/Cargo.toml index 9739b07f..de44df47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,3 +53,9 @@ members = [ "otl-normalizer", "fontc_crater", ] + +[patch.crates-io] +write-fonts = { git = "https://github.com/daltonmaag/fontations.git", branch = "conditional-gvar-intermediates" } +skrifa = { git = "https://github.com/daltonmaag/fontations.git", branch = "conditional-gvar-intermediates" } +read-fonts = { git = "https://github.com/daltonmaag/fontations.git", branch = "conditional-gvar-intermediates" } +font-types = { git = "https://github.com/daltonmaag/fontations.git", branch = "conditional-gvar-intermediates" } \ No newline at end of file diff --git a/fontbe/src/gvar.rs b/fontbe/src/gvar.rs index 0e5ed7ee..eb70e1eb 100644 --- a/fontbe/src/gvar.rs +++ b/fontbe/src/gvar.rs @@ -86,10 +86,7 @@ impl Work for GvarWork { mod tests { use fontir::ir::GlyphOrder; use write_fonts::{ - tables::{ - gvar::{GlyphDelta, GlyphDeltas}, - variations::Tuple, - }, + tables::gvar::{AxisCoordinates, GlyphDelta, GlyphDeltas}, types::F2Dot14, }; @@ -110,9 +107,8 @@ mod tests { v if v == glyph_without_var => Vec::new(), // At the maximum extent (normalized pos 1.0) of our axis, add +1, +1 v if v == glyph_with_var => vec![GlyphDeltas::new( - Tuple::new(vec![F2Dot14::from_f32(1.0)]), + vec![AxisCoordinates::new(F2Dot14::from_f32(1.0), None)], vec![GlyphDelta::new(1, 1, false)], - None, )], v => panic!("unexpected {v}"), } diff --git a/fontbe/src/orchestration.rs b/fontbe/src/orchestration.rs index eb86ec21..f49fc07f 100644 --- a/fontbe/src/orchestration.rs +++ b/fontbe/src/orchestration.rs @@ -30,7 +30,6 @@ use fontir::{ }, variations::VariationRegion, }; -use log::trace; use ordered_float::OrderedFloat; use serde::{Deserialize, Serialize}; @@ -59,10 +58,9 @@ use write_fonts::{ os2::Os2, post::Post, stat::Stat, - variations::Tuple, vhea::Vhea, }, - types::{F2Dot14, GlyphId16, Tag}, + types::{GlyphId16, Tag}, validate::Validate, FontWrite, }; @@ -385,9 +383,13 @@ impl GvarFragment { return None; } - let tuple_builder = TupleBuilder::new(region, axis_order); - let (min, peak, max) = tuple_builder.build(); - Some(GlyphDeltas::new(peak, deltas.clone(), Some((min, max)))) + let coordinates = axis_order + .iter() + .map(|axis| *region.get(axis).unwrap()) + .map(Into::into) + .collect(); + + Some(GlyphDeltas::new(coordinates, deltas.clone())) }) .collect() } @@ -409,40 +411,6 @@ impl Persistable for GvarFragment { } } -/// -#[derive(Debug, Default)] -struct TupleBuilder { - axes: Vec, - min: Vec, - peak: Vec, - max: Vec, -} - -impl TupleBuilder { - fn new(region: &VariationRegion, axis_order: &[Tag]) -> Self { - let mut builder = TupleBuilder::default(); - for tag in axis_order { - let tent = region.get(tag).unwrap(); - builder.axes.push(*tag); - builder.min.push(F2Dot14::from_f32(tent.min.to_f64() as _)); - builder - .peak - .push(F2Dot14::from_f32(tent.peak.to_f64() as _)); - builder.max.push(F2Dot14::from_f32(tent.max.to_f64() as _)); - } - trace!("{builder:?}"); - builder - } - - fn build(self) -> (Tuple, Tuple, Tuple) { - ( - Tuple::new(self.min), - Tuple::new(self.peak), - Tuple::new(self.max), - ) - } -} - /// Marks, ready to feed to fea-rs in the form it expects #[derive(Default, Clone, Serialize, Deserialize, PartialEq)] pub struct FeaRsMarks { diff --git a/fontir/src/variations.rs b/fontir/src/variations.rs index 1cc62420..7f0dd7ef 100644 --- a/fontir/src/variations.rs +++ b/fontir/src/variations.rs @@ -15,7 +15,7 @@ use ordered_float::OrderedFloat; use serde::{Deserialize, Serialize}; use thiserror::Error; use write_fonts::{ - tables::variations::RegionAxisCoordinates, + tables::{gvar, variations::RegionAxisCoordinates}, types::{F2Dot14, Tag}, }; @@ -590,7 +590,7 @@ impl VariationRegion { /// /// Visualize as a tent of influence, starting at min, peaking at peak, /// and dropping off to zero at max. -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] pub struct Tent { pub min: NormalizedCoord, pub peak: NormalizedCoord, @@ -677,6 +677,16 @@ impl From<(f64, f64, f64)> for Tent { } } +impl From for gvar::AxisCoordinates { + fn from(val: Tent) -> Self { + let Tent { peak, min, max } = val; + gvar::AxisCoordinates::new( + peak.into(), + Some(gvar::Intermediate::explicit(min.into(), max.into())), + ) + } +} + /// Split space into regions. /// /// VariationModel::_locationsToRegions in Python. @@ -756,7 +766,7 @@ fn master_influence(axis_order: &[Tag], regions: &[VariationRegion]) -> Vec {