[font] Optimize glyph scaling
This commit is contained in:
parent
a1c45bbb55
commit
556e7078f0
|
@ -1649,6 +1649,8 @@ DEFINE_NULL_INSTANCE (hb_font_t) =
|
||||||
1000, /* y_scale */
|
1000, /* y_scale */
|
||||||
0., /* slant */
|
0., /* slant */
|
||||||
0., /* slant_xy; */
|
0., /* slant_xy; */
|
||||||
|
1000, /* upem */
|
||||||
|
0.001f, /* upem_inv */
|
||||||
1<<16, /* x_mult */
|
1<<16, /* x_mult */
|
||||||
1<<16, /* y_mult */
|
1<<16, /* y_mult */
|
||||||
|
|
||||||
|
@ -1682,6 +1684,8 @@ _hb_font_create (hb_face_t *face)
|
||||||
font->klass = hb_font_funcs_get_empty ();
|
font->klass = hb_font_funcs_get_empty ();
|
||||||
font->data.init0 (font);
|
font->data.init0 (font);
|
||||||
font->x_scale = font->y_scale = hb_face_get_upem (face);
|
font->x_scale = font->y_scale = hb_face_get_upem (face);
|
||||||
|
font->upem = face->get_upem ();
|
||||||
|
font->upem_inv = 1.f / font->upem;
|
||||||
font->x_mult = font->y_mult = 1 << 16;
|
font->x_mult = font->y_mult = 1 << 16;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
|
|
|
@ -114,6 +114,8 @@ struct hb_font_t
|
||||||
int32_t y_scale;
|
int32_t y_scale;
|
||||||
float slant;
|
float slant;
|
||||||
float slant_xy;
|
float slant_xy;
|
||||||
|
unsigned upem;
|
||||||
|
float upem_inv;
|
||||||
int64_t x_mult;
|
int64_t x_mult;
|
||||||
int64_t y_mult;
|
int64_t y_mult;
|
||||||
|
|
||||||
|
@ -629,11 +631,12 @@ struct hb_font_t
|
||||||
|
|
||||||
void mults_changed ()
|
void mults_changed ()
|
||||||
{
|
{
|
||||||
signed upem = face->get_upem ();
|
upem = face->get_upem ();
|
||||||
|
upem_inv = 1.f / upem;
|
||||||
bool x_neg = x_scale < 0;
|
bool x_neg = x_scale < 0;
|
||||||
x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) / upem;
|
x_mult = (x_neg ? -((int64_t) -x_scale << 16) : ((int64_t) x_scale << 16)) * upem_inv;
|
||||||
bool y_neg = y_scale < 0;
|
bool y_neg = y_scale < 0;
|
||||||
y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) / upem;
|
y_mult = (y_neg ? -((int64_t) -y_scale << 16) : ((int64_t) y_scale << 16)) * upem_inv;
|
||||||
slant_xy = y_scale ? slant * x_scale / y_scale : 0.f;
|
slant_xy = y_scale ? slant * x_scale / y_scale : 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,9 +645,9 @@ struct hb_font_t
|
||||||
hb_position_t em_scalef (float v, int scale)
|
hb_position_t em_scalef (float v, int scale)
|
||||||
{ return (hb_position_t) roundf (em_fscalef (v, scale)); }
|
{ return (hb_position_t) roundf (em_fscalef (v, scale)); }
|
||||||
float em_fscalef (float v, int scale)
|
float em_fscalef (float v, int scale)
|
||||||
{ return v * scale / face->get_upem (); }
|
{ return v * scale * upem_inv; }
|
||||||
float em_fscale (int16_t v, int scale)
|
float em_fscale (int16_t v, int scale)
|
||||||
{ return (float) v * scale / face->get_upem (); }
|
{ return (float) v * scale * upem_inv; }
|
||||||
};
|
};
|
||||||
DECLARE_NULL_INSTANCE (hb_font_t);
|
DECLARE_NULL_INSTANCE (hb_font_t);
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,7 @@ test_hb_draw_font_kit_glyphs_tests (void)
|
||||||
char expected[] = "M581,274L443,274Q409,274 384,259Q359,243 348,219Q336,194 340,166"
|
char expected[] = "M581,274L443,274Q409,274 384,259Q359,243 348,219Q336,194 340,166"
|
||||||
"Q343,138 365,111L468,-13Q470,-10 473,-6Q475,-3 477,0L253,0Q225,0 203,8"
|
"Q343,138 365,111L468,-13Q470,-10 473,-6Q475,-3 477,0L253,0Q225,0 203,8"
|
||||||
"Q180,15 168,32Q155,48 155,73L155,269L50,269L50,73Q50,24 69,-10"
|
"Q180,15 168,32Q155,48 155,73L155,269L50,269L50,73Q50,24 69,-10"
|
||||||
"Q88,-44 118,-64Q147,-85 181,-94Q214,-104 243,-104L473,-104"
|
"Q88,-44 118,-65Q147,-85 181,-95Q214,-104 243,-104L473,-104"
|
||||||
"Q501,-104 525,-91Q549,-78 564,-56Q578,-34 578,-8Q578,18 557,43"
|
"Q501,-104 525,-91Q549,-78 564,-56Q578,-34 578,-8Q578,18 557,43"
|
||||||
"L442,182Q439,179 437,176Q435,173 432,170L581,170L581,274ZM184,-194"
|
"L442,182Q439,179 437,176Q435,173 432,170L581,170L581,274ZM184,-194"
|
||||||
"Q184,-216 199,-231Q214,-246 236,-246Q258,-246 273,-231Q288,-216 288,-194"
|
"Q184,-216 199,-231Q214,-246 236,-246Q258,-246 273,-231Q288,-216 288,-194"
|
||||||
|
|
Loading…
Reference in New Issue