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),
36 mbDecomposingSvgNode(false)
40 SvgUseNode::~SvgUseNode()
44 const SvgStyleAttributes
* SvgUseNode::getSvgStyleAttributes() const
46 return checkForCssStyle("use", maSvgStyleAttributes
);
49 void SvgUseNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
52 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
54 // read style attributes
55 maSvgStyleAttributes
.parseStyleAttribute(aSVGToken
, aContent
, false);
62 readLocalCssStyle(aContent
);
65 case SVGToken::Transform
:
67 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
69 if(!aMatrix
.isIdentity())
71 setTransform(&aMatrix
);
79 if(readSingleNumber(aContent
, aNum
))
89 if(readSingleNumber(aContent
, aNum
))
99 if(readSingleNumber(aContent
, aNum
))
101 if(aNum
.isPositive())
108 case SVGToken::Height
:
112 if(readSingleNumber(aContent
, aNum
))
114 if(aNum
.isPositive())
121 case SVGToken::XlinkHref
:
123 const sal_Int32
nLen(aContent
.getLength());
125 if(nLen
&& '#' == aContent
[0])
127 maXLink
= aContent
.copy(1);
138 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool /*bReferenced*/) const
140 // try to access link to content
141 const SvgNode
* pXLink
= getDocument().findSvgNodeById(maXLink
);
143 if (!pXLink
|| Display::None
== pXLink
->getDisplay() || mbDecomposingSvgNode
)
146 // decompose children
147 drawinglayer::primitive2d::Primitive2DContainer aNewTarget
;
149 // todo: in case mpXLink is a SVGToken::Svg or SVGToken::Symbol the
150 // SVG docs want the getWidth() and getHeight() from this node
151 // to be valid for the subtree.
152 mbDecomposingSvgNode
= true;
153 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent(this);
154 pXLink
->decomposeSvgNode(aNewTarget
, true);
155 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent();
156 mbDecomposingSvgNode
= false;
158 if(aNewTarget
.empty())
161 basegfx::B2DHomMatrix aTransform
;
163 if(getX().isSet() || getY().isSet())
165 aTransform
.translate(
166 getX().solve(*this, NumberType::xcoordinate
),
167 getY().solve(*this, NumberType::ycoordinate
));
172 aTransform
= *getTransform() * aTransform
;
175 if(!aTransform
.isIdentity())
177 const drawinglayer::primitive2d::Primitive2DReference
xRef(
178 new drawinglayer::primitive2d::TransformPrimitive2D(
182 rTarget
.push_back(xRef
);
186 rTarget
.append(aNewTarget
);
190 } // end of namespace svgio::svgreader
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */