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 <svgio/svgreader/svgusenode.hxx>
21 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
22 #include <svgio/svgreader/svgdocument.hxx>
24 //////////////////////////////////////////////////////////////////////////////
30 SvgUseNode::SvgUseNode(
31 SvgDocument
& rDocument
,
33 : SvgNode(SVGTokenG
, rDocument
, pParent
),
34 maSvgStyleAttributes(*this),
44 SvgUseNode::~SvgUseNode()
46 if(mpaTransform
) delete mpaTransform
;
49 const SvgStyleAttributes
* SvgUseNode::getSvgStyleAttributes() const
51 static rtl::OUString
aClassStr(rtl::OUString::createFromAscii("use"));
52 return checkForCssStyle(aClassStr
, maSvgStyleAttributes
);
55 void SvgUseNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
58 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
60 // read style attributes
61 maSvgStyleAttributes
.parseStyleAttribute(rTokenName
, aSVGToken
, aContent
);
68 maSvgStyleAttributes
.readStyle(aContent
);
71 case SVGTokenTransform
:
73 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
75 if(!aMatrix
.isIdentity())
77 setTransform(&aMatrix
);
85 if(readSingleNumber(aContent
, aNum
))
95 if(readSingleNumber(aContent
, aNum
))
105 if(readSingleNumber(aContent
, aNum
))
107 if(aNum
.isPositive())
118 if(readSingleNumber(aContent
, aNum
))
120 if(aNum
.isPositive())
126 case SVGTokenXlinkHref
:
128 const sal_Int32
nLen(aContent
.getLength());
130 if(nLen
&& sal_Unicode('#') == aContent
[0])
132 maXLink
= aContent
.copy(1);
143 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence
& rTarget
, bool /*bReferenced*/) const
145 // try to access link to content
146 const SvgNode
* mpXLink
= getDocument().findSvgNodeById(maXLink
);
151 drawinglayer::primitive2d::Primitive2DSequence aNewTarget
;
153 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
154 // SVG docs want the getWidth() and getHeight() from this node
155 // to be valid for the subtree.
156 const_cast< SvgNode
* >(mpXLink
)->setAlternativeParent(this);
157 mpXLink
->decomposeSvgNode(aNewTarget
, true);
158 const_cast< SvgNode
* >(mpXLink
)->setAlternativeParent(0);
160 if(aNewTarget
.hasElements())
162 basegfx::B2DHomMatrix aTransform
;
164 if(getX().isSet() || getY().isSet())
166 aTransform
.translate(
167 getX().solve(*this, xcoordinate
),
168 getY().solve(*this, ycoordinate
));
173 aTransform
= *getTransform() * aTransform
;
176 if(!aTransform
.isIdentity())
178 const drawinglayer::primitive2d::Primitive2DReference
xRef(
179 new drawinglayer::primitive2d::TransformPrimitive2D(
183 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget
, xRef
);
187 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget
, aNewTarget
);
193 } // end of namespace svgreader
194 } // end of namespace svgio
196 //////////////////////////////////////////////////////////////////////////////
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */