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