svgio/inc/svgcharacternode.hxx                |   51 ----------
 svgio/inc/svgtextnode.hxx                     |    9 -
 svgio/inc/svgtspannode.hxx                    |   44 +++++++-
 svgio/source/svgreader/svgcharacternode.cxx   |  132 +++-----------------------
 svgio/source/svgreader/svgdocumenthandler.cxx |    2 
 svgio/source/svgreader/svgtextnode.cxx        |   25 ----
 svgio/source/svgreader/svgtspannode.cxx       |   85 +++++++++++++++-
 7 files changed, 148 insertions(+), 200 deletions(-)

New commits:
commit 1e4d10dcfbeeeb997bf93145da2326514ffcfad3
Author:     Xisco Fauli <[email protected]>
AuthorDate: Wed Aug 9 11:47:37 2023 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Wed Aug 9 20:20:58 2023 +0200

    svgio: get rid of SvgTextPositions
    
    and make SvgText inherit from SvgTspan
    
    Change-Id: Ief25e52ba2a493936f82f1674f73168ed5647278
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155521
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/svgio/inc/svgcharacternode.hxx b/svgio/inc/svgcharacternode.hxx
index c74f881df468..f44d7547b4ca 100644
--- a/svgio/inc/svgcharacternode.hxx
+++ b/svgio/inc/svgcharacternode.hxx
@@ -25,57 +25,12 @@
 #include <string_view>
 
 #include "svgnode.hxx"
