bump product version to 7.2.5.1
[LibreOffice.git] / svgio / source / svgreader / svgpolynode.cxx
blobd7bcb0f07330efada9abb48c507ec1824f107ab8
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 <svgpolynode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
25 namespace svgio::svgreader
27 SvgPolyNode::SvgPolyNode(
28 SvgDocument& rDocument,
29 SvgNode* pParent,
30 bool bIsPolyline)
31 : SvgNode(SVGToken::Polygon, rDocument, pParent),
32 maSvgStyleAttributes(*this),
33 mbIsPolyline(bIsPolyline)
37 SvgPolyNode::~SvgPolyNode()
41 const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
43 return checkForCssStyle(mbIsPolyline? OUString("polyline") : OUString("polygon"), maSvgStyleAttributes);
46 void SvgPolyNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
48 // call parent
49 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
51 // read style attributes
52 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent, false);
54 // parse own
55 switch(aSVGToken)
57 case SVGToken::Style:
59 readLocalCssStyle(aContent);
60 break;
62 case SVGToken::Points:
64 basegfx::B2DPolygon aPath;
66 if(basegfx::utils::importFromSvgPoints(aPath, aContent))
68 if(aPath.count())
70 if(!mbIsPolyline)
72 aPath.setClosed(true);
75 setPolygon(&aPath);
78 break;
80 case SVGToken::Transform:
82 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
84 if(!aMatrix.isIdentity())
86 setTransform(&aMatrix);
88 break;
90 default:
92 break;
97 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
99 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
101 if(pStyle && mpPolygon)
103 drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
105 pStyle->add_path(basegfx::B2DPolyPolygon(*mpPolygon), aNewTarget, nullptr);
107 if(!aNewTarget.empty())
109 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
113 } // end of namespace svgio::svgreader
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */