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 <svgio/svgreader/svgrectnode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
30 SvgRectNode::SvgRectNode(
31 SvgDocument
& rDocument
,
33 : SvgNode(SVGTokenRect
, rDocument
, pParent
),
34 maSvgStyleAttributes(*this),
45 SvgRectNode::~SvgRectNode()
47 if(mpaTransform
) delete mpaTransform
;
50 const SvgStyleAttributes
* SvgRectNode::getSvgStyleAttributes() const
52 static rtl::OUString
aClassStr(rtl::OUString::createFromAscii("rect"));
53 return checkForCssStyle(aClassStr
, maSvgStyleAttributes
);
56 void SvgRectNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
59 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
61 // read style attributes
62 maSvgStyleAttributes
.parseStyleAttribute(rTokenName
, aSVGToken
, aContent
);
69 maSvgStyleAttributes
.readStyle(aContent
);
76 if(readSingleNumber(aContent
, aNum
))
86 if(readSingleNumber(aContent
, aNum
))
96 if(readSingleNumber(aContent
, aNum
))
109 if(readSingleNumber(aContent
, aNum
))
111 if(aNum
.isPositive())
122 if(readSingleNumber(aContent
, aNum
))
124 if(aNum
.isPositive())
135 if(readSingleNumber(aContent
, aNum
))
137 if(aNum
.isPositive())
144 case SVGTokenTransform
:
146 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
148 if(!aMatrix
.isIdentity())
150 setTransform(&aMatrix
);
161 void SvgRectNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence
& rTarget
, bool /*bReferenced*/) const
163 // get size range and create path
164 const SvgStyleAttributes
* pStyle
= getSvgStyleAttributes();
166 if(pStyle
&& getWidth().isSet() && getHeight().isSet())
168 const double fWidth(getWidth().solve(*this, xcoordinate
));
169 const double fHeight(getHeight().solve(*this, ycoordinate
));
171 if(fWidth
> 0.0 && fHeight
> 0.0)
173 const double fX(getX().isSet() ? getX().solve(*this, xcoordinate
) : 0.0);
174 const double fY(getY().isSet() ? getY().solve(*this, ycoordinate
) : 0.0);
175 const basegfx::B2DRange
aRange(fX
, fY
, fX
+ fWidth
, fY
+ fHeight
);
176 basegfx::B2DPolygon aPath
;
178 if(getRx().isSet() || getRy().isSet())
180 double frX(getRx().isSet() ? getRx().solve(*this, xcoordinate
) : 0.0);
181 double frY(getRy().isSet() ? getRy().solve(*this, ycoordinate
) : 0.0);
183 frX
= std::max(0.0, frX
);
184 frY
= std::max(0.0, frY
);
186 if(0.0 == frY
&& frX
> 0.0)
190 else if(0.0 == frX
&& frY
> 0.0)
198 frX
= std::min(0.5, frX
);
199 frY
= std::min(0.5, frY
);
201 aPath
= basegfx::tools::createPolygonFromRect(aRange
, frX
* 2.0, frY
* 2.0);
205 aPath
= basegfx::tools::createPolygonFromRect(aRange
);
208 drawinglayer::primitive2d::Primitive2DSequence aNewTarget
;
210 pStyle
->add_path(basegfx::B2DPolyPolygon(aPath
), aNewTarget
);
212 if(aNewTarget
.hasElements())
214 pStyle
->add_postProcess(rTarget
, aNewTarget
, getTransform());
219 } // end of namespace svgreader
220 } // end of namespace svgio
222 //////////////////////////////////////////////////////////////////////////////
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */