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