From 5a7157d319477830426797532e02ac39d3b859f4 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 11:29:03 +0200 Subject: Merging upstream version 4:24.2.1. Signed-off-by: Daniel Baumann --- svgio/inc/svgstyleattributes.hxx | 3 +- svgio/inc/svgsymbolnode.hxx | 15 +++++ svgio/qa/cppunit/SvgImportTest.cxx | 36 ++++++++++- svgio/qa/cppunit/data/tdf156834.svg | 3 +- svgio/qa/cppunit/data/tdf158445.svg | 5 ++ svgio/qa/cppunit/data/tdf159594.svg | 7 ++ svgio/source/svgreader/svgcharacternode.cxx | 1 + svgio/source/svgreader/svgstyleattributes.cxx | 4 ++ svgio/source/svgreader/svgsymbolnode.cxx | 92 ++++++++++++++++++++++++++- 9 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 svgio/qa/cppunit/data/tdf158445.svg create mode 100644 svgio/qa/cppunit/data/tdf159594.svg (limited to 'svgio') diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index 6078194266..4516773e83 100644 --- a/svgio/inc/svgstyleattributes.hxx +++ b/svgio/inc/svgstyleattributes.hxx @@ -166,7 +166,8 @@ namespace svgio::svgreader { Auto, Middle, - Hanging + Hanging, + Central }; enum class Visibility diff --git a/svgio/inc/svgsymbolnode.hxx b/svgio/inc/svgsymbolnode.hxx index 7a19b335b7..e82f75a767 100644 --- a/svgio/inc/svgsymbolnode.hxx +++ b/svgio/inc/svgsymbolnode.hxx @@ -29,6 +29,12 @@ namespace svgio::svgreader /// use styles SvgStyleAttributes maSvgStyleAttributes; + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + + std::unique_ptr mpViewBox; SvgAspectRatio maSvgAspectRatio; public: @@ -39,6 +45,15 @@ namespace svgio::svgreader virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; virtual void parseAttribute(SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// viewBox content + const basegfx::B2DRange* getViewBox() const { return mpViewBox.get(); } + void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset( new basegfx::B2DRange(*pViewBox) ); } + + /// SvgAspectRatio content + const SvgAspectRatio& getSvgAspectRatio() const { return maSvgAspectRatio; } + }; } // end of namespace svgio::svgreader diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 1b0be44177..0ba32d8cb9 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -764,7 +764,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156834) CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, 3); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, 4); assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, "text"_ostr, "Auto"); assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, "x"_ostr, "30"); assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, "y"_ostr, "20"); @@ -776,6 +776,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156834) assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, "text"_ostr, "Hanging"); assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, "x"_ostr, "30"); assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, "y"_ostr, "94"); + + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]"_ostr, "text"_ostr, "Central"); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]"_ostr, "x"_ostr, "30"); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]"_ostr, "y"_ostr, "116"); } CPPUNIT_TEST_FIXTURE(Test, testTdf104339) @@ -1591,6 +1595,36 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf155733) assertXPath(pDocument, "/primitive2D/transform/transform/unifiedtransparence"_ostr, "transparence"_ostr, "50"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf158445) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf158445.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/mask/transform/transform/transform/polypolygoncolor"_ostr, "color"_ostr, "#000000"); + assertXPath(pDocument, "/primitive2D/transform/mask/transform/transform/transform/polypolygoncolor/polypolygon"_ostr, "height"_ostr, "8.052"); + assertXPath(pDocument, "/primitive2D/transform/mask/transform/transform/transform/polypolygoncolor/polypolygon"_ostr, "width"_ostr, "5.328"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf159594) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf159594.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor"_ostr, "color"_ostr, "#000000"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon"_ostr, "height"_ostr, "11.671875"); + assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon"_ostr, "width"_ostr, "7.5"); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf97663) { Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/em_units.svg"); diff --git a/svgio/qa/cppunit/data/tdf156834.svg b/svgio/qa/cppunit/data/tdf156834.svg index 74dc154818..0ef81f9a6a 100644 --- a/svgio/qa/cppunit/data/tdf156834.svg +++ b/svgio/qa/cppunit/data/tdf156834.svg @@ -1,7 +1,8 @@ - + Auto Middle Hanging + Central diff --git a/svgio/qa/cppunit/data/tdf158445.svg b/svgio/qa/cppunit/data/tdf158445.svg new file mode 100644 index 0000000000..20e084dd05 --- /dev/null +++ b/svgio/qa/cppunit/data/tdf158445.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/svgio/qa/cppunit/data/tdf159594.svg b/svgio/qa/cppunit/data/tdf159594.svg new file mode 100644 index 0000000000..c2b470ec0f --- /dev/null +++ b/svgio/qa/cppunit/data/tdf159594.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx index 7d5a2fcb9f..02bc3911a3 100644 --- a/svgio/source/svgreader/svgcharacternode.cxx +++ b/svgio/source/svgreader/svgcharacternode.cxx @@ -287,6 +287,7 @@ namespace svgio::svgreader switch(aDominantBaseline) { case DominantBaseline::Middle: + case DominantBaseline::Central: { aPosition.setY(aPosition.getY() - aRange.getCenterY()); break; diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 869b071dad..731df59aee 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1969,6 +1969,10 @@ namespace svgio::svgreader { setDominantBaseline(DominantBaseline::Hanging); } + else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"central")) + { + setDominantBaseline(DominantBaseline::Central); + } else { // no DominantBaseline diff --git a/svgio/source/svgreader/svgsymbolnode.cxx b/svgio/source/svgreader/svgsymbolnode.cxx index 6e18d4bca0..2f226b841e 100644 --- a/svgio/source/svgreader/svgsymbolnode.cxx +++ b/svgio/source/svgreader/svgsymbolnode.cxx @@ -18,6 +18,8 @@ */ #include +#include +#include namespace svgio::svgreader { @@ -54,9 +56,60 @@ namespace svgio::svgreader readLocalCssStyle(aContent); break; } + case SVGToken::X: + { + SvgNumber aNum; + + if(readSingleNumber(aContent, aNum)) + { + maX = aNum; + } + break; + } + case SVGToken::Y: + { + SvgNumber aNum; + + if(readSingleNumber(aContent, aNum)) + { + maY = aNum; + } + break; + } + case SVGToken::Width: + { + SvgNumber aNum; + + if(readSingleNumber(aContent, aNum)) + { + if(aNum.isPositive()) + { + maWidth = aNum; + } + } + break; + } + case SVGToken::Height: + { + SvgNumber aNum; + + if(readSingleNumber(aContent, aNum)) + { + if(aNum.isPositive()) + { + maHeight = aNum; + } + } + break; + } case SVGToken::ViewBox: { - readViewBox(aContent, *this); + const basegfx::B2DRange aRange(readViewBox(aContent, *this)); + + if(!aRange.isEmpty()) + { + setViewBox(&aRange); + } break; } case SVGToken::PreserveAspectRatio: @@ -71,6 +124,43 @@ namespace svgio::svgreader } } + void SvgSymbolNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const + { + // decompose children + SvgNode::decomposeSvgNode(rTarget, bReferenced); + + if (rTarget.empty()) + return; + + if(getViewBox()) + { + // create mapping + // #i122610 SVG 1.1 defines in section 5.1.2 that if the attribute preserveAspectRatio is not specified, + // then the effect is as if a value of 'xMidYMid meet' were specified. + SvgAspectRatio aRatioDefault(SvgAlign::xMidYMid, true); + const SvgAspectRatio& rRatio = getSvgAspectRatio().isSet()? getSvgAspectRatio() : aRatioDefault; + + const double fX(maX.solve(*this, NumberType::xcoordinate)); + const double fY(maY.solve(*this, NumberType::ycoordinate)); + const double fWidth(maWidth.solve(*this, NumberType::xcoordinate)); + const double fHeight(maHeight.solve(*this, NumberType::ycoordinate)); + const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight); + + // let mapping be created from SvgAspectRatio + const basegfx::B2DHomMatrix aEmbeddingTransform( + rRatio.createMapping(aRange, *getViewBox())); + + // prepare embedding in transformation + // create embedding group element with transformation + const drawinglayer::primitive2d::Primitive2DReference xRef( + new drawinglayer::primitive2d::TransformPrimitive2D( + aEmbeddingTransform, + drawinglayer::primitive2d::Primitive2DContainer(rTarget))); + + rTarget.push_back(xRef); + } + } + } // end of namespace svgio::svgreader /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3