Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svgio/svgreader/svgpolynode.hxx>
21 : #include <basegfx/polygon/b2dpolygon.hxx>
22 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
23 :
24 : //////////////////////////////////////////////////////////////////////////////
25 :
26 : namespace svgio
27 : {
28 : namespace svgreader
29 : {
30 0 : SvgPolyNode::SvgPolyNode(
31 : SvgDocument& rDocument,
32 : SvgNode* pParent,
33 : bool bIsPolyline)
34 : : SvgNode(SVGTokenPolygon, rDocument, pParent),
35 : maSvgStyleAttributes(*this),
36 : mpPolygon(0),
37 : mpaTransform(0),
38 0 : mbIsPolyline(bIsPolyline)
39 : {
40 0 : }
41 :
42 0 : SvgPolyNode::~SvgPolyNode()
43 : {
44 0 : if(mpaTransform) delete mpaTransform;
45 0 : if(mpPolygon) delete mpPolygon;
46 0 : }
47 :
48 0 : const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
49 : {
50 0 : static rtl::OUString aClassStrA(rtl::OUString::createFromAscii("polygon"));
51 0 : static rtl::OUString aClassStrB(rtl::OUString::createFromAscii("polyline"));
52 0 : maSvgStyleAttributes.checkForCssStyle(mbIsPolyline? aClassStrB : aClassStrA);
53 :
54 0 : return &maSvgStyleAttributes;
55 : }
56 :
57 0 : void SvgPolyNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
58 : {
59 : // call parent
60 0 : SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
61 :
62 : // read style attributes
63 0 : maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
64 :
65 : // parse own
66 0 : switch(aSVGToken)
67 : {
68 : case SVGTokenStyle:
69 : {
70 0 : maSvgStyleAttributes.readStyle(aContent);
71 0 : break;
72 : }
73 : case SVGTokenPoints:
74 : {
75 0 : basegfx::B2DPolygon aPath;
76 :
77 0 : if(basegfx::tools::importFromSvgPoints(aPath, aContent))
78 : {
79 0 : if(aPath.count())
80 : {
81 0 : if(!isPolyline())
82 : {
83 0 : aPath.setClosed(true);
84 : }
85 :
86 0 : setPolygon(&aPath);
87 : }
88 : }
89 0 : break;
90 : }
91 : case SVGTokenTransform:
92 : {
93 0 : const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
94 :
95 0 : if(!aMatrix.isIdentity())
96 : {
97 0 : setTransform(&aMatrix);
98 : }
99 0 : break;
100 : }
101 : default:
102 : {
103 0 : break;
104 : }
105 : }
106 0 : }
107 :
108 0 : void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
109 : {
110 0 : const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
111 :
112 0 : if(pStyle && getPolygon())
113 : {
114 0 : drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
115 :
116 0 : pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget);
117 :
118 0 : if(aNewTarget.hasElements())
119 : {
120 0 : pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
121 0 : }
122 : }
123 0 : }
124 : } // end of namespace svgreader
125 : } // end of namespace svgio
126 :
127 : //////////////////////////////////////////////////////////////////////////////
128 : // eof
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|