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/svgcirclenode.hxx>
21 : #include <basegfx/polygon/b2dpolygon.hxx>
22 : #include <basegfx/polygon/b2dpolygontools.hxx>
23 :
24 : //////////////////////////////////////////////////////////////////////////////
25 :
26 : namespace svgio
27 : {
28 : namespace svgreader
29 : {
30 0 : SvgCircleNode::SvgCircleNode(
31 : SvgDocument& rDocument,
32 : SvgNode* pParent)
33 : : SvgNode(SVGTokenCircle, rDocument, pParent),
34 : maSvgStyleAttributes(*this),
35 : maCx(0),
36 : maCy(0),
37 : maR(0),
38 0 : mpaTransform(0)
39 : {
40 0 : }
41 :
42 0 : SvgCircleNode::~SvgCircleNode()
43 : {
44 0 : if(mpaTransform) delete mpaTransform;
45 0 : }
46 :
47 0 : const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
48 : {
49 0 : static rtl::OUString aClassStr(rtl::OUString::createFromAscii("circle"));
50 0 : maSvgStyleAttributes.checkForCssStyle(aClassStr);
51 :
52 0 : return &maSvgStyleAttributes;
53 : }
54 :
55 0 : void SvgCircleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
56 : {
57 : // call parent
58 0 : SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
59 :
60 : // read style attributes
61 0 : maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
62 :
63 : // parse own
64 0 : switch(aSVGToken)
65 : {
66 : case SVGTokenStyle:
67 : {
68 0 : maSvgStyleAttributes.readStyle(aContent);
69 0 : break;
70 : }
71 : case SVGTokenCx:
72 : {
73 0 : SvgNumber aNum;
74 :
75 0 : if(readSingleNumber(aContent, aNum))
76 : {
77 0 : setCx(aNum);
78 : }
79 : break;
80 : }
81 : case SVGTokenCy:
82 : {
83 0 : SvgNumber aNum;
84 :
85 0 : if(readSingleNumber(aContent, aNum))
86 : {
87 0 : setCy(aNum);
88 : }
89 : break;
90 : }
91 : case SVGTokenR:
92 : {
93 0 : SvgNumber aNum;
94 :
95 0 : if(readSingleNumber(aContent, aNum))
96 : {
97 0 : if(aNum.isPositive())
98 : {
99 0 : setR(aNum);
100 : }
101 : }
102 : break;
103 : }
104 : case SVGTokenTransform:
105 : {
106 0 : const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
107 :
108 0 : if(!aMatrix.isIdentity())
109 : {
110 0 : setTransform(&aMatrix);
111 : }
112 0 : break;
113 : }
114 : default:
115 : {
116 0 : break;
117 : }
118 : }
119 0 : }
120 :
121 0 : void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
122 : {
123 0 : const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
124 :
125 0 : if(pStyle && getR().isSet())
126 : {
127 0 : const double fR(getR().solve(*this, xcoordinate));
128 :
129 0 : if(fR > 0.0)
130 : {
131 : const basegfx::B2DPolygon aPath(
132 : basegfx::tools::createPolygonFromCircle(
133 : basegfx::B2DPoint(
134 0 : getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
135 0 : getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
136 0 : fR));
137 :
138 0 : drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
139 :
140 0 : pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget);
141 :
142 0 : if(aNewTarget.hasElements())
143 : {
144 0 : pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
145 0 : }
146 : }
147 : }
148 0 : }
149 : } // end of namespace svgreader
150 : } // end of namespace svgio
151 :
152 : //////////////////////////////////////////////////////////////////////////////
153 : // eof
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|