diff --git a/read-fonts/src/tables/cvar.rs b/read-fonts/src/tables/cvar.rs index 1ef669c3f..78e007c98 100644 --- a/read-fonts/src/tables/cvar.rs +++ b/read-fonts/src/tables/cvar.rs @@ -38,6 +38,33 @@ impl<'a> Cvar<'a> { }) } + /// Computes the accumulated deltas for the given set of normalized + /// coordinates and stores them in `deltas`. + /// + /// The `axis_count` parameter expects the value from the `fvar` + /// table. + /// + /// The `deltas` slice should have a length greater than or equal + /// to the number of values in the `cvt` table. The values are + /// computed in 16.16 format. + pub fn deltas( + &self, + axis_count: u16, + coords: &[F2Dot14], + deltas: &mut [i32], + ) -> Result<(), ReadError> { + let var_data = self.variation_data(axis_count)?; + for (tuple, scalar) in var_data.active_tuples_at(coords) { + for delta in tuple.deltas() { + let ix = delta.position as usize; + if let Some(value) = deltas.get_mut(ix) { + *value += delta.apply_scalar(scalar).to_bits(); + } + } + } + Ok(()) + } + fn raw_tuple_header_data(&self) -> FontData<'a> { let range = self.shape.tuple_variation_headers_byte_range(); self.data.split_off(range.start).unwrap() diff --git a/skrifa/src/outline/glyf/hint/instance.rs b/skrifa/src/outline/glyf/hint/instance.rs index ec89b517c..17f47f102 100644 --- a/skrifa/src/outline/glyf/hint/instance.rs +++ b/skrifa/src/outline/glyf/hint/instance.rs @@ -174,16 +174,7 @@ impl HintInstance { if let Some(cvar) = outlines.cvar.as_ref() { // First accumulate all the deltas in 16.16 self.cvt.resize(outlines.cvt.len(), 0); - if let Ok(var_data) = cvar.variation_data(axis_count) { - for (tuple, scalar) in var_data.active_tuples_at(coords) { - for delta in tuple.deltas() { - let ix = delta.position as usize; - if let Some(value) = self.cvt.get_mut(ix) { - *value += delta.apply_scalar(scalar).to_bits(); - } - } - } - } + let _ = cvar.deltas(axis_count, coords, &mut self.cvt); // Now add the base CVT values for (value, base_value) in self.cvt.iter_mut().zip(outlines.cvt.iter()) { // Deltas are converted from 16.16 to 26.6