diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2015-08-19 13:20:31 +0100 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2015-08-19 13:20:31 +0100 |
commit | 7c5bee09d9c7c25672c7c77572ebae0b731892d0 (patch) | |
tree | 7a2cd7806c1cb2af592dfb27b2539ffd36d140ca | |
parent | 902e74a098dad8c3b487856284f9fdf99b04f9f1 (diff) | |
download | harfbuzz-7c5bee09d9c7c25672c7c77572ebae0b731892d0.tar.gz |
[uniscribe] Fix font scale handling
By default shape at upem (or ppem), and scale results.
Similar to work done in CoreText backend, but using upem as default.
-rw-r--r-- | src/hb-uniscribe.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index e7bcad2e..3a08c747 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -486,14 +486,16 @@ struct hb_uniscribe_shaper_font_data_t { LOGFONTW log_font; HFONT hfont; SCRIPT_CACHE script_cache; + double x_mult, y_mult; /* From LOGFONT space to HB space. */ }; static bool populate_log_font (LOGFONTW *lf, - hb_font_t *font) + hb_font_t *font, + unsigned int font_size) { memset (lf, 0, sizeof (*lf)); - lf->lfHeight = -font->y_scale; + lf->lfHeight = -font_size; lf->lfCharSet = DEFAULT_CHARSET; hb_face_t *face = font->face; @@ -513,9 +515,19 @@ _hb_uniscribe_shaper_font_data_create (hb_font_t *font) if (unlikely (!data)) return NULL; + int font_size = font->face->get_upem (); /* Default... */ + /* No idea if the following is even a good idea. */ + if (font->y_ppem) + font_size = font->y_ppem; + + if (font_size < 0) + font_size = -font_size; + data->x_mult = (double) font->x_scale / font_size; + data->y_mult = (double) font->y_scale / font_size; + data->hdc = GetDC (NULL); - if (unlikely (!populate_log_font (&data->log_font, font))) { + if (unlikely (!populate_log_font (&data->log_font, font, font_size))) { DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed"); _hb_uniscribe_shaper_font_data_destroy (data); return NULL; @@ -1000,15 +1012,16 @@ retry: /* Set glyph positions */ buffer->clear_positions (); + double x_mult = font_data->x_mult, y_mult = font_data->y_mult; for (unsigned int i = 0; i < glyphs_len; i++) { hb_glyph_info_t *info = &buffer->info[i]; hb_glyph_position_t *pos = &buffer->pos[i]; /* TODO vertical */ - pos->x_advance = info->mask; - pos->x_offset = backward ? -info->var1.u32 : info->var1.u32; - pos->y_offset = info->var2.u32; + pos->x_advance = x_mult * info->mask; + pos->x_offset = x_mult * (backward ? -info->var1.u32 : info->var1.u32); + pos->y_offset = y_mult * info->var2.u32; } if (backward) |