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