1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
30 : SvgNode(SVGToken::Rect
, rDocument
, pParent
),
31 maSvgStyleAttributes(*this),
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
)
53 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
55 // read style attributes
56 maSvgStyleAttributes
.parseStyleAttribute(aSVGToken
, aContent
);
63 readLocalCssStyle(aContent
);
70 if(readSingleNumber(aContent
, aNum
))
80 if(readSingleNumber(aContent
, aNum
))
90 if(readSingleNumber(aContent
, aNum
))
99 case SVGToken::Height
:
103 if(readSingleNumber(aContent
, aNum
))
105 if(aNum
.isPositive())
116 if(readSingleNumber(aContent
, aNum
))
118 if(aNum
.isPositive())
129 if(readSingleNumber(aContent
, aNum
))
131 if(aNum
.isPositive())
138 case SVGToken::Transform
:
140 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
142 if(!aMatrix
.isIdentity())
144 setTransform(aMatrix
);
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()))
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)
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)
186 else if(0.0 == frX
&& frY
> 0.0)
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);
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: */