Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[read-fonts] revert midpoint change to match FT #1294

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions read-fonts/src/tables/glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,14 @@ impl PointCoord for i32 {
}

// Midpoint function that avoids overflow on large values.
#[inline(always)]
fn midpoint_i32(a: i32, b: i32) -> i32 {
// Original overflowing code was: (a + b) / 2
// Choose wrapping arithmetic here because we shouldn't ever
// hit this outside of fuzzing or broken fonts _and_ this is
// called from the outline to path conversion code which is
// very performance sensitive
a.wrapping_add(b.wrapping_sub(a) / 2)
a.wrapping_add(b) / 2
}

impl PointCoord for f32 {
Expand Down Expand Up @@ -1041,7 +1042,7 @@ mod tests {
fn avoid_midpoint_overflow() {
let a = F26Dot6::from_bits(1084092352);
let b = F26Dot6::from_bits(1085243712);
let expected = a.to_bits() + (b.to_bits() - a.to_bits()) / 2;
let expected = (a + b).to_bits() / 2;
// Don't panic!
let midpoint = a.midpoint(b);
assert_eq!(midpoint.to_bits(), expected);
Expand Down
Loading