Updated core
[LibreOffice.git] / svgio / source / svgreader / svgusenode.cxx
blob42d5c3111d250beb4929a11200086f9181840a1d
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 namespace svgio
26 namespace svgreader
28 SvgUseNode::SvgUseNode(
29 SvgDocument& rDocument,
30 SvgNode* pParent)
31 : SvgNode(SVGTokenG, rDocument, pParent),
32 maSvgStyleAttributes(*this),
33 mpaTransform(0),
34 maX(),
35 maY(),
36 maWidth(),
37 maHeight(),
38 maXLink()
42 SvgUseNode::~SvgUseNode()
44 if(mpaTransform) delete mpaTransform;
47 const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
49 return checkForCssStyle(OUString("use"), maSvgStyleAttributes);
52 void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
54 // call parent
55 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
57 // read style attributes
58 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent, false);
60 // parse own
61 switch(aSVGToken)
63 case SVGTokenStyle:
65 readLocalCssStyle(aContent);
66 break;
68 case SVGTokenTransform:
70 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
72 if(!aMatrix.isIdentity())
74 setTransform(&aMatrix);
76 break;
78 case SVGTokenX:
80 SvgNumber aNum;
82 if(readSingleNumber(aContent, aNum))
84 setX(aNum);
86 break;
88 case SVGTokenY:
90 SvgNumber aNum;
92 if(readSingleNumber(aContent, aNum))
94 setY(aNum);
96 break;
98 case SVGTokenWidth:
100 SvgNumber aNum;
102 if(readSingleNumber(aContent, aNum))
104 if(aNum.isPositive())
106 setWidth(aNum);
109 break;
111 case SVGTokenHeight:
113 SvgNumber aNum;
115 if(readSingleNumber(aContent, aNum))
117 if(aNum.isPositive())
119 setHeight(aNum);
122 break;
124 case SVGTokenXlinkHref:
126 const sal_Int32 nLen(aContent.getLength());
128 if(nLen && '#' == aContent[0])
130 maXLink = aContent.copy(1);
132 break;
134 default:
136 break;
141 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
143 // try to access link to content
144 const SvgNode* mpXLink = getDocument().findSvgNodeById(maXLink);
146 if(mpXLink && Display_none != mpXLink->getDisplay())
148 // decompose children
149 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
151 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
152 // SVG docs want the getWidth() and getHeight() from this node
153 // to be valid for the subtree.
154 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(this);
155 mpXLink->decomposeSvgNode(aNewTarget, true);
156 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(0);
158 if(aNewTarget.hasElements())
160 basegfx::B2DHomMatrix aTransform;
162 if(getX().isSet() || getY().isSet())
164 aTransform.translate(
165 getX().solve(*this, xcoordinate),
166 getY().solve(*this, ycoordinate));
169 if(getTransform())
171 aTransform = *getTransform() * aTransform;
174 if(!aTransform.isIdentity())
176 const drawinglayer::primitive2d::Primitive2DReference xRef(
177 new drawinglayer::primitive2d::TransformPrimitive2D(
178 aTransform,
179 aNewTarget));
181 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xRef);
183 else
185 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
191 } // end of namespace svgreader
192 } // end of namespace svgio
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */