diff options
Diffstat (limited to 'svgio')
-rw-r--r-- | svgio/inc/svgstyleattributes.hxx | 3 | ||||
-rw-r--r-- | svgio/inc/svgsymbolnode.hxx | 15 | ||||
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 36 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/tdf156834.svg | 3 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/tdf158445.svg | 5 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/tdf159594.svg | 7 | ||||
-rw-r--r-- | svgio/source/svgreader/svgcharacternode.cxx | 1 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 4 | ||||
-rw-r--r-- | svgio/source/svgreader/svgsymbolnode.cxx | 92 |
9 files changed, 162 insertions, 4 deletions
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<basegfx::B2DRange> 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<int>(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<int>(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 @@ <svg viewBox="0 0 200 120" xmlns="http://www.w3.org/2000/svg"> - <path d="M20,20 L180,20 M20,50 L180,50 M20,80 L180,80" stroke="grey" /> + <path d="M20,20 L180,20 M20,50 L180,50 M20,80 L180,80 M20,110 L180,110" stroke="grey" /> <text dominant-baseline="auto" x="30" y="20" font-size="20">Auto</text> <text dominant-baseline="middle" x="30" y="50" font-size="20">Middle</text> <text dominant-baseline="Hanging" x="30" y="80" font-size="20">Hanging</text> + <text dominant-baseline="central" x="30" y="110" font-size="20">Central</text> </svg> 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 @@ +<svg width="160.353" height="30.488" xmlns="http://www.w3.org/2000/svg" viewBox="-0.376 -26.625 160.353 30.488"> +<symbol id="STIXTwoMathRegular_4275" width="5.868" height="51.216" viewBox="0 -31.524 5.868 51.216"> +<path d="M 5.868 -2.088 L 5.868 -2.088 L 5.46 0 L 0.54 0 L 0.54 -0.588 L 2.244 -2.316 Q 2.916 -2.988 3.354 -3.504 Q 3.792 -4.02 4.008 -4.542 Q 4.224 -5.064 4.224 -5.736 Q 4.224 -6.372 3.834 -6.786 Q 3.444 -7.2 2.736 -7.2 Q 2.088 -7.2 1.65 -6.942 Q 1.212 -6.684 0.876 -6.096 L 0.552 -6.252 Q 0.852 -7.092 1.482 -7.572 Q 2.112 -8.052 3.036 -8.052 Q 3.756 -8.052 4.308 -7.794 Q 4.86 -7.536 5.172 -7.056 Q 5.484 -6.576 5.484 -5.892 Q 5.484 -5.304 5.22 -4.788 Q 4.956 -4.272 4.47 -3.732 Q 3.984 -3.192 3.312 -2.532 L 1.812 -1.08 L 1.812 -0.996 L 2.748 -1.044 L 4.308 -1.044 Q 4.656 -1.044 4.842 -1.14 Q 5.028 -1.236 5.16 -1.47 Q 5.292 -1.704 5.448 -2.088 Z " viewBox="0 -31.524 5.868 51.216"/> +</symbol> +<use href="#STIXTwoMathRegular_4275" transform="translate(151.174 -52.774) scale(1.4)" fill="black" /></svg> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100" version="1.1"> +<symbol overflow="visible" id="glyph"> +<path style="stroke:none;" d="M 1.3125 -11.671875 L 8.8125 -11.671875 L 8.8125 -11 L 4.578125 0 L 2.9375 0 L 6.921875 -10.34375 L 1.3125 -10.34375 Z M 1.3125 -11.671875 "/> +</symbol> +<use xlink:href="#glyph" x="40" y="30"/> +</svg> 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 <svgsymbolnode.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <drawinglayer/primitive2d/transformprimitive2d.hxx> 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: */ |