bump product version to 7.2.5.1
[LibreOffice.git] / svgio / source / svgreader / svgusenode.cxx
blobe4fc03ae7345187382632658abcaf469d917b9b4
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 maX(),
32 maY(),
33 maWidth(),
34 maHeight(),
35 maXLink(),
36 mbDecomposingSvgNode(false)
40 SvgUseNode::~SvgUseNode()
44 const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
46 return checkForCssStyle("use", maSvgStyleAttributes);
49 void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
51 // call parent
52 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
54 // read style attributes
55 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent, false);
57 // parse own
58 switch(aSVGToken)
60 case SVGToken::Style:
62 readLocalCssStyle(aContent);
63 break;
65 case SVGToken::Transform:
67 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
69 if(!aMatrix.isIdentity())
71 setTransform(&aMatrix);
73 break;
75 case SVGToken::X:
77 SvgNumber aNum;
79 if(readSingleNumber(aContent, aNum))
81 maX = aNum;
83 break;
85 case SVGToken::Y:
87 SvgNumber aNum;
89 if(readSingleNumber(aContent, aNum))
91 maY = aNum;
93 break;
95 case SVGToken::Width:
97 SvgNumber aNum;
99 if(readSingleNumber(aContent, aNum))
101 if(aNum.isPositive())
103 maWidth = aNum;
106 break;
108 case SVGToken::Height:
110 SvgNumber aNum;
112 if(readSingleNumber(aContent, aNum))
114 if(aNum.isPositive())
116 maHeight = aNum;
119 break;
121 case SVGToken::XlinkHref:
123 const sal_Int32 nLen(aContent.getLength());
125 if(nLen && '#' == aContent[0])
127 maXLink = aContent.copy(1);
129 break;
131 default:
133 break;
138 void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
140 // try to access link to content
141 const SvgNode* pXLink = getDocument().findSvgNodeById(maXLink);
143 if (!pXLink || Display::None == pXLink->getDisplay() || mbDecomposingSvgNode)
144 return;
146 // decompose children
147 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
149 // todo: in case mpXLink is a SVGToken::Svg or SVGToken::Symbol the
150 // SVG docs want the getWidth() and getHeight() from this node
151 // to be valid for the subtree.
152 mbDecomposingSvgNode = true;
153 const_cast< SvgNode* >(pXLink)->setAlternativeParent(this);
154 pXLink->decomposeSvgNode(aNewTarget, true);
155 const_cast< SvgNode* >(pXLink)->setAlternativeParent();
156 mbDecomposingSvgNode = false;
158 if(aNewTarget.empty())
159 return;
161 basegfx::B2DHomMatrix aTransform;
163 if(getX().isSet() || getY().isSet())
165 aTransform.translate(
166 getX().solve(*this, NumberType::xcoordinate),
167 getY().solve(*this, NumberType::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);
190 } // end of namespace svgio::svgreader
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */