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