diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-08-12 02:28:02 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-08-12 10:00:29 +0200 |
commit | dcb3cb0bd4e4bf2bed05ae3b9d370e17a331a9b1 (patch) | |
tree | 08503b04609b8574c537b5db0470647e8e4f7b09 /svgio/source/svgreader/svgdocumenthandler.cxx | |
parent | 0f3b36bd2749f360df84d1594c01e619ba0f4930 (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/svgdocumenthandler.cxx')
-rw-r--r-- | svgio/source/svgreader/svgdocumenthandler.cxx | 22 |
1 files changed, 17 insertions, 5 deletions
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); } } |