SVG parser - add ignore_
member variable to allow skipping of unsupported elements, currently clipPath
(#3818)
This commit is contained in:
parent
a04ca98c6b
commit
ff31c6d6eb
2 changed files with 15 additions and 3 deletions
|
@ -74,6 +74,7 @@ public:
|
|||
svg_converter_type & path_;
|
||||
bool is_defs_;
|
||||
bool strict_;
|
||||
bool ignore_;
|
||||
std::map<std::string, gradient> gradient_map_;
|
||||
std::map<std::string, boost::property_tree::detail::rapidxml::xml_node<char> const*> node_cache_;
|
||||
agg::trans_affine viewbox_tr_{};
|
||||
|
|
|
@ -368,6 +368,7 @@ bool parse_id_from_url (char const* str, std::string & id)
|
|||
|
||||
void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
|
||||
{
|
||||
if (parser.ignore_) return;
|
||||
auto const* name = node->name();
|
||||
switch (node->type())
|
||||
{
|
||||
|
@ -383,6 +384,11 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "clipPath"_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:
|
||||
|
@ -467,21 +473,25 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
|
|||
|
||||
void end_element(svg_parser & parser, rapidxml::xml_node<char> const* node)
|
||||
{
|
||||
auto const* name = node->name();
|
||||
if (!parser.is_defs_ && std::strcmp(name, "g") == 0)
|
||||
auto name = name_to_int(node->name());
|
||||
if (!parser.is_defs_ && (name == "g"_case))
|
||||
{
|
||||
if (node->first_node() != nullptr)
|
||||
{
|
||||
parser.path_.pop_attr();
|
||||
}
|
||||
}
|
||||
else if (std::strcmp(name, "defs") == 0)
|
||||
else if (name == "defs"_case)
|
||||
{
|
||||
if (node->first_node() != nullptr)
|
||||
{
|
||||
parser.is_defs_ = false;
|
||||
}
|
||||
}
|
||||
else if(name == "clipPath"_case)
|
||||
{
|
||||
parser.ignore_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void parse_element(svg_parser & parser, char const* name, rapidxml::xml_node<char> const* node)
|
||||
|
@ -1414,6 +1424,7 @@ void parse_linear_gradient(svg_parser & parser, rapidxml::xml_node<char> const*
|
|||
svg_parser::svg_parser(svg_converter_type & path, bool strict)
|
||||
: path_(path),
|
||||
is_defs_(false),
|
||||
ignore_(false),
|
||||
err_handler_(strict) {}
|
||||
|
||||
svg_parser::~svg_parser() {}
|
||||
|
|
Loading…
Reference in a new issue