Commit Graph
20668 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 f2eb9d58bc [gpu] Reduce default perspective in demo
The large default text block looked too distorted with
perspective=4.  Use 16 for a flatter initial view.
The user can still adjust with Shift+right-drag.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 18:38:27 -06:00
Behdad EsfahbodandClaude Opus 4.6 e4c174015f [gpu] Rename u_atlas uniform to hb_gpu_atlas
Namespace the GLSL uniform to avoid conflicts with user code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:21:27 -06:00
Behdad EsfahbodandClaude Opus 4.6 0582846c08 [gpu] Simplify shader API: return single string per language
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *.  Each language variant is one complete string.

Simplifies the demo shader compilation and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:10:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 77f7bde2a6 [gpu] Add comprehensive shader and rendering documentation
Document the full GPU rendering pipeline in the SECTION doc:
atlas setup, shader compilation, vertex attributes (position,
texcoord, normal, jac), hb_gpu_dilate usage, hb_gpu_render
usage, and typical vertex/fragment shader mains.

Note that this implements the Slug algorithm by Eric Lengyel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:06:15 -06:00
Behdad EsfahbodandClaude Opus 4.6 25e69d9b96 [gpu] Port hb-gpu-demo to options.hh infrastructure
Replace the manual getopt-based demo main with the standard
main_font_text_t / shape_consumer_t composition, getting all
harfbuzz options for free: --variations, --features, --script,
--direction, --face-index, --font-funcs, etc.

New gpu_output_t (in util/gpu-output.hh) implements the output
interface, feeding shaped glyphs to the demo's GL renderer.

Add demo_buffer_add_glyph() and demo_buffer_current_line() to
demo-buffer for glyph-at-a-time insertion (vs the old batch
add_text which did its own shaping).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 16:34:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 3ab11b19b6 [gpu] Clean up doc prose; add sample code to section doc
Remove stray "glyph" from doc comments where it referred to
the encoder rather than an actual glyph.  Add typical usage
example to the SECTION doc block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:45:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 89ef51691b [gpu] Add GPU encode fuzzer
Encodes up to 16 glyphs per fuzzed font input, exercising
draw accumulation, cu2qu, encode, extents, and blob recycling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:18:47 -06:00
Behdad EsfahbodandClaude Opus 4.6 686f3caa86 [gpu] Implement blob recycling in encode
recycle_blob stores the blob; encode reuses both the blob object
and its data buffer when the buffer is >= needed and < 2x needed.
Otherwise malloc fresh and replace_buffer on the recycled blob.

hb_blob_t::replace_buffer now skips destroy_user_data when the
new data pointer is the same as the old one (same-buffer reuse).

Add explicit destructor to hb_gpu_draw_t for recycled_blob cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 15:13:44 -06:00
Behdad EsfahbodandClaude Opus 4.6 9b918c5f77 [gpu] Use clear() instead of shrink(0) for curves on reset
shrink(0) frees the allocation; clear() keeps it.  Avoids
re-allocation on every encode cycle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:38:54 -06:00
Behdad EsfahbodandClaude Opus 4.6 023380343d [gpu] Use uint16 offset range via int16 bias trick
Store blob offsets as value-32768 in the signed int16 texel
fields; the shader recovers with +32768.  This doubles the
maximum blob size from 32767 to 65535 texels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:36:58 -06:00
Behdad EsfahbodandClaude Opus 4.6 6d355dddce [gpu] Report sizes in KiB in hb-gpu-encode-all
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:31:36 -06:00
Behdad EsfahbodandClaude Opus 4.6 76eb0ae60f [gpu] Detect degenerate cubics in cu2qu and emit lines
Cubics with collinear control points (common in CJK fonts)
caused cu2qu to subdivide to max depth, generating up to 1024
line segments per cubic.  Detect the collinear case early
using cross-product distance and emit a single line instead.

Fixes encode failure for NotoSerifCJK gid 897 (48 cubics
were producing 24672 quadratics; now produces 48 lines).
Reduces total encode size for the font by ~34%.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:29:19 -06:00
Behdad EsfahbodandClaude Opus 4.6 198dc300d0 [gpu] Add hb-gpu-encode-all utility
Encodes all glyphs in a font, reports failures and summary
statistics (encoded/empty/failed counts, total and average sizes).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:19:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 4b9ef70d85 [post] Fix glyph name sort direction for std::sort
The old cmp_gids comparator produced descending order due to
hb_array_t::cmp's reversed memcmp argument order.  This
happened to work with hb_qsort on Linux but broke with
std::sort on other platforms since bsearch expects ascending.

Switch to find_glyph_name(a).cmp(find_glyph_name(b)) > 0
which sorts ascending, matching what cmp_key expects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:13:53 -06:00
Behdad EsfahbodandClaude Opus 4.6 f82046bb01 [gpu] Use arrayZ[] for unchecked scratch vector access in encode
All indices are guaranteed in-range by construction.  Bypass
operator[] bounds checking for the hot encode loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:02:35 -06:00
Behdad EsfahbodandClaude Opus 4.6 52bb8a8304 [post] Break ties by gid in glyph name sort
std::sort is not stable — when two gids have the same name,
their relative order was undefined, causing the wrong gid to
be found by binary search on some platforms.

