Commit Graph
918 Commits
Author SHA1 Message Date
Behdad Esfahbod 4650398a07 [gpu] encode() returns extents + auto-clears; drop get_extents() (#5910)
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>
2026-04-13 00:15:54 -06:00
Behdad Esfahbod 5e6ae10f62 [raster][vector] Remove SVG-font glyph source rendering
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>
2026-04-11 22:46:35 -06:00
Behdad Esfahbod b5287cb3fb [gpu] Clamp exported draw extents
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.

Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.

Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
2026-04-09 23:15:34 -06:00
💀 f4600f3c87 test: add hb-ft load-flag preservation regression 2026-04-09 14:57:29 -06:00
Behdad Esfahbod 3b7ee09f0e [gpu] Fix draw encode blob ownership leaks
hb_gpu_draw_encode() could allocate a fresh output buffer and then
return NULL before transferring ownership to a blob, leaking that
temporary buffer on late encode failures.

The recycled-blob growth path also tried hb_realloc() first and fell
back to hb_malloc() when that failed. Once the new buffer was committed
to the recycled blob, the old recycled buffer could be orphaned.

Free temporary buffers on the remaining late-failure exits and keep
the old recycled buffer alive until a replacement has been committed.
Tighten the GPU API recycle test to encode a larger second outline so
that reused-buffer growth stays covered.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-04 19:44:54 -06:00
Behdad EsfahbodandOpenAI Codex a4aff49856 [gpu] Fix contour breaks and bounds quantization in encode (#5892)
Encode used adjacent endpoint equality to infer contour breaks, which
fails when two contours touch at the same point. Track contour starts
explicitly during accumulation instead, and use that flag when packing
shared endpoints.

Encode also rounded blob bounds to the nearest quarter unit. That can
shrink the encoded extents and clip coverage at glyph edges. Quantize
mins downward and maxes upward so the blob header always encloses the
actual geometry.

Add focused API tests for both regressions.

Testing:
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 12:09:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 d46f8e3444 [gpu] Rename HB_GPU_SHADER_GLSL_330 to HB_GPU_SHADER_LANG_GLSL
The shader source is compatible with both GLSL 3.30 and
GLSL ES 3.00.  Rename the enum value to reflect this and
match the type name convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:40:11 -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 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 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
Khaled Hosny b327f0c672 [tests] Fix warning when building without zlib
../test/api/test-raster.cc:67:1: warning: unused function 'render_svg_glyph' [-Wunused-function]
   67 | render_svg_glyph (hb_face_t      *face,
      | ^~~~~~~~~~~~~~~~
1 warning generated.
2026-03-12 17:36:39 +02:00
Behdad Esfahbod b7e4f5fd62 [raster] Support gzip-compressed SVG documents
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
2026-03-11 14:18:31 -03:00
Behdad Esfahbod cfd9a52c9d [svg] Gate SVG table processing under HB_NO_SVG (#5814)
Skip the SVG table accelerator and do not define the public
SVG color APIs when HB_NO_SVG is set. Guard internal
callers so SVG-table-dependent code compiles out cleanly,
and add HB_NO_SVG to the HB_TINY profile.

Tested: meson setup build-nosvg -Dc_args=-DHB_NO_SVG -Dcpp_args=-DHB_NO_SVG
Tested: meson compile -C build-nosvg hb-shape hb-info hb-vector main
Tested: meson compile -C build-nosvg (libharfbuzz/libharfbuzz-raster/libharfbuzz-vector linked; full tree stopped on unrelated missing chafa.h in util/hb-raster.cc)
Tested: nm -gU build-nosvg/src/libharfbuzz.0.dylib | grep -E "hb_ot_color_.*svg" (no matches)

Assisted-by: OpenAI Codex
2026-03-10 00:19:39 -06:00
Khaled Hosny b91d4b8d75 Add meson options to disable building harfbuzz-subset 2026-03-04 18:12:45 +02:00
Khaled Hosny 9520926168 Add meson options to disable building harfbuzz-raster 2026-03-04 18:12:45 +02:00
Behdad Esfahbod 5ea04afcda raster: adopt create_or_fail and strict render semantics 2026-02-24 04:46:51 -03:00
Behdad Esfahbod 742f79da08 raster: remove extents_from_glyph_extents API
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.
2026-02-23 12:10:41 -03:00
Behdad EsfahbodandKhaled Hosny 99a84d7f02 Update src/hb-raster.h
Co-authored-by: Khaled Hosny <khaled@aliftype.com>
2026-02-21 17:29:05 -03:00
Behdad EsfahbodandClaude Sonnet 4.6 35ba082aa2 hb-raster: add test_glyph to test-raster
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>
2026-02-21 17:29:05 -03:00
Behdad EsfahbodandClaude Sonnet 4.6 c9d459b8e9 hb-raster: fix tile bounds clipping; move test to test/api/
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>
2026-02-21 17:29:05 -03:00
Khaled Hosny c763763662 [buffer-serialize] Fix calculating absolute offsets with partial range
Fixes https://github.com/harfbuzz/harfbuzz/issues/5743
2026-02-15 17:30:16 +02:00
Garret Rieger 07e48ef1f0 Fix two bugs in hb_set_is_subset().
1. If smaller set has empty pages the subset checking logic was incorrectly incrementing the larger page index after skipping the empty smaller page index.
2. The logic for is_subset() on mixed inverted/not inverted sets was wrong.
2026-02-13 15:06:01 -07:00
Behdad Esfahbod bb7dbc25ec Fix some unused-var warnings under NDEBUG 2026-01-10 07:42:07 -07:00
David Corbett bc2c60e490 [Unicode 17] Add tests 2025-09-10 12:15:49 -04:00
Qunxin Liu 77d073044e [subset] fix HVAR encoding width (#5523) 2025-09-02 15:40:51 -06:00
Khaled Hosny af1b9acc27 [glib] Drop fallback code for versions we don’t support
We require Glib 2.30.0, so drop checks for older versions.
2025-07-02 20:14:51 +03:00
Behdad Esfahbod 47089fe7a3 Big misc changes
- Make geometry types into templates taking float or double.
- Changes to paint() transform elimination.
- Add font->has_nonzero_coords and use it across.
- Extensions to avar processing for otherwise invalid mappings.
2025-06-08 13:43:27 +03:00
Behdad Esfahbod 7e353d3718 [test] Remove u8 prefix from strings
No idea how/why this got in there to begin with.
2025-05-23 14:31:58 -06:00
Behdad Esfahbod fcedcf8111 [coretext] Another old-system build fix
Fixes https://github.com/harfbuzz/harfbuzz/issues/5300#issuecomment-2831684725
2025-04-25 19:04:37 -06:00
Behdad Esfahbod 38db1facf2 [paint] Change back return type of paint_glyph() to void
Add new "_or_fail" variants of draw_glyph and paint_glyph

New API:
+hb_font_draw_glyph_or_fail_func_t
+hb_font_paint_glyph_or_fail_func_t
+hb_font_funcs_set_draw_glyph_or_fail_func()
+hb_font_funcs_set_paint_glyph_or_fail_func()
+hb_font_draw_glyph_or_fail()
+hb_font_paint_glyph_or_fail()

Deprecated API:
-hb_font_draw_glyph_func_t
-hb_font_paint_glyph_func_t
-hb_font_funcs_set_draw_glyph_func()
-hb_font_funcs_set_paint_glyph_func()
2025-04-23 18:23:51 -06:00
Behdad Esfahbod e78310bfaa [paint] Change return type to bool, and return false for outline glyphs
It was impossible to get synthetic bold/slant correctly with the
previous API. This is a minor API break, but one I'm willing to take.
2025-04-23 01:02:15 -06:00
Behdad Esfahbod 9445778e18 [test-paint] Update expectations for recent slant changes 2025-04-22 21:33:15 -06:00
Behdad Esfahbod 8aa88aa416 [COLRv1:ot/ft] Use paint-bounded instead of paint-extents
Faster. Note that this also means that if there is no clip-box,
we don't compute the bounds and emit an initial clip anymore.
That was totally unnecessary and against the COLRv1 rendering
algorithm.

This makes painting of COLRv1 fonts without clipboxes *much*
faster, as previously we were computing bounds using all subglyph
outlines. Not anymore.

Before:
BM_Font/paint_glyph/Nupuram-Color.colrv1.ttf/ot                   1.78 ms

After:
BM_Font/paint_glyph/Nupuram-Color.colrv1.ttf/ot                  0.155 ms
2025-04-20 04:11:07 -06:00
Behdad Esfahbod a3d626b4b9 [test-object] Hopefully last ubsan fix
API change:
- hb_face_is_immutable() now takes `hb_face_t *` instead of previous
  `const hb_face_t *`.  This should not pose any problem for any
  clients in our belief.
2025-04-06 19:16:43 -06:00
Behdad Esfahbod b99382e292 [test-unicode] Try disabling one test under ubsan 2025-04-06 18:53:53 -06:00
Behdad Esfahbod ba4a92c53b [test-object] Fix ubsan issues 2025-04-06 18:48:39 -06:00
Behdad Esfahbod 8a1ba4d151 [test-object] See if this helps make ubsan happy 2025-04-06 18:12:22 -06:00
Behdad Esfahbod fb04a306fc [test/api] Fix a few ubsan issues 2025-04-06 18:08:50 -06:00
Behdad Esfahbod b43901151f [test-draw] Make ubsan happy 2025-04-06 17:28:03 -06:00
Behdad Esfahbod 155e1e633b [test/api] Use g_assert_true instead of g_assert
The latter terminates the program. The former marks the test
as failing.
2025-04-06 03:49:15 -06:00
Behdad Esfahbod e4e4d66523 [test/api] Test remaining tests to TAP 2025-04-06 02:34:48 -06:00
Behdad Esfahbod f69ecc9438 [test/api] Set protocol:tap 2025-04-06 02:34:48 -06:00
Behdad Esfahbod bee08cf290 [hb-test] Don't convert _ in test names to /
Slash is used for grouping...
2025-04-05 23:27:26 -06:00
Behdad Esfahbod 3cf48234b9 [hb-test.h] Remove unsed functions 2025-04-05 23:26:59 -06:00
Behdad Esfahbod 112b599826 [test] Minor use hb_test_init 2025-04-05 22:37:10 -06:00
Behdad Esfahbod 6c98519c7e [test/api] Simplify deps 2025-04-05 21:41:01 -06:00
Khaled Hosny a24c40dfb4 [test/ot-math] Do away with global variables 2025-04-06 03:22:20 +02:00
Khaled Hosny d74606bbff [test/ot-math] Port to use hb_test_open_font_file()
Avoids the unnecessary dependency on FreeType.
2025-04-06 03:22:20 +02:00
Khaled Hosny 2d8e5255f3 [test/ot-math] Add a test for the Cambria Math workaround 2025-04-06 02:48:49 +02:00
Garret Rieger a1e587b75a [subset] Add hb_subset_cff_get_charstrings_index and hb_subset_cff2_get_charstrings_index.
These methods allow retrieving the entire charstrings index structure from a CFF or CFF2 table.
2025-03-31 16:28:28 -06:00