1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include <tools/ref.hxx> 32 #include <tools/debug.hxx> 33 #include <tools/poly.hxx> 34 35 #include <vcl/metaact.hxx> 36 #include <vcl/gdimtf.hxx> 37 #include <vcl/outdev.hxx> 38 #include <vcl/virdev.hxx> 39 40 #include <salgdi.hxx> 41 #include <svdata.hxx> 42 #include <outdata.hxx> 43 #include <outdev.h> 44 45 // ======================================================================= 46 47 DBG_NAMEEX( OutputDevice ) 48 49 // ======================================================================= 50 51 void OutputDevice::DrawRect( const Rectangle& rRect, 52 sal_uLong nHorzRound, sal_uLong nVertRound ) 53 { 54 DBG_TRACE( "OutputDevice::DrawRoundRect()" ); 55 DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 56 57 if ( mpMetaFile ) 58 mpMetaFile->AddAction( new MetaRoundRectAction( rRect, nHorzRound, nVertRound ) ); 59 60 if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() ) 61 return; 62 63 const Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 64 65 if ( aRect.IsEmpty() ) 66 return; 67 68 nHorzRound = ImplLogicWidthToDevicePixel( nHorzRound ); 69 nVertRound = ImplLogicHeightToDevicePixel( nVertRound ); 70 71 // we need a graphics 72 if ( !mpGraphics ) 73 { 74 if ( !ImplGetGraphics() ) 75 return; 76 } 77 78 if ( mbInitClipRegion ) 79 ImplInitClipRegion(); 80 if ( mbOutputClipped ) 81 return; 82 83 if ( mbInitLineColor ) 84 ImplInitLineColor(); 85 if ( mbInitFillColor ) 86 ImplInitFillColor(); 87 88 if ( !nHorzRound && !nVertRound ) 89 mpGraphics->DrawRect( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight(), this ); 90 else 91 { 92 const Polygon aRoundRectPoly( aRect, nHorzRound, nVertRound ); 93 94 if ( aRoundRectPoly.GetSize() >= 2 ) 95 { 96 const SalPoint* pPtAry = (const SalPoint*) aRoundRectPoly.GetConstPointAry(); 97 98 if ( !mbFillColor ) 99 mpGraphics->DrawPolyLine( aRoundRectPoly.GetSize(), pPtAry, this ); 100 else 101 mpGraphics->DrawPolygon( aRoundRectPoly.GetSize(), pPtAry, this ); 102 } 103 } 104 105 if( mpAlphaVDev ) 106 mpAlphaVDev->DrawRect( rRect, nHorzRound, nVertRound ); 107 } 108 109 // ----------------------------------------------------------------------- 110 111 void OutputDevice::DrawEllipse( const Rectangle& rRect ) 112 { 113 DBG_TRACE( "OutputDevice::DrawEllipse()" ); 114 DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 115 116 if ( mpMetaFile ) 117 mpMetaFile->AddAction( new MetaEllipseAction( rRect ) ); 118 119 if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() ) 120 return; 121 122 Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 123 if ( aRect.IsEmpty() ) 124 return; 125 126 // we need a graphics 127 if ( !mpGraphics ) 128 { 129 if ( !ImplGetGraphics() ) 130 return; 131 } 132 133 if ( mbInitClipRegion ) 134 ImplInitClipRegion(); 135 if ( mbOutputClipped ) 136 return; 137 138 if ( mbInitLineColor ) 139 ImplInitLineColor(); 140 141 Polygon aRectPoly( aRect.Center(), aRect.GetWidth() >> 1, aRect.GetHeight() >> 1 ); 142 if ( aRectPoly.GetSize() >= 2 ) 143 { 144 const SalPoint* pPtAry = (const SalPoint*)aRectPoly.GetConstPointAry(); 145 if ( !mbFillColor ) 146 mpGraphics->DrawPolyLine( aRectPoly.GetSize(), pPtAry, this ); 147 else 148 { 149 if ( mbInitFillColor ) 150 ImplInitFillColor(); 151 mpGraphics->DrawPolygon( aRectPoly.GetSize(), pPtAry, this ); 152 } 153 } 154 155 if( mpAlphaVDev ) 156 mpAlphaVDev->DrawEllipse( rRect ); 157 } 158 159 // ----------------------------------------------------------------------- 160 161 void OutputDevice::DrawArc( const Rectangle& rRect, 162 const Point& rStartPt, const Point& rEndPt ) 163 { 164 DBG_TRACE( "OutputDevice::DrawArc()" ); 165 DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 166 167 if ( mpMetaFile ) 168 mpMetaFile->AddAction( new MetaArcAction( rRect, rStartPt, rEndPt ) ); 169 170 if ( !IsDeviceOutputNecessary() || !mbLineColor || ImplIsRecordLayout() ) 171 return; 172 173 Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 174 if ( aRect.IsEmpty() ) 175 return; 176 177 // we need a graphics 178 if ( !mpGraphics ) 179 { 180 if ( !ImplGetGraphics() ) 181 return; 182 } 183 184 if ( mbInitClipRegion ) 185 ImplInitClipRegion(); 186 if ( mbOutputClipped ) 187 return; 188 189 if ( mbInitLineColor ) 190 ImplInitLineColor(); 191 192 const Point aStart( ImplLogicToDevicePixel( rStartPt ) ); 193 const Point aEnd( ImplLogicToDevicePixel( rEndPt ) ); 194 Polygon aArcPoly( aRect, aStart, aEnd, POLY_ARC ); 195 196 if ( aArcPoly.GetSize() >= 2 ) 197 { 198 const SalPoint* pPtAry = (const SalPoint*)aArcPoly.GetConstPointAry(); 199 mpGraphics->DrawPolyLine( aArcPoly.GetSize(), pPtAry, this ); 200 } 201 202 if( mpAlphaVDev ) 203 mpAlphaVDev->DrawArc( rRect, rStartPt, rEndPt ); 204 } 205 206 // ----------------------------------------------------------------------- 207 208 void OutputDevice::DrawPie( const Rectangle& rRect, 209 const Point& rStartPt, const Point& rEndPt ) 210 { 211 DBG_TRACE( "OutputDevice::DrawPie()" ); 212 DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 213 214 if ( mpMetaFile ) 215 mpMetaFile->AddAction( new MetaPieAction( rRect, rStartPt, rEndPt ) ); 216 217 if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() ) 218 return; 219 220 Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 221 if ( aRect.IsEmpty() ) 222 return; 223 224 // we need a graphics 225 if ( !mpGraphics ) 226 { 227 if ( !ImplGetGraphics() ) 228 return; 229 } 230 231 if ( mbInitClipRegion ) 232 ImplInitClipRegion(); 233 if ( mbOutputClipped ) 234 return; 235 236 if ( mbInitLineColor ) 237 ImplInitLineColor(); 238 239 const Point aStart( ImplLogicToDevicePixel( rStartPt ) ); 240 const Point aEnd( ImplLogicToDevicePixel( rEndPt ) ); 241 Polygon aPiePoly( aRect, aStart, aEnd, POLY_PIE ); 242 243 if ( aPiePoly.GetSize() >= 2 ) 244 { 245 const SalPoint* pPtAry = (const SalPoint*)aPiePoly.GetConstPointAry(); 246 if ( !mbFillColor ) 247 mpGraphics->DrawPolyLine( aPiePoly.GetSize(), pPtAry, this ); 248 else 249 { 250 if ( mbInitFillColor ) 251 ImplInitFillColor(); 252 mpGraphics->DrawPolygon( aPiePoly.GetSize(), pPtAry, this ); 253 } 254 } 255 256 if( mpAlphaVDev ) 257 mpAlphaVDev->DrawPie( rRect, rStartPt, rEndPt ); 258 } 259 260 // ----------------------------------------------------------------------- 261 262 void OutputDevice::DrawChord( const Rectangle& rRect, 263 const Point& rStartPt, const Point& rEndPt ) 264 { 265 DBG_TRACE( "OutputDevice::DrawChord()" ); 266 DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 267 268 if ( mpMetaFile ) 269 mpMetaFile->AddAction( new MetaChordAction( rRect, rStartPt, rEndPt ) ); 270 271 if ( !IsDeviceOutputNecessary() || (!mbLineColor && !mbFillColor) || ImplIsRecordLayout() ) 272 return; 273 274 Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 275 if ( aRect.IsEmpty() ) 276 return; 277 278 // we need a graphics 279 if ( !mpGraphics ) 280 { 281 if ( !ImplGetGraphics() ) 282 return; 283 } 284 285 if ( mbInitClipRegion ) 286 ImplInitClipRegion(); 287 if ( mbOutputClipped ) 288 return; 289 290 if ( mbInitLineColor ) 291 ImplInitLineColor(); 292 293 const Point aStart( ImplLogicToDevicePixel( rStartPt ) ); 294 const Point aEnd( ImplLogicToDevicePixel( rEndPt ) ); 295 Polygon aChordPoly( aRect, aStart, aEnd, POLY_CHORD ); 296 297 if ( aChordPoly.GetSize() >= 2 ) 298 { 299 const SalPoint* pPtAry = (const SalPoint*)aChordPoly.GetConstPointAry(); 300 if ( !mbFillColor ) 301 mpGraphics->DrawPolyLine( aChordPoly.GetSize(), pPtAry, this ); 302 else 303 { 304 if ( mbInitFillColor ) 305 ImplInitFillColor(); 306 mpGraphics->DrawPolygon( aChordPoly.GetSize(), pPtAry, this ); 307 } 308 } 309 310 if( mpAlphaVDev ) 311 mpAlphaVDev->DrawChord( rRect, rStartPt, rEndPt ); 312 } 313