1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SV_SALGDI_H 29 #define _SV_SALGDI_H 30 31 // -=-= includes -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 32 #include "tools/fract.hxx" 33 34 #include "vcl/salgtype.hxx" 35 #include "vcl/vclenum.hxx" 36 37 #include "salstd.hxx" 38 #include "salgdi.hxx" 39 #include "sallayout.hxx" 40 #include "vclpluginapi.h" 41 42 #include <deque> 43 44 // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 45 struct ImplFontMetricData; 46 struct ImplFontSelectData; 47 class SalBitmap; 48 class SalColormap; 49 class SalDisplay; 50 class SalFrame; 51 class X11SalVirtualDevice; 52 class SalPolyLine; 53 class PspSalPrinter; 54 class PspSalInfoPrinter; 55 class ServerFont; 56 class ImplLayoutArgs; 57 class X11FontLayout; 58 class ServerFontLayout; 59 60 namespace basegfx { 61 class B2DTrapezoid; 62 } 63 64 // -=-= SalGraphicsData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 65 66 class CairoFontsCache 67 { 68 private: 69 static int mnRefCount; 70 typedef std::deque< std::pair<void *, void*> > LRUFonts; 71 static LRUFonts maLRUFonts; 72 public: 73 CairoFontsCache(); 74 static void CacheFont(void *pFont, void *pId); 75 static void* FindCachedFont(void *pId); 76 ~CairoFontsCache(); 77 }; 78 79 class VCLPLUG_GEN_PUBLIC X11SalGraphics : public SalGraphics 80 { 81 friend class X11FontLayout; 82 friend class ServerFontLayout; 83 protected: 84 SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL 85 X11SalVirtualDevice* m_pVDev; // the SalVirtualDevice which created this Graphics or NULL 86 87 const SalColormap* m_pColormap; 88 SalColormap *m_pDeleteColormap; 89 Drawable hDrawable_; // use 90 int m_nScreen; 91 void* m_pRenderFormat; 92 XID m_aRenderPicture; 93 CairoFontsCache m_aCairoFontsCache; 94 95 XLIB_Region pPaintRegion_; 96 XLIB_Region mpClipRegion; 97 98 GC pPenGC_; // Pen attributes 99 SalColor nPenColor_; 100 Pixel nPenPixel_; 101 102 GC pFontGC_; // Font attributes 103 ServerFont* mpServerFont[ MAX_FALLBACK ]; 104 105 SalColor nTextColor_; 106 Pixel nTextPixel_; 107 sal_Bool bFontVertical_; 108 109 sal_Bool bDisableGraphite_; 110 111 GC pBrushGC_; // Brush attributes 112 SalColor nBrushColor_; 113 Pixel nBrushPixel_; 114 Pixmap hBrush_; // Dither 115 116 GC pMonoGC_; 117 GC pCopyGC_; 118 GC pMaskGC_; 119 GC pInvertGC_; 120 GC pInvert50GC_; 121 GC pStippleGC_; 122 GC pTrackingGC_; 123 124 sal_Bool bWindow_ : 1; // is Window 125 sal_Bool bPrinter_ : 1; // is Printer 126 sal_Bool bVirDev_ : 1; // is VirDev 127 sal_Bool bPenGC_ : 1; // is Pen GC valid 128 sal_Bool bFontGC_ : 1; // is Font GC valid 129 sal_Bool bBrushGC_ : 1; // is Brush GC valid 130 sal_Bool bMonoGC_ : 1; // is Mono GC valid 131 sal_Bool bCopyGC_ : 1; // is Copy GC valid 132 sal_Bool bInvertGC_ : 1; // is Invert GC valid 133 sal_Bool bInvert50GC_ : 1; // is Invert50 GC valid 134 sal_Bool bStippleGC_ : 1; // is Stipple GC valid 135 sal_Bool bTrackingGC_ : 1; // is Tracking GC valid 136 bool bXORMode_ : 1; // is ROP XOR Mode set 137 sal_Bool bDitherBrush_ : 1; // is solid or tile 138 139 using SalGraphics::SetClipRegion; 140 void SetClipRegion( GC pGC, 141 XLIB_Region pXReg = NULL ) const; 142 143 GC GetTrackingGC(); 144 GC GetInvertGC(); 145 GC GetInvert50GC(); 146 GC CreateGC( Drawable hDrawable, 147 unsigned long nMask = GCGraphicsExposures ); 148 GC SelectPen(); 149 GC SelectBrush(); 150 void DrawLines( sal_uIntPtr nPoints, 151 const SalPolyLine &rPoints, 152 GC pGC, 153 bool bClose 154 ); 155 sal_Bool GetDitherPixmap ( SalColor nSalColor ); 156 157 inline GC GetMonoGC( Pixmap hPixmap ); 158 inline GC GetCopyGC(); 159 inline GC GetStippleGC(); 160 161 int Clip ( XLIB_Region pRegion, 162 int &nX, 163 int &nY, 164 unsigned int &nDX, 165 unsigned int &nDY, 166 int &nSrcX, 167 int &nSrcY ) const; 168 int Clip ( int &nX, 169 int &nY, 170 unsigned int &nDX, 171 unsigned int &nDY, 172 int &nSrcX, 173 int &nSrcY ) const; 174 GC SetMask ( int &nX, 175 int &nY, 176 unsigned int &nDX, 177 unsigned int &nDY, 178 int &nSrcX, 179 int &nSrcY, 180 Pixmap hClipMask ); 181 using SalGraphics::DrawBitmap; 182 void DrawBitmap( const SalTwoRect *pPosAry, 183 SalGraphics *pThis, 184 const SalBitmap &rSalBitmap, 185 const SalBitmap &rTransparentBitmap, 186 SalColor nTransparentColor ); 187 188 GC GetFontGC(); 189 bool setFont( const ImplFontSelectData* pEntry, int nFallbackLevel ); 190 191 void drawMaskedBitmap( const SalTwoRect* pPosAry, 192 const SalBitmap& rSalBitmap, 193 const SalBitmap& rTransparentBitmap ); 194 195 protected: 196 void DrawPrinterString( const SalLayout& ); 197 198 void DrawServerFontString( const ServerFontLayout& ); 199 void DrawServerSimpleFontString( const ServerFontLayout& ); 200 void DrawServerAAFontString( const ServerFontLayout& ); 201 bool DrawServerAAForcedString( const ServerFontLayout& ); 202 void DrawCairoAAFontString( const ServerFontLayout& ); 203 204 void freeResources(); 205 public: 206 X11SalGraphics(); 207 virtual ~X11SalGraphics(); 208 209 void Init( SalFrame *pFrame, Drawable aDrawable, int nScreen ); 210 void Init( X11SalVirtualDevice *pVirtualDevice, SalColormap* pColormap = NULL, bool bDeleteColormap = false ); 211 void Init( class ImplSalPrinterData *pPrinter ); 212 void DeInit(); 213 214 inline const SalDisplay* GetDisplay() const; 215 inline Display* GetXDisplay() const; 216 inline const SalVisual& GetVisual() const; 217 inline Drawable GetDrawable() const { return hDrawable_; } 218 void SetDrawable( Drawable d, int nScreen ); 219 XID GetXRenderPicture(); 220 void* GetXRenderFormat() const { return m_pRenderFormat; } 221 inline void SetXRenderFormat( void* pRenderFormat ) { m_pRenderFormat = pRenderFormat; } 222 inline const SalColormap& GetColormap() const { return *m_pColormap; } 223 using SalGraphics::GetPixel; 224 inline Pixel GetPixel( SalColor nSalColor ) const; 225 226 int GetScreenNumber() const { return m_nScreen; } 227 228 // overload all pure virtual methods 229 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ); 230 virtual sal_uInt16 GetBitCount(); 231 virtual long GetGraphicsWidth() const; 232 virtual long GetGraphicsHeight() const; 233 234 virtual void ResetClipRegion(); 235 virtual bool setClipRegion( const Region& ); 236 237 virtual void SetLineColor(); 238 virtual void SetLineColor( SalColor nSalColor ); 239 virtual void SetFillColor(); 240 241 virtual void SetFillColor( SalColor nSalColor ); 242 243 virtual void SetXORMode( bool bSet, bool ); 244 245 virtual void SetROPLineColor( SalROPColor nROPColor ); 246 virtual void SetROPFillColor( SalROPColor nROPColor ); 247 248 virtual void SetTextColor( SalColor nSalColor ); 249 virtual sal_uInt16 SetFont( ImplFontSelectData*, int nFallbackLevel ); 250 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ); 251 virtual sal_uLong GetKernPairs( sal_uLong nMaxPairs, ImplKernPairData* ); 252 virtual const ImplFontCharMap* GetImplFontCharMap() const; 253 virtual void GetDevFontList( ImplDevFontList* ); 254 virtual void GetDevFontSubstList( OutputDevice* ); 255 virtual bool AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName ); 256 virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile, 257 const ImplFontData*, 258 sal_Int32* pGlyphIDs, 259 sal_uInt8* pEncoding, 260 sal_Int32* pWidths, 261 int nGlyphs, 262 FontSubsetInfo& rInfo 263 ); 264 virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded ); 265 virtual const void* GetEmbedFontData( const ImplFontData*, 266 const sal_Ucs* pUnicodes, 267 sal_Int32* pWidths, 268 FontSubsetInfo& rInfo, 269 long* pDataLen ); 270 virtual void FreeEmbedFontData( const void* pData, long nDataLen ); 271 virtual void GetGlyphWidths( const ImplFontData*, 272 bool bVertical, 273 Int32Vector& rWidths, 274 Ucs2UIntMap& rUnicodeEnc ); 275 virtual sal_Bool GetGlyphBoundRect( long nIndex, Rectangle& ); 276 virtual sal_Bool GetGlyphOutline( long nIndex, ::basegfx::B2DPolyPolygon& ); 277 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ); 278 virtual void DrawServerFontLayout( const ServerFontLayout& ); 279 virtual bool supportsOperation( OutDevSupportType ) const; 280 virtual void drawPixel( long nX, long nY ); 281 virtual void drawPixel( long nX, long nY, SalColor nSalColor ); 282 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ); 283 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ); 284 void drawPolyLine( sal_uIntPtr nPoints, const SalPoint* pPtAry, bool bClose ); 285 virtual void drawPolyLine( sal_uIntPtr nPoints, const SalPoint* pPtAry ); 286 virtual void drawPolygon( sal_uIntPtr nPoints, const SalPoint* pPtAry ); 287 virtual void drawPolyPolygon( sal_uInt32 nPoly, 288 const sal_uInt32* pPoints, 289 PCONSTSALPOINT* pPtAry ); 290 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ); 291 virtual bool drawPolyLine( const ::basegfx::B2DPolygon&, double fTransparency, const ::basegfx::B2DVector& rLineWidth, basegfx::B2DLineJoin ); 292 virtual bool drawFilledTrapezoids( const ::basegfx::B2DTrapezoid*, int nTrapCount, double fTransparency ); 293 294 #if 1 // TODO: remove these obselete methods 295 virtual sal_Bool drawPolyLineBezier( sal_uIntPtr nPoints, 296 const SalPoint* pPtAry, 297 const sal_uInt8* pFlgAry ); 298 virtual sal_Bool drawPolygonBezier( sal_uIntPtr nPoints, 299 const SalPoint* pPtAry, 300 const sal_uInt8* pFlgAry ); 301 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, 302 const sal_uInt32* pPoints, 303 const SalPoint* const* pPtAry, 304 const sal_uInt8* const* pFlgAry ); 305 #endif 306 307 virtual void copyArea( long nDestX, 308 long nDestY, 309 long nSrcX, 310 long nSrcY, 311 long nSrcWidth, 312 long nSrcHeight, 313 sal_uInt16 nFlags ); 314 virtual void copyBits( const SalTwoRect* pPosAry, 315 SalGraphics* pSrcGraphics ); 316 virtual void drawBitmap( const SalTwoRect* pPosAry, 317 const SalBitmap& rSalBitmap ); 318 virtual void drawBitmap( const SalTwoRect* pPosAry, 319 const SalBitmap& rSalBitmap, 320 SalColor nTransparentColor ); 321 virtual void drawBitmap( const SalTwoRect* pPosAry, 322 const SalBitmap& rSalBitmap, 323 const SalBitmap& rMaskBitmap ); 324 virtual void drawMask( const SalTwoRect* pPosAry, 325 const SalBitmap& rSalBitmap, 326 SalColor nMaskColor ); 327 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ); 328 virtual SalColor getPixel( long nX, long nY ); 329 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags ); 330 virtual void invert( sal_uIntPtr nPoints, const SalPoint* pPtAry, SalInvert nFlags ); 331 332 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize ); 333 334 virtual bool drawAlphaBitmap( const SalTwoRect&, 335 const SalBitmap& rSourceBitmap, 336 const SalBitmap& rAlphaBitmap ); 337 338 virtual bool drawAlphaRect( long nX, long nY, long nWidth, 339 long nHeight, sal_uInt8 nTransparency ); 340 341 virtual SystemGraphicsData GetGraphicsData() const; 342 virtual SystemFontData GetSysFontData( int nFallbacklevel ) const; 343 344 /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends 345 * if pFrame is not NULL, corresponding Paint events are generated 346 * and dispatched to pFrame 347 * 348 * it is imperative to eat up graphics exposes even in case you don't need 349 * them because the next one using XCopyArea can depend on them 350 */ 351 void YieldGraphicsExpose(); 352 353 // do XCopyArea or XGet/PutImage depending on screen numbers 354 // signature is like XCopyArea with screen numbers added 355 static void CopyScreenArea( Display* pDisplay, 356 Drawable aSrc, int nScreenSrc, int nSrcDepth, 357 Drawable aDest, int nScreenDest, int nDestDepth, 358 GC aDestGC, 359 int src_x, int src_y, 360 unsigned int w, unsigned int h, 361 int dest_x, int dest_y ); 362 static void releaseGlyphPeer(); 363 }; 364 365 366 inline const SalDisplay *X11SalGraphics::GetDisplay() const 367 { return GetColormap().GetDisplay(); } 368 369 inline const SalVisual& X11SalGraphics::GetVisual() const 370 { return GetColormap().GetVisual(); } 371 372 inline Display *X11SalGraphics::GetXDisplay() const 373 { return GetColormap().GetXDisplay(); } 374 375 inline Pixel X11SalGraphics::GetPixel( SalColor nSalColor ) const 376 { return GetColormap().GetPixel( nSalColor ); } 377 378 379 // -=-= Shortcuts =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 380 381 #ifdef DBG_UTIL 382 #define stderr0( s ) fprintf( stderr, s ) 383 #else 384 #define stderr0( s ) ; 385 #endif 386 387 #endif // _SV_SALGDI_H 388 389