Stop leaking all ScPostIt instances.
[LibreOffice.git] / svgio / source / svgreader / svgpolynode.cxx
blobc475c79f72060a86337438d353513edee20bb9f1
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 <svgio/svgreader/svgpolynode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygontools.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
25 //////////////////////////////////////////////////////////////////////////////
27 namespace svgio
29 namespace svgreader
31 SvgPolyNode::SvgPolyNode(
32 SvgDocument& rDocument,
33 SvgNode* pParent,
34 bool bIsPolyline)
35 : SvgNode(SVGTokenPolygon, rDocument, pParent),
36 maSvgStyleAttributes(*this),
37 mpPolygon(0),
38 mpaTransform(0),
39 mbIsPolyline(bIsPolyline)
43 SvgPolyNode::~SvgPolyNode()
45 if(mpaTransform) delete mpaTransform;
46 if(mpPolygon) delete mpPolygon;
49 const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
51 static rtl::OUString aClassStrA(rtl::OUString::createFromAscii("polygon"));
52 static rtl::OUString aClassStrB(rtl::OUString::createFromAscii("polyline"));
53 return checkForCssStyle(mbIsPolyline? aClassStrB : aClassStrA, maSvgStyleAttributes);
56 void SvgPolyNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
58 // call parent
59 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
61 // read style attributes
62 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
64 // parse own
65 switch(aSVGToken)
67 case SVGTokenStyle:
69 maSvgStyleAttributes.readStyle(aContent);
70 break;
72 case SVGTokenPoints:
74 basegfx::B2DPolygon aPath;
76 if(basegfx::tools::importFromSvgPoints(aPath, aContent))
78 if(aPath.count())
80 if(!isPolyline())
82 aPath.setClosed(true);
85 setPolygon(&aPath);
88 break;
90 case SVGTokenTransform:
92 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
94 if(!aMatrix.isIdentity())
96 setTransform(&aMatrix);
98 break;
100 default:
102 break;
107 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
109 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
111 if(pStyle && getPolygon())
113 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
115 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget, 0);
117 if(aNewTarget.hasElements())
119 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
123 } // end of namespace svgreader
124 } // end of namespace svgio
126 //////////////////////////////////////////////////////////////////////////////
127 // eof
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */