Teach symstore more duplicated DLLs
[LibreOffice.git] / svgio / source / svgreader / svgrectnode.cxx
blobd8c9ce6afb912350a9baf29fbed6df3cb45b888f
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 <svgrectnode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
24 namespace svgio
26 namespace svgreader
28 SvgRectNode::SvgRectNode(
29 SvgDocument& rDocument,
30 SvgNode* pParent)
31 : SvgNode(SVGTokenRect, rDocument, pParent),
32 maSvgStyleAttributes(*this),
33 maX(0),
34 maY(0),
35 maWidth(0),
36 maHeight(0),
37 maRx(0),
38 maRy(0)
42 SvgRectNode::~SvgRectNode()
46 const SvgStyleAttributes* SvgRectNode::getSvgStyleAttributes() const
48 return checkForCssStyle("rect", maSvgStyleAttributes);
51 void SvgRectNode::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 SVGTokenX:
69 SvgNumber aNum;
71 if(readSingleNumber(aContent, aNum))
73 maX = aNum;
75 break;
77 case SVGTokenY:
79 SvgNumber aNum;
81 if(readSingleNumber(aContent, aNum))
83 maY = aNum;
85 break;
87 case SVGTokenWidth:
89 SvgNumber aNum;
91 if(readSingleNumber(aContent, aNum))
93 if(aNum.isPositive())
95 maWidth = aNum;
98 break;
100 case SVGTokenHeight:
102 SvgNumber aNum;
104 if(readSingleNumber(aContent, aNum))
106 if(aNum.isPositive())
108 maHeight = aNum;
111 break;
113 case SVGTokenRx:
115 SvgNumber aNum;
117 if(readSingleNumber(aContent, aNum))
119 if(aNum.isPositive())
121 maRx = aNum;
124 break;
126 case SVGTokenRy:
128 SvgNumber aNum;
130 if(readSingleNumber(aContent, aNum))
132 if(aNum.isPositive())
134 maRy = aNum;
137 break;
139 case SVGTokenTransform:
141 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
143 if(!aMatrix.isIdentity())
145 setTransform(&aMatrix);
147 break;
149 default:
151 break;
156 void SvgRectNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
158 // get size range and create path
159 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
161 if(!(pStyle && getWidth().isSet() && getHeight().isSet()))
162 return;
164 const double fWidth(getWidth().solve(*this, xcoordinate));
165 const double fHeight(getHeight().solve(*this, ycoordinate));
167 if(!(fWidth > 0.0 && fHeight > 0.0))
168 return;
170 const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
171 const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
172 const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
173 basegfx::B2DPolygon aPath;
175 if(getRx().isSet() || getRy().isSet())
177 double frX(getRx().isSet() ? getRx().solve(*this, xcoordinate) : 0.0);
178 double frY(getRy().isSet() ? getRy().solve(*this, ycoordinate) : 0.0);
180 frX = std::max(0.0, frX);
181 frY = std::max(0.0, frY);
183 if(0.0 == frY && frX > 0.0)
185 frY = frX;
187 else if(0.0 == frX && frY > 0.0)
189 frX = frY;
192 frX /= fWidth;
193 frY /= fHeight;
195 frX = std::min(0.5, frX);
196 frY = std::min(0.5, frY);
198 aPath = basegfx::utils::createPolygonFromRect(aRange, frX * 2.0, frY * 2.0);
200 else
202 aPath = basegfx::utils::createPolygonFromRect(aRange);
205 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
207 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
209 if(!aNewTarget.empty())
211 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
214 } // end of namespace svgreader
215 } // end of namespace svgio
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */