summaryrefslogtreecommitdiff
path: root/svgio/source
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-08-10 14:54:15 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-08-10 16:52:32 +0200
commitad3d6732dc8905b1660fa25147a00024b0ac0cd0 (patch)
tree533612a73295cbb2756f3e89308dddc5f2133724 /svgio/source
parentfff601edf76b1783c5a47353452a83ac9c5ac07a (diff)
related: tdf#151103: simplify code
Keep the text line in the SvgTextNode and not in each SvgCharacterNode Change-Id: Ia33e46cc974a39a915e7b933337b4c529e6eeca5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155558 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source')
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx2
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx93
2 files changed, 7 insertions, 88 deletions
diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx
index 2c3fce247554..6150fbb62953 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -250,7 +250,7 @@ namespace svgio::svgreader
}
// Use the whole text line to calculate the align position
- double fWholeTextLineWidth(aTextLayouterDevice.getTextWidth(getWholeTextLine(), 0, getWholeTextLine().getLength()));
+ double fWholeTextLineWidth(aTextLayouterDevice.getTextWidth(mpTextParent->getTextLine(), 0, mpTextParent->getTextLine().getLength()));
// apply TextAlign
switch(aTextAlign)
{
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 793539de0602..16f100e0b01e 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::SvgCharacterNode* pLast)
+ svgio::svgreader::SvgCharacterNode* whiteSpaceHandling(svgio::svgreader::SvgNode const * pNode, svgio::svgreader::SvgTextNode* pText, svgio::svgreader::SvgCharacterNode* pLast)
{
if(pNode)
{
@@ -84,6 +84,9 @@ namespace
pCharNode->whiteSpaceHandling();
pLast = pCharNode->addGap(pLast);
+
+ pCharNode->setTextParent(pText);
+ pText->concatenateTextLine(pCharNode->getText());
break;
}
case SVGToken::Tspan:
@@ -91,7 +94,7 @@ namespace
case SVGToken::Tref:
{
// recursively clean whitespaces in subhierarchy
- pLast = whiteSpaceHandling(pCandidate, pLast);
+ pLast = whiteSpaceHandling(pCandidate, pText, pLast);
break;
}
default:
@@ -107,86 +110,6 @@ namespace
return pLast;
}
- OUString getWholeTextLine(svgio::svgreader::SvgNode const * pNode)
- {
- OUString sText;
- if (pNode)
- {
- const auto& rChilds = pNode->getChildren();
- const sal_uInt32 nCount(rChilds.size());
-
- for(sal_uInt32 a(0); a < nCount; a++)
- {
- svgio::svgreader::SvgNode* pCandidate = rChilds[a].get();
-
- if(pCandidate)
- {
- switch(pCandidate->getType())
- {
- case SVGToken::Character:
- {
- svgio::svgreader::SvgCharacterNode* pCharNode = static_cast< svgio::svgreader::SvgCharacterNode* >(pCandidate);
- sText += pCharNode->getText();
- break;
- }
- case SVGToken::Tspan:
- case SVGToken::TextPath:
- case SVGToken::Tref:
- {
- sText += getWholeTextLine(pCandidate);
- break;
- }
- default:
- {
- OSL_ENSURE(false, "Unexpected token inside SVGTokenText (!)");
- break;
- }
- }
- }
- }
- }
- return sText;
- }
-
- void setWholeTextLine(svgio::svgreader::SvgNode const * pNode, const OUString& rText)
- {
- if (pNode)
- {
- const auto& rChilds = pNode->getChildren();
- const sal_uInt32 nCount(rChilds.size());
-
- for(sal_uInt32 a(0); a < nCount; a++)
- {
- svgio::svgreader::SvgNode* pCandidate = rChilds[a].get();
-
- if(pCandidate)
- {
- switch(pCandidate->getType())
- {
- case SVGToken::Character:
- {
- svgio::svgreader::SvgCharacterNode* pCharNode = static_cast< svgio::svgreader::SvgCharacterNode* >(pCandidate);
- pCharNode->setWholeTextLine(rText);
- break;
- }
- case SVGToken::Tspan:
- case SVGToken::TextPath:
- case SVGToken::Tref:
- {
- setWholeTextLine(pCandidate, rText);
- break;
- }
- default:
- {
- OSL_ENSURE(false, "Unexpected token inside SVGTokenText (!)");
- break;
- }
- }
- }
- }
- }
- }
-
} // end anonymous namespace
SvgDocHdl::SvgDocHdl(const OUString& aAbsolutePath)
@@ -557,11 +480,7 @@ namespace
if(pTextNode)
{
// cleanup read strings
- whiteSpaceHandling(pTextNode, nullptr);
-
- // Iterate over all the nodes in this text element to get the whole text line
- OUString sWholeTextLine = getWholeTextLine(pTextNode);
- setWholeTextLine(pTextNode, sWholeTextLine);
+ whiteSpaceHandling(pTextNode, static_cast< SvgTextNode*>(pTextNode), nullptr);
}
}