[font] Keep font-space to user-space multiplier
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 5 Jul 2019 20:52:09 +0000 (13:52 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 5 Jul 2019 20:52:09 +0000 (13:52 -0700)
Part of https://github.com/harfbuzz/harfbuzz/issues/1801

src/hb-font.cc
src/hb-font.hh

index 5727247..9cd5011 100644 (file)
@@ -1300,6 +1300,8 @@ DEFINE_NULL_INSTANCE (hb_font_t) =
 
   1000, /* x_scale */
   1000, /* y_scale */
+  1<<16, /* x_mult */
+  1<<16, /* y_mult */
 
   0, /* x_ppem */
   0, /* y_ppem */
@@ -1330,6 +1332,7 @@ _hb_font_create (hb_face_t *face)
   font->klass = hb_font_funcs_get_empty ();
   font->data.init0 (font);
   font->x_scale = font->y_scale = hb_face_get_upem (face);
+  font->x_mult = font->y_mult = 1 << 16;
 
   return font;
 }
@@ -1603,6 +1606,7 @@ hb_font_set_face (hb_font_t *font,
 
   hb_face_make_immutable (face);
   font->face = hb_face_reference (face);
+  font->mults_changed ();
 
   hb_face_destroy (old);
 }
@@ -1712,6 +1716,7 @@ hb_font_set_scale (hb_font_t *font,
 
   font->x_scale = x_scale;
   font->y_scale = y_scale;
+  font->mults_changed ();
 }
 
 /**
index d807874..e379f12 100644 (file)
@@ -107,8 +107,10 @@ struct hb_font_t
   hb_font_t *parent;
   hb_face_t *face;
 
-  int x_scale;
-  int y_scale;
+  int32_t x_scale;
+  int32_t y_scale;
+  int64_t x_mult;
+  int64_t y_mult;
 
   unsigned int x_ppem;
   unsigned int y_ppem;
@@ -607,6 +609,13 @@ struct hb_font_t
     return false;
   }
 
+  void mults_changed ()
+  {
+    signed upem = face->get_upem ();
+    x_mult = ((int64_t) x_scale << 16) / upem;
+    y_mult = ((int64_t) y_scale << 16) / upem;
+  }
+
   hb_position_t em_scale (int16_t v, int scale)
   {
     signed upem = face->get_upem ();