Merge pull request #4450 from mapnik/svg-refactor

Svg refactor
This commit is contained in:
Artem Pavlenko 2024-04-30 10:07:21 +01:00 committed by GitHub
commit f84c30f20c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 61 deletions

View file

@ -73,7 +73,11 @@ class svg_converter : util::noncopyable
current_group_ = &current_group_->elements.back().get<group>();
}
void end_group() { current_group_ = current_group_->parent; }
void end_group()
{
if (current_group_->parent != nullptr)
current_group_ = current_group_->parent;
}
void begin_path()
{

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,14 @@ 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 +659,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);