+#include "svgtspannode.hxx"
 
 namespace drawinglayer::primitive2d { class TextSimplePortionPrimitive2D; }
 
 namespace svgio::svgreader
     {
-        class SvgTextPositions
-        {
-        private:
-            SvgNumberVector         maX;
-            SvgNumberVector         maY;
-            SvgNumberVector         maDx;
-            SvgNumberVector         maDy;
-            SvgNumberVector         maRotate;
-            SvgNumber               maTextLength;
-
-            bool                    mbLengthAdjust : 1; // true = spacing, 
false = spacingAndGlyphs
-
-        public:
-            SvgTextPositions();
-
-            void parseTextPositionAttributes(SVGToken aSVGToken, 
std::u16string_view aContent);
-
-            /// X content
-            const SvgNumberVector& getX() const { return maX; }
-            void setX(SvgNumberVector&& aX) { maX = std::move(aX); }
-
-            /// Y content
-            const SvgNumberVector& getY() const { return maY; }
-            void setY(SvgNumberVector&& aY) { maY = std::move(aY); }
-
-            /// Dx content
-            const SvgNumberVector& getDx() const { return maDx; }
-            void setDx(SvgNumberVector&& aDx) { maDx = std::move(aDx); }
-
-            /// Dy content
-            const SvgNumberVector& getDy() const { return maDy; }
-            void setDy(SvgNumberVector&& aDy) { maDy = std::move(aDy); }
-
-            /// Rotate content
-            const SvgNumberVector& getRotate() const { return maRotate; }
-            void setRotate(SvgNumberVector&& aRotate) { maRotate = 
std::move(aRotate); }
-
-            /// TextLength content
-            const SvgNumber& getTextLength() const { return maTextLength; }
-            void setTextLength(const SvgNumber& rTextLength) { maTextLength = 
rTextLength; }
-
-            /// LengthAdjust content
-            bool getLengthAdjust() const { return mbLengthAdjust; }
-            void setLengthAdjust(bool bNew) { mbLengthAdjust = bNew; }
-        };
-
         class SvgTextPosition
         {
         private:
@@ -98,8 +53,7 @@ namespace svgio::svgreader
         public:
             SvgTextPosition(
                 SvgTextPosition* pParent,
-                const InfoProvider& rInfoProvider,
-                const SvgTextPositions& rSvgTextPositions);
+                const SvgTspanNode& rSvgCharacterNode);
 
             // data read access
             const SvgTextPosition* getParent() const { return mpParent; }
@@ -147,6 +101,7 @@ namespace svgio::svgreader
             virtual ~SvgCharacterNode() override;
 
             virtual const SvgStyleAttributes* getSvgStyleAttributes() const 
override;
+
             void 
decomposeText(drawinglayer::primitive2d::Primitive2DContainer& rTarget, 
SvgTextPosition& rSvgTextPosition) const;
             void whiteSpaceHandling();
             void addGap();
diff --git a/svgio/inc/svgtextnode.hxx b/svgio/inc/svgtextnode.hxx
index 0cc78f130aed..da6f0e5cbcb2 100644
--- a/svgio/inc/svgtextnode.hxx
+++ b/svgio/inc/svgtextnode.hxx
@@ -19,23 +19,19 @@
 
 #pragma once
 
-#include "svgnode.hxx"
 #include "svgstyleattributes.hxx"
 #include "svgcharacternode.hxx"
+#include "svgtspannode.hxx"
 #include <basegfx/matrix/b2dhommatrix.hxx>
 
 namespace svgio::svgreader
     {
-        class SvgTextNode final : public SvgNode
+        class SvgTextNode final : public SvgTspanNode
         {
         private:
-            /// use styles
-            SvgStyleAttributes      maSvgStyleAttributes;
-
             /// variable scan values, dependent of given XAttributeList
             std::optional<basegfx::B2DHomMatrix>
                                     mpaTransform;
-            SvgTextPositions        maSvgTextPositions;
 
             /// local helpers
             void DecomposeChild(
@@ -53,7 +49,6 @@ namespace svgio::svgreader
                 SvgNode* pParent);
             virtual ~SvgTextNode() override;
 
-            virtual const SvgStyleAttributes* getSvgStyleAttributes() const 
override;
             virtual void parseAttribute(const OUString& rTokenName, SVGToken 
aSVGToken, const OUString& aContent) override;
             virtual void 
decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool 
bReferenced) const override;
 
diff --git a/svgio/inc/svgtspannode.hxx b/svgio/inc/svgtspannode.hxx
index 10a7b7ee16a9..d5d86c5a7c1a 100644
--- a/svgio/inc/svgtspannode.hxx
+++ b/svgio/inc/svgtspannode.hxx
@@ -19,22 +19,29 @@
 
 #pragma once
 
-#include "svgcharacternode.hxx"
+#include "svgnode.hxx"
 #include "svgstyleattributes.hxx"
 
 namespace svgio::svgreader
     {
-        class SvgTspanNode final : public SvgNode
+        class SvgTspanNode : public SvgNode
         {
         private:
             /// use styles
             SvgStyleAttributes      maSvgStyleAttributes;
 
-            /// variable scan values, dependent of given XAttributeList
-            SvgTextPositions        maSvgTextPositions;
+            SvgNumberVector         maX;
+            SvgNumberVector         maY;
+            SvgNumberVector         maDx;
+            SvgNumberVector         maDy;
+            SvgNumberVector         maRotate;
+            SvgNumber               maTextLength;
+
+            bool                    mbLengthAdjust : 1; // true = spacing, 
false = spacingAndGlyphs
 
         public:
             SvgTspanNode(
+                SVGToken aType,
                 SvgDocument& rDocument,
                 SvgNode* pParent);
             virtual ~SvgTspanNode() override;
@@ -44,8 +51,33 @@ namespace svgio::svgreader
 
             double getCurrentFontSize() const;
 
-            /// access to SvgTextPositions
-            const SvgTextPositions& getSvgTextPositions() const { return 
maSvgTextPositions; }
+            /// X content
+            const SvgNumberVector& getX() const { return maX; }
+            void setX(SvgNumberVector&& aX) { maX = std::move(aX); }
+
+            /// Y content
+            const SvgNumberVector& getY() const { return maY; }
+            void setY(SvgNumberVector&& aY) { maY = std::move(aY); }
+
+            /// Dx content
+            const SvgNumberVector& getDx() const { return maDx; }
+            void setDx(SvgNumberVector&& aDx) { maDx = std::move(aDx); }
+
+            /// Dy content
+            const SvgNumberVector& getDy() const { return maDy; }
+            void setDy(SvgNumberVector&& aDy) { maDy = std::move(aDy); }
+
+            /// Rotate content
+            const SvgNumberVector& getRotate() const { return maRotate; }
+            void setRotate(SvgNumberVector&& aRotate) { maRotate = 
std::move(aRotate); }
+
+            /// TextLength content
+            const SvgNumber& getTextLength() const { return maTextLength; }
+            void setTextLength(const SvgNumber& rTextLength) { maTextLength = 
rTextLength; }
+
+            /// LengthAdjust content
+            bool getLengthAdjust() const { return mbLengthAdjust; }
+            void setLengthAdjust(bool bNew) { mbLengthAdjust = bNew; }
         };
 
 } // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svgcharacternode.cxx 
b/svgio/source/svgreader/svgcharacternode.cxx
index fc926afbedaa..c953c5fc89c9 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -26,105 +26,12 @@
 #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;
 
 namespace svgio::svgreader
 {
-        SvgTextPositions::SvgTextPositions()
-        :  mbLengthAdjust(true)
-        {
-        }
-
-        void SvgTextPositions::parseTextPositionAttributes(SVGToken aSVGToken, 
std::u16string_view aContent)
-        {
-            // parse own
-            switch(aSVGToken)
-            {
-                case SVGToken::X:
-                {
-                    SvgNumberVector aVector;
-
-                    if(readSvgNumberVector(aContent, aVector))
-                    {
-                        setX(std::move(aVector));
-                    }
-                    break;
-                }
-                case SVGToken::Y:
-                {
-                    SvgNumberVector aVector;
-
-                    if(readSvgNumberVector(aContent, aVector))
-                    {
-                        setY(std::move(aVector));
-                    }
-                    break;
-                }
-                case SVGToken::Dx:
-                {
-                    SvgNumberVector aVector;
-
-                    if(readSvgNumberVector(aContent, aVector))
-                    {
-                        setDx(std::move(aVector));
-                    }
-                    break;
-                }
-                case SVGToken::Dy:
-                {
-                    SvgNumberVector aVector;
-
-                    if(readSvgNumberVector(aContent, aVector))
-                    {
-                        setDy(std::move(aVector));
-                    }
-                    break;
-                }
-                case SVGToken::Rotate:
-                {
-                    SvgNumberVector aVector;
-
-                    if(readSvgNumberVector(aContent, aVector))
-                    {
-                        setRotate(std::move(aVector));
-                    }
-                    break;
-                }
-                case SVGToken::TextLength:
-                {
-                    SvgNumber aNum;
-
-                    if(readSingleNumber(aContent, aNum))
-                    {
-                        if(aNum.isPositive())
-                        {
-                            setTextLength(aNum);
-                        }
-                    }
-                    break;
-                }
-                case SVGToken::LengthAdjust:
-                {
-                    if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), 
u"spacing"))
-                    {
-                        setLengthAdjust(true);
-                    }
-                    else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), 
u"spacingAndGlyphs"))
-                    {
-                        setLengthAdjust(false);
-                    }
-                    break;
-                }
-                default:
-                {
-                    break;
-                }
-            }
-        }
-
         namespace {
 
         class localTextBreakupHelper : public TextBreakupHelper
@@ -583,19 +490,20 @@ namespace svgio::svgreader
 
         SvgTextPosition::SvgTextPosition(
             SvgTextPosition* pParent,
-            const InfoProvider& rInfoProvider,
-            const SvgTextPositions& rSvgTextPositions)
+            const SvgTspanNode& rSvgTspanNode)
         :   mpParent(pParent),
