Skip to content

Commit 1cac7c7

Browse files
authored
Only apply avar table to the variation axis being set (#175)
Fixes harfbuzz/rustybuzz#136
1 parent daa00fc commit 1cac7c7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,13 +2323,11 @@ impl<'a> Face<'a> {
23232323
for (i, var_axis) in self.variation_axes().into_iter().enumerate() {
23242324
if var_axis.tag == axis {
23252325
self.coordinates.data[i] = var_axis.normalized_value(value);
2326-
}
2327-
}
23282326

2329-
// TODO: optimize
2330-
if let Some(avar) = self.tables.avar {
2331-
// Ignore error.
2332-
let _ = avar.map_coordinates(self.coordinates.as_mut_slice());
2327+
if let Some(avar) = self.tables.avar {
2328+
let _ = avar.map_coordinate(self.coordinates.as_mut_slice(), i);
2329+
}
2330+
}
23332331
}
23342332

23352333
Some(())

src/tables/avar.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,22 @@ impl<'a> Table<'a> {
114114
})
115115
}
116116

117-
/// Maps coordinates.
118-
pub fn map_coordinates(&self, coordinates: &mut [NormalizedCoordinate]) -> Option<()> {
117+
/// Maps a single coordinate
118+
pub fn map_coordinate(
119+
&self,
120+
coordinates: &mut [NormalizedCoordinate],
121+
coordinate_index: usize,
122+
) -> Option<()> {
119123
if usize::from(self.segment_maps.count) != coordinates.len() {
120124
return None;
121125
}
122126

123-
for (map, coord) in self.segment_maps.into_iter().zip(coordinates) {
127+
if let Some((map, coord)) = self
128+
.segment_maps
129+
.into_iter()
130+
.zip(coordinates)
131+
.nth(coordinate_index)
132+
{
124133
*coord = NormalizedCoordinate::from(map_value(&map, coord.0)?);
125134
}
126135

0 commit comments

Comments
 (0)