xref: /AOO41X/main/vcl/inc/unx/salgdi.h (revision 54ae6a3709853714848b4c639248f08787cf46a5)
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 class   ImplFontMetricData;
42 class   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& rPosAry,
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& rPosAry,
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;
GetDrawable()213     inline  Drawable        GetDrawable() const { return hDrawable_; }
214     void                    SetDrawable( Drawable d, int nScreen );
215     XID                     GetXRenderPicture();
GetXRenderFormat()216     void*                   GetXRenderFormat() const { return m_pRenderFormat; }
SetXRenderFormat(void * pRenderFormat)217     inline  void            SetXRenderFormat( void* pRenderFormat ) { m_pRenderFormat = pRenderFormat; }
GetColormap()218     inline  const SalColormap&    GetColormap() const { return *m_pColormap; }
219     using SalGraphics::GetPixel;
220     inline  Pixel           GetPixel( SalColor nSalColor ) const;
221 
GetScreenNumber()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_GlyphId* 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 bool            GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& );
272     virtual bool            GetGlyphOutline( sal_GlyphId 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_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
281     virtual void            drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry );
282     virtual void            drawPolygon( sal_uInt32 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(
288         const ::basegfx::B2DPolygon&,
289         double fTransparency,
290         const ::basegfx::B2DVector& rLineWidth,
291         basegfx::B2DLineJoin,
292         com::sun::star::drawing::LineCap);
293     virtual bool            drawFilledTrapezoids( const ::basegfx::B2DTrapezoid*, int nTrapCount, double fTransparency );
294 
295 #if 1 // TODO: remove these obselete methods
296     virtual sal_Bool        drawPolyLineBezier( sal_uInt32 nPoints,
297                                                 const SalPoint* pPtAry,
298                                                 const sal_uInt8* pFlgAry );
299     virtual sal_Bool        drawPolygonBezier( sal_uInt32 nPoints,
300                                                const SalPoint* pPtAry,
301                                                const sal_uInt8* pFlgAry );
302     virtual sal_Bool        drawPolyPolygonBezier( sal_uInt32 nPoly,
303                                                    const sal_uInt32* pPoints,
304                                                    const SalPoint* const* pPtAry,
305                                                    const sal_uInt8* const* pFlgAry );
306 #endif
307 
308     virtual void            copyArea( long nDestX,
309                                       long nDestY,
310                                       long nSrcX,
311                                       long nSrcY,
312                                       long nSrcWidth,
313                                       long nSrcHeight,
314                                       sal_uInt16 nFlags );
315     virtual void            copyBits( const SalTwoRect& rPosAry,
316                                       SalGraphics* pSrcGraphics );
317     virtual void            drawBitmap( const SalTwoRect& rPosAry,
318                                         const SalBitmap& rSalBitmap );
319     virtual void            drawBitmap( const SalTwoRect& rPosAry,
320                                         const SalBitmap& rSalBitmap,
321                                         SalColor nTransparentColor );
322     virtual void            drawBitmap( const SalTwoRect& rPosAry,
323                                         const SalBitmap& rSalBitmap,
324                                         const SalBitmap& rMaskBitmap );
325     virtual void            drawMask( const SalTwoRect& rPosAry,
326                                       const SalBitmap& rSalBitmap,
327                                       SalColor nMaskColor );
328     virtual SalBitmap*      getBitmap( long nX, long nY, long nWidth, long nHeight );
329     virtual SalColor        getPixel( long nX, long nY );
330     virtual void            invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags );
331     virtual void            invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags );
332 
333     virtual sal_Bool            drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize );
334 
335     virtual bool            drawAlphaBitmap( const SalTwoRect&,
336                                              const SalBitmap& rSourceBitmap,
337                                              const SalBitmap& rAlphaBitmap );
338     virtual bool drawTransformedBitmap(
339         const basegfx::B2DPoint& rNull,
340         const basegfx::B2DPoint& rX,
341         const basegfx::B2DPoint& rY,
342         const SalBitmap& rSourceBitmap,
343         const SalBitmap* pAlphaBitmap);
344 
345     virtual bool            drawAlphaRect( long nX, long nY, long nWidth,
346                                            long nHeight, sal_uInt8 nTransparency );
347 
348     virtual SystemGraphicsData GetGraphicsData() const;
349     virtual SystemFontData     GetSysFontData( int nFallbacklevel ) const;
350 
351     /*  use to handle GraphicsExpose/NoExpose after XCopyArea & friends
352      *  if pFrame is not NULL, corresponding Paint events are generated
353      *  and dispatched to pFrame
354      *
355      *  it is imperative to eat up graphics exposes even in case you don't need
356      *  them because the next one using XCopyArea can depend on them
357      */
358     void YieldGraphicsExpose();
359 
360     // do XCopyArea or XGet/PutImage depending on screen numbers
361     // signature is like XCopyArea with screen numbers added
362     static void CopyScreenArea( Display* pDisplay,
363                                 Drawable aSrc, int nScreenSrc, int nSrcDepth,
364                                 Drawable aDest, int nScreenDest, int nDestDepth,
365                                 GC aDestGC,
366                                 int src_x, int src_y,
367                                 unsigned int w, unsigned int h,
368                                 int dest_x, int dest_y );
369     static void releaseGlyphPeer();
370 };
371 
372 
GetDisplay()373 inline const SalDisplay *X11SalGraphics::GetDisplay() const
374 { return GetColormap().GetDisplay(); }
375 
GetVisual()376 inline const SalVisual& X11SalGraphics::GetVisual() const
377 { return GetColormap().GetVisual(); }
378 
GetXDisplay()379 inline Display *X11SalGraphics::GetXDisplay() const
380 { return GetColormap().GetXDisplay(); }
381 
GetPixel(SalColor nSalColor)382 inline Pixel X11SalGraphics::GetPixel( SalColor nSalColor ) const
383 { return GetColormap().GetPixel( nSalColor ); }
384 
385 
386 // -=-= Shortcuts =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
387 
388 #ifdef DBG_UTIL
389 #define stderr0( s )            fprintf( stderr, s )
390 #else
391 #define stderr0( s )            ;
392 #endif
393 
394 #endif // _SV_SALGDI_H
395 
396