@@ -1688,26 +1688,52 @@ TEST (SVGParserTests, ParseFontSizeWithUnits)
16881688
16891689TEST (SVGParserTests, ParsePreserveAspectRatioNone)
16901690{
1691- Drawable d;
1692- EXPECT_TRUE (d.parseSVG (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" none\" ></svg>" ));
1691+ auto doc = SVGParser::parse (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" none\" ></svg>" );
1692+ ASSERT_NE (doc, nullptr );
1693+ doc->visit ([] (const SVGData& data)
1694+ {
1695+ EXPECT_TRUE (data.rootHasPreserveAspectRatio );
1696+ EXPECT_EQ (Fitting::fill, data.rootPreserveAspectRatioFitting );
1697+ });
16931698}
16941699
16951700TEST (SVGParserTests, ParsePreserveAspectRatioXMidYMid)
16961701{
1697- Drawable d;
1698- EXPECT_TRUE (d.parseSVG (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMidYMid meet\" ></svg>" ));
1702+ auto doc = SVGParser::parse (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMidYMid meet\" ></svg>" );
1703+ ASSERT_NE (doc, nullptr );
1704+ doc->visit ([] (const SVGData& data)
1705+ {
1706+ EXPECT_TRUE (data.rootHasPreserveAspectRatio );
1707+ EXPECT_EQ (Fitting::scaleToFit, data.rootPreserveAspectRatioFitting );
1708+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::horizontalCenter));
1709+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::verticalCenter));
1710+ });
16991711}
17001712
17011713TEST (SVGParserTests, ParsePreserveAspectRatioXMinYMin)
17021714{
1703- Drawable d;
1704- EXPECT_TRUE (d.parseSVG (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMinYMin meet\" ></svg>" ));
1715+ auto doc = SVGParser::parse (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMinYMin meet\" ></svg>" );
1716+ ASSERT_NE (doc, nullptr );
1717+ doc->visit ([] (const SVGData& data)
1718+ {
1719+ EXPECT_TRUE (data.rootHasPreserveAspectRatio );
1720+ EXPECT_EQ (Fitting::scaleToFit, data.rootPreserveAspectRatioFitting );
1721+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::left));
1722+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::top));
1723+ });
17051724}
17061725
17071726TEST (SVGParserTests, ParsePreserveAspectRatioXMaxYMax)
17081727{
1709- Drawable d;
1710- EXPECT_TRUE (d.parseSVG (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMaxYMax slice\" ></svg>" ));
1728+ auto doc = SVGParser::parse (" <svg viewBox=\" 0 0 100 100\" preserveAspectRatio=\" xMaxYMax slice\" ></svg>" );
1729+ ASSERT_NE (doc, nullptr );
1730+ doc->visit ([] (const SVGData& data)
1731+ {
1732+ EXPECT_TRUE (data.rootHasPreserveAspectRatio );
1733+ EXPECT_EQ (Fitting::scaleToFill, data.rootPreserveAspectRatioFitting );
1734+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::right));
1735+ EXPECT_TRUE (data.rootPreserveAspectRatioJustification .testFlags (Justification::bottom));
1736+ });
17111737}
17121738
17131739TEST (SVGParserTests, ParsePreserveAspectRatioWithInternalEntities)
@@ -1736,23 +1762,25 @@ TEST (SVGParserTests, ParsePreserveAspectRatioWithInternalEntities)
17361762
17371763 ASSERT_NE (doc, nullptr );
17381764
1739- bool foundSmileCircle = false ;
1765+ int nestedSmileCircles = 0 ;
17401766 doc->visit ([&] (const SVGData& data)
17411767 {
1742- std::function<void (const SVGElement&)> visitElement = [&] (const SVGElement& element)
1768+ std::function<void (const SVGElement&, bool )> visitElement = [&] (const SVGElement& element, bool insideNestedSVG )
17431769 {
1744- if (element.tagName == " circle" )
1745- foundSmileCircle = true ;
1770+ const auto isNestedSVG = insideNestedSVG || (element.tagName == " svg" && element.viewBox .has_value ());
1771+
1772+ if (isNestedSVG && element.tagName == " circle" )
1773+ ++nestedSmileCircles;
17461774
17471775 for (const auto & child : element.children )
1748- visitElement (*child);
1776+ visitElement (*child, isNestedSVG );
17491777 };
17501778
17511779 for (const auto & element : data.elements )
1752- visitElement (*element);
1780+ visitElement (*element, false );
17531781 });
17541782
1755- EXPECT_TRUE (foundSmileCircle );
1783+ EXPECT_EQ ( 1 , nestedSmileCircles );
17561784}
17571785
17581786TEST (SVGParserTests, ParsePreserveAspectRatioOnSymbol)
0 commit comments