1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir #include <tools/line.hxx> 33*cdf0e10cSrcweir #include <tools/poly.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <vcl/gradient.hxx> 36*cdf0e10cSrcweir #include <vcl/metaact.hxx> 37*cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 38*cdf0e10cSrcweir #include <vcl/salbtype.hxx> 39*cdf0e10cSrcweir #include <vcl/hatch.hxx> 40*cdf0e10cSrcweir #include <vcl/window.hxx> 41*cdf0e10cSrcweir #include <vcl/virdev.hxx> 42*cdf0e10cSrcweir #include <vcl/outdev.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include "pdfwriter_impl.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include "window.h" 47*cdf0e10cSrcweir #include "salframe.hxx" 48*cdf0e10cSrcweir #include "salgdi.hxx" 49*cdf0e10cSrcweir #include "svdata.hxx" 50*cdf0e10cSrcweir #include "outdata.hxx" 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 53*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 54*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // ----------- 57*cdf0e10cSrcweir // - Defines - 58*cdf0e10cSrcweir // ----------- 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #define HATCH_MAXPOINTS 1024 61*cdf0e10cSrcweir #define GRADIENT_DEFAULT_STEPCOUNT 0 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // ---------------- 64*cdf0e10cSrcweir // - Cmp-Function - 65*cdf0e10cSrcweir // ---------------- 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir extern "C" int __LOADONCALLAPI ImplHatchCmpFnc( const void* p1, const void* p2 ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir const long nX1 = ( (Point*) p1 )->X(); 70*cdf0e10cSrcweir const long nX2 = ( (Point*) p2 )->X(); 71*cdf0e10cSrcweir const long nY1 = ( (Point*) p1 )->Y(); 72*cdf0e10cSrcweir const long nY2 = ( (Point*) p2 )->Y(); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir return ( nX1 > nX2 ? 1 : nX1 == nX2 ? nY1 > nY2 ? 1: nY1 == nY2 ? 0 : -1 : -1 ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // ======================================================================= 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir DBG_NAMEEX( OutputDevice ) 80*cdf0e10cSrcweir DBG_NAMEEX( Gradient ) 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // ======================================================================= 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir void OutputDevice::ImplDrawPolygon( const Polygon& rPoly, const PolyPolygon* pClipPolyPoly ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir if( pClipPolyPoly ) 87*cdf0e10cSrcweir ImplDrawPolyPolygon( rPoly, pClipPolyPoly ); 88*cdf0e10cSrcweir else 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir sal_uInt16 nPoints = rPoly.GetSize(); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir if ( nPoints < 2 ) 93*cdf0e10cSrcweir return; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir const SalPoint* pPtAry = (const SalPoint*)rPoly.GetConstPointAry(); 96*cdf0e10cSrcweir mpGraphics->DrawPolygon( nPoints, pPtAry, this ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // ----------------------------------------------------------------------- 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void OutputDevice::ImplDrawPolyPolygon( const PolyPolygon& rPolyPoly, const PolyPolygon* pClipPolyPoly ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir PolyPolygon* pPolyPoly; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir if( pClipPolyPoly ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir pPolyPoly = new PolyPolygon; 109*cdf0e10cSrcweir rPolyPoly.GetIntersection( *pClipPolyPoly, *pPolyPoly ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir else 112*cdf0e10cSrcweir pPolyPoly = (PolyPolygon*) &rPolyPoly; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir if( pPolyPoly->Count() == 1 ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir const Polygon rPoly = pPolyPoly->GetObject( 0 ); 117*cdf0e10cSrcweir sal_uInt16 nSize = rPoly.GetSize(); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if( nSize >= 2 ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir const SalPoint* pPtAry = (const SalPoint*)rPoly.GetConstPointAry(); 122*cdf0e10cSrcweir mpGraphics->DrawPolygon( nSize, pPtAry, this ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir else if( pPolyPoly->Count() ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir sal_uInt16 nCount = pPolyPoly->Count(); 128*cdf0e10cSrcweir sal_uInt32* pPointAry = new sal_uInt32[nCount]; 129*cdf0e10cSrcweir PCONSTSALPOINT* pPointAryAry = new PCONSTSALPOINT[nCount]; 130*cdf0e10cSrcweir sal_uInt16 i = 0; 131*cdf0e10cSrcweir do 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir const Polygon& rPoly = pPolyPoly->GetObject( i ); 134*cdf0e10cSrcweir sal_uInt16 nSize = rPoly.GetSize(); 135*cdf0e10cSrcweir if ( nSize ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir pPointAry[i] = nSize; 138*cdf0e10cSrcweir pPointAryAry[i] = (PCONSTSALPOINT)rPoly.GetConstPointAry(); 139*cdf0e10cSrcweir i++; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir else 142*cdf0e10cSrcweir nCount--; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir while( i < nCount ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if( nCount == 1 ) 147*cdf0e10cSrcweir mpGraphics->DrawPolygon( *pPointAry, *pPointAryAry, this ); 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir mpGraphics->DrawPolyPolygon( nCount, pPointAry, pPointAryAry, this ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir delete[] pPointAry; 152*cdf0e10cSrcweir delete[] pPointAryAry; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if( pClipPolyPoly ) 156*cdf0e10cSrcweir delete pPolyPoly; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // ----------------------------------------------------------------------- 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir inline sal_uInt8 ImplGetGradientColorValue( long nValue ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir if ( nValue < 0 ) 164*cdf0e10cSrcweir return 0; 165*cdf0e10cSrcweir else if ( nValue > 0xFF ) 166*cdf0e10cSrcweir return 0xFF; 167*cdf0e10cSrcweir else 168*cdf0e10cSrcweir return (sal_uInt8)nValue; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // ----------------------------------------------------------------------- 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir void OutputDevice::ImplDrawLinearGradient( const Rectangle& rRect, 174*cdf0e10cSrcweir const Gradient& rGradient, 175*cdf0e10cSrcweir sal_Bool bMtf, const PolyPolygon* pClipPolyPoly ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir // rotiertes BoundRect ausrechnen 178*cdf0e10cSrcweir Rectangle aRect = rRect; 179*cdf0e10cSrcweir aRect.Left()--; 180*cdf0e10cSrcweir aRect.Top()--; 181*cdf0e10cSrcweir aRect.Right()++; 182*cdf0e10cSrcweir aRect.Bottom()++; 183*cdf0e10cSrcweir sal_uInt16 nAngle = rGradient.GetAngle() % 3600; 184*cdf0e10cSrcweir double fAngle = nAngle * F_PI1800; 185*cdf0e10cSrcweir double fWidth = aRect.GetWidth(); 186*cdf0e10cSrcweir double fHeight = aRect.GetHeight(); 187*cdf0e10cSrcweir double fDX = fWidth * fabs( cos( fAngle ) ) + 188*cdf0e10cSrcweir fHeight * fabs( sin( fAngle ) ); 189*cdf0e10cSrcweir double fDY = fHeight * fabs( cos( fAngle ) ) + 190*cdf0e10cSrcweir fWidth * fabs( sin( fAngle ) ); 191*cdf0e10cSrcweir fDX = (fDX - fWidth) * 0.5 + 0.5; 192*cdf0e10cSrcweir fDY = (fDY - fHeight) * 0.5 + 0.5; 193*cdf0e10cSrcweir aRect.Left() -= (long)fDX; 194*cdf0e10cSrcweir aRect.Right() += (long)fDX; 195*cdf0e10cSrcweir aRect.Top() -= (long)fDY; 196*cdf0e10cSrcweir aRect.Bottom() += (long)fDY; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // Rand berechnen und Rechteck neu setzen 199*cdf0e10cSrcweir Point aCenter = rRect.Center(); 200*cdf0e10cSrcweir Rectangle aFullRect = aRect; 201*cdf0e10cSrcweir long nBorder = (long)rGradient.GetBorder() * aRect.GetHeight() / 100; 202*cdf0e10cSrcweir sal_Bool bLinear; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // Rand berechnen und Rechteck neu setzen fuer linearen Farbverlauf 205*cdf0e10cSrcweir if ( rGradient.GetStyle() == GRADIENT_LINEAR ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir bLinear = sal_True; 208*cdf0e10cSrcweir aRect.Top() += nBorder; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir // Rand berechnen und Rechteck neu setzen fuer axiale Farbverlauf 211*cdf0e10cSrcweir else 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir bLinear = sal_False; 214*cdf0e10cSrcweir nBorder >>= 1; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir aRect.Top() += nBorder; 217*cdf0e10cSrcweir aRect.Bottom() -= nBorder; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // Top darf nicht groesser als Bottom sein 221*cdf0e10cSrcweir aRect.Top() = Min( aRect.Top(), (long)(aRect.Bottom() - 1) ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir long nMinRect = aRect.GetHeight(); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // Intensitaeten von Start- und Endfarbe ggf. aendern und 226*cdf0e10cSrcweir // Farbschrittweiten berechnen 227*cdf0e10cSrcweir long nFactor; 228*cdf0e10cSrcweir Color aStartCol = rGradient.GetStartColor(); 229*cdf0e10cSrcweir Color aEndCol = rGradient.GetEndColor(); 230*cdf0e10cSrcweir long nStartRed = aStartCol.GetRed(); 231*cdf0e10cSrcweir long nStartGreen = aStartCol.GetGreen(); 232*cdf0e10cSrcweir long nStartBlue = aStartCol.GetBlue(); 233*cdf0e10cSrcweir long nEndRed = aEndCol.GetRed(); 234*cdf0e10cSrcweir long nEndGreen = aEndCol.GetGreen(); 235*cdf0e10cSrcweir long nEndBlue = aEndCol.GetBlue(); 236*cdf0e10cSrcweir nFactor = rGradient.GetStartIntensity(); 237*cdf0e10cSrcweir nStartRed = (nStartRed * nFactor) / 100; 238*cdf0e10cSrcweir nStartGreen = (nStartGreen * nFactor) / 100; 239*cdf0e10cSrcweir nStartBlue = (nStartBlue * nFactor) / 100; 240*cdf0e10cSrcweir nFactor = rGradient.GetEndIntensity(); 241*cdf0e10cSrcweir nEndRed = (nEndRed * nFactor) / 100; 242*cdf0e10cSrcweir nEndGreen = (nEndGreen * nFactor) / 100; 243*cdf0e10cSrcweir nEndBlue = (nEndBlue * nFactor) / 100; 244*cdf0e10cSrcweir long nRedSteps = nEndRed - nStartRed; 245*cdf0e10cSrcweir long nGreenSteps = nEndGreen - nStartGreen; 246*cdf0e10cSrcweir long nBlueSteps = nEndBlue - nStartBlue; 247*cdf0e10cSrcweir long nStepCount = rGradient.GetSteps(); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // Bei nicht linearen Farbverlaeufen haben wir nur die halben Steps 250*cdf0e10cSrcweir // pro Farbe 251*cdf0e10cSrcweir if ( !bLinear ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir nRedSteps <<= 1; 254*cdf0e10cSrcweir nGreenSteps <<= 1; 255*cdf0e10cSrcweir nBlueSteps <<= 1; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // Anzahl der Schritte berechnen, falls nichts uebergeben wurde 259*cdf0e10cSrcweir if ( !nStepCount ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir long nInc; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir if ( meOutDevType != OUTDEV_PRINTER && !bMtf ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir nInc = (nMinRect < 50) ? 2 : 4; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir else 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir // #105998# Use display-equivalent step size calculation 270*cdf0e10cSrcweir nInc = (nMinRect < 800) ? 10 : 20; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir if ( !nInc ) 274*cdf0e10cSrcweir nInc = 1; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir nStepCount = nMinRect / nInc; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir // minimal drei Schritte und maximal die Anzahl der Farbunterschiede 279*cdf0e10cSrcweir long nSteps = Max( nStepCount, 2L ); 280*cdf0e10cSrcweir long nCalcSteps = Abs( nRedSteps ); 281*cdf0e10cSrcweir long nTempSteps = Abs( nGreenSteps ); 282*cdf0e10cSrcweir if ( nTempSteps > nCalcSteps ) 283*cdf0e10cSrcweir nCalcSteps = nTempSteps; 284*cdf0e10cSrcweir nTempSteps = Abs( nBlueSteps ); 285*cdf0e10cSrcweir if ( nTempSteps > nCalcSteps ) 286*cdf0e10cSrcweir nCalcSteps = nTempSteps; 287*cdf0e10cSrcweir if ( nCalcSteps < nSteps ) 288*cdf0e10cSrcweir nSteps = nCalcSteps; 289*cdf0e10cSrcweir if ( !nSteps ) 290*cdf0e10cSrcweir nSteps = 1; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir // Falls axialer Farbverlauf, muss die Schrittanzahl ungerade sein 293*cdf0e10cSrcweir if ( !bLinear && !(nSteps & 1) ) 294*cdf0e10cSrcweir nSteps++; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir // Berechnung ueber Double-Addition wegen Genauigkeit 297*cdf0e10cSrcweir double fScanLine = aRect.Top(); 298*cdf0e10cSrcweir double fScanInc = (double)aRect.GetHeight() / (double)nSteps; 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir // Startfarbe berechnen und setzen 301*cdf0e10cSrcweir sal_uInt8 nRed; 302*cdf0e10cSrcweir sal_uInt8 nGreen; 303*cdf0e10cSrcweir sal_uInt8 nBlue; 304*cdf0e10cSrcweir long nSteps2; 305*cdf0e10cSrcweir long nStepsHalf = 0; 306*cdf0e10cSrcweir if ( bLinear ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir // Um 1 erhoeht, um die Border innerhalb der Schleife 309*cdf0e10cSrcweir // zeichnen zu koennen 310*cdf0e10cSrcweir nSteps2 = nSteps + 1; 311*cdf0e10cSrcweir nRed = (sal_uInt8)nStartRed; 312*cdf0e10cSrcweir nGreen = (sal_uInt8)nStartGreen; 313*cdf0e10cSrcweir nBlue = (sal_uInt8)nStartBlue; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir else 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir // Um 2 erhoeht, um die Border innerhalb der Schleife 318*cdf0e10cSrcweir // zeichnen zu koennen 319*cdf0e10cSrcweir nSteps2 = nSteps + 2; 320*cdf0e10cSrcweir nRed = (sal_uInt8)nEndRed; 321*cdf0e10cSrcweir nGreen = (sal_uInt8)nEndGreen; 322*cdf0e10cSrcweir nBlue = (sal_uInt8)nEndBlue; 323*cdf0e10cSrcweir nStepsHalf = nSteps >> 1; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir if ( bMtf ) 327*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 328*cdf0e10cSrcweir else 329*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir // Startpolygon erzeugen (== Borderpolygon) 332*cdf0e10cSrcweir Polygon aPoly( 4 ); 333*cdf0e10cSrcweir Polygon aTempPoly( 2 ); 334*cdf0e10cSrcweir aPoly[0] = aFullRect.TopLeft(); 335*cdf0e10cSrcweir aPoly[1] = aFullRect.TopRight(); 336*cdf0e10cSrcweir aPoly[2] = aRect.TopRight(); 337*cdf0e10cSrcweir aPoly[3] = aRect.TopLeft(); 338*cdf0e10cSrcweir aPoly.Rotate( aCenter, nAngle ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // Schleife, um rotierten Verlauf zu fuellen 341*cdf0e10cSrcweir for ( long i = 0; i < nSteps2; i++ ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir // berechnetesPolygon ausgeben 344*cdf0e10cSrcweir if ( bMtf ) 345*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPolygonAction( aPoly ) ); 346*cdf0e10cSrcweir else 347*cdf0e10cSrcweir ImplDrawPolygon( aPoly, pClipPolyPoly ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir // neues Polygon berechnen 350*cdf0e10cSrcweir aRect.Top() = (long)(fScanLine += fScanInc); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // unteren Rand komplett fuellen 353*cdf0e10cSrcweir if ( i == nSteps ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir aTempPoly[0] = aFullRect.BottomLeft(); 356*cdf0e10cSrcweir aTempPoly[1] = aFullRect.BottomRight(); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir else 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir aTempPoly[0] = aRect.TopLeft(); 361*cdf0e10cSrcweir aTempPoly[1] = aRect.TopRight(); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir aTempPoly.Rotate( aCenter, nAngle ); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir aPoly[0] = aPoly[3]; 366*cdf0e10cSrcweir aPoly[1] = aPoly[2]; 367*cdf0e10cSrcweir aPoly[2] = aTempPoly[1]; 368*cdf0e10cSrcweir aPoly[3] = aTempPoly[0]; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir // Farbintensitaeten aendern... 371*cdf0e10cSrcweir // fuer lineare FV 372*cdf0e10cSrcweir if ( bLinear ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir nRed = ImplGetGradientColorValue( nStartRed+((nRedSteps*i)/nSteps2) ); 375*cdf0e10cSrcweir nGreen = ImplGetGradientColorValue( nStartGreen+((nGreenSteps*i)/nSteps2) ); 376*cdf0e10cSrcweir nBlue = ImplGetGradientColorValue( nStartBlue+((nBlueSteps*i)/nSteps2) ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir // fuer radiale FV 379*cdf0e10cSrcweir else 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir // fuer axiale FV muss die letzte Farbe der ersten 382*cdf0e10cSrcweir // Farbe entsprechen 383*cdf0e10cSrcweir // #107350# Setting end color one step earlier, as the 384*cdf0e10cSrcweir // last time we get here, we drop out of the loop later 385*cdf0e10cSrcweir // on. 386*cdf0e10cSrcweir if ( i >= nSteps ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir nRed = (sal_uInt8)nEndRed; 389*cdf0e10cSrcweir nGreen = (sal_uInt8)nEndGreen; 390*cdf0e10cSrcweir nBlue = (sal_uInt8)nEndBlue; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir else 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir if ( i <= nStepsHalf ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir nRed = ImplGetGradientColorValue( nEndRed-((nRedSteps*i)/nSteps2) ); 397*cdf0e10cSrcweir nGreen = ImplGetGradientColorValue( nEndGreen-((nGreenSteps*i)/nSteps2) ); 398*cdf0e10cSrcweir nBlue = ImplGetGradientColorValue( nEndBlue-((nBlueSteps*i)/nSteps2) ); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir // genau die Mitte und hoeher 401*cdf0e10cSrcweir else 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir long i2 = i - nStepsHalf; 404*cdf0e10cSrcweir nRed = ImplGetGradientColorValue( nStartRed+((nRedSteps*i2)/nSteps2) ); 405*cdf0e10cSrcweir nGreen = ImplGetGradientColorValue( nStartGreen+((nGreenSteps*i2)/nSteps2) ); 406*cdf0e10cSrcweir nBlue = ImplGetGradientColorValue( nStartBlue+((nBlueSteps*i2)/nSteps2) ); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir if ( bMtf ) 412*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 413*cdf0e10cSrcweir else 414*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir // ----------------------------------------------------------------------- 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect, 421*cdf0e10cSrcweir const Gradient& rGradient, 422*cdf0e10cSrcweir sal_Bool bMtf, const PolyPolygon* pClipPolyPoly ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir // Feststellen ob Ausgabe ueber Polygon oder PolyPolygon 425*cdf0e10cSrcweir // Bei Rasteroperationen ungleich Overpaint immer PolyPolygone, 426*cdf0e10cSrcweir // da es zu falschen Ergebnissen kommt, wenn man mehrfach uebereinander 427*cdf0e10cSrcweir // ausgibt 428*cdf0e10cSrcweir // Bei Druckern auch immer PolyPolygone, da nicht alle Drucker 429*cdf0e10cSrcweir // das Uebereinanderdrucken von Polygonen koennen 430*cdf0e10cSrcweir // Virtuelle Device werden auch ausgeklammert, da einige Treiber 431*cdf0e10cSrcweir // ansonsten zu langsam sind 432*cdf0e10cSrcweir PolyPolygon* pPolyPoly; 433*cdf0e10cSrcweir Rectangle aRect( rRect ); 434*cdf0e10cSrcweir Color aStartCol( rGradient.GetStartColor() ); 435*cdf0e10cSrcweir Color aEndCol( rGradient.GetEndColor() ); 436*cdf0e10cSrcweir long nStartRed = ( (long) aStartCol.GetRed() * rGradient.GetStartIntensity() ) / 100; 437*cdf0e10cSrcweir long nStartGreen = ( (long) aStartCol.GetGreen() * rGradient.GetStartIntensity() ) / 100; 438*cdf0e10cSrcweir long nStartBlue = ( (long) aStartCol.GetBlue() * rGradient.GetStartIntensity() ) / 100; 439*cdf0e10cSrcweir long nEndRed = ( (long) aEndCol.GetRed() * rGradient.GetEndIntensity() ) / 100; 440*cdf0e10cSrcweir long nEndGreen = ( (long) aEndCol.GetGreen() * rGradient.GetEndIntensity() ) / 100; 441*cdf0e10cSrcweir long nEndBlue = ( (long) aEndCol.GetBlue() * rGradient.GetEndIntensity() ) / 100; 442*cdf0e10cSrcweir long nRedSteps = nEndRed - nStartRed; 443*cdf0e10cSrcweir long nGreenSteps = nEndGreen - nStartGreen; 444*cdf0e10cSrcweir long nBlueSteps = nEndBlue - nStartBlue; 445*cdf0e10cSrcweir long nStepCount = rGradient.GetSteps(); 446*cdf0e10cSrcweir sal_uInt16 nAngle = rGradient.GetAngle() % 3600; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir if( (meRasterOp != ROP_OVERPAINT) || (meOutDevType != OUTDEV_WINDOW) || bMtf ) 449*cdf0e10cSrcweir pPolyPoly = new PolyPolygon( 2 ); 450*cdf0e10cSrcweir else 451*cdf0e10cSrcweir pPolyPoly = NULL; 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir if( rGradient.GetStyle() == GRADIENT_SQUARE || rGradient.GetStyle() == GRADIENT_RECT ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir const double fAngle = nAngle * F_PI1800; 456*cdf0e10cSrcweir const double fWidth = aRect.GetWidth(); 457*cdf0e10cSrcweir const double fHeight = aRect.GetHeight(); 458*cdf0e10cSrcweir double fDX = fWidth * fabs( cos( fAngle ) ) + fHeight * fabs( sin( fAngle ) ); 459*cdf0e10cSrcweir double fDY = fHeight * fabs( cos( fAngle ) ) + fWidth * fabs( sin( fAngle ) ); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir fDX = ( fDX - fWidth ) * 0.5 + 0.5; 462*cdf0e10cSrcweir fDY = ( fDY - fHeight ) * 0.5 + 0.5; 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir aRect.Left() -= (long) fDX; 465*cdf0e10cSrcweir aRect.Right() += (long) fDX; 466*cdf0e10cSrcweir aRect.Top() -= (long) fDY; 467*cdf0e10cSrcweir aRect.Bottom() += (long) fDY; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir Size aSize( aRect.GetSize() ); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir if( rGradient.GetStyle() == GRADIENT_RADIAL ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir // Radien-Berechnung fuer Kreis 475*cdf0e10cSrcweir aSize.Width() = (long)(0.5 + sqrt((double)aSize.Width()*(double)aSize.Width() + (double)aSize.Height()*(double)aSize.Height())); 476*cdf0e10cSrcweir aSize.Height() = aSize.Width(); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir else if( rGradient.GetStyle() == GRADIENT_ELLIPTICAL ) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir // Radien-Berechnung fuer Ellipse 481*cdf0e10cSrcweir aSize.Width() = (long)( 0.5 + (double) aSize.Width() * 1.4142 ); 482*cdf0e10cSrcweir aSize.Height() = (long)( 0.5 + (double) aSize.Height() * 1.4142 ); 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir else if( rGradient.GetStyle() == GRADIENT_SQUARE ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir if ( aSize.Width() > aSize.Height() ) 487*cdf0e10cSrcweir aSize.Height() = aSize.Width(); 488*cdf0e10cSrcweir else 489*cdf0e10cSrcweir aSize.Width() = aSize.Height(); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir // neue Mittelpunkte berechnen 493*cdf0e10cSrcweir long nZWidth = aRect.GetWidth() * (long) rGradient.GetOfsX() / 100; 494*cdf0e10cSrcweir long nZHeight = aRect.GetHeight() * (long) rGradient.GetOfsY() / 100; 495*cdf0e10cSrcweir long nBorderX = (long) rGradient.GetBorder() * aSize.Width() / 100; 496*cdf0e10cSrcweir long nBorderY = (long) rGradient.GetBorder() * aSize.Height() / 100; 497*cdf0e10cSrcweir Point aCenter( aRect.Left() + nZWidth, aRect.Top() + nZHeight ); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir // Rand beruecksichtigen 500*cdf0e10cSrcweir aSize.Width() -= nBorderX; 501*cdf0e10cSrcweir aSize.Height() -= nBorderY; 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir // Ausgaberechteck neu setzen 504*cdf0e10cSrcweir aRect.Left() = aCenter.X() - ( aSize.Width() >> 1 ); 505*cdf0e10cSrcweir aRect.Top() = aCenter.Y() - ( aSize.Height() >> 1 ); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir aRect.SetSize( aSize ); 508*cdf0e10cSrcweir long nMinRect = Min( aRect.GetWidth(), aRect.GetHeight() ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // Anzahl der Schritte berechnen, falls nichts uebergeben wurde 511*cdf0e10cSrcweir if( !nStepCount ) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir long nInc; 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir if ( meOutDevType != OUTDEV_PRINTER && !bMtf ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir nInc = ( nMinRect < 50 ) ? 2 : 4; 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir else 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir // #105998# Use display-equivalent step size calculation 522*cdf0e10cSrcweir nInc = (nMinRect < 800) ? 10 : 20; 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir if( !nInc ) 526*cdf0e10cSrcweir nInc = 1; 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir nStepCount = nMinRect / nInc; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // minimal drei Schritte und maximal die Anzahl der Farbunterschiede 532*cdf0e10cSrcweir long nSteps = Max( nStepCount, 2L ); 533*cdf0e10cSrcweir long nCalcSteps = Abs( nRedSteps ); 534*cdf0e10cSrcweir long nTempSteps = Abs( nGreenSteps ); 535*cdf0e10cSrcweir if ( nTempSteps > nCalcSteps ) 536*cdf0e10cSrcweir nCalcSteps = nTempSteps; 537*cdf0e10cSrcweir nTempSteps = Abs( nBlueSteps ); 538*cdf0e10cSrcweir if ( nTempSteps > nCalcSteps ) 539*cdf0e10cSrcweir nCalcSteps = nTempSteps; 540*cdf0e10cSrcweir if ( nCalcSteps < nSteps ) 541*cdf0e10cSrcweir nSteps = nCalcSteps; 542*cdf0e10cSrcweir if ( !nSteps ) 543*cdf0e10cSrcweir nSteps = 1; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir // Ausgabebegrenzungen und Schrittweite fuer jede Richtung festlegen 546*cdf0e10cSrcweir Polygon aPoly; 547*cdf0e10cSrcweir double fScanLeft = aRect.Left(); 548*cdf0e10cSrcweir double fScanTop = aRect.Top(); 549*cdf0e10cSrcweir double fScanRight = aRect.Right(); 550*cdf0e10cSrcweir double fScanBottom = aRect.Bottom(); 551*cdf0e10cSrcweir double fScanInc = (double) nMinRect / (double) nSteps * 0.5; 552*cdf0e10cSrcweir sal_uInt8 nRed = (sal_uInt8) nStartRed, nGreen = (sal_uInt8) nStartGreen, nBlue = (sal_uInt8) nStartBlue; 553*cdf0e10cSrcweir bool bPaintLastPolygon( false ); // #107349# Paint last polygon only if loop has generated any output 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir if( bMtf ) 556*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 557*cdf0e10cSrcweir else 558*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir if( pPolyPoly ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir pPolyPoly->Insert( aPoly = rRect ); 563*cdf0e10cSrcweir pPolyPoly->Insert( aPoly ); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir else 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir // extend rect, to avoid missing bounding line 568*cdf0e10cSrcweir Rectangle aExtRect( rRect ); 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir aExtRect.Left() -= 1; 571*cdf0e10cSrcweir aExtRect.Top() -= 1; 572*cdf0e10cSrcweir aExtRect.Right() += 1; 573*cdf0e10cSrcweir aExtRect.Bottom() += 1; 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir ImplDrawPolygon( aPoly = aExtRect, pClipPolyPoly ); 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir // Schleife, um nacheinander die Polygone/PolyPolygone auszugeben 579*cdf0e10cSrcweir for( long i = 1; i < nSteps; i++ ) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir // neues Polygon berechnen 582*cdf0e10cSrcweir aRect.Left() = (long)( fScanLeft += fScanInc ); 583*cdf0e10cSrcweir aRect.Top() = (long)( fScanTop += fScanInc ); 584*cdf0e10cSrcweir aRect.Right() = (long)( fScanRight -= fScanInc ); 585*cdf0e10cSrcweir aRect.Bottom() = (long)( fScanBottom -= fScanInc ); 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir if( ( aRect.GetWidth() < 2 ) || ( aRect.GetHeight() < 2 ) ) 588*cdf0e10cSrcweir break; 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir if( rGradient.GetStyle() == GRADIENT_RADIAL || rGradient.GetStyle() == GRADIENT_ELLIPTICAL ) 591*cdf0e10cSrcweir aPoly = Polygon( aRect.Center(), aRect.GetWidth() >> 1, aRect.GetHeight() >> 1 ); 592*cdf0e10cSrcweir else 593*cdf0e10cSrcweir aPoly = Polygon( aRect ); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir aPoly.Rotate( aCenter, nAngle ); 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir // Farbe entsprechend anpassen 598*cdf0e10cSrcweir const long nStepIndex = ( ( pPolyPoly != NULL ) ? i : ( i + 1 ) ); 599*cdf0e10cSrcweir nRed = ImplGetGradientColorValue( nStartRed + ( ( nRedSteps * nStepIndex ) / nSteps ) ); 600*cdf0e10cSrcweir nGreen = ImplGetGradientColorValue( nStartGreen + ( ( nGreenSteps * nStepIndex ) / nSteps ) ); 601*cdf0e10cSrcweir nBlue = ImplGetGradientColorValue( nStartBlue + ( ( nBlueSteps * nStepIndex ) / nSteps ) ); 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir // entweder langsame PolyPolygon-Ausgaben oder schnelles Polygon-Painting 604*cdf0e10cSrcweir if( pPolyPoly ) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir bPaintLastPolygon = true; // #107349# Paint last polygon only if loop has generated any output 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir pPolyPoly->Replace( pPolyPoly->GetObject( 1 ), 0 ); 609*cdf0e10cSrcweir pPolyPoly->Replace( aPoly, 1 ); 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir if( bMtf ) 612*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPolyPolygonAction( *pPolyPoly ) ); 613*cdf0e10cSrcweir else 614*cdf0e10cSrcweir ImplDrawPolyPolygon( *pPolyPoly, pClipPolyPoly ); 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir // #107349# Set fill color _after_ geometry painting: 617*cdf0e10cSrcweir // pPolyPoly's geometry is the band from last iteration's 618*cdf0e10cSrcweir // aPoly to current iteration's aPoly. The window outdev 619*cdf0e10cSrcweir // path (see else below), on the other hand, paints the 620*cdf0e10cSrcweir // full aPoly. Thus, here, we're painting the band before 621*cdf0e10cSrcweir // the one painted in the window outdev path below. To get 622*cdf0e10cSrcweir // matching colors, have to delay color setting here. 623*cdf0e10cSrcweir if( bMtf ) 624*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 625*cdf0e10cSrcweir else 626*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir else 629*cdf0e10cSrcweir { 630*cdf0e10cSrcweir // #107349# Set fill color _before_ geometry painting 631*cdf0e10cSrcweir if( bMtf ) 632*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 633*cdf0e10cSrcweir else 634*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir ImplDrawPolygon( aPoly, pClipPolyPoly ); 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir // Falls PolyPolygon-Ausgabe, muessen wir noch ein letztes inneres Polygon zeichnen 641*cdf0e10cSrcweir if( pPolyPoly ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir const Polygon& rPoly = pPolyPoly->GetObject( 1 ); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir if( !rPoly.GetBoundRect().IsEmpty() ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir // #107349# Paint last polygon with end color only if loop 648*cdf0e10cSrcweir // has generated output. Otherwise, the current 649*cdf0e10cSrcweir // (i.e. start) color is taken, to generate _any_ output. 650*cdf0e10cSrcweir if( bPaintLastPolygon ) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir nRed = ImplGetGradientColorValue( nEndRed ); 653*cdf0e10cSrcweir nGreen = ImplGetGradientColorValue( nEndGreen ); 654*cdf0e10cSrcweir nBlue = ImplGetGradientColorValue( nEndBlue ); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir if( bMtf ) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaFillColorAction( Color( nRed, nGreen, nBlue ), sal_True ) ); 660*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPolygonAction( rPoly ) ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir else 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir mpGraphics->SetFillColor( MAKE_SALCOLOR( nRed, nGreen, nBlue ) ); 665*cdf0e10cSrcweir ImplDrawPolygon( rPoly, pClipPolyPoly ); 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir delete pPolyPoly; 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir // ----------------------------------------------------------------------- 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir void OutputDevice::DrawGradient( const Rectangle& rRect, 676*cdf0e10cSrcweir const Gradient& rGradient ) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir DBG_TRACE( "OutputDevice::DrawGradient()" ); 679*cdf0e10cSrcweir DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 680*cdf0e10cSrcweir DBG_CHKOBJ( &rGradient, Gradient, NULL ); 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_NOGRADIENT ) 683*cdf0e10cSrcweir return; 684*cdf0e10cSrcweir else if ( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) ) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir Color aColor; 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_BLACKGRADIENT ) 689*cdf0e10cSrcweir aColor = Color( COL_BLACK ); 690*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_WHITEGRADIENT ) 691*cdf0e10cSrcweir aColor = Color( COL_WHITE ); 692*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_SETTINGSGRADIENT ) 693*cdf0e10cSrcweir aColor = GetSettings().GetStyleSettings().GetWindowColor(); 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT ) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80, 698*cdf0e10cSrcweir ( aColor.GetGreen() >> 1 ) | 0x80, 699*cdf0e10cSrcweir ( aColor.GetBlue() >> 1 ) | 0x80 ); 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir Push( PUSH_LINECOLOR | PUSH_FILLCOLOR ); 703*cdf0e10cSrcweir SetLineColor( aColor ); 704*cdf0e10cSrcweir SetFillColor( aColor ); 705*cdf0e10cSrcweir DrawRect( rRect ); 706*cdf0e10cSrcweir Pop(); 707*cdf0e10cSrcweir return; 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir Gradient aGradient( rGradient ); 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir if ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir Color aStartCol( aGradient.GetStartColor() ); 715*cdf0e10cSrcweir Color aEndCol( aGradient.GetEndColor() ); 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GRAYGRADIENT ) 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir sal_uInt8 cStartLum = aStartCol.GetLuminance(), cEndLum = aEndCol.GetLuminance(); 720*cdf0e10cSrcweir aStartCol = Color( cStartLum, cStartLum, cStartLum ); 721*cdf0e10cSrcweir aEndCol = Color( cEndLum, cEndLum, cEndLum ); 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT ) 725*cdf0e10cSrcweir { 726*cdf0e10cSrcweir aStartCol = Color( ( aStartCol.GetRed() >> 1 ) | 0x80, 727*cdf0e10cSrcweir ( aStartCol.GetGreen() >> 1 ) | 0x80, 728*cdf0e10cSrcweir ( aStartCol.GetBlue() >> 1 ) | 0x80 ); 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir aEndCol = Color( ( aEndCol.GetRed() >> 1 ) | 0x80, 731*cdf0e10cSrcweir ( aEndCol.GetGreen() >> 1 ) | 0x80, 732*cdf0e10cSrcweir ( aEndCol.GetBlue() >> 1 ) | 0x80 ); 733*cdf0e10cSrcweir } 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir aGradient.SetStartColor( aStartCol ); 736*cdf0e10cSrcweir aGradient.SetEndColor( aEndCol ); 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir if( mpMetaFile ) 740*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaGradientAction( rRect, aGradient ) ); 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) 743*cdf0e10cSrcweir return; 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir // Rechteck in Pixel umrechnen 746*cdf0e10cSrcweir Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); 747*cdf0e10cSrcweir aRect.Justify(); 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir // Wenn Rechteck leer ist, brauchen wir nichts machen 750*cdf0e10cSrcweir if ( !aRect.IsEmpty() ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir // Clip Region sichern 753*cdf0e10cSrcweir Push( PUSH_CLIPREGION ); 754*cdf0e10cSrcweir IntersectClipRegion( rRect ); 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir // because we draw with no border line, we have to expand gradient 757*cdf0e10cSrcweir // rect to avoid missing lines on the right and bottom edge 758*cdf0e10cSrcweir aRect.Left()--; 759*cdf0e10cSrcweir aRect.Top()--; 760*cdf0e10cSrcweir aRect.Right()++; 761*cdf0e10cSrcweir aRect.Bottom()++; 762*cdf0e10cSrcweir 763*cdf0e10cSrcweir // we need a graphics 764*cdf0e10cSrcweir if ( !mpGraphics ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir if ( !ImplGetGraphics() ) 767*cdf0e10cSrcweir return; 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir 770*cdf0e10cSrcweir if ( mbInitClipRegion ) 771*cdf0e10cSrcweir ImplInitClipRegion(); 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir if ( !mbOutputClipped ) 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir // Gradienten werden ohne Umrandung gezeichnet 776*cdf0e10cSrcweir if ( mbLineColor || mbInitLineColor ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir mpGraphics->SetLineColor(); 779*cdf0e10cSrcweir mbInitLineColor = sal_True; 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir mbInitFillColor = sal_True; 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir // calculate step count if neccessary 785*cdf0e10cSrcweir if ( !aGradient.GetSteps() ) 786*cdf0e10cSrcweir aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir if( aGradient.GetStyle() == GRADIENT_LINEAR || aGradient.GetStyle() == GRADIENT_AXIAL ) 789*cdf0e10cSrcweir ImplDrawLinearGradient( aRect, aGradient, sal_False, NULL ); 790*cdf0e10cSrcweir else 791*cdf0e10cSrcweir ImplDrawComplexGradient( aRect, aGradient, sal_False, NULL ); 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir Pop(); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir if( mpAlphaVDev ) 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir // #i32109#: Make gradient area opaque 800*cdf0e10cSrcweir mpAlphaVDev->ImplFillOpaqueRectangle( rRect ); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir // ----------------------------------------------------------------------- 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir void OutputDevice::DrawGradient( const PolyPolygon& rPolyPoly, 807*cdf0e10cSrcweir const Gradient& rGradient ) 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir DBG_TRACE( "OutputDevice::DrawGradient()" ); 810*cdf0e10cSrcweir DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 811*cdf0e10cSrcweir DBG_CHKOBJ( &rGradient, Gradient, NULL ); 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir if( mbInitClipRegion ) 814*cdf0e10cSrcweir ImplInitClipRegion(); 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir if( mbOutputClipped ) 817*cdf0e10cSrcweir return; 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir if( !mpGraphics ) 820*cdf0e10cSrcweir if( !ImplGetGraphics() ) 821*cdf0e10cSrcweir return; 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir if( rPolyPoly.Count() && rPolyPoly[ 0 ].GetSize() && !( mnDrawMode & DRAWMODE_NOGRADIENT ) ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir if ( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) ) 826*cdf0e10cSrcweir { 827*cdf0e10cSrcweir Color aColor; 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_BLACKGRADIENT ) 830*cdf0e10cSrcweir aColor = Color( COL_BLACK ); 831*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_WHITEGRADIENT ) 832*cdf0e10cSrcweir aColor = Color( COL_WHITE ); 833*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_SETTINGSGRADIENT ) 834*cdf0e10cSrcweir aColor = GetSettings().GetStyleSettings().GetWindowColor(); 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT ) 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80, 839*cdf0e10cSrcweir ( aColor.GetGreen() >> 1 ) | 0x80, 840*cdf0e10cSrcweir ( aColor.GetBlue() >> 1 ) | 0x80 ); 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir Push( PUSH_LINECOLOR | PUSH_FILLCOLOR ); 844*cdf0e10cSrcweir SetLineColor( aColor ); 845*cdf0e10cSrcweir SetFillColor( aColor ); 846*cdf0e10cSrcweir DrawPolyPolygon( rPolyPoly ); 847*cdf0e10cSrcweir Pop(); 848*cdf0e10cSrcweir return; 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir if( mpMetaFile ) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir const Rectangle aRect( rPolyPoly.GetBoundRect() ); 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaCommentAction( "XGRAD_SEQ_BEGIN" ) ); 856*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaGradientExAction( rPolyPoly, rGradient ) ); 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir if( OUTDEV_PRINTER == meOutDevType ) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir Push( PUSH_CLIPREGION ); 861*cdf0e10cSrcweir IntersectClipRegion( rPolyPoly ); 862*cdf0e10cSrcweir DrawGradient( aRect, rGradient ); 863*cdf0e10cSrcweir Pop(); 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir else 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir const sal_Bool bOldOutput = IsOutputEnabled(); 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir EnableOutput( sal_False ); 870*cdf0e10cSrcweir Push( PUSH_RASTEROP ); 871*cdf0e10cSrcweir SetRasterOp( ROP_XOR ); 872*cdf0e10cSrcweir DrawGradient( aRect, rGradient ); 873*cdf0e10cSrcweir SetFillColor( COL_BLACK ); 874*cdf0e10cSrcweir SetRasterOp( ROP_0 ); 875*cdf0e10cSrcweir DrawPolyPolygon( rPolyPoly ); 876*cdf0e10cSrcweir SetRasterOp( ROP_XOR ); 877*cdf0e10cSrcweir DrawGradient( aRect, rGradient ); 878*cdf0e10cSrcweir Pop(); 879*cdf0e10cSrcweir EnableOutput( bOldOutput ); 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaCommentAction( "XGRAD_SEQ_END" ) ); 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) 886*cdf0e10cSrcweir return; 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir Gradient aGradient( rGradient ); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir if ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir Color aStartCol( aGradient.GetStartColor() ); 893*cdf0e10cSrcweir Color aEndCol( aGradient.GetEndColor() ); 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GRAYGRADIENT ) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir sal_uInt8 cStartLum = aStartCol.GetLuminance(), cEndLum = aEndCol.GetLuminance(); 898*cdf0e10cSrcweir aStartCol = Color( cStartLum, cStartLum, cStartLum ); 899*cdf0e10cSrcweir aEndCol = Color( cEndLum, cEndLum, cEndLum ); 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GHOSTEDGRADIENT ) 903*cdf0e10cSrcweir { 904*cdf0e10cSrcweir aStartCol = Color( ( aStartCol.GetRed() >> 1 ) | 0x80, 905*cdf0e10cSrcweir ( aStartCol.GetGreen() >> 1 ) | 0x80, 906*cdf0e10cSrcweir ( aStartCol.GetBlue() >> 1 ) | 0x80 ); 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir aEndCol = Color( ( aEndCol.GetRed() >> 1 ) | 0x80, 909*cdf0e10cSrcweir ( aEndCol.GetGreen() >> 1 ) | 0x80, 910*cdf0e10cSrcweir ( aEndCol.GetBlue() >> 1 ) | 0x80 ); 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir aGradient.SetStartColor( aStartCol ); 914*cdf0e10cSrcweir aGradient.SetEndColor( aEndCol ); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir if( OUTDEV_PRINTER == meOutDevType || ImplGetSVData()->maGDIData.mbNoXORClipping ) 918*cdf0e10cSrcweir { 919*cdf0e10cSrcweir const Rectangle aBoundRect( rPolyPoly.GetBoundRect() ); 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir if( !Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) 922*cdf0e10cSrcweir { 923*cdf0e10cSrcweir // Rechteck in Pixel umrechnen 924*cdf0e10cSrcweir Rectangle aRect( ImplLogicToDevicePixel( aBoundRect ) ); 925*cdf0e10cSrcweir aRect.Justify(); 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir // Wenn Rechteck leer ist, brauchen wir nichts machen 928*cdf0e10cSrcweir if ( !aRect.IsEmpty() ) 929*cdf0e10cSrcweir { 930*cdf0e10cSrcweir if( !mpGraphics && !ImplGetGraphics() ) 931*cdf0e10cSrcweir return; 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir if( mbInitClipRegion ) 934*cdf0e10cSrcweir ImplInitClipRegion(); 935*cdf0e10cSrcweir 936*cdf0e10cSrcweir if( !mbOutputClipped ) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir PolyPolygon aClipPolyPoly( ImplLogicToDevicePixel( rPolyPoly ) ); 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir // Gradienten werden ohne Umrandung gezeichnet 941*cdf0e10cSrcweir if( mbLineColor || mbInitLineColor ) 942*cdf0e10cSrcweir { 943*cdf0e10cSrcweir mpGraphics->SetLineColor(); 944*cdf0e10cSrcweir mbInitLineColor = sal_True; 945*cdf0e10cSrcweir } 946*cdf0e10cSrcweir 947*cdf0e10cSrcweir mbInitFillColor = sal_True; 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir // calculate step count if neccessary 950*cdf0e10cSrcweir if ( !aGradient.GetSteps() ) 951*cdf0e10cSrcweir aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir if( aGradient.GetStyle() == GRADIENT_LINEAR || aGradient.GetStyle() == GRADIENT_AXIAL ) 954*cdf0e10cSrcweir ImplDrawLinearGradient( aRect, aGradient, sal_False, &aClipPolyPoly ); 955*cdf0e10cSrcweir else 956*cdf0e10cSrcweir ImplDrawComplexGradient( aRect, aGradient, sal_False, &aClipPolyPoly ); 957*cdf0e10cSrcweir } 958*cdf0e10cSrcweir } 959*cdf0e10cSrcweir } 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir else 962*cdf0e10cSrcweir { 963*cdf0e10cSrcweir const PolyPolygon aPolyPoly( LogicToPixel( rPolyPoly ) ); 964*cdf0e10cSrcweir const Rectangle aBoundRect( aPolyPoly.GetBoundRect() ); 965*cdf0e10cSrcweir Point aPoint; 966*cdf0e10cSrcweir Rectangle aDstRect( aPoint, GetOutputSizePixel() ); 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir aDstRect.Intersection( aBoundRect ); 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir if( OUTDEV_WINDOW == meOutDevType ) 971*cdf0e10cSrcweir { 972*cdf0e10cSrcweir const Region aPaintRgn( ( (Window*) this )->GetPaintRegion() ); 973*cdf0e10cSrcweir 974*cdf0e10cSrcweir if( !aPaintRgn.IsNull() ) 975*cdf0e10cSrcweir aDstRect.Intersection( LogicToPixel( aPaintRgn ).GetBoundRect() ); 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir if( !aDstRect.IsEmpty() ) 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir VirtualDevice* pVDev; 981*cdf0e10cSrcweir const Size aDstSize( aDstRect.GetSize() ); 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir if( HasAlpha() ) 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir // #110958# Pay attention to alpha VDevs here, otherwise, 986*cdf0e10cSrcweir // background will be wrong: Temp VDev has to have alpha, too. 987*cdf0e10cSrcweir pVDev = new VirtualDevice( *this, 0, GetAlphaBitCount() > 1 ? 0 : 1 ); 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir else 990*cdf0e10cSrcweir { 991*cdf0e10cSrcweir // nothing special here. Plain VDev 992*cdf0e10cSrcweir pVDev = new VirtualDevice(); 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir if( pVDev->SetOutputSizePixel( aDstSize) ) 996*cdf0e10cSrcweir { 997*cdf0e10cSrcweir MapMode aVDevMap; 998*cdf0e10cSrcweir const sal_Bool bOldMap = mbMap; 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir EnableMapMode( sal_False ); 1001*cdf0e10cSrcweir 1002*cdf0e10cSrcweir pVDev->DrawOutDev( Point(), aDstSize, aDstRect.TopLeft(), aDstSize, *this ); 1003*cdf0e10cSrcweir pVDev->SetRasterOp( ROP_XOR ); 1004*cdf0e10cSrcweir aVDevMap.SetOrigin( Point( -aDstRect.Left(), -aDstRect.Top() ) ); 1005*cdf0e10cSrcweir pVDev->SetMapMode( aVDevMap ); 1006*cdf0e10cSrcweir pVDev->DrawGradient( aBoundRect, aGradient ); 1007*cdf0e10cSrcweir pVDev->SetFillColor( COL_BLACK ); 1008*cdf0e10cSrcweir pVDev->SetRasterOp( ROP_0 ); 1009*cdf0e10cSrcweir pVDev->DrawPolyPolygon( aPolyPoly ); 1010*cdf0e10cSrcweir pVDev->SetRasterOp( ROP_XOR ); 1011*cdf0e10cSrcweir pVDev->DrawGradient( aBoundRect, aGradient ); 1012*cdf0e10cSrcweir aVDevMap.SetOrigin( Point() ); 1013*cdf0e10cSrcweir pVDev->SetMapMode( aVDevMap ); 1014*cdf0e10cSrcweir DrawOutDev( aDstRect.TopLeft(), aDstSize, Point(), aDstSize, *pVDev ); 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir EnableMapMode( bOldMap ); 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir delete pVDev; 1020*cdf0e10cSrcweir } 1021*cdf0e10cSrcweir } 1022*cdf0e10cSrcweir } 1023*cdf0e10cSrcweir 1024*cdf0e10cSrcweir if( mpAlphaVDev ) 1025*cdf0e10cSrcweir mpAlphaVDev->DrawPolyPolygon( rPolyPoly ); 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1029*cdf0e10cSrcweir 1030*cdf0e10cSrcweir void OutputDevice::AddGradientActions( const Rectangle& rRect, const Gradient& rGradient, 1031*cdf0e10cSrcweir GDIMetaFile& rMtf ) 1032*cdf0e10cSrcweir { 1033*cdf0e10cSrcweir DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 1034*cdf0e10cSrcweir DBG_CHKOBJ( &rGradient, Gradient, NULL ); 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir Rectangle aRect( rRect ); 1037*cdf0e10cSrcweir 1038*cdf0e10cSrcweir aRect.Justify(); 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir // Wenn Rechteck leer ist, brauchen wir nichts machen 1041*cdf0e10cSrcweir if ( !aRect.IsEmpty() ) 1042*cdf0e10cSrcweir { 1043*cdf0e10cSrcweir Gradient aGradient( rGradient ); 1044*cdf0e10cSrcweir GDIMetaFile* pOldMtf = mpMetaFile; 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir mpMetaFile = &rMtf; 1047*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPushAction( PUSH_ALL ) ); 1048*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaISectRectClipRegionAction( aRect ) ); 1049*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaLineColorAction( Color(), sal_False ) ); 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir // because we draw with no border line, we have to expand gradient 1052*cdf0e10cSrcweir // rect to avoid missing lines on the right and bottom edge 1053*cdf0e10cSrcweir aRect.Left()--; 1054*cdf0e10cSrcweir aRect.Top()--; 1055*cdf0e10cSrcweir aRect.Right()++; 1056*cdf0e10cSrcweir aRect.Bottom()++; 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir // calculate step count if neccessary 1059*cdf0e10cSrcweir if ( !aGradient.GetSteps() ) 1060*cdf0e10cSrcweir aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir if( aGradient.GetStyle() == GRADIENT_LINEAR || aGradient.GetStyle() == GRADIENT_AXIAL ) 1063*cdf0e10cSrcweir ImplDrawLinearGradient( aRect, aGradient, sal_True, NULL ); 1064*cdf0e10cSrcweir else 1065*cdf0e10cSrcweir ImplDrawComplexGradient( aRect, aGradient, sal_True, NULL ); 1066*cdf0e10cSrcweir 1067*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPopAction() ); 1068*cdf0e10cSrcweir mpMetaFile = pOldMtf; 1069*cdf0e10cSrcweir } 1070*cdf0e10cSrcweir } 1071*cdf0e10cSrcweir 1072*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1073*cdf0e10cSrcweir 1074*cdf0e10cSrcweir void OutputDevice::DrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch ) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir DBG_TRACE( "OutputDevice::DrawHatch()" ); 1077*cdf0e10cSrcweir DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 1078*cdf0e10cSrcweir 1079*cdf0e10cSrcweir Hatch aHatch( rHatch ); 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir if ( mnDrawMode & ( DRAWMODE_BLACKLINE | DRAWMODE_WHITELINE | 1082*cdf0e10cSrcweir DRAWMODE_GRAYLINE | DRAWMODE_GHOSTEDLINE | 1083*cdf0e10cSrcweir DRAWMODE_SETTINGSLINE ) ) 1084*cdf0e10cSrcweir { 1085*cdf0e10cSrcweir Color aColor( rHatch.GetColor() ); 1086*cdf0e10cSrcweir 1087*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_BLACKLINE ) 1088*cdf0e10cSrcweir aColor = Color( COL_BLACK ); 1089*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_WHITELINE ) 1090*cdf0e10cSrcweir aColor = Color( COL_WHITE ); 1091*cdf0e10cSrcweir else if ( mnDrawMode & DRAWMODE_GRAYLINE ) 1092*cdf0e10cSrcweir { 1093*cdf0e10cSrcweir const sal_uInt8 cLum = aColor.GetLuminance(); 1094*cdf0e10cSrcweir aColor = Color( cLum, cLum, cLum ); 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir else if( mnDrawMode & DRAWMODE_SETTINGSLINE ) 1097*cdf0e10cSrcweir { 1098*cdf0e10cSrcweir aColor = GetSettings().GetStyleSettings().GetFontColor(); 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir if ( mnDrawMode & DRAWMODE_GHOSTEDLINE ) 1102*cdf0e10cSrcweir { 1103*cdf0e10cSrcweir aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80, 1104*cdf0e10cSrcweir ( aColor.GetGreen() >> 1 ) | 0x80, 1105*cdf0e10cSrcweir ( aColor.GetBlue() >> 1 ) | 0x80); 1106*cdf0e10cSrcweir } 1107*cdf0e10cSrcweir 1108*cdf0e10cSrcweir aHatch.SetColor( aColor ); 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir if( mpMetaFile ) 1112*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaHatchAction( rPolyPoly, aHatch ) ); 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) 1115*cdf0e10cSrcweir return; 1116*cdf0e10cSrcweir 1117*cdf0e10cSrcweir if( !mpGraphics && !ImplGetGraphics() ) 1118*cdf0e10cSrcweir return; 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir if( mbInitClipRegion ) 1121*cdf0e10cSrcweir ImplInitClipRegion(); 1122*cdf0e10cSrcweir 1123*cdf0e10cSrcweir if( mbOutputClipped ) 1124*cdf0e10cSrcweir return; 1125*cdf0e10cSrcweir 1126*cdf0e10cSrcweir if( rPolyPoly.Count() ) 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir PolyPolygon aPolyPoly( LogicToPixel( rPolyPoly ) ); 1129*cdf0e10cSrcweir GDIMetaFile* pOldMetaFile = mpMetaFile; 1130*cdf0e10cSrcweir sal_Bool bOldMap = mbMap; 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir aPolyPoly.Optimize( POLY_OPTIMIZE_NO_SAME ); 1133*cdf0e10cSrcweir aHatch.SetDistance( ImplLogicWidthToDevicePixel( aHatch.GetDistance() ) ); 1134*cdf0e10cSrcweir 1135*cdf0e10cSrcweir mpMetaFile = NULL; 1136*cdf0e10cSrcweir EnableMapMode( sal_False ); 1137*cdf0e10cSrcweir Push( PUSH_LINECOLOR ); 1138*cdf0e10cSrcweir SetLineColor( aHatch.GetColor() ); 1139*cdf0e10cSrcweir ImplInitLineColor(); 1140*cdf0e10cSrcweir ImplDrawHatch( aPolyPoly, aHatch, sal_False ); 1141*cdf0e10cSrcweir Pop(); 1142*cdf0e10cSrcweir EnableMapMode( bOldMap ); 1143*cdf0e10cSrcweir mpMetaFile = pOldMetaFile; 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir if( mpAlphaVDev ) 1147*cdf0e10cSrcweir mpAlphaVDev->DrawHatch( rPolyPoly, rHatch ); 1148*cdf0e10cSrcweir } 1149*cdf0e10cSrcweir 1150*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1151*cdf0e10cSrcweir 1152*cdf0e10cSrcweir void OutputDevice::AddHatchActions( const PolyPolygon& rPolyPoly, const Hatch& rHatch, 1153*cdf0e10cSrcweir GDIMetaFile& rMtf ) 1154*cdf0e10cSrcweir { 1155*cdf0e10cSrcweir DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice ); 1156*cdf0e10cSrcweir 1157*cdf0e10cSrcweir PolyPolygon aPolyPoly( rPolyPoly ); 1158*cdf0e10cSrcweir aPolyPoly.Optimize( POLY_OPTIMIZE_NO_SAME | POLY_OPTIMIZE_CLOSE ); 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir if( aPolyPoly.Count() ) 1161*cdf0e10cSrcweir { 1162*cdf0e10cSrcweir GDIMetaFile* pOldMtf = mpMetaFile; 1163*cdf0e10cSrcweir 1164*cdf0e10cSrcweir mpMetaFile = &rMtf; 1165*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPushAction( PUSH_ALL ) ); 1166*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaLineColorAction( rHatch.GetColor(), sal_True ) ); 1167*cdf0e10cSrcweir ImplDrawHatch( aPolyPoly, rHatch, sal_True ); 1168*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaPopAction() ); 1169*cdf0e10cSrcweir mpMetaFile = pOldMtf; 1170*cdf0e10cSrcweir } 1171*cdf0e10cSrcweir } 1172*cdf0e10cSrcweir 1173*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1174*cdf0e10cSrcweir 1175*cdf0e10cSrcweir void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch, sal_Bool bMtf ) 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir Rectangle aRect( rPolyPoly.GetBoundRect() ); 1178*cdf0e10cSrcweir const long nLogPixelWidth = ImplDevicePixelToLogicWidth( 1 ); 1179*cdf0e10cSrcweir const long nWidth = ImplDevicePixelToLogicWidth( Max( ImplLogicWidthToDevicePixel( rHatch.GetDistance() ), 3L ) ); 1180*cdf0e10cSrcweir Point* pPtBuffer = new Point[ HATCH_MAXPOINTS ]; 1181*cdf0e10cSrcweir Point aPt1, aPt2, aEndPt1; 1182*cdf0e10cSrcweir Size aInc; 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir // Single hatch 1185*cdf0e10cSrcweir aRect.Left() -= nLogPixelWidth; aRect.Top() -= nLogPixelWidth; aRect.Right() += nLogPixelWidth; aRect.Bottom() += nLogPixelWidth; 1186*cdf0e10cSrcweir ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle(), aPt1, aPt2, aInc, aEndPt1 ); 1187*cdf0e10cSrcweir do 1188*cdf0e10cSrcweir { 1189*cdf0e10cSrcweir ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); 1190*cdf0e10cSrcweir aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height(); 1191*cdf0e10cSrcweir aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height(); 1192*cdf0e10cSrcweir } 1193*cdf0e10cSrcweir while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) ); 1194*cdf0e10cSrcweir 1195*cdf0e10cSrcweir if( ( rHatch.GetStyle() == HATCH_DOUBLE ) || ( rHatch.GetStyle() == HATCH_TRIPLE ) ) 1196*cdf0e10cSrcweir { 1197*cdf0e10cSrcweir // Double hatch 1198*cdf0e10cSrcweir ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 900, aPt1, aPt2, aInc, aEndPt1 ); 1199*cdf0e10cSrcweir do 1200*cdf0e10cSrcweir { 1201*cdf0e10cSrcweir ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); 1202*cdf0e10cSrcweir aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height(); 1203*cdf0e10cSrcweir aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height(); 1204*cdf0e10cSrcweir } 1205*cdf0e10cSrcweir while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) ); 1206*cdf0e10cSrcweir 1207*cdf0e10cSrcweir if( rHatch.GetStyle() == HATCH_TRIPLE ) 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir // Triple hatch 1210*cdf0e10cSrcweir ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 450, aPt1, aPt2, aInc, aEndPt1 ); 1211*cdf0e10cSrcweir do 1212*cdf0e10cSrcweir { 1213*cdf0e10cSrcweir ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); 1214*cdf0e10cSrcweir aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height(); 1215*cdf0e10cSrcweir aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height(); 1216*cdf0e10cSrcweir } 1217*cdf0e10cSrcweir while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) ); 1218*cdf0e10cSrcweir } 1219*cdf0e10cSrcweir } 1220*cdf0e10cSrcweir 1221*cdf0e10cSrcweir delete[] pPtBuffer; 1222*cdf0e10cSrcweir } 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1225*cdf0e10cSrcweir 1226*cdf0e10cSrcweir void OutputDevice::ImplCalcHatchValues( const Rectangle& rRect, long nDist, sal_uInt16 nAngle10, 1227*cdf0e10cSrcweir Point& rPt1, Point& rPt2, Size& rInc, Point& rEndPt1 ) 1228*cdf0e10cSrcweir { 1229*cdf0e10cSrcweir Point aRef; 1230*cdf0e10cSrcweir long nAngle = nAngle10 % 1800; 1231*cdf0e10cSrcweir long nOffset = 0; 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir if( nAngle > 900 ) 1234*cdf0e10cSrcweir nAngle -= 1800; 1235*cdf0e10cSrcweir 1236*cdf0e10cSrcweir aRef = ( !IsRefPoint() ? rRect.TopLeft() : GetRefPoint() ); 1237*cdf0e10cSrcweir 1238*cdf0e10cSrcweir if( 0 == nAngle ) 1239*cdf0e10cSrcweir { 1240*cdf0e10cSrcweir rInc = Size( 0, nDist ); 1241*cdf0e10cSrcweir rPt1 = rRect.TopLeft(); 1242*cdf0e10cSrcweir rPt2 = rRect.TopRight(); 1243*cdf0e10cSrcweir rEndPt1 = rRect.BottomLeft(); 1244*cdf0e10cSrcweir 1245*cdf0e10cSrcweir if( aRef.Y() <= rRect.Top() ) 1246*cdf0e10cSrcweir nOffset = ( ( rRect.Top() - aRef.Y() ) % nDist ); 1247*cdf0e10cSrcweir else 1248*cdf0e10cSrcweir nOffset = ( nDist - ( ( aRef.Y() - rRect.Top() ) % nDist ) ); 1249*cdf0e10cSrcweir 1250*cdf0e10cSrcweir rPt1.Y() -= nOffset; 1251*cdf0e10cSrcweir rPt2.Y() -= nOffset; 1252*cdf0e10cSrcweir } 1253*cdf0e10cSrcweir else if( 900 == nAngle ) 1254*cdf0e10cSrcweir { 1255*cdf0e10cSrcweir rInc = Size( nDist, 0 ); 1256*cdf0e10cSrcweir rPt1 = rRect.TopLeft(); 1257*cdf0e10cSrcweir rPt2 = rRect.BottomLeft(); 1258*cdf0e10cSrcweir rEndPt1 = rRect.TopRight(); 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir if( aRef.X() <= rRect.Left() ) 1261*cdf0e10cSrcweir nOffset = ( rRect.Left() - aRef.X() ) % nDist; 1262*cdf0e10cSrcweir else 1263*cdf0e10cSrcweir nOffset = nDist - ( ( aRef.X() - rRect.Left() ) % nDist ); 1264*cdf0e10cSrcweir 1265*cdf0e10cSrcweir rPt1.X() -= nOffset; 1266*cdf0e10cSrcweir rPt2.X() -= nOffset; 1267*cdf0e10cSrcweir } 1268*cdf0e10cSrcweir else if( nAngle >= -450 && nAngle <= 450 ) 1269*cdf0e10cSrcweir { 1270*cdf0e10cSrcweir const double fAngle = F_PI1800 * labs( nAngle ); 1271*cdf0e10cSrcweir const double fTan = tan( fAngle ); 1272*cdf0e10cSrcweir const long nYOff = FRound( ( rRect.Right() - rRect.Left() ) * fTan ); 1273*cdf0e10cSrcweir long nPY; 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir rInc = Size( 0, nDist = FRound( nDist / cos( fAngle ) ) ); 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir if( nAngle > 0 ) 1278*cdf0e10cSrcweir { 1279*cdf0e10cSrcweir rPt1 = rRect.TopLeft(); 1280*cdf0e10cSrcweir rPt2 = Point( rRect.Right(), rRect.Top() - nYOff ); 1281*cdf0e10cSrcweir rEndPt1 = Point( rRect.Left(), rRect.Bottom() + nYOff ); 1282*cdf0e10cSrcweir nPY = FRound( aRef.Y() - ( ( rPt1.X() - aRef.X() ) * fTan ) ); 1283*cdf0e10cSrcweir } 1284*cdf0e10cSrcweir else 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir rPt1 = rRect.TopRight(); 1287*cdf0e10cSrcweir rPt2 = Point( rRect.Left(), rRect.Top() - nYOff ); 1288*cdf0e10cSrcweir rEndPt1 = Point( rRect.Right(), rRect.Bottom() + nYOff ); 1289*cdf0e10cSrcweir nPY = FRound( aRef.Y() + ( ( rPt1.X() - aRef.X() ) * fTan ) ); 1290*cdf0e10cSrcweir } 1291*cdf0e10cSrcweir 1292*cdf0e10cSrcweir if( nPY <= rPt1.Y() ) 1293*cdf0e10cSrcweir nOffset = ( rPt1.Y() - nPY ) % nDist; 1294*cdf0e10cSrcweir else 1295*cdf0e10cSrcweir nOffset = nDist - ( ( nPY - rPt1.Y() ) % nDist ); 1296*cdf0e10cSrcweir 1297*cdf0e10cSrcweir rPt1.Y() -= nOffset; 1298*cdf0e10cSrcweir rPt2.Y() -= nOffset; 1299*cdf0e10cSrcweir } 1300*cdf0e10cSrcweir else 1301*cdf0e10cSrcweir { 1302*cdf0e10cSrcweir const double fAngle = F_PI1800 * labs( nAngle ); 1303*cdf0e10cSrcweir const double fTan = tan( fAngle ); 1304*cdf0e10cSrcweir const long nXOff = FRound( ( rRect.Bottom() - rRect.Top() ) / fTan ); 1305*cdf0e10cSrcweir long nPX; 1306*cdf0e10cSrcweir 1307*cdf0e10cSrcweir rInc = Size( nDist = FRound( nDist / sin( fAngle ) ), 0 ); 1308*cdf0e10cSrcweir 1309*cdf0e10cSrcweir if( nAngle > 0 ) 1310*cdf0e10cSrcweir { 1311*cdf0e10cSrcweir rPt1 = rRect.TopLeft(); 1312*cdf0e10cSrcweir rPt2 = Point( rRect.Left() - nXOff, rRect.Bottom() ); 1313*cdf0e10cSrcweir rEndPt1 = Point( rRect.Right() + nXOff, rRect.Top() ); 1314*cdf0e10cSrcweir nPX = FRound( aRef.X() - ( ( rPt1.Y() - aRef.Y() ) / fTan ) ); 1315*cdf0e10cSrcweir } 1316*cdf0e10cSrcweir else 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir rPt1 = rRect.BottomLeft(); 1319*cdf0e10cSrcweir rPt2 = Point( rRect.Left() - nXOff, rRect.Top() ); 1320*cdf0e10cSrcweir rEndPt1 = Point( rRect.Right() + nXOff, rRect.Bottom() ); 1321*cdf0e10cSrcweir nPX = FRound( aRef.X() + ( ( rPt1.Y() - aRef.Y() ) / fTan ) ); 1322*cdf0e10cSrcweir } 1323*cdf0e10cSrcweir 1324*cdf0e10cSrcweir if( nPX <= rPt1.X() ) 1325*cdf0e10cSrcweir nOffset = ( rPt1.X() - nPX ) % nDist; 1326*cdf0e10cSrcweir else 1327*cdf0e10cSrcweir nOffset = nDist - ( ( nPX - rPt1.X() ) % nDist ); 1328*cdf0e10cSrcweir 1329*cdf0e10cSrcweir rPt1.X() -= nOffset; 1330*cdf0e10cSrcweir rPt2.X() -= nOffset; 1331*cdf0e10cSrcweir } 1332*cdf0e10cSrcweir } 1333*cdf0e10cSrcweir 1334*cdf0e10cSrcweir // ------------------------------------------------------------------------ 1335*cdf0e10cSrcweir 1336*cdf0e10cSrcweir void OutputDevice::ImplDrawHatchLine( const Line& rLine, const PolyPolygon& rPolyPoly, 1337*cdf0e10cSrcweir Point* pPtBuffer, sal_Bool bMtf ) 1338*cdf0e10cSrcweir { 1339*cdf0e10cSrcweir double fX, fY; 1340*cdf0e10cSrcweir long nAdd, nPCounter = 0; 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir for( long nPoly = 0, nPolyCount = rPolyPoly.Count(); nPoly < nPolyCount; nPoly++ ) 1343*cdf0e10cSrcweir { 1344*cdf0e10cSrcweir const Polygon& rPoly = rPolyPoly[ (sal_uInt16) nPoly ]; 1345*cdf0e10cSrcweir 1346*cdf0e10cSrcweir if( rPoly.GetSize() > 1 ) 1347*cdf0e10cSrcweir { 1348*cdf0e10cSrcweir Line aCurSegment( rPoly[ 0 ], Point() ); 1349*cdf0e10cSrcweir 1350*cdf0e10cSrcweir for( long i = 1, nCount = rPoly.GetSize(); i <= nCount; i++ ) 1351*cdf0e10cSrcweir { 1352*cdf0e10cSrcweir aCurSegment.SetEnd( rPoly[ (sal_uInt16)( i % nCount ) ] ); 1353*cdf0e10cSrcweir nAdd = 0; 1354*cdf0e10cSrcweir 1355*cdf0e10cSrcweir if( rLine.Intersection( aCurSegment, fX, fY ) ) 1356*cdf0e10cSrcweir { 1357*cdf0e10cSrcweir if( ( fabs( fX - aCurSegment.GetStart().X() ) <= 0.0000001 ) && 1358*cdf0e10cSrcweir ( fabs( fY - aCurSegment.GetStart().Y() ) <= 0.0000001 ) ) 1359*cdf0e10cSrcweir { 1360*cdf0e10cSrcweir const Line aPrevSegment( rPoly[ (sal_uInt16)( ( i > 1 ) ? ( i - 2 ) : ( nCount - 1 ) ) ], aCurSegment.GetStart() ); 1361*cdf0e10cSrcweir const double fPrevDistance = rLine.GetDistance( aPrevSegment.GetStart() ); 1362*cdf0e10cSrcweir const double fCurDistance = rLine.GetDistance( aCurSegment.GetEnd() ); 1363*cdf0e10cSrcweir 1364*cdf0e10cSrcweir if( ( fPrevDistance <= 0.0 && fCurDistance > 0.0 ) || 1365*cdf0e10cSrcweir ( fPrevDistance > 0.0 && fCurDistance < 0.0 ) ) 1366*cdf0e10cSrcweir { 1367*cdf0e10cSrcweir nAdd = 1; 1368*cdf0e10cSrcweir } 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir else if( ( fabs( fX - aCurSegment.GetEnd().X() ) <= 0.0000001 ) && 1371*cdf0e10cSrcweir ( fabs( fY - aCurSegment.GetEnd().Y() ) <= 0.0000001 ) ) 1372*cdf0e10cSrcweir { 1373*cdf0e10cSrcweir const Line aNextSegment( aCurSegment.GetEnd(), rPoly[ (sal_uInt16)( ( i + 1 ) % nCount ) ] ); 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir if( ( fabs( rLine.GetDistance( aNextSegment.GetEnd() ) ) <= 0.0000001 ) && 1376*cdf0e10cSrcweir ( rLine.GetDistance( aCurSegment.GetStart() ) > 0.0 ) ) 1377*cdf0e10cSrcweir { 1378*cdf0e10cSrcweir nAdd = 1; 1379*cdf0e10cSrcweir } 1380*cdf0e10cSrcweir } 1381*cdf0e10cSrcweir else 1382*cdf0e10cSrcweir nAdd = 1; 1383*cdf0e10cSrcweir 1384*cdf0e10cSrcweir if( nAdd ) 1385*cdf0e10cSrcweir pPtBuffer[ nPCounter++ ] = Point( FRound( fX ), FRound( fY ) ); 1386*cdf0e10cSrcweir } 1387*cdf0e10cSrcweir 1388*cdf0e10cSrcweir aCurSegment.SetStart( aCurSegment.GetEnd() ); 1389*cdf0e10cSrcweir } 1390*cdf0e10cSrcweir } 1391*cdf0e10cSrcweir } 1392*cdf0e10cSrcweir 1393*cdf0e10cSrcweir if( nPCounter > 1 ) 1394*cdf0e10cSrcweir { 1395*cdf0e10cSrcweir qsort( pPtBuffer, nPCounter, sizeof( Point ), ImplHatchCmpFnc ); 1396*cdf0e10cSrcweir 1397*cdf0e10cSrcweir if( nPCounter & 1 ) 1398*cdf0e10cSrcweir nPCounter--; 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir if( bMtf ) 1401*cdf0e10cSrcweir { 1402*cdf0e10cSrcweir for( long i = 0; i < nPCounter; i += 2 ) 1403*cdf0e10cSrcweir mpMetaFile->AddAction( new MetaLineAction( pPtBuffer[ i ], pPtBuffer[ i + 1 ] ) ); 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir else 1406*cdf0e10cSrcweir { 1407*cdf0e10cSrcweir for( long i = 0; i < nPCounter; i += 2 ) 1408*cdf0e10cSrcweir { 1409*cdf0e10cSrcweir if( mpPDFWriter ) 1410*cdf0e10cSrcweir { 1411*cdf0e10cSrcweir mpPDFWriter->drawLine( pPtBuffer[ i ], pPtBuffer[ i+1 ] ); 1412*cdf0e10cSrcweir } 1413*cdf0e10cSrcweir else 1414*cdf0e10cSrcweir { 1415*cdf0e10cSrcweir const Point aPt1( ImplLogicToDevicePixel( pPtBuffer[ i ] ) ); 1416*cdf0e10cSrcweir const Point aPt2( ImplLogicToDevicePixel( pPtBuffer[ i + 1 ] ) ); 1417*cdf0e10cSrcweir mpGraphics->DrawLine( aPt1.X(), aPt1.Y(), aPt2.X(), aPt2.Y(), this ); 1418*cdf0e10cSrcweir } 1419*cdf0e10cSrcweir } 1420*cdf0e10cSrcweir } 1421*cdf0e10cSrcweir } 1422*cdf0e10cSrcweir } 1423