xref: /aoo41x/main/vcl/inc/win/salgdi.h (revision 5aaf853b)
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(
190         const ::basegfx::B2DPolygon&,
191         double fTransparency,
192         const ::basegfx::B2DVector& rLineWidth,
193         basegfx::B2DLineJoin,
194         com::sun::star::drawing::LineCap);
195     virtual sal_Bool	drawPolyLineBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
196     virtual sal_Bool	drawPolygonBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
197     virtual sal_Bool	drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const BYTE* const* pFlgAry );
198 
199     // CopyArea --> No RasterOp, but ClipRegion
200     virtual void		copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
201                                   long nSrcHeight, sal_uInt16 nFlags );
202 
203     // CopyBits and DrawBitmap --> RasterOp and ClipRegion
204     // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
205     virtual void		copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics );
206     virtual void		drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap );
207     virtual void		drawBitmap( const SalTwoRect* pPosAry,
208                                     const SalBitmap& rSalBitmap,
209                                     SalColor nTransparentColor );
210     virtual void		drawBitmap( const SalTwoRect* pPosAry,
211                                     const SalBitmap& rSalBitmap,
212                                     const SalBitmap& rTransparentBitmap );
213     virtual void		drawMask( const SalTwoRect* pPosAry,
214                                   const SalBitmap& rSalBitmap,
215                                   SalColor nMaskColor );
216 
217     virtual SalBitmap*	getBitmap( long nX, long nY, long nWidth, long nHeight );
218     virtual SalColor	getPixel( long nX, long nY );
219 
220     // invert --> ClipRegion (only Windows or VirDevs)
221     virtual void		invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags);
222     virtual void		invert( sal_uIntPtr nPoints, const SalPoint* pPtAry, SalInvert nFlags );
223 
224     virtual sal_Bool		drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize );
225 
226     // native widget rendering methods that require mirroring
227     virtual sal_Bool        hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
228                                               const Point& aPos, sal_Bool& rIsInside );
229     virtual sal_Bool        drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
230                                            ControlState nState, const ImplControlValue& aValue,
231                                            const rtl::OUString& aCaption );
232     virtual sal_Bool        drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
233                                                ControlState nState, const ImplControlValue& aValue,
234                                                const rtl::OUString& aCaption );
235     virtual sal_Bool        getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
236                                                 const ImplControlValue& aValue, const rtl::OUString& aCaption,
237                                                 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
238 
239     virtual bool		drawAlphaBitmap( const SalTwoRect&,
240                                          const SalBitmap& rSourceBitmap,
241                                          const SalBitmap& rAlphaBitmap );
242     virtual bool		drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency );
243 
244 public:
245     // public SalGraphics methods, the interface to teh independent vcl part
246 
247     // get device resolution
248     virtual void			GetResolution( long& rDPIX, long& rDPIY );
249     // get the depth of the device
250     virtual sal_uInt16			GetBitCount();
251     // get the width of the device
252     virtual long			GetGraphicsWidth() const;
253 
254     // set the clip region to empty
255     virtual void			ResetClipRegion();
256 
257     // set the line color to transparent (= don't draw lines)
258     virtual void			SetLineColor();
259     // set the line color to a specific color
260     virtual void			SetLineColor( SalColor nSalColor );
261     // set the fill color to transparent (= don't fill)
262     virtual void			SetFillColor();
263     // set the fill color to a specific color, shapes will be
264     // filled accordingly
265     virtual void          	SetFillColor( SalColor nSalColor );
266     // enable/disable XOR drawing
267     virtual void			SetXORMode( bool bSet, bool );
268     // set line color for raster operations
269     virtual void			SetROPLineColor( SalROPColor nROPColor );
270     // set fill color for raster operations
271     virtual void			SetROPFillColor( SalROPColor nROPColor );
272     // set the text color to a specific color
273     virtual void			SetTextColor( SalColor nSalColor );
274     // set the font
275     virtual sal_uInt16         SetFont( ImplFontSelectData*, int nFallbackLevel );
276     // get the current font's etrics
277     virtual void			GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
278     // get kernign pairs of the current font
279     // return only PairCount if (pKernPairs == NULL)
280     virtual sal_uLong			GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs );
281     // get the repertoire of the current font
282     virtual const ImplFontCharMap* GetImplFontCharMap() const;
283     // graphics must fill supplied font list
284     virtual void			GetDevFontList( ImplDevFontList* );
285     // graphics should call ImplAddDevFontSubstitute on supplied
286     // OutputDevice for all its device specific preferred font substitutions
287     virtual void			GetDevFontSubstList( OutputDevice* );
288     virtual bool			AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName );
289     // CreateFontSubset: a method to get a subset of glyhps of a font
290     // inside a new valid font file
291     // returns TRUE if creation of subset was successfull
292     // parameters: rToFile: contains a osl file URL to write the subset to
293     //             pFont: describes from which font to create a subset
294     //             pGlyphIDs: the glyph ids to be extracted
295     //             pEncoding: the character code corresponding to each glyph
296     //             pWidths: the advance widths of the correspoding glyphs (in PS font units)
297     //             nGlyphs: the number of glyphs
298     //             rInfo: additional outgoing information
299     // implementation note: encoding 0 with glyph id 0 should be added implicitly
300     // as "undefined character"
301     virtual sal_Bool			CreateFontSubset( const rtl::OUString& rToFile,
302                                               const ImplFontData*,
303                                               long* pGlyphIDs,
304                                               sal_uInt8* pEncoding,
305                                               sal_Int32* pWidths,
306                                               int nGlyphs,
307                                               FontSubsetInfo& rInfo // out parameter
308                                               );
309 
310     // GetFontEncodingVector: a method to get the encoding map Unicode
311 	// to font encoded character; this is only used for type1 fonts and
312     // may return NULL in case of unknown encoding vector
313     // if ppNonEncoded is set and non encoded characters (that is type1
314     // glyphs with only a name) exist it is set to the corresponding
315     // map for non encoded glyphs; the encoding vector contains -1
316     // as encoding for these cases
317     virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded );
318 
319     // GetEmbedFontData: gets the font data for a font marked
320     // embeddable by GetDevFontList or NULL in case of error
321     // parameters: pFont: describes the font in question
322     //             pWidths: the widths of all glyphs from char code 0 to 255
323     //                      pWidths MUST support at least 256 members;
324     //             rInfo: additional outgoing information
325     //             pDataLen: out parameter, contains the byte length of the returned buffer
326     virtual const void*	GetEmbedFontData( const ImplFontData*,
327                                           const sal_Ucs* pUnicodes,
328                                           sal_Int32* pWidths,
329                                           FontSubsetInfo& rInfo,
330                                           long* pDataLen );
331     // frees the font data again
332     virtual void			FreeEmbedFontData( const void* pData, long nDataLen );
333     virtual void            GetGlyphWidths( const ImplFontData*,
334                                             bool bVertical,
335                                             Int32Vector& rWidths,
336                                             Ucs2UIntMap& rUnicodeEnc );
337 	virtual int             GetMinKashidaWidth();
338 
339     virtual sal_Bool                    GetGlyphBoundRect( long nIndex, Rectangle& );
340     virtual sal_Bool                    GetGlyphOutline( long nIndex, ::basegfx::B2DPolyPolygon& );
341 
342     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
343     virtual void					 DrawServerFontLayout( const ServerFontLayout& );
344 
345     virtual bool            supportsOperation( OutDevSupportType ) const;
346     // Query the platform layer for control support
347     virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
348 
349     virtual SystemGraphicsData GetGraphicsData() const;
350     virtual SystemFontData     GetSysFontData( int nFallbacklevel ) const;
351 };
352 
353 // Init/Deinit Graphics
354 void	ImplSalInitGraphics( WinSalGraphics* );
355 void	ImplSalDeInitGraphics( WinSalGraphics* );
356 void	ImplUpdateSysColorEntries();
357 int 	ImplIsSysColorEntry( SalColor nSalColor );
358 void    ImplGetLogFontFromFontSelect( HDC, const ImplFontSelectData*,
359             LOGFONTW&, bool bTestVerticalAvail );
360 
361 // -----------
362 // - Defines -
363 // -----------
364 
365 #define MAX_64KSALPOINTS	((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
366 
367 // -----------
368 // - Inlines -
369 // -----------
370 
371 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
372 // SalGraphicsData::mpFontKernPairs is sorted by
373 inline bool ImplCmpKernData( const KERNINGPAIR& a, const KERNINGPAIR& b )
374 {
375     if( a.wFirst < b.wFirst )
376         return true;
377     if( a.wFirst > b.wFirst )
378         return false;
379     return (a.wSecond < b.wSecond);
380 }
381 
382 // called extremely often from just one spot => inline
383 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar ) const
384 {
385     if( mpUnicodeMap->HasChar( cChar ) )
386         return true;
387     // second chance to allow symbol aliasing
388     if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) )
389         cChar -= 0xF000;
390     else if( mbAliasSymbolsHigh && (cChar <= 0xFF) )
391         cChar += 0xF000;
392     else
393         return false;
394     return mpUnicodeMap->HasChar( cChar );
395 }
396 
397 #endif // _SV_SALGDI_H
398 
399