[paint] Add internal push_skew/pop_skew API

This commit is contained in:
Behdad Esfahbod 2022-12-31 11:40:12 -07:00
parent 46adf31b4c
commit 6b47fcb17a
3 changed files with 29 additions and 12 deletions

View File

@ -374,14 +374,14 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
{ {
float dx = paint.u.skew.center_x / 65536.f; float dx = paint.u.skew.center_x / 65536.f;
float dy = paint.u.skew.center_y / 65536.f; float dy = paint.u.skew.center_y / 65536.f;
float x = +tanf (paint.u.skew.x_skew_angle / 65536.f * (float) M_PI); float sx = paint.u.skew.x_skew_angle / 65536.f;
float y = -tanf (paint.u.skew.y_skew_angle / 65536.f * (float) M_PI); float sy = paint.u.skew.y_skew_angle / 65536.f;
c->funcs->push_translate (c->data, +dx, +dy); c->funcs->push_translate (c->data, +dx, +dy);
c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0.); c->funcs->push_skew (c->data, sx, sy);
c->funcs->push_translate (c->data, -dx, -dy); c->funcs->push_translate (c->data, -dx, -dy);
c->recurse (paint.u.skew.paint); c->recurse (paint.u.skew.paint);
c->funcs->pop_translate (c->data, -dx, -dy); c->funcs->pop_translate (c->data, -dx, -dy);
c->funcs->pop_transform (c->data); c->funcs->pop_skew (c->data, sx, sy);
c->funcs->pop_translate (c->data, +dx, +dy); c->funcs->pop_translate (c->data, +dx, +dy);
} }
break; break;

View File

@ -1153,11 +1153,11 @@ struct PaintSkew
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{ {
float x = +tanf (xSkewAngle.to_float(c->instancer (varIdxBase, 0)) * (float) M_PI); float sx = xSkewAngle.to_float(c->instancer (varIdxBase, 0));
float y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1));
c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0.); c->funcs->push_skew (c->data, sx, sy);
c->recurse (this+src); c->recurse (this+src);
c->funcs->pop_transform (c->data); c->funcs->pop_skew (c->data, sx, sy);
} }
HBUINT8 format; /* format = 28(noVar) or 29 (Var) */ HBUINT8 format; /* format = 28(noVar) or 29 (Var) */
@ -1189,16 +1189,16 @@ struct PaintSkewAroundCenter
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{ {
float x = +tanf (xSkewAngle.to_float(c->instancer (varIdxBase, 0)) * (float) M_PI); float sx = xSkewAngle.to_float(c->instancer (varIdxBase, 0));
float y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1));
float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterX = centerX + c->instancer (varIdxBase, 2);
float tCenterY = centerY + c->instancer (varIdxBase, 3); float tCenterY = centerY + c->instancer (varIdxBase, 3);
c->funcs->push_translate (c->data, +tCenterX, +tCenterY); c->funcs->push_translate (c->data, +tCenterX, +tCenterY);
c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0.); c->funcs->push_skew (c->data, sx, sy);
c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->funcs->push_translate (c->data, -tCenterX, -tCenterY);
c->recurse (this+src); c->recurse (this+src);
c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_translate (c->data, -tCenterX, -tCenterY);
c->funcs->pop_transform (c->data); c->funcs->pop_skew (c->data, sx, sy);
c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); c->funcs->pop_translate (c->data, +tCenterX, +tCenterY);
} }

View File

@ -218,6 +218,23 @@ struct hb_paint_funcs_t
if (a) if (a)
pop_transform (paint_data); pop_transform (paint_data);
} }
void push_skew (void *paint_data,
float sx, float sy)
{
if (sx || sy)
{
float x = +tanf (sx * (float) M_PI);
float y = -tanf (sy * (float) M_PI);
push_transform (paint_data, 1.f, y, x, 1.f, 0.f, 0.f);
}
}
void pop_skew (void *paint_data,
float sx, float sy)
{
if (sx || sy)
pop_transform (paint_data);
}
}; };
DECLARE_NULL_INSTANCE (hb_paint_funcs_t); DECLARE_NULL_INSTANCE (hb_paint_funcs_t);