xref: /trunk/main/vcl/inc/win/salgdi.h (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SV_SALGDI_H
29 #define _SV_SALGDI_H
30 
31 #include <sallayout.hxx>
32 #include <salgdi.hxx>
33 #include <outfont.hxx>
34 #include <impfont.hxx>
35 
36 #include "boost/scoped_ptr.hpp"
37 #include <hash_set>
38 
39 class ImplFontSelectData;
40 class ImplWinFontEntry;
41 class ImplFontAttrCache;
42 
43 // -----------
44 // - Defines -
45 // -----------
46 
47 #define RGB_TO_PALRGB(nRGB) 		((nRGB)|0x02000000)
48 #define PALRGB_TO_RGB(nPalRGB)		((nPalRGB)&0x00ffffff)
49 
50 // win32 platform specific options. Move them to the PMK file?
51 
52 #define GCP_KERN_HACK
53 #define GNG_VERT_HACK
54 
55 // win32 specific physically available font face
56 class ImplWinFontData : public ImplFontData
57 {
58 public:
59     explicit                ImplWinFontData( const ImplDevFontAttributes&,
60                                 int nFontHeight, BYTE eWinCharSet,
61                                 BYTE nPitchAndFamily  );
62     virtual                 ~ImplWinFontData();
63 
64     virtual ImplFontData*   Clone() const;
65     virtual ImplFontEntry*  CreateFontInstance( ImplFontSelectData& ) const;
66     virtual sal_IntPtr      GetFontId() const;
67     void                    SetFontId( sal_IntPtr nId ) { mnId = nId; }
68     void                    UpdateFromHDC( HDC ) const;
69 
70     bool                    HasChar( sal_uInt32 cChar ) const;
71 
72     BYTE                GetCharSet() const          { return meWinCharSet; }
73     BYTE                GetPitchAndFamily() const   { return mnPitchAndFamily; }
74     bool                    IsGlyphApiDisabled() const  { return mbDisableGlyphApi; }
75     bool                    SupportsKorean() const      { return mbHasKoreanRange; }
76     bool                    SupportsCJK() const         { return mbHasCJKSupport; }
77     bool                    SupportsArabic() const      { return mbHasArabicSupport; }
78     bool                    AliasSymbolsHigh() const    { return mbAliasSymbolsHigh; }
79     bool                    AliasSymbolsLow() const     { return mbAliasSymbolsLow; }
80 #ifdef ENABLE_GRAPHITE
81 	bool                    SupportsGraphite() const    { return mbHasGraphiteSupport; }
82 #endif
83 
84     const ImplFontCharMap*  GetImplFontCharMap() const;
85     const Ucs2SIntMap* GetEncodingVector() const { return mpEncodingVector; }
86     void SetEncodingVector( const Ucs2SIntMap* pNewVec ) const
87     {
88         if( mpEncodingVector )
89             delete mpEncodingVector;
90         mpEncodingVector = pNewVec;
91     }
92 private:
93     sal_IntPtr              mnId;
94 
95     // some members that are initalized lazily when the font gets selected into a HDC
96     mutable bool                    mbDisableGlyphApi;
97     mutable bool                    mbHasKoreanRange;
98     mutable bool                    mbHasCJKSupport;
99 #ifdef ENABLE_GRAPHITE
100     mutable bool                    mbHasGraphiteSupport;
101 #endif
102     mutable bool                    mbHasArabicSupport;
103     mutable ImplFontCharMap*        mpUnicodeMap;
104     mutable const Ucs2SIntMap*      mpEncodingVector;
105 
106     // TODO: get rid of the members below needed to work with the Win9x non-unicode API
107     BYTE*                   mpFontCharSets;     // all Charsets for the current font (used on W98 for kerning)
108     BYTE                    mnFontCharSetCount; // Number of Charsets of the current font; 0 - if not queried
109     BYTE                meWinCharSet;
110     BYTE                mnPitchAndFamily;
111     bool                    mbAliasSymbolsHigh;
112     bool                    mbAliasSymbolsLow;
113 private:
114     void                    ReadCmapTable( HDC ) const;
115     void                    ReadOs2Table( HDC ) const;
116 
117 #ifdef GNG_VERT_HACK
118     void                    ReadGsubTable( HDC ) const;
119 
120     typedef std::hash_set<sal_UCS4> UcsHashSet;
121     mutable UcsHashSet      maGsubTable;
122     mutable bool            mbGsubRead;
123 public:
124     bool                    HasGSUBstitutions( HDC ) const;
125     bool                    IsGSUBstituted( sal_UCS4 ) const;
126 #endif // GNG_VERT_HACK
127 };
128 
129 // ------------------
130 // - WinSalGraphics -
131 // ------------------
132 
133 class WinSalGraphics : public SalGraphics
134 {
135 public:
136 	HDC 					mhDC;				// HDC
137 	HWND					mhWnd;				// Window-Handle, when Window-Graphics
138 	HFONT					mhFonts[ MAX_FALLBACK ];        // Font + Fallbacks
139     const ImplWinFontData*  mpWinFontData[ MAX_FALLBACK ];  // pointer to the most recent font face
140     ImplWinFontEntry*       mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
141     float                   mfFontScale;        // allows metrics emulation of huge font sizes
142 	HPEN					mhPen;				// Pen
143 	HBRUSH					mhBrush;			// Brush
144 	HRGN					mhRegion;			// Region Handle
145 	HPEN					mhDefPen;			// DefaultPen
146 	HBRUSH					mhDefBrush; 		// DefaultBrush
147 	HFONT					mhDefFont;			// DefaultFont
148 	HPALETTE				mhDefPal;			// DefaultPalette
149 	COLORREF				mnPenColor; 		// PenColor
150 	COLORREF				mnBrushColor;		// BrushColor
151 	COLORREF				mnTextColor;		// TextColor
152 	RGNDATA*				mpClipRgnData;		// ClipRegion-Data
153 	RGNDATA*				mpStdClipRgnData;	// Cache Standard-ClipRegion-Data
154 	LOGFONTA*				mpLogFont;			// LOG-Font which is currently selected (only W9x)
155 	ImplFontAttrCache*		mpFontAttrCache;	// Cache font attributes from files in so/share/fonts
156 	BYTE*					mpFontCharSets; 	// All Charsets for the current font
157 	BYTE					mnFontCharSetCount; // Number of Charsets of the current font; 0 - if not queried
158 	sal_Bool					mbFontKernInit; 	// FALSE: FontKerns must be queried
159 	KERNINGPAIR*			mpFontKernPairs;	// Kerning Pairs of the current Font
160 	sal_uIntPtr					mnFontKernPairCount;// Number of Kerning Pairs of the current Font
161 	int 					mnPenWidth; 		// Linienbreite
162 	sal_Bool					mbStockPen; 		// is Pen a stockpen
163 	sal_Bool					mbStockBrush;		// is Brush a stcokbrush
164 	sal_Bool					mbPen;				// is Pen (FALSE == NULL_PEN)
165 	sal_Bool					mbBrush;			// is Brush (FALSE == NULL_BRUSH)
166 	sal_Bool					mbPrinter;			// is Printer
167 	sal_Bool					mbVirDev;			// is VirDev
168 	sal_Bool					mbWindow;			// is Window
169 	sal_Bool					mbScreen;			// is Screen compatible
170 	bool					mbXORMode;			// _every_ output with RasterOp XOR
171 
172     // remember RGB values for SetLineColor/SetFillColor
173     SalColor                maLineColor;
174     SalColor                maFillColor;
175 
176     HFONT                   ImplDoSetFont( ImplFontSelectData* i_pFont, float& o_rFontScale, HFONT& o_rOldFont );
177 
178 public:
179     explicit WinSalGraphics();
180     virtual ~WinSalGraphics();
181 
182 protected:
183     virtual bool        setClipRegion( const Region& );
184     // draw --> LineColor and FillColor and RasterOp and ClipRegion
185     virtual void		drawPixel( long nX, long nY );
186     virtual void		drawPixel( long nX, long nY, SalColor nSalColor );
187     virtual void		drawLine( long nX1, long nY1, long nX2, long nY2 );
188     virtual void		drawRect( long nX, long nY, long nWidth, long nHeight );
189     virtual void		drawPolyLine( sal_uIntPtr nPoints, const SalPoint* pPtAry );
190     virtual void		drawPolygon( sal_uIntPtr nPoints, const SalPoint* pPtAry );
191     virtual void		drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry );
192     virtual bool        drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency );
193     virtual bool        drawPolyLine( const ::basegfx::B2DPolygon&, double fTransparency, const ::basegfx::B2DVector& rLineWidth, basegfx::B2DLineJoin );
194     virtual sal_Bool	drawPolyLineBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
195     virtual sal_Bool	drawPolygonBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
196     virtual sal_Bool	drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const BYTE* const* pFlgAry );
197 
198     // CopyArea --> No RasterOp, but ClipRegion
199     virtual void		copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
200                                   long nSrcHeight, sal_uInt16 nFlags );
201 
202     // CopyBits and DrawBitmap --> RasterOp and ClipRegion
203     // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
204     virtual void		copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics );
205     virtual void		drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap );
206     virtual void		drawBitmap( const SalTwoRect* pPosAry,
207                                     const SalBitmap& rSalBitmap,
208                                     SalColor nTransparentColor );
209     virtual void		drawBitmap( const SalTwoRect* pPosAry,
210                                     const SalBitmap& rSalBitmap,
211                                     const SalBitmap& rTransparentBitmap );
212     virtual void		drawMask( const SalTwoRect* pPosAry,
213                                   const SalBitmap& rSalBitmap,
214                                   SalColor nMaskColor );
215 
216     virtual SalBitmap*	getBitmap( long nX, long nY, long nWidth, long nHeight );
217     virtual SalColor	getPixel( long nX, long nY );
218 
219     // invert --> ClipRegion (only Windows or VirDevs)
220     virtual void		invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags);
221     virtual void		invert( sal_uIntPtr nPoints, const SalPoint* pPtAry, SalInvert nFlags );
222 
223     virtual sal_Bool		drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize );
224 
225     // native widget rendering methods that require mirroring
226     virtual sal_Bool        hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
227                                               const Point& aPos, sal_Bool& rIsInside );
228     virtual sal_Bool        drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
229                                            ControlState nState, const ImplControlValue& aValue,
230                                            const rtl::OUString& aCaption );
231     virtual sal_Bool        drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
232                                                ControlState nState, const ImplControlValue& aValue,
233                                                const rtl::OUString& aCaption );
234     virtual sal_Bool        getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
235                                                 const ImplControlValue& aValue, const rtl::OUString& aCaption,
236                                                 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
237 
238     virtual bool		drawAlphaBitmap( const SalTwoRect&,
239                                          const SalBitmap& rSourceBitmap,
240                                          const SalBitmap& rAlphaBitmap );
241     virtual bool		drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency );
242 
243 public:
244     // public SalGraphics methods, the interface to teh independent vcl part
245 
246     // get device resolution
247     virtual void			GetResolution( long& rDPIX, long& rDPIY );
248     // get the depth of the device
249     virtual sal_uInt16			GetBitCount();
250     // get the width of the device
251     virtual long			GetGraphicsWidth() const;
252 
253     // set the clip region to empty
254     virtual void			ResetClipRegion();
255 
256     // set the line color to transparent (= don't draw lines)
257     virtual void			SetLineColor();
258     // set the line color to a specific color
259     virtual void			SetLineColor( SalColor nSalColor );
260     // set the fill color to transparent (= don't fill)
261     virtual void			SetFillColor();
262     // set the fill color to a specific color, shapes will be
263     // filled accordingly
264     virtual void          	SetFillColor( SalColor nSalColor );
265     // enable/disable XOR drawing
266     virtual void			SetXORMode( bool bSet, bool );
267     // set line color for raster operations
268     virtual void			SetROPLineColor( SalROPColor nROPColor );
269     // set fill color for raster operations
270     virtual void			SetROPFillColor( SalROPColor nROPColor );
271     // set the text color to a specific color
272     virtual void			SetTextColor( SalColor nSalColor );
273     // set the font
274     virtual sal_uInt16         SetFont( ImplFontSelectData*, int nFallbackLevel );
275     // get the current font's etrics
276     virtual void			GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
277     // get kernign pairs of the current font
278     // return only PairCount if (pKernPairs == NULL)
279     virtual sal_uLong			GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs );
280     // get the repertoire of the current font
281     virtual const ImplFontCharMap* GetImplFontCharMap() const;
282     // graphics must fill supplied font list
283     virtual void			GetDevFontList( ImplDevFontList* );
284     // graphics should call ImplAddDevFontSubstitute on supplied
285     // OutputDevice for all its device specific preferred font substitutions
286     virtual void			GetDevFontSubstList( OutputDevice* );
287     virtual bool			AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName );
288     // CreateFontSubset: a method to get a subset of glyhps of a font
289     // inside a new valid font file
290     // returns TRUE if creation of subset was successfull
291     // parameters: rToFile: contains a osl file URL to write the subset to
292     //             pFont: describes from which font to create a subset
293     //             pGlyphIDs: the glyph ids to be extracted
294     //             pEncoding: the character code corresponding to each glyph
295     //             pWidths: the advance widths of the correspoding glyphs (in PS font units)
296     //             nGlyphs: the number of glyphs
297     //             rInfo: additional outgoing information
298     // implementation note: encoding 0 with glyph id 0 should be added implicitly
299     // as "undefined character"
300     virtual sal_Bool			CreateFontSubset( const rtl::OUString& rToFile,
301                                               const ImplFontData*,
302                                               long* pGlyphIDs,
303                                               sal_uInt8* pEncoding,
304                                               sal_Int32* pWidths,
305                                               int nGlyphs,
306                                               FontSubsetInfo& rInfo // out parameter
307                                               );
308 
309     // GetFontEncodingVector: a method to get the encoding map Unicode
310 	// to font encoded character; this is only used for type1 fonts and
311     // may return NULL in case of unknown encoding vector
312     // if ppNonEncoded is set and non encoded characters (that is type1
313     // glyphs with only a name) exist it is set to the corresponding
314     // map for non encoded glyphs; the encoding vector contains -1
315     // as encoding for these cases
316     virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded );
317 
318     // GetEmbedFontData: gets the font data for a font marked
319     // embeddable by GetDevFontList or NULL in case of error
320     // parameters: pFont: describes the font in question
321     //             pWidths: the widths of all glyphs from char code 0 to 255
322     //                      pWidths MUST support at least 256 members;
323     //             rInfo: additional outgoing information
324     //             pDataLen: out parameter, contains the byte length of the returned buffer
325     virtual const void*	GetEmbedFontData( const ImplFontData*,
326                                           const sal_Ucs* pUnicodes,
327                                           sal_Int32* pWidths,
328                                           FontSubsetInfo& rInfo,
329                                           long* pDataLen );
330     // frees the font data again
331     virtual void			FreeEmbedFontData( const void* pData, long nDataLen );
332     virtual void            GetGlyphWidths( const ImplFontData*,
333                                             bool bVertical,
334                                             Int32Vector& rWidths,
335                                             Ucs2UIntMap& rUnicodeEnc );
336 	virtual int             GetMinKashidaWidth();
337 
338     virtual sal_Bool                    GetGlyphBoundRect( long nIndex, Rectangle& );
339     virtual sal_Bool                    GetGlyphOutline( long nIndex, ::basegfx::B2DPolyPolygon& );
340 
341     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
342     virtual void					 DrawServerFontLayout( const ServerFontLayout& );
343 
344     virtual bool            supportsOperation( OutDevSupportType ) const;
345     // Query the platform layer for control support
346     virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
347 
348     virtual SystemGraphicsData GetGraphicsData() const;
349     virtual SystemFontData     GetSysFontData( int nFallbacklevel ) const;
350 };
351 
352 // Init/Deinit Graphics
353 void	ImplSalInitGraphics( WinSalGraphics* );
354 void	ImplSalDeInitGraphics( WinSalGraphics* );
355 void	ImplUpdateSysColorEntries();
356 int 	ImplIsSysColorEntry( SalColor nSalColor );
357 void    ImplGetLogFontFromFontSelect( HDC, const ImplFontSelectData*,
358             LOGFONTW&, bool bTestVerticalAvail );
359 
360 // -----------
361 // - Defines -
362 // -----------
363 
364 #define MAX_64KSALPOINTS	((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
365 
366 // -----------
367 // - Inlines -
368 // -----------
369 
370 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
371 // SalGraphicsData::mpFontKernPairs is sorted by
372 inline bool ImplCmpKernData( const KERNINGPAIR& a, const KERNINGPAIR& b )
373 {
374     if( a.wFirst < b.wFirst )
375         return true;
376     if( a.wFirst > b.wFirst )
377         return false;
378     return (a.wSecond < b.wSecond);
379 }
380 
381 // called extremely often from just one spot => inline
382 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar ) const
383 {
384     if( mpUnicodeMap->HasChar( cChar ) )
385         return true;
386     // second chance to allow symbol aliasing
387     if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) )
388         cChar -= 0xF000;
389     else if( mbAliasSymbolsHigh && (cChar <= 0xFF) )
390         cChar += 0xF000;
391     else
392         return false;
393     return mpUnicodeMap->HasChar( cChar );
394 }
395 
396 #endif // _SV_SALGDI_H
397 
398