Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed May 30, 2024
1 parent c266e0f commit 464f554
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions write-fonts/src/tables/gvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum GvarInputError {
UnexpectedAxisCount {
gid: GlyphId,
expected: u16,
got: u16,
actual: u16,
},
/// A single glyph contains variations with inconsistent axis counts
InconsistentGlyphAxisCount(GlyphId),
Expand Down Expand Up @@ -99,16 +99,15 @@ impl Gvar {
var.validate()?;
}

for var in &variations {
if let Some(x) = var.axis_count() {
if x != axis_count {
return Err(GvarInputError::UnexpectedAxisCount {
gid: var.gid,
expected: axis_count,
got: x,
});
}
}
if let Some(bad_var) = variations
.iter()
.find(|var| var.axis_count().is_some() && var.axis_count().unwrap() != axis_count)
{
return Err(GvarInputError::UnexpectedAxisCount {
gid: bad_var.gid,
expected: axis_count,
actual: bad_var.axis_count().unwrap(),
});
}

let shared = compute_shared_peak_tuples(&variations);
Expand Down Expand Up @@ -643,11 +642,15 @@ impl FontWrite for TupleVariationCount {
impl std::fmt::Display for GvarInputError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GvarInputError::UnexpectedAxisCount { gid, expected, got } => {
GvarInputError::UnexpectedAxisCount {
gid,
expected,
actual,
} => {
write!(
f,
"Expected {} axes for glyph {}, got {}",
expected, gid, got
expected, gid, actual
)
}
GvarInputError::InconsistentGlyphAxisCount(gid) => write!(
Expand Down Expand Up @@ -1321,7 +1324,7 @@ mod tests {
Err(GvarInputError::UnexpectedAxisCount {
gid: GlyphId::NOTDEF,
expected: 2,
got: 1
actual: 1
})
));
}
Expand Down

0 comments on commit 464f554

Please sign in to comment.