mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-04 21:15:06 +00:00
[font] Move emboldening advances to the font layer
Instead of each font-funcs impl. TODO: Do the same for draw_glyphs.
This commit is contained in:
parent
a588761198
commit
83481d65d0
3 changed files with 48 additions and 53 deletions
|
@ -317,16 +317,34 @@ struct hb_font_t
|
||||||
|
|
||||||
hb_position_t get_glyph_h_advance (hb_codepoint_t glyph)
|
hb_position_t get_glyph_h_advance (hb_codepoint_t glyph)
|
||||||
{
|
{
|
||||||
return klass->get.f.glyph_h_advance (this, user_data,
|
hb_position_t advance = klass->get.f.glyph_h_advance (this, user_data,
|
||||||
glyph,
|
glyph,
|
||||||
!klass->user_data ? nullptr : klass->user_data->glyph_h_advance);
|
!klass->user_data ? nullptr : klass->user_data->glyph_h_advance);
|
||||||
|
|
||||||
|
if (x_strength && !embolden_in_place)
|
||||||
|
{
|
||||||
|
/* Emboldening. */
|
||||||
|
hb_position_t x_strength = x_scale >= 0 ? x_strength : -x_strength;
|
||||||
|
advance += advance ? x_strength : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_position_t get_glyph_v_advance (hb_codepoint_t glyph)
|
hb_position_t get_glyph_v_advance (hb_codepoint_t glyph)
|
||||||
{
|
{
|
||||||
return klass->get.f.glyph_v_advance (this, user_data,
|
hb_position_t advance = klass->get.f.glyph_v_advance (this, user_data,
|
||||||
glyph,
|
glyph,
|
||||||
!klass->user_data ? nullptr : klass->user_data->glyph_v_advance);
|
!klass->user_data ? nullptr : klass->user_data->glyph_v_advance);
|
||||||
|
|
||||||
|
if (y_strength && !embolden_in_place)
|
||||||
|
{
|
||||||
|
/* Emboldening. */
|
||||||
|
hb_position_t y_strength = y_scale >= 0 ? y_strength : -y_strength;
|
||||||
|
advance += advance ? y_strength : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return advance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_glyph_h_advances (unsigned int count,
|
void get_glyph_h_advances (unsigned int count,
|
||||||
|
@ -340,6 +358,17 @@ struct hb_font_t
|
||||||
first_glyph, glyph_stride,
|
first_glyph, glyph_stride,
|
||||||
first_advance, advance_stride,
|
first_advance, advance_stride,
|
||||||
!klass->user_data ? nullptr : klass->user_data->glyph_h_advances);
|
!klass->user_data ? nullptr : klass->user_data->glyph_h_advances);
|
||||||
|
|
||||||
|
if (x_strength && !embolden_in_place)
|
||||||
|
{
|
||||||
|
/* Emboldening. */
|
||||||
|
hb_position_t x_strength = x_scale >= 0 ? x_strength : -x_strength;
|
||||||
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
*first_advance += *first_advance ? x_strength : 0;
|
||||||
|
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_glyph_v_advances (unsigned int count,
|
void get_glyph_v_advances (unsigned int count,
|
||||||
|
@ -353,6 +382,17 @@ struct hb_font_t
|
||||||
first_glyph, glyph_stride,
|
first_glyph, glyph_stride,
|
||||||
first_advance, advance_stride,
|
first_advance, advance_stride,
|
||||||
!klass->user_data ? nullptr : klass->user_data->glyph_v_advances);
|
!klass->user_data ? nullptr : klass->user_data->glyph_v_advances);
|
||||||
|
|
||||||
|
if (y_strength && !embolden_in_place)
|
||||||
|
{
|
||||||
|
/* Emboldening. */
|
||||||
|
hb_position_t y_strength = y_scale >= 0 ? y_strength : -y_strength;
|
||||||
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
*first_advance += *first_advance ? y_strength : 0;
|
||||||
|
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph,
|
hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph,
|
||||||
|
|
21
src/hb-ft.cc
21
src/hb-ft.cc
|
@ -477,7 +477,6 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
|
||||||
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_ft_hb_font_check_changed (font, ft_font);
|
_hb_ft_hb_font_check_changed (font, ft_font);
|
||||||
|
|
||||||
hb_position_t *orig_first_advance = first_advance;
|
|
||||||
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;
|
||||||
|
@ -518,18 +517,6 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font->x_strength && !font->embolden_in_place)
|
|
||||||
{
|
|
||||||
/* Emboldening. */
|
|
||||||
hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength;
|
|
||||||
first_advance = orig_first_advance;
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
*first_advance += *first_advance ? x_strength : 0;
|
|
||||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HB_NO_VERTICAL
|
#ifndef HB_NO_VERTICAL
|
||||||
|
@ -562,15 +549,11 @@ hb_ft_get_glyph_v_advance (hb_font_t *font,
|
||||||
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;
|
||||||
|
|
||||||
v = (int) (y_mult * v);
|
|
||||||
|
|
||||||
/* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
|
/* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
|
||||||
* have a Y growing upward. Hence the extra negation. */
|
* have a Y growing upward. Hence the extra negation. */
|
||||||
|
v = ((-v + (1<<9)) >> 10);
|
||||||
|
|
||||||
hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength;
|
return (hb_position_t) (y_mult * v);
|
||||||
v = ((-v + (1<<9)) >> 10) + (font->embolden_in_place ? 0 : y_strength);
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -205,8 +205,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
|
||||||
const hb_ot_face_t *ot_face = ot_font->ot_face;
|
const hb_ot_face_t *ot_face = ot_font->ot_face;
|
||||||
const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx;
|
const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx;
|
||||||
|
|
||||||
hb_position_t *orig_first_advance = first_advance;
|
|
||||||
|
|
||||||
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
||||||
const OT::HVAR &HVAR = *hmtx.var_table;
|
const OT::HVAR &HVAR = *hmtx.var_table;
|
||||||
const OT::ItemVariationStore &varStore = &HVAR + HVAR.varStore;
|
const OT::ItemVariationStore &varStore = &HVAR + HVAR.varStore;
|
||||||
|
@ -280,18 +278,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
|
||||||
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
||||||
OT::ItemVariationStore::destroy_cache (varStore_cache);
|
OT::ItemVariationStore::destroy_cache (varStore_cache);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (font->x_strength && !font->embolden_in_place)
|
|
||||||
{
|
|
||||||
/* Emboldening. */
|
|
||||||
hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength;
|
|
||||||
first_advance = orig_first_advance;
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
*first_advance += *first_advance ? x_strength : 0;
|
|
||||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HB_NO_VERTICAL
|
#ifndef HB_NO_VERTICAL
|
||||||
|
@ -308,8 +294,6 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
|
||||||
const hb_ot_face_t *ot_face = ot_font->ot_face;
|
const hb_ot_face_t *ot_face = ot_font->ot_face;
|
||||||
const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
|
const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
|
||||||
|
|
||||||
hb_position_t *orig_first_advance = first_advance;
|
|
||||||
|
|
||||||
if (vmtx.has_data ())
|
if (vmtx.has_data ())
|
||||||
{
|
{
|
||||||
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
|
||||||
|
@ -344,18 +328,6 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
|
||||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font->y_strength && !font->embolden_in_place)
|
|
||||||
{
|
|
||||||
/* Emboldening. */
|
|
||||||
hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength;
|
|
||||||
first_advance = orig_first_advance;
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
*first_advance += *first_advance ? y_strength : 0;
|
|
||||||
first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue