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 _SV_SALGDI_H
21 : #define _SV_SALGDI_H
22 :
23 : #include "tools/fract.hxx"
24 :
25 : #include "vcl/salgtype.hxx"
26 : #include "vcl/vclenum.hxx"
27 :
28 : #include "salstd.hxx"
29 : #include "salgdi.hxx"
30 : #include "sallayout.hxx"
31 : #include "vclpluginapi.h"
32 :
33 : #include <deque>
34 :
35 : // -=-= forwards -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 :
50 : namespace basegfx {
51 : class B2DTrapezoid;
52 : }
53 :
54 : // -=-= SalGraphicsData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 : return maFace == rOther.maFace &&
70 : mpOptions == rOther.mpOptions &&
71 : 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 : sal_Bool bFontVertical_;
114 :
115 : sal_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 : sal_Bool bWindow_ : 1; // is Window
131 : sal_Bool bPrinter_ : 1; // is Printer
132 : sal_Bool bVirDev_ : 1; // is VirDev
133 : sal_Bool bPenGC_ : 1; // is Pen GC valid
134 : sal_Bool bFontGC_ : 1; // is Font GC valid
135 : sal_Bool bBrushGC_ : 1; // is Brush GC valid
136 : sal_Bool bMonoGC_ : 1; // is Mono GC valid
137 : sal_Bool bCopyGC_ : 1; // is Copy GC valid
138 : sal_Bool bInvertGC_ : 1; // is Invert GC valid
139 : sal_Bool bInvert50GC_ : 1; // is Invert50 GC valid
140 : sal_Bool bStippleGC_ : 1; // is Stipple GC valid
141 : sal_Bool bTrackingGC_ : 1; // is Tracking GC valid
142 : bool bXORMode_ : 1; // is ROP XOR Mode set
143 : sal_Bool bDitherBrush_ : 1; // is solid or tile
144 :
145 : using SalGraphics::SetClipRegion;
146 : void SetClipRegion( GC pGC,
147 : XLIB_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 : sal_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 *pPosAry,
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* pPosAry,
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 );
212 : virtual sal_uInt16 GetBitCount() const;
213 : virtual long GetGraphicsWidth() const;
214 : virtual long GetGraphicsHeight() const;
215 :
216 : virtual void ResetClipRegion();
217 : virtual bool setClipRegion( const Region& );
218 :
219 : virtual void SetLineColor();
220 : virtual void SetLineColor( SalColor nSalColor );
221 : virtual void SetFillColor();
222 :
223 : virtual void SetFillColor( SalColor nSalColor );
224 :
225 : virtual void SetXORMode( bool bSet, bool );
226 :
227 : virtual void SetROPLineColor( SalROPColor nROPColor );
228 : virtual void SetROPFillColor( SalROPColor nROPColor );
229 :
230 : virtual void SetTextColor( SalColor nSalColor );
231 : virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel );
232 : virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
233 : virtual sal_uLong GetKernPairs( sal_uLong nMaxPairs, ImplKernPairData* );
234 : virtual const ImplFontCharMap* GetImplFontCharMap() const;
235 : virtual bool GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
236 : virtual void GetDevFontList( ImplDevFontList* );
237 : virtual void ClearDevFontCache();
238 : virtual void GetDevFontSubstList( OutputDevice* );
239 : virtual bool AddTempDevFont( ImplDevFontList*, const rtl::OUString& rFileURL, const rtl::OUString& rFontName );
240 : virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile,
241 : const PhysicalFontFace*,
242 : sal_Int32* pGlyphIDs,
243 : sal_uInt8* pEncoding,
244 : sal_Int32* pWidths,
245 : int nGlyphs,
246 : FontSubsetInfo& rInfo
247 : );
248 : virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded );
249 : virtual const void* GetEmbedFontData( const PhysicalFontFace*,
250 : const sal_Ucs* pUnicodes,
251 : sal_Int32* pWidths,
252 : FontSubsetInfo& rInfo,
253 : long* pDataLen );
254 : virtual void FreeEmbedFontData( const void* pData, long nDataLen );
255 : virtual void GetGlyphWidths( const PhysicalFontFace*,
256 : bool bVertical,
257 : Int32Vector& rWidths,
258 : Ucs2UIntMap& rUnicodeEnc );
259 : virtual sal_Bool GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& );
260 : virtual sal_Bool GetGlyphOutline( sal_GlyphId nIndex, ::basegfx::B2DPolyPolygon& );
261 : virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
262 : virtual void DrawServerFontLayout( const ServerFontLayout& );
263 : virtual bool supportsOperation( OutDevSupportType ) const;
264 : virtual void drawPixel( long nX, long nY );
265 : virtual void drawPixel( long nX, long nY, SalColor nSalColor );
266 : virtual void drawLine( long nX1, long nY1, long nX2, long nY2 );
267 : virtual void drawRect( long nX, long nY, long nWidth, long nHeight );
268 : void drawPolyLine( sal_uIntPtr nPoints, const SalPoint* pPtAry, bool bClose );
269 : virtual void drawPolyLine( sal_uIntPtr nPoints, const SalPoint* pPtAry );
270 : virtual void drawPolygon( sal_uIntPtr nPoints, const SalPoint* pPtAry );
271 : virtual void drawPolyPolygon( sal_uInt32 nPoly,
272 : const sal_uInt32* pPoints,
273 : PCONSTSALPOINT* pPtAry );
274 : virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency );
275 : virtual bool drawPolyLine(
276 : const ::basegfx::B2DPolygon&,
277 : double fTransparency,
278 : const ::basegfx::B2DVector& rLineWidth,
279 : basegfx::B2DLineJoin,
280 : com::sun::star::drawing::LineCap);
281 : virtual bool drawFilledTrapezoids( const ::basegfx::B2DTrapezoid*, int nTrapCount, double fTransparency );
282 :
283 : #if 1 // TODO: remove these obselete methods
284 : virtual sal_Bool drawPolyLineBezier( sal_uIntPtr nPoints,
285 : const SalPoint* pPtAry,
286 : const sal_uInt8* pFlgAry );
287 : virtual sal_Bool drawPolygonBezier( sal_uIntPtr nPoints,
288 : const SalPoint* pPtAry,
289 : const sal_uInt8* pFlgAry );
290 : virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly,
291 : const sal_uInt32* pPoints,
292 : const SalPoint* const* pPtAry,
293 : const sal_uInt8* const* pFlgAry );
294 : #endif
295 :
296 : virtual void copyArea( long nDestX,
297 : long nDestY,
298 : long nSrcX,
299 : long nSrcY,
300 : long nSrcWidth,
301 : long nSrcHeight,
302 : sal_uInt16 nFlags );
303 : virtual void copyBits( const SalTwoRect* pPosAry,
304 : SalGraphics* pSrcGraphics );
305 : virtual void drawBitmap( const SalTwoRect* pPosAry,
306 : const SalBitmap& rSalBitmap );
307 : virtual void drawBitmap( const SalTwoRect* pPosAry,
308 : const SalBitmap& rSalBitmap,
309 : SalColor nTransparentColor );
310 : virtual void drawBitmap( const SalTwoRect* pPosAry,
311 : const SalBitmap& rSalBitmap,
312 : const SalBitmap& rMaskBitmap );
313 : virtual void drawMask( const SalTwoRect* pPosAry,
314 : const SalBitmap& rSalBitmap,
315 : SalColor nMaskColor );
316 : virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight );
317 : virtual SalColor getPixel( long nX, long nY );
318 : virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags );
319 : virtual void invert( sal_uIntPtr nPoints, const SalPoint* pPtAry, SalInvert nFlags );
320 :
321 : virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize );
322 :
323 : virtual bool drawAlphaBitmap( const SalTwoRect&,
324 : const SalBitmap& rSourceBitmap,
325 : const SalBitmap& rAlphaBitmap );
326 :
327 : virtual bool drawAlphaRect( long nX, long nY, long nWidth,
328 : long nHeight, sal_uInt8 nTransparency );
329 :
330 : virtual SystemGraphicsData GetGraphicsData() const;
331 : virtual SystemFontData GetSysFontData( int nFallbacklevel ) const;
332 :
333 : /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
334 : * if pFrame is not NULL, corresponding Paint events are generated
335 : * and dispatched to pFrame
336 : *
337 : * it is imperative to eat up graphics exposes even in case you don't need
338 : * them because the next one using XCopyArea can depend on them
339 : */
340 : void YieldGraphicsExpose();
341 :
342 : // do XCopyArea or XGet/PutImage depending on screen numbers
343 : // signature is like XCopyArea with screen numbers added
344 : static void CopyScreenArea( Display* pDisplay,
345 : Drawable aSrc, SalX11Screen nXScreenSrc, int nSrcDepth,
346 : Drawable aDest, SalX11Screen nXScreenDest, int nDestDepth,
347 : GC aDestGC,
348 : int src_x, int src_y,
349 : unsigned int w, unsigned int h,
350 : int dest_x, int dest_y );
351 : static void releaseGlyphPeer();
352 : };
353 :
354 :
355 0 : inline const SalDisplay *X11SalGraphics::GetDisplay() const
356 0 : { return GetColormap().GetDisplay(); }
357 :
358 0 : inline const SalVisual& X11SalGraphics::GetVisual() const
359 0 : { return GetColormap().GetVisual(); }
360 :
361 0 : inline Display *X11SalGraphics::GetXDisplay() const
362 0 : { return GetColormap().GetXDisplay(); }
363 :
364 0 : inline Pixel X11SalGraphics::GetPixel( SalColor nSalColor ) const
365 0 : { return GetColormap().GetPixel( nSalColor ); }
366 :
367 :
368 : // -=-= Shortcuts =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
369 :
370 : #ifdef DBG_UTIL
371 : #define stderr0( s ) fprintf( stderr, s )
372 : #else
373 : #define stderr0( s ) ;
374 : #endif
375 :
376 : #endif // _SV_SALGDI_H
377 :
378 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|