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 .
20 #ifndef INCLUDED_VCL_INC_WIN_SALGDI_H
21 #define INCLUDED_VCL_INC_WIN_SALGDI_H
23 #include "sallayout.hxx"
24 #include "salgeom.hxx"
26 #include "fontinstance.hxx"
27 #include "fontattributes.hxx"
28 #include "PhysicalFontFace.hxx"
29 #include "impfont.hxx"
30 #include <vcl/fontcapabilities.hxx>
31 #include <vcl/fontcharmap.hxx>
34 #include <unordered_set>
36 #ifndef INCLUDED_PRE_POST_WIN_H
37 #define INCLUDED_PRE_POST_WIN_H
45 class FontSelectPattern
;
46 class WinFontInstance
;
47 class ImplFontAttrCache
;
49 class PhysicalFontCollection
;
50 class SalGraphicsImpl
;
51 class WinOpenGLSalGraphicsImpl
;
52 class ImplFontMetricData
;
53 class CommonSalLayout
;
55 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
56 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
58 // win32 specific physically available font face
59 class WinFontFace
: public PhysicalFontFace
62 explicit WinFontFace( const FontAttributes
&,
63 int nFontHeight
, BYTE eWinCharSet
,
64 BYTE nPitchAndFamily
);
65 virtual ~WinFontFace() override
;
67 virtual PhysicalFontFace
* Clone() const override
;
68 virtual LogicalFontInstance
* CreateFontInstance( FontSelectPattern
& ) const override
;
69 virtual sal_IntPtr
GetFontId() const override
;
70 void SetFontId( sal_IntPtr nId
) { mnId
= nId
; }
71 void UpdateFromHDC( HDC
) const;
73 bool HasChar( sal_uInt32 cChar
) const;
75 BYTE
GetCharSet() const { return meWinCharSet
; }
76 BYTE
GetPitchAndFamily() const { return mnPitchAndFamily
; }
78 FontCharMapRef
GetFontCharMap() const;
79 bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const;
84 // some members that are initialized lazily when the font gets selected into a HDC
85 mutable bool mbFontCapabilitiesRead
;
86 mutable FontCharMapRef mxUnicodeMap
;
87 mutable vcl::FontCapabilities maFontCapabilities
;
90 BYTE mnPitchAndFamily
;
91 bool mbAliasSymbolsHigh
;
92 bool mbAliasSymbolsLow
;
94 void ReadCmapTable( HDC
) const;
95 void GetFontCapabilities( HDC hDC
) const;
97 mutable hb_font_t
* mpHbFont
;
99 hb_font_t
* GetHbFont() const { return mpHbFont
; }
100 void SetHbFont( hb_font_t
* pHbFont
) const { mpHbFont
= pHbFont
; }
103 /** Class that creates (and destroys) a compatible Device Context.
105 This is to be used for GDI drawing into a DIB that we later use as a texture for OpenGL drawing.
107 class OpenGLCompatibleDC
110 /// The compatible DC that we create for our purposes.
113 /// DIBSection that we use for the GDI drawing, and later obtain.
116 /// Return the previous bitmap to undo the SelectObject.
117 HBITMAP mhOrigBitmap
;
122 /// Mapping between the GDI position and OpenGL, to use for OpenGL drawing.
125 /// The OpenGL-based SalGraphicsImpl where we will draw. If null, we ignore the drawing, it means it happened directly to the DC...
126 WinOpenGLSalGraphicsImpl
*mpImpl
;
129 OpenGLCompatibleDC(SalGraphics
&rGraphics
, int x
, int y
, int width
, int height
);
130 ~OpenGLCompatibleDC();
132 HDC
getCompatibleHDC() { return mhCompatibleDC
; }
134 SalTwoRect
getTwoRect() { return maRects
; }
136 Size
getBitmapSize() { return Size(maRects
.mnSrcWidth
, maRects
.mnSrcHeight
); }
138 /// Reset the DC with the defined color.
139 void fill(sal_uInt32 color
);
141 /// Obtain the texture; the caller must delete it after use.
142 OpenGLTexture
* getTexture();
144 /// Copy bitmap data to the texture. Texutre must be initialized and the correct size to hold the bitmap.
145 bool copyToTexture(OpenGLTexture
& aTexture
);
148 class WinSalGraphics
: public SalGraphics
150 friend class WinSalGraphicsImpl
;
151 friend class WinOpenGLSalGraphicsImpl
;
152 friend class ScopedFont
;
153 friend class OpenGLCompatibleDC
;
156 std::unique_ptr
<SalGraphicsImpl
> mpImpl
;
159 HDC mhLocalDC
; // HDC
160 bool mbPrinter
: 1; // is Printer
161 bool mbVirDev
: 1; // is VirDev
162 bool mbWindow
: 1; // is Window
163 bool mbScreen
: 1; // is Screen compatible
164 HWND mhWnd
; // Window-Handle, when Window-Graphics
166 HFONT mhFonts
[ MAX_FALLBACK
]; // Font + Fallbacks
167 const WinFontFace
* mpWinFontData
[ MAX_FALLBACK
]; // pointer to the most recent font face
168 WinFontInstance
* mpWinFontEntry
[ MAX_FALLBACK
]; // pointer to the most recent font instance
169 HRGN mhRegion
; // vcl::Region Handle
170 HPEN mhDefPen
; // DefaultPen
171 HBRUSH mhDefBrush
; // DefaultBrush
172 HFONT mhDefFont
; // DefaultFont
173 HPALETTE mhDefPal
; // DefaultPalette
174 COLORREF mnTextColor
; // TextColor
175 RGNDATA
* mpClipRgnData
; // ClipRegion-Data
176 RGNDATA
* mpStdClipRgnData
; // Cache Standard-ClipRegion-Data
177 int mnPenWidth
; // Linienbreite
179 LogicalFontInstance
* GetWinFontEntry(int nFallbackLevel
);
181 bool CacheGlyphs(const CommonSalLayout
& rLayout
);
182 bool DrawCachedGlyphs(const CommonSalLayout
& rLayout
);
185 HDC
getHDC() const { return mhLocalDC
; }
186 void setHDC(HDC aNew
) { mhLocalDC
= aNew
; }
188 HPALETTE
getDefPal() const;
189 void setDefPal(HPALETTE hDefPal
);
191 HRGN
getRegion() const;
194 void DeInitGraphics();
208 HFONT
ImplDoSetFont( FontSelectPattern
* i_pFont
, HFONT
& o_rOldFont
);
211 explicit WinSalGraphics(WinSalGraphics::Type eType
, bool bScreen
, HWND hWnd
,
212 SalGeometryProvider
*pProvider
);
213 virtual ~WinSalGraphics() override
;
215 SalGraphicsImpl
* GetImpl() const override
;
216 bool isPrinter() const;
217 bool isVirtualDevice() const;
218 bool isWindow() const;
219 bool isScreen() const;
221 void setHWND(HWND hWnd
);
224 virtual bool setClipRegion( const vcl::Region
& ) override
;
225 // draw --> LineColor and FillColor and RasterOp and ClipRegion
226 virtual void drawPixel( long nX
, long nY
) override
;
227 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) override
;
228 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) override
;
229 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) override
;
230 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
231 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
232 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) override
;
233 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
234 virtual bool drawPolyLine(
235 const basegfx::B2DPolygon
&,
236 double fTransparency
,
237 const basegfx::B2DVector
& rLineWidth
,
238 basegfx::B2DLineJoin
,
239 css::drawing::LineCap
,
240 double fMiterMinimumAngle
) override
;
241 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const PolyFlags
* pFlgAry
) override
;
242 virtual bool drawPolygonBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const PolyFlags
* pFlgAry
) override
;
243 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const PolyFlags
* const* pFlgAry
) override
;
244 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
{ return false; };
246 // CopyArea --> No RasterOp, but ClipRegion
247 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
248 long nSrcHeight
, bool bWindowInvalidate
) override
;
250 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
251 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
252 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) override
;
253 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) override
;
254 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
255 const SalBitmap
& rSalBitmap
,
256 const SalBitmap
& rTransparentBitmap
) override
;
257 virtual void drawMask( const SalTwoRect
& rPosAry
,
258 const SalBitmap
& rSalBitmap
,
259 SalColor nMaskColor
) override
;
261 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) override
;
262 virtual SalColor
getPixel( long nX
, long nY
) override
;
264 // invert --> ClipRegion (only Windows or VirDevs)
265 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) override
;
266 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) override
;
268 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uIntPtr nSize
) override
;
270 // native widget rendering methods that require mirroring
271 virtual bool hitTestNativeControl( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
,
272 const Point
& aPos
, bool& rIsInside
) override
;
273 virtual bool drawNativeControl( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
,
274 ControlState nState
, const ImplControlValue
& aValue
,
275 const OUString
& aCaption
) override
;
276 virtual bool getNativeControlRegion( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
, ControlState nState
,
277 const ImplControlValue
& aValue
, const OUString
& aCaption
,
278 tools::Rectangle
&rNativeBoundingRegion
, tools::Rectangle
&rNativeContentRegion
) override
;
280 virtual bool blendBitmap( const SalTwoRect
&,
281 const SalBitmap
& rBitmap
) override
;
283 virtual bool blendAlphaBitmap( const SalTwoRect
&,
284 const SalBitmap
& rSrcBitmap
,
285 const SalBitmap
& rMaskBitmap
,
286 const SalBitmap
& rAlphaBitmap
) override
;
288 virtual bool drawAlphaBitmap( const SalTwoRect
&,
289 const SalBitmap
& rSourceBitmap
,
290 const SalBitmap
& rAlphaBitmap
) override
;
291 virtual bool drawTransformedBitmap(
292 const basegfx::B2DPoint
& rNull
,
293 const basegfx::B2DPoint
& rX
,
294 const basegfx::B2DPoint
& rY
,
295 const SalBitmap
& rSourceBitmap
,
296 const SalBitmap
* pAlphaBitmap
) override
;
297 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
) override
;
302 void DrawTextLayout(const CommonSalLayout
&, HDC
, bool bUseDWrite
);
305 // public SalGraphics methods, the interface to the independent vcl part
307 // get device resolution
308 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
309 // get the depth of the device
310 virtual sal_uInt16
GetBitCount() const override
;
311 // get the width of the device
312 virtual long GetGraphicsWidth() const override
;
314 // set the clip region to empty
315 virtual void ResetClipRegion() override
;
317 // set the line color to transparent (= don't draw lines)
318 virtual void SetLineColor() override
;
319 // set the line color to a specific color
320 virtual void SetLineColor( SalColor nSalColor
) override
;
321 // set the fill color to transparent (= don't fill)
322 virtual void SetFillColor() override
;
323 // set the fill color to a specific color, shapes will be
324 // filled accordingly
325 virtual void SetFillColor( SalColor nSalColor
) override
;
326 // enable/disable XOR drawing
327 virtual void SetXORMode( bool bSet
) override
;
328 // set line color for raster operations
329 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
330 // set fill color for raster operations
331 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
332 // set the text color to a specific color
333 virtual void SetTextColor( SalColor nSalColor
) override
;
335 virtual void SetFont( FontSelectPattern
*, int nFallbackLevel
) override
;
336 // get the current font's metrics
337 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) override
;
338 // get the repertoire of the current font
339 virtual const FontCharMapRef
GetFontCharMap() const override
;
340 // get the layout capabilities of the current font
341 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rGetFontCapabilities
) const override
;
342 // graphics must fill supplied font list
343 virtual void GetDevFontList( PhysicalFontCollection
* ) override
;
344 // graphics must drop any cached font info
345 virtual void ClearDevFontCache() override
;
346 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) override
;
347 // CreateFontSubset: a method to get a subset of glyhps of a font
348 // inside a new valid font file
349 // returns TRUE if creation of subset was successful
350 // parameters: rToFile: contains a osl file URL to write the subset to
351 // pFont: describes from which font to create a subset
352 // pGlyphIDs: the glyph ids to be extracted
353 // pEncoding: the character code corresponding to each glyph
354 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
355 // nGlyphs: the number of glyphs
356 // rInfo: additional outgoing information
357 // implementation note: encoding 0 with glyph id 0 should be added implicitly
358 // as "undefined character"
359 virtual bool CreateFontSubset( const OUString
& rToFile
,
360 const PhysicalFontFace
*,
361 const sal_GlyphId
* pGlyphIDs
,
362 const sal_uInt8
* pEncoding
,
365 FontSubsetInfo
& rInfo
// out parameter
368 // GetEmbedFontData: gets the font data for a font marked
369 // embeddable by GetDevFontList or NULL in case of error
370 // parameters: pFont: describes the font in question
371 // pDataLen: out parameter, contains the byte length of the returned buffer
372 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, long* pDataLen
) override
;
373 // frees the font data again
374 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) override
;
375 virtual void GetGlyphWidths( const PhysicalFontFace
*,
377 std::vector
< sal_Int32
>& rWidths
,
378 Ucs2UIntMap
& rUnicodeEnc
) override
;
380 virtual bool GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) override
;
381 virtual bool GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) override
;
383 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) override
;
384 virtual void DrawTextLayout( const CommonSalLayout
& ) override
;
386 virtual bool supportsOperation( OutDevSupportType
) const override
;
387 // Query the platform layer for control support
388 virtual bool IsNativeControlSupported( ControlType nType
, ControlPart nPart
) override
;
390 virtual SystemGraphicsData
GetGraphicsData() const override
;
392 /// Update settings based on the platform values
393 static void updateSettingsNative( AllSettings
& rSettings
);
396 // Init/Deinit Graphics
397 void ImplUpdateSysColorEntries();
398 int ImplIsSysColorEntry( SalColor nSalColor
);
399 void ImplGetLogFontFromFontSelect( HDC
, const FontSelectPattern
*,
400 LOGFONTW
&, bool bTestVerticalAvail
);
402 #define MAX_64KSALPOINTS ((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
404 // called extremely often from just one spot => inline
405 inline bool WinFontFace::HasChar( sal_uInt32 cChar
) const
407 if( mxUnicodeMap
->HasChar( cChar
) )
409 // second chance to allow symbol aliasing
410 if( mbAliasSymbolsLow
&& ((cChar
-0xF000) <= 0xFF) )
412 else if( mbAliasSymbolsHigh
&& (cChar
<= 0xFF) )
416 return mxUnicodeMap
->HasChar( cChar
);
419 #endif // INCLUDED_VCL_INC_WIN_SALGDI_H
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */