1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svgusenode.hxx>
21 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
22 #include <svgdocument.hxx>
24 namespace svgio::svgreader
26 SvgUseNode::SvgUseNode(
27 SvgDocument
& rDocument
,
29 : SvgNode(SVGToken::Use
, rDocument
, pParent
),
30 maSvgStyleAttributes(*this),
31 mbDecomposingSvgNode(false)
35 SvgUseNode::~SvgUseNode()
39 const SvgStyleAttributes
* SvgUseNode::getSvgStyleAttributes() const
41 return checkForCssStyle("use", maSvgStyleAttributes
);
44 void SvgUseNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
47 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
49 // read style attributes
50 maSvgStyleAttributes
.parseStyleAttribute(aSVGToken
, aContent
);
57 readLocalCssStyle(aContent
);
60 case SVGToken::Transform
:
62 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
64 if(!aMatrix
.isIdentity())
66 setTransform(aMatrix
);
74 if(readSingleNumber(aContent
, aNum
))
84 if(readSingleNumber(aContent
, aNum
))
94 if(readSingleNumber(aContent
, aNum
))
103 case SVGToken::Height
:
107 if(readSingleNumber(aContent
, aNum
))
109 if(aNum
.isPositive())
117 case SVGToken::XlinkHref
:
119 readLocalLink(aContent
, maXLink
);
129 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool /*bReferenced*/) const
131 // try to access link to content
132 const SvgNode
* pXLink
= getDocument().findSvgNodeById(maXLink
);
134 if (!pXLink
|| Display::None
== pXLink
->getDisplay() || mbDecomposingSvgNode
)
137 // decompose children
138 drawinglayer::primitive2d::Primitive2DContainer aNewTarget
;
140 // todo: in case mpXLink is a SVGToken::Svg or SVGToken::Symbol the
141 // SVG docs want the getWidth() and getHeight() from this node
142 // to be valid for the subtree.
143 mbDecomposingSvgNode
= true;
144 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent(this);
145 pXLink
->decomposeSvgNode(aNewTarget
, true);
146 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent();
147 mbDecomposingSvgNode
= false;
149 if(aNewTarget
.empty())
152 basegfx::B2DHomMatrix aTransform
;
154 if(getX().isSet() || getY().isSet())
156 aTransform
.translate(
157 getX().solve(*this, NumberType::xcoordinate
),
158 getY().solve(*this, NumberType::ycoordinate
));
163 aTransform
= *getTransform() * aTransform
;
166 if(!aTransform
.isIdentity())
168 const drawinglayer::primitive2d::Primitive2DReference
xRef(
169 new drawinglayer::primitive2d::TransformPrimitive2D(
171 std::move(aNewTarget
)));
173 rTarget
.push_back(xRef
);
177 rTarget
.append(aNewTarget
);
181 } // end of namespace svgio::svgreader
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */