mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 06:51:01 +01:00
[vector] Size PDF gradient soft masks to cover the painted area
For a linear or radial COLRv1 gradient with a translucent stop, the PDF backend painted the alpha ramp through a luminosity soft mask whose Form XObject /BBox was the rectangle spanned by the gradient axis (linear) or the enclosing square of the outer circle (radial). An axial shading is not confined to its axis rectangle, and a radial shading with /Extend extends beyond its circles; the RGB fill relies on that. A form's /BBox clips everything it paints and the luminosity backdrop is black (mask 0) outside it, so the translucent gradient was masked out entirely for a horizontal or vertical axis (zero-area box) and cropped otherwise. Give both soft-mask forms a large box covering the whole painted area, as hb_pdf_paint_sweep_gradient() already does, instead of the axis or circle box. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-3BXWX3QQ. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
105fb37749
commit
21fc7db92d
1 file changed
+18
-6
@@ -1115,9 +1115,17 @@ hb_pdf_paint_linear_gradient (hb_paint_funcs_t *,
|
||||
ash.append_str (">>");
|
||||
unsigned alpha_sh_id = res->add_object (std::move (ash));
|
||||
|
||||
/* An axial shading is not confined to the rectangle spanned by its axis:
|
||||
* it extends perpendicular to the axis, and along it with /Extend, and the
|
||||
* RGB fill relies on that. The soft-mask form clips the alpha shading to
|
||||
* its /BBox, so give it a large box covering the whole painted area (as
|
||||
* the sweep gradient does) instead of the axis box, which is zero-area for
|
||||
* a horizontal or vertical gradient and otherwise crops the fill. */
|
||||
const float R = 32767.f;
|
||||
float scx = paint->sx (gx0), scy = paint->sy (gy0);
|
||||
unsigned gs_idx = res->add_extgstate_smask (alpha_sh_id,
|
||||
paint->sx (gx0), paint->sy (gy0),
|
||||
paint->sx (gx1 - gx0), paint->sy (gy1 - gy0),
|
||||
scx - R - 1, scy - R - 1,
|
||||
2 * (R + 1), 2 * (R + 1),
|
||||
paint->get_precision ());
|
||||
body.append_str ("/GS");
|
||||
body.append_unsigned (gs_idx);
|
||||
@@ -1215,13 +1223,17 @@ hb_pdf_paint_radial_gradient (hb_paint_funcs_t *,
|
||||
ash.append_str (">>");
|
||||
unsigned alpha_sh_id = res->add_object (std::move (ash));
|
||||
|
||||
/* BBox: enclosing square of the outer circle. */
|
||||
/* The alpha shading extends beyond the circles with /Extend, and the RGB
|
||||
* fill relies on that, so the soft-mask form must cover the whole painted
|
||||
* area rather than just the enclosing square of the outer circle (which
|
||||
* crops the padded region). Use a large box as the sweep gradient does. */
|
||||
const float R = 32767.f;
|
||||
float cx = (gr1 >= gr0) ? gx1 : gx0;
|
||||
float cy = (gr1 >= gr0) ? gy1 : gy0;
|
||||
float rr = hb_max (gr0, gr1);
|
||||
float scx = paint->sx (cx), scy = paint->sy (cy);
|
||||
unsigned gs_idx = res->add_extgstate_smask (alpha_sh_id,
|
||||
paint->sx (cx - rr), paint->sy (cy - rr),
|
||||
paint->sx (2 * rr), paint->sy (2 * rr),
|
||||
scx - R - 1, scy - R - 1,
|
||||
2 * (R + 1), 2 * (R + 1),
|
||||
paint->get_precision ());
|
||||
body.append_str ("/GS");
|
||||
body.append_unsigned (gs_idx);
|
||||
|
||||
Reference in new issue
Block a user