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