svgio/inc/svgcharacternode.hxx                |    9 --
 svgio/inc/svgtextnode.hxx                     |    7 +
 svgio/source/svgreader/svgcharacternode.cxx   |    2 
 svgio/source/svgreader/svgdocumenthandler.cxx |   93 +-------------------------
 4 files changed, 17 insertions(+), 94 deletions(-)

New commits:
commit ad3d6732dc8905b1660fa25147a00024b0ac0cd0
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Aug 10 14:54:15 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Aug 10 16:52:32 2023 +0200

    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 <xiscofa...@libreoffice.org>

diff --git a/svgio/inc/svgcharacternode.hxx b/svgio/inc/svgcharacternode.hxx
index 007f9028e80b..391c4029e46c 100644
--- a/svgio/inc/svgcharacternode.hxx
+++ b/svgio/inc/svgcharacternode.hxx
@@ -24,7 +24,7 @@
 
 #include <string_view>
 
-#include "svgnode.hxx"
+#include "svgtextnode.hxx"
 #include "svgtextposition.hxx"
 
 namespace drawinglayer::primitive2d { class TextSimplePortionPrimitive2D; }
@@ -40,8 +40,7 @@ namespace svgio::svgreader
             // keep a copy of string data before space handling
             OUString           maTextBeforeSpaceHandling;
 
-            // The whole text line of which this SvgCharacterNode is parted of
-            OUString           maWholeTextLine;
+            SvgTextNode*        mpTextParent;
 
             /// local helpers
             rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> 
createSimpleTextPrimitive(
@@ -69,9 +68,7 @@ namespace svgio::svgreader
             /// Text content
             const OUString& getText() const { return maText; }
 
-            void setWholeTextLine(const OUString& rWholeTextLine) { 
maWholeTextLine = rWholeTextLine; }
-
-            const OUString& getWholeTextLine() const { return maWholeTextLine; 
}
+            void setTextParent(SvgTextNode* pTextParent) { mpTextParent = 
pTextParent; }
         };
 
 } // end of namespace svgio::svgreader
diff --git a/svgio/inc/svgtextnode.hxx b/svgio/inc/svgtextnode.hxx
index 787687977e11..2d5f98ec18fc 100644
--- a/svgio/inc/svgtextnode.hxx
+++ b/svgio/inc/svgtextnode.hxx
@@ -33,6 +33,10 @@ namespace svgio::svgreader
             std::optional<basegfx::B2DHomMatrix>
                                     mpaTransform;
 
+            // The text line composed by the different SvgCharacterNode 
children
+            // it will be used to calculate their alignment
+            OUString maTextLine;
+
             /// local helpers
             void DecomposeChild(
                 const SvgNode& rCandidate,
@@ -55,6 +59,9 @@ namespace svgio::svgreader
             /// transform content, set if found in current context
             const std::optional<basegfx::B2DHomMatrix>& getTransform() const { 
return mpaTransform; }
             void setTransform(const std::optional<basegfx::B2DHomMatrix>& 
pMatrix) { mpaTransform = pMatrix; }
+
+            void concatenateTextLine(std::u16string_view rText) {maTextLine += 
rText;}
+            const OUString& getTextLine() const { return maTextLine; }
         };
 
 } // end of namespace svgio::svgreader
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);
             }
         }
 

Reply via email to