[paint] Add internal push_scale/pop_scale API

This commit is contained in:
Behdad Esfahbod 2022-12-31 11:32:15 -07:00
parent 7363eb373a
commit ce7835124a
3 changed files with 30 additions and 22 deletions

View File

@ -345,16 +345,14 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
{ {
float dx = paint.u.scale.center_x / 65536.f; float dx = paint.u.scale.center_x / 65536.f;
float dy = paint.u.scale.center_y / 65536.f; float dy = paint.u.scale.center_y / 65536.f;
float sx = paint.u.scale.scale_x / 65536.f;
float sy = paint.u.scale.scale_y / 65536.f;
c->funcs->push_translate (c->data, +dx, +dy); c->funcs->push_translate (c->data, +dx, +dy);
c->funcs->push_transform (c->data, c->funcs->push_scale (c->data, sx, sy);
paint.u.scale.scale_x / 65536.f,
0.f, 0.f,
paint.u.scale.scale_y / 65536.f,
0.f, 0.f);
c->funcs->push_translate (c->data, -dx, -dy); c->funcs->push_translate (c->data, -dx, -dy);
c->recurse (paint.u.scale.paint); c->recurse (paint.u.scale.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_scale (c->data, sx, sy);
c->funcs->pop_translate (c->data, +dx, +dy); c->funcs->pop_translate (c->data, +dx, +dy);
} }
break; break;

View File

@ -921,13 +921,11 @@ struct PaintScale
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{ {
c->funcs->push_transform (c->data, float sx = scaleX.to_float (c->instancer (varIdxBase, 0));
scaleX.to_float (c->instancer (varIdxBase, 0)), float sy = scaleY.to_float (c->instancer (varIdxBase, 1));
0., 0., c->funcs->push_scale (c->data, sx, sy);
scaleY.to_float (c->instancer (varIdxBase, 1)),
0., 0.);
c->recurse (this+src); c->recurse (this+src);
c->funcs->pop_transform (c->data); c->funcs->pop_scale (c->data, sx, sy);
} }
HBUINT8 format; /* format = 16 (noVar) or 17(Var) */ HBUINT8 format; /* format = 16 (noVar) or 17(Var) */
@ -959,18 +957,16 @@ struct PaintScaleAroundCenter
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 sx = scaleX.to_float (c->instancer (varIdxBase, 0));
float sy = scaleY.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, c->funcs->push_scale (c->data, sx, sy);
scaleX.to_float (c->instancer (varIdxBase, 0)),
0., 0.,
scaleY.to_float (c->instancer (varIdxBase, 1)),
0., 0.);
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_scale (c->data, sx, sy);
c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); c->funcs->pop_translate (c->data, +tCenterX, +tCenterY);
} }
@ -1006,9 +1002,9 @@ struct PaintScaleUniform
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 s = scale + c->instancer (varIdxBase, 0); float s = scale + c->instancer (varIdxBase, 0);
c->funcs->push_transform (c->data, s, 0., 0., s, 0., 0.); c->funcs->push_scale (c->data, s, s);
c->recurse (this+src); c->recurse (this+src);
c->funcs->pop_transform (c->data); c->funcs->pop_scale (c->data, s, s);
} }
HBUINT8 format; /* format = 20 (noVar) or 21(Var) */ HBUINT8 format; /* format = 20 (noVar) or 21(Var) */
@ -1043,11 +1039,11 @@ struct PaintScaleUniformAroundCenter
float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterX = centerX + c->instancer (varIdxBase, 1);
float tCenterY = centerY + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 2);
c->funcs->push_translate (c->data, +tCenterX, +tCenterY); c->funcs->push_translate (c->data, +tCenterX, +tCenterY);
c->funcs->push_transform (c->data, s, 0., 0., s, 0., 0.); c->funcs->push_scale (c->data, s, s);
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->push_translate (c->data, -tCenterX, -tCenterY); c->funcs->push_translate (c->data, -tCenterX, -tCenterY);
c->funcs->pop_transform (c->data); c->funcs->pop_scale (c->data, s, s);
c->funcs->push_translate (c->data, +tCenterX, +tCenterY); c->funcs->push_translate (c->data, +tCenterX, +tCenterY);
} }

View File

@ -187,6 +187,20 @@ struct hb_paint_funcs_t
if (dx || dy) if (dx || dy)
pop_transform (paint_data); pop_transform (paint_data);
} }
void push_scale (void *paint_data,
float sx, float sy)
{
if (sx != 1.f || sy != 1.f)
push_transform (paint_data,
sx, 0.f, 0.f, sy, 0.f, 0.f);
}
void pop_scale (void *paint_data,
float sx, float sy)
{
if (sx != 1.f || sy != 1.f)
pop_transform (paint_data);
}
}; };
DECLARE_NULL_INSTANCE (hb_paint_funcs_t); DECLARE_NULL_INSTANCE (hb_paint_funcs_t);