1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salgdi.h,v $
10 * $Revision: 1.30.20.5 $
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 ************************************************************************/
35 #include <vcl/sallayout.hxx>
36 #include <vcl/salgdi.hxx>
37 #include <vcl/outfont.hxx>
38 #include <vcl/impfont.hxx>
40 #include "boost/scoped_ptr.hpp"
43 class ImplFontSelectData
;
44 class ImplWinFontEntry
;
45 class ImplFontAttrCache
;
51 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
52 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
54 // win32 platform specific options. Move them to the PMK file?
59 // win32 specific physically available font face
60 class ImplWinFontData
: public ImplFontData
63 ImplWinFontData( const ImplDevFontAttributes
&,
64 int nFontHeight
, WIN_BYTE eWinCharSet
,
65 WIN_BYTE nPitchAndFamily
);
68 virtual ImplFontData
* Clone() const;
69 virtual ImplFontEntry
* CreateFontInstance( ImplFontSelectData
& ) const;
70 virtual sal_IntPtr
GetFontId() const;
71 void SetFontId( sal_IntPtr nId
) { mnId
= nId
; }
72 void UpdateFromHDC( HDC
) const;
74 bool HasChar( sal_uInt32 cChar
) const;
76 WIN_BYTE
GetCharSet() const { return meWinCharSet
; }
77 WIN_BYTE
GetPitchAndFamily() const { return mnPitchAndFamily
; }
78 bool IsGlyphApiDisabled() const { return mbDisableGlyphApi
; }
79 bool SupportsKorean() const { return mbHasKoreanRange
; }
80 bool SupportsCJK() const { return mbHasCJKSupport
; }
81 bool SupportsArabic() const { return mbHasArabicSupport
; }
82 bool AliasSymbolsHigh() const { return mbAliasSymbolsHigh
; }
83 bool AliasSymbolsLow() const { return mbAliasSymbolsLow
; }
84 #ifdef ENABLE_GRAPHITE
85 bool SupportsGraphite() const { return mbHasGraphiteSupport
; }
88 ImplFontCharMap
* GetImplFontCharMap() const;
89 const Ucs2SIntMap
* GetEncodingVector() const { return mpEncodingVector
; }
90 void SetEncodingVector( const Ucs2SIntMap
* pNewVec
) const
92 if( mpEncodingVector
)
93 delete mpEncodingVector
;
94 mpEncodingVector
= pNewVec
;
99 // some members that are initalized lazily when the font gets selected into a HDC
100 mutable bool mbDisableGlyphApi
;
101 mutable bool mbHasKoreanRange
;
102 mutable bool mbHasCJKSupport
;
103 #ifdef ENABLE_GRAPHITE
104 mutable bool mbHasGraphiteSupport
;
106 mutable bool mbHasArabicSupport
;
107 mutable ImplFontCharMap
* mpUnicodeMap
;
108 mutable const Ucs2SIntMap
* mpEncodingVector
;
110 // TODO: get rid of the members below needed to work with the Win9x non-unicode API
111 BYTE
* mpFontCharSets
; // all Charsets for the current font (used on W98 for kerning)
112 BYTE mnFontCharSetCount
; // Number of Charsets of the current font; 0 - if not queried
113 WIN_BYTE meWinCharSet
;
114 WIN_BYTE mnPitchAndFamily
;
115 bool mbAliasSymbolsHigh
;
116 bool mbAliasSymbolsLow
;
118 void ReadCmapTable( HDC
) const;
119 void ReadOs2Table( HDC
) const;
122 void ReadGsubTable( HDC
) const;
124 typedef std::hash_set
<sal_UCS4
> UcsHashSet
;
125 mutable UcsHashSet maGsubTable
;
126 mutable bool mbGsubRead
;
128 bool HasGSUBstitutions( HDC
) const;
129 bool IsGSUBstituted( sal_UCS4
) const;
130 #endif // GNG_VERT_HACK
133 // -------------------
134 // - SalGraphicsData -
135 // -------------------
137 class WinSalGraphics
: public SalGraphics
141 HWND mhWnd
; // Window-Handle, when Window-Graphics
142 HFONT mhFonts
[ MAX_FALLBACK
]; // Font + Fallbacks
143 const ImplWinFontData
* mpWinFontData
[ MAX_FALLBACK
]; // pointer to the most recent font face
144 ImplWinFontEntry
* mpWinFontEntry
[ MAX_FALLBACK
]; // pointer to the most recent font instance
145 float mfFontScale
; // allows metrics emulation of huge font sizes
147 HBRUSH mhBrush
; // Brush
148 HRGN mhRegion
; // Region Handle
149 HPEN mhDefPen
; // DefaultPen
150 HBRUSH mhDefBrush
; // DefaultBrush
151 HFONT mhDefFont
; // DefaultFont
152 HPALETTE mhDefPal
; // DefaultPalette
153 COLORREF mnPenColor
; // PenColor
154 COLORREF mnBrushColor
; // BrushColor
155 COLORREF mnTextColor
; // TextColor
156 RGNDATA
* mpClipRgnData
; // ClipRegion-Data
157 RGNDATA
* mpStdClipRgnData
; // Cache Standard-ClipRegion-Data
158 RECT
* mpNextClipRect
; // Naechstes ClipRegion-Rect
159 BOOL mbFirstClipRect
; // Flag for first cliprect to insert
160 LOGFONTA
* mpLogFont
; // LOG-Font which is currently selected (only W9x)
161 ImplFontAttrCache
* mpFontAttrCache
; // Cache font attributes from files in so/share/fonts
162 BYTE
* mpFontCharSets
; // All Charsets for the current font
163 BYTE mnFontCharSetCount
; // Number of Charsets of the current font; 0 - if not queried
164 BOOL mbFontKernInit
; // FALSE: FontKerns must be queried
165 KERNINGPAIR
* mpFontKernPairs
; // Kerning Pairs of the current Font
166 ULONG mnFontKernPairCount
;// Number of Kerning Pairs of the current Font
167 int mnPenWidth
; // Linienbreite
168 BOOL mbStockPen
; // is Pen a stockpen
169 BOOL mbStockBrush
; // is Brush a stcokbrush
170 BOOL mbPen
; // is Pen (FALSE == NULL_PEN)
171 BOOL mbBrush
; // is Brush (FALSE == NULL_BRUSH)
172 BOOL mbPrinter
; // is Printer
173 BOOL mbVirDev
; // is VirDev
174 BOOL mbWindow
; // is Window
175 BOOL mbScreen
; // is Screen compatible
176 bool mbXORMode
; // _every_ output with RasterOp XOR
178 // remember RGB values for SetLineColor/SetFillColor
179 SalColor maLineColor
;
180 SalColor maFillColor
;
182 HFONT
ImplDoSetFont( ImplFontSelectData
* i_pFont
, float& o_rFontScale
, HFONT
& o_rOldFont
);
186 virtual ~WinSalGraphics();
189 virtual BOOL
unionClipRegion( long nX
, long nY
, long nWidth
, long nHeight
);
190 virtual bool unionClipRegion( const ::basegfx::B2DPolyPolygon
& );
191 // draw --> LineColor and FillColor and RasterOp and ClipRegion
192 virtual void drawPixel( long nX
, long nY
);
193 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
);
194 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
);
195 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
);
196 virtual void drawPolyLine( ULONG nPoints
, const SalPoint
* pPtAry
);
197 virtual void drawPolygon( ULONG nPoints
, const SalPoint
* pPtAry
);
198 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
);
199 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
);
200 virtual bool drawPolyLine( const ::basegfx::B2DPolygon
&, const ::basegfx::B2DVector
& rLineWidth
, basegfx::B2DLineJoin
);
201 virtual sal_Bool
drawPolyLineBezier( ULONG nPoints
, const SalPoint
* pPtAry
, const BYTE
* pFlgAry
);
202 virtual sal_Bool
drawPolygonBezier( ULONG nPoints
, const SalPoint
* pPtAry
, const BYTE
* pFlgAry
);
203 virtual sal_Bool
drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const BYTE
* const* pFlgAry
);
205 // CopyArea --> No RasterOp, but ClipRegion
206 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
207 long nSrcHeight
, USHORT nFlags
);
209 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
210 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
211 virtual void copyBits( const SalTwoRect
* pPosAry
, SalGraphics
* pSrcGraphics
);
212 virtual void drawBitmap( const SalTwoRect
* pPosAry
, const SalBitmap
& rSalBitmap
);
213 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
214 const SalBitmap
& rSalBitmap
,
215 SalColor nTransparentColor
);
216 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
217 const SalBitmap
& rSalBitmap
,
218 const SalBitmap
& rTransparentBitmap
);
219 virtual void drawMask( const SalTwoRect
* pPosAry
,
220 const SalBitmap
& rSalBitmap
,
221 SalColor nMaskColor
);
223 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
);
224 virtual SalColor
getPixel( long nX
, long nY
);
226 // invert --> ClipRegion (only Windows or VirDevs)
227 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
);
228 virtual void invert( ULONG nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
);
230 virtual BOOL
drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, ULONG nSize
);
232 // native widget rendering methods that require mirroring
233 virtual BOOL
hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
234 const Point
& aPos
, SalControlHandle
& rControlHandle
, BOOL
& rIsInside
);
235 virtual BOOL
drawNativeControl( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
236 ControlState nState
, const ImplControlValue
& aValue
, SalControlHandle
& rControlHandle
,
237 const rtl::OUString
& aCaption
);
238 virtual BOOL
drawNativeControlText( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
,
239 ControlState nState
, const ImplControlValue
& aValue
,
240 SalControlHandle
& rControlHandle
, const rtl::OUString
& aCaption
);
241 virtual BOOL
getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Region
& rControlRegion
, ControlState nState
,
242 const ImplControlValue
& aValue
, SalControlHandle
& rControlHandle
, const rtl::OUString
& aCaption
,
243 Region
&rNativeBoundingRegion
, Region
&rNativeContentRegion
);
245 virtual bool drawAlphaBitmap( const SalTwoRect
&,
246 const SalBitmap
& rSourceBitmap
,
247 const SalBitmap
& rAlphaBitmap
);
248 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
);
251 // public SalGraphics methods, the interface to teh independent vcl part
253 // get device resolution
254 virtual void GetResolution( long& rDPIX
, long& rDPIY
);
255 // get the depth of the device
256 virtual USHORT
GetBitCount();
257 // get the width of the device
258 virtual long GetGraphicsWidth() const;
260 // set the clip region to empty
261 virtual void ResetClipRegion();
262 // begin setting the clip region, add rectangles to the
263 // region with the UnionClipRegion call
264 virtual void BeginSetClipRegion( ULONG nCount
);
265 // all rectangles were added and the clip region should be set now
266 virtual void EndSetClipRegion();
268 // set the line color to transparent (= don't draw lines)
269 virtual void SetLineColor();
270 // set the line color to a specific color
271 virtual void SetLineColor( SalColor nSalColor
);
272 // set the fill color to transparent (= don't fill)
273 virtual void SetFillColor();
274 // set the fill color to a specific color, shapes will be
275 // filled accordingly
276 virtual void SetFillColor( SalColor nSalColor
);
277 // enable/disable XOR drawing
278 virtual void SetXORMode( bool bSet
, bool );
279 // set line color for raster operations
280 virtual void SetROPLineColor( SalROPColor nROPColor
);
281 // set fill color for raster operations
282 virtual void SetROPFillColor( SalROPColor nROPColor
);
283 // set the text color to a specific color
284 virtual void SetTextColor( SalColor nSalColor
);
286 virtual USHORT
SetFont( ImplFontSelectData
*, int nFallbackLevel
);
287 // get the current font's etrics
288 virtual void GetFontMetric( ImplFontMetricData
* );
289 // get kernign pairs of the current font
290 // return only PairCount if (pKernPairs == NULL)
291 virtual ULONG
GetKernPairs( ULONG nPairs
, ImplKernPairData
* pKernPairs
);
292 // get the repertoire of the current font
293 virtual ImplFontCharMap
* GetImplFontCharMap() const;
294 // graphics must fill supplied font list
295 virtual void GetDevFontList( ImplDevFontList
* );
296 // graphics should call ImplAddDevFontSubstitute on supplied
297 // OutputDevice for all its device specific preferred font substitutions
298 virtual void GetDevFontSubstList( OutputDevice
* );
299 virtual bool AddTempDevFont( ImplDevFontList
*, const String
& rFileURL
, const String
& rFontName
);
300 // CreateFontSubset: a method to get a subset of glyhps of a font
301 // inside a new valid font file
302 // returns TRUE if creation of subset was successfull
303 // parameters: rToFile: contains a osl file URL to write the subset to
304 // pFont: describes from which font to create a subset
305 // pGlyphIDs: the glyph ids to be extracted
306 // pEncoding: the character code corresponding to each glyph
307 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
308 // nGlyphs: the number of glyphs
309 // rInfo: additional outgoing information
310 // implementation note: encoding 0 with glyph id 0 should be added implicitly
311 // as "undefined character"
312 virtual BOOL
CreateFontSubset( const rtl::OUString
& rToFile
,
315 sal_uInt8
* pEncoding
,
318 FontSubsetInfo
& rInfo
// out parameter
321 // GetFontEncodingVector: a method to get the encoding map Unicode
322 // to font encoded character; this is only used for type1 fonts and
323 // may return NULL in case of unknown encoding vector
324 // if ppNonEncoded is set and non encoded characters (that is type1
325 // glyphs with only a name) exist it is set to the corresponding
326 // map for non encoded glyphs; the encoding vector contains -1
327 // as encoding for these cases
328 virtual const Ucs2SIntMap
* GetFontEncodingVector( const ImplFontData
*, const Ucs2OStrMap
** ppNonEncoded
);
330 // GetEmbedFontData: gets the font data for a font marked
331 // embeddable by GetDevFontList or NULL in case of error
332 // parameters: pFont: describes the font in question
333 // pWidths: the widths of all glyphs from char code 0 to 255
334 // pWidths MUST support at least 256 members;
335 // rInfo: additional outgoing information
336 // pDataLen: out parameter, contains the byte length of the returned buffer
337 virtual const void* GetEmbedFontData( const ImplFontData
*,
338 const sal_Ucs
* pUnicodes
,
340 FontSubsetInfo
& rInfo
,
342 // frees the font data again
343 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
);
344 virtual void GetGlyphWidths( const ImplFontData
*,
346 Int32Vector
& rWidths
,
347 Ucs2UIntMap
& rUnicodeEnc
);
348 virtual int GetMinKashidaWidth();
350 virtual BOOL
GetGlyphBoundRect( long nIndex
, Rectangle
& );
351 virtual BOOL
GetGlyphOutline( long nIndex
, ::basegfx::B2DPolyPolygon
& );
353 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
);
354 virtual void DrawServerFontLayout( const ServerFontLayout
& );
356 virtual bool supportsOperation( OutDevSupportType
) const;
357 // Query the platform layer for control support
358 virtual BOOL
IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
360 virtual SystemGraphicsData
GetGraphicsData() const;
361 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const;
364 // Init/Deinit Graphics
365 void ImplSalInitGraphics( WinSalGraphics
* mpData
);
366 void ImplSalDeInitGraphics( WinSalGraphics
* mpData
);
367 void ImplUpdateSysColorEntries();
368 int ImplIsSysColorEntry( SalColor nSalColor
);
369 void ImplGetLogFontFromFontSelect( HDC hDC
, const ImplFontSelectData
*,
370 LOGFONTW
&, bool bTestVerticalAvail
);
376 #define MAX_64KSALPOINTS ((((USHORT)0xFFFF)-8)/sizeof(POINTS))
382 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
383 // SalGraphicsData::mpFontKernPairs is sorted by
384 inline bool ImplCmpKernData( const KERNINGPAIR
& a
, const KERNINGPAIR
& b
)
386 if( a
.wFirst
< b
.wFirst
)
388 if( a
.wFirst
> b
.wFirst
)
390 return (a
.wSecond
< b
.wSecond
);
393 // called extremely often from just one spot => inline
394 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar
) const
396 if( mpUnicodeMap
->HasChar( cChar
) )
398 // second chance to allow symbol aliasing
399 if( mbAliasSymbolsLow
&& ((cChar
-0xF000) <= 0xFF) )
401 else if( mbAliasSymbolsHigh
&& (cChar
<= 0xFF) )
403 return mpUnicodeMap
->HasChar( cChar
);
406 #endif // _SV_SALGDI_H