svg_parser - cleanup + consistent push/pop attributes

This commit is contained in:
Artem Pavlenko 2024-04-30 10:01:02 +01:00
parent 77cd733258
commit e412e12599

View file

@ -500,7 +500,7 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
switch (node->type())
{
case rapidxml::node_element: {
case rapidxml::node_element:
parser.font_sizes_.push_back(parser.font_sizes_.back());
switch (name)
{
@ -525,22 +525,13 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
case "radialGradient"_case:
parse_radial_gradient(parser, node);
break;
}
if (!parser.is_defs_) // FIXME
{
switch (name)
{
case "g"_case:
if (node->first_node() != nullptr)
{
parser.path_.push_attr();
parse_id(parser, node);
if (parser.css_style_)
process_css(parser, node);
parse_attr(parser, node);
parser.path_.begin_group();
}
break;
case "use"_case:
parser.path_.push_attr();
@ -570,12 +561,7 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
parser.path_.end_group();
}
parser.path_.pop_attr();
}
}
else
{
// save node for later
parse_id(parser, node);
break;
}
if ("style"_case == name)
@ -607,7 +593,6 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node<char> const* node)
}
end_element(parser, node);
}
break;
default:
break;
@ -618,20 +603,15 @@ void end_element(svg_parser& parser, rapidxml::xml_node<char> const* node)
{
parser.font_sizes_.pop_back();
auto name = name_to_int(node->name());
if (!parser.is_defs_ && (name == "g"_case))
if (name == "g"_case)
{
parser.path_.end_group();
if (node->first_node() != nullptr)
{
parser.path_.pop_attr();
}
}
else if (name == "svg"_case)
{
// if (node->first_node() != nullptr)
//{
// parser.path_.pop_attr();
//}
parser.path_.pop_attr();
}
else if (name == "defs"_case)
{
@ -680,7 +660,7 @@ void parse_element(svg_parser& parser, char const* name, rapidxml::xml_node<char
parse_ellipse(parser, node);
break;
case "svg"_case:
// parser.path_.push_attr();
parser.path_.push_attr();
parse_dimensions(parser, node);
parse_attr(parser, node);
parser.path_.set_opacity(parser.path_.cur_attr().opacity);