[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - svgio/qa svgio/source
svgio/qa/cppunit/SvgImportTest.cxx| 66 +- svgio/qa/cppunit/data/Drawing_NoWidthHeight.svg | 12 svgio/qa/cppunit/data/Drawing_WithWidthHeight.svg | 14 svgio/source/svgreader/svgsvgnode.cxx | 51 +++-- 4 files changed, 124 insertions(+), 19 deletions(-) New commits: commit e374afa01404ef4690c4384bdafd567071b3945a Author: Tomaž Vajngerl AuthorDate: Sun May 13 20:21:17 2018 +0900 Commit: Tor Lillqvist CommitDate: Thu May 23 13:06:03 2019 +0200 svgio: fix rendering when the width/height isn't present in SVG The general size of the image should be the same when width/height attributes are present. It is very wrong to assume the size of the image is the area covered by all the primitives in the image. Change-Id: I56f241e84dee37796f9804ce2569c4eb416e83a0 Reviewed-on: https://gerrit.libreoffice.org/54191 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl (cherry picked from commit 7e6dac4edce063a766497ecb498e293bf4e16e66) Reviewed-on: https://gerrit.libreoffice.org/72821 Reviewed-by: Tor Lillqvist Tested-by: Tor Lillqvist diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index d91e6331fcef..68fb55696325 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -28,11 +28,13 @@ namespace { +using namespace css; using namespace css::uno; using namespace css::io; using namespace css::graphic; using drawinglayer::primitive2d::Primitive2DSequence; using drawinglayer::primitive2d::Primitive2DContainer; +using drawinglayer::primitive2d::Primitive2DReference; class Test : public test::BootstrapFixture, public XmlTestTools { @@ -62,6 +64,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testMaskText(); void testTdf4(); void testTdf101237(); +void testBehaviourWhenWidthAndHeightIsOrIsNotSet(); Primitive2DSequence parseSvg(const OUString& aSource); @@ -91,6 +94,7 @@ public: CPPUNIT_TEST(testMaskText); CPPUNIT_TEST(testTdf4); CPPUNIT_TEST(testTdf101237); +CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet); CPPUNIT_TEST_SUITE_END(); }; @@ -133,7 +137,6 @@ void Test::checkRectPrimitive(Primitive2DSequence const & rPrimitive) } - bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB) { const sal_Int32 nCount(rA.getLength()); @@ -630,7 +633,68 @@ void Test::testTdf101237() assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#ff"); assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#00"); assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "5"); +} + +void Test::testBehaviourWhenWidthAndHeightIsOrIsNotSet() +{ +// This test checks the behaviour when width and height attributes +// are and are not set. In both cases the result must be the same, +// however if the width / height are set, then the size of the image +// is enforced, but this isn't really possible in LibreOffice (or +// maybe we could lock the size in this case). +// The behaviour in browsers is that when a SVG image has width / height +// attributes set, then the image is shown with that size, but if it +// isn't set then it is shown as scalable image which is the size of +// the container. + +{ +Primitive2DSequence aSequence = parseSvg("svgio/qa/cppunit/data/Drawing_WithWidthHeight.svg"); +CPPUNIT_ASSERT(aSequence.hasElements()); + +geometry::RealRectangle2D aRealRect; +basegfx::B2DRange aRange; +uno::Sequence aViewParameters; + +for (Primitive2DReference const & xReference : aSequence) +{ +if (xReference.is()) +{ +aRealRect = xReference->getRange(aViewParameters); +aRange.expand(basegfx::B2DRange(aRealRect.X1, aRealRect.Y1, aRealRect.X2, aRealRect.Y2)); +} +} + +double fWidth = (aRange.getWidth() / 2540.0) * 96.0; +double fHeight = (aRange.getHeight() / 2540.0) * 96.0; + +CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fWidth, 1E-12); +CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fHeight, 1E-12); +} + +{ +Primitive2DSequence aSequence = parseSvg("svgio/qa/cppunit/data/Drawing_NoWidthHeight.svg"); +CPPUNIT_ASSERT(aSequence.hasElements()); + +geometry::RealRectangle2D aRealRect; +basegfx::B2DRange aRange; +uno::Sequence aViewParameters; + +for (Primitive2DReference const & xReference : aSequence) +{ +if (xReference.is()) +{ +aRealRect = xReference->getRange(aViewParameters); +aRange.expand(basegfx::B2DRange(aRealRect.X1, aRealRect.Y1, aRealRect.X2, aRealRect.Y2)); +}
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - svgio/qa
svgio/qa/cppunit/SvgRead.cxx |8 1 file changed, 4 insertions(+), 4 deletions(-) New commits: commit 8a82814679c986e5627151ae84340974c468ac18 Author: Mike Kaganski AuthorDate: Mon Mar 11 22:18:14 2019 +0300 Commit: Tomaž Vajngerl CommitDate: Mon Mar 11 21:26:07 2019 +0100 Fix build [CXX] svgio/qa/cppunit/SvgRead.cxx C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(103): error C2440: '': cannot convert from 'Color' to 'sal_Int32' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(103): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(103): error C2672: 'CppUnit::assertEquals': no matching overloaded function found C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(103): error C2780: 'void CppUnit::assertEquals(const T &,const T &,CppUnit::SourceLine,const std::string &)': expects 4 arguments - 3 provided C:\lo\src\core2\workdir\UnpackedTarball\cppunit\include\cppunit/TestAssert.h(127): note: see declaration of 'CppUnit::assertEquals' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(105): error C2440: '': cannot convert from 'Color' to 'sal_Int32' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(105): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(105): error C2672: 'CppUnit::assertEquals': no matching overloaded function found C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(105): error C2780: 'void CppUnit::assertEquals(const T &,const T &,CppUnit::SourceLine,const std::string &)': expects 4 arguments - 3 provided C:\lo\src\core2\workdir\UnpackedTarball\cppunit\include\cppunit/TestAssert.h(127): note: see declaration of 'CppUnit::assertEquals' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(134): error C2440: '': cannot convert from 'Color' to 'sal_Int32' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(134): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(134): error C2672: 'CppUnit::assertEquals': no matching overloaded function found C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(134): error C2780: 'void CppUnit::assertEquals(const T &,const T &,CppUnit::SourceLine,const std::string &)': expects 4 arguments - 3 provided C:\lo\src\core2\workdir\UnpackedTarball\cppunit\include\cppunit/TestAssert.h(127): note: see declaration of 'CppUnit::assertEquals' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(136): error C2440: '': cannot convert from 'Color' to 'sal_Int32' C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(136): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(136): error C2672: 'CppUnit::assertEquals': no matching overloaded function found C:/lo/src/core2/svgio/qa/cppunit/SvgRead.cxx(136): error C2780: 'void CppUnit::assertEquals(const T &,const T &,CppUnit::SourceLine,const std::string &)': expects 4 arguments - 3 provided C:\lo\src\core2\workdir\UnpackedTarball\cppunit\include\cppunit/TestAssert.h(127): note: see declaration of 'CppUnit::assertEquals' make[1]: *** [C:/lo/src/core2/solenv/gbuild/LinkTarget.mk:293: C:/lo/src/core2/workdir/CxxObject/svgio/qa/cppunit/SvgRead.o] Error 2 make: *** [Makefile:166: CppunitTest_svgio_read] Error 2 Change-Id: I4e1cf222a416772f1920194ccfcf459f40b577d6 Reviewed-on: https://gerrit.libreoffice.org/69064 Reviewed-by: Tomaž Vajngerl Tested-by: Tomaž Vajngerl diff --git a/svgio/qa/cppunit/SvgRead.cxx b/svgio/qa/cppunit/SvgRead.cxx index 996be9d21f08..8b13bd68bb45 100644 --- a/svgio/qa/cppunit/SvgRead.cxx +++ b/svgio/qa/cppunit/SvgRead.cxx @@ -100,9 +100,9 @@ void TestParsing::testSimpleRectangle() CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(10, 10, 110, 110), pDrawRect->maRectangle); CPPUNIT_ASSERT_EQUAL(3.0, pDrawRect->mnStrokeWidth); CPPUNIT_ASSERT(bool(pDrawRect->mpStrokeColor)); -CPPUNIT_ASSERT_EQUAL(sal_Int32(0xff), sal_Int32(Color(*pDrawRect->mpStrokeColor))); +CPPUNIT_ASSERT_EQUAL(ColorData(0xff), Color(*pDrawRect->mpStrokeColor).GetRGBColor()); CPPUNIT_ASSERT(bool(pDrawRect->mpFillColor)); -CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00cc00), sal_Int32(Color(*pDrawRect->mpFillColor))); +CPPUNIT_ASSERT_EQUAL(ColorData(0x00cc00), Color(*pDrawRect->mpFillColor).GetRGBColor()); } void TestParsing::testPath() @@ -131,9 +131,9 @@ void TestParsing::testPath() basegfx::utils::exportToSvgD(pDrawPath->maPolyPolygon, true, true, false)); CPPUNIT_ASSERT_EQUAL(0.0, pDrawPath->mnStrokeWidth); CPPUNIT_ASSERT(bool(pDrawPath->mpStrokeColor)); -