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>
The other utils (hb-view, hb-raster) treat --margin as pixels, but
hb-vector was applying it directly to the upem-space extents. For a
font with upem=1000 rendered at font-size=72, the default 16-pixel
margin came out as 16/1000*72 = ~1.15 pixels per side, much smaller
than expected.
Convert margin from pixels to upem before adding it to the extents,
matching the per-axis x_scale/y_scale used elsewhere in the file.
Now hb-vector and hb-raster produce matching surface dimensions for
the same input (e.g. NotoNastaliqUrdu "اردو" at 72px: 137x213 in both).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb-cairo's render_color_glyph drops _or_fail in favor of
the synthesizing hb_font_paint_glyph, so the paint callback
handles every glyph (color or mono) through the paint
pipeline instead of returning NOT_IMPLEMENTED on non-color
glyphs and forcing cairo to fall through to the outline
path.
Hb-view's helper-cairo then picks paint vs draw the same
way the other utils do — --paint wins over --draw,
otherwise auto-detect via the font's color tables — and
expresses "draw" by setting CAIRO_COLOR_MODE_NO_COLOR on
the font options (which makes cairo skip render_color_glyph
entirely, falling through to render_glyph for the cheaper
outline path). No new public API.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the force_draw / force_paint flags from gpu-output.hh
into the shared view-options.hh so all rendering utils
expose --draw and --paint with the same semantics: --paint
wins over --draw, otherwise auto-detect via the font's
color tables.
raster and vector previously only ran the paint pipeline
when the font had a color table; they now also honor
--paint (renders mono fonts via paint synthesis) and
--draw (forces the outline path even on color fonts).
Vector's per-glyph try-paint-then-fall-back-to-draw is
replaced with a single mode decision up front. Each
glyph then goes through hb_vector_{paint,draw}_glyph
(non-_or_fail), which handles the synthesis fallback
internally — color glyphs render in either mode (paint
synthesizes for non-color fonts; draw renders nothing for
color-only glyphs without an outline, which matches user
intent for --draw).
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>
hb_vector_{paint,draw}_set_extents stored caller-supplied
extents as-is, while per-glyph extents accumulated via
hb_vector_set_glyph_extents_common were divided by
scale_factor on the way in. When callers passed extents in
input-space (the natural unit alongside the glyph geometry
they're feeding) and a non-1 scale_factor, the resulting
viewBox didn't match what the glyphs drew.
Make set_extents divide by scale_factor too, matching the
accumulate path; callers can now pass input-space extents
uniformly.
Also:
* hb-vector-paint's global transform wrapper dropped the
redundant /scale_factor division. Each per-glyph
<use transform="... scale(1/scale_factor, ...)"> already
applies scale_factor; wrapping the body in another
/scale_factor matrix double-scaled the output, shrinking
color-glyph output to 1/scale_factor^2 of its intended
size. The wrapper now only fires when the user set a
non-identity paint->transform, and emits that transform
as-is.
* util/vector-output.hh simplification: now that set_extents
handles the divide, drop the local pre-multiply of extents
by upem_to_pixel -- pass the upem-space extents through.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>