1*c82f2877SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c82f2877SAndrew Rist * distributed with this work for additional information 6*c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c82f2877SAndrew Rist * "License"); you may not use this file except in compliance 9*c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c82f2877SAndrew Rist * software distributed under the License is distributed on an 15*c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c82f2877SAndrew Rist * KIND, either express or implied. See the License for the 17*c82f2877SAndrew Rist * specific language governing permissions and limitations 18*c82f2877SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c82f2877SAndrew Rist *************************************************************/ 21*c82f2877SAndrew Rist 22*c82f2877SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "tools/debug.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygon.hxx" 30cdf0e10cSrcweir #include "basegfx/polygon/b2dpolypolygon.hxx" 31cdf0e10cSrcweir #include "basegfx/polygon/b2dpolypolygontools.hxx" 32cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygontools.hxx" 33cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygonclipper.hxx" 34cdf0e10cSrcweir #include "basegfx/polygon/b2dlinegeometry.hxx" 35cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrix.hxx" 36cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrixtools.hxx" 37cdf0e10cSrcweir #include "basegfx/polygon/b2dpolypolygoncutter.hxx" 38cdf0e10cSrcweir #include "basegfx/polygon/b2dtrapezoid.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "vcl/jobdata.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "unx/Xproto.h" 43cdf0e10cSrcweir #include "unx/salunx.h" 44cdf0e10cSrcweir #include "unx/saldata.hxx" 45cdf0e10cSrcweir #include "unx/saldisp.hxx" 46cdf0e10cSrcweir #include "unx/salgdi.h" 47cdf0e10cSrcweir #include "unx/salframe.h" 48cdf0e10cSrcweir #include "unx/salvd.h" 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include "printergfx.hxx" 51cdf0e10cSrcweir #include "xrender_peer.hxx" 52cdf0e10cSrcweir #include "region.h" 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <vector> 55cdf0e10cSrcweir #include <queue> 56cdf0e10cSrcweir #include <set> 57cdf0e10cSrcweir 58cdf0e10cSrcweir // -=-= SalPolyLine =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 59cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 60cdf0e10cSrcweir #define STATIC_POINTS 64 61cdf0e10cSrcweir 62cdf0e10cSrcweir class SalPolyLine 63cdf0e10cSrcweir { 64cdf0e10cSrcweir XPoint Points_[STATIC_POINTS]; 65cdf0e10cSrcweir XPoint *pFirst_; 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir inline SalPolyLine( sal_uLong nPoints ); 68cdf0e10cSrcweir inline SalPolyLine( sal_uLong nPoints, const SalPoint *p ); 69cdf0e10cSrcweir inline ~SalPolyLine(); 70cdf0e10cSrcweir inline XPoint &operator [] ( sal_uLong n ) const 71cdf0e10cSrcweir { return pFirst_[n]; } 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir inline SalPolyLine::SalPolyLine( sal_uLong nPoints ) 75cdf0e10cSrcweir : pFirst_( nPoints+1 > STATIC_POINTS ? new XPoint[nPoints+1] : Points_ ) 76cdf0e10cSrcweir {} 77cdf0e10cSrcweir 78cdf0e10cSrcweir inline SalPolyLine::SalPolyLine( sal_uLong nPoints, const SalPoint *p ) 79cdf0e10cSrcweir : pFirst_( nPoints+1 > STATIC_POINTS ? new XPoint[nPoints+1] : Points_ ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir for( sal_uLong i = 0; i < nPoints; i++ ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir pFirst_[i].x = (short)p[i].mnX; 84cdf0e10cSrcweir pFirst_[i].y = (short)p[i].mnY; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir pFirst_[nPoints] = pFirst_[0]; // close polyline 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir inline SalPolyLine::~SalPolyLine() 90cdf0e10cSrcweir { if( pFirst_ != Points_ ) delete [] pFirst_; } 91cdf0e10cSrcweir 92cdf0e10cSrcweir #undef STATIC_POINTS 93cdf0e10cSrcweir // -=-= X11SalGraphics =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 94cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 95cdf0e10cSrcweir X11SalGraphics::X11SalGraphics() 96cdf0e10cSrcweir { 97cdf0e10cSrcweir m_pFrame = NULL; 98cdf0e10cSrcweir m_pVDev = NULL; 99cdf0e10cSrcweir m_pDeleteColormap = NULL; 100cdf0e10cSrcweir hDrawable_ = None; 101cdf0e10cSrcweir m_aRenderPicture = 0; 102cdf0e10cSrcweir m_pRenderFormat = NULL; 103cdf0e10cSrcweir 104cdf0e10cSrcweir mpClipRegion = NULL; 105cdf0e10cSrcweir pPaintRegion_ = NULL; 106cdf0e10cSrcweir 107cdf0e10cSrcweir pPenGC_ = NULL; 108cdf0e10cSrcweir nPenPixel_ = 0; 109cdf0e10cSrcweir nPenColor_ = MAKE_SALCOLOR( 0x00, 0x00, 0x00 ); // Black 110cdf0e10cSrcweir 111cdf0e10cSrcweir pFontGC_ = NULL; 112cdf0e10cSrcweir for( int i = 0; i < MAX_FALLBACK; ++i ) 113cdf0e10cSrcweir mpServerFont[i] = NULL; 114cdf0e10cSrcweir 115cdf0e10cSrcweir nTextPixel_ = 0; 116cdf0e10cSrcweir nTextColor_ = MAKE_SALCOLOR( 0x00, 0x00, 0x00 ); // Black 117cdf0e10cSrcweir 118cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE 119cdf0e10cSrcweir // check if graphite fonts have been disabled 120cdf0e10cSrcweir static const char* pDisableGraphiteStr = getenv( "SAL_DISABLE_GRAPHITE" ); 121cdf0e10cSrcweir bDisableGraphite_ = pDisableGraphiteStr ? (pDisableGraphiteStr[0]!='0') : sal_False; 122cdf0e10cSrcweir #endif 123cdf0e10cSrcweir 124cdf0e10cSrcweir pBrushGC_ = NULL; 125cdf0e10cSrcweir nBrushPixel_ = 0; 126cdf0e10cSrcweir nBrushColor_ = MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ); // White 127cdf0e10cSrcweir hBrush_ = None; 128cdf0e10cSrcweir 129cdf0e10cSrcweir pMonoGC_ = NULL; 130cdf0e10cSrcweir pCopyGC_ = NULL; 131cdf0e10cSrcweir pMaskGC_ = NULL; 132cdf0e10cSrcweir pInvertGC_ = NULL; 133cdf0e10cSrcweir pInvert50GC_ = NULL; 134cdf0e10cSrcweir pStippleGC_ = NULL; 135cdf0e10cSrcweir pTrackingGC_ = NULL; 136cdf0e10cSrcweir 137cdf0e10cSrcweir bWindow_ = sal_False; 138cdf0e10cSrcweir bPrinter_ = sal_False; 139cdf0e10cSrcweir bVirDev_ = sal_False; 140cdf0e10cSrcweir bPenGC_ = sal_False; 141cdf0e10cSrcweir bFontGC_ = sal_False; 142cdf0e10cSrcweir bBrushGC_ = sal_False; 143cdf0e10cSrcweir bMonoGC_ = sal_False; 144cdf0e10cSrcweir bCopyGC_ = sal_False; 145cdf0e10cSrcweir bInvertGC_ = sal_False; 146cdf0e10cSrcweir bInvert50GC_ = sal_False; 147cdf0e10cSrcweir bStippleGC_ = sal_False; 148cdf0e10cSrcweir bTrackingGC_ = sal_False; 149cdf0e10cSrcweir bXORMode_ = sal_False; 150cdf0e10cSrcweir bDitherBrush_ = sal_False; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 154cdf0e10cSrcweir X11SalGraphics::~X11SalGraphics() 155cdf0e10cSrcweir { 156cdf0e10cSrcweir ReleaseFonts(); 157cdf0e10cSrcweir freeResources(); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir // -=-= SalGraphics / X11SalGraphics =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 161cdf0e10cSrcweir 162cdf0e10cSrcweir void X11SalGraphics::freeResources() 163cdf0e10cSrcweir { 164cdf0e10cSrcweir Display *pDisplay = GetXDisplay(); 165cdf0e10cSrcweir 166cdf0e10cSrcweir DBG_ASSERT( !pPaintRegion_, "pPaintRegion_" ); 167cdf0e10cSrcweir if( mpClipRegion ) XDestroyRegion( mpClipRegion ), mpClipRegion = None; 168cdf0e10cSrcweir 169cdf0e10cSrcweir if( hBrush_ ) XFreePixmap( pDisplay, hBrush_ ), hBrush_ = None; 170cdf0e10cSrcweir if( pPenGC_ ) XFreeGC( pDisplay, pPenGC_ ), pPenGC_ = None; 171cdf0e10cSrcweir if( pFontGC_ ) XFreeGC( pDisplay, pFontGC_ ), pFontGC_ = None; 172cdf0e10cSrcweir if( pBrushGC_ ) XFreeGC( pDisplay, pBrushGC_ ), pBrushGC_ = None; 173cdf0e10cSrcweir if( pMonoGC_ ) XFreeGC( pDisplay, pMonoGC_ ), pMonoGC_ = None; 174cdf0e10cSrcweir if( pCopyGC_ ) XFreeGC( pDisplay, pCopyGC_ ), pCopyGC_ = None; 175cdf0e10cSrcweir if( pMaskGC_ ) XFreeGC( pDisplay, pMaskGC_ ), pMaskGC_ = None; 176cdf0e10cSrcweir if( pInvertGC_ ) XFreeGC( pDisplay, pInvertGC_ ), pInvertGC_ = None; 177cdf0e10cSrcweir if( pInvert50GC_ ) XFreeGC( pDisplay, pInvert50GC_ ), pInvert50GC_ = None; 178cdf0e10cSrcweir if( pStippleGC_ ) XFreeGC( pDisplay, pStippleGC_ ), pStippleGC_ = None; 179cdf0e10cSrcweir if( pTrackingGC_ ) XFreeGC( pDisplay, pTrackingGC_ ), pTrackingGC_ = None; 180cdf0e10cSrcweir if( m_pDeleteColormap ) 181cdf0e10cSrcweir delete m_pDeleteColormap, m_pColormap = m_pDeleteColormap = NULL; 182cdf0e10cSrcweir 183cdf0e10cSrcweir if( m_aRenderPicture ) 184cdf0e10cSrcweir XRenderPeer::GetInstance().FreePicture( m_aRenderPicture ), m_aRenderPicture = 0; 185cdf0e10cSrcweir 186cdf0e10cSrcweir bPenGC_ = bFontGC_ = bBrushGC_ = bMonoGC_ = bCopyGC_ = bInvertGC_ = bInvert50GC_ = bStippleGC_ = bTrackingGC_ = false; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir void X11SalGraphics::SetDrawable( Drawable aDrawable, int nScreen ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir // shortcut if nothing changed 192cdf0e10cSrcweir if( hDrawable_ == aDrawable ) 193cdf0e10cSrcweir return; 194cdf0e10cSrcweir 195cdf0e10cSrcweir // free screen specific resources if needed 196cdf0e10cSrcweir if( nScreen != m_nScreen ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir freeResources(); 199cdf0e10cSrcweir m_pColormap = &GetX11SalData()->GetDisplay()->GetColormap( nScreen ); 200cdf0e10cSrcweir m_nScreen = nScreen; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir hDrawable_ = aDrawable; 204cdf0e10cSrcweir SetXRenderFormat( NULL ); 205cdf0e10cSrcweir if( m_aRenderPicture ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir XRenderPeer::GetInstance().FreePicture( m_aRenderPicture ); 208cdf0e10cSrcweir m_aRenderPicture = 0; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir if( hDrawable_ ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir nPenPixel_ = GetPixel( nPenColor_ ); 214cdf0e10cSrcweir nTextPixel_ = GetPixel( nTextColor_ ); 215cdf0e10cSrcweir nBrushPixel_ = GetPixel( nBrushColor_ ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir void X11SalGraphics::Init( SalFrame *pFrame, Drawable aTarget, int nScreen ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir #if 0 // TODO: use SetDrawable() instead 222cdf0e10cSrcweir m_pColormap = &GetX11SalData()->GetDisplay()->GetColormap(nScreen); 223cdf0e10cSrcweir hDrawable_ = aTarget; 224cdf0e10cSrcweir m_nScreen = nScreen; 225cdf0e10cSrcweir SetXRenderFormat( NULL ); 226cdf0e10cSrcweir if( m_aRenderPicture ) 227cdf0e10cSrcweir XRenderPeer::GetInstance().FreePicture( m_aRenderPicture ), m_aRenderPicture = 0; 228cdf0e10cSrcweir 229cdf0e10cSrcweir nPenPixel_ = GetPixel( nPenColor_ ); 230cdf0e10cSrcweir nTextPixel_ = GetPixel( nTextColor_ ); 231cdf0e10cSrcweir nBrushPixel_ = GetPixel( nBrushColor_ ); 232cdf0e10cSrcweir #else 233cdf0e10cSrcweir m_pColormap = &GetX11SalData()->GetDisplay()->GetColormap(nScreen); 234cdf0e10cSrcweir m_nScreen = nScreen; 235cdf0e10cSrcweir SetDrawable( aTarget, nScreen ); 236cdf0e10cSrcweir #endif 237cdf0e10cSrcweir 238cdf0e10cSrcweir bWindow_ = sal_True; 239cdf0e10cSrcweir m_pFrame = pFrame; 240cdf0e10cSrcweir m_pVDev = NULL; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 244cdf0e10cSrcweir void X11SalGraphics::DeInit() 245cdf0e10cSrcweir { 246cdf0e10cSrcweir SetDrawable( None, m_nScreen ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 250cdf0e10cSrcweir void X11SalGraphics::SetClipRegion( GC pGC, XLIB_Region pXReg ) const 251cdf0e10cSrcweir { 252cdf0e10cSrcweir Display *pDisplay = GetXDisplay(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir int n = 0; 255cdf0e10cSrcweir XLIB_Region Regions[3]; 256cdf0e10cSrcweir 257cdf0e10cSrcweir if( mpClipRegion /* && !XEmptyRegion( mpClipRegion ) */ ) 258cdf0e10cSrcweir Regions[n++] = mpClipRegion; 259cdf0e10cSrcweir // if( pPaintRegion_ /* && !XEmptyRegion( pPaintRegion_ ) */ ) 260cdf0e10cSrcweir // Regions[n++] = pPaintRegion_; 261cdf0e10cSrcweir 262cdf0e10cSrcweir if( pXReg && !XEmptyRegion( pXReg ) ) 263cdf0e10cSrcweir Regions[n++] = pXReg; 264cdf0e10cSrcweir 265cdf0e10cSrcweir if( 0 == n ) 266cdf0e10cSrcweir XSetClipMask( pDisplay, pGC, None ); 267cdf0e10cSrcweir else if( 1 == n ) 268cdf0e10cSrcweir XSetRegion( pDisplay, pGC, Regions[0] ); 269cdf0e10cSrcweir else 270cdf0e10cSrcweir { 271cdf0e10cSrcweir XLIB_Region pTmpRegion = XCreateRegion(); 272cdf0e10cSrcweir XIntersectRegion( Regions[0], Regions[1], pTmpRegion ); 273cdf0e10cSrcweir // if( 3 == n ) 274cdf0e10cSrcweir // XIntersectRegion( Regions[2], pTmpRegion, pTmpRegion ); 275cdf0e10cSrcweir XSetRegion( pDisplay, pGC, pTmpRegion ); 276cdf0e10cSrcweir XDestroyRegion( pTmpRegion ); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 281cdf0e10cSrcweir GC X11SalGraphics::SelectPen() 282cdf0e10cSrcweir { 283cdf0e10cSrcweir Display *pDisplay = GetXDisplay(); 284cdf0e10cSrcweir 285cdf0e10cSrcweir if( !pPenGC_ ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir XGCValues values; 288cdf0e10cSrcweir values.subwindow_mode = ClipByChildren; 289cdf0e10cSrcweir values.fill_rule = EvenOddRule; // Pict import/ Gradient 290cdf0e10cSrcweir values.graphics_exposures = False; 291cdf0e10cSrcweir 292cdf0e10cSrcweir pPenGC_ = XCreateGC( pDisplay, hDrawable_, 293cdf0e10cSrcweir GCSubwindowMode | GCFillRule | GCGraphicsExposures, 294cdf0e10cSrcweir &values ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir if( !bPenGC_ ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 300cdf0e10cSrcweir XSetForeground( pDisplay, pPenGC_, nPenPixel_ ); 301cdf0e10cSrcweir XSetFunction ( pDisplay, pPenGC_, bXORMode_ ? GXxor : GXcopy ); 302cdf0e10cSrcweir SetClipRegion( pPenGC_ ); 303cdf0e10cSrcweir bPenGC_ = sal_True; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir return pPenGC_; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 310cdf0e10cSrcweir GC X11SalGraphics::SelectBrush() 311cdf0e10cSrcweir { 312cdf0e10cSrcweir Display *pDisplay = GetXDisplay(); 313cdf0e10cSrcweir 314cdf0e10cSrcweir DBG_ASSERT( nBrushColor_ != SALCOLOR_NONE, "Brush Transparent" ); 315cdf0e10cSrcweir 316cdf0e10cSrcweir if( !pBrushGC_ ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir XGCValues values; 319cdf0e10cSrcweir // values.subwindow_mode = IncludeInferiors; 320cdf0e10cSrcweir values.subwindow_mode = ClipByChildren; 321cdf0e10cSrcweir values.fill_rule = EvenOddRule; // Pict import/ Gradient 322cdf0e10cSrcweir values.graphics_exposures = False; 323cdf0e10cSrcweir 324cdf0e10cSrcweir pBrushGC_ = XCreateGC( pDisplay, hDrawable_, 325cdf0e10cSrcweir GCSubwindowMode | GCFillRule | GCGraphicsExposures, 326cdf0e10cSrcweir &values ); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir if( !bBrushGC_ ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir if( !bDitherBrush_ ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir XSetFillStyle ( pDisplay, pBrushGC_, FillSolid ); 334cdf0e10cSrcweir XSetForeground( pDisplay, pBrushGC_, nBrushPixel_ ); 335cdf0e10cSrcweir if( bPrinter_ ) 336cdf0e10cSrcweir XSetTile( pDisplay, pBrushGC_, None ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir else 339cdf0e10cSrcweir { 340cdf0e10cSrcweir // Bug in Sun Solaris 2.5.1, XFillPolygon doesn't allways reflect 341cdf0e10cSrcweir // changes of the tile. PROPERTY_BUG_Tile doesn't fix this ! 342cdf0e10cSrcweir if (GetDisplay()->GetProperties() & PROPERTY_BUG_FillPolygon_Tile) 343cdf0e10cSrcweir XSetFillStyle ( pDisplay, pBrushGC_, FillSolid ); 344cdf0e10cSrcweir 345cdf0e10cSrcweir XSetFillStyle ( pDisplay, pBrushGC_, FillTiled ); 346cdf0e10cSrcweir XSetTile ( pDisplay, pBrushGC_, hBrush_ ); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir XSetFunction ( pDisplay, pBrushGC_, bXORMode_ ? GXxor : GXcopy ); 349cdf0e10cSrcweir SetClipRegion( pBrushGC_ ); 350cdf0e10cSrcweir 351cdf0e10cSrcweir bBrushGC_ = sal_True; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir return pBrushGC_; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 358cdf0e10cSrcweir GC X11SalGraphics::GetTrackingGC() 359cdf0e10cSrcweir { 360cdf0e10cSrcweir const char dash_list[2] = {2, 2}; 361cdf0e10cSrcweir 362cdf0e10cSrcweir if( !pTrackingGC_ ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir XGCValues values; 365cdf0e10cSrcweir 366cdf0e10cSrcweir values.graphics_exposures = False; 367cdf0e10cSrcweir values.foreground = m_pColormap->GetBlackPixel() 368cdf0e10cSrcweir ^ m_pColormap->GetWhitePixel(); 369cdf0e10cSrcweir values.function = GXxor; 370cdf0e10cSrcweir values.line_width = 1; 371cdf0e10cSrcweir values.line_style = LineOnOffDash; 372cdf0e10cSrcweir 373cdf0e10cSrcweir pTrackingGC_ = XCreateGC( GetXDisplay(), GetDrawable(), 374cdf0e10cSrcweir GCGraphicsExposures | GCForeground | GCFunction 375cdf0e10cSrcweir | GCLineWidth | GCLineStyle, 376cdf0e10cSrcweir &values ); 377cdf0e10cSrcweir XSetDashes( GetXDisplay(), pTrackingGC_, 0, dash_list, 2 ); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir if( !bTrackingGC_ ) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir SetClipRegion( pTrackingGC_ ); 383cdf0e10cSrcweir bTrackingGC_ = sal_True; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir return pTrackingGC_; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 390cdf0e10cSrcweir void X11SalGraphics::DrawLines( sal_uLong nPoints, 391cdf0e10cSrcweir const SalPolyLine &rPoints, 392cdf0e10cSrcweir GC pGC, 393cdf0e10cSrcweir bool bClose 394cdf0e10cSrcweir ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir // errechne wie viele Linien XWindow auf einmal zeichnen kann 397cdf0e10cSrcweir sal_uLong nMaxLines = (GetDisplay()->GetMaxRequestSize() - sizeof(xPolyPointReq)) 398cdf0e10cSrcweir / sizeof(xPoint); 399cdf0e10cSrcweir if( nMaxLines > nPoints ) nMaxLines = nPoints; 400cdf0e10cSrcweir 401cdf0e10cSrcweir // gebe alle Linien aus, die XWindows zeichnen kann. 402cdf0e10cSrcweir sal_uLong n; 403cdf0e10cSrcweir for( n = 0; nPoints - n > nMaxLines; n += nMaxLines - 1 ) 404cdf0e10cSrcweir XDrawLines( GetXDisplay(), 405cdf0e10cSrcweir GetDrawable(), 406cdf0e10cSrcweir pGC, 407cdf0e10cSrcweir &rPoints[n], 408cdf0e10cSrcweir nMaxLines, 409cdf0e10cSrcweir CoordModeOrigin ); 410cdf0e10cSrcweir 411cdf0e10cSrcweir if( n < nPoints ) 412cdf0e10cSrcweir XDrawLines( GetXDisplay(), 413cdf0e10cSrcweir GetDrawable(), 414cdf0e10cSrcweir pGC, 415cdf0e10cSrcweir &rPoints[n], 416cdf0e10cSrcweir nPoints - n, 417cdf0e10cSrcweir CoordModeOrigin ); 418cdf0e10cSrcweir if( bClose ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir if( rPoints[nPoints-1].x != rPoints[0].x || rPoints[nPoints-1].y != rPoints[0].y ) 421cdf0e10cSrcweir drawLine( rPoints[nPoints-1].x, rPoints[nPoints-1].y, rPoints[0].x, rPoints[0].y ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 426cdf0e10cSrcweir // Dithern: Calculate a dither-pixmap and make a brush of it 427cdf0e10cSrcweir #define P_DELTA 51 428cdf0e10cSrcweir #define DMAP( v, m ) ((v % P_DELTA) > m ? (v / P_DELTA) + 1 : (v / P_DELTA)) 429cdf0e10cSrcweir 430cdf0e10cSrcweir BOOL X11SalGraphics::GetDitherPixmap( SalColor nSalColor ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir static const short nOrdDither8Bit[ 8 ][ 8 ] = 433cdf0e10cSrcweir { 434cdf0e10cSrcweir { 0, 38, 9, 48, 2, 40, 12, 50}, 435cdf0e10cSrcweir {25, 12, 35, 22, 28, 15, 37, 24}, 436cdf0e10cSrcweir { 6, 44, 3, 41, 8, 47, 5, 44}, 437cdf0e10cSrcweir {32, 19, 28, 16, 34, 21, 31, 18}, 438cdf0e10cSrcweir { 1, 40, 11, 49, 0, 39, 10, 48}, 439cdf0e10cSrcweir {27, 14, 36, 24, 26, 13, 36, 23}, 440cdf0e10cSrcweir { 8, 46, 4, 43, 7, 45, 4, 42}, 441cdf0e10cSrcweir {33, 20, 30, 17, 32, 20, 29, 16} 442cdf0e10cSrcweir }; 443cdf0e10cSrcweir 444cdf0e10cSrcweir // test for correct depth (8bit) 445cdf0e10cSrcweir if( GetColormap().GetVisual().GetDepth() != 8 ) 446cdf0e10cSrcweir return sal_False; 447cdf0e10cSrcweir 448cdf0e10cSrcweir char pBits[64]; 449cdf0e10cSrcweir char *pBitsPtr = pBits; 450cdf0e10cSrcweir 451cdf0e10cSrcweir // Set the pallette-entries for the dithering tile 452cdf0e10cSrcweir sal_uInt8 nSalColorRed = SALCOLOR_RED ( nSalColor ); 453cdf0e10cSrcweir sal_uInt8 nSalColorGreen = SALCOLOR_GREEN ( nSalColor ); 454cdf0e10cSrcweir sal_uInt8 nSalColorBlue = SALCOLOR_BLUE ( nSalColor ); 455cdf0e10cSrcweir 456cdf0e10cSrcweir for( int nY = 0; nY < 8; nY++ ) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir for( int nX = 0; nX < 8; nX++ ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir short nMagic = nOrdDither8Bit[nY][nX]; 461cdf0e10cSrcweir sal_uInt8 nR = P_DELTA * DMAP( nSalColorRed, nMagic ); 462cdf0e10cSrcweir sal_uInt8 nG = P_DELTA * DMAP( nSalColorGreen, nMagic ); 463cdf0e10cSrcweir sal_uInt8 nB = P_DELTA * DMAP( nSalColorBlue, nMagic ); 464cdf0e10cSrcweir 465cdf0e10cSrcweir *pBitsPtr++ = GetColormap().GetPixel( MAKE_SALCOLOR( nR, nG, nB ) ); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir // create the tile as ximage and an according pixmap -> caching 470cdf0e10cSrcweir XImage *pImage = XCreateImage( GetXDisplay(), 471cdf0e10cSrcweir GetColormap().GetXVisual(), 472cdf0e10cSrcweir 8, 473cdf0e10cSrcweir ZPixmap, 474cdf0e10cSrcweir 0, // offset 475cdf0e10cSrcweir pBits, // data 476cdf0e10cSrcweir 8, 8, // width & height 477cdf0e10cSrcweir 8, // bitmap_pad 478cdf0e10cSrcweir 0 ); // (default) bytes_per_line 479cdf0e10cSrcweir 480cdf0e10cSrcweir if ( GetDisplay()->GetProperties() & PROPERTY_BUG_Tile ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir if (hBrush_) 483cdf0e10cSrcweir XFreePixmap (GetXDisplay(), hBrush_); 484cdf0e10cSrcweir hBrush_ = XCreatePixmap( GetXDisplay(), GetDrawable(), 8, 8, 8 ); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir else 487cdf0e10cSrcweir if( !hBrush_ ) 488cdf0e10cSrcweir hBrush_ = XCreatePixmap( GetXDisplay(), GetDrawable(), 8, 8, 8 ); 489cdf0e10cSrcweir 490cdf0e10cSrcweir // put the ximage to the pixmap 491cdf0e10cSrcweir XPutImage( GetXDisplay(), 492cdf0e10cSrcweir hBrush_, 493cdf0e10cSrcweir GetDisplay()->GetCopyGC( m_nScreen ), 494cdf0e10cSrcweir pImage, 495cdf0e10cSrcweir 0, 0, // Source 496cdf0e10cSrcweir 0, 0, // Destination 497cdf0e10cSrcweir 8, 8 ); // width & height 498cdf0e10cSrcweir 499cdf0e10cSrcweir // destroy image-frame but not palette-data 500cdf0e10cSrcweir pImage->data = NULL; 501cdf0e10cSrcweir XDestroyImage( pImage ); 502cdf0e10cSrcweir 503cdf0e10cSrcweir return sal_True; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 507cdf0e10cSrcweir void X11SalGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY ) // const 508cdf0e10cSrcweir { 509cdf0e10cSrcweir const SalDisplay *pDisplay = GetDisplay(); 510cdf0e10cSrcweir 511cdf0e10cSrcweir rDPIX = pDisplay->GetResolution().A(); 512cdf0e10cSrcweir rDPIY = pDisplay->GetResolution().B(); 513cdf0e10cSrcweir if( !pDisplay->GetExactResolution() && rDPIY < 96 ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir rDPIX = Divide( rDPIX * 96, rDPIY ); 516cdf0e10cSrcweir rDPIY = 96; 517cdf0e10cSrcweir } 518cdf0e10cSrcweir else if ( rDPIY > 200 ) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir rDPIX = Divide( rDPIX * 200, rDPIY ); 521cdf0e10cSrcweir rDPIY = 200; 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir // #i12705# equalize x- and y-resolution if they are close enough 525cdf0e10cSrcweir if( rDPIX != rDPIY ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir // different x- and y- resolutions are usually artifacts of 528cdf0e10cSrcweir // a wrongly calculated screen size. 529cdf0e10cSrcweir //if( (13*rDPIX >= 10*rDPIY) && (13*rDPIY >= 10*rDPIX) ) //+-30% 530cdf0e10cSrcweir { 531cdf0e10cSrcweir #ifdef DEBUG 532cdf0e10cSrcweir printf("Forcing Resolution from %" SAL_PRIdINT32 "x%" SAL_PRIdINT32 " to %" SAL_PRIdINT32 "x%" SAL_PRIdINT32 "\n", 533cdf0e10cSrcweir rDPIX,rDPIY,rDPIY,rDPIY); 534cdf0e10cSrcweir #endif 535cdf0e10cSrcweir rDPIX = rDPIY; // y-resolution is more trustworthy 536cdf0e10cSrcweir } 537cdf0e10cSrcweir } 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 541cdf0e10cSrcweir sal_uInt16 X11SalGraphics::GetBitCount() // const 542cdf0e10cSrcweir { 543cdf0e10cSrcweir return GetVisual().GetDepth(); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir 546cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 547cdf0e10cSrcweir long X11SalGraphics::GetGraphicsWidth() const 548cdf0e10cSrcweir { 549cdf0e10cSrcweir if( m_pFrame ) 550cdf0e10cSrcweir return m_pFrame->maGeometry.nWidth; 551cdf0e10cSrcweir else if( m_pVDev ) 552cdf0e10cSrcweir return m_pVDev->GetWidth(); 553cdf0e10cSrcweir else 554cdf0e10cSrcweir return 0; 555cdf0e10cSrcweir } 556cdf0e10cSrcweir 557cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 558cdf0e10cSrcweir long X11SalGraphics::GetGraphicsHeight() const 559cdf0e10cSrcweir { 560cdf0e10cSrcweir if( m_pFrame ) 561cdf0e10cSrcweir return m_pFrame->maGeometry.nHeight; 562cdf0e10cSrcweir else if( m_pVDev ) 563cdf0e10cSrcweir return m_pVDev->GetHeight(); 564cdf0e10cSrcweir else 565cdf0e10cSrcweir return 0; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 569cdf0e10cSrcweir void X11SalGraphics::ResetClipRegion() 570cdf0e10cSrcweir { 571cdf0e10cSrcweir if( mpClipRegion ) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir bPenGC_ = sal_False; 574cdf0e10cSrcweir bFontGC_ = sal_False; 575cdf0e10cSrcweir bBrushGC_ = sal_False; 576cdf0e10cSrcweir bMonoGC_ = sal_False; 577cdf0e10cSrcweir bCopyGC_ = sal_False; 578cdf0e10cSrcweir bInvertGC_ = sal_False; 579cdf0e10cSrcweir bInvert50GC_ = sal_False; 580cdf0e10cSrcweir bStippleGC_ = sal_False; 581cdf0e10cSrcweir bTrackingGC_ = sal_False; 582cdf0e10cSrcweir 583cdf0e10cSrcweir XDestroyRegion( mpClipRegion ); 584cdf0e10cSrcweir mpClipRegion = NULL; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir bool X11SalGraphics::setClipRegion( const Region& i_rClip ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir if( mpClipRegion ) 591cdf0e10cSrcweir XDestroyRegion( mpClipRegion ); 592cdf0e10cSrcweir mpClipRegion = XCreateRegion(); 593cdf0e10cSrcweir 594cdf0e10cSrcweir ImplRegionInfo aInfo; 595cdf0e10cSrcweir long nX, nY, nW, nH; 596cdf0e10cSrcweir bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH ); 597cdf0e10cSrcweir while( bRegionRect ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir if ( nW && nH ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir XRectangle aRect; 602cdf0e10cSrcweir aRect.x = (short)nX; 603cdf0e10cSrcweir aRect.y = (short)nY; 604cdf0e10cSrcweir aRect.width = (unsigned short)nW; 605cdf0e10cSrcweir aRect.height = (unsigned short)nH; 606cdf0e10cSrcweir 607cdf0e10cSrcweir XUnionRectWithRegion( &aRect, mpClipRegion, mpClipRegion ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH ); 610cdf0e10cSrcweir } 611cdf0e10cSrcweir 612cdf0e10cSrcweir // done, invalidate GCs 613cdf0e10cSrcweir bPenGC_ = sal_False; 614cdf0e10cSrcweir bFontGC_ = sal_False; 615cdf0e10cSrcweir bBrushGC_ = sal_False; 616cdf0e10cSrcweir bMonoGC_ = sal_False; 617cdf0e10cSrcweir bCopyGC_ = sal_False; 618cdf0e10cSrcweir bInvertGC_ = sal_False; 619cdf0e10cSrcweir bInvert50GC_ = sal_False; 620cdf0e10cSrcweir bStippleGC_ = sal_False; 621cdf0e10cSrcweir bTrackingGC_ = sal_False; 622cdf0e10cSrcweir 623cdf0e10cSrcweir if( XEmptyRegion( mpClipRegion ) ) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir XDestroyRegion( mpClipRegion ); 626cdf0e10cSrcweir mpClipRegion= NULL; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir return true; 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 632cdf0e10cSrcweir void X11SalGraphics::SetLineColor() 633cdf0e10cSrcweir { 634cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir nPenColor_ = SALCOLOR_NONE; 637cdf0e10cSrcweir bPenGC_ = sal_False; 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 642cdf0e10cSrcweir void X11SalGraphics::SetLineColor( SalColor nSalColor ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir if( nPenColor_ != nSalColor ) 645cdf0e10cSrcweir { 646cdf0e10cSrcweir nPenColor_ = nSalColor; 647cdf0e10cSrcweir nPenPixel_ = GetPixel( nSalColor ); 648cdf0e10cSrcweir bPenGC_ = sal_False; 649cdf0e10cSrcweir } 650cdf0e10cSrcweir } 651cdf0e10cSrcweir 652cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 653cdf0e10cSrcweir void X11SalGraphics::SetFillColor() 654cdf0e10cSrcweir { 655cdf0e10cSrcweir if( nBrushColor_ != SALCOLOR_NONE ) 656cdf0e10cSrcweir { 657cdf0e10cSrcweir bDitherBrush_ = sal_False; 658cdf0e10cSrcweir nBrushColor_ = SALCOLOR_NONE; 659cdf0e10cSrcweir bBrushGC_ = sal_False; 660cdf0e10cSrcweir } 661cdf0e10cSrcweir } 662cdf0e10cSrcweir 663cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 664cdf0e10cSrcweir void X11SalGraphics::SetFillColor( SalColor nSalColor ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir if( nBrushColor_ != nSalColor ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir bDitherBrush_ = sal_False; 669cdf0e10cSrcweir nBrushColor_ = nSalColor; 670cdf0e10cSrcweir nBrushPixel_ = GetPixel( nSalColor ); 671cdf0e10cSrcweir if( TrueColor != GetColormap().GetVisual().GetClass() 672cdf0e10cSrcweir && GetColormap().GetColor( nBrushPixel_ ) != nBrushColor_ 673cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0x00 ) // black 674cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0x80 ) // blue 675cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0x80, 0x00 ) // green 676cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0x80, 0x80 ) // cyan 677cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x80, 0x00, 0x00 ) // red 678cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x80, 0x00, 0x80 ) // magenta 679cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x80, 0x80, 0x00 ) // brown 680cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x80, 0x80, 0x80 ) // gray 681cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0xC0, 0xC0, 0xC0 ) // light gray 682cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0x00, 0xFF ) // light blue 683cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0xFF, 0x00 ) // light green 684cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0x00, 0xFF, 0xFF ) // light cyan 685cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0xFF, 0x00, 0x00 ) // light red 686cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0xFF, 0x00, 0xFF ) // light magenta 687cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0xFF, 0xFF, 0x00 ) // light brown 688cdf0e10cSrcweir && nSalColor != MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ) ) 689cdf0e10cSrcweir bDitherBrush_ = GetDitherPixmap(nSalColor); 690cdf0e10cSrcweir bBrushGC_ = sal_False; 691cdf0e10cSrcweir } 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 695cdf0e10cSrcweir void X11SalGraphics::SetROPLineColor( SalROPColor nROPColor ) 696cdf0e10cSrcweir { 697cdf0e10cSrcweir switch( nROPColor ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir case SAL_ROP_0 : // 0 700cdf0e10cSrcweir nPenPixel_ = (Pixel)0; 701cdf0e10cSrcweir break; 702cdf0e10cSrcweir case SAL_ROP_1 : // 1 703cdf0e10cSrcweir nPenPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1; 704cdf0e10cSrcweir break; 705cdf0e10cSrcweir case SAL_ROP_INVERT : // 2 706cdf0e10cSrcweir nPenPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1; 707cdf0e10cSrcweir break; 708cdf0e10cSrcweir } 709cdf0e10cSrcweir nPenColor_ = GetColormap().GetColor( nPenPixel_ ); 710cdf0e10cSrcweir bPenGC_ = sal_False; 711cdf0e10cSrcweir } 712cdf0e10cSrcweir 713cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 714cdf0e10cSrcweir void X11SalGraphics::SetROPFillColor( SalROPColor nROPColor ) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir switch( nROPColor ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir case SAL_ROP_0 : // 0 719cdf0e10cSrcweir nBrushPixel_ = (Pixel)0; 720cdf0e10cSrcweir break; 721cdf0e10cSrcweir case SAL_ROP_1 : // 1 722cdf0e10cSrcweir nBrushPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1; 723cdf0e10cSrcweir break; 724cdf0e10cSrcweir case SAL_ROP_INVERT : // 2 725cdf0e10cSrcweir nBrushPixel_ = (Pixel)(1 << GetVisual().GetDepth()) - 1; 726cdf0e10cSrcweir break; 727cdf0e10cSrcweir } 728cdf0e10cSrcweir bDitherBrush_ = sal_False; 729cdf0e10cSrcweir nBrushColor_ = GetColormap().GetColor( nBrushPixel_ ); 730cdf0e10cSrcweir bBrushGC_ = sal_False; 731cdf0e10cSrcweir } 732cdf0e10cSrcweir 733cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 734cdf0e10cSrcweir void X11SalGraphics::SetXORMode( bool bSet, bool ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir if( !bXORMode_ == bSet ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir bXORMode_ = bSet; 739cdf0e10cSrcweir bPenGC_ = sal_False; 740cdf0e10cSrcweir bFontGC_ = sal_False; 741cdf0e10cSrcweir bBrushGC_ = sal_False; 742cdf0e10cSrcweir bMonoGC_ = sal_False; 743cdf0e10cSrcweir bCopyGC_ = sal_False; 744cdf0e10cSrcweir bInvertGC_ = sal_False; 745cdf0e10cSrcweir bInvert50GC_ = sal_False; 746cdf0e10cSrcweir bStippleGC_ = sal_False; 747cdf0e10cSrcweir bTrackingGC_ = sal_False; 748cdf0e10cSrcweir } 749cdf0e10cSrcweir } 750cdf0e10cSrcweir 751cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 752cdf0e10cSrcweir void X11SalGraphics::drawPixel( long nX, long nY ) 753cdf0e10cSrcweir { 754cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 755cdf0e10cSrcweir XDrawPoint( GetXDisplay(), GetDrawable(), SelectPen(), nX, nY ); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir void X11SalGraphics::drawPixel( long nX, long nY, SalColor nSalColor ) 759cdf0e10cSrcweir { 760cdf0e10cSrcweir if( nSalColor != SALCOLOR_NONE ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir Display *pDisplay = GetXDisplay(); 763cdf0e10cSrcweir 764cdf0e10cSrcweir if( (nPenColor_ == SALCOLOR_NONE) && !bPenGC_ ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir SetLineColor( nSalColor ); 767cdf0e10cSrcweir XDrawPoint( pDisplay, GetDrawable(), SelectPen(), nX, nY ); 768cdf0e10cSrcweir nPenColor_ = SALCOLOR_NONE; 769cdf0e10cSrcweir bPenGC_ = False; 770cdf0e10cSrcweir } 771cdf0e10cSrcweir else 772cdf0e10cSrcweir { 773cdf0e10cSrcweir GC pGC = SelectPen(); 774cdf0e10cSrcweir 775cdf0e10cSrcweir if( nSalColor != nPenColor_ ) 776cdf0e10cSrcweir XSetForeground( pDisplay, pGC, GetPixel( nSalColor ) ); 777cdf0e10cSrcweir 778cdf0e10cSrcweir XDrawPoint( pDisplay, GetDrawable(), pGC, nX, nY ); 779cdf0e10cSrcweir 780cdf0e10cSrcweir if( nSalColor != nPenColor_ ) 781cdf0e10cSrcweir XSetForeground( pDisplay, pGC, nPenPixel_ ); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir } 784cdf0e10cSrcweir } 785cdf0e10cSrcweir 786cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 787cdf0e10cSrcweir void X11SalGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir if ( GetDisplay()->GetProperties() & PROPERTY_BUG_DrawLine ) 792cdf0e10cSrcweir { 793cdf0e10cSrcweir GC aGC = SelectPen(); 794cdf0e10cSrcweir XDrawPoint (GetXDisplay(), GetDrawable(), aGC, (int)nX1, (int)nY1); 795cdf0e10cSrcweir XDrawPoint (GetXDisplay(), GetDrawable(), aGC, (int)nX2, (int)nY2); 796cdf0e10cSrcweir XDrawLine (GetXDisplay(), GetDrawable(), aGC, nX1, nY1, nX2, nY2 ); 797cdf0e10cSrcweir } 798cdf0e10cSrcweir else 799cdf0e10cSrcweir XDrawLine( GetXDisplay(), GetDrawable(),SelectPen(), 800cdf0e10cSrcweir nX1, nY1, nX2, nY2 ); 801cdf0e10cSrcweir } 802cdf0e10cSrcweir } 803cdf0e10cSrcweir 804cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 805cdf0e10cSrcweir void X11SalGraphics::drawRect( long nX, long nY, long nDX, long nDY ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir if( nBrushColor_ != SALCOLOR_NONE ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir XFillRectangle( GetXDisplay(), 810cdf0e10cSrcweir GetDrawable(), 811cdf0e10cSrcweir SelectBrush(), 812cdf0e10cSrcweir nX, nY, nDX, nDY ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir // Beschreibung DrawRect verkehrt, deshalb -1 815cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 816cdf0e10cSrcweir XDrawRectangle( GetXDisplay(), 817cdf0e10cSrcweir GetDrawable(), 818cdf0e10cSrcweir SelectPen(), 819cdf0e10cSrcweir nX, nY, nDX-1, nDY-1 ); 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 823cdf0e10cSrcweir void X11SalGraphics::drawPolyLine( sal_uLong nPoints, const SalPoint *pPtAry ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir drawPolyLine( nPoints, pPtAry, false ); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir 828cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 829cdf0e10cSrcweir void X11SalGraphics::drawPolyLine( sal_uLong nPoints, const SalPoint *pPtAry, bool bClose ) 830cdf0e10cSrcweir { 8310d3f51feSHerbert Dürr if( nPenColor_ != SALCOLOR_NONE) 832cdf0e10cSrcweir { 833cdf0e10cSrcweir SalPolyLine Points( nPoints, pPtAry ); 834cdf0e10cSrcweir 835cdf0e10cSrcweir DrawLines( nPoints, Points, SelectPen(), bClose ); 836cdf0e10cSrcweir } 837cdf0e10cSrcweir } 838cdf0e10cSrcweir 839cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 840cdf0e10cSrcweir void X11SalGraphics::drawPolygon( sal_uLong nPoints, const SalPoint* pPtAry ) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir if( nPoints == 0 ) 843cdf0e10cSrcweir return; 844cdf0e10cSrcweir 845cdf0e10cSrcweir if( nPoints < 3 ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir if( !bXORMode_ ) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir if( 1 == nPoints ) 850cdf0e10cSrcweir drawPixel( pPtAry[0].mnX, pPtAry[0].mnY ); 851cdf0e10cSrcweir else 852cdf0e10cSrcweir drawLine( pPtAry[0].mnX, pPtAry[0].mnY, 853cdf0e10cSrcweir pPtAry[1].mnX, pPtAry[1].mnY ); 854cdf0e10cSrcweir } 855cdf0e10cSrcweir return; 856cdf0e10cSrcweir } 857cdf0e10cSrcweir 858cdf0e10cSrcweir SalPolyLine Points( nPoints, pPtAry ); 859cdf0e10cSrcweir 860cdf0e10cSrcweir nPoints++; 861cdf0e10cSrcweir 862cdf0e10cSrcweir /* WORKAROUND: some Xservers (Xorg, VIA chipset in this case) 863cdf0e10cSrcweir * do not draw the visible part of a polygon 864cdf0e10cSrcweir * if it overlaps to the left of screen 0,y. 865cdf0e10cSrcweir * This happens to be the case in the gradient drawn in the 866cdf0e10cSrcweir * menubar background. workaround for the special case of 867cdf0e10cSrcweir * of a rectangle overlapping to the left. 868cdf0e10cSrcweir */ 869cdf0e10cSrcweir if( nPoints == 5 && 870cdf0e10cSrcweir Points[ 0 ].x == Points[ 1 ].x && 871cdf0e10cSrcweir Points[ 1 ].y == Points[ 2 ].y && 872cdf0e10cSrcweir Points[ 2 ].x == Points[ 3 ].x && 873cdf0e10cSrcweir Points[ 0 ].x == Points[ 4 ].x && Points[ 0 ].y == Points[ 4 ].y 874cdf0e10cSrcweir ) 875cdf0e10cSrcweir { 876cdf0e10cSrcweir bool bLeft = false; 877cdf0e10cSrcweir bool bRight = false; 878cdf0e10cSrcweir for(unsigned int i = 0; i < nPoints; i++ ) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir if( Points[i].x < 0 ) 881cdf0e10cSrcweir bLeft = true; 882cdf0e10cSrcweir else 883cdf0e10cSrcweir bRight= true; 884cdf0e10cSrcweir } 885cdf0e10cSrcweir if( bLeft && ! bRight ) 886cdf0e10cSrcweir return; 887cdf0e10cSrcweir if( bLeft && bRight ) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir for( unsigned int i = 0; i < nPoints; i++ ) 890cdf0e10cSrcweir if( Points[i].x < 0 ) 891cdf0e10cSrcweir Points[i].x = 0; 892cdf0e10cSrcweir } 893cdf0e10cSrcweir } 894cdf0e10cSrcweir 895cdf0e10cSrcweir if( nBrushColor_ != SALCOLOR_NONE ) 896cdf0e10cSrcweir XFillPolygon( GetXDisplay(), 897cdf0e10cSrcweir GetDrawable(), 898cdf0e10cSrcweir SelectBrush(), 899cdf0e10cSrcweir &Points[0], nPoints, 900cdf0e10cSrcweir Complex, CoordModeOrigin ); 901cdf0e10cSrcweir 9020d3f51feSHerbert Dürr if( nPenColor_ != SALCOLOR_NONE) 903cdf0e10cSrcweir DrawLines( nPoints, Points, SelectPen(), true ); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir 906cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 907cdf0e10cSrcweir void X11SalGraphics::drawPolyPolygon( sal_uInt32 nPoly, 908cdf0e10cSrcweir const sal_uInt32 *pPoints, 909cdf0e10cSrcweir PCONSTSALPOINT *pPtAry ) 910cdf0e10cSrcweir { 911cdf0e10cSrcweir if( nBrushColor_ != SALCOLOR_NONE ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir sal_uInt32 i, n; 914cdf0e10cSrcweir XLIB_Region pXRegA = NULL; 915cdf0e10cSrcweir 916cdf0e10cSrcweir for( i = 0; i < nPoly; i++ ) { 917cdf0e10cSrcweir n = pPoints[i]; 918cdf0e10cSrcweir SalPolyLine Points( n, pPtAry[i] ); 919cdf0e10cSrcweir if( n > 2 ) 920cdf0e10cSrcweir { 921cdf0e10cSrcweir XLIB_Region pXRegB = XPolygonRegion( &Points[0], n+1, WindingRule ); 922cdf0e10cSrcweir if( !pXRegA ) 923cdf0e10cSrcweir pXRegA = pXRegB; 924cdf0e10cSrcweir else 925cdf0e10cSrcweir { 926cdf0e10cSrcweir XXorRegion( pXRegA, pXRegB, pXRegA ); 927cdf0e10cSrcweir XDestroyRegion( pXRegB ); 928cdf0e10cSrcweir } 929cdf0e10cSrcweir } 930cdf0e10cSrcweir } 931cdf0e10cSrcweir 932cdf0e10cSrcweir if( pXRegA ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir XRectangle aXRect; 935cdf0e10cSrcweir XClipBox( pXRegA, &aXRect ); 936cdf0e10cSrcweir 937cdf0e10cSrcweir GC pGC = SelectBrush(); 938cdf0e10cSrcweir SetClipRegion( pGC, pXRegA ); // ??? doppelt 939cdf0e10cSrcweir XDestroyRegion( pXRegA ); 940cdf0e10cSrcweir bBrushGC_ = sal_False; 941cdf0e10cSrcweir 942cdf0e10cSrcweir XFillRectangle( GetXDisplay(), 943cdf0e10cSrcweir GetDrawable(), 944cdf0e10cSrcweir pGC, 945cdf0e10cSrcweir aXRect.x, aXRect.y, aXRect.width, aXRect.height ); 946cdf0e10cSrcweir } 947cdf0e10cSrcweir } 948cdf0e10cSrcweir 949cdf0e10cSrcweir if( nPenColor_ != SALCOLOR_NONE ) 950cdf0e10cSrcweir for( sal_uInt32 i = 0; i < nPoly; i++ ) 951cdf0e10cSrcweir drawPolyLine( pPoints[i], pPtAry[i], true ); 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 955cdf0e10cSrcweir 956cdf0e10cSrcweir sal_Bool X11SalGraphics::drawPolyLineBezier( sal_uLong, const SalPoint*, const BYTE* ) 957cdf0e10cSrcweir { 958cdf0e10cSrcweir return sal_False; 959cdf0e10cSrcweir } 960cdf0e10cSrcweir 961cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 962cdf0e10cSrcweir 963cdf0e10cSrcweir sal_Bool X11SalGraphics::drawPolygonBezier( sal_uLong, const SalPoint*, const BYTE* ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir return sal_False; 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 969cdf0e10cSrcweir 970cdf0e10cSrcweir sal_Bool X11SalGraphics::drawPolyPolygonBezier( sal_uInt32, const sal_uInt32*, 971cdf0e10cSrcweir const SalPoint* const*, const BYTE* const* ) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir return sal_False; 974cdf0e10cSrcweir } 975cdf0e10cSrcweir 976cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 977cdf0e10cSrcweir 978cdf0e10cSrcweir void X11SalGraphics::invert( sal_uLong nPoints, 979cdf0e10cSrcweir const SalPoint* pPtAry, 980cdf0e10cSrcweir SalInvert nFlags ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir SalPolyLine Points ( nPoints, pPtAry ); 983cdf0e10cSrcweir 984cdf0e10cSrcweir GC pGC; 985cdf0e10cSrcweir if( SAL_INVERT_50 & nFlags ) 986cdf0e10cSrcweir pGC = GetInvert50GC(); 987cdf0e10cSrcweir else 988cdf0e10cSrcweir if ( SAL_INVERT_TRACKFRAME & nFlags ) 989cdf0e10cSrcweir pGC = GetTrackingGC(); 990cdf0e10cSrcweir else 991cdf0e10cSrcweir pGC = GetInvertGC(); 992cdf0e10cSrcweir 993cdf0e10cSrcweir if( SAL_INVERT_TRACKFRAME & nFlags ) 994cdf0e10cSrcweir DrawLines ( nPoints, Points, pGC, true ); 995cdf0e10cSrcweir else 996cdf0e10cSrcweir XFillPolygon( GetXDisplay(), 997cdf0e10cSrcweir GetDrawable(), 998cdf0e10cSrcweir pGC, 999cdf0e10cSrcweir &Points[0], nPoints, 1000cdf0e10cSrcweir Complex, CoordModeOrigin ); 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir BOOL X11SalGraphics::drawEPS( long,long,long,long,void*,sal_uLong ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir return sal_False; 1008cdf0e10cSrcweir } 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir XID X11SalGraphics::GetXRenderPicture() 1013cdf0e10cSrcweir { 1014cdf0e10cSrcweir XRenderPeer& rRenderPeer = XRenderPeer::GetInstance(); 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir if( !m_aRenderPicture ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir // check xrender support for matching visual 1019cdf0e10cSrcweir // find a XRenderPictFormat compatible with the Drawable 1020cdf0e10cSrcweir XRenderPictFormat* pVisualFormat = static_cast<XRenderPictFormat*>(GetXRenderFormat()); 1021cdf0e10cSrcweir if( !pVisualFormat ) 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir Visual* pVisual = GetDisplay()->GetVisual( m_nScreen ).GetVisual(); 1024cdf0e10cSrcweir pVisualFormat = rRenderPeer.FindVisualFormat( pVisual ); 1025cdf0e10cSrcweir if( !pVisualFormat ) 1026cdf0e10cSrcweir return 0; 1027cdf0e10cSrcweir // cache the XRenderPictFormat 1028cdf0e10cSrcweir SetXRenderFormat( static_cast<void*>(pVisualFormat) ); 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir // get the matching xrender target for drawable 1032cdf0e10cSrcweir m_aRenderPicture = rRenderPeer.CreatePicture( hDrawable_, pVisualFormat, 0, NULL ); 1033cdf0e10cSrcweir } 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir #if 0 1036cdf0e10cSrcweir // setup clipping so the callers don't have to do it themselves 1037cdf0e10cSrcweir // TODO: avoid clipping if already set correctly 1038cdf0e10cSrcweir if( mpClipRegion && !XEmptyRegion( mpClipRegion ) ) 1039cdf0e10cSrcweir rRenderPeer.SetPictureClipRegion( aDstPic, mpClipRegion ); 1040cdf0e10cSrcweir else 1041cdf0e10cSrcweir #endif 1042cdf0e10cSrcweir { 1043cdf0e10cSrcweir // reset clip region 1044cdf0e10cSrcweir // TODO: avoid clip reset if already done 1045cdf0e10cSrcweir XRenderPictureAttributes aAttr; 1046cdf0e10cSrcweir aAttr.clip_mask = None; 1047cdf0e10cSrcweir rRenderPeer.ChangePicture( m_aRenderPicture, CPClipMask, &aAttr ); 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir return m_aRenderPicture; 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir SystemGraphicsData X11SalGraphics::GetGraphicsData() const 1056cdf0e10cSrcweir { 1057cdf0e10cSrcweir SystemGraphicsData aRes; 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir aRes.nSize = sizeof(aRes); 1060cdf0e10cSrcweir aRes.pDisplay = GetXDisplay(); 1061cdf0e10cSrcweir aRes.hDrawable = hDrawable_; 1062cdf0e10cSrcweir aRes.pVisual = GetDisplay()->GetVisual( m_nScreen ).GetVisual(); 1063cdf0e10cSrcweir aRes.nScreen = m_nScreen; 1064cdf0e10cSrcweir aRes.nDepth = GetDisplay()->GetVisual( m_nScreen ).GetDepth(); 1065cdf0e10cSrcweir aRes.aColormap = GetDisplay()->GetColormap( m_nScreen ).GetXColormap(); 1066cdf0e10cSrcweir aRes.pRenderFormat = m_pRenderFormat; 1067cdf0e10cSrcweir return aRes; 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1071cdf0e10cSrcweir 1072cdf0e10cSrcweir // draw a poly-polygon 1073cdf0e10cSrcweir bool X11SalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rOrigPolyPoly, double fTransparency ) 1074cdf0e10cSrcweir { 1075cdf0e10cSrcweir // nothing to do for empty polypolygons 1076cdf0e10cSrcweir const int nOrigPolyCount = rOrigPolyPoly.count(); 1077cdf0e10cSrcweir if( nOrigPolyCount <= 0 ) 1078cdf0e10cSrcweir return sal_True; 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir // nothing to do if everything is transparent 1081cdf0e10cSrcweir if( (nBrushColor_ == SALCOLOR_NONE) 1082cdf0e10cSrcweir && (nPenColor_ == SALCOLOR_NONE) ) 1083cdf0e10cSrcweir return sal_True; 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir // cannot handle pencolor!=brushcolor yet 1086cdf0e10cSrcweir if( (nPenColor_ != SALCOLOR_NONE) 1087cdf0e10cSrcweir && (nPenColor_ != nBrushColor_) ) 1088cdf0e10cSrcweir return sal_False; 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir // TODO: remove the env-variable when no longer needed 1091cdf0e10cSrcweir static const char* pRenderEnv = getenv( "SAL_DISABLE_RENDER_POLY" ); 1092cdf0e10cSrcweir if( pRenderEnv ) 1093cdf0e10cSrcweir return sal_False; 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir // snap to raster if requested 1096cdf0e10cSrcweir basegfx::B2DPolyPolygon aPolyPoly = rOrigPolyPoly; 1097cdf0e10cSrcweir const bool bSnapToRaster = !getAntiAliasB2DDraw(); 1098cdf0e10cSrcweir if( bSnapToRaster ) 1099cdf0e10cSrcweir aPolyPoly = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges( aPolyPoly ); 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir // don't bother with polygons outside of visible area 1102cdf0e10cSrcweir const basegfx::B2DRange aViewRange( 0, 0, GetGraphicsWidth(), GetGraphicsHeight() ); 1103cdf0e10cSrcweir aPolyPoly = basegfx::tools::clipPolyPolygonOnRange( aPolyPoly, aViewRange, true, false ); 1104cdf0e10cSrcweir if( !aPolyPoly.count() ) 1105cdf0e10cSrcweir return true; 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir // tesselate the polypolygon into trapezoids 1108cdf0e10cSrcweir basegfx::B2DTrapezoidVector aB2DTrapVector; 1109cdf0e10cSrcweir basegfx::tools::trapezoidSubdivide( aB2DTrapVector, aPolyPoly ); 1110cdf0e10cSrcweir const int nTrapCount = aB2DTrapVector.size(); 1111cdf0e10cSrcweir if( !nTrapCount ) 1112cdf0e10cSrcweir return true; 1113cdf0e10cSrcweir const bool bDrawn = drawFilledTrapezoids( &aB2DTrapVector[0], nTrapCount, fTransparency ); 1114cdf0e10cSrcweir return bDrawn; 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir bool X11SalGraphics::drawFilledTrapezoids( const ::basegfx::B2DTrapezoid* pB2DTraps, int nTrapCount, double fTransparency ) 1120cdf0e10cSrcweir { 1121cdf0e10cSrcweir if( nTrapCount <= 0 ) 1122cdf0e10cSrcweir return true; 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir Picture aDstPic = GetXRenderPicture(); 1125cdf0e10cSrcweir // check xrender support for this drawable 1126cdf0e10cSrcweir if( !aDstPic ) 1127cdf0e10cSrcweir return false; 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir // convert the B2DTrapezoids into XRender-Trapezoids 1130cdf0e10cSrcweir typedef std::vector<XTrapezoid> TrapezoidVector; 1131cdf0e10cSrcweir TrapezoidVector aTrapVector( nTrapCount ); 1132cdf0e10cSrcweir const basegfx::B2DTrapezoid* pB2DTrap = pB2DTraps; 1133cdf0e10cSrcweir for( int i = 0; i < nTrapCount; ++pB2DTrap, ++i ) 1134cdf0e10cSrcweir { 1135cdf0e10cSrcweir XTrapezoid& rTrap = aTrapVector[ i ] ; 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir // set y-coordinates 1138cdf0e10cSrcweir const double fY1 = pB2DTrap->getTopY(); 1139cdf0e10cSrcweir rTrap.left.p1.y = rTrap.right.p1.y = rTrap.top = XDoubleToFixed( fY1 ); 1140cdf0e10cSrcweir const double fY2 = pB2DTrap->getBottomY(); 1141cdf0e10cSrcweir rTrap.left.p2.y = rTrap.right.p2.y = rTrap.bottom = XDoubleToFixed( fY2 ); 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir // set x-coordinates 1144cdf0e10cSrcweir const double fXL1 = pB2DTrap->getTopXLeft(); 1145cdf0e10cSrcweir rTrap.left.p1.x = XDoubleToFixed( fXL1 ); 1146cdf0e10cSrcweir const double fXR1 = pB2DTrap->getTopXRight(); 1147cdf0e10cSrcweir rTrap.right.p1.x = XDoubleToFixed( fXR1 ); 1148cdf0e10cSrcweir const double fXL2 = pB2DTrap->getBottomXLeft(); 1149cdf0e10cSrcweir rTrap.left.p2.x = XDoubleToFixed( fXL2 ); 1150cdf0e10cSrcweir const double fXR2 = pB2DTrap->getBottomXRight(); 1151cdf0e10cSrcweir rTrap.right.p2.x = XDoubleToFixed( fXR2 ); 1152cdf0e10cSrcweir } 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir // get xrender Picture for polygon foreground 1155cdf0e10cSrcweir // TODO: cache it like the target picture which uses GetXRenderPicture() 1156cdf0e10cSrcweir XRenderPeer& rRenderPeer = XRenderPeer::GetInstance(); 1157cdf0e10cSrcweir SalDisplay::RenderEntry& rEntry = GetDisplay()->GetRenderEntries( m_nScreen )[ 32 ]; 1158cdf0e10cSrcweir if( !rEntry.m_aPicture ) 1159cdf0e10cSrcweir { 1160cdf0e10cSrcweir Display* pXDisplay = GetXDisplay(); 1161cdf0e10cSrcweir 1162cdf0e10cSrcweir rEntry.m_aPixmap = ::XCreatePixmap( pXDisplay, hDrawable_, 1, 1, 32 ); 1163cdf0e10cSrcweir XRenderPictureAttributes aAttr; 1164cdf0e10cSrcweir aAttr.repeat = true; 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir XRenderPictFormat* pXRPF = rRenderPeer.FindStandardFormat( PictStandardARGB32 ); 1167cdf0e10cSrcweir rEntry.m_aPicture = rRenderPeer.CreatePicture( rEntry.m_aPixmap, pXRPF, CPRepeat, &aAttr ); 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir // set polygon foreground color and opacity 1171cdf0e10cSrcweir XRenderColor aRenderColor = GetXRenderColor( nBrushColor_ , fTransparency ); 1172cdf0e10cSrcweir rRenderPeer.FillRectangle( PictOpSrc, rEntry.m_aPicture, &aRenderColor, 0, 0, 1, 1 ); 1173cdf0e10cSrcweir 1174cdf0e10cSrcweir // set clipping 1175cdf0e10cSrcweir // TODO: move into GetXRenderPicture? 1176cdf0e10cSrcweir if( mpClipRegion && !XEmptyRegion( mpClipRegion ) ) 1177cdf0e10cSrcweir rRenderPeer.SetPictureClipRegion( aDstPic, mpClipRegion ); 1178cdf0e10cSrcweir 1179cdf0e10cSrcweir // render the trapezoids 1180cdf0e10cSrcweir const XRenderPictFormat* pMaskFormat = rRenderPeer.GetStandardFormatA8(); 1181cdf0e10cSrcweir rRenderPeer.CompositeTrapezoids( PictOpOver, 1182cdf0e10cSrcweir rEntry.m_aPicture, aDstPic, pMaskFormat, 0, 0, &aTrapVector[0], aTrapVector.size() ); 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir return true; 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1188cdf0e10cSrcweir 1189cdf0e10cSrcweir bool X11SalGraphics::drawPolyLine(const ::basegfx::B2DPolygon& rPolygon, double fTransparency, const ::basegfx::B2DVector& rLineWidth, basegfx::B2DLineJoin eLineJoin) 1190cdf0e10cSrcweir { 1191cdf0e10cSrcweir const bool bIsHairline = (rLineWidth.getX() == rLineWidth.getY()) && (rLineWidth.getX() <= 1.2); 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir // #i101491# 1194cdf0e10cSrcweir if( !bIsHairline && (rPolygon.count() > 1000) ) 1195cdf0e10cSrcweir { 1196cdf0e10cSrcweir // the used basegfx::tools::createAreaGeometry is simply too 1197cdf0e10cSrcweir // expensive with very big polygons; fallback to caller (who 1198cdf0e10cSrcweir // should use ImplLineConverter normally) 1199cdf0e10cSrcweir // AW: ImplLineConverter had to be removed since it does not even 1200cdf0e10cSrcweir // know LineJoins, so the fallback will now prepare the line geometry 1201cdf0e10cSrcweir // the same way. 1202cdf0e10cSrcweir return false; 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir // temporarily adjust brush color to pen color 1206cdf0e10cSrcweir // since the line is drawn as an area-polygon 1207cdf0e10cSrcweir const SalColor aKeepBrushColor = nBrushColor_; 1208cdf0e10cSrcweir nBrushColor_ = nPenColor_; 1209cdf0e10cSrcweir 1210cdf0e10cSrcweir // #i11575#desc5#b adjust B2D tesselation result to raster positions 1211cdf0e10cSrcweir basegfx::B2DPolygon aPolygon = rPolygon; 1212cdf0e10cSrcweir const double fHalfWidth = 0.5 * rLineWidth.getX(); 1213cdf0e10cSrcweir aPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix(+fHalfWidth,+fHalfWidth) ); 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir // shortcut for hairline drawing to improve performance 1216cdf0e10cSrcweir bool bDrawnOk = true; 1217cdf0e10cSrcweir if( bIsHairline ) 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir // hairlines can benefit from a simplified tesselation 1220cdf0e10cSrcweir // e.g. for hairlines the linejoin style can be ignored 1221cdf0e10cSrcweir basegfx::B2DTrapezoidVector aB2DTrapVector; 1222cdf0e10cSrcweir basegfx::tools::createLineTrapezoidFromB2DPolygon( aB2DTrapVector, aPolygon, rLineWidth.getX() ); 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir // draw tesselation result 1225cdf0e10cSrcweir const int nTrapCount = aB2DTrapVector.size(); 1226cdf0e10cSrcweir if( nTrapCount > 0 ) 1227cdf0e10cSrcweir bDrawnOk = drawFilledTrapezoids( &aB2DTrapVector[0], nTrapCount, fTransparency ); 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir // restore the original brush GC 1230cdf0e10cSrcweir nBrushColor_ = aKeepBrushColor; 1231cdf0e10cSrcweir return bDrawnOk; 1232cdf0e10cSrcweir } 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir // get the area polygon for the line polygon 1235cdf0e10cSrcweir if( (rLineWidth.getX() != rLineWidth.getY()) 1236cdf0e10cSrcweir && !basegfx::fTools::equalZero( rLineWidth.getY() ) ) 1237cdf0e10cSrcweir { 1238cdf0e10cSrcweir // prepare for createAreaGeometry() with anisotropic linewidth 1239cdf0e10cSrcweir aPolygon.transform( basegfx::tools::createScaleB2DHomMatrix(1.0, rLineWidth.getX() / rLineWidth.getY())); 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir // create the area-polygon for the line 1243cdf0e10cSrcweir const basegfx::B2DPolyPolygon aAreaPolyPoly( basegfx::tools::createAreaGeometry(aPolygon, fHalfWidth, eLineJoin) ); 1244cdf0e10cSrcweir 1245cdf0e10cSrcweir if( (rLineWidth.getX() != rLineWidth.getY()) 1246cdf0e10cSrcweir && !basegfx::fTools::equalZero( rLineWidth.getX() ) ) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir // postprocess createAreaGeometry() for anisotropic linewidth 1249cdf0e10cSrcweir aPolygon.transform(basegfx::tools::createScaleB2DHomMatrix(1.0, rLineWidth.getY() / rLineWidth.getX())); 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir // draw each area polypolygon component individually 1253cdf0e10cSrcweir // to emulate the polypolygon winding rule "non-zero" 1254cdf0e10cSrcweir const int nPolyCount = aAreaPolyPoly.count(); 1255cdf0e10cSrcweir for( int nPolyIdx = 0; nPolyIdx < nPolyCount; ++nPolyIdx ) 1256cdf0e10cSrcweir { 1257cdf0e10cSrcweir const ::basegfx::B2DPolyPolygon aOnePoly( aAreaPolyPoly.getB2DPolygon( nPolyIdx ) ); 1258cdf0e10cSrcweir bDrawnOk = drawPolyPolygon( aOnePoly, fTransparency ); 1259cdf0e10cSrcweir if( !bDrawnOk ) 1260cdf0e10cSrcweir break; 1261cdf0e10cSrcweir } 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir // restore the original brush GC 1264cdf0e10cSrcweir nBrushColor_ = aKeepBrushColor; 1265cdf0e10cSrcweir return bDrawnOk; 1266cdf0e10cSrcweir } 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1269cdf0e10cSrcweir 1270