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>
28 SvgUseNode::SvgUseNode(
29 SvgDocument
& rDocument
,
31 : SvgNode(SVGTokenG
, rDocument
, pParent
),
32 maSvgStyleAttributes(*this),
38 mbDecomposingSvgNode(false)
42 SvgUseNode::~SvgUseNode()
46 const SvgStyleAttributes
* SvgUseNode::getSvgStyleAttributes() const
48 return checkForCssStyle("use", maSvgStyleAttributes
);
51 void SvgUseNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
54 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
56 // read style attributes
57 maSvgStyleAttributes
.parseStyleAttribute(aSVGToken
, aContent
, false);
64 readLocalCssStyle(aContent
);
67 case SVGTokenTransform
:
69 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
71 if(!aMatrix
.isIdentity())
73 setTransform(&aMatrix
);
81 if(readSingleNumber(aContent
, aNum
))
91 if(readSingleNumber(aContent
, aNum
))
101 if(readSingleNumber(aContent
, aNum
))
103 if(aNum
.isPositive())
114 if(readSingleNumber(aContent
, aNum
))
116 if(aNum
.isPositive())
123 case SVGTokenXlinkHref
:
125 const sal_Int32
nLen(aContent
.getLength());
127 if(nLen
&& '#' == aContent
[0])
129 maXLink
= aContent
.copy(1);
140 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool /*bReferenced*/) const
142 // try to access link to content
143 const SvgNode
* pXLink
= getDocument().findSvgNodeById(maXLink
);
145 if (pXLink
&& Display_none
!= pXLink
->getDisplay() && !mbDecomposingSvgNode
)
147 // decompose children
148 drawinglayer::primitive2d::Primitive2DContainer aNewTarget
;
150 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
151 // SVG docs want the getWidth() and getHeight() from this node
152 // to be valid for the subtree.
153 mbDecomposingSvgNode
= true;
154 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent(this);
155 pXLink
->decomposeSvgNode(aNewTarget
, true);
156 const_cast< SvgNode
* >(pXLink
)->setAlternativeParent();
157 mbDecomposingSvgNode
= false;
159 if(!aNewTarget
.empty())
161 basegfx::B2DHomMatrix aTransform
;
163 if(getX().isSet() || getY().isSet())
165 aTransform
.translate(
166 getX().solve(*this, xcoordinate
),
167 getY().solve(*this, 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
);
192 } // end of namespace svgreader
193 } // end of namespace svgio
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */