xref: /trunk/main/vcl/inc/win/salgdi.h (revision 97f9399e)
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;
SetFontId(sal_IntPtr nId)63     void                    SetFontId( sal_IntPtr nId ) { mnId = nId; }
64     void                    UpdateFromHDC( HDC ) const;
65 
66     bool                    HasChar( sal_uInt32 cChar ) const;
67 
GetCharSet() const68     BYTE                GetCharSet() const          { return meWinCharSet; }
GetPitchAndFamily() const69     BYTE                GetPitchAndFamily() const   { return mnPitchAndFamily; }
IsGlyphApiDisabled() const70     bool                    IsGlyphApiDisabled() const  { return mbDisableGlyphApi; }
SupportsKorean() const71     bool                    SupportsKorean() const      { return mbHasKoreanRange; }
SupportsCJK() const72     bool                    SupportsCJK() const         { return mbHasCJKSupport; }
SupportsArabic() const73     bool                    SupportsArabic() const      { return mbHasArabicSupport; }
AliasSymbolsHigh() const74     bool                    AliasSymbolsHigh() const    { return mbAliasSymbolsHigh; }
AliasSymbolsLow() const75     bool                    AliasSymbolsLow() const     { return mbAliasSymbolsLow; }
76 #ifdef ENABLE_GRAPHITE
SupportsGraphite() const77 	bool                    SupportsGraphite() const    { return mbHasGraphiteSupport; }
78 #endif
79 
80     const ImplFontCharMap* GetImplFontCharMap() const;
GetEncodingVector() const81     const Ucs2SIntMap* GetEncodingVector() const { return mpEncodingVector; }
SetEncodingVector(const Ucs2SIntMap * pNewVec) const82     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 initialized 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 private:
132 	HDC 					mhLocalDC;				// HDC
133 
134 public:
getHDC()135 	HDC getHDC() { return mhLocalDC; }
setHDC(HDC aNew)136 	void setHDC(HDC aNew) { mhLocalDC = aNew; }
137 
138 public:
139 	HWND					mhWnd;				// Window-Handle, when Window-Graphics
140 	HFONT					mhFonts[ MAX_FALLBACK ];        // Font + Fallbacks
141 	const ImplWinFontData*	mpWinFontData[ MAX_FALLBACK ];  // pointer to the most recent font face
142 	ImplWinFontEntry*		mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
143 	float					mfFontScale;		// allows metrics emulation of huge font sizes
144 	HPEN					mhPen;				// Pen
145 	HBRUSH					mhBrush;			// Brush
146 	HRGN					mhRegion;			// Region Handle
147 	HPEN					mhDefPen;			// DefaultPen
148 	HBRUSH					mhDefBrush; 		// DefaultBrush
149 	HFONT					mhDefFont;			// DefaultFont
150 	HPALETTE				mhDefPal;			// DefaultPalette
151 	COLORREF				mnPenColor; 		// PenColor
152 	COLORREF				mnBrushColor;		// BrushColor
153 	COLORREF				mnTextColor;		// TextColor
154 	RGNDATA*				mpClipRgnData;		// ClipRegion-Data
155 	RGNDATA*				mpStdClipRgnData;	// Cache Standard-ClipRegion-Data
156 	LOGFONTA*				mpLogFont;			// LOG-Font which is currently selected (only W9x)
157 	ImplFontAttrCache*		mpFontAttrCache;	// Cache font attributes from files in so/share/fonts
158 	BYTE*					mpFontCharSets; 	// All Charsets for the current font
159 	BYTE					mnFontCharSetCount; // Number of Charsets of the current font; 0 - if not queried
160 	sal_Bool					mbFontKernInit; 	// FALSE: FontKerns must be queried
161 	KERNINGPAIR*			mpFontKernPairs;	// Kerning Pairs of the current Font
162 	sal_uIntPtr					mnFontKernPairCount;// Number of Kerning Pairs of the current Font
163 	int 					mnPenWidth; 		// LineWidth
164 
165 	/// bitfield
166 	bool                    mbStockPen : 1; 		// is Pen a stockpen
167 	bool                    mbStockBrush : 1;		// is Brush a stockbrush
168 	bool                    mbPen : 1;				// is Pen (FALSE == NULL_PEN)
169 	bool                    mbBrush : 1;			// is Brush (FALSE == NULL_BRUSH)
170 	bool                    mbPrinter : 1;			// is Printer
171 	bool                    mbVirDev : 1;			// is VirDev
172 	bool                    mbWindow : 1;			// is Window
173 	bool                    mbScreen : 1;			// is Screen compatible
174 	bool					mbXORMode : 1;			// _every_ output with RasterOp XOR
175 
176     // remember RGB values for SetLineColor/SetFillColor
177     SalColor                maLineColor;
178     SalColor                maFillColor;
179 
180     HFONT                   ImplDoSetFont( ImplFontSelectData* i_pFont, float& o_rFontScale, HFONT& o_rOldFont );
181 
182 public:
183     explicit WinSalGraphics();
184     virtual ~WinSalGraphics();
185 
186 protected:
187     virtual bool		setClipRegion( const Region& );
188     // draw --> LineColor and FillColor and RasterOp and ClipRegion
189     virtual void		drawPixel( long nX, long nY );
190     virtual void		drawPixel( long nX, long nY, SalColor nSalColor );
191     virtual void		drawLine( long nX1, long nY1, long nX2, long nY2 );
192     virtual void		drawRect( long nX, long nY, long nWidth, long nHeight );
193     virtual void		drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry );
194     virtual void		drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
195     virtual void		drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry );
196     virtual bool		drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency );
197     virtual bool		drawPolyLine(
198         const ::basegfx::B2DPolygon&,
199         double fTransparency,
200         const ::basegfx::B2DVector& rLineWidth,
201         basegfx::B2DLineJoin,
202         com::sun::star::drawing::LineCap);
203     virtual sal_Bool	drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
204     virtual sal_Bool	drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
205     virtual sal_Bool	drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const BYTE* const* pFlgAry );
206 
207     // CopyArea --> No RasterOp, but ClipRegion
208     virtual void		copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
209                                   long nSrcHeight, sal_uInt16 nFlags );
210 
211     // CopyBits and DrawBitmap --> RasterOp and ClipRegion
212     // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
213     virtual void		copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics );
214     virtual void		drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap );
215     virtual void		drawBitmap( const SalTwoRect& rPosAry,
216                                     const SalBitmap& rSalBitmap,
217                                     SalColor nTransparentColor );
218     virtual void		drawBitmap( const SalTwoRect& rPosAry,
219                                     const SalBitmap& rSalBitmap,
220                                     const SalBitmap& rTransparentBitmap );
221     virtual void		drawMask( const SalTwoRect& rPosAry,
222                                   const SalBitmap& rSalBitmap,
223                                   SalColor nMaskColor );
224 
225     virtual SalBitmap*	getBitmap( long nX, long nY, long nWidth, long nHeight );
226     virtual SalColor	getPixel( long nX, long nY );
227 
228     // invert --> ClipRegion (only Windows or VirDevs)
229     virtual void		invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags);
230     virtual void		invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags );
231 
232     virtual sal_Bool		drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize );
233 
234     // native widget rendering methods that require mirroring
235     virtual sal_Bool        hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
236                                               const Point& aPos, sal_Bool& rIsInside );
237     virtual sal_Bool        drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
238                                            ControlState nState, const ImplControlValue& aValue,
239                                            const rtl::OUString& aCaption );
240     virtual sal_Bool        drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
241                                                ControlState nState, const ImplControlValue& aValue,
242                                                const rtl::OUString& aCaption );
243     virtual sal_Bool        getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
244                                                 const ImplControlValue& aValue, const rtl::OUString& aCaption,
245                                                 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
246 
247     virtual bool		drawAlphaBitmap( const SalTwoRect&,
248                                          const SalBitmap& rSourceBitmap,
249                                          const SalBitmap& rAlphaBitmap );
250     virtual bool drawTransformedBitmap(
251         const basegfx::B2DPoint& rNull,
252         const basegfx::B2DPoint& rX,
253         const basegfx::B2DPoint& rY,
254         const SalBitmap& rSourceBitmap,
255         const SalBitmap* pAlphaBitmap);
256     virtual bool		drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency );
257 
258 private:
259     // local helpers
260     bool tryDrawBitmapGdiPlus(const SalTwoRect& rTR, const SalBitmap& rSrcBitmap);
261 
262 public:
263     // public SalGraphics methods, the interface to the independent vcl part
264 
265     // get device resolution
266     virtual void			GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY );
267     // get the depth of the device
268     virtual sal_uInt16			GetBitCount();
269     // get the width of the device
270     virtual long			GetGraphicsWidth() const;
271 
272     // set the clip region to empty
273     virtual void			ResetClipRegion();
274 
275     // set the line color to transparent (= don't draw lines)
276     virtual void			SetLineColor();
277     // set the line color to a specific color
278     virtual void			SetLineColor( SalColor nSalColor );
279     // set the fill color to transparent (= don't fill)
280     virtual void			SetFillColor();
281     // set the fill color to a specific color, shapes will be
282     // filled accordingly
283     virtual void          	SetFillColor( SalColor nSalColor );
284     // enable/disable XOR drawing
285     virtual void			SetXORMode( bool bSet, bool );
286     // set line color for raster operations
287     virtual void			SetROPLineColor( SalROPColor nROPColor );
288     // set fill color for raster operations
289     virtual void			SetROPFillColor( SalROPColor nROPColor );
290     // set the text color to a specific color
291     virtual void			SetTextColor( SalColor nSalColor );
292     // set the font
293     virtual sal_uInt16         SetFont( ImplFontSelectData*, int nFallbackLevel );
294     // get the current font's metrics
295     virtual void			GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
296     // get kerning pairs of the current font
297     // return only PairCount if (pKernPairs == NULL)
298     virtual sal_uLong			GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs );
299     // get the repertoire of the current font
300     virtual const ImplFontCharMap* GetImplFontCharMap() const;
301     // graphics must fill supplied font list
302     virtual void			GetDevFontList( ImplDevFontList* );
303     // graphics should call ImplAddDevFontSubstitute on supplied
304     // OutputDevice for all its device specific preferred font substitutions
305     virtual void			GetDevFontSubstList( OutputDevice* );
306     virtual bool			AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName );
307     // CreateFontSubset: a method to get a subset of glyhps of a font
308     // inside a new valid font file
309     // returns TRUE if creation of subset was successful
310     // parameters: rToFile: contains a osl file URL to write the subset to
311     //             pFont: describes from which font to create a subset
312     //             pGlyphIDs: the glyph ids to be extracted
313     //             pEncoding: the character code corresponding to each glyph
314     //             pWidths: the advance widths of the corresponding glyphs (in PS font units)
315     //             nGlyphs: the number of glyphs
316     //             rInfo: additional outgoing information
317     // implementation note: encoding 0 with glyph id 0 should be added implicitly
318     // as "undefined character"
319     virtual sal_Bool			CreateFontSubset( const rtl::OUString& rToFile,
320                                               const ImplFontData*,
321                                               sal_GlyphId* pGlyphIds,
322                                               sal_uInt8* pEncoding,
323                                               sal_Int32* pWidths,
324                                               int nGlyphs,
325                                               FontSubsetInfo& rInfo // out parameter
326                                               );
327 
328     // GetFontEncodingVector: a method to get the encoding map Unicode
329 	// to font encoded character; this is only used for type1 fonts and
330     // may return NULL in case of unknown encoding vector
331     // if ppNonEncoded is set and non encoded characters (that is type1
332     // glyphs with only a name) exist it is set to the corresponding
333     // map for non encoded glyphs; the encoding vector contains -1
334     // as encoding for these cases
335     virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded );
336 
337     // GetEmbedFontData: gets the font data for a font marked
338     // embeddable by GetDevFontList or NULL in case of error
339     // parameters: pFont: describes the font in question
340     //             pWidths: the widths of all glyphs from char code 0 to 255
341     //                      pWidths MUST support at least 256 members;
342     //             rInfo: additional outgoing information
343     //             pDataLen: out parameter, contains the byte length of the returned buffer
344     virtual const void*	GetEmbedFontData( const ImplFontData*,
345                                           const sal_Ucs* pUnicodes,
346                                           sal_Int32* pWidths,
347                                           FontSubsetInfo& rInfo,
348                                           long* pDataLen );
349     // frees the font data again
350     virtual void			FreeEmbedFontData( const void* pData, long nDataLen );
351     virtual void            GetGlyphWidths( const ImplFontData*,
352                                             bool bVertical,
353                                             Int32Vector& rWidths,
354                                             Ucs2UIntMap& rUnicodeEnc );
355 	virtual int             GetMinKashidaWidth();
356 
357     virtual bool                    GetGlyphBoundRect( sal_GlyphId, Rectangle& );
358     virtual bool                    GetGlyphOutline( sal_GlyphId, ::basegfx::B2DPolyPolygon& );
359 
360     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
361     virtual void					 DrawServerFontLayout( const ServerFontLayout& );
362 
363     virtual bool            supportsOperation( OutDevSupportType ) const;
364     // Query the platform layer for control support
365     virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
366 
367     virtual SystemGraphicsData GetGraphicsData() const;
368     virtual SystemFontData     GetSysFontData( int nFallbacklevel ) const;
369 };
370 
371 // Init/Deinit Graphics
372 void	ImplSalInitGraphics( WinSalGraphics* );
373 void	ImplSalDeInitGraphics( WinSalGraphics* );
374 void	ImplUpdateSysColorEntries();
375 int 	ImplIsSysColorEntry( SalColor nSalColor );
376 void    ImplGetLogFontFromFontSelect( HDC, const ImplFontSelectData*,
377             LOGFONTW&, bool bTestVerticalAvail );
378 
379 // -----------
380 // - Defines -
381 // -----------
382 
383 #define MAX_64KSALPOINTS	((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
384 
385 // -----------
386 // - Inlines -
387 // -----------
388 
389 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
390 // SalGraphicsData::mpFontKernPairs is sorted by
ImplCmpKernData(const KERNINGPAIR & a,const KERNINGPAIR & b)391 inline bool ImplCmpKernData( const KERNINGPAIR& a, const KERNINGPAIR& b )
392 {
393     if( a.wFirst < b.wFirst )
394         return true;
395     if( a.wFirst > b.wFirst )
396         return false;
397     return (a.wSecond < b.wSecond);
398 }
399 
400 // called extremely often from just one spot => inline
HasChar(sal_uInt32 cChar) const401 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar ) const
402 {
403     if( mpUnicodeMap->HasChar( cChar ) )
404         return true;
405     // second chance to allow symbol aliasing
406     if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) )
407         cChar -= 0xF000;
408     else if( mbAliasSymbolsHigh && (cChar <= 0xFF) )
409         cChar += 0xF000;
410     else
411         return false;
412     return mpUnicodeMap->HasChar( cChar );
413 }
414 
415 #endif // _SV_SALGDI_H
416 
417