Teach symstore more duplicated DLLs
[LibreOffice.git] / svgio / source / svgreader / svgpatternnode.cxx
blobd3ae1e609a9aed2bb2cc9ab88a42ec8e23257393
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 <svgpatternnode.hxx>
21 #include <svgdocument.hxx>
23 namespace svgio
25 namespace svgreader
27 void SvgPatternNode::tryToFindLink()
29 if(!mpXLink && !maXLink.isEmpty())
31 mpXLink = dynamic_cast< const SvgPatternNode* >(getDocument().findSvgNodeById(maXLink));
35 SvgPatternNode::SvgPatternNode(
36 SvgDocument& rDocument,
37 SvgNode* pParent)
38 : SvgNode(SVGTokenPattern, rDocument, pParent),
39 aPrimitives(),
40 maSvgStyleAttributes(*this),
41 maSvgAspectRatio(),
42 maX(),
43 maY(),
44 maWidth(),
45 maHeight(),
46 mbResolvingLink(false),
47 maXLink(),
48 mpXLink(nullptr)
52 SvgPatternNode::~SvgPatternNode()
56 const SvgStyleAttributes* SvgPatternNode::getSvgStyleAttributes() const
58 return checkForCssStyle("pattern", maSvgStyleAttributes);
61 void SvgPatternNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
63 // call parent
64 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
66 // read style attributes
67 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent, false);
69 // parse own
70 switch(aSVGToken)
72 case SVGTokenStyle:
74 readLocalCssStyle(aContent);
75 break;
77 case SVGTokenViewBox:
79 const basegfx::B2DRange aRange(readViewBox(aContent, *this));
81 if(!aRange.isEmpty())
83 setViewBox(&aRange);
85 break;
87 case SVGTokenPreserveAspectRatio:
89 maSvgAspectRatio = readSvgAspectRatio(aContent);
90 break;
92 case SVGTokenX:
94 SvgNumber aNum;
96 if(readSingleNumber(aContent, aNum))
98 maX = aNum;
100 break;
102 case SVGTokenY:
104 SvgNumber aNum;
106 if(readSingleNumber(aContent, aNum))
108 maY = aNum;
110 break;
112 case SVGTokenWidth:
114 SvgNumber aNum;
116 if(readSingleNumber(aContent, aNum))
118 if(aNum.isPositive())
120 maWidth = aNum;
123 break;
125 case SVGTokenHeight:
127 SvgNumber aNum;
129 if(readSingleNumber(aContent, aNum))
131 if(aNum.isPositive())
133 maHeight = aNum;
136 break;
138 case SVGTokenPatternUnits:
140 if(!aContent.isEmpty())
142 if(aContent.match(commonStrings::aStrUserSpaceOnUse))
144 setPatternUnits(userSpaceOnUse);
146 else if(aContent.match(commonStrings::aStrObjectBoundingBox))
148 setPatternUnits(objectBoundingBox);
151 break;
153 case SVGTokenPatternContentUnits:
155 if(!aContent.isEmpty())
157 if(aContent.match(commonStrings::aStrUserSpaceOnUse))
159 setPatternContentUnits(userSpaceOnUse);
161 else if(aContent.match(commonStrings::aStrObjectBoundingBox))
163 setPatternContentUnits(objectBoundingBox);
166 break;
168 case SVGTokenPatternTransform:
170 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
172 if(!aMatrix.isIdentity())
174 setPatternTransform(&aMatrix);
176 break;
178 case SVGTokenXlinkHref:
180 const sal_Int32 nLen(aContent.getLength());
182 if(nLen && '#' == aContent[0])
184 maXLink = aContent.copy(1);
185 tryToFindLink();
187 break;
189 default:
191 break;
196 void SvgPatternNode::getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode const & rUser) const
198 double fTargetWidth(rGeoRange.getWidth());
199 double fTargetHeight(rGeoRange.getHeight());
201 if(!(fTargetWidth > 0.0 && fTargetHeight > 0.0))
202 return;
204 const SvgUnits aPatternUnits(getPatternUnits() ? *getPatternUnits() : objectBoundingBox);
206 if(objectBoundingBox == aPatternUnits)
208 rfW = (getWidth().isSet()) ? getWidth().getNumber() : 0.0;
209 rfH = (getHeight().isSet()) ? getHeight().getNumber() : 0.0;
211 if(Unit_percent == getWidth().getUnit())
213 rfW *= 0.01;
216 if(Unit_percent == getHeight().getUnit())
218 rfH *= 0.01;
221 else
223 rfW = (getWidth().isSet()) ? getWidth().solve(rUser, xcoordinate) : 0.0;
224 rfH = (getHeight().isSet()) ? getHeight().solve(rUser, ycoordinate) : 0.0;
226 // make relative to rGeoRange
227 rfW /= fTargetWidth;
228 rfH /= fTargetHeight;
231 if(!(rfW > 0.0 && rfH > 0.0))
232 return;
234 if(objectBoundingBox == aPatternUnits)
236 rfX = (getX().isSet()) ? getX().getNumber() : 0.0;
237 rfY = (getY().isSet()) ? getY().getNumber() : 0.0;
239 if(Unit_percent == getX().getUnit())
241 rfX *= 0.01;
244 if(Unit_percent == getY().getUnit())
246 rfY *= 0.01;
249 else
251 rfX = (getX().isSet()) ? getX().solve(rUser, xcoordinate) : 0.0;
252 rfY = (getY().isSet()) ? getY().solve(rUser, ycoordinate) : 0.0;
254 // make relative to rGeoRange
255 rfX = (rfX - rGeoRange.getMinX()) / fTargetWidth;
256 rfY = (rfY - rGeoRange.getMinY()) / fTargetHeight;
260 const drawinglayer::primitive2d::Primitive2DContainer& SvgPatternNode::getPatternPrimitives() const
262 if(aPrimitives.empty() && Display_none != getDisplay())
264 decomposeSvgNode(const_cast< SvgPatternNode* >(this)->aPrimitives, true);
267 if(aPrimitives.empty() && !maXLink.isEmpty())
269 const_cast< SvgPatternNode* >(this)->tryToFindLink();
271 if (mpXLink && !mbResolvingLink)
273 mbResolvingLink = true;
274 const drawinglayer::primitive2d::Primitive2DContainer& ret = mpXLink->getPatternPrimitives();
275 mbResolvingLink = false;
276 return ret;
280 return aPrimitives;
283 basegfx::B2DRange SvgPatternNode::getCurrentViewPort() const
285 if(getViewBox())
287 return *(getViewBox());
289 else
291 return SvgNode::getCurrentViewPort();
295 const basegfx::B2DRange* SvgPatternNode::getViewBox() const
297 if(mpViewBox)
299 return mpViewBox.get();
302 const_cast< SvgPatternNode* >(this)->tryToFindLink();
304 if (mpXLink && !mbResolvingLink)
306 mbResolvingLink = true;
307 auto ret = mpXLink->getViewBox();
308 mbResolvingLink = false;
309 return ret;
312 return nullptr;
315 const SvgAspectRatio& SvgPatternNode::getSvgAspectRatio() const
317 if(maSvgAspectRatio.isSet())
319 return maSvgAspectRatio;
322 const_cast< SvgPatternNode* >(this)->tryToFindLink();
324 if (mpXLink && !mbResolvingLink)
326 mbResolvingLink = true;
327 const SvgAspectRatio& ret = mpXLink->getSvgAspectRatio();
328 mbResolvingLink = false;
329 return ret;
332 return maSvgAspectRatio;
335 const SvgNumber& SvgPatternNode::getX() const
337 if(maX.isSet())
339 return maX;
342 const_cast< SvgPatternNode* >(this)->tryToFindLink();
344 if (mpXLink && !mbResolvingLink)
346 mbResolvingLink = true;
347 const SvgNumber& ret = mpXLink->getX();
348 mbResolvingLink = false;
349 return ret;
352 return maX;
355 const SvgNumber& SvgPatternNode::getY() const
357 if(maY.isSet())
359 return maY;
362 const_cast< SvgPatternNode* >(this)->tryToFindLink();
364 if (mpXLink && !mbResolvingLink)
366 mbResolvingLink = true;
367 const SvgNumber& ret = mpXLink->getY();
368 mbResolvingLink = false;
369 return ret;
372 return maY;
375 const SvgNumber& SvgPatternNode::getWidth() const
377 if(maWidth.isSet())
379 return maWidth;
382 const_cast< SvgPatternNode* >(this)->tryToFindLink();
384 if (mpXLink && !mbResolvingLink)
386 mbResolvingLink = true;
387 const SvgNumber& ret = mpXLink->getWidth();
388 mbResolvingLink = false;
389 return ret;
392 return maWidth;
395 const SvgNumber& SvgPatternNode::getHeight() const
397 if(maHeight.isSet())
399 return maHeight;
402 const_cast< SvgPatternNode* >(this)->tryToFindLink();
404 if (mpXLink && !mbResolvingLink)
406 mbResolvingLink = true;
407 const SvgNumber& ret = mpXLink->getHeight();
408 mbResolvingLink = false;
409 return ret;
412 return maHeight;
415 const SvgUnits* SvgPatternNode::getPatternUnits() const
417 if(mpPatternUnits)
419 return mpPatternUnits.get();
422 const_cast< SvgPatternNode* >(this)->tryToFindLink();
424 if (mpXLink && !mbResolvingLink)
426 mbResolvingLink = true;
427 auto ret = mpXLink->getPatternUnits();
428 mbResolvingLink = false;
429 return ret;
432 return nullptr;
435 const SvgUnits* SvgPatternNode::getPatternContentUnits() const
437 if(mpPatternContentUnits)
439 return mpPatternContentUnits.get();
442 const_cast< SvgPatternNode* >(this)->tryToFindLink();
444 if (mpXLink && !mbResolvingLink)
446 mbResolvingLink = true;
447 auto ret = mpXLink->getPatternContentUnits();
448 mbResolvingLink = false;
449 return ret;
452 return nullptr;
455 const basegfx::B2DHomMatrix* SvgPatternNode::getPatternTransform() const
457 if(mpaPatternTransform)
459 return mpaPatternTransform.get();
462 const_cast< SvgPatternNode* >(this)->tryToFindLink();
464 if (mpXLink && !mbResolvingLink)
466 mbResolvingLink = true;
467 auto ret = mpXLink->getPatternTransform();
468 mbResolvingLink = false;
469 return ret;
472 return nullptr;
475 } // end of namespace svgreader
476 } // end of namespace svgio
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */