xref: /aoo42x/main/vcl/inc/os2/salgdi.h (revision 86e1cf34)
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;
SetFontId(sal_IntPtr nId)58     void                    SetFontId( sal_IntPtr nId ) { mnId = nId; }
59     void                    UpdateFromHPS( HPS ) const;
60 
61     bool                    HasChar( sal_uInt32 cChar ) const;
62 
GetFontMetrics() const63     PFONTMETRICS            GetFontMetrics() const          { return pFontMetric; }
GetCharSet() const64     USHORT                  GetCharSet() const          { return meOs2CharSet; }
GetPitchAndFamily() const65     PM_BYTE                    GetPitchAndFamily() const   { return mnPitchAndFamily; }
IsGlyphApiDisabled() const66     bool                    IsGlyphApiDisabled() const  { return mbDisableGlyphApi; }
SupportsKorean() const67     bool                    SupportsKorean() const      { return mbHasKoreanRange; }
SupportsCJK() const68     bool                    SupportsCJK() const         { return mbHasCJKSupport; }
SupportsArabic() const69     bool                    SupportsArabic() const      { return mbHasArabicSupport; }
AliasSymbolsHigh() const70     bool                    AliasSymbolsHigh() const    { return mbAliasSymbolsHigh; }
AliasSymbolsLow() const71     bool                    AliasSymbolsLow() const     { return mbAliasSymbolsLow; }
72 
73     const ImplFontCharMap*        GetImplFontCharMap() const;
GetEncodingVector() const74     const Ucs2SIntMap* GetEncodingVector() const { return mpEncodingVector; }
SetEncodingVector(const Ucs2SIntMap * pNewVec) const75     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( sal_uInt32 nPoints, const SalPoint* pPtAry );
166     virtual void		drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
167     virtual void		drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* 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_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry );
176     virtual sal_Bool	drawPolygonBezier( sal_uInt32 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& rPosAry, SalGraphics* pSrcGraphics );
186     virtual void		drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap );
187     virtual void		drawBitmap( const SalTwoRect& rPosAry,
188                                     const SalBitmap& rSalBitmap,
189                                     SalColor nTransparentColor );
190     virtual void		drawBitmap( const SalTwoRect& rPosAry,
191                                     const SalBitmap& rSalBitmap,
192                                     const SalBitmap& rTransparentBitmap );
193     virtual void		drawMask( const SalTwoRect& rPosAry,
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( sal_uInt32 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 drawTransformedBitmap(
225         const basegfx::B2DPoint& rNull,
226         const basegfx::B2DPoint& rX,
227         const basegfx::B2DPoint& rY,
228         const SalBitmap& rSourceBitmap,
229         const SalBitmap* pAlphaBitmap);
230     virtual bool		drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency );
231 
232 public:
233     // public SalGraphics methods, the interface to the independent vcl part
234 
235     // get device resolution
236     virtual void			GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY );
237     // get the depth of the device
238     virtual USHORT			GetBitCount();
239     // get the width of the device
240     virtual long			GetGraphicsWidth() const;
241 
242     // set the clip region to empty
243     virtual void			ResetClipRegion();
244 
245     // set the line color to transparent (= don't draw lines)
246     virtual void			SetLineColor();
247     // set the line color to a specific color
248     virtual void			SetLineColor( SalColor nSalColor );
249     // set the fill color to transparent (= don't fill)
250     virtual void			SetFillColor();
251     // set the fill color to a specific color, shapes will be
252     // filled accordingly
253     virtual void          	SetFillColor( SalColor nSalColor );
254     // enable/disable XOR drawing
255     virtual void			SetXORMode( bool bSet, bool );
256     // set line color for raster operations
257     virtual void			SetROPLineColor( SalROPColor nROPColor );
258     // set fill color for raster operations
259     virtual void			SetROPFillColor( SalROPColor nROPColor );
260     // set the text color to a specific color
261     virtual void			SetTextColor( SalColor nSalColor );
262     // set the font
263     virtual USHORT         SetFont( ImplFontSelectData*, int nFallbackLevel );
264     // get the current font's etrics
265     virtual void			GetFontMetric( ImplFontMetricData*, int nFallbackLevel );
266     // get kernign pairs of the current font
267     // return only PairCount if (pKernPairs == NULL)
268     virtual ULONG			GetKernPairs( ULONG nPairs, ImplKernPairData* pKernPairs );
269     // get the repertoire of the current font
270     virtual const ImplFontCharMap* GetImplFontCharMap() const;
271     // graphics must fill supplied font list
272     virtual void			GetDevFontList( ImplDevFontList* );
273     // graphics should call ImplAddDevFontSubstitute on supplied
274     // OutputDevice for all its device specific preferred font substitutions
275     virtual void			GetDevFontSubstList( OutputDevice* );
276     virtual bool			AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName );
277     // CreateFontSubset: a method to get a subset of glyhps of a font
278     // inside a new valid font file
279     // returns TRUE if creation of subset was successful
280     // parameters: rToFile: contains a osl file URL to write the subset to
281     //             pFont: describes from which font to create a subset
282     //             pGlyphIDs: the glyph ids to be extracted
283     //             pEncoding: the character code corresponding to each glyph
284     //             pWidths: the advance widths of the correspoding glyphs (in PS font units)
285     //             nGlyphs: the number of glyphs
286     //             rInfo: additional outgoing information
287     // implementation note: encoding 0 with glyph id 0 should be added implicitly
288     // as "undefined character"
289     virtual sal_Bool			CreateFontSubset( const rtl::OUString& rToFile,
290                                               const ImplFontData* pFont,
291                                               sal_GlyphId* pGlyphIds,
292                                               sal_uInt8* pEncoding,
293                                               sal_Int32* pWidths,
294                                               int nGlyphs,
295                                               FontSubsetInfo& rInfo // out parameter
296                                               );
297 
298     // GetFontEncodingVector: a method to get the encoding map Unicode
299 	// to font encoded character; this is only used for type1 fonts and
300     // may return NULL in case of unknown encoding vector
301     // if ppNonEncoded is set and non encoded characters (that is type1
302     // glyphs with only a name) exist it is set to the corresponding
303     // map for non encoded glyphs; the encoding vector contains -1
304     // as encoding for these cases
305     virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded );
306 
307     // GetEmbedFontData: gets the font data for a font marked
308     // embeddable by GetDevFontList or NULL in case of error
309     // parameters: pFont: describes the font in question
310     //             pWidths: the widths of all glyphs from char code 0 to 255
311     //                      pWidths MUST support at least 256 members;
312     //             rInfo: additional outgoing information
313     //             pDataLen: out parameter, contains the PM_BYTE length of the returned buffer
314     virtual const void*	GetEmbedFontData( const ImplFontData*,
315                                           const sal_Ucs* pUnicodes,
316                                           sal_Int32* pWidths,
317                                           FontSubsetInfo& rInfo,
318                                           long* pDataLen );
319     // frees the font data again
320     virtual void			FreeEmbedFontData( const void* pData, long nDataLen );
321 
322     virtual void            GetGlyphWidths( const ImplFontData* pFont,
323                                             bool bVertical,
324                                             Int32Vector& rWidths,
325                                             Ucs2UIntMap& rUnicodeEnc );
326 
327     virtual bool                    GetGlyphBoundRect( sal_GlyphId, Rectangle& );
328     virtual bool                    GetGlyphOutline( sal_GlyphId, ::basegfx::B2DPolyPolygon& );
329 
330     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel );
331     virtual void					 DrawServerFontLayout( const ServerFontLayout& );
332     virtual bool            supportsOperation( OutDevSupportType ) const;
333 
334     // Query the platform layer for control support
335     virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
336 
337     virtual SystemGraphicsData GetGraphicsData() const;
338     virtual SystemFontData     GetSysFontData( int nFallbacklevel ) const;
339 };
340 
341 // Init/Deinit Graphics
342 void ImplSalInitGraphics( Os2SalGraphics* mpData );
343 void ImplSalDeInitGraphics( Os2SalGraphics* mpData );
344 
345 // -----------
346 // - Defines -
347 // -----------
348 
349 #define TY( y ) 			(mnHeight-(y)-1)
350 
351 // offset for lcid field, used for fallback font selection
352 #define LCID_BASE						100
353 
354 // -----------
355 // - Inlines -
356 // -----------
357 
358 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
359 // SalGraphicsData::mpFontKernPairs is sorted by
ImplCmpKernData(const KERNINGPAIRS & a,const KERNINGPAIRS & b)360 inline bool ImplCmpKernData( const KERNINGPAIRS& a, const KERNINGPAIRS& b )
361 {
362     if( a.sFirstChar < b.sFirstChar )
363         return true;
364     if( a.sFirstChar > b.sFirstChar )
365         return false;
366     return (a.sSecondChar < b.sSecondChar);
367 }
368 
369 // called extremely often from just one spot => inline
HasChar(sal_uInt32 cChar) const370 inline bool ImplOs2FontData::HasChar( sal_uInt32 cChar ) const
371 {
372     if( mpUnicodeMap->HasChar( cChar ) )
373         return true;
374     // second chance to allow symbol aliasing
375     if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) )
376         cChar -= 0xF000;
377     else if( mbAliasSymbolsHigh && (cChar <= 0xFF) )
378         cChar += 0xF000;
379     return mpUnicodeMap->HasChar( cChar );
380 }
381 
382 #endif // _SV_SALGDI_H
383