Break ties with the gid value itself to make the order
deterministic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:46:50 -06:00
Behdad EsfahbodandClaude Opus 4.6 a32cd49bc4 [gpu] Add encode scratch buffers to avoid per-call allocation
Embed hb_gpu_encode_scratch_t in hb_gpu_draw_t with all the
temporary vectors the encoder needs.  They persist across
encode calls and only grow, never shrink — eliminating
malloc/free overhead after the first glyph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:46:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 52f0115c0f [algs] Use std::sort in hb_array_t::qsort; simplify hb_qsort
hb_array_t::qsort(Compar) now uses std::sort for typed, inlineable
sorting.  The no-arg qsort() uses priority dispatch: std::sort for
move-assignable types, hb_qsort fallback for packed OT structs
with deleted move ops.

hb_qsort itself is simplified to just forward to system qsort().
sort_r_simple is retained as fallback when qsort is unavailable.

Convert all direct hb_qsort callers to use typed array qsort with
lambdas.  Remove dead comparator functions.

225 tests pass, 0 failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 13:14:56 -06:00
Behdad EsfahbodandClaude Opus 4.6 df433afe6c [algs] Simplify hb_qsort: single template, inline all callers
Reduce to one templated hb_qsort, one templated qsort() on
hb_array_t/hb_vector_t, plus the no-arg qsort() that casts
Type::cmp to resolve ambiguity.

Convert all external call sites to lambdas so comparators
inline everywhere.  Remove the void*-arg overload and the
plain function-pointer overload.

225 tests pass, 0 failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 12:50:30 -06:00
Behdad EsfahbodandClaude Opus 4.6 05762b2fac [algs] Template hb_qsort comparator for inlining
Make sort_r_simple and sort_r_cmpswap take the comparator as a
template parameter instead of a function pointer.  This allows
lambdas and functors to inline into the sort, avoiding the
indirect-call overhead.

The function-pointer overloads remain for backward compatibility
and for the __OPTIMIZE_SIZE__ / qsort_r paths.

17% speedup on GPU encode benchmark (NotoSansCJK).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 12:36:59 -06:00
Behdad EsfahbodandClaude Opus 4.6 583b13d95c [gpu] Fix stale parameter names in header; add section doc
Three declarations in hb-gpu.h still had *glyph instead of *draw.
Add SECTION doc block in new hb-gpu.cc for gtk-doc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:33:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 971e607319 [gpu] Add API test and google-benchmark encode benchmark
test-gpu: 7 subtests covering create/destroy, empty encode,
glyph encode, reset, draw funcs singleton, shader sources,
and recycle_blob.

benchmark-gpu: benchmarks draw, encode, and draw+encode
per-glyph across several fonts using google-benchmark.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:27:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 33ad6419e3 [gpu] Remove std::sort; add qsort with context to hb_array_t
Add an hb_array_t::qsort overload that takes a comparator with a
void* context argument, forwarding to hb_qsort's existing qsort_r
support.  Use it in the GPU encoder to eliminate the last std::
usage from library code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:48:10 -06:00
Behdad EsfahbodandClaude Opus 4.6 f5f6e90703 [gpu] Replace std:: with hb equivalents in encode
Use hb_min/hb_max instead of std::min/std::max, and
INT16_MIN/INT16_MAX instead of std::numeric_limits.
Only std::sort remains (needs lambda captures).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:43:45 -06:00
Behdad EsfahbodandClaude Opus 4.6 d9a81a9cc5 [gpu] Add hb-gpu to docs sections and docs index
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:40:13 -06:00
Behdad EsfahbodandClaude Opus 4.6 83fe2fa4fa [gpu] Fix doc comments: "GPU shape encoder", "GPU rasterization library"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:37:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 2e24eccfd3 [gpu] Use XSince: REPLACEME in doc comments
Per AGENTS.md, new API uses XSince not Since.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:34:51 -06:00
Behdad EsfahbodandClaude Opus 4.6 7828141773 [gpu] Use HUGE_VAL instead of INFINITY for double extents
INFINITY is float; assigning to double triggers -Wdouble-promotion.
HUGE_VAL is the double-precision infinity constant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:32:48 -06:00
Behdad EsfahbodandClaude Opus 4.6 0c6ce48e8b [gpu] Rename encode local 'blob' to 'buf'
Avoid confusion with hb_blob_t variables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:29:00 -06:00
Behdad EsfahbodandClaude Opus 4.6 cd6d6ce7bf [gpu] Fix -Wcast-align in encode buffer allocation
Allocate as hb_gpu_texel_t* directly instead of char* to avoid
an alignment-increasing cast.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:26:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 69686b0768 [gpu] Use hb-gpu-demo name in help text and window title
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:23:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 4c78e3bf67 [gpu] Rename demo binary to hb-gpu-demo
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:21:12 -06:00
Behdad EsfahbodandClaude Opus 4.6 39811d2933 [gpu] Rename parameter 'glyph' to 'draw'; inline encode_impl
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:20:10 -06:00
Behdad EsfahbodandClaude Opus 4.6 e8d2bddfab [gpu] Make GL deps optional; add them to Linux CI
The demo requires GLEW, GLFW3, and GL. Make these optional so the
library still builds on headless systems. The demo is skipped when
they're missing.

Install the GL packages in the Linux CI workflow so the demo
builds there.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:14:10 -06:00
Behdad EsfahbodandClaude Opus 4.6 65d357f808 [gpu] Rename hb_gpu_glyph_t to hb_gpu_draw_t
The object is a draw_funcs_t closure, same role as hb_raster_draw_t.
Rename for consistency with the other modules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:09:40 -06:00
Behdad EsfahbodandClaude Opus 4.6 9732ad4bcf [gpu] Build hb-gpu binary in util/ instead of util/gpu/
Move the executable definition to util/meson.build so the binary
lands at util/hb-gpu, consistent with other utilities.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:50:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 3ccec5b9ed [gpu] Fix double-free in hb_gpu_glyph_destroy
hb_object_destroy() already calls obj->~Type() for non-trivially-
destructible types, which runs hb_vector_t's destructor.  The
explicit curves.fini() was freeing the array a second time.

Also remove encode_buf reuse — allocate fresh each encode call
and let the blob own the buffer via its destroy callback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:48:51 -06:00
Behdad EsfahbodandClaude Opus 4.6 294b625f7c [gpu] Wire up default font/text in demo
Fall back to an embedded font when no font file is given,
matching the glyphy-demo behaviour.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:32:21 -06:00
Behdad EsfahbodandClaude Opus 4.6 03c2688436 [gpu] Add GPU demo app in util/gpu
Port the glyphy-demo to use the hb-gpu API.  Builds as util/hb-gpu
and requires GLEW, GLFW3, and OpenGL 3.3.  Includes default text
and embedded font for quick testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:30:13 -06:00
Behdad Esfahbod 93aab15340 [gpu] Add new hb-gpu module for GPU glyph encoding
Port the glyphy library into harfbuzz as a new hb-gpu module,
following the hb-raster / hb-vector library pattern.  The module
encodes glyph outlines into compact RGBA16I blobs for GPU rendering
using the Slug algorithm.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5877
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:16:19 -06:00
Behdad EsfahbodandClaude Opus 4.6 e6d8ad97dc [vector] Use clear() instead of resize(0)/shrink(0) (#5876)
Also simplify clear() itself to just call shrink_vector(0) directly,
avoiding the resize() -> alloc() path which both fails in error state
and requires Type to be default-constructible.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 15:15:56 -06:00
Behdad Esfahbod 6e45962326 [raster] Guard direct SVG paint callbacks
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>
2026-03-26 14:41:14 -06:00
Behdad EsfahbodandClaude Opus 4.6 41de3c3272 [vector] Destruct items in clear() when vector is in error state
The previous fix (d134f888) zeroed `length` but skipped element
destructors. Call shrink_vector(0) instead, which properly destructs
items before clearing length.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 14:19:41 -06:00
Behdad Esfahbod 7433361337 [gpos] Guard cursive attachment reversal
Cursive attachment reversal clears the old child edge before
walking the existing chain and reinstalling reversed links.
If the chain distance does not stay in range for
attach_chain(), reinstalling the reversed edge can truncate
and leave a poisoned chain value.

Pass the buffer length into the reversal helper so it drops
out-of-bounds chains, and use a round-trip fit check before
storing the reversed distance. When the reversed distance does
not fit, leave the old edge detached instead of corrupting
the chain.

Testing: CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Fixes https://issues.chromium.org/issues/496302307
Assisted-by: OpenAI Codex <codex@openai.com>
2026-03-26 14:14:57 -06:00
Behdad Esfahbod cbe62baf81 [raster] Increase max image buffer size
Somebody already hit it it seems.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5874
2026-03-26 13:40:08 -06:00
Behdad Esfahbod 84d821ffac Remove two redundant conditionals
Fixes https://github.com/harfbuzz/harfbuzz/issues/5873
2026-03-25 11:59:58 -06:00
Behdad Esfahbod ef6a54cac3 [glyf] Reject simple glyphs with too few points
Reject simple glyf data that claims fewer points than contours.
Such data cannot describe a valid outline, so fail before
allocating and decoding contour points.

Testing: CCACHE_DISABLE=1 meson test -C b
Assisted-by: OpenAI Codex <codex@openai.com>
2026-03-24 14:26:42 -06:00
Behdad Esfahbod b268ba10ad [font] Fix typo in setting design coords (#5871)
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-8p7p-f952-473p
2026-03-24 11:29:42 -06:00
Behdad Esfahbod e6a9f6e889 [font] Avoid div-by-zero in parent scale
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-fw7p-wr9p-p9ww
2026-03-24 11:29:02 -06:00
Behdad Esfahbod 9b997ccc4e [font] Avoid creating a cycle in set_parent()
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-6f7c-qw56-fvvr
2026-03-24 11:27:51 -06:00