[raster] Fast-path common style properties in SVG style parser

This commit is contained in:
Behdad Esfahbod committed 2026-02-26 01:30:26 -03:00
1 parent 8fa382dd67
commit bbd0635b9a
1 file changed
+56 -35
+56 -35
View File
@@ -66,41 +66,62 @@ svg_parse_style_props (hb_svg_str_t style, hb_svg_style_props_t *out)
hb_svg_str_t prop_name = {name_start, (unsigned) (name_end - name_start)};
hb_svg_str_t prop_value = {value_start, (unsigned) (value_end - value_start)};
if (prop_name.eq_ascii_ci ("fill")) out->fill = prop_value;
else if (prop_name.eq_ascii_ci ("fill-opacity")) out->fill_opacity = prop_value;
else if (prop_name.eq_ascii_ci ("opacity")) out->opacity = prop_value;
else if (prop_name.eq_ascii_ci ("transform")) out->transform = prop_value;
else if (prop_name.eq_ascii_ci ("clip-path")) out->clip_path = prop_value;
else if (prop_name.eq_ascii_ci ("display")) out->display = prop_value;
else if (prop_name.eq_ascii_ci ("color")) out->color = prop_value;
else if (prop_name.eq_ascii_ci ("visibility")) out->visibility = prop_value;
else if (prop_name.eq_ascii_ci ("offset")) out->offset = prop_value;
else if (prop_name.eq_ascii_ci ("stop-color")) out->stop_color = prop_value;
else if (prop_name.eq_ascii_ci ("stop-opacity")) out->stop_opacity = prop_value;
else if (prop_name.eq_ascii_ci ("spreadmethod") ||
prop_name.eq_ascii_ci ("spread-method")) out->spread_method = prop_value;
else if (prop_name.eq_ascii_ci ("gradientunits") ||
prop_name.eq_ascii_ci ("gradient-units")) out->gradient_units = prop_value;
else if (prop_name.eq_ascii_ci ("gradienttransform") ||
prop_name.eq_ascii_ci ("gradient-transform")) out->gradient_transform = prop_value;
else if (prop_name.eq_ascii_ci ("x")) out->x = prop_value;
else if (prop_name.eq_ascii_ci ("y")) out->y = prop_value;
else if (prop_name.eq_ascii_ci ("width")) out->width = prop_value;
else if (prop_name.eq_ascii_ci ("height")) out->height = prop_value;
else if (prop_name.eq_ascii_ci ("cx")) out->cx = prop_value;
else if (prop_name.eq_ascii_ci ("cy")) out->cy = prop_value;
else if (prop_name.eq_ascii_ci ("r")) out->r = prop_value;
else if (prop_name.eq_ascii_ci ("fx")) out->fx = prop_value;
else if (prop_name.eq_ascii_ci ("fy")) out->fy = prop_value;
else if (prop_name.eq_ascii_ci ("fr")) out->fr = prop_value;
else if (prop_name.eq_ascii_ci ("rx")) out->rx = prop_value;
else if (prop_name.eq_ascii_ci ("ry")) out->ry = prop_value;
else if (prop_name.eq_ascii_ci ("x1")) out->x1 = prop_value;
else if (prop_name.eq_ascii_ci ("y1")) out->y1 = prop_value;
else if (prop_name.eq_ascii_ci ("x2")) out->x2 = prop_value;
else if (prop_name.eq_ascii_ci ("y2")) out->y2 = prop_value;
else if (prop_name.eq_ascii_ci ("points")) out->points = prop_value;
else if (prop_name.eq_ascii_ci ("d")) out->d = prop_value;
bool handled = false;
if (prop_name.len)
{
switch (hb_svg_ascii_lower (prop_name.data[0]))
{
case 'f':
if (prop_name.eq_ascii_ci ("fill")) { out->fill = prop_value; handled = true; }
else if (prop_name.eq_ascii_ci ("fill-opacity")) { out->fill_opacity = prop_value; handled = true; }
break;
case 'o':
if (prop_name.eq_ascii_ci ("opacity")) { out->opacity = prop_value; handled = true; }
else if (prop_name.eq_ascii_ci ("offset")) { out->offset = prop_value; handled = true; }
break;
case 't':
if (prop_name.eq_ascii_ci ("transform")) { out->transform = prop_value; handled = true; }
break;
case 'c':
if (prop_name.eq_ascii_ci ("clip-path")) { out->clip_path = prop_value; handled = true; }
else if (prop_name.eq_ascii_ci ("color")) { out->color = prop_value; handled = true; }
break;
case 'd':
if (prop_name.eq_ascii_ci ("display")) { out->display = prop_value; handled = true; }
else if (prop_name.eq_ascii_ci ("d")) { out->d = prop_value; handled = true; }
break;
case 'v':
if (prop_name.eq_ascii_ci ("visibility")) { out->visibility = prop_value; handled = true; }
break;
default:
break;
}
}
if (!handled && prop_name.eq_ascii_ci ("stop-color")) out->stop_color = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("stop-opacity")) out->stop_opacity = prop_value;
else if (!handled && (prop_name.eq_ascii_ci ("spreadmethod") ||
prop_name.eq_ascii_ci ("spread-method"))) out->spread_method = prop_value;
else if (!handled && (prop_name.eq_ascii_ci ("gradientunits") ||
prop_name.eq_ascii_ci ("gradient-units"))) out->gradient_units = prop_value;
else if (!handled && (prop_name.eq_ascii_ci ("gradienttransform") ||
prop_name.eq_ascii_ci ("gradient-transform"))) out->gradient_transform = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("x")) out->x = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("y")) out->y = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("width")) out->width = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("height")) out->height = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("cx")) out->cx = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("cy")) out->cy = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("r")) out->r = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("fx")) out->fx = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("fy")) out->fy = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("fr")) out->fr = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("rx")) out->rx = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("ry")) out->ry = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("x1")) out->x1 = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("y1")) out->y1 = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("x2")) out->x2 = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("y2")) out->y2 = prop_value;
else if (!handled && prop_name.eq_ascii_ci ("points")) out->points = prop_value;
if (p < end && *p == ';') p++;
}