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 0 : 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 3 : ImpLineStartEndAttribute(
44 : double fWidth,
45 : const basegfx::B2DPolyPolygon& rPolyPolygon,
46 : bool bCentered)
47 : : mnRefCount(0),
48 : mfWidth(fWidth),
49 : maPolyPolygon(rPolyPolygon),
50 3 : mbCentered(bCentered)
51 : {
52 3 : }
53 :
54 : // data read access
55 15 : double getWidth() const { return mfWidth; }
56 20 : const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; }
57 2 : 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 2 : static ImpLineStartEndAttribute* get_global_default()
67 : {
68 : static ImpLineStartEndAttribute* pDefault = 0;
69 :
70 2 : if(!pDefault)
71 : {
72 : pDefault = new ImpLineStartEndAttribute(
73 : 0.0,
74 : basegfx::B2DPolyPolygon(),
75 1 : false);
76 :
77 : // never delete; start with RefCount 1, not 0
78 1 : pDefault->mnRefCount++;
79 : }
80 :
81 2 : return pDefault;
82 : }
83 : };
84 :
85 2 : LineStartEndAttribute::LineStartEndAttribute(
86 : double fWidth,
87 : const basegfx::B2DPolyPolygon& rPolyPolygon,
88 : bool bCentered)
89 : : mpLineStartEndAttribute(new ImpLineStartEndAttribute(
90 2 : fWidth, rPolyPolygon, bCentered))
91 : {
92 2 : }
93 :
94 0 : LineStartEndAttribute::LineStartEndAttribute()
95 0 : : mpLineStartEndAttribute(ImpLineStartEndAttribute::get_global_default())
96 : {
97 0 : mpLineStartEndAttribute->mnRefCount++;
98 0 : }
99 :
100 2 : LineStartEndAttribute::LineStartEndAttribute(const LineStartEndAttribute& rCandidate)
101 2 : : mpLineStartEndAttribute(rCandidate.mpLineStartEndAttribute)
102 : {
103 2 : mpLineStartEndAttribute->mnRefCount++;
104 2 : }
105 :
106 2 : LineStartEndAttribute::~LineStartEndAttribute()
107 : {
108 2 : if(mpLineStartEndAttribute->mnRefCount)
109 : {
110 2 : mpLineStartEndAttribute->mnRefCount--;
111 : }
112 : else
113 : {
114 0 : delete mpLineStartEndAttribute;
115 : }
116 2 : }
117 :
118 2 : bool LineStartEndAttribute::isDefault() const
119 : {
120 2 : 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 15 : double LineStartEndAttribute::getWidth() const
159 : {
160 15 : return mpLineStartEndAttribute->getWidth();
161 : }
162 :
163 20 : const basegfx::B2DPolyPolygon& LineStartEndAttribute::getB2DPolyPolygon() const
164 : {
165 20 : return mpLineStartEndAttribute->getB2DPolyPolygon();
166 : }
167 :
168 2 : bool LineStartEndAttribute::isCentered() const
169 : {
170 2 : return mpLineStartEndAttribute->isCentered();
171 : }
172 :
173 12 : bool LineStartEndAttribute::isActive() const
174 : {
175 12 : return (0.0 != getWidth()
176 12 : && 0 != getB2DPolyPolygon().count()
177 36 : && 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: */
|