Don't apply preserveAscpectRatio logic logic if width and height expressed as % values (#3812)

This commit is contained in:
Artem Pavlenko 2017-12-06 11:00:06 +01:00
parent 2f28d9897f
commit 5227f84e07

View file

@ -745,7 +745,6 @@ void parse_dimensions(svg_parser & parser, rapidxml::xml_node<char> const* node)
double height = 0;
double aspect_ratio = 1;
viewbox vbox = {0, 0, 0, 0};
bool has_viewbox = false;
bool has_percent_height = true;
bool has_percent_width = true;
@ -761,9 +760,10 @@ void parse_dimensions(svg_parser & parser, rapidxml::xml_node<char> const* node)
}
auto const* viewbox_attr = node->first_attribute("viewBox");
if (viewbox_attr)
if (viewbox_attr && parse_viewbox(parser.err_handler(), viewbox_attr->value(), vbox))
{
if (!has_percent_width && !has_percent_height)
{
has_viewbox = parse_viewbox(parser.err_handler(), viewbox_attr->value(), vbox);
if (width > 0 && height > 0 && vbox.width > 0 && vbox.height > 0)
{
agg::trans_affine t{};
@ -826,24 +826,23 @@ void parse_dimensions(svg_parser & parser, rapidxml::xml_node<char> const* node)
t = agg::trans_affine_translation(-vbox.x0, -vbox.y0) * t;
parser.viewbox_tr_ = t;
}
}
if (has_percent_width && !has_percent_height && has_viewbox)
if (has_percent_width && !has_percent_height)
{
aspect_ratio = vbox.width / vbox.height;
width = aspect_ratio * height;
}
else if (!has_percent_width && has_percent_height && has_viewbox)
else if (!has_percent_width && has_percent_height)
{
aspect_ratio = vbox.width/vbox.height;
height = height / aspect_ratio;
}
else if (has_percent_width && has_percent_height && has_viewbox)
else if (has_percent_width && has_percent_height)
{
width = vbox.width;
height = vbox.height;
}
}
parser.path_.set_dimensions(width, height);
}