lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svgio / source / svgreader / svgusenode.cxx
blob5904a143068a80e35c5df446425443dd22aa7d59
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 <svgusenode.hxx>
21 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
22 #include <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 maX(),
34 maY(),
35 maWidth(),
36 maHeight(),
37 maXLink(),
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)
53 // call parent
54 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
56 // read style attributes
57 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent, false);
59 // parse own
60 switch(aSVGToken)
62 case SVGTokenStyle:
64 readLocalCssStyle(aContent);
65 break;
67 case SVGTokenTransform:
69 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
71 if(!aMatrix.isIdentity())
73 setTransform(&aMatrix);
75 break;
77 case SVGTokenX:
79 SvgNumber aNum;
81 if(readSingleNumber(aContent, aNum))
83 maX = aNum;
85 break;
87 case SVGTokenY:
89 SvgNumber aNum;
91 if(readSingleNumber(aContent, aNum))
93 maY = aNum;
95 break;
97 case SVGTokenWidth:
99 SvgNumber aNum;
101 if(readSingleNumber(aContent, aNum))
103 if(aNum.isPositive())
105 maWidth = aNum;
108 break;
110 case SVGTokenHeight:
112 SvgNumber aNum;
114 if(readSingleNumber(aContent, aNum))
116 if(aNum.isPositive())
118 maHeight = aNum;
121 break;
123 case SVGTokenXlinkHref:
125 const sal_Int32 nLen(aContent.getLength());
127 if(nLen && '#' == aContent[0])
129 maXLink = aContent.copy(1);
131 break;
133 default:
135 break;
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));
170 if(getTransform())
172 aTransform = *getTransform() * aTransform;
175 if(!aTransform.isIdentity())
177 const drawinglayer::primitive2d::Primitive2DReference xRef(
178 new drawinglayer::primitive2d::TransformPrimitive2D(
179 aTransform,
180 aNewTarget));
182 rTarget.push_back(xRef);
184 else
186 rTarget.append(aNewTarget);
192 } // end of namespace svgreader
193 } // end of namespace svgio
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */