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