diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-19 16:17:00 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-06-23 18:49:12 +0200 |
commit | 66d92943fd2ec8b9e4068326785455102a8bae35 (patch) | |
tree | 01767463d9d08a07996bae5098135d8506eacc01 /svgio | |
parent | 31bb86fe8be035cbf71ca2e2d7b5db92c55b6cf3 (diff) |
tdf#145896: set style to 'text/css' by default
This is a regression from 4c31a0be1d8048bf3340acbb59248185e4b93041
"Resolves: #i125326# accept CssStyles with missing type attribute"
Calling setTextCss(true) when there are no attributes is wrong,
since it might have attributes like 'id'.
The unittest added also covers i125326 is still fixed
Change-Id: Ic5e4899211ae98c866f64f17e69a3a8cd24e4959
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153279
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153310
Diffstat (limited to 'svgio')
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 18 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/tdf145896.svg | 12 | ||||
-rw-r--r-- | svgio/source/svgreader/svgdocumenthandler.cxx | 17 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstylenode.cxx | 6 |
4 files changed, 36 insertions, 17 deletions
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index c8305517ce00..ce9329b1a21a 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -273,6 +273,24 @@ CPPUNIT_TEST_FIXTURE(Test, testFontsizeRelative) assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "familyname", "serif"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf145896) +{ + Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf145896.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence); + + CPPUNIT_ASSERT (pDocument); + + // Without the fix in place, this test would have failed with + // - Expected: #ffff00 + // - Actual : #000000 + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "color", "#ffff00"); + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "color", "#008000"); + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[3]", "color", "#0000ff"); +} + CPPUNIT_TEST_FIXTURE(Test, testMarkerOrient) { Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/MarkerOrient.svg"); diff --git a/svgio/qa/cppunit/data/tdf145896.svg b/svgio/qa/cppunit/data/tdf145896.svg new file mode 100644 index 000000000000..d434a961b9d0 --- /dev/null +++ b/svgio/qa/cppunit/data/tdf145896.svg @@ -0,0 +1,12 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-0 0 300 300"> + + <style id="style2"> + .st0{fill:yellow;}.st1{fill:green;} + </style> + <style type="text/some-unknown-styling-language"> + .st2{fill:red;} + </style> + <rect x="0" y="0" height="50" width="50" class="st0" fill="blue"></rect> + <rect x="60" y="0" height="50" width="50" class="st1" fill="blue"></rect> + <rect x="120" y="0" height="50" width="50" class="st2" fill="blue"></rect> +</svg> diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx index dc2dd6fa7c6b..fffc4106c768 100644 --- a/svgio/source/svgreader/svgdocumenthandler.cxx +++ b/svgio/source/svgreader/svgdocumenthandler.cxx @@ -299,21 +299,10 @@ namespace { SvgStyleNode* pNew = new SvgStyleNode(maDocument, mpTarget); mpTarget = pNew; - const sal_uInt32 nAttributes(xAttribs->getLength()); - if(0 == nAttributes) - { - // #i125326# no attributes, thus also no type="text/css". This is allowed to be missing, - // thus do mark this style as CssStyle. This is required to read the contained - // text (which defines the css style) - pNew->setTextCss(true); - } - else - { - // #i125326# there are attributes, read them. This will set isTextCss to true if - // a type="text/css" is contained as exact match, else not - mpTarget->parseAttributes(xAttribs); - } + // #i125326# there are attributes, read them. This will set isTextCss to false if + // type attibute is different to "text/css" + mpTarget->parseAttributes(xAttribs); if(pNew->isTextCss()) { diff --git a/svgio/source/svgreader/svgstylenode.cxx b/svgio/source/svgreader/svgstylenode.cxx index ef25e6a83b47..b11f7129e0b3 100644 --- a/svgio/source/svgreader/svgstylenode.cxx +++ b/svgio/source/svgreader/svgstylenode.cxx @@ -28,7 +28,7 @@ namespace svgio::svgreader SvgDocument& rDocument, SvgNode* pParent) : SvgNode(SVGToken::Style, rDocument, pParent), - mbTextCss(false) + mbTextCss(true) { } @@ -57,9 +57,9 @@ namespace svgio::svgreader { if(!aContent.isEmpty()) { - if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"text/css")) + if(!o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"text/css")) { - setTextCss(true); + setTextCss(false); } } break; |