From ddf695db44bcb23dc2f1459fd439f93c0b6d5f2a Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Thu, 22 Sep 2022 10:59:29 +0200 Subject: 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 --- svgio/source/svgreader/svgcharacternode.cxx | 4 ++-- svgio/source/svgreader/svgtools.cxx | 36 ++++++++--------------------- 2 files changed, 12 insertions(+), 28 deletions(-) (limited to 'svgio/source') 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; -- cgit