-            maRotate(solveSvgNumberVector(rSvgTextPositions.getRotate(), 
rInfoProvider)),
+            maRotate(solveSvgNumberVector(rSvgTspanNode.getRotate(), 
rSvgTspanNode)),
             mfTextLength(0.0),
             mnRotationIndex(0),
-            mbLengthAdjust(rSvgTextPositions.getLengthAdjust()),
+            mbLengthAdjust(rSvgTspanNode.getLengthAdjust()),
             mbAbsoluteX(false)
         {
+            const InfoProvider& rInfoProvider(rSvgTspanNode);
+
             // get TextLength if provided
-            if(rSvgTextPositions.getTextLength().isSet())
+            if(rSvgTspanNode.getTextLength().isSet())
             {
-                mfTextLength = 
rSvgTextPositions.getTextLength().solve(rInfoProvider);
+                mfTextLength = 
rSvgTspanNode.getTextLength().solve(rInfoProvider);
             }
 
             // SVG does not really define in which units a \91rotate\92 for 
Text/TSpan is given,
@@ -609,12 +517,12 @@ namespace svgio::svgreader
             }
 
             // get text positions X
-            const sal_uInt32 nSizeX(rSvgTextPositions.getX().size());
+            const sal_uInt32 nSizeX(rSvgTspanNode.getX().size());
 
             if(nSizeX)
             {
                 // we have absolute positions, get first one as current text 
position X
-                
maPosition.setX(rSvgTextPositions.getX()[0].solve(rInfoProvider, 
NumberType::xcoordinate));
+                maPosition.setX(rSvgTspanNode.getX()[0].solve(rInfoProvider, 
NumberType::xcoordinate));
                 mbAbsoluteX = true;
             }
             else
@@ -626,11 +534,11 @@ namespace svgio::svgreader
                 }
             }
 
-            const sal_uInt32 nSizeDx(rSvgTextPositions.getDx().size());
+            const sal_uInt32 nSizeDx(rSvgTspanNode.getDx().size());
             if(nSizeDx)
             {
                 // relative positions given, translate position derived from 
parent
-                maPosition.setX(maPosition.getX() + 
rSvgTextPositions.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate));
+                maPosition.setX(maPosition.getX() + 
rSvgTspanNode.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate));
             }
 
             // fill deltas to maX
@@ -640,11 +548,11 @@ namespace svgio::svgreader
             {
                 if (a < nSizeX)
                 {
-                    double nPos = 
rSvgTextPositions.getX()[a].solve(rInfoProvider, NumberType::xcoordinate) - 
maPosition.getX();
+                    double nPos = rSvgTspanNode.getX()[a].solve(rInfoProvider, 
NumberType::xcoordinate) - maPosition.getX();
 
                     if(a < nSizeDx)
                     {
-                        nPos += 
rSvgTextPositions.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate);
+                        nPos += rSvgTspanNode.getDx()[a].solve(rInfoProvider, 
NumberType::xcoordinate);
                     }
 
                     maX.push_back(nPos);
@@ -653,17 +561,17 @@ namespace svgio::svgreader
                 {
                     // Apply them later since it also needs the character 
width to calculate
                     // the final character position
-                    
maDx.push_back(rSvgTextPositions.getDx()[a].solve(rInfoProvider, 
NumberType::xcoordinate));
+                    
maDx.push_back(rSvgTspanNode.getDx()[a].solve(rInfoProvider, 
NumberType::xcoordinate));
                 }
             }
 
             // get text positions Y
-            const sal_uInt32 nSizeY(rSvgTextPositions.getY().size());
+            const sal_uInt32 nSizeY(rSvgTspanNode.getY().size());
 
             if(nSizeY)
             {
                 // we have absolute positions, get first one as current text 
position Y
-                
maPosition.setY(rSvgTextPositions.getY()[0].solve(rInfoProvider, 
NumberType::ycoordinate));
+                maPosition.setY(rSvgTspanNode.getY()[0].solve(rInfoProvider, 
NumberType::ycoordinate));
                 mbAbsoluteX = true;
             }
             else
@@ -675,12 +583,12 @@ namespace svgio::svgreader
                 }
             }
 
-            const sal_uInt32 nSizeDy(rSvgTextPositions.getDy().size());
+            const sal_uInt32 nSizeDy(rSvgTspanNode.getDy().size());
 
             if(nSizeDy)
             {
                 // relative positions given, translate position derived from 
parent
-                maPosition.setY(maPosition.getY() + 
rSvgTextPositions.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate));
+                maPosition.setY(maPosition.getY() + 
rSvgTspanNode.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate));
             }
 
             // fill deltas to maY
@@ -688,11 +596,11 @@ namespace svgio::svgreader
 
             for(sal_uInt32 a(1); a < nSizeY; a++)
             {
-                double nPos = rSvgTextPositions.getY()[a].solve(rInfoProvider, 
NumberType::ycoordinate) - maPosition.getY();
+                double nPos = rSvgTspanNode.getY()[a].solve(rInfoProvider, 
NumberType::ycoordinate) - maPosition.getY();
 
                 if(a < nSizeDy)
                 {
-                    nPos += rSvgTextPositions.getDy()[a].solve(rInfoProvider, 
NumberType::ycoordinate);
+                    nPos += rSvgTspanNode.getDy()[a].solve(rInfoProvider, 
NumberType::ycoordinate);
                 }
 
                 maY.push_back(nPos);
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx 
b/svgio/source/svgreader/svgdocumenthandler.cxx
index b47df2ec4d2c..8e92d3ddd339 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -404,7 +404,7 @@ namespace
                 }
                 case SVGToken::Tspan:
                 {
-                    mpTarget = new SvgTspanNode(maDocument, mpTarget);
+                    mpTarget = new SvgTspanNode(aSVGToken, maDocument, 
mpTarget);
                     mpTarget->parseAttributes(xAttribs);
                     break;
                 }
diff --git a/svgio/source/svgreader/svgtextnode.cxx 
b/svgio/source/svgreader/svgtextnode.cxx
index 5b8cc3187070..bd8a334c5e11 100644
--- a/svgio/source/svgreader/svgtextnode.cxx
+++ b/svgio/source/svgreader/svgtextnode.cxx
@@ -30,8 +30,7 @@ namespace svgio::svgreader
         SvgTextNode::SvgTextNode(
             SvgDocument& rDocument,
             SvgNode* pParent)
-        :   SvgNode(SVGToken::Text, rDocument, pParent),
-            maSvgStyleAttributes(*this)
+        :   SvgTspanNode(SVGToken::Text, rDocument, pParent)
         {
         }
 
@@ -39,30 +38,14 @@ namespace svgio::svgreader
         {
         }
 
-        const SvgStyleAttributes* SvgTextNode::getSvgStyleAttributes() const
-        {
-            return checkForCssStyle(maSvgStyleAttributes);
-        }
-
         void SvgTextNode::parseAttribute(const OUString& rTokenName, SVGToken 
aSVGToken, const OUString& aContent)
         {
             // call parent
-            SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
-
-            // read style attributes
-            maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
-
-            // read text position attributes
-            maSvgTextPositions.parseTextPositionAttributes(aSVGToken, 
aContent);
+            SvgTspanNode::parseAttribute(rTokenName, aSVGToken, aContent);
 
             // parse own
             switch(aSVGToken)
             {
-                case SVGToken::Style:
-                {
-                    readLocalCssStyle(aContent);
-                    break;
-                }
                 case SVGToken::Transform:
                 {
                     const basegfx::B2DHomMatrix 
aMatrix(readTransform(aContent, *this));
@@ -159,7 +142,7 @@ namespace svgio::svgreader
 
                     if(nCount)
                     {
-                        SvgTextPosition aSvgTextPosition(&rSvgTextPosition, 
rSvgTspanNode, rSvgTspanNode.getSvgTextPositions());
+                        SvgTextPosition aSvgTextPosition(&rSvgTextPosition, 
rSvgTspanNode);
                         drawinglayer::primitive2d::Primitive2DContainer 
aNewTarget;
 
                         for(sal_uInt32 a(0); a < nCount; a++)
@@ -229,7 +212,7 @@ namespace svgio::svgreader
             if(fOpacity <= 0.0)
                 return;
 
-            SvgTextPosition aSvgTextPosition(nullptr, *this, 
maSvgTextPositions);
+            SvgTextPosition aSvgTextPosition(nullptr, *this);
             drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
             const auto& rChildren = getChildren();
             const sal_uInt32 nCount(rChildren.size());
diff --git a/svgio/source/svgreader/svgtspannode.cxx 
b/svgio/source/svgreader/svgtspannode.cxx
index df5e440080f8..4472b88ab3ad 100644
--- a/svgio/source/svgreader/svgtspannode.cxx
+++ b/svgio/source/svgreader/svgtspannode.cxx
@@ -18,14 +18,17 @@
  */
 
 #include <svgtspannode.hxx>
+#include <o3tl/string_view.hxx>
 
 namespace svgio::svgreader
 {
         SvgTspanNode::SvgTspanNode(
+            SVGToken aType,
             SvgDocument& rDocument,
             SvgNode* pParent)
-        :   SvgNode(SVGToken::Tspan, rDocument, pParent),
-            maSvgStyleAttributes(*this)
+        :   SvgNode(aType, rDocument, pParent),
+            maSvgStyleAttributes(*this),
+            mbLengthAdjust(true)
         {
         }
 
@@ -47,9 +50,6 @@ namespace svgio::svgreader
             // read style attributes
             maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
 
-            // read text position attributes
-            maSvgTextPositions.parseTextPositionAttributes(aSVGToken, 
aContent);
-
             // parse own
             switch(aSVGToken)
             {
@@ -58,6 +58,81 @@ namespace svgio::svgreader
                     readLocalCssStyle(aContent);
                     break;
                 }
+                case SVGToken::X:
+                {
+                    SvgNumberVector aVector;
+
+                    if(readSvgNumberVector(aContent, aVector))
+                    {
+                        setX(std::move(aVector));
+                    }
+                    break;
+                }
+                case SVGToken::Y:
+                {
+                    SvgNumberVector aVector;
+
+                    if(readSvgNumberVector(aContent, aVector))
+                    {
+                        setY(std::move(aVector));
+                    }
+                    break;
+                }
+                case SVGToken::Dx:
+                {
+                    SvgNumberVector aVector;
+
+                    if(readSvgNumberVector(aContent, aVector))
+                    {
+                        setDx(std::move(aVector));
+                    }
+                    break;
+                }
+                case SVGToken::Dy:
+                {
+                    SvgNumberVector aVector;
+
+                    if(readSvgNumberVector(aContent, aVector))
+                    {
+                        setDy(std::move(aVector));
+                    }
+                    break;
+                }
+                case SVGToken::Rotate:
+                {
+                    SvgNumberVector aVector;
+
+                    if(readSvgNumberVector(aContent, aVector))
+                    {
+                        setRotate(std::move(aVector));
+                    }
+                    break;
+                }
+                case SVGToken::TextLength:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        if(aNum.isPositive())
+                        {
+                            setTextLength(aNum);
+                        }
+                    }
+                    break;
+                }
+                case SVGToken::LengthAdjust:
+                {
+                    if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), 
u"spacing"))
+                    {
+                        setLengthAdjust(true);
+                    }
+                    else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), 
u"spacingAndGlyphs"))
+                    {
+                        setLengthAdjust(false);
+                    }
+                    break;
+                }
                 default:
                 {
                     break;

Reply via email to