summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2022-09-22 10:59:29 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2022-09-22 13:43:59 +0200
commitddf695db44bcb23dc2f1459fd439f93c0b6d5f2a (patch)
tree6aab04eba98b423b424db3ca878ab8bc9d2839a7 /svgio
parentcde237f7612cc34b1a7e46b83507877754b8e921 (diff)
tdf#151118: svg: fix handling of xml:space="preserve"
This allows the code to be simplified a bit Change-Id: If42dd9d3ebd7860ece9ff78cb090ff1b07e1b432 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140404 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgtools.hxx5
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx21
-rw-r--r--svgio/qa/cppunit/data/textXmlSpace.svg12
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx4
-rw-r--r--svgio/source/svgreader/svgtools.cxx36
5 files changed, 47 insertions, 31 deletions
diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx
index a5a0b3aa418b..0a4e200c746b 100644
--- a/svgio/inc/svgtools.hxx
+++ b/svgio/inc/svgtools.hxx
@@ -125,10 +125,9 @@ namespace svgio::svgreader
void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rMimeType, OUString& rData);
- OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew, bool bRemove);
+ OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew);
OUString consolidateContiguousSpace(const OUString& rCandidate);
- OUString whiteSpaceHandlingDefault(const OUString& rCandidate);
- OUString whiteSpaceHandlingPreserve(const OUString& rCandidate);
+ OUString xmlSpaceHandling(const OUString& rCandidate, bool bIsDefault);
// #125325# removes block comment of the general form '/* ... */', returns
// an adapted string or the original if no comments included
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 07a98f4a5a2f..23734777cf2c 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -48,6 +48,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools
void testMarkerOrient();
void testMarkerInPresentation();
void testMarkerInCssStyle();
+ void testTextXmlSpace();
void testTdf45771();
void testTdf97941();
void testTdf104339();
@@ -97,6 +98,7 @@ public:
CPPUNIT_TEST(testMarkerOrient);
CPPUNIT_TEST(testMarkerInPresentation);
CPPUNIT_TEST(testMarkerInCssStyle);
+ CPPUNIT_TEST(testTextXmlSpace);
CPPUNIT_TEST(testTdf45771);
CPPUNIT_TEST(testTdf97941);
CPPUNIT_TEST(testTdf104339);
@@ -420,6 +422,25 @@ void Test::testMarkerInCssStyle()
assertXPath(pDocument, "/primitive2D/transform/transform[1]/polypolygonstroke/line", "linecap", "BUTT");
}
+void Test::testTextXmlSpace()
+{
+ //Check tspan fontsize when using relative units
+ Primitive2DSequence aSequenceTdf97941 = parseSvg(u"/svgio/qa/cppunit/data/textXmlSpace.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97941.getLength()));
+
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequenceTdf97941);
+
+ CPPUNIT_ASSERT (pDocument);
+
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[1]", "text", "a b");
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[2]", "text", "a b");
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[3]", "text", "a b");
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[4]", "text", "a b");
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[5]", "text", "a b");
+ assertXPath(pDocument, "/primitive2D/transform/mask/textsimpleportion[6]", "text", "a b");
+}
+
void Test::testTdf45771()
{
//Check text fontsize when using relative units
diff --git a/svgio/qa/cppunit/data/textXmlSpace.svg b/svgio/qa/cppunit/data/textXmlSpace.svg
new file mode 100644
index 000000000000..606e2eb7a306
--- /dev/null
+++ b/svgio/qa/cppunit/data/textXmlSpace.svg
@@ -0,0 +1,12 @@
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+ viewBox="0 0 250 250">
+ <text y="10" xml:space="default">a b</text>
+ <text y="30" xml:space="default">a b</text>
+ <text y="50" xml:space="default">a
+ b</text>
+ <text y="70" xml:space="preserve">a b</text>
+ <text y="90" xml:space="preserve">a b</text>
+ <text y="110" xml:space="preserve">a
+ b</text>
+</svg>
+
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index 31376ee179a8..456a3abc8013 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -541,11 +541,11 @@ namespace svgio::svgreader
{
if (XmlSpace::Default == getXmlSpace())
{
- maText = whiteSpaceHandlingDefault(maText);
+ maText = xmlSpaceHandling(maText, true);
}
else
{
- maText = whiteSpaceHandlingPreserve(maText);
+ maText = xmlSpaceHandling(maText, false);
}
}
diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx
index 5e56ee83b19e..92b2ecab3fb3 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -1375,7 +1375,7 @@ namespace svgio::svgreader
}
}
- OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew, bool bRemove)
+ OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew)
{
const sal_Int32 nLen(rCandidate.getLength());
@@ -1392,11 +1392,7 @@ namespace svgio::svgreader
if(nPattern == aChar)
{
bChanged = true;
-
- if(!bRemove)
- {
- aBuffer.append(nNew);
- }
+ aBuffer.append(nNew);
}
else
{
@@ -1513,42 +1509,30 @@ namespace svgio::svgreader
return rCandidate;
}
- OUString whiteSpaceHandlingDefault(const OUString& rCandidate)
+ OUString xmlSpaceHandling(const OUString& rCandidate, bool bIsDefault)
{
const sal_Unicode aNewline('\n');
const sal_Unicode aTab('\t');
const sal_Unicode aSpace(' ');
// remove all newline characters
- OUString aRetval(convert(rCandidate, aNewline, aNewline, true));
+ OUString aRetval(convert(rCandidate, aNewline, aSpace));
// convert tab to space
- aRetval = convert(aRetval, aTab, aSpace, false);
+ aRetval = convert(aRetval, aTab, aSpace);
// strip of all leading and trailing spaces
aRetval = aRetval.trim();
- // consolidate contiguous space
- aRetval = consolidateContiguousSpace(aRetval);
+ if(bIsDefault)
+ {
+ // consolidate contiguous space
+ aRetval = consolidateContiguousSpace(aRetval);
+ }
return aRetval;
}
- OUString whiteSpaceHandlingPreserve(const OUString& rCandidate)
- {
- const sal_Unicode aNewline('\n');
- const sal_Unicode aTab('\t');
- const sal_Unicode aSpace(' ');
-
- // convert newline to space
- convert(rCandidate, aNewline, aSpace, false);
-
- // convert tab to space
- convert(rCandidate, aTab, aSpace, false);
-
- return rCandidate;
- }
-
::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider)
{
::std::vector< double > aRetval;