hb-subset serialized only the final face, leaving serialization out of
the repeated work measured by --num-iterations.
Reference each subset face's blob inside the loop, releasing the
previous blob on the next iteration and writing the final blob once.
Tested with meson test -C build: 299 passed, 1 skipped. Also checked
identical output for one and three iterations with and without
preprocessing, plus zero iterations and invalid-font handling.
Assisted-by: Codex
* [hb-info] Skip unresolvable variation sequences in --list-unicodes
_list_unicodes() asserted that every codepoint returned by
hb_face_collect_variation_unicodes() also resolves via
hb_font_get_variation_glyph(), but the library never guarantees
that: collection reads only the cmap format 14 subtable, while
lookup additionally requires a nominal cmap mapping for Default UVS
ranges and a non-zero glyph for Non-Default UVS mappings. A
structurally valid, sanitizer-clean font that lists an unmapped
codepoint in a Default UVS range, or glyph 0 in a Non-Default UVS
entry, therefore aborted hb-info --list-unicodes/--list-all/--all in
any assertion-enabled build (the meson debugoptimized default).
Treat a failed lookup as data and skip the sequence instead of
asserting. Both library calls behave as documented, and the
subsetter relies on collect_variation_unicodes() returning every
listed entry, so the fix belongs in the tool.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-DM9ORF9Z.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [hb-info] Skip dangling LangSys feature indices in --list-features
The script-sensitive path of _list_features() printed a local
hb_tag_t that hb_ot_layout_table_get_feature_tags() only writes when
the requested index exists. LangSys::sanitize bounds-checks the
feature-index array but not its values, so a featureIndex past the
end of the FeatureList left the tag uninitialised and hb-info printed
stack garbage (NUL bytes under -O2, the previous tag under ASan).
Initialise the tag, resolve it at the top of the per-feature loop,
and honour the returned count by skipping the entry when it is zero,
matching how the shaper ignores such indices. This is a tool-only
defect: the library already returns zero tags for the dangling index.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-TM7BTKMU.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
In hb-gpu-web and hb-gpu-web-webgpu, rebuild_buffer() frees current_text
after duplicating the input text, but then passes the original text
pointer to demo_buffer_add_text(). When called from web_load_font(),
web_set_variations(), web_set_features(), or web_set_palette() with
custom text active, text aliases current_text, resulting in a
use-after-free read of recently freed heap memory.
Fix this by:
1. Skipping redundant reallocation when text already equals
current_text.
2. Passing current_text to demo_buffer_add_text().
3. Handling a null text input safely with a default fallback.
Assisted-by: Gemini
sscanf("%lf") for --font-size, --embolden, --font-extents and
--margin follows the environment LC_NUMERIC set by setlocale(LC_ALL,
""), so "10.5" parses as 10 under a comma-radix locale. Force
LC_NUMERIC to C after the environment locale is applied so these
options use a '.' radix, like g_ascii_strtod already does for --width.
The quiet option currently exits immediately after compiling the
dependency graph, making it impossible to measure public API retrieval
separately from formatting and output.
Make -q/--quiet retrieve all selected edges without printing them, and
add --compile for construction-only runs. Avoid creating a font in
quiet mode since glyph names are not needed.
On Noto Nastaliq, compilation takes 362ms and retrieving every edge adds
about 1.4ms, showing that formatting rather than public API retrieval is
the remaining tool-side cost.
Tested with the full Meson test suite (272/272 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
Add -q/--quiet to build and validate a dependency graph without spending
time formatting or printing it. This makes graph-construction profiling
and performance measurements straightforward.
Tested with the full Meson test suite (270/270 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
The D3D11 demo atlas backend advanced its cursor and copied glyph data into the
shadow buffer without checking the fixed atlas capacity. Long sessions could
therefore write past the end of the shadow buffer once the atlas filled.
Match the other demo atlas backends by failing before advancing the cursor when
the requested glyph data does not fit.
Testing: meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
* [util] Fix Unicode command line arguments on Windows
GLib g_option_context_parse() converts argv strings from the system ACP via g_locale_to_utf8(), but Windows cmd deliver arguments encoded in the system codepage (ex: CP1252), which cannot represent most Unicode codepoints. This caused non ascii character to be corrupted
For example, for this command, it rendered garbage instead of the emoji:
```
hb-view.exe "C:\Windows\Fonts\seguiemj.ttf" "😋" --output-file=output.png
```
Fix this in all util binaries (hb-ft-raster, hb-info, hb-raster, hb-shape, hb-subset, hb-vector, hb-view) by:
1. Calling g_win32_get_command_line() to obtain correctly UTF-8-encoded arguments from GetCommandLineW().
2. Parsing with g_option_context_parse_strv() which skips the g_locale_to_utf8() conversion for G_OPTION_ARG_STRING entries.
3. Adding G_OPTION_FLAG_FILENAME to the G_OPTION_REMAINING callback entry in main-font-text.hh, so the callback path also skips the locale conversion in strv_mode (see https://gitlab.gnome.org/GNOME/glib/-/blob/8ef2f3ad402daf9fb94615ddef63ceef978fd76f/glib/goption.c#L1305).
* [util] Fix Windows UTF-8 argv parsing
On Windows, GLib's option parser treats argv as encoded in the
system codepage and converts strings with g_locale_to_utf8(). The
utilities need to parse the UTF-8 command line obtained from
GetCommandLineW() instead, otherwise non-ASCII arguments can be
corrupted before reaching the tool logic.
Add a small argv_t wrapper for utility entry points to replace argv
with g_win32_get_command_line() on Windows, and use the strv parser
there so GLib skips the top-level argv conversion. Mark remaining
callback arguments as filenames so GLib also skips callback argument
conversion for positional text and font arguments.
Testing:
meson test -C build
Assisted-by: OpenAI Codex
* [mingw] Update instructions
---------
Co-authored-by: moi15moi <moi15moismokerlolilol@gmail.com>
The SECTION annotation in hb-depend.cc used the old name "hb-depend"
which didn't match the "hb-subset-depend" FILE name in sections.txt
after the header rename. This caused gtkdoc to report the section
description as unused and the section symbols as undocumented. Also
add HB_SUBSET_DEPEND_EDGE_FLAGS_T_DEFINED to a Private subsection
so gtkdoc doesn't flag it as an unused declaration.
The header move from hb.h to hb-subset.h (e3e754f9c) also left
util/hb-subset-depend.cc and test/api/test-ot-depend.c without
access to hb-subset-depend.h, causing build failures on sanitizer
CI jobs that build the utility and test. Add the missing
#include <hb-subset.h> to both.
Assisted-by: Claude <noreply@anthropic.com>
Add uninstalled util/hb-subset-depend that prints the glyph dependency
graph for a font. Supports filtering by GID range (--gids), showing only
flagged edges (--flagged), suppressing context output (--no-context), and
using numeric IDs instead of glyph names (--no-glyph-names). Registered
in util/meson.build under experimental_api + subset guards.
Also fix a bug in hb_subset_depend_lookup_glyph where the flags field of
hb_subset_depend_entry_t (a 4-byte enum) was written via a uint8_t*,
leaving the upper 3 bytes uninitialized. Use a local uint8_t variable and
assign it properly to entries[i].flags.
Co-Authored-By: Claude Sonnet 4.6 <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>
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>
Nastaliq and other deep-descender scripts were clipped because
the fit used only logical extents (one em height). Now uses
the union of ink and logical extents so all ink is visible.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- demo_buffer_set_features() sets global features for hb_shape
- web_set_features() wasm export parses comma-separated features
- Shell message handler accepts { kind: "features", value }
- Features applied to all shape calls in demo_buffer_add_text
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allows the host page to simulate keypresses (e.g. 'b' for
dark mode toggle) via postMessage { kind: 'key', value }.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_gpu_paint() now takes an out float coverage parameter that
receives the maximum slug coverage across all paint layers.
This lets the caller apply stem darkening and gamma correction
to edge antialiasing only, without distorting interior paint
colors (gradients, semi-transparent layers).
The demo shaders (GLSL, MSL, HLSL, WGSL) use the new parameter
to share a single coverage-correction block between draw and
paint paths. Also fixes the blend func to GL_ONE for correct
premultiplied compositing.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_gpu_paint() returns premultiplied RGBA, as documented in
hb-gpu.cc. The GL demo was using GL_SRC_ALPHA which
double-applied alpha, darkening semi-transparent colors.
Use GL_ONE as the API docs prescribe.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The recently added --stroke option is only meaningful in
hb-view (cairo rendering). The experimental utils
(hb-raster, hb-vector, hb-gpu) don't support stroked
outline rendering. Hide from --help but keep functional;
--rainbow still enables it implicitly.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The GPU util's auto-detect only checked hb_ot_color_has_paint
(COLRv1). COLRv0 fonts like BungeeTint have layers but no
paint tree, so they were incorrectly routed to the mono draw
path.
Add hb_ot_color_has_layers and hb_ot_color_has_png to the
check, matching the raster and vector utils.
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>
Move foreground fill from a global wrapper (SVG <g fill>,
PDF initial rg) to per-glyph emission:
SVG: each <use> gets fill="rgb(...)" from the current
draw->foreground at emission time.
PDF: each glyph path gets an rg operator before fill.
This lets callers change foreground between glyph calls
(e.g. per-glyph palette cycling) without post-processing.
Wire per-glyph palette cycling for the draw path in the
hb-vector util, matching how paint already does it.
Regenerated vector test expected outputs.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
With --draw/--paint forcing a single mode per render, the
draw and paint paths are mutually exclusive — both can't
produce output in the same render. Remove the combined
SVG merger and simplify to a single blob output.
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 util had its own background rect emitter that wrote
directly to the output file. Now that hb_vector_paint has
set_background, the library handles it. Remove the
duplicate to avoid double background emission.
Note: the draw path currently has no background support;
this is consistent — mono/draw SVGs are typically embedded
inline where background comes from the container.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allows explicitly requesting transparent output without
needing to spell out --background=00000000.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add hb_vector_paint_set_background() / get_background() and
hb_raster_paint_set_background() / get_background().
For vector: if set to a non-transparent color, the SVG renderer
emits a <rect> covering the viewBox before glyph content, and
the PDF renderer prepends a filled rectangle to the content
stream. Both support semi-transparent backgrounds (SVG via
fill-opacity, PDF via ExtGState /ca).
For raster: the root surface is pre-filled with the background
color before glyph compositing begins.
Default is transparent (no background emitted).
The hb-vector CLI util wires --background to the new API.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
get_normalized_stroke_width() was gated on stroke_enabled,
returning the raw pixel value (1.0) when --stroke wasn't
active. The show-extents overlay uses this value regardless
of --stroke, so it got a stroke_width of 1 in font-scale
space (= 0.016 pixels after /SCALE).
Remove the stroke_enabled guard so the pixel → font-scale
conversion always applies.
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>
Drop the bespoke red pen dot + magenta extents rectangle in
favor of a single foreground-color overlay that matches the
look raster, vector, and gpu now produce after their port to
the shared helper: stroked rect around each glyph's ink box,
plus a filled dot at the pen origin.
Cairo's annotation pass stays native (post-glyph drawing
through cairo, not via hb_paint funcs); only the colors and
the dot rendering changed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extend the shared overlay helper (and rename it from
util_emit_extents_rect_into_* to util_emit_extents_overlay_
into_*) to emit two pieces of geometry per glyph: the
existing stroked rect around the ink box, plus a filled
dot at the pen origin via hb_draw_circle. Both go in the
foreground color through the same draw / paint flow.
The dot helps debug glyph positioning at a glance and gives
the previously-uncalled hb_draw_circle a real caller in the
suite.
Raster, vector, and gpu utils pick up the dot automatically
via the renamed helper.
Co-Authored-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>
Use util_emit_extents_rect_into_{draw,paint} from
helper-extents-overlay.hh so the GPU demo's extents
overlay matches the raster and vector ports — same
coordinate, padding, and stroke convention; same
foreground-color fill via the arbitrary-path clip API in
paint mode.
Adds --show-extents support for the paint (color-glyph)
path, which previously only the draw path implemented.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bake the per-glyph extents rectangle into the same draw or
paint context that rendered the glyph, via the shared
helper from helper-extents-overlay.hh. Matches the raster
util's port: in paint mode, the rect goes through
push_clip_path_start/end + paint_color (foreground); in
draw mode, hb_draw_rectangle on hb_vector_draw_get_funcs
appends to the scratch which the next glyph's entry-flush
(or render) emits as its own <path>/fill.
Drops the standalone emit_extents_overlay function and
its FF0000-dot + FF00FF-stroke SVG markup — the new
overlay renders in the glyph's foreground color, same as
the raster port.
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>
Add util_emit_extents_rect_into_draw in helper-extents-
overlay.hh — takes a draw funcs pair + glyph extents + pen
position + stroke_width and emits the padded stroked rect
in one place. util_emit_extents_rect_into_paint (renamed
from _paint for clarity) now wraps it in the
push_clip_path_start/_end + paint_color + pop_clip dance.
Both raster draw loops (finish_draw_solid accumulated into
one rdr, finish_draw_palette per-glyph) now bake the extents
ring into the draw context with util_emit_extents_rect_into_
draw, alongside the glyph outline in foreground color.
finish_paint's call site collapses from an inline
coord-normalize-and-pad block to a single helper call.
Uses copysignf on the padding so the "outward" shift tracks
the y_bearing/height sign instead of needing a caller-side
normalize; pairs with the hb_draw_rect fix for negative
w/h in the same branch.
Drop the now-unused collect_ink_extents_rects /
overlay_rects_bgra / overlay_rects_rgb / rect_i_t helpers
that implemented the old manual BGRA overlay pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the manual BGRA 1-pixel overlay with a per-glyph
hb_paint_push_clip_path_start/_end + hb_draw_rect + paint
foreground sequence, wrapped in the new shared helper
util_emit_extents_rect_paint in helper-extents-overlay.hh.
Each glyph now bakes its own extents ring into the glyph's
rendered mask via the raster-paint backend's arbitrary-
path clip, so compositing picks it up alongside the glyph
ink (same code path as the color layers).
Pads the nominal rect outward by stroke_width/2 so the
stroke's inner edge sits at the ink box — otherwise the
inner half would knock out against glyph ink under non-
zero-winding clipping. Normalizes w/h to positive before
padding so the outward shift is unambiguous regardless of
y_bearing / height sign conventions.
Draw-mode loops (finish_draw_solid, finish_draw_palette)
still use the old collect+overlay path and will follow up.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Reset Since tags to XSince: REPLACEME for new non-or_fail
glyph functions (gpu, raster, vector paint).
- Remove duplicate doc comment on static
hb_vector_paint_glyph_impl helper.
- Fix hb_gpu_paint_glyph doc: remove internal LAYER_SOLID
reference.
- Drop hb_ot_color_has_svg() from color-detection in all utils
(cairo, raster, vector, hb-raster-all); HarfBuzz does not
render SVG table natively, so checking it caused fallback to
monochrome drawing of the actual outlines.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>