LCOV - code coverage report
Current view: top level - vcl/unx/generic/gdi - salgdi.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 610 0.0 %
Date: 2014-11-03 Functions: 0 50 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10