WGSL transcription of the paint interpreter. Takes the atlas and
palette as explicit storage-buffer pointer parameters (matching
the WGSL draw helper's calling convention):
fn hb_gpu_paint (renderCoord: vec2f, glyphLoc: u32,
foreground: vec4f,
hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,
hb_gpu_palette: ptr<storage, array<vec4f>, read>) -> vec4f
hb_gpu_paint_shader_source() now returns real content for
HB_GPU_SHADER_LANG_WGSL fragment; HLSL still stubs to "".
util/gpu/web/hb-gpu-web-webgpu.cc:
- Concats the paint source alongside the draw source into the
WGSL shader module.
- Declares @group(0) @binding(2) for hb_gpu_palette.
- Allocates a 256 * vec4f storage buffer (zero-filled for now;
real palette upload is TODO), binds it at entry index 2.
- Fragment main switches from hb_gpu_draw to hb_gpu_paint.
util/gpu/web/gl-stub.h: adds glUniform4fv stub (demo-font.cc now
calls it for the GL palette path) and makes
glGetUniformLocation return -1 so the WebGPU build's
demo_font_upload_palette short-circuits.
Wasm sizes:
WebGL index.wasm : 443628 181597 gz
WebGPU webgpu.wasm : 461110 188045 gz
Non-color text should render through WebGPU. COLRv0 color glyphs
come up transparent until the cross-backend palette upload lands.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
MSL transcription of the GLSL paint fragment interpreter. Same
per-pixel op-stream walk and LAYER_SOLID SRC_OVER composite; the
only surface difference is that MSL's hb_gpu_fetch /
hb_gpu_paint take the atlas and palette as explicit buffer
pointer parameters (matching MSL's lack of globally-scoped
device-address-space globals).
float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc,
float4 foreground,
device const short4* hb_gpu_atlas,
constant float4* hb_gpu_palette);
hb_gpu_paint_shader_source() now returns a real string for
HB_GPU_SHADER_LANG_MSL fragment; vertex and WGSL/HLSL still stub
to "".
util/gpu/demo-metal.mm: concatenates the paint source alongside
the draw source into the Metal library, fragment_main switches
from hb_gpu_draw to hb_gpu_paint, and a 256-element palette
MTLBuffer is created + bound at fragment buffer index 2. The
palette buffer is zero-filled for now; real palette upload from
the font's active palette is a follow-up (the GL path in
demo-font.cc uses glUniform4fv, which is GL-specific; a cleaner
cross-backend upload will come with the general palette plumbing).
Non-color text (u_foreground path) should render correctly on
Metal. COLRv0 color glyphs will render transparent until the
palette upload lands -- ready for Mac smoke-testing.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements the paint-renderer fragment entry point
hb_gpu_paint(renderCoord, glyphLoc, foreground) -> vec4 as an
interpreter over the blob format documented in hb-gpu-paint.hh.
For this first slice only LAYER_SOLID ops are handled -- enough
to render COLRv0 color glyphs end to end once the demo is
rewired. LAYER_GRADIENT and PUSH/POP_GROUP cause the interpreter
to stop; COLRv1 support lands in follow-up commits.
The shader:
* Reads the blob header for num_ops and ops_offset.
* Walks the op stream. For each LAYER_SOLID it fetches the
clip-glyph coverage via hb_gpu_draw() (provided by
hb_gpu_draw_shader_source), looks up the color from
hb_gpu_palette[] or the caller-supplied foreground parameter
(per the is_foreground flag), and composites SRC_OVER.
hb_gpu_paint_shader_source() now returns the compiled source for
GLSL fragment; other languages and the vertex stage still return
"" until transcribed.
Wires meson.build and gen-gpu-shader-artifacts.py to generate the
.hh artifact.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Each subsystem already had a dedicated source file for its C API;
having the shader-source getter live in a separate `*-shaders.cc`
was unnecessary. Merge:
hb-gpu-shaders.cc -> hb-gpu.cc
hb-gpu-draw-shaders.cc -> hb-gpu-draw.cc
hb-gpu-paint-shaders.cc -> hb-gpu-paint.cc
Each subsystem's .cc is now self-contained: the lifecycle, glyph
accumulation, and shader-source getter all live together.
The large stringized-shader .hh artifacts are included locally at
the bottom of each file, right above the function that uses them,
rather than with the primary includes at the top -- they are only
used by one function.
Updates meson.build, CMakeLists.txt, and harfbuzz-world.cc to
drop the removed files. All 241 tests still pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reserve the API shape for the upcoming GPU color-glyph paint
encoder. The skeleton adds:
hb_gpu_paint_t opaque type
hb_gpu_paint_create_or_fail ()
hb_gpu_paint_reference ()
hb_gpu_paint_destroy ()
hb_gpu_paint_set_user_data () / _get_user_data ()
hb_gpu_paint_shader_source (stage, lang)
Only the lifecycle is functional. hb_gpu_paint_shader_source()
returns an empty string for all supported (stage, lang) pairs
until the paint-renderer shaders land.
This commit wires up the files, public declarations, section
index, and build system (meson, CMake, harfbuzz-world.cc,
vtable). Callers can now hold, reference, destroy, and attach
user data to a paint context.
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>
The file implements hb_gpu_draw_shader_source() and only dispatches
draw-subsystem shader sources. Matching the file-naming convention
recently applied to the .glsl/.msl/.wgsl/.hlsl sources and their
generated .hh artifacts.
No behavior change; updates CMakeLists.txt, src/meson.build, and
src/harfbuzz-world.cc to reference the new filename.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename hb-gpu-{fragment,vertex}.{glsl,msl,wgsl,hlsl} and their
generated .hh artifacts to hb-gpu-draw-{fragment,vertex}.{glsl,msl,
wgsl,hlsl}. Likewise rename the C symbols in each artifact from
hb_gpu_{fragment,vertex}_<lang> to hb_gpu_draw_{fragment,vertex}_<lang>.
These are the shader sources for the hb_gpu_draw_t (Slug-style
coverage) renderer. A COLRv1 paint renderer is planned and will
introduce its own hb-gpu-paint-*.{glsl,...} shader family, so the
existing shaders need a subsystem-qualified name to disambiguate.
No behavior change; hb_gpu_draw_shader_source() keeps returning the
same strings.
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>
Rename files to follow hb-vector-{draw,paint}[-{svg,pdf}] convention:
hb-vector-svg-draw.cc -> hb-vector-draw.cc
hb-vector-svg-paint.cc -> hb-vector-paint.cc
hb-vector-pdf-paint.cc -> hb-vector-paint-pdf.cc
Rename internal API to match:
hb_vector_pdf_paint_funcs_get -> hb_vector_paint_pdf_funcs_get
hb_vector_pdf_paint_render -> hb_vector_paint_render_pdf
Remove stale declarations for hb_vector_svg_paint_funcs_get and
hb_vector_svg_paint_render which were declared but never defined.
Update meson.build, CMakeLists.txt, and harfbuzz-world.cc.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_extents_t::to_glyph_extents() rounded bounds to hb_position_t
before subtracting them. Extreme extents from fuzzed VARC and
raster paths could therefore overflow signed int arithmetic while
forming glyph widths or heights.
Compute the rounded endpoints in double, clamp the exported values
to hb_position_t, and reject non-finite results. Also avoid the
same overflow in the reverse hb_glyph_extents_t constructor, add
an internal regression for the shared helper, and include the
minimized raster testcase.
Fixes: https://oss-fuzz.com/testcase-detail/4826864710647808
Not-tested: Skipped by request.
Assisted-by: OpenAI Codex
Add hb-vector-pdf-paint.cc with a complete set of PDF paint
callbacks for the HarfBuzz paint API:
push/pop_transform → q + cm / Q
push/pop_clip_glyph → q + path + W n / Q
push/pop_clip_rect → q + re + W n / Q
color → rg + re + f
push/pop_group → q / Q
gradients → solid fallback (first stop color)
The PDF paint backend reuses the draw funcs for glyph clip
path emission and shares the hb_vector_paint_t struct with
the SVG backend via hb-vector-paint.hh.
hb_vector_paint_glyph dispatches to SVG or PDF paint funcs
based on format. hb_vector_paint_render delegates to the
PDF render function for PDF output.
Tested with COLRv0 (RocherColorGX) — color layers render
correctly with proper clipping.
Assisted-by: Claude <noreply@anthropic.com>
Add HB_VECTOR_FORMAT_PDF to hb_vector_format_t. The hb-vector
tool now produces self-contained PDF when invoked with -o out.pdf.
PDF path operators map directly from the draw callbacks:
move_to → m, line_to → l, cubic_to → c, close_path → h,
with quadratic-to-cubic promotion (PDF has no Q operator).
The render function builds a minimal PDF 1.4 with catalog,
page, and content stream objects plus a cross-reference table.
Implementation:
- Extract hb_vector_draw_t struct to hb-vector-draw.hh so
future backends can share it.
- Draw callbacks branch on format for SVG vs PDF syntax.
- hb_vector_draw_glyph and hb_vector_draw_render dispatch by
format.
- vector-output.hh selects format from file extension and
skips paint (color glyphs) for PDF.
Coordinate system needs refinement — the page layout inherits
the SVG Y-flip transform, placing glyphs at the top with
extra whitespace. Correct PDF coordinate handling is a
follow-up.
Assisted-by: Claude <noreply@anthropic.com>
Port fragment and vertex shaders to HLSL (Shader Model 5.0+).
Uses asuint for bit reinterpretation, StructuredBuffer<int4> for
atlas, and mul() for matrix multiply. Verified with DXC on Linux.
Adds HB_GPU_SHADER_LANG_HLSL to the enum. Reorders enum to:
GLSL, WGSL, MSL, HLSL. Updates doc strings for consistency.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add MSL shader translations of the Slug GPU text rasterizer, and a
Metal rendering backend for hb-gpu-demo selectable via --metal flag.
Library changes:
- Add HB_GPU_SHADER_LANG_MSL enum value
- Add hb-gpu-vertex.msl and hb-gpu-fragment.msl
- Extend gen-gpu-shader-artifacts.py for MSL
Demo changes:
- Add demo-metal.h/mm with CAMetalLayer rendering
- Add external atlas backend for non-GL paths
- Add demo_buffer_get_vertices for Metal draw path
- Skip GL init when using Metal (GLFW_NO_API)
- Add --metal command-line flag
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A template-based amalgamation that includes all harfbuzz components
behind HB_HAS_* guards:
#define HB_HAS_SUBSET
#define HB_HAS_GPU
#include "harfbuzz-world.cc"
If HB_FEATURES_H is defined, includes that header for the defines.
HB_HAS_SUBSET selects harfbuzz-subset sources, otherwise core only.
Optional modules: HB_HAS_ICU, HB_HAS_CAIRO, HB_HAS_RASTER,
HB_HAS_VECTOR, HB_HAS_GPU.
Generated from meson source lists via gen-harfbuzz-world.py and
a .cc.in template. Committed artifact auto-regenerates like
harfbuzz.cc.
Also: add include guard to hb-zlib.cc (shared between raster
and vector, would cause duplicate symbols without it), and
remove .hh files from hb_gpu_sources list.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pre-generate hb-gpu-{fragment,vertex}-glsl.hh from the .glsl
sources so the library builds without Python/stringize at
compile time.
When stringize is found, a build rule regenerates them from
the .glsl sources and copies back to the source tree, matching
the ragel artifact pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
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>
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>
Add HB_HAS_SUBSET to hb-features.h and wire it through the same
HAVE_* feature plumbing used by the other HB_HAS_* macros.
Refactor the raster/vector SVG helper code so the duplicated
private helpers live in shared internal headers, avoiding
duplicate definitions when sources are combined in a single
translation unit.
Testing: meson compile -C build
Assisted-by: OpenAI Codex
Raster and vector libraries were configurable, but hb-features.h.in
did not expose matching HB_HAS_* macros.
Set HAVE_RASTER and HAVE_VECTOR during configuration, include both
features in the generated hb-features.h list, and add them to the
gtk-doc section index.
Testing: meson test -C build
Assisted-by: OpenAI Codex
The core libharfbuzz SVG table code should not include zlib headers or
link against zlib. Only the raster and vector libraries need to
normalize svgz documents before parsing them.
Move the gzip decoder into a private hb-zlib translation unit that is
built only by harfbuzz-raster and harfbuzz-vector, and move SVG blob
normalization into a private helper header used only there. Keep the
shared SVG table and cache logic in libharfbuzz free of zlib includes.
Assisted-by: OpenAI Codex
Vector SVG extraction still treated SVG table documents as plain text,
so svgz payloads worked in raster but failed in hb-vector.
Move the gzip helpers into a new internal hb-zlib.hh header and add a
shared SVG blob normalization helper in svg.hh. Raster and vector now
both normalize SVG documents before doc-cache or rendering/subsetting
logic sees them, with the same 16 MiB uncompressed size limit.
Also link zlib into harfbuzz-vector when available and add a vector
regression that checks matching output for the existing plain and
compressed handwriting SVG fonts.
Tested:
- meson test -C build
Assisted-by: OpenAI Codex
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