Skip to content

Commit

Permalink
Only apply avar table to the variation axis being set (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmelander authored Oct 3, 2024
1 parent daa00fc commit 1cac7c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,13 +2323,11 @@ impl<'a> Face<'a> {
for (i, var_axis) in self.variation_axes().into_iter().enumerate() {
if var_axis.tag == axis {
self.coordinates.data[i] = var_axis.normalized_value(value);
}
}

// TODO: optimize
if let Some(avar) = self.tables.avar {
// Ignore error.
let _ = avar.map_coordinates(self.coordinates.as_mut_slice());
if let Some(avar) = self.tables.avar {
let _ = avar.map_coordinate(self.coordinates.as_mut_slice(), i);
}
}
}

Some(())
Expand Down
15 changes: 12 additions & 3 deletions src/tables/avar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,22 @@ impl<'a> Table<'a> {
})
}

/// Maps coordinates.
pub fn map_coordinates(&self, coordinates: &mut [NormalizedCoordinate]) -> Option<()> {
/// Maps a single coordinate
pub fn map_coordinate(
&self,
coordinates: &mut [NormalizedCoordinate],
coordinate_index: usize,
) -> Option<()> {
if usize::from(self.segment_maps.count) != coordinates.len() {
return None;
}

for (map, coord) in self.segment_maps.into_iter().zip(coordinates) {
if let Some((map, coord)) = self
.segment_maps
.into_iter()
.zip(coordinates)
.nth(coordinate_index)
{
*coord = NormalizedCoordinate::from(map_value(&map, coord.0)?);
}

Expand Down

0 comments on commit 1cac7c7

Please sign in to comment.