* [raster] Fix background color premultiplication and stride handling
ensure_initialized()'s background fill had two bugs:
1. The background pixel was built with HB_COLOR(blue, green, red,
alpha), which packs channels through HB_TAG's bit layout
(b<<24 | g<<16 | r<<8 | a). Every other pixel in this buffer is
premultiplied BGRA32 (b | g<<8 | r<<16 | a<<24, see hb-raster.hh's
SRC_OVER comment: "premultiplied src over premultiplied dst"), so
the background was both unpremultiplied and in the wrong byte
positions: a half-transparent red background (blue=0, green=0,
red=255, alpha=128) filled the buffer with 0x0000ff80 instead of
the correct premultiplied 0x80800000.
2. The fill then wrote that pixel into a contiguous run of
width * height uint32_t slots starting at the buffer origin,
assuming every row is packed at exactly width * 4 bytes. Once a
caller sets a stride wider than that (row padding, alignment,
embedding the glyph image inside a larger atlas), the fill drifts
across row boundaries after the first row, leaving later rows
partially uninitialized or wrongly colored.
Build bg with color_to_premul_pixel(), the same helper solid fills
already use, and fill row by row using the actual stride.
Added two regression tests in test/api/test-raster.cc:
test_background_premultiplied (default stride, half-alpha background,
checks the stored pixel is premultiplied) and test_background_stride
(stride much wider than width * 4, opaque background, checks every
row).
Assisted-by: Claude
* [raster] Handle unaligned background strides
A caller-supplied stride does not have to be word-aligned, so casting
each row to uint32_t * can perform misaligned stores.
Use hb_packed_t<uint32_t> for the row writes, and exercise an odd
stride in the regression test with byte-wise pixel checks.
Tests: meson test -C build
Assisted-by: Codex <noreply@openai.com>
---------
Co-authored-by: Arthur031221 <levi74108520963@gmail.com>
The analytic rasterizer stored every row's area and cover in 32- and
16-bit accumulators. Highly overlapping outlines could exceed those
ranges and trigger signed overflow before coverage was clamped.
Keep compact SIMD accumulators for rows with at most 127 active edges.
Lazily use 64-bit scalar accumulators for denser rows, where the narrow
cover bound no longer holds. Add regressions for area overflow and
cover wrapping.
Tested with meson test -C build, the ASan/UBSan raster API test, all
raster fuzzer corpus chunks, and the supplied reproducer.
Assisted-by: OpenAI Codex <noreply@openai.com>
raster-paint reached into the rasterizer through two internal functions:
hb_raster_draw_set_external_work() to inject a shared work counter and
hb_raster_draw_get_edge_work() to read scanline cost back. Both are gone.
The paint session now carries two budgets for two different resources:
- The outline budget bounds glyph outline traversal and curve
flattening. It is the public draw/paint budget: raster-paint seeds the
rasterizer with hb_draw_set_budget() before each glyph and reads the
remainder back with hb_draw_get_budget_remaining(), so a whole COLR
walk shares one budget without touching rasterizer internals.
- The pixel budget bounds scanline and fill work, which scales with
surface area, not outline complexity. It is charged from the public
extents of the rendered mask (and other pixel areas) and keeps its
surface-sized default. An unlimited outline policy disables it too.
Folding pixel work into the outline budget was why the default had to be
inflated by the surface passes; the two now live apart, so HB_BUDGET_GLYPH
is a pure outline budget and the surface scaling belongs to the pixel
budget. Standalone hb_raster_draw is unchanged: it draws once, so its
scanline work needs no session budget, only its structural caps.
COLR drives only push_clip_glyph, whose seed/emit/readback is a single
self-contained step, so the aggregate outline budget is always conserved
across a COLR walk. The push_clip_path_start/end pair spans client draw
calls; like push/pop it must be balanced by the client for the outline
budget to reconcile, and each render is still bounded by the rasterizer's
structural caps regardless. hb_draw_set_budget() clamps a negative seed
to zero, so outline exhaustion does not latch across glyphs; an empty
mask can then be rendered once more, but that path is bounded by the
pixel budget.
Add a regression test that paints a real multi-layer COLR glyph into a
1x1 surface (unbounded pixel budget) and checks the outline budget both
aggregates the layers' work and bounds the walk.
Tests: meson test -C build (275/275 passed); the raster and gpu COLR
regression seeds complete in 0.40s and 0.44s.
Assisted-by: Claude <noreply@anthropic.com>
Store budget policy and live state on raster draw and paint contexts.
Make outline traversal and curve flattening borrow the paint session's
live counter, while standalone draw keeps its own finite session counter.
Preserve raster's dynamic surface-sized default, resolving it only after
initialization and never replacing concrete or unlimited client policy.
Recharge on clear and restore DEFAULT on reset. Add lifecycle and lazy
default coverage.
Tests: meson test -C build (273/273 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
* [raster] clamp coordinates before converting to int
the transformed glyph extents and the flattened segment endpoints are floats derived from int32 inputs and can land far outside the int range, so the conversions were undefined and the extent subtraction overflowed on top of that. saturate through a shared helper and widen the subtraction.
* [raster] generalize int32 saturating cast into hb_clamp_to<>
Move the raster-local hb_raster_clamp_to_int32 helper into hb-algs.hh
as a generic hb_clamp_to<T> that saturates a floating-point value to
the range of any integer type, and use hb_clamp_to<int32_t> at the
three raster call sites.
Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
---------
Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
The range test guarding the bilinear sampler is comparison-based, so NaN
coordinates pass it and reach (int) floorf() in
hb_raster_sample_bilinear_premul, where only x1/y1 are clamped. The
determinant guard has the same shape, so a transform that overflows to
infinity is accepted and 1/inf turns inf * 0 into NaN.
The six public draw / paint funcs getters across raster,
vector, and gpu used to be singletons:
hb_raster_draw_get_funcs (void)
hb_raster_paint_get_funcs (void)
hb_vector_draw_get_funcs (void)
hb_vector_paint_get_funcs (void)
hb_gpu_draw_get_funcs (void)
hb_gpu_paint_get_funcs (void)
That works fine for raster and gpu, where there's a single
backend per type, but breaks for the vector backend where
SVG and PDF have separate funcs sets — callers using the
public getter always got SVG funcs and silently produced
SVG markup inside PDF output streams when invoking the new
arbitrary-path clip API on a PDF context.
Make all six take a const-pointer to the relevant context
instance. vector_paint dispatches on paint->format; the
other five just use the instance for symmetry today (room
for future format-style dispatch later).
Also expose hb_vector_draw_get_format / hb_vector_paint_
get_format public getters so callers (or third parties)
can ask a vector context for its format without poking at
internals.
Also: hb_vector_paint_push_clip_path_end now wraps the
emitted SVG clipPath's path in transform="scale(1,-1)" so
free-form arbitrary clips at base body level land in the
same coord system the per-glyph <use scale(_,-sy)>
wrappers establish. Without this, free-form clip-path
arbitrary outlines emitted between paint_glyph calls came
out mirrored across the X axis.
Updates internal callers (hb_vector_paint_glyph,
hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_
start, hb_gpu_paint_push_clip_path_start, the GPU pen
adapter), util sites (raster-output.hh, vector-output.hh,
gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc),
and the docs section index.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove support for rendering glyphs whose source is the OpenType
SVG table, in both hb-raster and hb-vector. SVG is a large format
and our in-tree parser/renderer was half-finished; the complexity
was not justified by the partial coverage.
This is source-side only: hb-vector's SVG *output* backend (used
to serialize outline / COLR glyphs to SVG) is unaffected. Fonts
that have an SVG table will still load; glyphs served only by that
table will not render from these libraries.
hb-raster:
- Delete the hb-raster-svg-* file cluster (11 .cc/.hh files plus
hb-raster-svg.hh: parse, base, bbox, clip, color, defs,
defs-scan, fill, gradient, parse, render, use, context).
- Drop svg_glyph/svg_font/svg_palette state from
hb_raster_paint_t and the HB_PAINT_IMAGE_FORMAT_SVG branch in
the image callback.
- Drop hb_raster_paint_push_clip_path + hb_raster_svg_path_func_t
(only used from the SVG renderer).
- Drop zlib dependency (gzip decompression was only used for the
SVG table reader; libpng brings its own zlib linkage for PNGs).
hb-vector:
- Delete hb-vector-svg-subset.{cc,hh} (extracted font-SVG glyph
for embedding in SVG output).
- Remove the HB_TAG('s','v','g',' ') branch from the image paint
callback; PNG embedding remains.
- Drop svg_image tracking state from hb_vector_paint_t
(current_color_glyph_has_svg_image, current_svg_image_glyph,
current_face, svg_image_counter, subset_body_scratch).
- Simplify the color-glyph cache to store just def_id instead of
packed (def_id, image_like).
- Drop hb_svg_append_image_instance_translate.
Build wiring: src/meson.build, CMakeLists.txt, harfbuzz-world.cc
updated to match. Test suite: remove SVG-specific cases from
test/api/test-raster.cc and the handwriting-{svg,picosvg} vector
tests + expected fixtures.
~5700 LOC deleted, ~10 LOC added. Full test suite (240 tests)
passes.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The raster SVG image callback assumes hb_raster_paint_glyph()
seeded svg_font/svg_glyph state before the paint protocol
reaches HB_PAINT_IMAGE_FORMAT_SVG. Clients can also call
hb_font_paint_glyph_or_fail() directly with
hb_raster_paint_get_funcs(), which leaves svg_font unset and
crashes in hb_raster_svg_render().
Return false when the callback is reached without that
wrapper-only state, and cover the direct API path with a
regression test.
Testing: CCACHE_DISABLE=1 meson test -C build
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-ggh9-cgg2-r4vr
Assisted-by: OpenAI Codex <codex@openai.com>
The raster SVG path treated hb_ot_color_glyph_reference_svg()
blobs as plain XML, even though SVG table documents may
legally be gzip encoded. That caused hb-raster to reject
fonts that store compressed SVG documents.
Detect gzip payloads in the raster SVG renderer, reject
documents whose advertised uncompressed size exceeds
HB_SVG_MAX_DOCUMENT_SIZE, and inflate the rest through
zlib while keeping the same size cap enforced during
decompression. Plain SVG documents are also bounded by the
same 16 MiB limit.
Add a raster API regression that renders the existing
plain and compressed noto_handwriting SVG fixtures and
verifies identical output.
Testing:
- meson test -C build
Assisted-by: OpenAI Codex
Remove hb_raster_extents_from_glyph_extents and switch callers to the new transform-aware set_glyph_extents APIs on raster draw/paint. Also add test coverage for transformed glyph extents and update section symbol listings.
Renders glyph IDs 2-5 from fonts/adwaita.ttf at upem scale, writes
PGMs to /tmp/ for visual inspection, and asserts non-zero coverage.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix out-of-bounds pixel write in rasterize_tile: border tiles that
extend past the image edge were writing px-x_origin beyond the row
stride, wrapping into the start of the next row and overwriting
correctly-rasterized pixels with zero. Pass px1/py1 (exclusive
bounds) to rasterize_tile and clip the pixel loops accordingly.
Also: drop unused ex0 in pass 2 of tile assignment; move test-raster
from src/ to test/api/ and convert it to the GLib g_assert/hb_test_add
framework.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>