svgio/qa/cppunit/SvgImportTest.cxx | 27 +++++++++++++++ svgio/qa/cppunit/data/tdf156269.svg | 8 ++++ svgio/source/svgreader/svgcharacternode.cxx | 48 ++++++++++++++-------------- 3 files changed, 59 insertions(+), 24 deletions(-)
New commits: commit 1df7a1ac274db509f1a135b84a01ea51c4d0c1f9 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Jul 13 11:14:25 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jul 13 23:09:53 2023 +0200 tdf#156269: dx and dy do not depend on x and y Change-Id: I99be5aa45b333ec3825373c3a10be0e24d23cb29 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154380 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index b3d20603cfa7..7263439e86c1 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -1404,6 +1404,33 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf97663) assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "y", "236"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf156269) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156269.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "//textsimpleportion[@text='one']", "width", "16"); + assertXPath(pDocument, "//textsimpleportion[@text='one']", "height", "16"); + assertXPath(pDocument, "//textsimpleportion[@text='one']", "x", "10"); + assertXPath(pDocument, "//textsimpleportion[@text='one']", "y", "50"); + assertXPath(pDocument, "//textsimpleportion[@text='one']", "fontcolor", "#808080"); + + assertXPath(pDocument, "//textsimpleportion[@text='two']", "width", "16"); + assertXPath(pDocument, "//textsimpleportion[@text='two']", "height", "16"); + + // Without the fix in place, this test would have failed with + // - Expected: 60 + // - Actual : 10 + assertXPath(pDocument, "//textsimpleportion[@text='two']", "x", "60"); + assertXPath(pDocument, "//textsimpleportion[@text='two']", "y", "100"); + assertXPath(pDocument, "//textsimpleportion[@text='two']", "fontcolor", "#000000"); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf149880) { Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf149880.svg"); diff --git a/svgio/qa/cppunit/data/tdf156269.svg b/svgio/qa/cppunit/data/tdf156269.svg new file mode 100644 index 000000000000..e840b351d17d --- /dev/null +++ b/svgio/qa/cppunit/data/tdf156269.svg @@ -0,0 +1,8 @@ +<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> + <!-- Some reference text --> + <text x="10%" y="50%" fill="grey">one</text> + + <!-- The same text with a shift --> + <text dx="50%" dy="50%" x="10%" y="50%">two</text> +</svg> + diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx index 4ffc46a483db..e62d21528d96 100644 --- a/svgio/source/svgreader/svgcharacternode.cxx +++ b/svgio/source/svgreader/svgcharacternode.cxx @@ -645,23 +645,23 @@ namespace svgio::svgreader { maPosition.setX(pParent->getPosition().getX()); } + } + + const sal_uInt32 nSizeDx(rSvgTextPositions.getDx().size()); - const sal_uInt32 nSizeDx(rSvgTextPositions.getDx().size()); + if(nSizeDx) + { + // relative positions given, translate position derived from parent + maPosition.setX(maPosition.getX() + rSvgTextPositions.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate)); - if(nSizeDx) + if(nSizeDx > 1) { - // relative positions given, translate position derived from parent - maPosition.setX(maPosition.getX() + rSvgTextPositions.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate)); + // fill deltas to maX + maX.reserve(nSizeDx); - if(nSizeDx > 1) + for(sal_uInt32 a(1); a < nSizeDx; a++) { - // fill deltas to maX - maX.reserve(nSizeDx); - - for(sal_uInt32 a(1); a < nSizeDx; a++) - { - maX.push_back(rSvgTextPositions.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate)); - } + maX.push_back(rSvgTextPositions.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate)); } } } @@ -693,23 +693,23 @@ namespace svgio::svgreader { maPosition.setY(pParent->getPosition().getY()); } + } + + const sal_uInt32 nSizeDy(rSvgTextPositions.getDy().size()); - const sal_uInt32 nSizeDy(rSvgTextPositions.getDy().size()); + if(nSizeDy) + { + // relative positions given, translate position derived from parent + maPosition.setY(maPosition.getY() + rSvgTextPositions.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate)); - if(nSizeDy) + if(nSizeDy > 1) { - // relative positions given, translate position derived from parent - maPosition.setY(maPosition.getY() + rSvgTextPositions.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate)); + // fill deltas to maY + maY.reserve(nSizeDy); - if(nSizeDy > 1) + for(sal_uInt32 a(1); a < nSizeDy; a++) { - // fill deltas to maY - maY.reserve(nSizeDy); - - for(sal_uInt32 a(1); a < nSizeDy; a++) - { - maY.push_back(rSvgTextPositions.getDy()[a].solve(rInfoProvider, NumberType::ycoordinate)); - } + maY.push_back(rSvgTextPositions.getDy()[a].solve(rInfoProvider, NumberType::ycoordinate)); } } }