Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
Add focused API tests for hb_buffer_create_similar() and buffer
configuration persistence across clear/reset. Also exercise public hb_map
copy, equality, hash, update, iteration, keys, and values paths with
order-independent assertions.
Validation:
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer
meson test -C build-tgl-precheck --print-errorlogs --suite api test-map
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer test-map
Assisted-by: OpenAI Codex <codex@openai.com>
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
* [fontations] Fix OOB write on glyph-name callback with size == 0
The Rust `_hb_fontations_glyph_name()` callback computed
`glyph_name.len().min(size as usize - 1)`. When a caller passed
`size == 0`, `size as usize - 1` underflowed a `usize` to
`usize::MAX`, the `min()` clamp collapsed to `glyph_name.len()`,
and the subsequent `copy_nonoverlapping` / trailing NUL wrote
`glyph_name.len() + 1` bytes into a zero-capacity caller buffer.
This is an out-of-bounds write reachable from the public API
whenever the build was configured with `-Dfontations=enabled`
and the application had called `hb_fontations_font_set_funcs()`.
Short-circuit the `size == 0` case before the subtraction.
Return `true` in that case to match the existing post and CFF1
backends (`hb-ot-post-table.hh`, `hb-ot-cff1-table.hh`), which
both early-out with `return true` on `!buf_len` — the glyph
does have a name; we simply had no buffer to write it into.
Regression tests added in `test/api/test-glyph-names.c` cover
the zero-size path on post and CFF1 backends, a sub-font, a
NULL buffer, and `size == 1` / small-buffer / exact-fit cases
so the truncation path does not silently regress.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5946
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Reject glyph-name lookups with size == 0 at the wrapper
`hb_font_t::get_glyph_name()` previously pre-wrote the trailing
NUL only when `size != 0` but still dispatched to the backend
callback with `size == 0`. Every current glyph-name backend has
to re-validate that argument: `post` and `cff1` short-circuit
with `return true`, the new Rust `fontations` callback now
short-circuits too (prior commit), and the CoreText callback in
`hb-coretext-font.cc` has a structurally similar `(CFIndex)size
- 1` pattern.
Normalize this at the wrapper layer: return `false` immediately
on `size == 0`, before any backend dispatch and before the
`*name = '\0'` write. This makes the zero-size case a single,
auditable no-op for every glyph-name provider (native or Rust,
current or future) and removes the CoreText underflow from the
reachable surface through the same chokepoint.
Observable change: callers that invoked
`hb_font_get_glyph_name(font, gid, buf, 0)` on post/cff1 backed
fonts used to get `true` back; they now get `false`. `size == 0`
queries carry no useful information for the caller, so this is
considered a safe hardening rather than a contract break.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Preserve glyph-name zero-size probe semantics
Keep `hb_font_get_glyph_name(..., NULL, 0)` as a valid
return-value-only probe instead of rejecting `size == 0` in the
wrapper.
Fix the remaining backend-specific zero-size paths in hb-ft and
hb-coretext-font so they answer the probe without dereferencing the
caller buffer, and update the API tests to assert the preserved
behavior.
Testing: CCACHE_DISABLE=1 meson test -C build test-glyph-names
Testing: CCACHE_DISABLE=1 meson test -C build test-ft
Assisted-by: OpenAI Codex <codex@openai.com>
---------
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
push_clip_glyph kept a hash + linear-scan cache of emitted
clip paths to dedup repeated clip-glyph uses within a single
COLRv1 paint tree. With paint contexts being one-glyph per
use, the cache mostly churned; it also made hb_memcmp trip
on sanitizer-null when an empty path matched an equally-empty
existing entry (fuzzer-reached null-deref).
Drop the cache: always emit a fresh <path> + <clipPath> pair
per push_clip_glyph. Removes defined_paths / content_entry_t
from the paint struct.
Regenerate the two handwriting COLR expected SVGs whose
clip-reuse now produces distinct path defs.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
include_point used to flip Y so the computed line-box extents
matched the old Y-down internal model. With the library now
tracking extents in Y-up (font) space and wrapping SVG body
in <g transform="scale(1,-1)">, that flip sent the auto-fit
viewBox above the glyph ink instead of around it.
Regenerate the vector expected SVGs that had captured the
shifted viewBox.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SVG render now wraps all body content in a single
<g transform="scale(1,-1)">. All coordinates inside are
in Y-up (font) space. The viewBox maps the flipped range.
This eliminates:
- Per-path scale(1,-1) wrappers in draw flush_path_svg
- Per-glyph Y-flip in paint _glyph_impl's push_transform
- The {-xy, -yy, -ty} negation in extents transforms
- Format switch in paint _glyph_impl
paint _glyph_impl now passes the raw transform to
push_transform — no format knowledge needed.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove content-based color glyph dedup from paint — no more
<defs>/<use> for color glyphs. Each glyph's paint output is
emitted inline, wrapped by push_transform/pop_transform from
the paint funcs (which emit <g transform="..."> for SVG and
q cm ... Q for PDF).
_glyph_impl is now format-agnostic: extend extents,
push_transform, paint, pop_transform.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove format switch from _glyph_or_fail — it now just extends
extents, calls hb_font_draw_glyph with the context's own funcs,
and flushes. All format-specific work is in flush_path() and
the draw callbacks.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Draw SVG output is now flat inline <path> elements — no
<defs>, no <use>, no id references. Each glyph is an
independent <path d="..." transform="..." fill="..."/>.
Remove hb_vector_draw_set_svg_prefix / get_svg_prefix since
draw output no longer emits any ids. Paint keeps svg_prefix
for gradient and clip ids which SVG requires.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These are convenience APIs, not typesetting APIs — positioning
is the caller's responsibility via set_transform(). This
matches the GPU API which never had pen parameters.
All callers updated to use set_transform with pen position
before each _glyph call.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace glyph-ID-based dedup with content-based dedup for SVG
path definitions and color glyph groups. Path/paint output is
hashed and compared byte-for-byte against existing defs;
identical content reuses the same def regardless of glyph ID.
This eliminates the font reference held by draw/paint contexts
(cached_font + hb_font_reference), which was keeping the font
and its face alive longer than the caller expected. No font
pointer is stored at all now.
Also removes changed() — with content-based dedup, foreground
and palette changes produce different content that naturally
won't match cached entries.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Malicious fonts with extreme scale values cause huge pixel
buffer allocations across multiple push_group surfaces. The
library correctly bounds individual surfaces at 1 GB, but
stacked group surfaces can exceed the fuzzer RSS limit.
Cap the font scale to 1000 in the harness so the exercised
surface stays within fuzzer memory constraints.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When clip nesting exceeds HB_GPU_PAINT_MAX_CLIP_DEPTH (3),
push_clip_glyph sets unsupported=true but still increments
clip_depth. emit_all_clip_sub_blobs then iterated clip_depth
without capping, reading past the fixed-size clip_stack array.
Cap the iteration at HB_GPU_PAINT_MAX_CLIP_DEPTH.
Fixes: https://oss-fuzz.com/testcase-detail/6573156621156352
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Scale all SVG paint and draw coordinates by 1/scale_factor
so paths, clips, gradients, transforms, and images emit
fractional pixel values instead of font-scale integers.
The per-glyph <use> transform now applies only a Y-flip
(scale(1,-1)) instead of scale(1/sf,-1/sf), since the
content is already in output-space.
Revert the 1000000 fill rect bandaid back to 32767 — in
output-space, 32767 pixels is always large enough.
SVG paint callbacks:
- push_clip_glyph: path sink divides by scale_factor
- push_clip_rectangle: coords divided by sx/sy
- push_transform: translation (dx,dy) divided by sx/sy
- gradient coords: divided by sx/sy
- sweep center: divided by sx/sy
- image extents: divided by sx/sy
SVG draw:
- Glyph outline path sink divides by scale_factor
Regenerated all vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SVG and PDF paint backends use large clipped rectangles
to fill solid colors and gradient backgrounds. The old
constant 32767 was sized for upem-space coordinates (~2048
max). After the pixel-space change, coordinates can be in
font-scale (upem * SCALE, e.g. 131072 for a 2048-upem font
at SCALE=64). Values above 32767 fell outside the fill
rect, causing COLRv0 glyph layers to be clipped at the top.
Bump all instances to 1000000 as a bandaid; proper fix is
to emit paint coordinates in output-space.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The paint SVG backend bakes all colors directly — no CSS
var(--hb-...) references remain in the output. So the util's
SVG parser, var resolver, palette cache, and slice_svg
infrastructure are all dead code.
write_blob is now just fwrite.
Removes ~340 lines: slice_svg, write_slice_resolving_palette_vars,
parse_var_color_expr, find_next_var_expr, find_matching_paren,
emit_css_color, lookup_palette_color, init_palette_color_cache,
skip_ascii_ws, trim_ascii_ws_right, parsed_var_color_expr_t,
and associated palette cache state.
Regenerated vector test expected outputs (color font SVGs
now emit directly without var resolution pass).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Now that the draw library handles per-glyph foreground fills
and background rects, the util no longer needs to parse and
re-emit SVG for draw blobs. Draw blobs are written directly
to the output file, same as PDF.
Paint SVG still needs var(--hb-...) resolution, so paint
blobs go through the existing write_slice_resolving_palette_vars
path.
Removes ~120 lines: emit_fill_group_open/close,
emit_draw_body_with_palette, emit_fill_stroke_attrs_for_color,
emit_stroke_attrs, and the draw-specific branches in write_blob.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hb_vector_draw_set_{foreground,background}() and getters.
SVG: foreground wraps body in <g fill="rgb(...)">; background
emits a <rect> covering the viewBox before content.
PDF: foreground sets fill color via rg operator before glyph
content; background emits a filled rect at the start of the
content stream.
Default: foreground opaque black, background transparent.
Wire both into the hb-vector CLI util alongside the paint
equivalents. Remove the old util-side emit_background_rect.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The vector util was creating a separate upem-scaled font clone,
converting all shaping positions from font-scale to upem, and
setting scale_factor to upem/font_size to undo that on emit.
Simplify: use the caller's font directly. Positions from
shaping are stored as-is (in font-scale = pixel * SCALE).
scale_factor is just SCALE (= 1 << subpixel_bits), so the
lib divides by SCALE on emit to produce pixel-space output.
This removes ~40 lines: the upem_font creation, variation
coord copying, scale_to_upem_x/y helpers, and the complex
upem_per_pixel margin/stroke conversions. Margin conversion
simplifies from margin * upem * SCALE / x_scale to just
margin * SCALE.
Regenerated vector test expected outputs for the new
coordinate space.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
API rename for the not-yet-released stroked/filled
rectangle helper added to hb-draw — full names
(hb_draw_line, hb_draw_circle, hb_draw_rectangle) read
better than mixed full/abbreviated.
Updates the public header, impl, the gpu doc reference,
the GPU API test, the GPU demo's extents overlay, the
extents-overlay paint helper, and the docs section
listing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Folded into the existing test-paint binary. Two tests,
both font-independent (registered ahead of the glyph-based
flavor setup so they run even on builds without the test
COLRv1 font):
* test_push_clip_path_nil_returns_null: an unset paint-funcs
table returns NULL from push_clip_path_start and clears
the out-param draw_data, and push_clip_path_end is safe
to call on the nil stub.
* test_push_clip_path_round_trip: registered start/end fire
in order, the returned draw-funcs + draw-data round-trip
through the public entry points, and every hb_draw_*()
call reaches the sink accumulator. Asserts the count
includes hb_draw_close_path's synthetic back-to-start
line_to so the contract is documented by the test.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Consolidate the {vector,raster,gpu}_{draw,paint}_glyph APIs
to match the hb_font_{draw,paint}_glyph / _or_fail pattern:
* Each existing *_glyph() public function now returns void.
For the draw variants this is purely a return-value drop.
For the paint variants the void entry additionally gains a
synthesize fallback for non-color glyphs (calls
hb_font_paint_glyph instead of _or_fail) so a mono glyph
still produces output via a foreground-colored outline.
* New *_glyph_or_fail() variants return hb_bool_t, reporting
exactly what hb_font_{draw,paint}_glyph_or_fail() would.
Callers that care about distinguishing color paint from
synthesized outline now have a clean boolean signal.
Refactors the internal impls behind a shared static helper
parameterised by a `fallible` flag; the two public entries
delegate, passing true (for _or_fail) or false (for the void
alias).
For GPU specifically, paint_glyph_or_fail no longer folds the
encoder's unsupported flag into its return -- that state was
always better reported from hb_gpu_paint_encode() (which
returns NULL), and conflating the two prevented callers from
telling "font has no paint data" from "encoder hit a limit".
While in there, remove a dead branch at the end of
hb_vector_paint_glyph's SVG case (both inner blocks had
already returned; the tail was unreachable).
Updates docs/harfbuzz-sections.txt with the six new symbols
and the NEWS note with the Changed API callouts. Updates
in-tree callers (hb-vector-svg-all, hb-raster-all, test-gpu,
util/vector-output.hh) to the _or_fail variants where they
previously read the return value.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5926
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [gpu] Add hb_gpu_draw_line / _rect / _circle shape helpers
The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:
hb_gpu_draw_line (draw, x0,y0,w0, x1,y1,w1);
hb_gpu_draw_rect (draw, x,y,w,h, stroke_width);
hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);
stroke_width = NaN means "filled". A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.
For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.
Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.
Assisted-by: Claude <noreply@anthropic.com>
* [util/gpu] Add --show-extents flag
Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.
The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).
Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.
Assisted-by: Claude <noreply@anthropic.com>
* [util/gpu] Cmdline toggles mirroring interactive keybindings
Add --dark / --no-vsync / --fullscreen / --no-stem-darken /
--debug so scripts and CI can start hb-gpu in any of the
states previously reachable only by pressing a key
interactively. Applied via the same keystroke path by
synthesizing the corresponding key characters through
demo_view_type() at startup -- single source of truth for
each toggle.
Assisted-by: Claude <noreply@anthropic.com>
* [draw] Promote shape helpers from hb-gpu-draw to hb-draw
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend. Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.
API rename / move:
hb_gpu_draw_line -> hb_draw_line (in src/hb-draw.h)
hb_gpu_draw_rect -> hb_draw_rect
hb_gpu_draw_circle -> hb_draw_circle
Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.
Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.
Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.
Assisted-by: Claude <noreply@anthropic.com>
* [draw] hb_draw_line: NaN second width defaults to first
Common case is a uniform-width line. Letting @w1 default to
@w0 when NaN is passed makes the call shorter:
hb_draw_line (..., x0, y0, 4, x1, y1, NAN); /* uniform 4 */
Mirrors the NaN-as-sentinel convention used in hb_draw_rect /
hb_draw_circle for the stroke_width parameter.
Assisted-by: Claude <noreply@anthropic.com>
* [draw] hb_draw_line: add cap parameter (butt / square)
Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.
Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.
Round caps not implemented yet; can be added as a third enum
value when a use case shows up.
Assisted-by: Claude <noreply@anthropic.com>
SVG <stop offset="..."> requires offsets in [0, 1]. Out-of-
range stops were silently clamped by browsers, producing
visually wrong gradients for COLR fonts whose color lines
extend past those bounds.
Use the centralized hb_paint_normalize_color_line() to rescale
stops in place; shift the gradient axis (linear) / centers and
radii (radial) / start+end angles (sweep) by (mn, mx) along
the gradient axis to keep the visible gradient in the same
place.
Drop the now-unused local hb_vector_color_stop_cmp -- the
shared normalize helper sorts internally.
Regenerate the two affected basic.tests expected SVGs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb-vector-paint emitted (2*x1 - x2, 2*y1 - y2) as the SVG end
point -- the reflection of P2 about P1, not the projection.
For COLR linear gradients the SVG end should be P1 projected
onto the line through P0 perpendicular to (P2 - P0); that's
the gradient's actual axis (perpendicular to the rotation
line). With the old formula, fonts with rotation references
far from the color line ended up with massively over-scaled
gradient axes -- e.g. BungeeSpice's ABC showed solid red where
raster shows a full red->yellow gradient.
Add hb_paint_reduce_linear_anchors() to hb-paint.hh as the
shared canonical implementation (matches hb-raster-paint and
hb-cairo) and use it from hb-vector-paint.
Regenerate the two affected basic.tests expected SVGs; the
new gradient endpoints are now consistent with the cairo /
raster outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output. Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache. No remaining callers in
tree (util/vector-output.hh's --flat option goes too).
Removes:
- hb_vector_draw_set_flat / get_flat
- hb_vector_paint_set_flat / get_flat
- the `flat` field on both contexts
- all `if (flat)` / `bool can_cache = !flat` branches
- the --flat option in util/vector-output.hh
- the four "flat*" expected files in test/vector/basic
- the flat_draw / flat_paint params in the vector fuzzer
- sections-list entries
meson test --no-rebuild green (241/241).
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.
Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.
Round caps not implemented yet; can be added as a third enum
value when a use case shows up.
Assisted-by: Claude <noreply@anthropic.com>
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend. Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.
API rename / move:
hb_gpu_draw_line -> hb_draw_line (in src/hb-draw.h)
hb_gpu_draw_rect -> hb_draw_rect
hb_gpu_draw_circle -> hb_draw_circle
Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.
Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.
Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.
Assisted-by: Claude <noreply@anthropic.com>
The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:
hb_gpu_draw_line (draw, x0,y0,w0, x1,y1,w1);
hb_gpu_draw_rect (draw, x,y,w,h, stroke_width);
hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);
stroke_width = NaN means "filled". A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.
For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.
Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.
Assisted-by: Claude <noreply@anthropic.com>
Three accumulator vectors -- ops, sub_blobs, transform_stack --
can enter error state via failed push_or_fail() under
failing-malloc. Once in error state, resize(0) short-circuits
at the in_error() guard in alloc() and leaves length unchanged.
In hb_gpu_paint_clear that means the next iteration's clear
walks the stale entries again. For sub_blobs this is a
double-destroy: the blob pointers were already freed in the
previous clear, and hb_blob_destroy reads the dead ref_count
field -- heap-use-after-free.
Fix by calling vector.reset(), which clears the error state
before resizing to 0. Matches the pattern hb_gpu_draw_clear
already uses for draw->curves.
Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer; minimized testcase
added to the fuzz corpus.
Assisted-by: Claude <noreply@anthropic.com>
Two sites queried color-stop count, resized the scratch vector to
match, then called hb_color_line_get_color_stops() passing the
requested count as the write capacity. If the resize() failed
(OOM), the vector stayed at its previous (smaller) length while
the callee still wrote the full requested count -- heap-buffer-
overflow.
Fixed by checking resize() and bailing: build_gradient_function
returns 0, paint_sweep_gradient returns. Matches the pattern
already used in hb-raster-paint.cc and hb-vector-paint.cc.
Found by oss-fuzz/CIFuzz on hb-vector-fuzzer against a sweep-
gradient COLRv1 glyph under failing-malloc.
Assisted-by: Claude <noreply@anthropic.com>
hb_gpu_draw_encode already returns the empty-blob singleton (not
NULL) when the encoder has accumulated no curves -- the convention
is "NULL = encoder failed, empty blob = nothing to render".
Make hb_gpu_paint_encode follow the same shape:
- NULL -> hard failure (paint_glyph hit an unsupported feature
or allocation failed).
- empty -> no ink (e.g. space glyph or paint tree that produced
no layer ops).
Document on both encode functions, and update the tests to expect
empty (not NULL) for the no-ink path.
The demo already short-circuits on length 0 (no atlas upload) and
_hb_gpu_blob_recycle drops the empty singleton instead of stashing
it, so nothing downstream needs to change.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Paint encoder used to push past several limits and produce a blob
that wraps an int16, overflows the shader's group stack, or skips
unsupported callbacks entirely. Detect each:
- num_ops > 32767 (the i16 blob header field's range): set
paint->unsupported in every emit path.
- group depth > HB_GPU_PAINT_MAX_GROUP_DEPTH (4 -- matches the
fragment shader's HB_GPU_PAINT_GROUP_DEPTH): set unsupported
in push_group; mirror the symmetric pop guard.
- PaintImage: register an `image` callback that sets unsupported
(the slug+gradient encoder can't represent raster images).
push_clip_rectangle is intentionally NOT trapped -- the encoder
silently ignores it; rendered output is wider than the rectangle
asks but doesn't fail.
Nested PaintGlyph clips still silently override the outer clip
(only depth 1 is faithfully stored); follow-up commit will lift
this to depth 2.
Document all of the above in NEWS, and relax the COLR test to
tolerate a font where every glyph trips one of these limits.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Casting hb_blob_get_data()'s const char* to a struct pointer
trips clang's -Wcast-align (1-byte to 2-byte short). In practice
the blob's underlying buffer is malloc'd and so suitably aligned
for any standard type; suppress the warning around the cast with
the same #pragma GCC diagnostic ignored "-Wcast-align" pattern
used elsewhere in the codebase (hb-bit-set.hh, hb-machinery.hh).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The existing hb-gpu-fuzzer only exercised hb_gpu_draw. Add a
parallel paint round-trip per glyph (paint_glyph -> encode ->
recycle_blob) so the paint encoder gets the same fuzzed-input
coverage -- gradient / transform / composite parsing in
particular has a lot more surface than the slug encoder.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
test/api/test-gpu: extends the existing draw test suite with
paint counterparts -- create/destroy, get_funcs singleton,
shader_source for all four langs, empty encode returns nullptr,
encode of a monochrome glyph (synthesized single-layer fallback),
encode of a real COLRv1 glyph (test_glyphs-glyf_colr_1.ttf,
scanning for a glyph our encoder fully supports), auto-clear on
encode, reset wipes config, recycle_blob roundtrip.
perf/benchmark-gpu: add BM_GpuPaintEncode parallel to
BM_GpuDrawEncode (renamed from BM_GpuEncode for symmetry) so the
two paths can be compared on the same fonts.
NEWS: draft entry under "leading to NEXT (REPLACEME)" listing the
new hb_gpu_paint_* API surface and the recent GPU library changes
(--draw / --paint flags, gradient inverse-transform). Release
manager will fold this into the actual release section.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The draw-renderer fragment shaders defined utilities
(HB_GPU_UNITS_PER_EM, the hb_gpu_atlas uniform, hb_gpu_fetch) that
any future GPU renderer will also need. The draw-renderer vertex
shader likewise contained only the generic hb_gpu_dilate helper.
If a paint renderer were added today and a caller linked both
fragment sources together, hb_gpu_fetch would be defined twice.
Move these shared helpers into a new family of sources and expose
them via a new public entry point:
hb_gpu_shader_source (stage, lang);
The existing hb_gpu_draw_shader_source() now returns only the
draw-specific fragment code; it returns an empty string for the
vertex stage because all current vertex logic is shared. Callers
concatenate the shared source first, then the draw-specific
source, then their own main():
[#version, hb_gpu_shader_source (...), hb_gpu_draw_shader_source
(...), main]
Additions:
- src/hb-gpu-fragment.{glsl,msl,wgsl,hlsl} — shared fragment
- src/hb-gpu-vertex.{glsl,msl,wgsl,hlsl} — shared vertex,
renamed from hb-gpu-draw-vertex.*
- src/hb-gpu-shaders.cc — hb_gpu_shader_source() dispatcher
Removals:
- src/hb-gpu-draw-vertex.{glsl,msl,wgsl,hlsl} — moved to common
Shared sources are Behdad-only copyright; the Eric Lengyel / Slug
attribution stays on the draw-specific fragment sources where the
Slug algorithm actually lives.
Updates: test/api/test-gpu.cc, the Metal/D3D11/WebGPU/GL demo
shaders, the hb-gpu SECTION documentation, meson.build,
CMakeLists.txt, gen-gpu-shader-artifacts.py decl_map,
harfbuzz-world.cc, and docs/harfbuzz-sections.txt.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_raster_paint_glyph() took the palette index and foreground
color as per-call arguments, duplicating state that also lives on
the paint context (foreground via hb_raster_paint_set_foreground,
palette previously only available as a per-call arg). This gave
callers two paths for configuring the same state.
Drop the per-call palette/foreground arguments and require callers
to configure them via setters before painting, matching the
already-established pattern in hb_vector_paint_glyph() and
elsewhere in the subsystem.
- Drop palette and foreground args from hb_raster_paint_glyph().
- Add hb_raster_paint_set_palette() / _get_palette() and a
hb_raster_paint_get_foreground() companion.
- Store palette on hb_raster_paint_t (default 0).
- Update util/raster-output.hh, util/hb-raster-all.cc, and
test/fuzzing/hb-raster-fuzzer.cc to the new API.
- Update the hb-raster section-doc example.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the two separate getters
hb_gpu_shader_fragment_source (lang)
hb_gpu_shader_vertex_source (lang)
with a single
hb_gpu_draw_shader_source (stage, lang)
where stage is the new hb_gpu_shader_stage_t enum (VERTEX or
FRAGMENT). Parameter order is stage-first because "the vertex
shader in GLSL" reads more naturally than the reverse, and stage
is the primary axis (it determines which shader object the source
is compiled into).
The `_draw_` in the new name makes room for the incoming
hb_gpu_paint_shader_source() once the COLRv1 encoder lands —
that family will have its own (likely different) shader sources
per stage and language.
Updated the four in-tree callers: test/api/test-gpu.cc, and the
GPU demos under util/gpu/. ABI break on a 14.0-only API; the
gpu library is still young enough that this is acceptable.
Marked new API with XSince: REPLACEME.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously only HB_VECTOR_FORMAT_SVG was fuzzed. Factor the
create/paint/render body into a helper and call it twice per
input — once for SVG, once for PDF — so the PDF-specific code
paths get the same coverage:
- PDF content-stream encoder
- Type 2/3 shading + stitching function builder
- Type 6 Coons-patch sweep gradient encoder (hb_pdf_add_sweep_patch)
- PNG IDAT passthrough
- Indexed-PNG SMask builder (hb_pdf_build_indexed_smask, zlib inflate
+ PNG un-filter + palette-to-alpha mapping)
Input-fuzzed knobs (precision, flat-draw, flat-paint) are shared
between the two formats.
Smoke-tested on a handful of existing fuzzing/fonts corpus entries;
all pass clean.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).
HB_EXTERN hb_blob_t *
hb_gpu_draw_encode (hb_gpu_draw_t *draw,
hb_glyph_extents_t *extents);
Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.
Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant. The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.
ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.
All 240 tests pass.
Assisted-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>