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