summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-08-10 11:49:19 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-08-10 16:34:04 +0200
commit4f656a057e2a92e2107f7820fc563498c801d7d3 (patch)
treed218e6684940d939753410e182b228b2f6bdb5de /svgio
parent5b54f61e2c969a547582f759803f3c4f80d44697 (diff)
svgio: handle addGap internally inside SvgCharacterNode
Also add the gap at the beginning of the current node, not at the end of the previous one Change-Id: I6583059b4a7418010ac2af459e00fb0d02d39605 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155552 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgcharacternode.hxx4
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx16
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx42
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx41
4 files changed, 50 insertions, 53 deletions
diff --git a/svgio/inc/svgcharacternode.hxx b/svgio/inc/svgcharacternode.hxx
index f44d7547b4ca..e0e353a429a7 100644
--- a/svgio/inc/svgcharacternode.hxx
+++ b/svgio/inc/svgcharacternode.hxx
@@ -104,14 +104,12 @@ namespace svgio::svgreader
void decomposeText(drawinglayer::primitive2d::Primitive2DContainer& rTarget, SvgTextPosition& rSvgTextPosition) const;
void whiteSpaceHandling();
- void addGap();
+ SvgCharacterNode* addGap(SvgCharacterNode* pPreviousCharacterNode);
void concatenate(std::u16string_view rText);
/// Text content
const OUString& getText() const { return maText; }
- const OUString& getTextBeforeSpaceHandling() const { return maTextBeforeSpaceHandling; }
-
void setWholeTextLine(const OUString& rWholeTextLine) { maWholeTextLine = rWholeTextLine; }
const OUString& getWholeTextLine() const { return maWholeTextLine; }
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 80234e8b1f56..cf66e5bb623f 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -737,11 +737,11 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf85770)
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "11");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#000000");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "Start ");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "Start");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "height", "11");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "familyname", "Times New Roman");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "fontcolor", "#000000");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", "End");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", " End");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "height", "11");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "familyname", "Times New Roman");
@@ -1163,12 +1163,12 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156251)
// Without the fix in place, this test would have failed with
// - Expected: 'You are '
// - Actual : 'You are'
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "You are ");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "not ");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", "a banana!");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "text", "You are ");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "text", "not ");
- assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "text", "a banana!");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "You are");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", " not");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", " a banana!");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "text", "You are");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "text", " not");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "text", " a banana!");
}
CPPUNIT_TEST_FIXTURE(Test, testMaskText)
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index c953c5fc89c9..e014cd6bf1bf 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -26,6 +26,7 @@
#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
#include <utility>
+#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
using namespace drawinglayer::primitive2d;
@@ -464,9 +465,46 @@ namespace svgio::svgreader
}
}
- void SvgCharacterNode::addGap()
+ SvgCharacterNode* SvgCharacterNode::addGap(SvgCharacterNode* pPreviousCharacterNode)
{
- maText += " ";
+ // maText may have lost all text. If that's the case, ignore as invalid character node
+ // Also ignore if maTextBeforeSpaceHandling just have spaces
+ if(!maText.isEmpty() && !o3tl::trim(maTextBeforeSpaceHandling).empty())
+ {
+ if(pPreviousCharacterNode)
+ {
+ bool bAddGap(true);
+
+ // Do not add a gap if last node doesn't end with a space and
+ // current note doesn't start with a space
+ const sal_uInt32 nLastLength(pPreviousCharacterNode->maTextBeforeSpaceHandling.getLength());
+ if(pPreviousCharacterNode->maTextBeforeSpaceHandling[nLastLength - 1] != ' ' && maTextBeforeSpaceHandling[0] != ' ')
+ bAddGap = false;
+
+ // With this option a baseline shift between two char parts ('words')
+ // will not add a space 'gap' to the end of the (non-last) word. This
+ // seems to be the standard behaviour, see last bugdoc attached #122524#
+ const SvgStyleAttributes* pStyleLast = pPreviousCharacterNode->getSvgStyleAttributes();
+ const SvgStyleAttributes* pStyleCurrent = getSvgStyleAttributes();
+
+ if(pStyleLast && pStyleCurrent && pStyleLast->getBaselineShift() != pStyleCurrent->getBaselineShift())
+ {
+ bAddGap = false;
+ }
+
+ // add in-between whitespace (single space) to last
+ // known character node
+ if(bAddGap)
+ {
+ maText = " " + maText;
+ }
+ }
+
+ // this becomes the previous character node
+ return this;
+ }
+
+ return pPreviousCharacterNode;
}
void SvgCharacterNode::concatenate(std::u16string_view rText)
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index fe942d53f6b3..793539de0602 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -54,7 +54,6 @@
#include <svgtitledescnode.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
-#include <o3tl/string_view.hxx>
using namespace com::sun::star;
@@ -84,45 +83,7 @@ namespace
svgio::svgreader::SvgCharacterNode* pCharNode = static_cast< svgio::svgreader::SvgCharacterNode* >(pCandidate);
pCharNode->whiteSpaceHandling();
-
- // pCharNode may have lost all text. If that's the case, ignore
- // as invalid character node
- // Also ignore if textBeforeSpaceHandling just have spaces
- if(!pCharNode->getText().isEmpty() && !o3tl::trim(pCharNode->getTextBeforeSpaceHandling()).empty())
- {
- if(pLast)
- {
- bool bAddGap(true);
-
- // Do not add a gap if last node doesn't end with a space and
- // current note doesn't start with a space
- const sal_uInt32 nLastLength(pLast->getTextBeforeSpaceHandling().getLength());
- if(pLast->getTextBeforeSpaceHandling()[nLastLength - 1] != ' ' && pCharNode->getTextBeforeSpaceHandling()[0] != ' ')
- bAddGap = false;
-
- // With this option a baseline shift between two char parts ('words')
- // will not add a space 'gap' to the end of the (non-last) word. This
- // seems to be the standard behaviour, see last bugdoc attached #122524#
- const svgio::svgreader::SvgStyleAttributes* pStyleLast = pLast->getSvgStyleAttributes();
- const svgio::svgreader::SvgStyleAttributes* pStyleCurrent = pCandidate->getSvgStyleAttributes();
-
- if(pStyleLast && pStyleCurrent && pStyleLast->getBaselineShift() != pStyleCurrent->getBaselineShift())
- {
- bAddGap = false;
- }
-
- // add in-between whitespace (single space) to last
- // known character node
- if(bAddGap)
- {
- pLast->addGap();
- }
- }
-
- // remember new last corrected character node
- pLast = pCharNode;
- }
-
+ pLast = pCharNode->addGap(pLast);
break;
}
case SVGToken::Tspan: