From b847769292aca13345fd1facae35aaf999198ad4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 5 Jul 2019 13:52:09 -0700 Subject: [PATCH] [font] Keep font-space to user-space multiplier Part of https://github.com/harfbuzz/harfbuzz/issues/1801 --- src/hb-font.cc | 5 +++++ src/hb-font.hh | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index 5727247..9cd5011 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -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 (); } /** diff --git a/src/hb-font.hh b/src/hb-font.hh index d807874..e379f12 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -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 (); -- 2.7.4