[raster] Always unwind transforms on SVG <use> cycle skip

This commit is contained in:
Behdad Esfahbod committed 2026-02-26 00:46:33 -03:00
1 parent 4a4f9f2b7a
commit 53bfaeabdd
1 file changed
+23 -19
+23 -19
View File
@@ -205,33 +205,37 @@ hb_raster_svg_render_use_element (const hb_svg_use_context_t *ctx,
if (found)
{
bool can_render = true;
hb_decycler_node_t node (*ctx->use_decycler);
if (unlikely (!node.visit ((uintptr_t) found)))
return;
can_render = false;
unsigned remaining = ctx->doc_start + ctx->doc_len - found;
hb_svg_xml_parser_t ref_parser (found, remaining);
hb_svg_token_type_t tok = ref_parser.next ();
if (tok == SVG_TOKEN_OPEN_TAG || tok == SVG_TOKEN_SELF_CLOSE_TAG)
if (can_render)
{
bool has_viewport_scale = false;
if ((ref_parser.tag_name.eq ("svg") || ref_parser.tag_name.eq ("symbol")) &&
use_w > 0.f && use_h > 0.f)
unsigned remaining = ctx->doc_start + ctx->doc_len - found;
hb_svg_xml_parser_t ref_parser (found, remaining);
hb_svg_token_type_t tok = ref_parser.next ();
if (tok == SVG_TOKEN_OPEN_TAG || tok == SVG_TOKEN_SELF_CLOSE_TAG)
{
float vb_x = 0.f, vb_y = 0.f, vb_w = 0.f, vb_h = 0.f;
hb_svg_transform_t t;
if (svg_parse_viewbox (ref_parser.find_attr ("viewBox"), &vb_x, &vb_y, &vb_w, &vb_h) &&
svg_compute_viewbox_transform (use_w, use_h, vb_x, vb_y, vb_w, vb_h,
ref_parser.find_attr ("preserveAspectRatio"),
&t))
bool has_viewport_scale = false;
if ((ref_parser.tag_name.eq ("svg") || ref_parser.tag_name.eq ("symbol")) &&
use_w > 0.f && use_h > 0.f)
{
hb_paint_push_transform (ctx->pfuncs, ctx->paint, t.xx, t.yx, t.xy, t.yy, t.dx, t.dy);
has_viewport_scale = true;
float vb_x = 0.f, vb_y = 0.f, vb_w = 0.f, vb_h = 0.f;
hb_svg_transform_t t;
if (svg_parse_viewbox (ref_parser.find_attr ("viewBox"), &vb_x, &vb_y, &vb_w, &vb_h) &&
svg_compute_viewbox_transform (use_w, use_h, vb_x, vb_y, vb_w, vb_h,
ref_parser.find_attr ("preserveAspectRatio"),
&t))
{
hb_paint_push_transform (ctx->pfuncs, ctx->paint, t.xx, t.yx, t.xy, t.yy, t.dx, t.dy);
has_viewport_scale = true;
}
}
render_cb (render_user, ref_parser, state);
if (has_viewport_scale)
hb_paint_pop_transform (ctx->pfuncs, ctx->paint);
}
render_cb (render_user, ref_parser, state);
if (has_viewport_scale)
hb_paint_pop_transform (ctx->pfuncs, ctx->paint);
}
}