summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-26 13:48:54 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-26 22:44:47 +0200
commit897fce4abd0c731bf697ca1e38a8049f66f9ac7c (patch)
tree151b75697bb1efaaaf5a897cb741ba8bf18feac7 /svgio
parentfb3dfbd57d91307de383d401c1caf4bb0d9029b9 (diff)
svgio: simplify code
Change-Id: Ie363236a4b2e2d74d583b9f842b48743eefa9d24 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153625 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgnode.hxx5
-rw-r--r--svgio/inc/svgpolynode.hxx6
-rw-r--r--svgio/source/svgreader/svganode.cxx2
-rw-r--r--svgio/source/svgreader/svgcirclenode.cxx2
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx4
-rw-r--r--svgio/source/svgreader/svgellipsenode.cxx2
-rw-r--r--svgio/source/svgreader/svggnode.cxx13
-rw-r--r--svgio/source/svgreader/svggradientnode.cxx4
-rw-r--r--svgio/source/svgreader/svggradientstopnode.cxx2
-rw-r--r--svgio/source/svgreader/svgimagenode.cxx2
-rw-r--r--svgio/source/svgreader/svglinenode.cxx2
-rw-r--r--svgio/source/svgreader/svgmarkernode.cxx2
-rw-r--r--svgio/source/svgreader/svgnode.cxx27
-rw-r--r--svgio/source/svgreader/svgpathnode.cxx2
-rw-r--r--svgio/source/svgreader/svgpatternnode.cxx2
-rw-r--r--svgio/source/svgreader/svgpolynode.cxx13
-rw-r--r--svgio/source/svgreader/svgrectnode.cxx2
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx6
-rw-r--r--svgio/source/svgreader/svgsvgnode.cxx2
-rw-r--r--svgio/source/svgreader/svgtextnode.cxx2
-rw-r--r--svgio/source/svgreader/svgtspannode.cxx2
-rw-r--r--svgio/source/svgreader/svgusenode.cxx2
22 files changed, 48 insertions, 58 deletions
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index af23bc4eb32f..a85958936d9e 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -116,15 +116,14 @@ namespace svgio::svgreader
protected:
/// helper to evtl. link to css style
- const SvgStyleAttributes* checkForCssStyle(const OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
+ const SvgStyleAttributes* checkForCssStyle(const SvgStyleAttributes& rOriginal) const;
/// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
- void fillCssStyleVector(const OUString& rClassStr, const SvgStyleAttributes& rOriginal);
+ void fillCssStyleVector(const SvgStyleAttributes& rOriginal);
void addCssStyle(
const SvgDocument& rDocument,
const OUString& aConcatenated);
void fillCssStyleVectorUsingHierarchyAndSelectors(
- const OUString& rClassStr,
const SvgNode& rCurrent,
const OUString& aConcatenated);
diff --git a/svgio/inc/svgpolynode.hxx b/svgio/inc/svgpolynode.hxx
index fd356cd55588..772965475eb9 100644
--- a/svgio/inc/svgpolynode.hxx
+++ b/svgio/inc/svgpolynode.hxx
@@ -37,13 +37,11 @@ namespace svgio::svgreader
std::optional<basegfx::B2DPolygon> mpPolygon;
std::optional<basegfx::B2DHomMatrix> mpaTransform;
- bool mbIsPolyline : 1; // true = polyline, false = polygon
-
public:
SvgPolyNode(
+ SVGToken aType,
SvgDocument& rDocument,
- SvgNode* pParent,
- bool bIsPolyline);
+ SvgNode* pParent);
virtual ~SvgPolyNode() override;
virtual const SvgStyleAttributes* getSvgStyleAttributes() const override;
diff --git a/svgio/source/svgreader/svganode.cxx b/svgio/source/svgreader/svganode.cxx
index 927b13d06eb8..83dd7c50175e 100644
--- a/svgio/source/svgreader/svganode.cxx
+++ b/svgio/source/svgreader/svganode.cxx
@@ -35,7 +35,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgANode::getSvgStyleAttributes() const
{
- return checkForCssStyle("a", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgANode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgcirclenode.cxx b/svgio/source/svgreader/svgcirclenode.cxx
index 0cf15e5e7ca9..363e85d111ab 100644
--- a/svgio/source/svgreader/svgcirclenode.cxx
+++ b/svgio/source/svgreader/svgcirclenode.cxx
@@ -41,7 +41,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("circle", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgCircleNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index 25d58ceee440..6158c70f631c 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -219,14 +219,14 @@ namespace
case SVGToken::Polygon:
{
/// new node for Polygon
- mpTarget = new SvgPolyNode(maDocument, mpTarget, false);
+ mpTarget = new SvgPolyNode(aSVGToken, maDocument, mpTarget);
mpTarget->parseAttributes(xAttribs);
break;
}
case SVGToken::Polyline:
{
/// new node for Polyline
- mpTarget = new SvgPolyNode(maDocument, mpTarget, true);
+ mpTarget = new SvgPolyNode(aSVGToken, maDocument, mpTarget);
mpTarget->parseAttributes(xAttribs);
break;
}
diff --git a/svgio/source/svgreader/svgellipsenode.cxx b/svgio/source/svgreader/svgellipsenode.cxx
index 9b5fa1b061e1..a822ef7134f0 100644
--- a/svgio/source/svgreader/svgellipsenode.cxx
+++ b/svgio/source/svgreader/svgellipsenode.cxx
@@ -42,7 +42,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgEllipseNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("ellipse", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgEllipseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svggnode.cxx b/svgio/source/svgreader/svggnode.cxx
index d668f9c5b08d..e59db2972e13 100644
--- a/svgio/source/svgreader/svggnode.cxx
+++ b/svgio/source/svgreader/svggnode.cxx
@@ -38,16 +38,9 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgGNode::getSvgStyleAttributes() const
{
- if (SVGToken::Defs == getType())
- {
- // tdf#98599 attributes may be inherit by the children, therefore read them
- return checkForCssStyle("defs", maSvgStyleAttributes);
- }
- else
- {
- // #i125258# for SVGToken::G take CssStyles into account
- return checkForCssStyle("g", maSvgStyleAttributes);
- }
+ // tdf#98599 attributes may be inherit by the children, therefore read them
+ // #i125258# for SVGToken::G take CssStyles into account
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgGNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svggradientnode.cxx b/svgio/source/svgreader/svggradientnode.cxx
index 02e1b85bf17f..92a2372a196e 100644
--- a/svgio/source/svgreader/svggradientnode.cxx
+++ b/svgio/source/svgreader/svggradientnode.cxx
@@ -54,9 +54,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgGradientNode::getSvgStyleAttributes() const
{
- return checkForCssStyle(
- SVGToken::LinearGradient == getType() ? OUString("linearGradient") : OUString("radialGradient"),
- maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgGradientNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svggradientstopnode.cxx b/svgio/source/svgreader/svggradientstopnode.cxx
index f28f198e5e7a..a1b4cde13235 100644
--- a/svgio/source/svgreader/svggradientstopnode.cxx
+++ b/svgio/source/svgreader/svggradientstopnode.cxx
@@ -35,7 +35,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgGradientStopNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("stop", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgGradientStopNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgimagenode.cxx b/svgio/source/svgreader/svgimagenode.cxx
index 45e5467d64f2..d0e821a52092 100644
--- a/svgio/source/svgreader/svgimagenode.cxx
+++ b/svgio/source/svgreader/svgimagenode.cxx
@@ -54,7 +54,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgImageNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("image", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgImageNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svglinenode.cxx b/svgio/source/svgreader/svglinenode.cxx
index 2fc5e64fc9f9..7f433c7f6fc1 100644
--- a/svgio/source/svgreader/svglinenode.cxx
+++ b/svgio/source/svgreader/svglinenode.cxx
@@ -41,7 +41,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgLineNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("line", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgLineNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgmarkernode.cxx b/svgio/source/svgreader/svgmarkernode.cxx
index 9cc1cee6ce17..7229a7bdc94c 100644
--- a/svgio/source/svgreader/svgmarkernode.cxx
+++ b/svgio/source/svgreader/svgmarkernode.cxx
@@ -43,7 +43,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgMarkerNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("marker", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgMarkerNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 35277ef0ed87..399b92231543 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -93,7 +93,6 @@ namespace {
} //namespace
void SvgNode::fillCssStyleVectorUsingHierarchyAndSelectors(
- const OUString& rClassStr,
const SvgNode& rCurrent,
const OUString& aConcatenated)
{
@@ -116,7 +115,7 @@ namespace {
if(pParent)
{
// check for combined selectors at parent first so that higher specificity will be in front
- fillCssStyleVectorUsingHierarchyAndSelectors(rClassStr, *pParent, aNewConcatenated);
+ fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, aNewConcatenated);
}
addCssStyle(rDocument, aNewConcatenated);
@@ -136,7 +135,7 @@ namespace {
if(pParent)
{
// check for combined selectors at parent first so that higher specificity will be in front
- fillCssStyleVectorUsingHierarchyAndSelectors(rClassStr, *pParent, aNewConcatenated);
+ fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, aNewConcatenated);
}
addCssStyle(rDocument, aNewConcatenated);
@@ -151,26 +150,28 @@ namespace {
}
}
+ OUString sCurrentType(SVGTokenToStr(getType()));
+
// check for class-dependent references to CssStyles
- if(rClassStr.isEmpty())
+ if(sCurrentType.isEmpty())
return;
OUString aNewConcatenated(aConcatenated);
- if(!rCurrent.getId() && !rCurrent.getClass() && 0 == aConcatenated.indexOf(rClassStr))
+ if(!rCurrent.getId() && !rCurrent.getClass() && 0 == aConcatenated.indexOf(sCurrentType))
{
- // no new CssStyle Selector and already starts with rClassStr, do not concatenate;
+ // no new CssStyle Selector and already starts with sCurrentType, do not concatenate;
// we pass an 'empty' node (in the sense of CssStyle Selector)
}
else
{
- aNewConcatenated = rClassStr + aConcatenated;
+ aNewConcatenated = sCurrentType + aConcatenated;
}
if(pParent)
{
// check for combined selectors at parent first so that higher specificity will be in front
- fillCssStyleVectorUsingHierarchyAndSelectors(rClassStr, *pParent, aNewConcatenated);
+ fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, aNewConcatenated);
}
addCssStyle(rDocument, aNewConcatenated);
@@ -179,11 +180,11 @@ namespace {
if(pParent)
{
OUString sParentType(SVGTokenToStr(pParent->getType()));
- addCssStyle(rDocument, sParentType + rClassStr);
+ addCssStyle(rDocument, sParentType + sCurrentType);
}
}
- void SvgNode::fillCssStyleVector(const OUString& rClassStr, const SvgStyleAttributes& rOriginal)
+ void SvgNode::fillCssStyleVector(const SvgStyleAttributes& rOriginal)
{
OSL_ENSURE(!mbCssStyleVectorBuilt, "OOps, fillCssStyleVector called double ?!?");
mbCssStyleVectorBuilt = true;
@@ -211,7 +212,7 @@ namespace {
}
// check the hierarchy for concatenated patterns of Selectors
- fillCssStyleVectorUsingHierarchyAndSelectors(rClassStr, *this, OUString());
+ fillCssStyleVectorUsingHierarchyAndSelectors(*this, OUString());
// tdf#99115, Add css selector '*' style only if the element is on top of the hierarchy
// meaning its parent is <svg>
@@ -233,12 +234,12 @@ namespace {
maCssStyleVector.push_back(&rOriginal);
}
- const SvgStyleAttributes* SvgNode::checkForCssStyle(const OUString& rClassStr, const SvgStyleAttributes& rOriginal) const
+ const SvgStyleAttributes* SvgNode::checkForCssStyle(const SvgStyleAttributes& rOriginal) const
{
if(!mbCssStyleVectorBuilt)
{
// build needed CssStyleVector for local node
- const_cast< SvgNode* >(this)->fillCssStyleVector(rClassStr, rOriginal);
+ const_cast< SvgNode* >(this)->fillCssStyleVector(rOriginal);
}
if(maCssStyleVector.empty())
diff --git a/svgio/source/svgreader/svgpathnode.cxx b/svgio/source/svgreader/svgpathnode.cxx
index 82b603734985..f34d4d3198c8 100644
--- a/svgio/source/svgreader/svgpathnode.cxx
+++ b/svgio/source/svgreader/svgpathnode.cxx
@@ -36,7 +36,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgPathNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("path", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgPathNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgpatternnode.cxx b/svgio/source/svgreader/svgpatternnode.cxx
index 9b94c537eaef..5620bd6b2ced 100644
--- a/svgio/source/svgreader/svgpatternnode.cxx
+++ b/svgio/source/svgreader/svgpatternnode.cxx
@@ -47,7 +47,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgPatternNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("pattern", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgPatternNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgpolynode.cxx b/svgio/source/svgreader/svgpolynode.cxx
index 84beea4b55f4..38a908a18756 100644
--- a/svgio/source/svgreader/svgpolynode.cxx
+++ b/svgio/source/svgreader/svgpolynode.cxx
@@ -25,12 +25,11 @@
namespace svgio::svgreader
{
SvgPolyNode::SvgPolyNode(
+ SVGToken aType,
SvgDocument& rDocument,
- SvgNode* pParent,
- bool bIsPolyline)
- : SvgNode(SVGToken::Polygon, rDocument, pParent),
- maSvgStyleAttributes(*this),
- mbIsPolyline(bIsPolyline)
+ SvgNode* pParent)
+ : SvgNode(aType, rDocument, pParent),
+ maSvgStyleAttributes(*this)
{
}
@@ -40,7 +39,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
{
- return checkForCssStyle(mbIsPolyline? OUString("polyline") : OUString("polygon"), maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgPolyNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
@@ -67,7 +66,7 @@ namespace svgio::svgreader
{
if(aPath.count())
{
- if(!mbIsPolyline)
+ if(getType() == SVGToken::Polygon)
{
aPath.setClosed(true);
}
diff --git a/svgio/source/svgreader/svgrectnode.cxx b/svgio/source/svgreader/svgrectnode.cxx
index 3e81927ab2b2..782887be9f35 100644
--- a/svgio/source/svgreader/svgrectnode.cxx
+++ b/svgio/source/svgreader/svgrectnode.cxx
@@ -44,7 +44,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgRectNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("rect", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgRectNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 189a1879799a..66b8f60848f4 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1127,7 +1127,8 @@ namespace svgio::svgreader
// create fill
basegfx::B2DPolyPolygon aPath(rPath);
- if(SVGToken::Path == mrOwner.getType() || SVGToken::Polygon == mrOwner.getType())
+ if(SVGToken::Path == mrOwner.getType() || SVGToken::Polygon == mrOwner.getType()
+ || SVGToken::Polyline == mrOwner.getType())
{
if(FillRule::evenodd != getClipRule() && FillRule::evenodd != getFillRule())
{
@@ -1149,7 +1150,8 @@ namespace svgio::svgreader
// Svg supports markers for path, polygon, polyline and line
if(SVGToken::Path == mrOwner.getType() || // path
- SVGToken::Polygon == mrOwner.getType() || // polygon, polyline
+ SVGToken::Polygon == mrOwner.getType() || // polygon
+ SVGToken::Polyline == mrOwner.getType() || // polyline
SVGToken::Line == mrOwner.getType() || // line
SVGToken::Style == mrOwner.getType()) // tdf#150323
{
diff --git a/svgio/source/svgreader/svgsvgnode.cxx b/svgio/source/svgreader/svgsvgnode.cxx
index 346e457aa17e..dfc3285f30cc 100644
--- a/svgio/source/svgreader/svgsvgnode.cxx
+++ b/svgio/source/svgreader/svgsvgnode.cxx
@@ -104,7 +104,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgSvgNode::getSvgStyleAttributes() const
{
// #i125258# svg node can have CssStyles, too, so check for it here
- return checkForCssStyle("svg", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgSvgNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgtextnode.cxx b/svgio/source/svgreader/svgtextnode.cxx
index 55ba6b60b13e..35e130a097de 100644
--- a/svgio/source/svgreader/svgtextnode.cxx
+++ b/svgio/source/svgreader/svgtextnode.cxx
@@ -41,7 +41,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgTextNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("text", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgTextNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgtspannode.cxx b/svgio/source/svgreader/svgtspannode.cxx
index db024e2f2ff7..df5e440080f8 100644
--- a/svgio/source/svgreader/svgtspannode.cxx
+++ b/svgio/source/svgreader/svgtspannode.cxx
@@ -36,7 +36,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgTspanNode::getSvgStyleAttributes() const
{
// #i125293# Need to support CssStyles in tspan text sections
- return checkForCssStyle("tspan", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgTspanNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
diff --git a/svgio/source/svgreader/svgusenode.cxx b/svgio/source/svgreader/svgusenode.cxx
index 185dc4f919a0..0d385576ac88 100644
--- a/svgio/source/svgreader/svgusenode.cxx
+++ b/svgio/source/svgreader/svgusenode.cxx
@@ -38,7 +38,7 @@ namespace svgio::svgreader
const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
{
- return checkForCssStyle("use", maSvgStyleAttributes);
+ return checkForCssStyle(maSvgStyleAttributes);
}
void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)