[raster] Push/pop transform in paint _glyph_impl, not ensure_initialized

Remove the initial base_transform push from ensure_initialized.
Instead, _glyph_impl pushes/pops the positioning transform via
the paint funcs, matching the vector paint model.

current_transform() returns identity when the stack is empty.
pop_transform allows popping to empty (for the final glyph-level
pop).

This makes changing set_transform between glyph calls work
correctly — the transform is applied fresh for each glyph.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-18 11:31:12 -06:00
1 parent 36174584ba
commit 31c518df7a
3 files changed
+21 -16

No files matched your search

+7 -4
View File
@@ -972,10 +972,13 @@ hb_gpu_draw_get_scale (const hb_gpu_draw_t *draw,
* @font: font to draw from
* @glyph: glyph ID to draw
*
* Convenience wrapper that draws a single glyph outline into the
* encoder using hb_font_draw_glyph_or_fail(). Calls
* hb_gpu_draw_set_scale() with the font's scale before walking the
* outline.
* Convenience to draw one glyph outline. Equivalent to:
*
* |[<!-- language="plain" -->
* hb_gpu_draw_set_scale (draw, x_scale, y_scale);
* hb_font_draw_glyph_or_fail (font, glyph,
* hb_gpu_draw_get_funcs (draw), draw);
* ]|
*
* Return value: `true` if the glyph was drawn, `false` if the font
* has no outlines for @glyph.
+11 -11
View File
@@ -134,13 +134,6 @@ ensure_initialized (hb_raster_paint_t *c)
return;
}
/* Initial transform */
if (unlikely (!c->transform_stack.push_or_fail (c->base_transform)))
{
c->release_surface (c->surface_stack.pop ());
return;
}
/* Initial clip: full coverage rectangle */
hb_raster_clip_t clip;
clip.init_full (c->fixed_extents.width, c->fixed_extents.height);
@@ -163,7 +156,6 @@ hb_raster_paint_push_transform (hb_paint_funcs_t *pfuncs HB_UNUSED,
hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data;
ensure_initialized (c);
if (unlikely (!c->transform_stack.length)) return;
hb_transform_t<> t = c->current_transform ();
t.multiply ({xx, yx, xy, yy, dx, dy});
@@ -176,7 +168,7 @@ hb_raster_paint_pop_transform (hb_paint_funcs_t *pfuncs HB_UNUSED,
void *user_data HB_UNUSED)
{
hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data;
if (c->transform_stack.length > 1)
if (c->transform_stack.length)
c->transform_stack.pop ();
}
@@ -2230,15 +2222,23 @@ hb_raster_paint_glyph_impl (hb_raster_paint_t *paint,
hb_raster_paint_set_glyph_extents (paint, &ge);
}
hb_paint_funcs_t *funcs = hb_raster_paint_get_funcs (paint);
hb_paint_push_transform (funcs, paint,
paint->base_transform.xx, paint->base_transform.yx,
paint->base_transform.xy, paint->base_transform.yy,
paint->base_transform.x0, paint->base_transform.y0);
hb_bool_t ret = true;
if (fallible)
ret = hb_font_paint_glyph_or_fail (font, glyph,
hb_raster_paint_get_funcs (paint), paint,
funcs, paint,
paint->palette, paint->foreground);
else
hb_font_paint_glyph (font, glyph,
hb_raster_paint_get_funcs (paint), paint,
funcs, paint,
paint->palette, paint->foreground);
hb_paint_pop_transform (funcs, paint);
return ret;
}
+3 -1
View File
@@ -193,8 +193,10 @@ struct hb_raster_paint_t
return clip_stack.tail ();
}
hb_transform_t<> &current_transform ()
hb_transform_t<> current_transform ()
{
if (unlikely (!transform_stack.length))
return {1, 0, 0, 1, 0, 0};
return transform_stack.tail ();
}