[ft] Try working around fonts with transform set

Fixes https://github.com/harfbuzz/harfbuzz/issues/3772
pull/3773/head
Behdad Esfahbod 2 years ago
parent 04d28d94e5
commit ba9b20534c
  1. 2
      src/hb-buffer.h
  2. 18
      src/hb-ft.cc

@ -145,7 +145,7 @@ typedef struct hb_glyph_info_t {
* @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL: In scripts that use elongation (Arabic, * @HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL: In scripts that use elongation (Arabic,
Mongolian, Syriac, etc.), this flag signifies Mongolian, Syriac, etc.), this flag signifies
that it is safe to insert a U+0640 TATWEEL that it is safe to insert a U+0640 TATWEEL
character *before* this cluster for elongation. character before this cluster for elongation.
This flag does not determine the This flag does not determine the
script-specific elongation places, but only script-specific elongation places, but only
when it is safe to do the elongation without when it is safe to do the elongation without

@ -431,9 +431,9 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
#ifdef HAVE_FT_GET_TRANSFORM #ifdef HAVE_FT_GET_TRANSFORM
FT_Matrix matrix; FT_Matrix matrix;
FT_Get_Transform (ft_face, &matrix, nullptr); FT_Get_Transform (ft_face, &matrix, nullptr);
float mult = matrix.xx / 65536.f; float x_mult = sqrtf (matrix.xx * matrix.xx + matrix.xy * matrix.xy) / 65536.f;
#else #else
float mult = font->x_scale < 0 ? -1 : +1; float x_mult = font->x_scale < 0 ? -1 : +1;
#endif #endif
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
@ -450,7 +450,7 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
ft_font->advance_cache.set (glyph, v); 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_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
} }
@ -469,7 +469,7 @@ hb_ft_get_glyph_v_advance (hb_font_t *font,
#ifdef HAVE_FT_GET_TRANSFORM #ifdef HAVE_FT_GET_TRANSFORM
FT_Matrix matrix; FT_Matrix matrix;
FT_Get_Transform (ft_font->ft_face, &matrix, nullptr); FT_Get_Transform (ft_font->ft_face, &matrix, nullptr);
float y_mult = matrix.yy / 65536.f; float y_mult = sqrtf (matrix.yx * matrix.yx + matrix.yy * matrix.yy) / 65536.f;
#else #else
float y_mult = font->y_scale < 0 ? -1 : +1; float y_mult = font->y_scale < 0 ? -1 : +1;
#endif #endif
@ -501,8 +501,8 @@ hb_ft_get_glyph_v_origin (hb_font_t *font,
#ifdef HAVE_FT_GET_TRANSFORM #ifdef HAVE_FT_GET_TRANSFORM
FT_Matrix matrix; FT_Matrix matrix;
FT_Get_Transform (ft_face, &matrix, nullptr); FT_Get_Transform (ft_face, &matrix, nullptr);
float x_mult = matrix.xx / 65536.f; float x_mult = sqrtf (matrix.xx * matrix.xx + matrix.xy * matrix.xy) / 65536.f;
float y_mult = matrix.yy / 65536.f; float y_mult = sqrtf (matrix.yx * matrix.yx + matrix.yy * matrix.yy) / 65536.f;
#else #else
float x_mult = font->x_scale < 0 ? -1 : +1; float x_mult = font->x_scale < 0 ? -1 : +1;
float y_mult = font->y_scale < 0 ? -1 : +1; float y_mult = font->y_scale < 0 ? -1 : +1;
@ -556,8 +556,8 @@ hb_ft_get_glyph_extents (hb_font_t *font,
#ifdef HAVE_FT_GET_TRANSFORM #ifdef HAVE_FT_GET_TRANSFORM
FT_Matrix matrix; FT_Matrix matrix;
FT_Get_Transform (ft_face, &matrix, nullptr); FT_Get_Transform (ft_face, &matrix, nullptr);
float x_mult = matrix.xx / 65536.f; float x_mult = sqrtf (matrix.xx * matrix.xx + matrix.xy * matrix.xy) / 65536.f;
float y_mult = matrix.yy / 65536.f; float y_mult = sqrtf (matrix.yx * matrix.yx + matrix.yy * matrix.yy) / 65536.f;
#else #else
float x_mult = font->x_scale < 0 ? -1 : +1; float x_mult = font->x_scale < 0 ? -1 : +1;
float y_mult = font->y_scale < 0 ? -1 : +1; float y_mult = font->y_scale < 0 ? -1 : +1;
@ -666,7 +666,7 @@ hb_ft_get_font_h_extents (hb_font_t *font HB_UNUSED,
#ifdef HAVE_FT_GET_TRANSFORM #ifdef HAVE_FT_GET_TRANSFORM
FT_Matrix matrix; FT_Matrix matrix;
FT_Get_Transform (ft_face, &matrix, nullptr); FT_Get_Transform (ft_face, &matrix, nullptr);
float y_mult = matrix.yy / 65536.f; float y_mult = sqrtf (matrix.yx * matrix.yx + matrix.yy * matrix.yy) / 65536.f;
#else #else
float y_mult = font->y_scale < 0 ? -1 : +1; float y_mult = font->y_scale < 0 ? -1 : +1;
#endif #endif

Loading…
Cancel
Save