From df91677997c42cf5639718755267488af1389140 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:12:02 -0700 Subject: [PATCH 1/7] [paint] Call internal API internally --- src/hb-paint.hh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 2271e0171..2bc14cfa0 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -138,6 +138,9 @@ struct hb_paint_funcs_t mode, !user_data ? nullptr : user_data->pop_group); } + + /* Internal specializations. */ + void push_root_transform (void *paint_data, const hb_font_t *font) { @@ -145,9 +148,8 @@ struct hb_paint_funcs_t int xscale = font->x_scale, yscale = font->y_scale; float slant = font->slant_xy; - func.push_transform (this, paint_data, - xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0, - !user_data ? nullptr : user_data->push_transform); + push_transform (paint_data, + xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0); } void pop_root_transform (void *paint_data) { @@ -163,9 +165,8 @@ struct hb_paint_funcs_t int yscale = font->y_scale ? font->y_scale : upem; float slant = font->slant_xy; - func.push_transform (this, paint_data, - upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0, - !user_data ? nullptr : user_data->push_transform); + push_transform (paint_data, + upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0); } void pop_inverse_root_transform (void *paint_data) { From 7363eb373a14310a3d15b5a5889e4c158a55e533 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:24:42 -0700 Subject: [PATCH 2/7] [paint] Add internal push_translate/pop_translate --- src/hb-ft-colr.hh | 63 ++++++++++++----------------------- src/hb-ot-color-colr-table.hh | 41 +++++++++++------------ src/hb-paint.hh | 14 ++++++++ 3 files changed, 56 insertions(+), 62 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 6af0cdbd0..dba73296a 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -334,78 +334,59 @@ _hb_ft_paint (hb_ft_paint_context_t *c, break; case FT_COLR_PAINTFORMAT_TRANSLATE: { - c->funcs->push_transform (c->data, - 0.f, 0.f, 0.f, 0.f, - paint.u.translate.dx / 65536.f, - paint.u.translate.dy / 65536.f); + float dx = paint.u.translate.dx / 65536.f; + float dy = paint.u.translate.dy / 65536.f; + c->funcs->push_translate (c->data, dx, dy); c->recurse (paint.u.translate.paint); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, dx, dy); } break; case FT_COLR_PAINTFORMAT_SCALE: { - bool has_translate = paint.u.scale.center_x != 0 || paint.u.scale.center_y != 0; - if (has_translate) - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - +paint.u.scale.center_x / 65536.f, - +paint.u.scale.center_y / 65536.f); + float dx = paint.u.scale.center_x / 65536.f; + float dy = paint.u.scale.center_y / 65536.f; + c->funcs->push_translate (c->data, +dx, +dy); c->funcs->push_transform (c->data, paint.u.scale.scale_x / 65536.f, 0.f, 0.f, paint.u.scale.scale_y / 65536.f, 0.f, 0.f); - if (has_translate) - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - -paint.u.scale.center_x / 65536.f, - -paint.u.scale.center_y / 65536.f); + 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_transform (c->data); - if (has_translate) - { - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); - } + c->funcs->pop_translate (c->data, +dx, +dy); } break; case FT_COLR_PAINTFORMAT_ROTATE: { + float dx = paint.u.rotate.center_x / 65536.f; + float dy = paint.u.rotate.center_y / 65536.f; float a = paint.u.rotate.angle / 65536.f; float cc = cosf (a * (float) M_PI); float ss = sinf (a * (float) M_PI); - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - +paint.u.rotate.center_x / 65536.f, - +paint.u.rotate.center_y / 65536.f); + c->funcs->push_translate (c->data, +dx, +dy); c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0.); - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - -paint.u.rotate.center_x / 65536.f, - -paint.u.rotate.center_y / 65536.f); + 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_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, +dx, +dy); } break; case FT_COLR_PAINTFORMAT_SKEW: { + float dx = paint.u.skew.center_x / 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 y = -tanf (paint.u.skew.y_skew_angle / 65536.f * (float) M_PI); - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - +paint.u.skew.center_x / 65536.f, - +paint.u.skew.center_y / 65536.f); + c->funcs->push_translate (c->data, +dx, +dy); c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0.); - c->funcs->push_transform (c->data, - 1.f, 0.f, 0.f, 1.f, - -paint.u.skew.center_x / 65536.f, - -paint.u.skew.center_y / 65536.f); + 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_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, +dx, +dy); } break; case FT_COLR_PAINTFORMAT_COMPOSITE: diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index dc590e3da..9054f5149 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -885,12 +885,11 @@ struct PaintTranslate void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - c->funcs->push_transform (c->data, - 1., 0., 0., 1., - dx + c->instancer (varIdxBase, 0), - dy + c->instancer (varIdxBase, 0)); + float ddx = dx + c->instancer (varIdxBase, 0); + float ddy = dy + c->instancer (varIdxBase, 1); + c->funcs->push_translate (c->data, ddx, ddy); c->recurse (this+src); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, ddx, ddy); } HBUINT8 format; /* format = 14(noVar) or 15 (Var) */ @@ -962,17 +961,17 @@ struct PaintScaleAroundCenter { float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); - c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY); + c->funcs->push_translate (c->data, +tCenterX, +tCenterY); c->funcs->push_transform (c->data, scaleX.to_float (c->instancer (varIdxBase, 0)), 0., 0., scaleY.to_float (c->instancer (varIdxBase, 1)), 0., 0.); - c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY); + c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); + c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); } HBUINT8 format; /* format = 18 (noVar) or 19(Var) */ @@ -1043,13 +1042,13 @@ struct PaintScaleUniformAroundCenter float s = scale + c->instancer (varIdxBase, 0); float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); - c->funcs->push_transform (c->data, 0., 0., 0., 0., +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_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY); + c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); + c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->push_translate (c->data, +tCenterX, +tCenterY); } HBUINT8 format; /* format = 22 (noVar) or 23(Var) */ @@ -1123,13 +1122,13 @@ struct PaintRotateAroundCenter float ss = sinf (a * (float) M_PI); float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); - c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY); + c->funcs->push_translate (c->data, +tCenterX, +tCenterY); c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0.); - c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY); + c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); + c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); } HBUINT8 format; /* format = 26 (noVar) or 27(Var) */ @@ -1202,13 +1201,13 @@ struct PaintSkewAroundCenter float y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); - c->funcs->push_transform (c->data, 0., 0., 0., 0., +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_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY); + c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); + c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); - c->funcs->pop_transform (c->data); + c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); } HBUINT8 format; /* format = 30(noVar) or 31 (Var) */ diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 2bc14cfa0..a34032a60 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -173,6 +173,20 @@ struct hb_paint_funcs_t func.pop_transform (this, paint_data, !user_data ? nullptr : user_data->pop_transform); } + + void 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); + } }; DECLARE_NULL_INSTANCE (hb_paint_funcs_t); From ce7835124a741a75748b941ef1ff228e70437dfe Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:32:15 -0700 Subject: [PATCH 3/7] [paint] Add internal push_scale/pop_scale API --- src/hb-ft-colr.hh | 10 ++++------ src/hb-ot-color-colr-table.hh | 28 ++++++++++++---------------- src/hb-paint.hh | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index dba73296a..27529c894 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -345,16 +345,14 @@ _hb_ft_paint (hb_ft_paint_context_t *c, { float dx = paint.u.scale.center_x / 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_transform (c->data, - 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_scale (c->data, sx, sy); 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_transform (c->data); + c->funcs->pop_scale (c->data, sx, sy); c->funcs->pop_translate (c->data, +dx, +dy); } break; diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 9054f5149..805c01c76 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -921,13 +921,11 @@ struct PaintScale void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { - c->funcs->push_transform (c->data, - scaleX.to_float (c->instancer (varIdxBase, 0)), - 0., 0., - scaleY.to_float (c->instancer (varIdxBase, 1)), - 0., 0.); + 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); 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) */ @@ -959,18 +957,16 @@ struct PaintScaleAroundCenter 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 tCenterY = centerY + c->instancer (varIdxBase, 3); c->funcs->push_translate (c->data, +tCenterX, +tCenterY); - c->funcs->push_transform (c->data, - scaleX.to_float (c->instancer (varIdxBase, 0)), - 0., 0., - scaleY.to_float (c->instancer (varIdxBase, 1)), - 0., 0.); + c->funcs->push_scale (c->data, sx, sy); c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); 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); } @@ -1006,9 +1002,9 @@ struct PaintScaleUniform void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { 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->funcs->pop_transform (c->data); + c->funcs->pop_scale (c->data, s, s); } HBUINT8 format; /* format = 20 (noVar) or 21(Var) */ @@ -1043,11 +1039,11 @@ 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_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->recurse (this+src); 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); } diff --git a/src/hb-paint.hh b/src/hb-paint.hh index a34032a60..2c93ded6b 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -187,6 +187,20 @@ struct hb_paint_funcs_t if (dx || dy) 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); From 46adf31b4c6ac45c213c7ac492f27a18de8e1af5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:35:39 -0700 Subject: [PATCH 4/7] [paint] Add internal push_rotate/pop_rotate API --- src/hb-ft-colr.hh | 6 ++---- src/hb-ot-color-colr-table.hh | 12 ++++-------- src/hb-paint.hh | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 27529c894..e25609a66 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -361,14 +361,12 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float dx = paint.u.rotate.center_x / 65536.f; float dy = paint.u.rotate.center_y / 65536.f; float a = paint.u.rotate.angle / 65536.f; - float cc = cosf (a * (float) M_PI); - float ss = sinf (a * (float) M_PI); c->funcs->push_translate (c->data, +dx, +dy); - c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0.); + c->funcs->push_rotate (c->data, a); 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_transform (c->data); + c->funcs->pop_rotate (c->data, a); c->funcs->pop_translate (c->data, +dx, +dy); } break; diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 805c01c76..c37e710e4 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -1078,11 +1078,9 @@ struct PaintRotate void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { float a = angle.to_float (c->instancer (varIdxBase, 0)); - float cc = cosf (a * (float) M_PI); - float ss = sinf (a * (float) M_PI); - c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0.); + c->funcs->push_rotate (c->data, a); c->recurse (this+src); - c->funcs->pop_transform (c->data); + c->funcs->pop_rotate (c->data, a); } HBUINT8 format; /* format = 24 (noVar) or 25(Var) */ @@ -1114,16 +1112,14 @@ struct PaintRotateAroundCenter void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { float a = angle.to_float (c->instancer (varIdxBase, 0)); - float cc = cosf (a * (float) M_PI); - float ss = sinf (a * (float) M_PI); 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_transform (c->data, cc, ss, -ss, cc, 0., 0.); + c->funcs->push_rotate (c->data, a); c->funcs->push_translate (c->data, -tCenterX, -tCenterY); c->recurse (this+src); c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); - c->funcs->pop_transform (c->data); + c->funcs->pop_rotate (c->data, a); c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); } diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 2c93ded6b..05fcaa923 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -201,6 +201,23 @@ struct hb_paint_funcs_t if (sx != 1.f || sy != 1.f) pop_transform (paint_data); } + + void 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); + } }; DECLARE_NULL_INSTANCE (hb_paint_funcs_t); From 6b47fcb17aa138d1c60e07516ce4323c9fe594cc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:40:12 -0700 Subject: [PATCH 5/7] [paint] Add internal push_skew/pop_skew API --- src/hb-ft-colr.hh | 8 ++++---- src/hb-ot-color-colr-table.hh | 16 ++++++++-------- src/hb-paint.hh | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index e25609a66..da1ce5513 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -374,14 +374,14 @@ _hb_ft_paint (hb_ft_paint_context_t *c, { float dx = paint.u.skew.center_x / 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 y = -tanf (paint.u.skew.y_skew_angle / 65536.f * (float) M_PI); + 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_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->recurse (paint.u.skew.paint); 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); } break; diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index c37e710e4..cabbb9642 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -1153,11 +1153,11 @@ struct PaintSkew 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 y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); - c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0.); + 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); 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) */ @@ -1189,16 +1189,16 @@ struct PaintSkewAroundCenter 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 y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); + float sx = xSkewAngle.to_float(c->instancer (varIdxBase, 0)); + float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1)); 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_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->recurse (this+src); 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); } diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 05fcaa923..55c85b431 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -218,6 +218,23 @@ struct hb_paint_funcs_t if (a) 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); From 9e3ff0e9f0078aa17d616ae9670a3843949a212d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 31 Dec 2022 11:55:45 -0700 Subject: [PATCH 6/7] [paint] Fixup --- src/hb-ft-colr.hh | 4 ++++ src/hb-ot-color-colr-table.hh | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index da1ce5513..4ae4412b8 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -336,6 +336,7 @@ _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); c->recurse (paint.u.translate.paint); c->funcs->pop_translate (c->data, dx, dy); @@ -347,6 +348,7 @@ _hb_ft_paint (hb_ft_paint_context_t *c, 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_scale (c->data, sx, sy); c->funcs->push_translate (c->data, -dx, -dy); @@ -361,6 +363,7 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float dx = paint.u.rotate.center_x / 65536.f; 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); @@ -376,6 +379,7 @@ _hb_ft_paint (hb_ft_paint_context_t *c, float dy = paint.u.skew.center_y / 65536.f; 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); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index cabbb9642..e26e0db51 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -887,6 +887,7 @@ struct PaintTranslate { float ddx = dx + c->instancer (varIdxBase, 0); float ddy = dy + c->instancer (varIdxBase, 1); + c->funcs->push_translate (c->data, ddx, ddy); c->recurse (this+src); c->funcs->pop_translate (c->data, ddx, ddy); @@ -923,6 +924,7 @@ 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); c->recurse (this+src); c->funcs->pop_scale (c->data, sx, sy); @@ -961,6 +963,7 @@ struct PaintScaleAroundCenter float sy = scaleY.to_float (c->instancer (varIdxBase, 1)); 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); @@ -1002,6 +1005,7 @@ struct PaintScaleUniform void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { float s = scale + c->instancer (varIdxBase, 0); + c->funcs->push_scale (c->data, s, s); c->recurse (this+src); c->funcs->pop_scale (c->data, s, s); @@ -1038,13 +1042,14 @@ struct PaintScaleUniformAroundCenter float s = scale + c->instancer (varIdxBase, 0); 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); c->recurse (this+src); - c->funcs->push_translate (c->data, -tCenterX, -tCenterY); + c->funcs->pop_translate (c->data, -tCenterX, -tCenterY); c->funcs->pop_scale (c->data, s, s); - c->funcs->push_translate (c->data, +tCenterX, +tCenterY); + c->funcs->pop_translate (c->data, +tCenterX, +tCenterY); } HBUINT8 format; /* format = 22 (noVar) or 23(Var) */ @@ -1078,6 +1083,7 @@ struct PaintRotate void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { float a = angle.to_float (c->instancer (varIdxBase, 0)); + c->funcs->push_rotate (c->data, a); c->recurse (this+src); c->funcs->pop_rotate (c->data, a); @@ -1114,6 +1120,7 @@ struct PaintRotateAroundCenter float a = angle.to_float (c->instancer (varIdxBase, 0)); 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); @@ -1155,6 +1162,7 @@ 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); c->recurse (this+src); c->funcs->pop_skew (c->data, sx, sy); @@ -1193,6 +1201,7 @@ struct PaintSkewAroundCenter float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1)); 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); From 9f3b59fe6b27e3f8c2a32a89263264ceaceaa5be Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 31 Dec 2022 16:19:20 -0500 Subject: [PATCH 7/7] Update expected test results These need updates, because they record every callback, and we've changed what callbacks are happening. --- test/api/results/test-20-0-106 | 4 ++-- test/api/results/test-20-0-123 | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/api/results/test-20-0-106 b/test/api/results/test-20-0-106 index 6803913f9..8f9d45cb6 100644 --- a/test/api/results/test-20-0-106 +++ b/test/api/results/test-20-0-106 @@ -9,9 +9,9 @@ start clip rectangle 5.000000 5.000000 15.000000 15.000000 end clip end transform push group - start transform 0.000000 0.000000 0.000000 0.000000 1000.000000 1000.000000 + start transform 1.000000 0.000000 0.000000 1.000000 1000.000000 1000.000000 start transform 1.000000 -0.363874 -0.176283 1.000000 0.000000 0.000000 - start transform 0.000000 0.000000 0.000000 0.000000 -1000.000000 -1000.000000 + start transform 1.000000 0.000000 0.000000 1.000000 -1000.000000 -1000.000000 start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 diff --git a/test/api/results/test-20-0-123 b/test/api/results/test-20-0-123 index 9d3fa7475..0a8e1dda4 100644 --- a/test/api/results/test-20-0-123 +++ b/test/api/results/test-20-0-123 @@ -11,9 +11,9 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 pop group mode 3 push group push group - start transform 0.000000 0.000000 0.000000 0.000000 333.000000 667.000000 + start transform 1.000000 0.000000 0.000000 1.000000 333.000000 667.000000 start transform 8192.000000 0.000000 0.000000 8192.000000 0.000000 0.000000 - start transform 0.000000 0.000000 0.000000 0.000000 -333.000000 -667.000000 + start transform 1.000000 0.000000 0.000000 1.000000 -333.000000 -667.000000 start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 2 start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 @@ -25,9 +25,9 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 end transform end transform push group - start transform 0.000000 0.000000 0.000000 0.000000 667.000000 333.000000 + start transform 1.000000 0.000000 0.000000 1.000000 667.000000 333.000000 start transform 8192.000000 0.000000 0.000000 8192.000000 0.000000 0.000000 - start transform 0.000000 0.000000 0.000000 0.000000 -667.000000 -333.000000 + start transform 1.000000 0.000000 0.000000 1.000000 -667.000000 -333.000000 start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 2 start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000