[font] Fix undefined-behavior when scales are negative
Fixes https://github.com/harfbuzz/harfbuzz/issues/3555
diff --git a/src/hb-font.hh b/src/hb-font.hh
index 952beab..abc8bb3 100644
--- a/src/hb-font.hh
+++ b/src/hb-font.hh
@@ -631,8 +631,10 @@
void mults_changed ()
{
signed upem = face->get_upem ();
- x_mult = ((int64_t) x_scale << 16) / upem;
- y_mult = ((int64_t) y_scale << 16) / upem;
+ bool x_neg = x_scale < 0;
+ x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) / upem;
+ bool y_neg = y_scale < 0;
+ y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) / upem;
slant_xy = y_scale ? slant * x_scale / y_scale : 0.f;
}