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>
28 SvgUseNode::SvgUseNode(
29 SvgDocument
& rDocument
,
31 : SvgNode(SVGTokenG
, rDocument
, pParent
),
32 maSvgStyleAttributes(*this),
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
)
55 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
57 // read style attributes
58 maSvgStyleAttributes
.parseStyleAttribute(rTokenName
, aSVGToken
, aContent
, false);
65 readLocalCssStyle(aContent
);
68 case SVGTokenTransform
:
70 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
72 if(!aMatrix
.isIdentity())
74 setTransform(&aMatrix
);
82 if(readSingleNumber(aContent
, aNum
))
92 if(readSingleNumber(aContent
, aNum
))
102 if(readSingleNumber(aContent
, aNum
))
104 if(aNum
.isPositive())
115 if(readSingleNumber(aContent
, aNum
))
117 if(aNum
.isPositive())
124 case SVGTokenXlinkHref
:
126 const sal_Int32
nLen(aContent
.getLength());
128 if(nLen
&& '#' == aContent
[0])
130 maXLink
= aContent
.copy(1);
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
));
171 aTransform
= *getTransform() * aTransform
;
174 if(!aTransform
.isIdentity())
176 const drawinglayer::primitive2d::Primitive2DReference
xRef(
177 new drawinglayer::primitive2d::TransformPrimitive2D(
181 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget
, xRef
);
185 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget
, aNewTarget
);
191 } // end of namespace svgreader
192 } // end of namespace svgio
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */