update credits
[LibreOffice.git] / svgio / source / svgreader / svgusenode.cxx
blob1768a176a98984b93c3c70524ecd466f98c03df8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 //////////////////////////////////////////////////////////////////////////////
26 namespace svgio
28 namespace svgreader
30 SvgUseNode::SvgUseNode(
31 SvgDocument& rDocument,
32 SvgNode* pParent)
33 : SvgNode(SVGTokenG, rDocument, pParent),
34 maSvgStyleAttributes(*this),
35 mpaTransform(0),
36 maX(),
37 maY(),
38 maWidth(),
39 maHeight(),
40 maXLink()
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)
57 // call parent
58 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
60 // read style attributes
61 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
63 // parse own
64 switch(aSVGToken)
66 case SVGTokenStyle:
68 maSvgStyleAttributes.readStyle(aContent);
69 break;
71 case SVGTokenTransform:
73 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
75 if(!aMatrix.isIdentity())
77 setTransform(&aMatrix);
79 break;
81 case SVGTokenX:
83 SvgNumber aNum;
85 if(readSingleNumber(aContent, aNum))
87 setX(aNum);
89 break;
91 case SVGTokenY:
93 SvgNumber aNum;
95 if(readSingleNumber(aContent, aNum))
97 setY(aNum);
99 break;
101 case SVGTokenWidth:
103 SvgNumber aNum;
105 if(readSingleNumber(aContent, aNum))
107 if(aNum.isPositive())
109 setWidth(aNum);
112 break;
114 case SVGTokenHeight:
116 SvgNumber aNum;
118 if(readSingleNumber(aContent, aNum))
120 if(aNum.isPositive())
122 setHeight(aNum);
126 case SVGTokenXlinkHref:
128 const sal_Int32 nLen(aContent.getLength());
130 if(nLen && sal_Unicode('#') == aContent[0])
132 maXLink = aContent.copy(1);
134 break;
136 default:
138 break;
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);
148 if(mpXLink)
150 // decompose childs
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));
171 if(getTransform())
173 aTransform = *getTransform() * aTransform;
176 if(!aTransform.isIdentity())
178 const drawinglayer::primitive2d::Primitive2DReference xRef(
179 new drawinglayer::primitive2d::TransformPrimitive2D(
180 aTransform,
181 aNewTarget));
183 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xRef);
185 else
187 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
193 } // end of namespace svgreader
194 } // end of namespace svgio
196 //////////////////////////////////////////////////////////////////////////////
197 // eof
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */