summaryrefslogtreecommitdiff
path: root/svgio/source
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-08-09 11:47:37 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-08-09 20:20:58 +0200
commit1e4d10dcfbeeeb997bf93145da2326514ffcfad3 (patch)
tree3b284df451a63ce7dd7d79ae8e7b53ce38e35cc9 /svgio/source
parent9346f31f39586445b0547a4810d11ebe3884e0e3 (diff)
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 <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source')
-rw-r--r--svgio/source/svgreader/svgcharacternode.cxx132
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx2
-rw-r--r--svgio/source/svgreader/svgtextnode.cxx25
-rw-r--r--svgio/source/svgreader/svgtspannode.cxx85
4 files changed, 105 insertions, 139 deletions
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;