Branch data 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 <drawinglayer/attribute/sdrlinestartendattribute.hxx>
21 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
22 : :
23 : : //////////////////////////////////////////////////////////////////////////////
24 : :
25 : : namespace drawinglayer
26 : : {
27 : : namespace attribute
28 : : {
29 [ + - ]: 30 : class ImpSdrLineStartEndAttribute
30 : : {
31 : : public:
32 : : // refcounter
33 : : sal_uInt32 mnRefCount;
34 : :
35 : : // line arrow definitions
36 : : basegfx::B2DPolyPolygon maStartPolyPolygon; // start Line PolyPolygon
37 : : basegfx::B2DPolyPolygon maEndPolyPolygon; // end Line PolyPolygon
38 : : double mfStartWidth; // 1/100th mm
39 : : double mfEndWidth; // 1/100th mm
40 : :
41 : : // bitfield
42 : : unsigned mbStartActive : 1L; // start of Line is active
43 : : unsigned mbEndActive : 1L; // end of Line is active
44 : : unsigned mbStartCentered : 1L; // Line is centered on line start point
45 : : unsigned mbEndCentered : 1L; // Line is centered on line end point
46 : :
47 : 83 : ImpSdrLineStartEndAttribute(
48 : : const basegfx::B2DPolyPolygon& rStartPolyPolygon,
49 : : const basegfx::B2DPolyPolygon& rEndPolyPolygon,
50 : : double fStartWidth,
51 : : double fEndWidth,
52 : : bool bStartActive,
53 : : bool bEndActive,
54 : : bool bStartCentered,
55 : : bool bEndCentered)
56 : : : mnRefCount(0),
57 : : maStartPolyPolygon(rStartPolyPolygon),
58 : : maEndPolyPolygon(rEndPolyPolygon),
59 : : mfStartWidth(fStartWidth),
60 : : mfEndWidth(fEndWidth),
61 : : mbStartActive(bStartActive),
62 : : mbEndActive(bEndActive),
63 : : mbStartCentered(bStartCentered),
64 [ + - ]: 83 : mbEndCentered(bEndCentered)
65 : : {
66 : 83 : }
67 : :
68 : : // data read access
69 : 50 : const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; }
70 : 50 : const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; }
71 : 50 : double getStartWidth() const { return mfStartWidth; }
72 : 50 : double getEndWidth() const { return mfEndWidth; }
73 : 40 : bool isStartActive() const { return mbStartActive; }
74 : 40 : bool isEndActive() const { return mbEndActive; }
75 : 50 : bool isStartCentered() const { return mbStartCentered; }
76 : 50 : bool isEndCentered() const { return mbEndCentered; }
77 : :
78 : 20 : bool operator==(const ImpSdrLineStartEndAttribute& rCandidate) const
79 : : {
80 : 20 : return (getStartPolyPolygon() == rCandidate.getStartPolyPolygon()
81 : 20 : && getEndPolyPolygon() == rCandidate.getEndPolyPolygon()
82 : 20 : && getStartWidth() == rCandidate.getStartWidth()
83 : 20 : && getEndWidth() == rCandidate.getEndWidth()
84 : 20 : && isStartActive() == rCandidate.isStartActive()
85 : 20 : && isEndActive() == rCandidate.isEndActive()
86 : 20 : && isStartCentered() == rCandidate.isStartCentered()
87 [ + - ][ + - : 140 : && isEndCentered() == rCandidate.isEndCentered());
+ - + - +
- + - + -
+ - ]
88 : : }
89 : :
90 : 155384 : static ImpSdrLineStartEndAttribute* get_global_default()
91 : : {
92 : : static ImpSdrLineStartEndAttribute* pDefault = 0;
93 : :
94 [ + + ]: 155384 : if(!pDefault)
95 : : {
96 : : pDefault = new ImpSdrLineStartEndAttribute(
97 : : basegfx::B2DPolyPolygon(),
98 : : basegfx::B2DPolyPolygon(),
99 : : 0.0,
100 : : 0.0,
101 : : false,
102 : : false,
103 : : false,
104 [ + - ][ + - ]: 53 : false);
[ + - ][ + - ]
105 : :
106 : : // never delete; start with RefCount 1, not 0
107 : 53 : pDefault->mnRefCount++;
108 : : }
109 : :
110 : 155384 : return pDefault;
111 : : }
112 : : };
113 : :
114 : 30 : SdrLineStartEndAttribute::SdrLineStartEndAttribute(
115 : : const basegfx::B2DPolyPolygon& rStartPolyPolygon,
116 : : const basegfx::B2DPolyPolygon& rEndPolyPolygon,
117 : : double fStartWidth,
118 : : double fEndWidth,
119 : : bool bStartActive,
120 : : bool bEndActive,
121 : : bool bStartCentered,
122 : : bool bEndCentered)
123 : : : mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute(
124 [ + - ]: 30 : rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered))
125 : : {
126 : 30 : }
127 : :
128 : 133235 : SdrLineStartEndAttribute::SdrLineStartEndAttribute()
129 : 133235 : : mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default())
130 : : {
131 : 133235 : mpSdrLineStartEndAttribute->mnRefCount++;
132 : 133235 : }
133 : :
134 : 183608 : SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate)
135 : 183608 : : mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute)
136 : : {
137 : 183608 : mpSdrLineStartEndAttribute->mnRefCount++;
138 : 183608 : }
139 : :
140 : 316873 : SdrLineStartEndAttribute::~SdrLineStartEndAttribute()
141 : : {
142 [ + + ]: 316873 : if(mpSdrLineStartEndAttribute->mnRefCount)
143 : : {
144 : 316843 : mpSdrLineStartEndAttribute->mnRefCount--;
145 : : }
146 : : else
147 : : {
148 [ + - ]: 30 : delete mpSdrLineStartEndAttribute;
149 : : }
150 : 316873 : }
151 : :
152 : 22149 : bool SdrLineStartEndAttribute::isDefault() const
153 : : {
154 : 22149 : return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default();
155 : : }
156 : :
157 : 23883 : SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate)
158 : : {
159 [ + + ]: 23883 : if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute)
160 : : {
161 [ + - ]: 30 : if(mpSdrLineStartEndAttribute->mnRefCount)
162 : : {
163 : 30 : mpSdrLineStartEndAttribute->mnRefCount--;
164 : : }
165 : : else
166 : : {
167 [ # # ]: 0 : delete mpSdrLineStartEndAttribute;
168 : : }
169 : :
170 : 30 : mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
171 : 30 : mpSdrLineStartEndAttribute->mnRefCount++;
172 : : }
173 : :
174 : 23883 : return *this;
175 : : }
176 : :
177 : 64304 : bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const
178 : : {
179 [ + + ]: 64304 : if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute)
180 : : {
181 : 64284 : return true;
182 : : }
183 : :
184 [ - + ]: 20 : if(rCandidate.isDefault() != isDefault())
185 : : {
186 : 0 : return false;
187 : : }
188 : :
189 : 64304 : return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute);
190 : : }
191 : :
192 : 10 : const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const
193 : : {
194 : 10 : return mpSdrLineStartEndAttribute->getStartPolyPolygon();
195 : : }
196 : :
197 : 10 : const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getEndPolyPolygon() const
198 : : {
199 : 10 : return mpSdrLineStartEndAttribute->getEndPolyPolygon();
200 : : }
201 : :
202 : 10 : double SdrLineStartEndAttribute::getStartWidth() const
203 : : {
204 : 10 : return mpSdrLineStartEndAttribute->getStartWidth();
205 : : }
206 : :
207 : 10 : double SdrLineStartEndAttribute::getEndWidth() const
208 : : {
209 : 10 : return mpSdrLineStartEndAttribute->getEndWidth();
210 : : }
211 : :
212 : 0 : bool SdrLineStartEndAttribute::isStartActive() const
213 : : {
214 : 0 : return mpSdrLineStartEndAttribute->isStartActive();
215 : : }
216 : :
217 : 0 : bool SdrLineStartEndAttribute::isEndActive() const
218 : : {
219 : 0 : return mpSdrLineStartEndAttribute->isEndActive();
220 : : }
221 : :
222 : 10 : bool SdrLineStartEndAttribute::isStartCentered() const
223 : : {
224 : 10 : return mpSdrLineStartEndAttribute->isStartCentered();
225 : : }
226 : :
227 : 10 : bool SdrLineStartEndAttribute::isEndCentered() const
228 : : {
229 : 10 : return mpSdrLineStartEndAttribute->isEndCentered();
230 : : }
231 : : } // end of namespace attribute
232 : : } // end of namespace drawinglayer
233 : :
234 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|