From f8491cdb66efb60e5f4dce6786f2e277073d0976 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 15 Apr 2026 15:44:28 -0600 Subject: [PATCH] [paint] Centralize reduce_anchors in hb-paint.hh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/hb-cairo-utils.cc | 33 +-------------------------------- src/hb-raster-paint.cc | 28 +++------------------------- 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc index 0d558df1b..f05575140 100644 --- a/src/hb-cairo-utils.cc +++ b/src/hb-cairo-utils.cc @@ -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); diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 8b0ce17a3..f98d88ed7 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -28,6 +28,7 @@ #include "hb-raster-paint.hh" #include "hb-machinery.hh" +#include "hb-paint.hh" #include @@ -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);