mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[paint] Use transforms from hb-geometry
This commit is contained in:
1 parent
120bc2c664
commit
a5b083b758
2 files changed
+27
-20
No files matched your search
+13
-9
@@ -175,6 +175,10 @@ struct hb_transform_t
|
||||
|
||||
void transform (const hb_transform_t &o, bool before=false) { multiply (o, before); }
|
||||
|
||||
static hb_transform_t translation (Float x, Float y)
|
||||
{
|
||||
return {1, 0, 0, 1, x, y};
|
||||
}
|
||||
void translate (Float x, Float y, bool before=false)
|
||||
{
|
||||
if (before)
|
||||
@@ -192,6 +196,10 @@ struct hb_transform_t
|
||||
}
|
||||
}
|
||||
|
||||
static hb_transform_t scaling (Float scaleX, Float scaleY)
|
||||
{
|
||||
return {scaleX, 0, 0, scaleY, 0, 0};
|
||||
}
|
||||
void scale (Float scaleX, Float scaleY)
|
||||
{
|
||||
if (scaleX == 1 && scaleY == 1)
|
||||
@@ -211,7 +219,6 @@ struct hb_transform_t
|
||||
hb_sincos (radians, s, c);
|
||||
return {c, s, -s, c, 0, 0};
|
||||
}
|
||||
|
||||
void rotate (Float radians, bool before=false)
|
||||
{
|
||||
if (radians == 0)
|
||||
@@ -230,7 +237,6 @@ struct hb_transform_t
|
||||
-s * center_x + (1 - c) * center_y
|
||||
};
|
||||
}
|
||||
|
||||
void rotate_around_center (Float radians, Float center_x, Float center_y, bool before=false)
|
||||
{
|
||||
if (radians == 0)
|
||||
@@ -239,18 +245,16 @@ struct hb_transform_t
|
||||
transform (rotation_around_center (radians, center_x, center_y), before);
|
||||
}
|
||||
|
||||
static hb_transform_t skewing (Float skewX, Float skewY)
|
||||
{
|
||||
return {1, skewY ? tanf (skewY) : 0, skewX ? tanf (skewX) : 0, 1, 0, 0};
|
||||
}
|
||||
void skew (Float skewX, Float skewY)
|
||||
{
|
||||
if (skewX == 0 && skewY == 0)
|
||||
return;
|
||||
|
||||
// https://github.com/fonttools/fonttools/blob/f66ee05f71c8b57b5f519ee975e95edcd1466e14/Lib/fontTools/misc/transform.py#L255
|
||||
auto other = hb_transform_t{1,
|
||||
skewY ? tanf (skewY) : 0,
|
||||
skewX ? tanf (skewX) : 0,
|
||||
1,
|
||||
0, 0};
|
||||
transform (other);
|
||||
transform (skewing (skewX, skewY));
|
||||
}
|
||||
|
||||
Float xx = 1;
|
||||
|
||||
+14
-11
@@ -28,6 +28,7 @@
|
||||
#include "hb.hh"
|
||||
#include "hb-face.hh"
|
||||
#include "hb-font.hh"
|
||||
#include "hb-geometry.hh"
|
||||
|
||||
#define HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS \
|
||||
HB_PAINT_FUNC_IMPLEMENT (push_transform) \
|
||||
@@ -180,6 +181,11 @@ struct hb_paint_funcs_t
|
||||
upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0);
|
||||
}
|
||||
|
||||
void push_transform (void *paint_data, hb_transform_t<float> t)
|
||||
{
|
||||
push_transform (paint_data, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0);
|
||||
}
|
||||
|
||||
HB_NODISCARD
|
||||
bool push_translate (void *paint_data,
|
||||
float dx, float dy)
|
||||
@@ -188,7 +194,7 @@ struct hb_paint_funcs_t
|
||||
return false;
|
||||
|
||||
push_transform (paint_data,
|
||||
1.f, 0.f, 0.f, 1.f, dx, dy);
|
||||
hb_transform_t<float>::translation (dx, dy));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -200,7 +206,7 @@ struct hb_paint_funcs_t
|
||||
return false;
|
||||
|
||||
push_transform (paint_data,
|
||||
sx, 0.f, 0.f, sy, 0.f, 0.f);
|
||||
hb_transform_t<float>::scaling (sx, sy));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -211,9 +217,8 @@ struct hb_paint_funcs_t
|
||||
if (!a)
|
||||
return false;
|
||||
|
||||
float c, s;
|
||||
hb_sincos (a * HB_PI, s, c);
|
||||
push_transform (paint_data, c, s, -s, c, 0.f, 0.f);
|
||||
push_transform (paint_data,
|
||||
hb_transform_t<float>::rotation (a * HB_PI));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -224,9 +229,8 @@ struct hb_paint_funcs_t
|
||||
if (!a)
|
||||
return false;
|
||||
|
||||
float c, s;
|
||||
hb_sincos (a * HB_PI, s, c);
|
||||
push_transform (paint_data, c, s, -s, c, cx * (1 - c) + cy * s, cy * (1 - c) - cx * s);
|
||||
push_transform (paint_data,
|
||||
hb_transform_t<float>::rotation_around_center (a * HB_PI, cx, cy));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -237,9 +241,8 @@ struct hb_paint_funcs_t
|
||||
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);
|
||||
push_transform (paint_data,
|
||||
hb_transform_t<float>::skewing (-sx * HB_PI, sy * HB_PI));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user