[COLRv1] Remove specialized transform optimization

If the font has them, it's unlikely that they are identity
transforms. So, no need to try to optimize out.
This commit is contained in:
Behdad Esfahbod 2025-03-21 11:23:57 -06:00
parent c867bc976a
commit 98e2333940
3 changed files with 58 additions and 78 deletions

View file

@ -1059,9 +1059,9 @@ struct PaintTranslate
float ddx = dx + c->instancer (varIdxBase, 0);
float ddy = dy + c->instancer (varIdxBase, 1);
bool p1 = c->funcs->push_translate (c->data, ddx, ddy);
c->funcs->push_translate (c->data, ddx, ddy);
c->recurse (this+src);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 14(noVar) or 15 (Var) */
@ -1108,9 +1108,9 @@ struct PaintScale
float sx = scaleX.to_float (c->instancer (varIdxBase, 0));
float sy = scaleY.to_float (c->instancer (varIdxBase, 1));
bool p1 = c->funcs->push_scale (c->data, sx, sy);
c->funcs->push_scale (c->data, sx, sy);
c->recurse (this+src);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 16 (noVar) or 17(Var) */
@ -1161,13 +1161,13 @@ struct PaintScaleAroundCenter
float tCenterX = centerX + c->instancer (varIdxBase, 2);
float tCenterY = centerY + c->instancer (varIdxBase, 3);
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->funcs->push_translate (c->data, +tCenterX, +tCenterY);
c->funcs->push_scale (c->data, sx, sy);
c->funcs->push_translate (c->data, -tCenterX, -tCenterY);
c->recurse (this+src);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 18 (noVar) or 19(Var) */
@ -1212,9 +1212,9 @@ struct PaintScaleUniform
TRACE_PAINT (this);
float s = scale.to_float (c->instancer (varIdxBase, 0));
bool p1 = c->funcs->push_scale (c->data, s, s);
c->funcs->push_scale (c->data, s, s);
c->recurse (this+src);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 20 (noVar) or 21(Var) */
@ -1262,13 +1262,13 @@ struct PaintScaleUniformAroundCenter
float tCenterX = centerX + c->instancer (varIdxBase, 1);
float tCenterY = centerY + c->instancer (varIdxBase, 2);
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->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);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 22 (noVar) or 23(Var) */
@ -1312,9 +1312,9 @@ struct PaintRotate
TRACE_PAINT (this);
float a = angle.to_float (c->instancer (varIdxBase, 0));
bool p1 = c->funcs->push_rotate (c->data, a);
c->funcs->push_rotate (c->data, a);
c->recurse (this+src);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 24 (noVar) or 25(Var) */
@ -1362,13 +1362,13 @@ struct PaintRotateAroundCenter
float tCenterX = centerX + c->instancer (varIdxBase, 1);
float tCenterY = centerY + c->instancer (varIdxBase, 2);
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->funcs->push_translate (c->data, +tCenterX, +tCenterY);
c->funcs->push_rotate (c->data, a);
c->funcs->push_translate (c->data, -tCenterX, -tCenterY);
c->recurse (this+src);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 26 (noVar) or 27(Var) */
@ -1416,9 +1416,9 @@ struct PaintSkew
float sx = xSkewAngle.to_float(c->instancer (varIdxBase, 0));
float sy = ySkewAngle.to_float(c->instancer (varIdxBase, 1));
bool p1 = c->funcs->push_skew (c->data, sx, sy);
c->funcs->push_skew (c->data, sx, sy);
c->recurse (this+src);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 28(noVar) or 29 (Var) */
@ -1469,13 +1469,13 @@ struct PaintSkewAroundCenter
float tCenterX = centerX + c->instancer (varIdxBase, 2);
float tCenterY = centerY + c->instancer (varIdxBase, 3);
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->funcs->push_translate (c->data, +tCenterX, +tCenterY);
c->funcs->push_skew (c->data, sx, sy);
c->funcs->push_translate (c->data, -tCenterX, -tCenterY);
c->recurse (this+src);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
HBUINT8 format; /* format = 30(noVar) or 31 (Var) */

View file

@ -397,9 +397,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;
bool p1 = c->funcs->push_translate (c->data, dx, dy);
c->funcs->push_translate (c->data, dx, dy);
c->recurse (paint.u.translate.paint);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
break;
case FT_COLR_PAINTFORMAT_SCALE:
@ -409,13 +409,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;
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->funcs->push_translate (c->data, +dx, +dy);
c->funcs->push_scale (c->data, sx, sy);
c->funcs->push_translate (c->data, -dx, -dy);
c->recurse (paint.u.scale.paint);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
break;
case FT_COLR_PAINTFORMAT_ROTATE:
@ -424,13 +424,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;
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->funcs->push_translate (c->data, +dx, +dy);
c->funcs->push_rotate (c->data, a);
c->funcs->push_translate (c->data, -dx, -dy);
c->recurse (paint.u.rotate.paint);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
break;
case FT_COLR_PAINTFORMAT_SKEW:
@ -440,13 +440,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;
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->funcs->push_translate (c->data, +dx, +dy);
c->funcs->push_skew (c->data, sx, sy);
c->funcs->push_translate (c->data, -dx, -dy);
c->recurse (paint.u.skew.paint);
if (p3) c->funcs->pop_transform (c->data);
if (p2) c->funcs->pop_transform (c->data);
if (p1) c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
c->funcs->pop_transform (c->data);
}
break;
case FT_COLR_PAINTFORMAT_COMPOSITE:

View file

@ -180,54 +180,34 @@ struct hb_paint_funcs_t
upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0);
}
HB_NODISCARD
bool push_translate (void *paint_data,
void push_translate (void *paint_data,
float dx, float dy)
{
if (!dx && !dy)
return false;
push_transform (paint_data,
1.f, 0.f, 0.f, 1.f, dx, dy);
return true;
}
HB_NODISCARD
bool push_scale (void *paint_data,
void push_scale (void *paint_data,
float sx, float sy)
{
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;
}
HB_NODISCARD
bool push_rotate (void *paint_data,
void push_rotate (void *paint_data,
float a)
{
if (!a)
return false;
float cc = cosf (a * HB_PI);
float ss = sinf (a * HB_PI);
push_transform (paint_data, cc, ss, -ss, cc, 0.f, 0.f);
return true;
}
HB_NODISCARD
bool push_skew (void *paint_data,
void push_skew (void *paint_data,
float sx, float sy)
{
if (!sx && !sy)
return false;
float x = tanf (-sx * HB_PI);
float y = tanf (+sy * HB_PI);
push_transform (paint_data, 1.f, y, x, 1.f, 0.f, 0.f);
return true;
}
};
DECLARE_NULL_INSTANCE (hb_paint_funcs_t);