mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 16:31:14 +01:00
[font] Don't apply synthetic bold/slant to parent
Fixes https://github.com/harfbuzz/harfbuzz/issues/5274
This commit is contained in:
1 parent
1a9e21758d
commit
9dbb84e6fd
2 files changed
+67
-39
No files matched your search
+14
-12
@@ -103,7 +103,7 @@ hb_font_get_font_h_extents_default (hb_font_t *font,
|
||||
hb_font_extents_t *extents,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_bool_t ret = font->parent->get_font_h_extents (extents);
|
||||
hb_bool_t ret = font->parent->get_font_h_extents (extents, false);
|
||||
if (ret) {
|
||||
extents->ascender = font->parent_scale_y_distance (extents->ascender);
|
||||
extents->descender = font->parent_scale_y_distance (extents->descender);
|
||||
@@ -128,7 +128,7 @@ hb_font_get_font_v_extents_default (hb_font_t *font,
|
||||
hb_font_extents_t *extents,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_bool_t ret = font->parent->get_font_v_extents (extents);
|
||||
hb_bool_t ret = font->parent->get_font_v_extents (extents, false);
|
||||
if (ret) {
|
||||
extents->ascender = font->parent_scale_x_distance (extents->ascender);
|
||||
extents->descender = font->parent_scale_x_distance (extents->descender);
|
||||
@@ -234,10 +234,10 @@ hb_font_get_glyph_h_advance_default (hb_font_t *font,
|
||||
if (font->has_glyph_h_advances_func_set ())
|
||||
{
|
||||
hb_position_t ret;
|
||||
font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
|
||||
font->get_glyph_h_advances (1, &glyph, 0, &ret, 0, false);
|
||||
return ret;
|
||||
}
|
||||
return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
|
||||
return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph, false));
|
||||
}
|
||||
|
||||
static hb_position_t
|
||||
@@ -259,10 +259,10 @@ hb_font_get_glyph_v_advance_default (hb_font_t *font,
|
||||
if (font->has_glyph_v_advances_func_set ())
|
||||
{
|
||||
hb_position_t ret;
|
||||
font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
|
||||
font->get_glyph_v_advances (1, &glyph, 0, &ret, 0, false);
|
||||
return ret;
|
||||
}
|
||||
return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
|
||||
return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph, false));
|
||||
}
|
||||
|
||||
#define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
|
||||
@@ -281,7 +281,7 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font,
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
*first_advance = font->get_glyph_h_advance (*first_glyph);
|
||||
*first_advance = font->get_glyph_h_advance (*first_glyph, false);
|
||||
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
|
||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
||||
}
|
||||
@@ -290,7 +290,8 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font,
|
||||
|
||||
font->parent->get_glyph_h_advances (count,
|
||||
first_glyph, glyph_stride,
|
||||
first_advance, advance_stride);
|
||||
first_advance, advance_stride,
|
||||
false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
*first_advance = font->parent_scale_x_distance (*first_advance);
|
||||
@@ -313,7 +314,7 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font,
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
*first_advance = font->get_glyph_v_advance (*first_glyph);
|
||||
*first_advance = font->get_glyph_v_advance (*first_glyph, false);
|
||||
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
|
||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
||||
}
|
||||
@@ -322,7 +323,8 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font,
|
||||
|
||||
font->parent->get_glyph_v_advances (count,
|
||||
first_glyph, glyph_stride,
|
||||
first_advance, advance_stride);
|
||||
first_advance, advance_stride,
|
||||
false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
*first_advance = font->parent_scale_y_distance (*first_advance);
|
||||
@@ -442,7 +444,7 @@ hb_font_get_glyph_extents_default (hb_font_t *font,
|
||||
hb_glyph_extents_t *extents,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
|
||||
hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents, false);
|
||||
if (ret) {
|
||||
font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
|
||||
font->parent_scale_distance (&extents->width, &extents->height);
|
||||
@@ -472,7 +474,7 @@ hb_font_get_glyph_contour_point_default (hb_font_t *font,
|
||||
hb_position_t *y,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
|
||||
hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y, false);
|
||||
if (ret)
|
||||
font->parent_scale_position (x, y);
|
||||
return ret;
|
||||
|
||||
+53
-27
@@ -206,7 +206,7 @@ struct hb_font_t
|
||||
|
||||
void synthetic_glyph_extents (hb_glyph_extents_t *extents)
|
||||
{
|
||||
/* Apply slant. */
|
||||
/* Slant. */
|
||||
if (slant_xy)
|
||||
{
|
||||
hb_position_t x1 = extents->x_bearing;
|
||||
@@ -221,6 +221,7 @@ struct hb_font_t
|
||||
extents->width = x2 - extents->x_bearing;
|
||||
}
|
||||
|
||||
/* Embolden. */
|
||||
if (x_strength || y_strength)
|
||||
{
|
||||
/* Y */
|
||||
@@ -263,14 +264,15 @@ struct hb_font_t
|
||||
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
|
||||
#undef HB_FONT_FUNC_IMPLEMENT
|
||||
|
||||
hb_bool_t get_font_h_extents (hb_font_extents_t *extents)
|
||||
hb_bool_t get_font_h_extents (hb_font_extents_t *extents,
|
||||
bool synthetic = true)
|
||||
{
|
||||
hb_memset (extents, 0, sizeof (*extents));
|
||||
bool ret = klass->get.f.font_h_extents (this, user_data,
|
||||
extents,
|
||||
!klass->user_data ? nullptr : klass->user_data->font_h_extents);
|
||||
|
||||
if (ret)
|
||||
if (synthetic && ret)
|
||||
{
|
||||
/* Embolden */
|
||||
int y_shift = y_scale < 0 ? -y_strength : y_strength;
|
||||
@@ -279,14 +281,15 @@ struct hb_font_t
|
||||
|
||||
return ret;
|
||||
}
|
||||
hb_bool_t get_font_v_extents (hb_font_extents_t *extents)
|
||||
hb_bool_t get_font_v_extents (hb_font_extents_t *extents,
|
||||
bool synthetic = true)
|
||||
{
|
||||
hb_memset (extents, 0, sizeof (*extents));
|
||||
bool ret = klass->get.f.font_v_extents (this, user_data,
|
||||
extents,
|
||||
!klass->user_data ? nullptr : klass->user_data->font_v_extents);
|
||||
|
||||
if (ret)
|
||||
if (synthetic && ret)
|
||||
{
|
||||
/* Embolden */
|
||||
int x_shift = x_scale < 0 ? -x_strength : x_strength;
|
||||
@@ -340,15 +343,16 @@ struct hb_font_t
|
||||
!klass->user_data ? nullptr : klass->user_data->variation_glyph);
|
||||
}
|
||||
|
||||
hb_position_t get_glyph_h_advance (hb_codepoint_t glyph)
|
||||
hb_position_t get_glyph_h_advance (hb_codepoint_t glyph,
|
||||
bool synthetic = true)
|
||||
{
|
||||
hb_position_t advance = klass->get.f.glyph_h_advance (this, user_data,
|
||||
glyph,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_h_advance);
|
||||
|
||||
if (x_strength && !embolden_in_place)
|
||||
if (synthetic && x_strength && !embolden_in_place)
|
||||
{
|
||||
/* Emboldening. */
|
||||
/* Embolden */
|
||||
hb_position_t strength = x_scale >= 0 ? x_strength : -x_strength;
|
||||
advance += advance ? strength : 0;
|
||||
}
|
||||
@@ -356,15 +360,16 @@ struct hb_font_t
|
||||
return advance;
|
||||
}
|
||||
|
||||
hb_position_t get_glyph_v_advance (hb_codepoint_t glyph)
|
||||
hb_position_t get_glyph_v_advance (hb_codepoint_t glyph,
|
||||
bool synthetic = true)
|
||||
{
|
||||
hb_position_t advance = klass->get.f.glyph_v_advance (this, user_data,
|
||||
glyph,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_v_advance);
|
||||
|
||||
if (y_strength && !embolden_in_place)
|
||||
if (synthetic && y_strength && !embolden_in_place)
|
||||
{
|
||||
/* Emboldening. */
|
||||
/* Embolden */
|
||||
hb_position_t strength = y_scale >= 0 ? y_strength : -y_strength;
|
||||
advance += advance ? strength : 0;
|
||||
}
|
||||
@@ -376,7 +381,8 @@ struct hb_font_t
|
||||
const hb_codepoint_t *first_glyph,
|
||||
unsigned int glyph_stride,
|
||||
hb_position_t *first_advance,
|
||||
unsigned int advance_stride)
|
||||
unsigned int advance_stride,
|
||||
bool synthetic = true)
|
||||
{
|
||||
klass->get.f.glyph_h_advances (this, user_data,
|
||||
count,
|
||||
@@ -384,9 +390,9 @@ struct hb_font_t
|
||||
first_advance, advance_stride,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_h_advances);
|
||||
|
||||
if (x_strength && !embolden_in_place)
|
||||
if (synthetic && x_strength && !embolden_in_place)
|
||||
{
|
||||
/* Emboldening. */
|
||||
/* Embolden */
|
||||
hb_position_t strength = x_scale >= 0 ? x_strength : -x_strength;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -400,7 +406,8 @@ struct hb_font_t
|
||||
const hb_codepoint_t *first_glyph,
|
||||
unsigned int glyph_stride,
|
||||
hb_position_t *first_advance,
|
||||
unsigned int advance_stride)
|
||||
unsigned int advance_stride,
|
||||
bool synthetic = true)
|
||||
{
|
||||
klass->get.f.glyph_v_advances (this, user_data,
|
||||
count,
|
||||
@@ -408,9 +415,9 @@ struct hb_font_t
|
||||
first_advance, advance_stride,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_v_advances);
|
||||
|
||||
if (y_strength && !embolden_in_place)
|
||||
if (synthetic && y_strength && !embolden_in_place)
|
||||
{
|
||||
/* Emboldening. */
|
||||
/* Embolden */
|
||||
hb_position_t strength = y_scale >= 0 ? y_strength : -y_strength;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -463,27 +470,45 @@ struct hb_font_t
|
||||
}
|
||||
|
||||
hb_bool_t get_glyph_extents (hb_codepoint_t glyph,
|
||||
hb_glyph_extents_t *extents)
|
||||
hb_glyph_extents_t *extents,
|
||||
bool synthetic = true)
|
||||
{
|
||||
hb_memset (extents, 0, sizeof (*extents));
|
||||
bool ret = klass->get.f.glyph_extents (this, user_data,
|
||||
glyph,
|
||||
extents,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_extents);
|
||||
if (ret)
|
||||
if (synthetic && ret)
|
||||
synthetic_glyph_extents (extents);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int point_index,
|
||||
hb_position_t *x, hb_position_t *y)
|
||||
hb_position_t *x, hb_position_t *y,
|
||||
bool synthetic = true)
|
||||
{
|
||||
*x = *y = 0;
|
||||
return klass->get.f.glyph_contour_point (this, user_data,
|
||||
glyph, point_index,
|
||||
x, y,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_contour_point);
|
||||
bool ret = klass->get.f.glyph_contour_point (this, user_data,
|
||||
glyph, point_index,
|
||||
x, y,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_contour_point);
|
||||
|
||||
if (synthetic && ret)
|
||||
{
|
||||
/* Slant */
|
||||
if (slant_xy)
|
||||
*x += roundf (*y * slant_xy);
|
||||
|
||||
/* Embolden */
|
||||
if (!embolden_in_place)
|
||||
{
|
||||
int x_shift = x_scale < 0 ? -x_strength : x_strength;
|
||||
*x += x_shift;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
hb_bool_t get_glyph_name (hb_codepoint_t glyph,
|
||||
@@ -508,14 +533,15 @@ struct hb_font_t
|
||||
}
|
||||
|
||||
void draw_glyph (hb_codepoint_t glyph,
|
||||
hb_draw_funcs_t *draw_funcs, void *draw_data)
|
||||
hb_draw_funcs_t *draw_funcs, void *draw_data,
|
||||
bool synthetic = true)
|
||||
{
|
||||
#ifndef HB_NO_OUTLINE
|
||||
bool embolden = x_strength || y_strength;
|
||||
bool slanted = slant_xy;
|
||||
bool synthetic = embolden || slanted;
|
||||
synthetic = synthetic && (embolden || slanted);
|
||||
#else
|
||||
constexpr bool synthetic = false;
|
||||
synthetic = false;
|
||||
#endif
|
||||
|
||||
if (!synthetic)
|
||||
|
||||
Reference in new issue
Block a user