[util/gpu] Add --show-extents flag

Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.

The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).

Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.

Assisted-by: Claude <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-15 02:19:53 -06:00
1 parent cfdcea6c79
commit a150fc2218
3 files changed
+43

No files matched your search

+3
View File
@@ -57,6 +57,7 @@ struct gpu_output_t
hb_bool_t bench = false;
hb_bool_t force_draw = false; /* --draw : use monochrome draw path */
hb_bool_t force_paint = false; /* --paint : use paint path */
hb_bool_t show_extents = false; /* --show-extents */
char *type_text = nullptr;
char *output_file = nullptr; /* PPM only; "-" for stdout */
view_options_t view;
@@ -86,6 +87,7 @@ struct gpu_output_t
{"draw", 0, 0, G_OPTION_ARG_NONE, &this->force_draw, "Force monochrome draw path", nullptr},
{"paint", 0, 0, G_OPTION_ARG_NONE, &this->force_paint, "Force color paint path", nullptr},
{"output-file", 'o', 0, G_OPTION_ARG_STRING, &this->output_file, "Render one frame to PPM file (\"-\" for stdout) and exit","filename"},
{"show-extents", 0, 0, G_OPTION_ARG_NONE, &this->show_extents, "Draw a frame around each glyph's ink extents", nullptr},
/* Reuse the storage in `view` for the four options hb-gpu
* actually honors. view_options_t::post_parse() does the
* parsing for us; gpu_output_t::post_parse() below forwards
@@ -179,6 +181,7 @@ struct gpu_output_t
demo_font_ = demo_font_create (font, renderer->get_atlas (), draw_only);
demo_font_set_palette (demo_font_, view.palette);
demo_font_set_show_extents (demo_font_, show_extents);
if (view.custom_palette_entries)
{
for (unsigned i = 0; i < view.custom_palette_entries->len; i++)
+33
View File
@@ -19,6 +19,7 @@ struct demo_font_t {
hb_gpu_paint_t *p;
hb_gpu_draw_t *d;
bool draw_only;
bool show_extents;
unsigned int num_glyphs;
unsigned int sum_bytes;
@@ -72,6 +73,15 @@ demo_font_get_font (demo_font_t *font)
return font->font;
}
void
demo_font_set_show_extents (demo_font_t *font, hb_bool_t show)
{
bool b = !!show;
if (font->show_extents == b) return;
font->show_extents = b;
demo_font_clear_cache (font);
}
void
demo_font_set_palette (demo_font_t *font, unsigned palette_index)
{
@@ -114,6 +124,29 @@ _demo_font_upload_glyph (demo_font_t *font,
{
hb_gpu_draw_clear (font->d);
hb_gpu_draw_glyph (font->d, font->font, glyph_index);
if (font->show_extents)
{
/* Embed a stroked rectangle around the glyph's ink
* extents in the same blob. Pad the nominal rect
* outward by stroke_width / 2 so the stroke sits
* entirely outside the ink box (otherwise the inner
* half of the stroke would knock out against the
* glyph shape, since both fill in the same blob). */
hb_glyph_extents_t g = {};
if (hb_font_get_glyph_extents (font->font, glyph_index, &g) &&
(g.width != 0 || g.height != 0))
{
int x_scale, y_scale;
hb_font_get_scale (font->font, &x_scale, &y_scale);
float sw = (float) (x_scale * 0.01);
float half = 0.5f * sw;
float x = (float) g.x_bearing - half;
float y = (float) (g.y_bearing + g.height) - half; /* min_y */
float w = (float) g.width + sw;
float h = (float) -g.height + sw; /* positive */
hb_gpu_draw_rect (font->d, x, y, w, h, sw);
}
}
blob = hb_gpu_draw_encode (font->d, &hb_ext);
}
else
+7
View File
@@ -55,6 +55,13 @@ demo_font_set_custom_palette_color (demo_font_t *font,
unsigned int color_index,
hb_color_t color);
/* Embed a stroked frame at each glyph's ink extents into the
* same blob as the glyph outline. Cached with the glyph;
* changing this invalidates the cache. */
void
demo_font_set_show_extents (demo_font_t *font,
hb_bool_t show);
void
demo_font_clear_cache (demo_font_t *font);