From e412e125995a72ecbe2cbc685c5ba820021e929b Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 30 Apr 2024 10:01:02 +0100 Subject: [PATCH] svg_parser - cleanup + consistent push/pop attributes --- src/svg/svg_parser.cpp | 216 +++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 118 deletions(-) diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index c67cf4466..853438fd3 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -500,117 +500,102 @@ void traverse_tree(svg_parser& parser, rapidxml::xml_node const* node) switch (node->type()) { - case rapidxml::node_element: { - parser.font_sizes_.push_back(parser.font_sizes_.back()); - switch (name) + case rapidxml::node_element: + parser.font_sizes_.push_back(parser.font_sizes_.back()); + switch (name) + { + case "defs"_case: { + if (node->first_node() != nullptr) { - case "defs"_case: { - if (node->first_node() != nullptr) - { - parser.is_defs_ = true; - } - break; - } - case "clipPath"_case: - case "symbol"_case: - case "pattern"_case: { - parser.ignore_ = true; - break; - } - // the gradient tags *should* be in defs, but illustrator seems not to put them in there so - // accept them anywhere - case "linearGradient"_case: - parse_linear_gradient(parser, node); - break; - case "radialGradient"_case: - parse_radial_gradient(parser, node); - break; + parser.is_defs_ = true; } - - 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(); - parse_id(parser, node); - if (parser.css_style_) - process_css(parser, node); - parse_attr(parser, node); - if (parser.path_.cur_attr().opacity < 1.0) - parser.path_.begin_group(); - parse_use(parser, node); - if (parser.path_.cur_attr().opacity < 1.0) - parser.path_.end_group(); - parser.path_.pop_attr(); - break; - default: - parser.path_.push_attr(); - parse_id(parser, node); - if (parser.css_style_) - process_css(parser, node); - parse_attr(parser, node); - if (parser.path_.display()) - { - if (parser.path_.cur_attr().opacity < 1.0) - parser.path_.begin_group(); - parse_element(parser, node->name(), node); - if (parser.path_.cur_attr().opacity < 1.0) - parser.path_.end_group(); - } - parser.path_.pop_attr(); - } - } - else - { - // save node for later - parse_id(parser, node); - } - - if ("style"_case == name) - { - //