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/sdrfillattribute.hxx>
21 : : #include <basegfx/color/bcolor.hxx>
22 : : #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
23 : : #include <drawinglayer/attribute/fillhatchattribute.hxx>
24 : : #include <drawinglayer/attribute/fillgradientattribute.hxx>
25 : :
26 : : //////////////////////////////////////////////////////////////////////////////
27 : :
28 : : namespace drawinglayer
29 : : {
30 : : namespace attribute
31 : : {
32 [ + - ][ + - ]: 56296 : class ImpSdrFillAttribute
[ + - ]
33 : : {
34 : : public:
35 : : // refcounter
36 : : sal_uInt32 mnRefCount;
37 : :
38 : : // fill definitions
39 : : double mfTransparence; // [0.0 .. 1.0], 0.0==no transp.
40 : : basegfx::BColor maColor; // fill color
41 : : FillGradientAttribute maGradient; // fill gradient (if used)
42 : : FillHatchAttribute maHatch; // fill hatch (if used)
43 : : SdrFillBitmapAttribute maBitmap; // fill bitmap (if used)
44 : :
45 : : public:
46 : 56349 : ImpSdrFillAttribute(
47 : : double fTransparence,
48 : : const basegfx::BColor& rColor,
49 : : const FillGradientAttribute& rGradient,
50 : : const FillHatchAttribute& rHatch,
51 : : const SdrFillBitmapAttribute& rBitmap)
52 : : : mnRefCount(0),
53 : : mfTransparence(fTransparence),
54 : : maColor(rColor),
55 : : maGradient(rGradient),
56 : : maHatch(rHatch),
57 [ + - ][ + - ]: 56349 : maBitmap(rBitmap)
[ + - ]
58 : : {
59 : 56349 : }
60 : :
61 : : // data read access
62 : 81547 : double getTransparence() const { return mfTransparence; }
63 : 80557 : const basegfx::BColor& getColor() const { return maColor; }
64 : 81456 : const FillGradientAttribute& getGradient() const { return maGradient; }
65 : 82312 : const FillHatchAttribute& getHatch() const { return maHatch; }
66 : 80018 : const SdrFillBitmapAttribute& getBitmap() const { return maBitmap; }
67 : :
68 : : // compare operator
69 : 33407 : bool operator==(const ImpSdrFillAttribute& rCandidate) const
70 : : {
71 : 33407 : return(getTransparence() == rCandidate.getTransparence()
72 : 33407 : && getColor() == rCandidate.getColor()
73 : 33361 : && getGradient() == rCandidate.getGradient()
74 : 33361 : && getHatch() == rCandidate.getHatch()
75 [ + - ][ + - : 133536 : && getBitmap() == rCandidate.getBitmap());
+ + + - +
- ]
76 : : }
77 : :
78 : 431948 : static ImpSdrFillAttribute* get_global_default()
79 : : {
80 : : static ImpSdrFillAttribute* pDefault = 0;
81 : :
82 [ + + ]: 431948 : if(!pDefault)
83 : : {
84 : : pDefault = new ImpSdrFillAttribute(
85 : : 0.0,
86 : : basegfx::BColor(),
87 : : FillGradientAttribute(),
88 : : FillHatchAttribute(),
89 [ + - ][ + - ]: 53 : SdrFillBitmapAttribute());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
90 : :
91 : : // never delete; start with RefCount 1, not 0
92 : 53 : pDefault->mnRefCount++;
93 : : }
94 : :
95 : 431948 : return pDefault;
96 : : }
97 : : };
98 : :
99 : 56296 : SdrFillAttribute::SdrFillAttribute(
100 : : double fTransparence,
101 : : const basegfx::BColor& rColor,
102 : : const FillGradientAttribute& rGradient,
103 : : const FillHatchAttribute& rHatch,
104 : : const SdrFillBitmapAttribute& rBitmap)
105 : : : mpSdrFillAttribute(new ImpSdrFillAttribute(
106 [ + - ]: 56296 : fTransparence, rColor, rGradient, rHatch, rBitmap))
107 : : {
108 : 56296 : }
109 : :
110 : 152343 : SdrFillAttribute::SdrFillAttribute()
111 : 152343 : : mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
112 : : {
113 : 152343 : mpSdrFillAttribute->mnRefCount++;
114 : 152343 : }
115 : :
116 : 183608 : SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
117 : 183608 : : mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
118 : : {
119 : 183608 : mpSdrFillAttribute->mnRefCount++;
120 : 183608 : }
121 : :
122 : 392247 : SdrFillAttribute::~SdrFillAttribute()
123 : : {
124 [ + + ]: 392247 : if(mpSdrFillAttribute->mnRefCount)
125 : : {
126 : 335951 : mpSdrFillAttribute->mnRefCount--;
127 : : }
128 : : else
129 : : {
130 [ + - ]: 56296 : delete mpSdrFillAttribute;
131 : : }
132 : 392247 : }
133 : :
134 : 279605 : bool SdrFillAttribute::isDefault() const
135 : : {
136 : 279605 : return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
137 : : }
138 : :
139 : 98924 : SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
140 : : {
141 [ + + ]: 98924 : if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
142 : : {
143 [ + - ]: 56267 : if(mpSdrFillAttribute->mnRefCount)
144 : : {
145 : 56267 : mpSdrFillAttribute->mnRefCount--;
146 : : }
147 : : else
148 : : {
149 [ # # ]: 0 : delete mpSdrFillAttribute;
150 : : }
151 : :
152 : 56267 : mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
153 : 56267 : mpSdrFillAttribute->mnRefCount++;
154 : : }
155 : :
156 : 98924 : return *this;
157 : : }
158 : :
159 : 64304 : bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
160 : : {
161 [ + + ]: 64304 : if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
162 : : {
163 : 30897 : return true;
164 : : }
165 : :
166 [ - + ]: 33407 : if(rCandidate.isDefault() != isDefault())
167 : : {
168 : 0 : return false;
169 : : }
170 : :
171 : 64304 : return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
172 : : }
173 : :
174 : 14733 : double SdrFillAttribute::getTransparence() const
175 : : {
176 : 14733 : return mpSdrFillAttribute->getTransparence();
177 : : }
178 : :
179 : 13743 : const basegfx::BColor& SdrFillAttribute::getColor() const
180 : : {
181 : 13743 : return mpSdrFillAttribute->getColor();
182 : : }
183 : :
184 : 14734 : const FillGradientAttribute& SdrFillAttribute::getGradient() const
185 : : {
186 : 14734 : return mpSdrFillAttribute->getGradient();
187 : : }
188 : :
189 : 15590 : const FillHatchAttribute& SdrFillAttribute::getHatch() const
190 : : {
191 : 15590 : return mpSdrFillAttribute->getHatch();
192 : : }
193 : :
194 : 13296 : const SdrFillBitmapAttribute& SdrFillAttribute::getBitmap() const
195 : : {
196 : 13296 : return mpSdrFillAttribute->getBitmap();
197 : : }
198 : : } // end of namespace attribute
199 : : } // end of namespace drawinglayer
200 : :
201 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|