diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-18 00:43:49 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-18 00:43:49 +0200 |
commit | 09d1ebb7aed4de4cc63e88d8e89a56c647b0d902 (patch) | |
tree | 6554636c35a6a81e7be73b9ef72fcdc8496fc3be /thirdparty/harfbuzz/src/hb-ft.cc | |
parent | 04082597f90dcb624c6466a7e1f173489a8ec517 (diff) | |
parent | ec8084d87f273266c5d79d06c421b5167dd97f94 (diff) |
Merge pull request #66004 from bruvzg/hb52
Update to version 5.2.0, add new Unicode 15 blocks and scripts.
Diffstat (limited to 'thirdparty/harfbuzz/src/hb-ft.cc')
-rw-r--r-- | thirdparty/harfbuzz/src/hb-ft.cc | 101 |
1 files changed, 69 insertions, 32 deletions
diff --git a/thirdparty/harfbuzz/src/hb-ft.cc b/thirdparty/harfbuzz/src/hb-ft.cc index ef073475cb..bcc1dd080f 100644 --- a/thirdparty/harfbuzz/src/hb-ft.cc +++ b/thirdparty/harfbuzz/src/hb-ft.cc @@ -80,16 +80,19 @@ */ +using hb_ft_advance_cache_t = hb_cache_t<16, 24, 8, false>; + struct hb_ft_font_t { int load_flags; bool symbol; /* Whether selected cmap is symbol cmap. */ bool unref; /* Whether to destroy ft_face when done. */ + bool transform; /* Whether to apply FT_Face's transform. */ mutable hb_mutex_t lock; FT_Face ft_face; mutable unsigned cached_serial; - mutable hb_advance_cache_t advance_cache; + mutable hb_ft_advance_cache_t advance_cache; }; static hb_ft_font_t * @@ -136,6 +139,8 @@ _hb_ft_font_destroy (void *data) /* hb_font changed, update FT_Face. */ static void _hb_ft_hb_font_changed (hb_font_t *font, FT_Face ft_face) { + hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data; + float x_mult = 1.f, y_mult = 1.f; if (font->x_scale < 0) x_mult = -x_mult; @@ -173,6 +178,7 @@ static void _hb_ft_hb_font_changed (hb_font_t *font, FT_Face ft_face) FT_Matrix matrix = { (int) roundf (x_mult * (1<<16)), 0, 0, (int) roundf (y_mult * (1<<16))}; FT_Set_Transform (ft_face, &matrix, nullptr); + ft_font->transform = true; } #if defined(HAVE_FT_GET_VAR_BLEND_COORDINATES) && !defined(HB_NO_VAR) @@ -428,13 +434,19 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; int load_flags = ft_font->load_flags; + float x_mult; #ifdef HAVE_FT_GET_TRANSFORM - FT_Matrix matrix; - FT_Get_Transform (ft_face, &matrix, nullptr); - float mult = matrix.xx / 65536.f; -#else - float mult = font->x_scale < 0 ? -1 : +1; + if (ft_font->transform) + { + FT_Matrix matrix; + FT_Get_Transform (ft_face, &matrix, nullptr); + x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f; + } + else #endif + { + x_mult = font->x_scale < 0 ? -1 : +1; + } for (unsigned int i = 0; i < count; i++) { @@ -450,7 +462,7 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, ft_font->advance_cache.set (glyph, v); } - *first_advance = (int) (v * mult + (1<<9)) >> 10; + *first_advance = (int) (v * x_mult + (1<<9)) >> 10; first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); } @@ -466,13 +478,19 @@ hb_ft_get_glyph_v_advance (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Fixed v; + float y_mult; #ifdef HAVE_FT_GET_TRANSFORM - FT_Matrix matrix; - FT_Get_Transform (ft_font->ft_face, &matrix, nullptr); - float y_mult = matrix.yy / 65536.f; -#else - float y_mult = font->y_scale < 0 ? -1 : +1; + if (ft_font->transform) + { + FT_Matrix matrix; + FT_Get_Transform (ft_font->ft_face, &matrix, nullptr); + y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f; + } + else #endif + { + y_mult = font->y_scale < 0 ? -1 : +1; + } if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags | FT_LOAD_VERTICAL_LAYOUT, &v))) return 0; @@ -498,15 +516,21 @@ hb_ft_get_glyph_v_origin (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; + float x_mult, y_mult; #ifdef HAVE_FT_GET_TRANSFORM - FT_Matrix matrix; - FT_Get_Transform (ft_face, &matrix, nullptr); - float x_mult = matrix.xx / 65536.f; - float y_mult = matrix.yy / 65536.f; -#else - float x_mult = font->x_scale < 0 ? -1 : +1; - float y_mult = font->y_scale < 0 ? -1 : +1; + if (ft_font->transform) + { + FT_Matrix matrix; + FT_Get_Transform (ft_face, &matrix, nullptr); + x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f; + y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f; + } + else #endif + { + x_mult = font->x_scale < 0 ? -1 : +1; + y_mult = font->y_scale < 0 ? -1 : +1; + } if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags))) return false; @@ -553,15 +577,21 @@ hb_ft_get_glyph_extents (hb_font_t *font, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; + float x_mult, y_mult; #ifdef HAVE_FT_GET_TRANSFORM - FT_Matrix matrix; - FT_Get_Transform (ft_face, &matrix, nullptr); - float x_mult = matrix.xx / 65536.f; - float y_mult = matrix.yy / 65536.f; -#else - float x_mult = font->x_scale < 0 ? -1 : +1; - float y_mult = font->y_scale < 0 ? -1 : +1; + if (ft_font->transform) + { + FT_Matrix matrix; + FT_Get_Transform (ft_face, &matrix, nullptr); + x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f; + y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f; + } + else #endif + { + x_mult = font->x_scale < 0 ? -1 : +1; + y_mult = font->y_scale < 0 ? -1 : +1; + } if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags))) return false; @@ -663,13 +693,19 @@ hb_ft_get_font_h_extents (hb_font_t *font HB_UNUSED, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; + float y_mult; #ifdef HAVE_FT_GET_TRANSFORM - FT_Matrix matrix; - FT_Get_Transform (ft_face, &matrix, nullptr); - float y_mult = matrix.yy / 65536.f; -#else - float y_mult = font->y_scale < 0 ? -1 : +1; + if (ft_font->transform) + { + FT_Matrix matrix; + FT_Get_Transform (ft_face, &matrix, nullptr); + y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f; + } + else #endif + { + y_mult = font->y_scale < 0 ? -1 : +1; + } if (ft_face->units_per_EM != 0) { @@ -1233,13 +1269,14 @@ hb_ft_font_set_funcs (hb_font_t *font) if (FT_Select_Charmap (ft_face, FT_ENCODING_MS_SYMBOL)) FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE); - _hb_ft_hb_font_changed (font, ft_face); ft_face->generic.data = blob; ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob; _hb_ft_font_set_funcs (font, ft_face, true); hb_ft_font_set_load_flags (font, FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING); + + _hb_ft_hb_font_changed (font, ft_face); } |