calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svgio / source / svgreader / svgrectnode.cxx
blobd744343de200240e4deedde582bed9a8ffe5bf8f
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>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
25 namespace svgio::svgreader
27 SvgRectNode::SvgRectNode(
28 SvgDocument& rDocument,
29 SvgNode* pParent)
30 : SvgNode(SVGToken::Rect, rDocument, pParent),
31 maSvgStyleAttributes(*this),
32 maX(0),
33 maY(0),
34 maWidth(0),
35 maHeight(0),
36 maRx(0),
37 maRy(0)
41 SvgRectNode::~SvgRectNode()
45 const SvgStyleAttributes* SvgRectNode::getSvgStyleAttributes() const
47 return checkForCssStyle("rect", maSvgStyleAttributes);
50 void SvgRectNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
52 // call parent
53 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
55 // read style attributes
56 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
58 // parse own
59 switch(aSVGToken)
61 case SVGToken::Style:
63 readLocalCssStyle(aContent);
64 break;
66 case SVGToken::X:
68 SvgNumber aNum;
70 if(readSingleNumber(aContent, aNum))
72 maX = aNum;
74 break;
76 case SVGToken::Y:
78 SvgNumber aNum;
80 if(readSingleNumber(aContent, aNum))
82 maY = aNum;
84 break;
86 case SVGToken::Width:
88 SvgNumber aNum;
90 if(readSingleNumber(aContent, aNum))
92 if(aNum.isPositive())
94 maWidth = aNum;
97 break;
99 case SVGToken::Height:
101 SvgNumber aNum;
103 if(readSingleNumber(aContent, aNum))
105 if(aNum.isPositive())
107 maHeight = aNum;
110 break;
112 case SVGToken::Rx:
114 SvgNumber aNum;
116 if(readSingleNumber(aContent, aNum))
118 if(aNum.isPositive())
120 maRx = aNum;
123 break;
125 case SVGToken::Ry:
127 SvgNumber aNum;
129 if(readSingleNumber(aContent, aNum))
131 if(aNum.isPositive())
133 maRy = aNum;
136 break;
138 case SVGToken::Transform:
140 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
142 if(!aMatrix.isIdentity())
144 setTransform(aMatrix);
146 break;
148 default:
150 break;
155 void SvgRectNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
157 // get size range and create path
158 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
160 if(!(pStyle && getWidth().isSet() && getHeight().isSet()))
161 return;
163 const double fWidth(getWidth().solve(*this, NumberType::xcoordinate));
164 const double fHeight(getHeight().solve(*this, NumberType::ycoordinate));
166 if(fWidth <= 0.0 || fHeight <= 0.0)
167 return;
169 const double fX(getX().isSet() ? getX().solve(*this, NumberType::xcoordinate) : 0.0);
170 const double fY(getY().isSet() ? getY().solve(*this, NumberType::ycoordinate) : 0.0);
171 const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
172 basegfx::B2DPolygon aPath;
174 if(getRx().isSet() || getRy().isSet())
176 double frX(getRx().isSet() ? getRx().solve(*this, NumberType::xcoordinate) : 0.0);
177 double frY(getRy().isSet() ? getRy().solve(*this, NumberType::ycoordinate) : 0.0);
179 frX = std::max(0.0, frX);
180 frY = std::max(0.0, frY);
182 if(0.0 == frY && frX > 0.0)
184 frY = frX;
186 else if(0.0 == frX && frY > 0.0)
188 frX = frY;
191 frX /= fWidth;
192 frY /= fHeight;
194 frX = std::min(0.5, frX);
195 frY = std::min(0.5, frY);
197 aPath = basegfx::utils::createPolygonFromRect(aRange, frX * 2.0, frY * 2.0);
199 else
201 aPath = basegfx::utils::createPolygonFromRect(aRange);
204 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
206 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
208 if(!aNewTarget.empty())
210 pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
213 } // end of namespace svgio::svgreader
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */