mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[paint] Centralize reduce_anchors in hb-paint.hh
hb-cairo-utils and hb-raster-paint each carried their own identical static copy of the COLR 3-anchor → 2-point gradient projection. Drop both, use the shared hb_paint_reduce_linear_anchors() added in the previous commit. Behavior unchanged. (hb-gpu-paint keeps its own copy intentionally -- it has slightly different surrounding code paths and we don't want to perturb the GPU encoder in this round.) Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ce4199c303
commit
f8491cdb66
2 files changed
+4
-57
No files matched your search
+1
-32
@@ -199,37 +199,6 @@ _hb_cairo_paint_glyph_image (hb_cairo_context_t *c,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
_hb_cairo_reduce_anchors (float x0, float y0,
|
||||
float x1, float y1,
|
||||
float x2, float y2,
|
||||
float *xx0, float *yy0,
|
||||
float *xx1, float *yy1)
|
||||
{
|
||||
float q1x, q1y, q2x, q2y;
|
||||
float s;
|
||||
float k;
|
||||
|
||||
q2x = x2 - x0;
|
||||
q2y = y2 - y0;
|
||||
q1x = x1 - x0;
|
||||
q1y = y1 - y0;
|
||||
|
||||
s = q2x * q2x + q2y * q2y;
|
||||
if (s < 0.000001f)
|
||||
{
|
||||
*xx0 = x0; *yy0 = y0;
|
||||
*xx1 = x1; *yy1 = y1;
|
||||
return;
|
||||
}
|
||||
|
||||
k = (q2x * q1x + q2y * q1y) / s;
|
||||
*xx0 = x0;
|
||||
*yy0 = y0;
|
||||
*xx1 = x1 - k * q2x;
|
||||
*yy1 = y1 - k * q2y;
|
||||
}
|
||||
|
||||
static void
|
||||
_hb_cairo_normalize_color_line (hb_color_stop_t *stops,
|
||||
unsigned int len,
|
||||
@@ -326,7 +295,7 @@ _hb_cairo_paint_linear_gradient (hb_cairo_context_t *c,
|
||||
return;
|
||||
_hb_cairo_normalize_color_line (stops, len, &min, &max);
|
||||
|
||||
_hb_cairo_reduce_anchors (x0, y0, x1, y1, x2, y2, &xx0, &yy0, &xx1, &yy1);
|
||||
hb_paint_reduce_linear_anchors (x0, y0, x1, y1, x2, y2, &xx0, &yy0, &xx1, &yy1);
|
||||
|
||||
xxx0 = xx0 + min * (xx1 - xx0);
|
||||
yyy0 = yy0 + min * (yy1 - yy0);
|
||||
|
||||
+3
-25
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "hb-raster-paint.hh"
|
||||
#include "hb-machinery.hh"
|
||||
#include "hb-paint.hh"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -1038,30 +1039,6 @@ lookup_gradient_lut (const uint32_t *lut,
|
||||
return lut[idx];
|
||||
}
|
||||
|
||||
static void
|
||||
reduce_anchors (float x0, float y0,
|
||||
float x1, float y1,
|
||||
float x2, float y2,
|
||||
float *xx0, float *yy0,
|
||||
float *xx1, float *yy1)
|
||||
{
|
||||
float q2x = x2 - x0, q2y = y2 - y0;
|
||||
float q1x = x1 - x0, q1y = y1 - y0;
|
||||
float s = q2x * q2x + q2y * q2y;
|
||||
if (s < 0.000001f)
|
||||
{
|
||||
*xx0 = x0; *yy0 = y0;
|
||||
*xx1 = x1; *yy1 = y1;
|
||||
return;
|
||||
}
|
||||
float k = (q2x * q1x + q2y * q1y) / s;
|
||||
*xx0 = x0;
|
||||
*yy0 = y0;
|
||||
*xx1 = x1 - k * q2x;
|
||||
*yy1 = y1 - k * q2y;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gradient paint callbacks
|
||||
*/
|
||||
@@ -1102,7 +1079,8 @@ hb_raster_paint_linear_gradient (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
|
||||
/* Reduce 3-point anchor to 2-point gradient axis */
|
||||
float lx0, ly0, lx1, ly1;
|
||||
reduce_anchors (x0, y0, x1, y1, x2, y2, &lx0, &ly0, &lx1, &ly1);
|
||||
hb_paint_reduce_linear_anchors (x0, y0, x1, y1, x2, y2,
|
||||
&lx0, &ly0, &lx1, &ly1);
|
||||
|
||||
/* Apply normalization to endpoints */
|
||||
float gx0 = lx0 + mn * (lx1 - lx0);
|
||||
|
||||
Reference in new issue
Block a user