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 : :
30 : : #include <tools/poly.hxx>
31 : :
32 : : #include <vcl/salbtype.hxx>
33 : : #include <vcl/bitmap.hxx>
34 : : #include <vcl/region.hxx>
35 : : #include <vcl/bmpacc.hxx>
36 : :
37 : : #include <bmpfast.hxx>
38 : :
39 : : // ---------------------
40 : : // - BitmapWriteAccess -
41 : : // ---------------------
42 : :
43 : 26266 : void BitmapWriteAccess::SetLineColor( const Color& rColor )
44 : : {
45 [ + + ]: 26266 : delete mpLineColor;
46 : :
47 [ - + ]: 26266 : if( rColor.GetTransparency() == 255 )
48 : 0 : mpLineColor = NULL;
49 : : else
50 [ - + ][ # # ]: 26266 : mpLineColor = ( HasPalette() ? new BitmapColor( (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) );
[ # # ][ + - ]
[ - + ][ # # ]
51 : 26266 : }
52 : :
53 : : // ------------------------------------------------------------------
54 : :
55 : 9550 : void BitmapWriteAccess::SetFillColor( const Color& rColor )
56 : : {
57 [ + + ]: 9550 : delete mpFillColor;
58 : :
59 [ - + ]: 9550 : if( rColor.GetTransparency() == 255 )
60 : 0 : mpFillColor = NULL;
61 : : else
62 [ + + ][ + - ]: 9550 : mpFillColor = ( HasPalette() ? new BitmapColor( (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) );
[ + - ][ + - ]
[ + + ][ # # ]
63 : 9550 : }
64 : :
65 : : // ------------------------------------------------------------------
66 : :
67 : 1752 : void BitmapWriteAccess::Erase( const Color& rColor )
68 : : {
69 : : // convert the color format from RGB to palette index if needed
70 : : // TODO: provide and use Erase( BitmapColor& method)
71 : 1752 : BitmapColor aColor = rColor;
72 [ + + ]: 1752 : if( HasPalette() )
73 [ + - ]: 1243 : aColor = BitmapColor( (sal_uInt8)GetBestPaletteIndex( rColor) );
74 : : // try fast bitmap method first
75 [ + - ][ + + ]: 1752 : if( ImplFastEraseBitmap( *mpBuffer, aColor ) )
76 : 1752 : return;
77 : :
78 : : // use the canonical method to clear the bitmap
79 [ - + ][ # # ]: 58 : BitmapColor* pOldFillColor = mpFillColor ? new BitmapColor( *mpFillColor ) : NULL;
80 : 58 : const Point aPoint;
81 [ + - ][ + - ]: 58 : const Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
82 : :
83 [ + - ]: 58 : SetFillColor( rColor );
84 [ + - ]: 58 : FillRect( aRect );
85 [ + - ]: 58 : delete mpFillColor;
86 [ + + ]: 1752 : mpFillColor = pOldFillColor;
87 : : }
88 : :
89 : : // ------------------------------------------------------------------
90 : :
91 : 24187 : void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
92 : : {
93 [ + - ]: 24187 : if( mpLineColor )
94 : : {
95 : 24187 : const BitmapColor& rLineColor = *mpLineColor;
96 : : long nX, nY;
97 : :
98 [ + + ]: 24187 : if ( rStart.X() == rEnd.X() )
99 : : {
100 : : // vertikale Line
101 : 9756 : const long nEndY = rEnd.Y();
102 : :
103 : 9756 : nX = rStart.X();
104 : 9756 : nY = rStart.Y();
105 : :
106 [ + + ]: 9756 : if ( nEndY > nY )
107 : : {
108 [ + + ]: 76627 : for (; nY <= nEndY; nY++ )
109 : 67074 : SetPixel( nY, nX, rLineColor );
110 : : }
111 : : else
112 : : {
113 [ + + ]: 1827 : for (; nY >= nEndY; nY-- )
114 : 1624 : SetPixel( nY, nX, rLineColor );
115 : : }
116 : : }
117 [ + - ]: 14431 : else if ( rStart.Y() == rEnd.Y() )
118 : : {
119 : : // horizontale Line
120 : 14431 : const long nEndX = rEnd.X();
121 : :
122 : 14431 : nX = rStart.X();
123 : 14431 : nY = rStart.Y();
124 : :
125 [ + + ]: 14431 : if ( nEndX > nX )
126 : : {
127 [ + + ]: 165452 : for (; nX <= nEndX; nX++ )
128 : 151224 : SetPixel( nY, nX, rLineColor );
129 : : }
130 : : else
131 : : {
132 [ + + ]: 1827 : for (; nX >= nEndX; nX-- )
133 : 1624 : SetPixel( nY, nX, rLineColor );
134 : : }
135 : : }
136 : : else
137 : : {
138 : 0 : const long nDX = labs( rEnd.X() - rStart.X() );
139 : 0 : const long nDY = labs( rEnd.Y() - rStart.Y() );
140 : : long nX1;
141 : : long nY1;
142 : : long nX2;
143 : : long nY2;
144 : :
145 [ # # ]: 0 : if ( nDX >= nDY )
146 : : {
147 [ # # ]: 0 : if ( rStart.X() < rEnd.X() )
148 : : {
149 : 0 : nX1 = rStart.X();
150 : 0 : nY1 = rStart.Y();
151 : 0 : nX2 = rEnd.X();
152 : 0 : nY2 = rEnd.Y();
153 : : }
154 : : else
155 : : {
156 : 0 : nX1 = rEnd.X();
157 : 0 : nY1 = rEnd.Y();
158 : 0 : nX2 = rStart.X();
159 : 0 : nY2 = rStart.Y();
160 : : }
161 : :
162 : 0 : const long nDYX = ( nDY - nDX ) << 1;
163 : 0 : const long nDY2 = nDY << 1;
164 : 0 : long nD = nDY2 - nDX;
165 : 0 : sal_Bool bPos = nY1 < nY2;
166 : :
167 [ # # ]: 0 : for ( nX = nX1, nY = nY1; nX <= nX2; nX++ )
168 : : {
169 : 0 : SetPixel( nY, nX, rLineColor );
170 : :
171 [ # # ]: 0 : if ( nD < 0 )
172 : 0 : nD += nDY2;
173 : : else
174 : : {
175 : 0 : nD += nDYX;
176 : :
177 [ # # ]: 0 : if ( bPos )
178 : 0 : nY++;
179 : : else
180 : 0 : nY--;
181 : : }
182 : : }
183 : : }
184 : : else
185 : : {
186 [ # # ]: 0 : if ( rStart.Y() < rEnd.Y() )
187 : : {
188 : 0 : nX1 = rStart.X();
189 : 0 : nY1 = rStart.Y();
190 : 0 : nX2 = rEnd.X();
191 : 0 : nY2 = rEnd.Y();
192 : : }
193 : : else
194 : : {
195 : 0 : nX1 = rEnd.X();
196 : 0 : nY1 = rEnd.Y();
197 : 0 : nX2 = rStart.X();
198 : 0 : nY2 = rStart.Y();
199 : : }
200 : :
201 : 0 : const long nDYX = ( nDX - nDY ) << 1;
202 : 0 : const long nDY2 = nDX << 1;
203 : 0 : long nD = nDY2 - nDY;
204 : 0 : sal_Bool bPos = nX1 < nX2;
205 : :
206 [ # # ]: 0 : for ( nX = nX1, nY = nY1; nY <= nY2; nY++ )
207 : : {
208 : 0 : SetPixel( nY, nX, rLineColor );
209 : :
210 [ # # ]: 0 : if ( nD < 0 )
211 : 0 : nD += nDY2;
212 : : else
213 : : {
214 : 0 : nD += nDYX;
215 : :
216 [ # # ]: 0 : if ( bPos )
217 : 0 : nX++;
218 : : else
219 : 0 : nX--;
220 : : }
221 : : }
222 : : }
223 : : }
224 : : }
225 : 24187 : }
226 : :
227 : : // ------------------------------------------------------------------
228 : :
229 : 9550 : void BitmapWriteAccess::FillRect( const Rectangle& rRect )
230 : : {
231 [ + - ]: 9550 : if( mpFillColor )
232 : : {
233 : 9550 : const BitmapColor& rFillColor = *mpFillColor;
234 : 9550 : Point aPoint;
235 [ + - ][ + - ]: 9550 : Rectangle aRect( aPoint, maBitmap.GetSizePixel() );
236 : :
237 [ + - ]: 9550 : aRect.Intersection( rRect );
238 : :
239 [ + - ][ + - ]: 9550 : if( !aRect.IsEmpty() )
240 : : {
241 : 9550 : const long nStartX = rRect.Left();
242 : 9550 : const long nStartY = rRect.Top();
243 : 9550 : const long nEndX = rRect.Right();
244 : 9550 : const long nEndY = rRect.Bottom();
245 : :
246 [ + + ]: 63747 : for( long nY = nStartY; nY <= nEndY; nY++ )
247 [ + + ]: 760985 : for( long nX = nStartX; nX <= nEndX; nX++ )
248 [ + - ]: 706788 : SetPixel( nY, nX, rFillColor );
249 : : }
250 : : }
251 : 9550 : }
252 : :
253 : : // ------------------------------------------------------------------
254 : :
255 : 4817 : void BitmapWriteAccess::DrawRect( const Rectangle& rRect )
256 : : {
257 [ + - ]: 4817 : if( mpFillColor )
258 : 4817 : FillRect( rRect );
259 : :
260 [ + + ][ + - ]: 4817 : if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) )
[ + + ][ + + ]
261 : : {
262 [ + - ]: 203 : DrawLine( rRect.TopLeft(), rRect.TopRight() );
263 [ + - ][ + - ]: 203 : DrawLine( rRect.TopRight(), rRect.BottomRight() );
264 [ + - ][ + - ]: 203 : DrawLine( rRect.BottomRight(), rRect.BottomLeft() );
265 [ + - ][ + - ]: 203 : DrawLine( rRect.BottomLeft(), rRect.TopLeft() );
266 : : }
267 : 4817 : }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|