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/linestartendattribute.hxx>
21 : : #include <basegfx/polygon/b2dpolygon.hxx>
22 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
23 : :
24 : : //////////////////////////////////////////////////////////////////////////////
25 : :
26 : : namespace drawinglayer
27 : : {
28 : : namespace attribute
29 : : {
30 : 20 : class ImpLineStartEndAttribute
31 : : {
32 : : public:
33 : : // refcounter
34 : : sal_uInt32 mnRefCount;
35 : :
36 : : // data definitions
37 : : double mfWidth; // absolute line StartEndGeometry base width
38 : : basegfx::B2DPolyPolygon maPolyPolygon; // the StartEndGeometry PolyPolygon
39 : :
40 : : // bitfield
41 : : unsigned mbCentered : 1; // use centered to ineStart/End point?
42 : :
43 : 26 : ImpLineStartEndAttribute(
44 : : double fWidth,
45 : : const basegfx::B2DPolyPolygon& rPolyPolygon,
46 : : bool bCentered)
47 : : : mnRefCount(0),
48 : : mfWidth(fWidth),
49 : : maPolyPolygon(rPolyPolygon),
50 : 26 : mbCentered(bCentered)
51 : : {
52 : 26 : }
53 : :
54 : : // data read access
55 : 122 : double getWidth() const { return mfWidth; }
56 : 174 : const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; }
57 : 15 : bool isCentered() const { return mbCentered; }
58 : :
59 : 0 : bool operator==(const ImpLineStartEndAttribute& rCandidate) const
60 : : {
61 [ # # ][ # # ]: 0 : return (basegfx::fTools::equal(getWidth(), rCandidate.getWidth())
[ # # # # ]
62 [ # # ]: 0 : && getB2DPolyPolygon() == rCandidate.getB2DPolyPolygon()
63 [ # # ][ # # ]: 0 : && isCentered() == rCandidate.isCentered());
[ # # ]
64 : : }
65 : :
66 : 20 : static ImpLineStartEndAttribute* get_global_default()
67 : : {
68 : : static ImpLineStartEndAttribute* pDefault = 0;
69 : :
70 [ + + ]: 20 : if(!pDefault)
71 : : {
72 : : pDefault = new ImpLineStartEndAttribute(
73 : : 0.0,
74 : : basegfx::B2DPolyPolygon(),
75 [ + - ][ + - ]: 6 : false);
76 : :
77 : : // never delete; start with RefCount 1, not 0
78 : 6 : pDefault->mnRefCount++;
79 : : }
80 : :
81 : 20 : return pDefault;
82 : : }
83 : : };
84 : :
85 : 20 : LineStartEndAttribute::LineStartEndAttribute(
86 : : double fWidth,
87 : : const basegfx::B2DPolyPolygon& rPolyPolygon,
88 : : bool bCentered)
89 : : : mpLineStartEndAttribute(new ImpLineStartEndAttribute(
90 [ + - ]: 20 : fWidth, rPolyPolygon, bCentered))
91 : : {
92 : 20 : }
93 : :
94 : 0 : LineStartEndAttribute::LineStartEndAttribute()
95 : 0 : : mpLineStartEndAttribute(ImpLineStartEndAttribute::get_global_default())
96 : : {
97 : 0 : mpLineStartEndAttribute->mnRefCount++;
98 : 0 : }
99 : :
100 : 20 : LineStartEndAttribute::LineStartEndAttribute(const LineStartEndAttribute& rCandidate)
101 : 20 : : mpLineStartEndAttribute(rCandidate.mpLineStartEndAttribute)
102 : : {
103 : 20 : mpLineStartEndAttribute->mnRefCount++;
104 : 20 : }
105 : :
106 : 40 : LineStartEndAttribute::~LineStartEndAttribute()
107 : : {
108 [ + + ]: 40 : if(mpLineStartEndAttribute->mnRefCount)
109 : : {
110 : 20 : mpLineStartEndAttribute->mnRefCount--;
111 : : }
112 : : else
113 : : {
114 [ + - ]: 20 : delete mpLineStartEndAttribute;
115 : : }
116 : 40 : }
117 : :
118 : 20 : bool LineStartEndAttribute::isDefault() const
119 : : {
120 : 20 : return mpLineStartEndAttribute == ImpLineStartEndAttribute::get_global_default();
121 : : }
122 : :
123 : 0 : LineStartEndAttribute& LineStartEndAttribute::operator=(const LineStartEndAttribute& rCandidate)
124 : : {
125 [ # # ]: 0 : if(rCandidate.mpLineStartEndAttribute != mpLineStartEndAttribute)
126 : : {
127 [ # # ]: 0 : if(mpLineStartEndAttribute->mnRefCount)
128 : : {
129 : 0 : mpLineStartEndAttribute->mnRefCount--;
130 : : }
131 : : else
132 : : {
133 [ # # ]: 0 : delete mpLineStartEndAttribute;
134 : : }
135 : :
136 : 0 : mpLineStartEndAttribute = rCandidate.mpLineStartEndAttribute;
137 : 0 : mpLineStartEndAttribute->mnRefCount++;
138 : : }
139 : :
140 : 0 : return *this;
141 : : }
142 : :
143 : 0 : bool LineStartEndAttribute::operator==(const LineStartEndAttribute& rCandidate) const
144 : : {
145 [ # # ]: 0 : if(rCandidate.mpLineStartEndAttribute == mpLineStartEndAttribute)
146 : : {
147 : 0 : return true;
148 : : }
149 : :
150 [ # # ]: 0 : if(rCandidate.isDefault() != isDefault())
151 : : {
152 : 0 : return false;
153 : : }
154 : :
155 : 0 : return (*rCandidate.mpLineStartEndAttribute == *mpLineStartEndAttribute);
156 : : }
157 : :
158 : 122 : double LineStartEndAttribute::getWidth() const
159 : : {
160 : 122 : return mpLineStartEndAttribute->getWidth();
161 : : }
162 : :
163 : 174 : const basegfx::B2DPolyPolygon& LineStartEndAttribute::getB2DPolyPolygon() const
164 : : {
165 : 174 : return mpLineStartEndAttribute->getB2DPolyPolygon();
166 : : }
167 : :
168 : 15 : bool LineStartEndAttribute::isCentered() const
169 : : {
170 : 15 : return mpLineStartEndAttribute->isCentered();
171 : : }
172 : :
173 : 97 : bool LineStartEndAttribute::isActive() const
174 : : {
175 [ + - ]: 97 : return (0.0 != getWidth()
176 [ + - ][ + - ]: 97 : && 0 != getB2DPolyPolygon().count()
177 [ + - ][ + + ]: 194 : && 0 != getB2DPolyPolygon().getB2DPolygon(0).count());
[ + - ][ + - ]
[ + - ][ + - ]
[ + + ][ # # ]
178 : : }
179 : : } // end of namespace attribute
180 : : } // end of namespace drawinglayer
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|