Position PNG images at bottom-left of glyph box for correct rendering.
Uses y_bearing + height to account for negative height values in glyph extents.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
PNG color-fonts (like Apple Color Emoji's sbix table) were not being
rendered by hb-draw. There were two issues:
1. probe_paint_funcs had no callbacks registered, so HarfBuzz couldn't
detect PNG glyphs as color glyphs. Fixed by adding a simple
probe_paint_image callback that returns true.
2. PNG images were using negative height directly in SVG <image>
elements, which doesn't work properly. Fixed by wrapping PNG images
in a <g> element with a transform that handles coordinate system
flip, similar to how SVG embedded images are handled.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Removes the --quiet/-q option that output raw path data only.
This simplifies the codebase by eliminating the write_raw_paths()
function and associated logic.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This increases the precision of scale and transform values in SVG output
for better accuracy in rendering.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Renames --ned option to --flat for better clarity. The option flattens
geometry and disables reuse of glyph definitions in SVG output.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Uses std::unordered_map to cache hb_glyph_extents_t by glyph ID, avoiding
redundant hb_font_get_glyph_extents() calls when the same glyph appears
multiple times (e.g., 'e' in "speed").
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When both --logical and --ink are specified, the bounding box is computed as
the union of logical and ink extents, providing maximum coverage. This matches
the behavior of specifying both flags in hb-view.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds --logical (default) and --ink options to control bounding box calculation.
--logical uses font logical extents (ascender/descender), --ink uses actual
glyph ink extents for a tighter bounding box. Default behavior is --logical.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds --margin option similar to hb-view but with default of 0 instead of 16.
Accepts 1-4 space-separated numbers (top right bottom left, with CSS-style
fallback logic). Expands SVG viewBox and dimensions accordingly.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Previously foreground only worked for color fonts. Now it works for all fonts
by wrapping content in a compact <g fill="..."> element that applies to all
child elements. Supports RGB and RGBA colors with transparency.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds --background command-line option to hb-draw, similar to hb-view/hb-cairo.
Supports RGB and RGBA color formats (rrggbb[aa]). Background is rendered as
an SVG rect element covering the viewBox when specified.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Color glyphs are now defined once in <defs> and reused via <use> elements,
similar to non-color glyphs. Previously each color glyph instance rendered
the full paint operations inline, causing duplication.
Tested with repeating emoji: reduces SVG size by ~44% for files with
repeated color glyphs (e.g., 3 emoji instances: 5.8KB vs 11KB without reuse).
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
In reuse mode, the outer scale(font_scale_x, -font_scale_y) wrapper
already flips Y. The color glyph wrapper was incorrectly also applying
scale(1,-1), causing a double Y-flip that made the output appear
off-bounds at any font size other than upem.
Now only apply scale(1,-1) in upem_scale mode (no outer wrapper).
Also restore precision 9 for 1/upem scale values.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reduce MAX_ANGLE from pi/8 to pi/16, producing ~32 slices per full
circle instead of ~16. This reduces visible color banding in sweep
gradient approximation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Coordinate data uses the user's --precision (default 2), but scale and
transform matrix values need more decimal places to avoid compounding
rounding errors. Add scale_precision() helper that returns max(precision, 5).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Creating upem_font as a sub-font of the main font (which has scale =
upem * 64 due to subpixel bits) caused the paint API to emit spurious
parent→child scale transforms. With precision=2 rounding, 1/64 rounds
to 0.02 and 0.02*64 = 1.28, destroying the mathematical cancellation
and making color glyphs ~1.6x too large.
Fix by creating upem_font directly from the face, eliminating the
parent-child relationship. Update expected test outputs accordingly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Render COLRv0/v1, CBDT/sbix bitmaps, and SVG table glyphs as rich SVG
with colors, gradients, compositing, and inlined bitmap images using
hb_font_paint_glyph(). Falls back to monochrome outlines when no color
data is available.
New options: --no-color, --palette N, --foreground rrggbb[aa]
Glyph outline paths are stored as shared <defs> and reused by both
display <use> elements and <clipPath> references, avoiding duplicate
path data.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>