lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svgio / source / svgreader / svgrectnode.cxx
blobc0ff40925f2dea6a1ff238490dd8c6d9be641d27
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())
163 const double fWidth(getWidth().solve(*this, xcoordinate));
164 const double fHeight(getHeight().solve(*this, ycoordinate));
166 if(fWidth > 0.0 && fHeight > 0.0)
168 const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
169 const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
170 const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
171 basegfx::B2DPolygon aPath;
173 if(getRx().isSet() || getRy().isSet())
175 double frX(getRx().isSet() ? getRx().solve(*this, xcoordinate) : 0.0);
176 double frY(getRy().isSet() ? getRy().solve(*this, ycoordinate) : 0.0);
178 frX = std::max(0.0, frX);
179 frY = std::max(0.0, frY);
181 if(0.0 == frY && frX > 0.0)
183 frY = frX;
185 else if(0.0 == frX && frY > 0.0)
187 frX = frY;
190 frX /= fWidth;
191 frY /= fHeight;
193 frX = std::min(0.5, frX);
194 frY = std::min(0.5, frY);
196 aPath = basegfx::utils::createPolygonFromRect(aRange, frX * 2.0, frY * 2.0);
198 else
200 aPath = basegfx::utils::createPolygonFromRect(aRange);
203 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
205 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
207 if(!aNewTarget.empty())
209 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
214 } // end of namespace svgreader
215 } // end of namespace svgio
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */