Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/stream.hxx>
30 : : #include <tools/vcompat.hxx>
31 : : #include <tools/debug.hxx>
32 : : #include <vcl/lineinfo.hxx>
33 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
34 : : #include <basegfx/polygon/b2dpolygontools.hxx>
35 : : #include <basegfx/polygon/b2dlinegeometry.hxx>
36 : : #include <numeric>
37 : :
38 : : DBG_NAME( LineInfo )
39 : :
40 : : // ----------------
41 : : // - ImplLineInfo -
42 : : // ----------------
43 : :
44 : 259396 : ImplLineInfo::ImplLineInfo() :
45 : : mnRefCount ( 1 ),
46 : : meStyle ( LINE_SOLID ),
47 : : mnWidth ( 0 ),
48 : : mnDashCount ( 0 ),
49 : : mnDashLen ( 0 ),
50 : : mnDotCount ( 0 ),
51 : : mnDotLen ( 0 ),
52 : : mnDistance ( 0 ),
53 : 259396 : meLineJoin ( basegfx::B2DLINEJOIN_ROUND )
54 : : {
55 : 259396 : }
56 : :
57 : : // -----------------------------------------------------------------------
58 : :
59 : 188232 : ImplLineInfo::ImplLineInfo( const ImplLineInfo& rImplLineInfo ) :
60 : : mnRefCount ( 1 ),
61 : : meStyle ( rImplLineInfo.meStyle ),
62 : : mnWidth ( rImplLineInfo.mnWidth ),
63 : : mnDashCount ( rImplLineInfo.mnDashCount ),
64 : : mnDashLen ( rImplLineInfo.mnDashLen ),
65 : : mnDotCount ( rImplLineInfo.mnDotCount ),
66 : : mnDotLen ( rImplLineInfo.mnDotLen ),
67 : : mnDistance ( rImplLineInfo.mnDistance ),
68 : 188232 : meLineJoin ( rImplLineInfo.meLineJoin )
69 : : {
70 : 188232 : }
71 : :
72 : : // -----------------------------------------------------------------------
73 : :
74 : 4333 : inline bool ImplLineInfo::operator==( const ImplLineInfo& rB ) const
75 : : {
76 : : return(meStyle == rB.meStyle
77 : : && mnWidth == rB.mnWidth
78 : : && mnDashCount == rB.mnDashCount
79 : : && mnDashLen == rB.mnDashLen
80 : : && mnDotCount == rB.mnDotCount
81 : : && mnDotLen == rB.mnDotLen
82 : : && mnDistance == rB.mnDistance
83 [ + - ][ + - ]: 4333 : && meLineJoin == rB.meLineJoin);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
84 : : }
85 : :
86 : : // ------------
87 : : // - LineInfo -
88 : : // ------------
89 : :
90 : 259396 : LineInfo::LineInfo( LineStyle eStyle, long nWidth )
91 : : {
92 : : DBG_CTOR( LineInfo, NULL );
93 : 259396 : mpImplLineInfo = new ImplLineInfo;
94 : 259396 : mpImplLineInfo->meStyle = eStyle;
95 : 259396 : mpImplLineInfo->mnWidth = nWidth;
96 : 259396 : }
97 : :
98 : : // -----------------------------------------------------------------------
99 : :
100 : 195942 : LineInfo::LineInfo( const LineInfo& rLineInfo )
101 : : {
102 : : DBG_CTOR( LineInfo, NULL );
103 : : DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
104 : 195942 : mpImplLineInfo = rLineInfo.mpImplLineInfo;
105 : 195942 : mpImplLineInfo->mnRefCount++;
106 : 195942 : }
107 : :
108 : : // -----------------------------------------------------------------------
109 : :
110 : 455338 : LineInfo::~LineInfo()
111 : : {
112 : : DBG_DTOR( LineInfo, NULL );
113 [ + + ]: 455338 : if( !( --mpImplLineInfo->mnRefCount ) )
114 : 441513 : delete mpImplLineInfo;
115 : 455338 : }
116 : :
117 : : // -----------------------------------------------------------------------
118 : :
119 : 10327 : LineInfo& LineInfo::operator=( const LineInfo& rLineInfo )
120 : : {
121 : : DBG_CHKTHIS( LineInfo, NULL );
122 : : DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
123 : :
124 : 10327 : rLineInfo.mpImplLineInfo->mnRefCount++;
125 : :
126 [ + + ]: 10327 : if( !( --mpImplLineInfo->mnRefCount ) )
127 : 6115 : delete mpImplLineInfo;
128 : :
129 : 10327 : mpImplLineInfo = rLineInfo.mpImplLineInfo;
130 : 10327 : return *this;
131 : : }
132 : :
133 : : // -----------------------------------------------------------------------
134 : :
135 : 4358 : sal_Bool LineInfo::operator==( const LineInfo& rLineInfo ) const
136 : : {
137 : : DBG_CHKTHIS( LineInfo, NULL );
138 : : DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
139 : :
140 : : return( mpImplLineInfo == rLineInfo.mpImplLineInfo ||
141 [ + + ][ + - ]: 4358 : *mpImplLineInfo == *rLineInfo.mpImplLineInfo );
142 : : }
143 : :
144 : : // -----------------------------------------------------------------------
145 : :
146 : 194018 : void LineInfo::ImplMakeUnique()
147 : : {
148 [ + + ]: 194018 : if( mpImplLineInfo->mnRefCount != 1 )
149 : : {
150 [ + - ]: 188232 : if( mpImplLineInfo->mnRefCount )
151 : 188232 : mpImplLineInfo->mnRefCount--;
152 : :
153 : 188232 : mpImplLineInfo = new ImplLineInfo( *mpImplLineInfo );
154 : : }
155 : 194018 : }
156 : :
157 : : // -----------------------------------------------------------------------
158 : :
159 : 1015 : void LineInfo::SetStyle( LineStyle eStyle )
160 : : {
161 : : DBG_CHKTHIS( LineInfo, NULL );
162 : 1015 : ImplMakeUnique();
163 : 1015 : mpImplLineInfo->meStyle = eStyle;
164 : 1015 : }
165 : :
166 : : // -----------------------------------------------------------------------
167 : :
168 : 188337 : void LineInfo::SetWidth( long nWidth )
169 : : {
170 : : DBG_CHKTHIS( LineInfo, NULL );
171 : 188337 : ImplMakeUnique();
172 : 188337 : mpImplLineInfo->mnWidth = nWidth;
173 : 188337 : }
174 : :
175 : : // -----------------------------------------------------------------------
176 : :
177 : 0 : void LineInfo::SetDashCount( sal_uInt16 nDashCount )
178 : : {
179 : : DBG_CHKTHIS( LineInfo, NULL );
180 : 0 : ImplMakeUnique();
181 : 0 : mpImplLineInfo->mnDashCount = nDashCount;
182 : 0 : }
183 : :
184 : : // -----------------------------------------------------------------------
185 : :
186 : 0 : void LineInfo::SetDashLen( long nDashLen )
187 : : {
188 : : DBG_CHKTHIS( LineInfo, NULL );
189 : 0 : ImplMakeUnique();
190 : 0 : mpImplLineInfo->mnDashLen = nDashLen;
191 : 0 : }
192 : :
193 : : // -----------------------------------------------------------------------
194 : :
195 : 0 : void LineInfo::SetDotCount( sal_uInt16 nDotCount )
196 : : {
197 : : DBG_CHKTHIS( LineInfo, NULL );
198 : 0 : ImplMakeUnique();
199 : 0 : mpImplLineInfo->mnDotCount = nDotCount;
200 : 0 : }
201 : :
202 : : // -----------------------------------------------------------------------
203 : :
204 : 0 : void LineInfo::SetDotLen( long nDotLen )
205 : : {
206 : : DBG_CHKTHIS( LineInfo, NULL );
207 : 0 : ImplMakeUnique();
208 : 0 : mpImplLineInfo->mnDotLen = nDotLen;
209 : 0 : }
210 : :
211 : : // -----------------------------------------------------------------------
212 : :
213 : 0 : void LineInfo::SetDistance( long nDistance )
214 : : {
215 : : DBG_CHKTHIS( LineInfo, NULL );
216 : 0 : ImplMakeUnique();
217 : 0 : mpImplLineInfo->mnDistance = nDistance;
218 : 0 : }
219 : :
220 : : // -----------------------------------------------------------------------
221 : :
222 : 405 : void LineInfo::SetLineJoin(basegfx::B2DLineJoin eLineJoin)
223 : : {
224 : : DBG_CHKTHIS( LineInfo, NULL );
225 : :
226 [ - + ]: 405 : if(eLineJoin != mpImplLineInfo->meLineJoin)
227 : : {
228 : 0 : ImplMakeUnique();
229 : 0 : mpImplLineInfo->meLineJoin = eLineJoin;
230 : : }
231 : 405 : }
232 : :
233 : : // -----------------------------------------------------------------------
234 : :
235 : 4666 : SvStream& operator>>( SvStream& rIStm, ImplLineInfo& rImplLineInfo )
236 : : {
237 [ + - ]: 4666 : VersionCompat aCompat( rIStm, STREAM_READ );
238 : 4666 : sal_uInt16 nTmp16(0);
239 : 4666 : sal_Int32 nTmp32(0);
240 : :
241 : : //#fdo39428 SvStream no longer supports operator>>(long&)
242 [ + - ]: 4666 : rIStm >> nTmp16; rImplLineInfo.meStyle = (LineStyle) nTmp16;
243 [ + - ]: 4666 : rIStm >> nTmp32;
244 : 4666 : rImplLineInfo.mnWidth = nTmp32;
245 : :
246 [ + - ]: 4666 : if( aCompat.GetVersion() >= 2 )
247 : : {
248 : : // version 2
249 [ + - ][ + - ]: 4666 : rIStm >> rImplLineInfo.mnDashCount >> nTmp32;
250 : 4666 : rImplLineInfo.mnDashLen = nTmp32;
251 [ + - ][ + - ]: 4666 : rIStm >> rImplLineInfo.mnDotCount >> nTmp32;
252 : 4666 : rImplLineInfo.mnDotLen = nTmp32;
253 [ + - ]: 4666 : rIStm >> nTmp32;
254 : 4666 : rImplLineInfo.mnDistance = nTmp32;
255 : : }
256 : :
257 [ + - ]: 4666 : if( aCompat.GetVersion() >= 3 )
258 : : {
259 : : // version 3
260 [ + - ]: 4666 : rIStm >> nTmp16; rImplLineInfo.meLineJoin = (basegfx::B2DLineJoin) nTmp16;
261 : : }
262 : :
263 [ + - ]: 4666 : return rIStm;
264 : : }
265 : :
266 : : // -----------------------------------------------------------------------
267 : :
268 : 13257 : SvStream& operator<<( SvStream& rOStm, const ImplLineInfo& rImplLineInfo )
269 : : {
270 [ + - ]: 13257 : VersionCompat aCompat( rOStm, STREAM_WRITE, 3 );
271 : :
272 : : //#fdo39428 SvStream no longer supports operator<<(long)
273 : : // version 1
274 [ + - ][ + - ]: 13257 : rOStm << (sal_uInt16) rImplLineInfo.meStyle << sal::static_int_cast<sal_Int32>(rImplLineInfo.mnWidth);
275 : :
276 : : // since version2
277 [ + - ][ + - ]: 13257 : rOStm << rImplLineInfo.mnDashCount << sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDashLen);
278 [ + - ][ + - ]: 13257 : rOStm << rImplLineInfo.mnDotCount << sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDotLen);
279 [ + - ]: 13257 : rOStm << sal::static_int_cast<sal_Int32>(rImplLineInfo.mnDistance);
280 : :
281 : : // since version3
282 [ + - ]: 13257 : rOStm << (sal_uInt16) rImplLineInfo.meLineJoin;
283 : :
284 [ + - ]: 13257 : return rOStm;
285 : : }
286 : :
287 : : // -----------------------------------------------------------------------
288 : :
289 : 4666 : SvStream& operator>>( SvStream& rIStm, LineInfo& rLineInfo )
290 : : {
291 : 4666 : rLineInfo.ImplMakeUnique();
292 : 4666 : return( rIStm >> *rLineInfo.mpImplLineInfo );
293 : : }
294 : :
295 : : // -----------------------------------------------------------------------
296 : :
297 : 13257 : SvStream& operator<<( SvStream& rOStm, const LineInfo& rLineInfo )
298 : : {
299 : 13257 : return( rOStm << *rLineInfo.mpImplLineInfo );
300 : : }
301 : :
302 : : // -----------------------------------------------------------------------
303 : :
304 : 0 : void LineInfo::applyToB2DPolyPolygon(
305 : : basegfx::B2DPolyPolygon& io_rLinePolyPolygon,
306 : : basegfx::B2DPolyPolygon& o_rFillPolyPolygon) const
307 : : {
308 : 0 : o_rFillPolyPolygon.clear();
309 : :
310 [ # # ]: 0 : if(io_rLinePolyPolygon.count())
311 : : {
312 [ # # ]: 0 : if(LINE_DASH == GetStyle())
313 : : {
314 [ # # ]: 0 : ::std::vector< double > fDotDashArray;
315 : 0 : const double fDashLen(GetDashLen());
316 : 0 : const double fDotLen(GetDotLen());
317 : 0 : const double fDistance(GetDistance());
318 : :
319 [ # # ]: 0 : for(sal_uInt16 a(0); a < GetDashCount(); a++)
320 : : {
321 [ # # ]: 0 : fDotDashArray.push_back(fDashLen);
322 [ # # ]: 0 : fDotDashArray.push_back(fDistance);
323 : : }
324 : :
325 [ # # ]: 0 : for(sal_uInt16 b(0); b < GetDotCount(); b++)
326 : : {
327 [ # # ]: 0 : fDotDashArray.push_back(fDotLen);
328 [ # # ]: 0 : fDotDashArray.push_back(fDistance);
329 : : }
330 : :
331 [ # # ]: 0 : const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
332 : :
333 [ # # ]: 0 : if(fAccumulated > 0.0)
334 : : {
335 [ # # ]: 0 : basegfx::B2DPolyPolygon aResult;
336 : :
337 [ # # ][ # # ]: 0 : for(sal_uInt32 c(0); c < io_rLinePolyPolygon.count(); c++)
338 : : {
339 [ # # ]: 0 : basegfx::B2DPolyPolygon aLineTraget;
340 : : basegfx::tools::applyLineDashing(
341 : : io_rLinePolyPolygon.getB2DPolygon(c),
342 : : fDotDashArray,
343 [ # # ][ # # ]: 0 : &aLineTraget);
[ # # ]
344 [ # # ]: 0 : aResult.append(aLineTraget);
345 [ # # ]: 0 : }
346 : :
347 [ # # ][ # # ]: 0 : io_rLinePolyPolygon = aResult;
348 : 0 : }
349 : : }
350 : :
351 [ # # ][ # # ]: 0 : if(GetWidth() > 1 && io_rLinePolyPolygon.count())
[ # # ]
352 : : {
353 : 0 : const double fHalfLineWidth((GetWidth() * 0.5) + 0.5);
354 : :
355 [ # # ]: 0 : for(sal_uInt32 a(0); a < io_rLinePolyPolygon.count(); a++)
356 : : {
357 : : o_rFillPolyPolygon.append(basegfx::tools::createAreaGeometry(
358 : : io_rLinePolyPolygon.getB2DPolygon(a),
359 : : fHalfLineWidth,
360 [ # # ][ # # ]: 0 : GetLineJoin()));
[ # # ]
361 : : }
362 : :
363 : 0 : io_rLinePolyPolygon.clear();
364 : : }
365 : : }
366 : 0 : }
367 : :
368 : : // -----------------------------------------------------------------------
369 : :
370 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|