[hb-ft] Only apply FT_Face's transform if we created FT_Face
Fixes https://github.com/harfbuzz/harfbuzz/issues/3788 https://github.com/harfbuzz/harfbuzz/issues/3790
This commit is contained in:
parent
4f59211762
commit
23461b7502
95
src/hb-ft.cc
95
src/hb-ft.cc
|
@ -87,6 +87,7 @@ struct hb_ft_font_t
|
||||||
int load_flags;
|
int load_flags;
|
||||||
bool symbol; /* Whether selected cmap is symbol cmap. */
|
bool symbol; /* Whether selected cmap is symbol cmap. */
|
||||||
bool unref; /* Whether to destroy ft_face when done. */
|
bool unref; /* Whether to destroy ft_face when done. */
|
||||||
|
bool transform; /* Whether to apply FT_Face's transform. */
|
||||||
|
|
||||||
mutable hb_mutex_t lock;
|
mutable hb_mutex_t lock;
|
||||||
FT_Face ft_face;
|
FT_Face ft_face;
|
||||||
|
@ -138,6 +139,8 @@ _hb_ft_font_destroy (void *data)
|
||||||
/* hb_font changed, update FT_Face. */
|
/* hb_font changed, update FT_Face. */
|
||||||
static void _hb_ft_hb_font_changed (hb_font_t *font, FT_Face 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;
|
float x_mult = 1.f, y_mult = 1.f;
|
||||||
|
|
||||||
if (font->x_scale < 0) x_mult = -x_mult;
|
if (font->x_scale < 0) x_mult = -x_mult;
|
||||||
|
@ -175,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,
|
FT_Matrix matrix = { (int) roundf (x_mult * (1<<16)), 0,
|
||||||
0, (int) roundf (y_mult * (1<<16))};
|
0, (int) roundf (y_mult * (1<<16))};
|
||||||
FT_Set_Transform (ft_face, &matrix, nullptr);
|
FT_Set_Transform (ft_face, &matrix, nullptr);
|
||||||
|
ft_font->transform = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_FT_GET_VAR_BLEND_COORDINATES) && !defined(HB_NO_VAR)
|
#if defined(HAVE_FT_GET_VAR_BLEND_COORDINATES) && !defined(HB_NO_VAR)
|
||||||
|
@ -430,13 +434,19 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
|
||||||
hb_lock_t lock (ft_font->lock);
|
hb_lock_t lock (ft_font->lock);
|
||||||
FT_Face ft_face = ft_font->ft_face;
|
FT_Face ft_face = ft_font->ft_face;
|
||||||
int load_flags = ft_font->load_flags;
|
int load_flags = ft_font->load_flags;
|
||||||
|
float x_mult;
|
||||||
#ifdef HAVE_FT_GET_TRANSFORM
|
#ifdef HAVE_FT_GET_TRANSFORM
|
||||||
FT_Matrix matrix;
|
if (ft_font->transform)
|
||||||
FT_Get_Transform (ft_face, &matrix, nullptr);
|
{
|
||||||
float x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
FT_Matrix matrix;
|
||||||
#else
|
FT_Get_Transform (ft_face, &matrix, nullptr);
|
||||||
float x_mult = font->x_scale < 0 ? -1 : +1;
|
x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
x_mult = font->x_scale < 0 ? -1 : +1;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
|
@ -468,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;
|
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
|
||||||
hb_lock_t lock (ft_font->lock);
|
hb_lock_t lock (ft_font->lock);
|
||||||
FT_Fixed v;
|
FT_Fixed v;
|
||||||
|
float y_mult;
|
||||||
#ifdef HAVE_FT_GET_TRANSFORM
|
#ifdef HAVE_FT_GET_TRANSFORM
|
||||||
FT_Matrix matrix;
|
if (ft_font->transform)
|
||||||
FT_Get_Transform (ft_font->ft_face, &matrix, nullptr);
|
{
|
||||||
float y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
FT_Matrix matrix;
|
||||||
#else
|
FT_Get_Transform (ft_font->ft_face, &matrix, nullptr);
|
||||||
float y_mult = font->y_scale < 0 ? -1 : +1;
|
y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#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)))
|
if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags | FT_LOAD_VERTICAL_LAYOUT, &v)))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -500,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;
|
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
|
||||||
hb_lock_t lock (ft_font->lock);
|
hb_lock_t lock (ft_font->lock);
|
||||||
FT_Face ft_face = ft_font->ft_face;
|
FT_Face ft_face = ft_font->ft_face;
|
||||||
|
float x_mult, y_mult;
|
||||||
#ifdef HAVE_FT_GET_TRANSFORM
|
#ifdef HAVE_FT_GET_TRANSFORM
|
||||||
FT_Matrix matrix;
|
if (ft_font->transform)
|
||||||
FT_Get_Transform (ft_face, &matrix, nullptr);
|
{
|
||||||
float x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
FT_Matrix matrix;
|
||||||
float y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
FT_Get_Transform (ft_face, &matrix, nullptr);
|
||||||
#else
|
x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
||||||
float x_mult = font->x_scale < 0 ? -1 : +1;
|
y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
||||||
float y_mult = font->y_scale < 0 ? -1 : +1;
|
}
|
||||||
|
else
|
||||||
#endif
|
#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)))
|
if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags)))
|
||||||
return false;
|
return false;
|
||||||
|
@ -555,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;
|
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
|
||||||
hb_lock_t lock (ft_font->lock);
|
hb_lock_t lock (ft_font->lock);
|
||||||
FT_Face ft_face = ft_font->ft_face;
|
FT_Face ft_face = ft_font->ft_face;
|
||||||
|
float x_mult, y_mult;
|
||||||
#ifdef HAVE_FT_GET_TRANSFORM
|
#ifdef HAVE_FT_GET_TRANSFORM
|
||||||
FT_Matrix matrix;
|
if (ft_font->transform)
|
||||||
FT_Get_Transform (ft_face, &matrix, nullptr);
|
{
|
||||||
float x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
FT_Matrix matrix;
|
||||||
float y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
FT_Get_Transform (ft_face, &matrix, nullptr);
|
||||||
#else
|
x_mult = sqrtf ((float)matrix.xx * matrix.xx + (float)matrix.xy * matrix.xy) / 65536.f;
|
||||||
float x_mult = font->x_scale < 0 ? -1 : +1;
|
y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
||||||
float y_mult = font->y_scale < 0 ? -1 : +1;
|
}
|
||||||
|
else
|
||||||
#endif
|
#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)))
|
if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags)))
|
||||||
return false;
|
return false;
|
||||||
|
@ -665,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;
|
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
|
||||||
hb_lock_t lock (ft_font->lock);
|
hb_lock_t lock (ft_font->lock);
|
||||||
FT_Face ft_face = ft_font->ft_face;
|
FT_Face ft_face = ft_font->ft_face;
|
||||||
|
float y_mult;
|
||||||
#ifdef HAVE_FT_GET_TRANSFORM
|
#ifdef HAVE_FT_GET_TRANSFORM
|
||||||
FT_Matrix matrix;
|
if (ft_font->transform)
|
||||||
FT_Get_Transform (ft_face, &matrix, nullptr);
|
{
|
||||||
float y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
FT_Matrix matrix;
|
||||||
#else
|
FT_Get_Transform (ft_face, &matrix, nullptr);
|
||||||
float y_mult = font->y_scale < 0 ? -1 : +1;
|
y_mult = sqrtf ((float)matrix.yx * matrix.yx + (float)matrix.yy * matrix.yy) / 65536.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
y_mult = font->y_scale < 0 ? -1 : +1;
|
||||||
|
}
|
||||||
|
|
||||||
if (ft_face->units_per_EM != 0)
|
if (ft_face->units_per_EM != 0)
|
||||||
{
|
{
|
||||||
|
@ -1235,13 +1269,14 @@ hb_ft_font_set_funcs (hb_font_t *font)
|
||||||
if (FT_Select_Charmap (ft_face, FT_ENCODING_MS_SYMBOL))
|
if (FT_Select_Charmap (ft_face, FT_ENCODING_MS_SYMBOL))
|
||||||
FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE);
|
FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE);
|
||||||
|
|
||||||
_hb_ft_hb_font_changed (font, ft_face);
|
|
||||||
|
|
||||||
ft_face->generic.data = blob;
|
ft_face->generic.data = blob;
|
||||||
ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob;
|
ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob;
|
||||||
|
|
||||||
_hb_ft_font_set_funcs (font, ft_face, true);
|
_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_font_set_load_flags (font, FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING);
|
||||||
|
|
||||||
|
_hb_ft_hb_font_changed (font, ft_face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue