summaryrefslogtreecommitdiff
path: root/svgio/source/svgreader
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-08-12 02:28:02 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-08-12 10:00:29 +0200
commitdcb3cb0bd4e4bf2bed05ae3b9d370e17a331a9b1 (patch)
tree08503b04609b8574c537b5db0470647e8e4f7b09 /svgio/source/svgreader
parent0f3b36bd2749f360df84d1594c01e619ba0f4930 (diff)
tdf#156616: check if character's parent has x or y
if so, only concatenate the characters that are in the same line so the alignment will be calculated based on the line's width Change-Id: I704370c0a470f8b4cff97c51ad9863158118ee8a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155636 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx8
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx22
2 files changed, 23 insertions, 7 deletions
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index 2b88944aa8d0..9ba70ffb3ef5 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -79,7 +79,7 @@ namespace svgio::svgreader
OUString aText)
: SvgNode(SVGToken::Character, rDocument, pParent),
maText(std::move(aText)),
- mpTextParent(nullptr)
+ mpParentLine(nullptr)
{
}
@@ -251,7 +251,7 @@ namespace svgio::svgreader
}
// Use the whole text line to calculate the align position
- double fWholeTextLineWidth(aTextLayouterDevice.getTextWidth(mpTextParent->getTextLine(), 0, mpTextParent->getTextLine().getLength()));
+ double fWholeTextLineWidth(aTextLayouterDevice.getTextWidth(mpParentLine->getTextLine(), 0, mpParentLine->getTextLine().getLength()));
// apply TextAlign
switch(aTextAlign)
{
@@ -482,6 +482,10 @@ namespace svgio::svgreader
if(pPreviousCharacterNode->maTextBeforeSpaceHandling[nLastLength - 1] != ' ' && maTextBeforeSpaceHandling[0] != ' ')
bAddGap = false;
+ // Do not add a gap if this node and last node are in different lines
+ if(pPreviousCharacterNode->mpParentLine != mpParentLine)
+ 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#
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 16f100e0b01e..ea70f3c5cbd6 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -62,7 +62,7 @@ namespace svgio::svgreader
namespace
{
- svgio::svgreader::SvgCharacterNode* whiteSpaceHandling(svgio::svgreader::SvgNode const * pNode, svgio::svgreader::SvgTextNode* pText, svgio::svgreader::SvgCharacterNode* pLast)
+ svgio::svgreader::SvgCharacterNode* whiteSpaceHandling(svgio::svgreader::SvgNode const * pNode, svgio::svgreader::SvgTspanNode* pParentLine, svgio::svgreader::SvgCharacterNode* pLast)
{
if(pNode)
{
@@ -82,19 +82,31 @@ namespace
// clean whitespace in text span
svgio::svgreader::SvgCharacterNode* pCharNode = static_cast< svgio::svgreader::SvgCharacterNode* >(pCandidate);
+ pCharNode->setParentLine(pParentLine);
+
pCharNode->whiteSpaceHandling();
pLast = pCharNode->addGap(pLast);
- pCharNode->setTextParent(pText);
- pText->concatenateTextLine(pCharNode->getText());
+ pParentLine->concatenateTextLine(pCharNode->getText());
break;
}
case SVGToken::Tspan:
+ {
+ svgio::svgreader::SvgTspanNode* pTspanNode = static_cast< svgio::svgreader::SvgTspanNode* >(pCandidate);
+
+ // If x or y exist it means it's a new line of text
+ if(!pTspanNode->getX().empty() || !pTspanNode->getY().empty())
+ pParentLine = pTspanNode;
+
+ // recursively clean whitespaces in subhierarchy
+ pLast = whiteSpaceHandling(pCandidate, pParentLine, pLast);
+ break;
+ }
case SVGToken::TextPath:
case SVGToken::Tref:
{
// recursively clean whitespaces in subhierarchy
- pLast = whiteSpaceHandling(pCandidate, pText, pLast);
+ pLast = whiteSpaceHandling(pCandidate, pParentLine, pLast);
break;
}
default:
@@ -480,7 +492,7 @@ namespace
if(pTextNode)
{
// cleanup read strings
- whiteSpaceHandling(pTextNode, static_cast< SvgTextNode*>(pTextNode), nullptr);
+ whiteSpaceHandling(pTextNode, static_cast< SvgTspanNode*>(pTextNode), nullptr);
}
}