Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
helper method in cvar for delta accumulation
  • Loading branch information
dfrg committed Mar 15, 2024
1 parent 9272757 commit 64e9e8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
27 changes: 27 additions & 0 deletions read-fonts/src/tables/cvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 1 addition & 10 deletions skrifa/src/outline/glyf/hint/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64e9e8f

Please sign in to comment.