calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svgio / source / svgreader / svgusenode.cxx
blob66f9d1a551a02da7639b202d5e9c4af7bbdd20b2
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::svgreader
26 SvgUseNode::SvgUseNode(
27 SvgDocument& rDocument,
28 SvgNode* pParent)
29 : SvgNode(SVGToken::Use, rDocument, pParent),
30 maSvgStyleAttributes(*this),
31 mbDecomposingSvgNode(false)
35 SvgUseNode::~SvgUseNode()
39 const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
41 return checkForCssStyle("use", maSvgStyleAttributes);
44 void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
46 // call parent
47 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
49 // read style attributes
50 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
52 // parse own
53 switch(aSVGToken)
55 case SVGToken::Style:
57 readLocalCssStyle(aContent);
58 break;
60 case SVGToken::Transform:
62 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
64 if(!aMatrix.isIdentity())
66 setTransform(aMatrix);
68 break;
70 case SVGToken::X:
72 SvgNumber aNum;
74 if(readSingleNumber(aContent, aNum))
76 maX = aNum;
78 break;
80 case SVGToken::Y:
82 SvgNumber aNum;
84 if(readSingleNumber(aContent, aNum))
86 maY = aNum;
88 break;
90 case SVGToken::Width:
92 SvgNumber aNum;
94 if(readSingleNumber(aContent, aNum))
96 if(aNum.isPositive())
98 maWidth = aNum;
101 break;
103 case SVGToken::Height:
105 SvgNumber aNum;
107 if(readSingleNumber(aContent, aNum))
109 if(aNum.isPositive())
111 maHeight = aNum;
114 break;
116 case SVGToken::Href:
117 case SVGToken::XlinkHref:
119 readLocalLink(aContent, maXLink);
120 break;
122 default:
124 break;
129 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
131 // try to access link to content
132 const SvgNode* pXLink = getDocument().findSvgNodeById(maXLink);
134 if (!pXLink || Display::None == pXLink->getDisplay() || mbDecomposingSvgNode)
135 return;
137 // decompose children
138 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
140 // todo: in case mpXLink is a SVGToken::Svg or SVGToken::Symbol the
141 // SVG docs want the getWidth() and getHeight() from this node
142 // to be valid for the subtree.
143 mbDecomposingSvgNode = true;
144 const_cast< SvgNode* >(pXLink)->setAlternativeParent(this);
145 pXLink->decomposeSvgNode(aNewTarget, true);
146 const_cast< SvgNode* >(pXLink)->setAlternativeParent();
147 mbDecomposingSvgNode = false;
149 if(aNewTarget.empty())
150 return;
152 basegfx::B2DHomMatrix aTransform;
154 if(getX().isSet() || getY().isSet())
156 aTransform.translate(
157 getX().solve(*this, NumberType::xcoordinate),
158 getY().solve(*this, NumberType::ycoordinate));
161 if(getTransform())
163 aTransform = *getTransform() * aTransform;
166 if(!aTransform.isIdentity())
168 const drawinglayer::primitive2d::Primitive2DReference xRef(
169 new drawinglayer::primitive2d::TransformPrimitive2D(
170 aTransform,
171 std::move(aNewTarget)));
173 rTarget.push_back(xRef);
175 else
177 rTarget.append(aNewTarget);
181 } // end of namespace svgio::svgreader
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */