1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <sallayout.hxx>
25 #include <outfont.hxx>
26 #include <impfont.hxx>
27 #include <vcl/fontcapabilities.hxx>
29 #include "boost/scoped_ptr.hpp"
30 #include <boost/unordered_set.hpp>
32 #include <config_graphite.h>
34 #include <graphite2/Font.h>
37 class FontSelectPattern
;
38 class ImplWinFontEntry
;
39 class ImplFontAttrCache
;
41 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
42 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
51 const void * getTable(unsigned int name
, size_t *len
) const;
52 const gr_face
* getFace() const { return mpFace
; }
53 void AddReference() { ++mnRefCount
; }
54 void DeReference() { if (--mnRefCount
== 0) delete this; }
56 GrFontData(GrFontData
&) {};
58 mutable std::vector
<RawFontData
*> mvData
;
60 unsigned int mnRefCount
;
64 // win32 specific physically available font face
65 class ImplWinFontData
: public PhysicalFontFace
68 explicit ImplWinFontData( const ImplDevFontAttributes
&,
69 int nFontHeight
, BYTE eWinCharSet
,
70 BYTE nPitchAndFamily
);
71 virtual ~ImplWinFontData();
73 virtual PhysicalFontFace
* Clone() const;
74 virtual ImplFontEntry
* CreateFontInstance( FontSelectPattern
& ) const;
75 virtual sal_IntPtr
GetFontId() const;
76 void SetFontId( sal_IntPtr nId
) { mnId
= nId
; }
77 void UpdateFromHDC( HDC
) const;
79 bool HasChar( sal_uInt32 cChar
) const;
81 BYTE
GetCharSet() const { return meWinCharSet
; }
82 BYTE
GetPitchAndFamily() const { return mnPitchAndFamily
; }
83 bool IsGlyphApiDisabled() const { return mbDisableGlyphApi
; }
84 bool SupportsKorean() const { return mbHasKoreanRange
; }
85 bool SupportsCJK() const { return mbHasCJKSupport
; }
86 bool SupportsArabic() const { return mbHasArabicSupport
; }
87 bool AliasSymbolsHigh() const { return mbAliasSymbolsHigh
; }
88 bool AliasSymbolsLow() const { return mbAliasSymbolsLow
; }
90 bool SupportsGraphite() const { return mbHasGraphiteSupport
; }
91 const gr_face
* GraphiteFace() const;
94 const ImplFontCharMap
* GetImplFontCharMap() const;
95 bool GetImplFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const;
96 const Ucs2SIntMap
* GetEncodingVector() const { return mpEncodingVector
; }
97 void SetEncodingVector( const Ucs2SIntMap
* pNewVec
) const
99 if( mpEncodingVector
)
100 delete mpEncodingVector
;
101 mpEncodingVector
= pNewVec
;
106 // some members that are initalized lazily when the font gets selected into a HDC
107 mutable bool mbDisableGlyphApi
;
108 mutable bool mbHasKoreanRange
;
109 mutable bool mbHasCJKSupport
;
111 mutable GrFontData
* mpGraphiteData
;
112 mutable bool mbHasGraphiteSupport
;
114 mutable bool mbHasArabicSupport
;
115 mutable bool mbFontCapabilitiesRead
;
116 mutable ImplFontCharMap
* mpUnicodeMap
;
117 mutable const Ucs2SIntMap
* mpEncodingVector
;
118 mutable vcl::FontCapabilities maFontCapabilities
;
120 // TODO: get rid of the members below needed to work with the Win9x non-unicode API
121 BYTE
* mpFontCharSets
; // all Charsets for the current font (used on W98 for kerning)
122 BYTE mnFontCharSetCount
; // Number of Charsets of the current font; 0 - if not queried
124 BYTE mnPitchAndFamily
;
125 bool mbAliasSymbolsHigh
;
126 bool mbAliasSymbolsLow
;
128 void ReadCmapTable( HDC
) const;
129 void GetFontCapabilities( HDC hDC
) const;
131 void ReadGsubTable( HDC
) const;
133 typedef boost::unordered_set
<sal_UCS4
> UcsHashSet
;
134 mutable UcsHashSet maGsubTable
;
135 mutable bool mbGsubRead
;
137 bool HasGSUBstitutions( HDC
) const;
138 bool IsGSUBstituted( sal_UCS4
) const;
141 class WinSalGraphics
: public SalGraphics
145 HWND mhWnd
; // Window-Handle, when Window-Graphics
146 HFONT mhFonts
[ MAX_FALLBACK
]; // Font + Fallbacks
147 const ImplWinFontData
* mpWinFontData
[ MAX_FALLBACK
]; // pointer to the most recent font face
148 ImplWinFontEntry
* mpWinFontEntry
[ MAX_FALLBACK
]; // pointer to the most recent font instance
149 float mfFontScale
[ MAX_FALLBACK
]; // allows metrics emulation of huge font sizes
150 float mfCurrentFontScale
;
152 HBRUSH mhBrush
; // Brush
153 HRGN mhRegion
; // Region Handle
154 HPEN mhDefPen
; // DefaultPen
155 HBRUSH mhDefBrush
; // DefaultBrush
156 HFONT mhDefFont
; // DefaultFont
157 HPALETTE mhDefPal
; // DefaultPalette
158 COLORREF mnPenColor
; // PenColor
159 COLORREF mnBrushColor
; // BrushColor
160 COLORREF mnTextColor
; // TextColor
161 RGNDATA
* mpClipRgnData
; // ClipRegion-Data
162 RGNDATA
* mpStdClipRgnData
; // Cache Standard-ClipRegion-Data
163 LOGFONTA
* mpLogFont
; // LOG-Font which is currently selected (only W9x)
164 ImplFontAttrCache
* mpFontAttrCache
; // Cache font attributes from files in so/share/fonts
165 BYTE
* mpFontCharSets
; // All Charsets for the current font
166 BYTE mnFontCharSetCount
; // Number of Charsets of the current font; 0 - if not queried
167 sal_Bool mbFontKernInit
; // FALSE: FontKerns must be queried
168 KERNINGPAIR
* mpFontKernPairs
; // Kerning Pairs of the current Font
169 sal_uIntPtr mnFontKernPairCount
;// Number of Kerning Pairs of the current Font
170 int mnPenWidth
; // Linienbreite
171 sal_Bool mbStockPen
; // is Pen a stockpen
172 sal_Bool mbStockBrush
; // is Brush a stcokbrush
173 sal_Bool mbPen
; // is Pen (FALSE == NULL_PEN)
174 sal_Bool mbBrush
; // is Brush (FALSE == NULL_BRUSH)
175 sal_Bool mbPrinter
; // is Printer
176 sal_Bool mbVirDev
; // is VirDev
177 sal_Bool mbWindow
; // is Window
178 sal_Bool mbScreen
; // is Screen compatible
179 bool mbXORMode
; // _every_ output with RasterOp XOR
181 // remember RGB values for SetLineColor/SetFillColor
182 SalColor maLineColor
;
183 SalColor maFillColor
;
185 HFONT
ImplDoSetFont( FontSelectPattern
* i_pFont
, float& o_rFontScale
, HFONT
& o_rOldFont
);
188 explicit WinSalGraphics();
189 virtual ~WinSalGraphics();
192 virtual bool setClipRegion( const Region
& );
193 // draw --> LineColor and FillColor and RasterOp and ClipRegion
194 virtual void drawPixel( long nX
, long nY
);
195 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
);
196 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
);
197 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
);
198 virtual void drawPolyLine( sal_uIntPtr nPoints
, const SalPoint
* pPtAry
);
199 virtual void drawPolygon( sal_uIntPtr nPoints
, const SalPoint
* pPtAry
);
200 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
);
201 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
);
202 virtual bool drawPolyLine(
203 const ::basegfx::B2DPolygon
&,
204 double fTransparency
,
205 const ::basegfx::B2DVector
& rLineWidth
,
206 basegfx::B2DLineJoin
,
207 com::sun::star::drawing::LineCap
);
208 virtual sal_Bool
drawPolyLineBezier( sal_uIntPtr nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
);
209 virtual sal_Bool
drawPolygonBezier( sal_uIntPtr nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
);
210 virtual sal_Bool
drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const BYTE
* const* pFlgAry
);
212 // CopyArea --> No RasterOp, but ClipRegion
213 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
214 long nSrcHeight
, sal_uInt16 nFlags
);
216 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
217 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
218 virtual void copyBits( const SalTwoRect
* pPosAry
, SalGraphics
* pSrcGraphics
);
219 virtual void drawBitmap( const SalTwoRect
* pPosAry
, const SalBitmap
& rSalBitmap
);
220 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
221 const SalBitmap
& rSalBitmap
,
222 SalColor nTransparentColor
);
223 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
224 const SalBitmap
& rSalBitmap
,
225 const SalBitmap
& rTransparentBitmap
);
226 virtual void drawMask( const SalTwoRect
* pPosAry
,
227 const SalBitmap
& rSalBitmap
,
228 SalColor nMaskColor
);
230 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
);
231 virtual SalColor
getPixel( long nX
, long nY
);
233 // invert --> ClipRegion (only Windows or VirDevs)
234 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
);
235 virtual void invert( sal_uIntPtr nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
);
237 virtual sal_Bool
drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uIntPtr nSize
);
239 // native widget rendering methods that require mirroring
240 virtual sal_Bool
hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
241 const Point
& aPos
, sal_Bool
& rIsInside
);
242 virtual sal_Bool
drawNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
243 ControlState nState
, const ImplControlValue
& aValue
,
244 const OUString
& aCaption
);
245 virtual sal_Bool
getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
, ControlState nState
,
246 const ImplControlValue
& aValue
, const OUString
& aCaption
,
247 Rectangle
&rNativeBoundingRegion
, Rectangle
&rNativeContentRegion
);
249 virtual bool drawAlphaBitmap( const SalTwoRect
&,
250 const SalBitmap
& rSourceBitmap
,
251 const SalBitmap
& rAlphaBitmap
);
252 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
);
255 // public SalGraphics methods, the interface to the independent vcl part
257 // get device resolution
258 virtual void GetResolution( long& rDPIX
, long& rDPIY
);
259 // get the depth of the device
260 virtual sal_uInt16
GetBitCount() const;
261 // get the width of the device
262 virtual long GetGraphicsWidth() const;
264 // set the clip region to empty
265 virtual void ResetClipRegion();
267 // set the line color to transparent (= don't draw lines)
268 virtual void SetLineColor();
269 // set the line color to a specific color
270 virtual void SetLineColor( SalColor nSalColor
);
271 // set the fill color to transparent (= don't fill)
272 virtual void SetFillColor();
273 // set the fill color to a specific color, shapes will be
274 // filled accordingly
275 virtual void SetFillColor( SalColor nSalColor
);
276 // enable/disable XOR drawing
277 virtual void SetXORMode( bool bSet
, bool );
278 // set line color for raster operations
279 virtual void SetROPLineColor( SalROPColor nROPColor
);
280 // set fill color for raster operations
281 virtual void SetROPFillColor( SalROPColor nROPColor
);
282 // set the text color to a specific color
283 virtual void SetTextColor( SalColor nSalColor
);
285 virtual sal_uInt16
SetFont( FontSelectPattern
*, int nFallbackLevel
);
286 // get the current font's etrics
287 virtual void GetFontMetric( ImplFontMetricData
*, int nFallbackLevel
);
288 // get kernign pairs of the current font
289 // return only PairCount if (pKernPairs == NULL)
290 virtual sal_uLong
GetKernPairs( sal_uLong nPairs
, ImplKernPairData
* pKernPairs
);
291 // get the repertoire of the current font
292 virtual const ImplFontCharMap
* GetImplFontCharMap() const;
293 // get the layout capabilities of the current font
294 virtual bool GetImplFontCapabilities(vcl::FontCapabilities
&rGetFontCapabilities
) const;
295 // graphics must fill supplied font list
296 virtual void GetDevFontList( ImplDevFontList
* );
297 // graphics must drop any cached font info
298 virtual void ClearDevFontCache();
299 // graphics should call ImplAddDevFontSubstitute on supplied
300 // OutputDevice for all its device specific preferred font substitutions
301 virtual void GetDevFontSubstList( OutputDevice
* );
302 virtual bool AddTempDevFont( ImplDevFontList
*, const OUString
& rFileURL
, const OUString
& rFontName
);
303 // CreateFontSubset: a method to get a subset of glyhps of a font
304 // inside a new valid font file
305 // returns TRUE if creation of subset was successful
306 // parameters: rToFile: contains a osl file URL to write the subset to
307 // pFont: describes from which font to create a subset
308 // pGlyphIDs: the glyph ids to be extracted
309 // pEncoding: the character code corresponding to each glyph
310 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
311 // nGlyphs: the number of glyphs
312 // rInfo: additional outgoing information
313 // implementation note: encoding 0 with glyph id 0 should be added implicitly
314 // as "undefined character"
315 virtual sal_Bool
CreateFontSubset( const OUString
& rToFile
,
316 const PhysicalFontFace
*,
318 sal_uInt8
* pEncoding
,
321 FontSubsetInfo
& rInfo
// out parameter
324 // GetFontEncodingVector: a method to get the encoding map Unicode
325 // to font encoded character; this is only used for type1 fonts and
326 // may return NULL in case of unknown encoding vector
327 // if ppNonEncoded is set and non encoded characters (that is type1
328 // glyphs with only a name) exist it is set to the corresponding
329 // map for non encoded glyphs; the encoding vector contains -1
330 // as encoding for these cases
331 virtual const Ucs2SIntMap
* GetFontEncodingVector( const PhysicalFontFace
*, const Ucs2OStrMap
** ppNonEncoded
);
333 // GetEmbedFontData: gets the font data for a font marked
334 // embeddable by GetDevFontList or NULL in case of error
335 // parameters: pFont: describes the font in question
336 // pWidths: the widths of all glyphs from char code 0 to 255
337 // pWidths MUST support at least 256 members;
338 // rInfo: additional outgoing information
339 // pDataLen: out parameter, contains the byte length of the returned buffer
340 virtual const void* GetEmbedFontData( const PhysicalFontFace
*,
341 const sal_Ucs
* pUnicodes
,
343 FontSubsetInfo
& rInfo
,
345 // frees the font data again
346 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
);
347 virtual void GetGlyphWidths( const PhysicalFontFace
*,
349 Int32Vector
& rWidths
,
350 Ucs2UIntMap
& rUnicodeEnc
);
351 virtual int GetMinKashidaWidth();
353 virtual sal_Bool
GetGlyphBoundRect( sal_GlyphId nIndex
, Rectangle
& );
354 virtual sal_Bool
GetGlyphOutline( sal_GlyphId nIndex
, ::basegfx::B2DPolyPolygon
& );
356 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
);
357 virtual void DrawServerFontLayout( const ServerFontLayout
& );
359 virtual bool supportsOperation( OutDevSupportType
) const;
360 // Query the platform layer for control support
361 virtual sal_Bool
IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
363 virtual SystemGraphicsData
GetGraphicsData() const;
364 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const;
366 /// Update settings based on the platform values
367 static void updateSettingsNative( AllSettings
& rSettings
);
370 // Init/Deinit Graphics
371 void ImplSalInitGraphics( WinSalGraphics
* );
372 void ImplSalDeInitGraphics( WinSalGraphics
* );
373 void ImplUpdateSysColorEntries();
374 int ImplIsSysColorEntry( SalColor nSalColor
);
375 void ImplGetLogFontFromFontSelect( HDC
, const FontSelectPattern
*,
376 LOGFONTW
&, bool bTestVerticalAvail
);
378 #define MAX_64KSALPOINTS ((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
380 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
381 // SalGraphicsData::mpFontKernPairs is sorted by
382 inline bool ImplCmpKernData( const KERNINGPAIR
& a
, const KERNINGPAIR
& b
)
384 if( a
.wFirst
< b
.wFirst
)
386 if( a
.wFirst
> b
.wFirst
)
388 return (a
.wSecond
< b
.wSecond
);
391 // called extremely often from just one spot => inline
392 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar
) const
394 if( mpUnicodeMap
->HasChar( cChar
) )
396 // second chance to allow symbol aliasing
397 if( mbAliasSymbolsLow
&& ((cChar
-0xF000) <= 0xFF) )
399 else if( mbAliasSymbolsHigh
&& (cChar
<= 0xFF) )
403 return mpUnicodeMap
->HasChar( cChar
);
406 #endif // _SV_SALGDI_H
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */