diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 4ae4412b8..180802f61 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -290,9 +290,9 @@ _hb_ft_paint (hb_ft_paint_context_t *c, c->ft_font->lock.lock (); c->funcs->push_root_transform (c->data, c->font); c->recurse (paint.u.glyph.paint); - c->funcs->pop_root_transform (c->data); + c->funcs->pop_transform (c->data); c->funcs->pop_clip (c->data); - c->funcs->pop_inverse_root_transform (c->data); + c->funcs->pop_transform (c->data); } break; case FT_COLR_PAINTFORMAT_COLR_GLYPH: @@ -337,9 +337,9 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float dx = paint.u.translate.dx / 65536.f; float dy = paint.u.translate.dy / 65536.f; - c->funcs->push_translate (c->data, dx, dy); + bool p1 = c->funcs->push_translate (c->data, dx, dy); c->recurse (paint.u.translate.paint); - c->funcs->pop_translate (c->data, dx, dy); + if (p1) c->funcs->pop_transform (c->data); } break; case FT_COLR_PAINTFORMAT_SCALE: @@ -349,13 +349,13 @@ _hb_ft_paint (hb_ft_paint_context_t *c, 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_scale (c->data, sx, sy); - c->funcs->push_translate (c->data, -dx, -dy); + bool p1 = c->funcs->push_translate (c->data, +dx, +dy); + bool p2 = c->funcs->push_scale (c->data, sx, sy); + bool p3 = c->funcs->push_translate (c->data, -dx, -dy); c->recurse (paint.u.scale.paint); - c->funcs->pop_translate (c->data, -dx, -dy); - c->funcs->pop_scale (c->data, sx, sy); - c->funcs->pop_translate (c->data, +dx, +dy); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } break; case FT_COLR_PAINTFORMAT_ROTATE: @@ -364,13 +364,13 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float dy = paint.u.rotate.center_y / 65536.f; float a = paint.u.rotate.angle / 65536.f; - c->funcs->push_translate (c->data, +dx, +dy); - c->funcs->push_rotate (c->data, a); - c->funcs->push_translate (c->data, -dx, -dy); + bool p1 = c->funcs->push_translate (c->data, +dx, +dy); + bool p2 = c->funcs->push_rotate (c->data, a); + bool p3 = c->funcs->push_translate (c->data, -dx, -dy); c->recurse (paint.u.rotate.paint); - c->funcs->pop_translate (c->data, -dx, -dy); - c->funcs->pop_rotate (c->data, a); - c->funcs->pop_translate (c->data, +dx, +dy); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } break; case FT_COLR_PAINTFORMAT_SKEW: @@ -380,13 +380,13 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float sx = paint.u.skew.x_skew_angle / 65536.f; float sy = paint.u.skew.y_skew_angle / 65536.f; - c->funcs->push_translate (c->data, +dx, +dy); - c->funcs->push_skew (c->data, sx, sy); - c->funcs->push_translate (c->data, -dx, -dy); + bool p1 = c->funcs->push_translate (c->data, +dx, +dy); + bool p2 = c->funcs->push_skew (c->data, sx, sy); + bool p3 = c->funcs->push_translate (c->data, -dx, -dy); c->recurse (paint.u.skew.paint); - c->funcs->pop_translate (c->data, -dx, -dy); - c->funcs->pop_skew (c->data, sx, sy); - c->funcs->pop_translate (c->data, +dx, +dy); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } break; case FT_COLR_PAINTFORMAT_COMPOSITE: @@ -478,7 +478,7 @@ hb_ft_paint_glyph_colr (hb_font_t *font, if (is_bounded) c.recurse (paint); - c.funcs->pop_root_transform (c.data); + c.funcs->pop_transform (c.data); c.funcs->pop_clip (c.data); return true; diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index e26e0db51..c098ff7fe 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -788,9 +788,9 @@ struct PaintGlyph c->funcs->push_clip_glyph (c->data, gid, c->font); c->funcs->push_root_transform (c->data, c->font); c->recurse (this+paint); - c->funcs->pop_root_transform (c->data); + c->funcs->pop_transform (c->data); c->funcs->pop_clip (c->data); - c->funcs->pop_inverse_root_transform (c->data); + c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 10 */ @@ -888,9 +888,9 @@ struct PaintTranslate float ddx = dx + c->instancer (varIdxBase, 0); float ddy = dy + c->instancer (varIdxBase, 1); - c->funcs->push_translate (c->data, ddx, ddy); + bool p1 = c->funcs->push_translate (c->data, ddx, ddy); c->recurse (this+src); - c->funcs->pop_translate (c->data, ddx, ddy); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 14(noVar) or 15 (Var) */ @@ -925,9 +925,9 @@ struct PaintScale float sx = scaleX.to_float (c->instancer (varIdxBase, 0)); float sy = scaleY.to_float (c->instancer (varIdxBase, 1)); - c->funcs->push_scale (c->data, sx, sy); + bool p1 = c->funcs->push_scale (c->data, sx, sy); c->recurse (this+src); - c->funcs->pop_scale (c->data, sx, sy); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 16 (noVar) or 17(Var) */ @@ -964,13 +964,13 @@ struct PaintScaleAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); - c->funcs->push_translate (c->data, +tCenterX, +tCenterY); - c->funcs->push_scale (c->data, sx, sy); - c->funcs->push_translate (c->data, -tCenterX, -tCenterY); + bool p1 = c->funcs->push_translate (c->data, +tCenterX, +tCenterY); + bool p2 = c->funcs->push_scale (c->data, sx, sy); + bool p3 = c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); - c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); - c->funcs->pop_scale (c->data, sx, sy); - c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 18 (noVar) or 19(Var) */ @@ -1006,9 +1006,9 @@ struct PaintScaleUniform { float s = scale + c->instancer (varIdxBase, 0); - c->funcs->push_scale (c->data, s, s); + bool p1 = c->funcs->push_scale (c->data, s, s); c->recurse (this+src); - c->funcs->pop_scale (c->data, s, s); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 20 (noVar) or 21(Var) */ @@ -1043,13 +1043,13 @@ struct PaintScaleUniformAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); - c->funcs->push_translate (c->data, +tCenterX, +tCenterY); - c->funcs->push_scale (c->data, s, s); - c->funcs->push_translate (c->data, -tCenterX, -tCenterY); + bool p1 = c->funcs->push_translate (c->data, +tCenterX, +tCenterY); + bool p2 = c->funcs->push_scale (c->data, s, s); + bool p3 = c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); - c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); - c->funcs->pop_scale (c->data, s, s); - c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 22 (noVar) or 23(Var) */ @@ -1084,9 +1084,9 @@ struct PaintRotate { float a = angle.to_float (c->instancer (varIdxBase, 0)); - c->funcs->push_rotate (c->data, a); + bool p1 = c->funcs->push_rotate (c->data, a); c->recurse (this+src); - c->funcs->pop_rotate (c->data, a); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 24 (noVar) or 25(Var) */ @@ -1121,13 +1121,13 @@ struct PaintRotateAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); - c->funcs->push_translate (c->data, +tCenterX, +tCenterY); - c->funcs->push_rotate (c->data, a); - c->funcs->push_translate (c->data, -tCenterX, -tCenterY); + bool p1 = c->funcs->push_translate (c->data, +tCenterX, +tCenterY); + bool p2 = c->funcs->push_rotate (c->data, a); + bool p3 = c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); - c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); - c->funcs->pop_rotate (c->data, a); - c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 26 (noVar) or 27(Var) */ @@ -1163,9 +1163,9 @@ struct PaintSkew float sx = xSkewAngle.to_float(c->instancer (varIdxBase, 0)); float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1)); - c->funcs->push_skew (c->data, sx, sy); + bool p1 = c->funcs->push_skew (c->data, sx, sy); c->recurse (this+src); - c->funcs->pop_skew (c->data, sx, sy); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 28(noVar) or 29 (Var) */ @@ -1202,13 +1202,13 @@ struct PaintSkewAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); - c->funcs->push_translate (c->data, +tCenterX, +tCenterY); - c->funcs->push_skew (c->data, sx, sy); - c->funcs->push_translate (c->data, -tCenterX, -tCenterY); + bool p1 = c->funcs->push_translate (c->data, +tCenterX, +tCenterY); + bool p2 = c->funcs->push_skew (c->data, sx, sy); + bool p3 = c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); - c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); - c->funcs->pop_skew (c->data, sx, sy); - c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); + if (p3) c->funcs->pop_transform (c->data); + if (p2) c->funcs->pop_transform (c->data); + if (p1) c->funcs->pop_transform (c->data); } HBUINT8 format; /* format = 30(noVar) or 31 (Var) */ @@ -2093,7 +2093,7 @@ struct COLR if (clip && pop_clip_first) c.funcs->pop_clip (c.data); - c.funcs->pop_root_transform (c.data); + c.funcs->pop_transform (c.data); if (clip && !pop_clip_first) c.funcs->pop_clip (c.data); diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 55c85b431..f38df9abb 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -151,11 +151,6 @@ struct hb_paint_funcs_t push_transform (paint_data, xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0); } - void pop_root_transform (void *paint_data) - { - func.pop_transform (this, paint_data, - !user_data ? nullptr : user_data->pop_transform); - } void push_inverse_root_transform (void *paint_data, hb_font_t *font) @@ -168,72 +163,55 @@ struct hb_paint_funcs_t push_transform (paint_data, upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0); } - void pop_inverse_root_transform (void *paint_data) - { - func.pop_transform (this, paint_data, - !user_data ? nullptr : user_data->pop_transform); - } - void push_translate (void *paint_data, + HB_NODISCARD + bool push_translate (void *paint_data, float dx, float dy) { - if (dx || dy) - push_transform (paint_data, - 1.f, 0.f, 0.f, 1.f, dx, dy); - } - void pop_translate (void *paint_data, - float dx, float dy) - { - if (dx || dy) - pop_transform (paint_data); + if (!dx && !dy) + return false; + + push_transform (paint_data, + 1.f, 0.f, 0.f, 1.f, dx, dy); + return true; } - void push_scale (void *paint_data, + HB_NODISCARD + bool 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); + if (sx == 1.f && sy == 1.f) + return false; + + push_transform (paint_data, + sx, 0.f, 0.f, sy, 0.f, 0.f); + return true; } - void push_rotate (void *paint_data, + HB_NODISCARD + bool push_rotate (void *paint_data, float a) { - if (a) - { - float cc = cosf (a * (float) M_PI); - float ss = sinf (a * (float) M_PI); - push_transform (paint_data, cc, ss, -ss, cc, 0.f, 0.f); - } - } - void pop_rotate (void *paint_data, - float a) - { - if (a) - pop_transform (paint_data); + if (!a) + return false; + + float cc = cosf (a * (float) M_PI); + float ss = sinf (a * (float) M_PI); + push_transform (paint_data, cc, ss, -ss, cc, 0.f, 0.f); + return true; } - void push_skew (void *paint_data, + HB_NODISCARD + bool 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); + if (!sx && !sy) + return false; + + 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); + return true; } }; DECLARE_NULL_INSTANCE (hb_paint_funcs_t);