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