update emoji autocorrect entries from po-files
[LibreOffice.git] / vcl / inc / win / salgdi.h
blob18b7ecfb3c2eb8e6a5189c2a473d876d337d0f39
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_VCL_INC_WIN_SALGDI_H
21 #define INCLUDED_VCL_INC_WIN_SALGDI_H
23 #include "sallayout.hxx"
24 #include "salgeom.hxx"
25 #include "salgdi.hxx"
26 #include "outfont.hxx"
27 #include "PhysicalFontFace.hxx"
28 #include "impfont.hxx"
29 #include <vcl/fontcapabilities.hxx>
31 #include <memory>
32 #include <unordered_set>
34 #include <config_graphite.h>
35 #if ENABLE_GRAPHITE
36 # include <graphite_static.hxx>
37 # include <graphite2/Font.h>
38 #endif
40 class FontSelectPattern;
41 class ImplWinFontEntry;
42 class ImplFontAttrCache;
43 class OpenGLTexture;
44 class PhysicalFontCollection;
45 class SalGraphicsImpl;
46 class WinOpenGLSalGraphicsImpl;
48 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
49 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
51 #if ENABLE_GRAPHITE
52 class RawFontData;
53 class GrFontData
55 public:
56 GrFontData(HDC hDC);
57 ~GrFontData();
58 const void * getTable(unsigned int name, size_t *len) const;
59 const gr_face * getFace() const { return mpFace; }
60 void AddReference() { ++mnRefCount; }
61 void DeReference() { if (--mnRefCount == 0) delete this; }
62 private:
63 GrFontData(GrFontData &) {};
64 HDC mhDC;
65 mutable std::vector<RawFontData*> mvData;
66 gr_face * mpFace;
67 unsigned int mnRefCount;
69 #endif
71 // win32 specific physically available font face
72 class ImplWinFontData : public PhysicalFontFace
74 public:
75 explicit ImplWinFontData( const ImplDevFontAttributes&,
76 int nFontHeight, BYTE eWinCharSet,
77 BYTE nPitchAndFamily );
78 virtual ~ImplWinFontData();
80 virtual PhysicalFontFace* Clone() const SAL_OVERRIDE;
81 virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const SAL_OVERRIDE;
82 virtual sal_IntPtr GetFontId() const SAL_OVERRIDE;
83 void SetFontId( sal_IntPtr nId ) { mnId = nId; }
84 void UpdateFromHDC( HDC ) const;
86 bool HasChar( sal_uInt32 cChar ) const;
88 BYTE GetCharSet() const { return meWinCharSet; }
89 BYTE GetPitchAndFamily() const { return mnPitchAndFamily; }
90 bool SupportsKorean() const { return mbHasKoreanRange; }
91 bool SupportsCJK() const { return mbHasCJKSupport; }
92 bool SupportsArabic() const { return mbHasArabicSupport; }
93 bool AliasSymbolsHigh() const { return mbAliasSymbolsHigh; }
94 bool AliasSymbolsLow() const { return mbAliasSymbolsLow; }
95 #if ENABLE_GRAPHITE
96 bool SupportsGraphite() const { return mbHasGraphiteSupport; }
97 const gr_face* GraphiteFace() const;
98 #endif
100 FontCharMapPtr GetFontCharMap() const;
101 bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const;
102 const Ucs2SIntMap* GetEncodingVector() const { return mpEncodingVector; }
103 void SetEncodingVector( const Ucs2SIntMap* pNewVec ) const
105 if( mpEncodingVector )
106 delete mpEncodingVector;
107 mpEncodingVector = pNewVec;
109 private:
110 sal_IntPtr mnId;
112 // some members that are initalized lazily when the font gets selected into a HDC
113 mutable bool mbHasKoreanRange;
114 mutable bool mbHasCJKSupport;
115 #if ENABLE_GRAPHITE
116 mutable GrFontData* mpGraphiteData;
117 mutable bool mbHasGraphiteSupport;
118 #endif
119 mutable bool mbHasArabicSupport;
120 mutable bool mbFontCapabilitiesRead;
121 mutable FontCharMapPtr mpUnicodeMap;
122 mutable const Ucs2SIntMap* mpEncodingVector;
123 mutable vcl::FontCapabilities maFontCapabilities;
125 BYTE meWinCharSet;
126 BYTE mnPitchAndFamily;
127 bool mbAliasSymbolsHigh;
128 bool mbAliasSymbolsLow;
129 private:
130 void ReadCmapTable( HDC ) const;
131 void GetFontCapabilities( HDC hDC ) const;
133 void ReadGsubTable( HDC ) const;
135 typedef std::unordered_set<sal_UCS4> UcsHashSet;
136 mutable UcsHashSet maGsubTable;
137 mutable bool mbGsubRead;
138 public:
139 bool HasGSUBstitutions( HDC ) const;
140 bool IsGSUBstituted( sal_UCS4 ) const;
143 /** Class that creates (and destroys) a compatible Device Context.
145 This is to be used for GDI drawing into a DIB that we later use as a texture for OpenGL drawing.
147 class OpenGLCompatibleDC
149 private:
150 /// The compatible DC that we create for our purposes.
151 HDC mhCompatibleDC;
153 /// DIBSection that we use for the GDI drawing, and later obtain.
154 HBITMAP mhBitmap;
156 /// Return the previous bitmap to undo the SelectObject.
157 HBITMAP mhOrigBitmap;
159 /// DIBSection data.
160 sal_uInt32 *mpData;
162 /// Mapping between the GDI position and OpenGL, to use for OpenGL drawing.
163 SalTwoRect maRects;
165 /// The OpenGL-based SalGraphicsImpl where we will draw. If null, we ignora the drawing, it means it happened directly to the DC..
166 WinOpenGLSalGraphicsImpl *mpImpl;
168 public:
169 OpenGLCompatibleDC(SalGraphics &rGraphics, int x, int y, int width, int height);
170 ~OpenGLCompatibleDC();
172 HDC getCompatibleHDC() { return mhCompatibleDC; }
174 SalTwoRect getTwoRect() { return maRects; }
176 /// Reset the DC with the defined color.
177 void fill(sal_uInt32 color);
179 /// Obtain the texture; the caller must delete it after use.
180 OpenGLTexture* getTexture();
183 class WinSalGraphics : public SalGraphics
185 friend class WinSalGraphicsImpl;
186 friend class WinOpenGLSalGraphicsImpl;
187 friend class ScopedFont;
188 friend class OpenGLCompatibleDC;
189 friend class WinLayout;
190 friend class UniscribeLayout;
192 protected:
193 std::unique_ptr<SalGraphicsImpl> mpImpl;
195 private:
196 HDC mhLocalDC; // HDC
197 bool mbPrinter : 1; // is Printer
198 bool mbVirDev : 1; // is VirDev
199 bool mbWindow : 1; // is Window
200 bool mbScreen : 1; // is Screen compatible
201 HWND mhWnd; // Window-Handle, when Window-Graphics
203 HFONT mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks
204 const ImplWinFontData* mpWinFontData[ MAX_FALLBACK ]; // pointer to the most recent font face
205 ImplWinFontEntry* mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance
206 float mfFontScale[ MAX_FALLBACK ]; // allows metrics emulation of huge font sizes
207 float mfCurrentFontScale;
208 HRGN mhRegion; // vcl::Region Handle
209 HPEN mhDefPen; // DefaultPen
210 HBRUSH mhDefBrush; // DefaultBrush
211 HFONT mhDefFont; // DefaultFont
212 HPALETTE mhDefPal; // DefaultPalette
213 COLORREF mnTextColor; // TextColor
214 RGNDATA* mpClipRgnData; // ClipRegion-Data
215 RGNDATA* mpStdClipRgnData; // Cache Standard-ClipRegion-Data
216 ImplFontAttrCache* mpFontAttrCache; // Cache font attributes from files in so/share/fonts
217 int mnPenWidth; // Linienbreite
219 public:
220 HDC getHDC() const { return mhLocalDC; }
221 void setHDC(HDC aNew) { mhLocalDC = aNew; }
223 HPALETTE getDefPal() const;
224 void setDefPal(HPALETTE hDefPal);
226 HRGN getRegion() const;
228 void InitGraphics();
229 void DeInitGraphics();
231 enum Type
233 PRINTER,
234 VIRTUAL_DEVICE,
235 WINDOW,
236 SCREEN
239 public:
241 HWND gethWnd();
243 HFONT ImplDoSetFont( FontSelectPattern* i_pFont, float& o_rFontScale, HFONT& o_rOldFont );
245 public:
246 explicit WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hWnd,
247 SalGeometryProvider *pProvider);
248 virtual ~WinSalGraphics();
250 SalGraphicsImpl* GetImpl() const SAL_OVERRIDE;
251 bool isPrinter() const;
252 bool isVirtualDevice() const;
253 bool isWindow() const;
254 bool isScreen() const;
256 void setHWND(HWND hWnd);
258 protected:
259 virtual bool setClipRegion( const vcl::Region& ) SAL_OVERRIDE;
260 // draw --> LineColor and FillColor and RasterOp and ClipRegion
261 virtual void drawPixel( long nX, long nY ) SAL_OVERRIDE;
262 virtual void drawPixel( long nX, long nY, SalColor nSalColor ) SAL_OVERRIDE;
263 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) SAL_OVERRIDE;
264 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
265 virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
266 virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
267 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) SAL_OVERRIDE;
268 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ) SAL_OVERRIDE;
269 virtual bool drawPolyLine(
270 const ::basegfx::B2DPolygon&,
271 double fTransparency,
272 const ::basegfx::B2DVector& rLineWidth,
273 basegfx::B2DLineJoin,
274 com::sun::star::drawing::LineCap) SAL_OVERRIDE;
275 virtual bool drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
276 virtual bool drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
277 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const BYTE* const* pFlgAry ) SAL_OVERRIDE;
278 virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) SAL_OVERRIDE { return false; };
280 // CopyArea --> No RasterOp, but ClipRegion
281 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
282 long nSrcHeight, sal_uInt16 nFlags ) SAL_OVERRIDE;
284 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
285 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
286 virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) SAL_OVERRIDE;
287 virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) SAL_OVERRIDE;
288 virtual void drawBitmap( const SalTwoRect& rPosAry,
289 const SalBitmap& rSalBitmap,
290 SalColor nTransparentColor ) SAL_OVERRIDE;
291 virtual void drawBitmap( const SalTwoRect& rPosAry,
292 const SalBitmap& rSalBitmap,
293 const SalBitmap& rTransparentBitmap ) SAL_OVERRIDE;
294 virtual void drawMask( const SalTwoRect& rPosAry,
295 const SalBitmap& rSalBitmap,
296 SalColor nMaskColor ) SAL_OVERRIDE;
298 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
299 virtual SalColor getPixel( long nX, long nY ) SAL_OVERRIDE;
301 // invert --> ClipRegion (only Windows or VirDevs)
302 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) SAL_OVERRIDE;
303 virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) SAL_OVERRIDE;
305 virtual bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uIntPtr nSize ) SAL_OVERRIDE;
307 // native widget rendering methods that require mirroring
308 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
309 const Point& aPos, bool& rIsInside ) SAL_OVERRIDE;
310 virtual bool drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
311 ControlState nState, const ImplControlValue& aValue,
312 const OUString& aCaption ) SAL_OVERRIDE;
313 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
314 const ImplControlValue& aValue, const OUString& aCaption,
315 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ) SAL_OVERRIDE;
317 virtual bool blendBitmap( const SalTwoRect&,
318 const SalBitmap& rBitmap ) SAL_OVERRIDE;
320 virtual bool blendAlphaBitmap( const SalTwoRect&,
321 const SalBitmap& rSrcBitmap,
322 const SalBitmap& rMaskBitmap,
323 const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
325 virtual bool drawAlphaBitmap( const SalTwoRect&,
326 const SalBitmap& rSourceBitmap,
327 const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
328 virtual bool drawTransformedBitmap(
329 const basegfx::B2DPoint& rNull,
330 const basegfx::B2DPoint& rX,
331 const basegfx::B2DPoint& rY,
332 const SalBitmap& rSourceBitmap,
333 const SalBitmap* pAlphaBitmap) SAL_OVERRIDE;
334 virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) SAL_OVERRIDE;
336 public:
337 // public SalGraphics methods, the interface to the independent vcl part
339 // get device resolution
340 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) SAL_OVERRIDE;
341 // get the depth of the device
342 virtual sal_uInt16 GetBitCount() const SAL_OVERRIDE;
343 // get the width of the device
344 virtual long GetGraphicsWidth() const SAL_OVERRIDE;
346 // set the clip region to empty
347 virtual void ResetClipRegion() SAL_OVERRIDE;
349 // set the line color to transparent (= don't draw lines)
350 virtual void SetLineColor() SAL_OVERRIDE;
351 // set the line color to a specific color
352 virtual void SetLineColor( SalColor nSalColor ) SAL_OVERRIDE;
353 // set the fill color to transparent (= don't fill)
354 virtual void SetFillColor() SAL_OVERRIDE;
355 // set the fill color to a specific color, shapes will be
356 // filled accordingly
357 virtual void SetFillColor( SalColor nSalColor ) SAL_OVERRIDE;
358 // enable/disable XOR drawing
359 virtual void SetXORMode( bool bSet, bool ) SAL_OVERRIDE;
360 // set line color for raster operations
361 virtual void SetROPLineColor( SalROPColor nROPColor ) SAL_OVERRIDE;
362 // set fill color for raster operations
363 virtual void SetROPFillColor( SalROPColor nROPColor ) SAL_OVERRIDE;
364 // set the text color to a specific color
365 virtual void SetTextColor( SalColor nSalColor ) SAL_OVERRIDE;
366 // set the font
367 virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel ) SAL_OVERRIDE;
368 // get the current font's metrics
369 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ) SAL_OVERRIDE;
370 // get the repertoire of the current font
371 virtual const FontCharMapPtr GetFontCharMap() const SAL_OVERRIDE;
372 // get the layout capabilities of the current font
373 virtual bool GetFontCapabilities(vcl::FontCapabilities &rGetFontCapabilities) const SAL_OVERRIDE;
374 // graphics must fill supplied font list
375 virtual void GetDevFontList( PhysicalFontCollection* ) SAL_OVERRIDE;
376 // graphics must drop any cached font info
377 virtual void ClearDevFontCache() SAL_OVERRIDE;
378 virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) SAL_OVERRIDE;
379 // CreateFontSubset: a method to get a subset of glyhps of a font
380 // inside a new valid font file
381 // returns TRUE if creation of subset was successful
382 // parameters: rToFile: contains a osl file URL to write the subset to
383 // pFont: describes from which font to create a subset
384 // pGlyphIDs: the glyph ids to be extracted
385 // pEncoding: the character code corresponding to each glyph
386 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
387 // nGlyphs: the number of glyphs
388 // rInfo: additional outgoing information
389 // implementation note: encoding 0 with glyph id 0 should be added implicitly
390 // as "undefined character"
391 virtual bool CreateFontSubset( const OUString& rToFile,
392 const PhysicalFontFace*,
393 const sal_GlyphId* pGlyphIDs,
394 const sal_uInt8* pEncoding,
395 sal_Int32* pWidths,
396 int nGlyphs,
397 FontSubsetInfo& rInfo // out parameter
398 ) SAL_OVERRIDE;
400 // GetFontEncodingVector: a method to get the encoding map Unicode
401 // to font encoded character; this is only used for type1 fonts and
402 // may return NULL in case of unknown encoding vector
403 // if ppNonEncoded is set and non encoded characters (that is type1
404 // glyphs with only a name) exist it is set to the corresponding
405 // map for non encoded glyphs; the encoding vector contains -1
406 // as encoding for these cases
407 virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded, std::set<sal_Unicode> const** ) SAL_OVERRIDE;
409 // GetEmbedFontData: gets the font data for a font marked
410 // embeddable by GetDevFontList or NULL in case of error
411 // parameters: pFont: describes the font in question
412 // pWidths: the widths of all glyphs from char code 0 to 255
413 // pWidths MUST support at least 256 members;
414 // rInfo: additional outgoing information
415 // pDataLen: out parameter, contains the byte length of the returned buffer
416 virtual const void* GetEmbedFontData( const PhysicalFontFace*,
417 const sal_Ucs* pUnicodes,
418 sal_Int32* pWidths,
419 size_t nLen,
420 FontSubsetInfo& rInfo,
421 long* pDataLen ) SAL_OVERRIDE;
422 // frees the font data again
423 virtual void FreeEmbedFontData( const void* pData, long nDataLen ) SAL_OVERRIDE;
424 virtual void GetGlyphWidths( const PhysicalFontFace*,
425 bool bVertical,
426 Int32Vector& rWidths,
427 Ucs2UIntMap& rUnicodeEnc ) SAL_OVERRIDE;
428 int GetMinKashidaWidth();
430 virtual bool GetGlyphBoundRect( sal_GlyphId, Rectangle& ) SAL_OVERRIDE;
431 virtual bool GetGlyphOutline( sal_GlyphId, ::basegfx::B2DPolyPolygon& ) SAL_OVERRIDE;
433 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) SAL_OVERRIDE;
434 virtual void DrawServerFontLayout( const ServerFontLayout& ) SAL_OVERRIDE;
436 virtual bool supportsOperation( OutDevSupportType ) const SAL_OVERRIDE;
437 // Query the platform layer for control support
438 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) SAL_OVERRIDE;
440 virtual SystemGraphicsData GetGraphicsData() const SAL_OVERRIDE;
441 virtual bool SupportsCairo() const SAL_OVERRIDE;
442 virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const SAL_OVERRIDE;
443 virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const SAL_OVERRIDE;
444 virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const SAL_OVERRIDE;
445 virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const ::basegfx::B2ISize& rSize) const SAL_OVERRIDE;
446 virtual SystemFontData GetSysFontData( int nFallbacklevel ) const SAL_OVERRIDE;
448 virtual OpenGLContext *BeginPaint() SAL_OVERRIDE;
450 /// Update settings based on the platform values
451 static void updateSettingsNative( AllSettings& rSettings );
454 // Init/Deinit Graphics
455 void ImplUpdateSysColorEntries();
456 int ImplIsSysColorEntry( SalColor nSalColor );
457 void ImplGetLogFontFromFontSelect( HDC, const FontSelectPattern*,
458 LOGFONTW&, bool bTestVerticalAvail );
460 #define MAX_64KSALPOINTS ((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
462 // #102411# Win's GCP mishandles kerning => we need to do it ourselves
463 // kerning pairs is sorted by
464 inline bool ImplCmpKernData( const KERNINGPAIR& a, const KERNINGPAIR& b )
466 if( a.wFirst < b.wFirst )
467 return true;
468 if( a.wFirst > b.wFirst )
469 return false;
470 return (a.wSecond < b.wSecond);
473 // called extremely often from just one spot => inline
474 inline bool ImplWinFontData::HasChar( sal_uInt32 cChar ) const
476 if( mpUnicodeMap->HasChar( cChar ) )
477 return true;
478 // second chance to allow symbol aliasing
479 if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) )
480 cChar -= 0xF000;
481 else if( mbAliasSymbolsHigh && (cChar <= 0xFF) )
482 cChar += 0xF000;
483 else
484 return false;
485 return mpUnicodeMap->HasChar( cChar );
488 #endif // INCLUDED_VCL_INC_WIN_SALGDI_H
490 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */