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
;
48 class PhysicalFontCollection
;
49 class SalGraphicsImpl
;
50 class WinSalGraphicsImplBase
;
51 class ImplFontMetricData
;
53 #define RGB_TO_PALRGB(nRGB) ((nRGB)|0x02000000)
54 #define PALRGB_TO_RGB(nPalRGB) ((nPalRGB)&0x00ffffff)
56 // win32 specific physically available font face
57 class WinFontFace
: public PhysicalFontFace
60 explicit WinFontFace( const FontAttributes
&,
62 BYTE nPitchAndFamily
);
63 virtual ~WinFontFace() override
;
65 virtual rtl::Reference
<LogicalFontInstance
> CreateFontInstance( const FontSelectPattern
& ) const override
;
66 virtual sal_IntPtr
GetFontId() const override
;
67 void SetFontId( sal_IntPtr nId
) { mnId
= nId
; }
68 void UpdateFromHDC( HDC
) const;
70 bool HasChar( sal_uInt32 cChar
) const;
72 BYTE
GetCharSet() const { return meWinCharSet
; }
73 BYTE
GetPitchAndFamily() const { return mnPitchAndFamily
; }
75 FontCharMapRef
GetFontCharMap() const override
;
76 bool GetFontCapabilities(vcl::FontCapabilities
&) const override
;
81 // some members that are initialized lazily when the font gets selected into a HDC
82 mutable bool mbFontCapabilitiesRead
;
83 mutable FontCharMapRef mxUnicodeMap
;
84 mutable vcl::FontCapabilities maFontCapabilities
;
87 BYTE mnPitchAndFamily
;
88 bool mbAliasSymbolsHigh
;
89 bool mbAliasSymbolsLow
;
91 void ReadCmapTable( HDC
) const;
92 void GetFontCapabilities( HDC hDC
) const;
95 /** Class that creates (and destroys) a compatible Device Context.
97 This is to be used for GDI drawing into a DIB that we later use for a different
98 drawing method, such as a texture for OpenGL drawing or surface for Skia drawing.
103 /// The compatible DC that we create for our purposes.
106 /// DIBSection that we use for the GDI drawing, and later obtain.
109 /// Return the previous bitmap to undo the SelectObject.
110 HBITMAP mhOrigBitmap
;
115 /// Mapping between the GDI position and OpenGL, to use for OpenGL drawing.
118 /// The SalGraphicsImpl where we will draw. If null, we ignore the drawing, it means it happened directly to the DC...
119 WinSalGraphicsImplBase
*mpImpl
;
121 // If 'disable' is true, this class is a simple wrapper for drawing directly. Subclasses should use true.
122 CompatibleDC(SalGraphics
&rGraphics
, int x
, int y
, int width
, int height
, bool disable
=true);
125 static std::unique_ptr
< CompatibleDC
> create(SalGraphics
&rGraphics
, int x
, int y
, int width
, int height
);
127 virtual ~CompatibleDC();
129 HDC
getCompatibleHDC() { return mhCompatibleDC
; }
131 SalTwoRect
getTwoRect() const { return maRects
; }
133 tools::Long
getBitmapWidth() const { return maRects
.mnSrcWidth
; }
134 tools::Long
getBitmapHeight() const { return maRects
.mnSrcHeight
; }
136 /// Reset the DC with the defined color.
137 void fill(sal_uInt32 color
);
140 class WinSalGraphics
: public SalGraphics
142 friend class WinSalGraphicsImpl
;
143 friend class ScopedFont
;
146 std::unique_ptr
<SalGraphicsImpl
> mpImpl
;
149 HDC mhLocalDC
; // HDC
150 bool mbPrinter
: 1; // is Printer
151 bool mbVirDev
: 1; // is VirDev
152 bool mbWindow
: 1; // is Window
153 bool mbScreen
: 1; // is Screen compatible
154 HWND mhWnd
; // Window-Handle, when Window-Graphics
156 rtl::Reference
<WinFontInstance
>
157 mpWinFontEntry
[ MAX_FALLBACK
]; // pointer to the most recent font instance
158 HRGN mhRegion
; // vcl::Region Handle
159 HPEN mhDefPen
; // DefaultPen
160 HBRUSH mhDefBrush
; // DefaultBrush
161 HFONT mhDefFont
; // DefaultFont
162 HPALETTE mhDefPal
; // DefaultPalette
163 COLORREF mnTextColor
; // TextColor
164 RGNDATA
* mpClipRgnData
; // ClipRegion-Data
165 RGNDATA
* mpStdClipRgnData
; // Cache Standard-ClipRegion-Data
166 int mnPenWidth
; // line width
169 // Return HFONT, and whether the font is for vertical writing ( prefixed with '@' )
170 // and tmDescent value for adjusting offset in vertical writing mode.
171 std::tuple
<HFONT
,bool,sal_Int32
> ImplDoSetFont(FontSelectPattern
const & i_rFont
, const PhysicalFontFace
* i_pFontFace
, HFONT
& o_rOldFont
);
173 HDC
getHDC() const { return mhLocalDC
; }
174 void setHDC(HDC aNew
) { mhLocalDC
= aNew
; }
176 HPALETTE
getDefPal() const;
177 void setDefPal(HPALETTE hDefPal
);
179 HRGN
getRegion() const;
182 void DeInitGraphics();
198 explicit WinSalGraphics(WinSalGraphics::Type eType
, bool bScreen
, HWND hWnd
,
199 SalGeometryProvider
*pProvider
);
200 virtual ~WinSalGraphics() override
;
202 SalGraphicsImpl
* GetImpl() const override
;
203 bool isPrinter() const;
204 bool isVirtualDevice() const;
205 bool isWindow() const;
206 bool isScreen() const;
208 void setHWND(HWND hWnd
);
212 virtual bool setClipRegion( const vcl::Region
& ) override
;
213 // draw --> LineColor and FillColor and RasterOp and ClipRegion
214 virtual void drawPixel( tools::Long nX
, tools::Long nY
) override
;
215 virtual void drawPixel( tools::Long nX
, tools::Long nY
, Color nColor
) override
;
216 virtual void drawLine( tools::Long nX1
, tools::Long nY1
, tools::Long nX2
, tools::Long nY2
) override
;
217 virtual void drawRect( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
) override
;
218 virtual void drawPolyLine( sal_uInt32 nPoints
, const Point
* pPtAry
) override
;
219 virtual void drawPolygon( sal_uInt32 nPoints
, const Point
* pPtAry
) override
;
220 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const Point
** pPtAry
) override
;
221 virtual bool drawPolyPolygon(
222 const basegfx::B2DHomMatrix
& rObjectToDevice
,
223 const basegfx::B2DPolyPolygon
&,
224 double fTransparency
) override
;
225 virtual bool drawPolyLine(
226 const basegfx::B2DHomMatrix
& rObjectToDevice
,
227 const basegfx::B2DPolygon
&,
228 double fTransparency
,
230 const std::vector
< double >* pStroke
, // MM01
231 basegfx::B2DLineJoin
,
232 css::drawing::LineCap
,
233 double fMiterMinimumAngle
,
234 bool bPixelSnapHairline
) override
;
235 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
, const Point
* pPtAry
, const PolyFlags
* pFlgAry
) override
;
236 virtual bool drawPolygonBezier( sal_uInt32 nPoints
, const Point
* pPtAry
, const PolyFlags
* pFlgAry
) override
;
237 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const Point
* const* pPtAry
, const PolyFlags
* const* pFlgAry
) override
;
238 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
;
239 virtual bool implDrawGradient(basegfx::B2DPolyPolygon
const & rPolyPolygon
, SalGradient
const & rGradient
) override
;
241 // CopyArea --> No RasterOp, but ClipRegion
242 virtual void copyArea( tools::Long nDestX
, tools::Long nDestY
, tools::Long nSrcX
, tools::Long nSrcY
, tools::Long nSrcWidth
,
243 tools::Long nSrcHeight
, bool bWindowInvalidate
) override
;
245 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
246 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
247 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) override
;
248 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) override
;
249 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
250 const SalBitmap
& rSalBitmap
,
251 const SalBitmap
& rTransparentBitmap
) override
;
252 virtual void drawMask( const SalTwoRect
& rPosAry
,
253 const SalBitmap
& rSalBitmap
,
254 Color nMaskColor
) override
;
256 virtual std::shared_ptr
<SalBitmap
> getBitmap( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
) override
;
257 virtual Color
getPixel( tools::Long nX
, tools::Long nY
) override
;
259 // invert --> ClipRegion (only Windows or VirDevs)
260 virtual void invert( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, SalInvert nFlags
) override
;
261 virtual void invert( sal_uInt32 nPoints
, const Point
* pPtAry
, SalInvert nFlags
) override
;
263 virtual bool drawEPS( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, void* pPtr
, sal_uInt32 nSize
) override
;
265 // native widget rendering methods that require mirroring
267 virtual bool isNativeControlSupported( ControlType nType
, ControlPart nPart
) override
;
268 virtual bool hitTestNativeControl( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
,
269 const Point
& aPos
, bool& rIsInside
) override
;
270 virtual bool drawNativeControl( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
,
271 ControlState nState
, const ImplControlValue
& aValue
,
272 const OUString
& aCaption
, const Color
& rBackgroundColor
) override
;
273 virtual bool getNativeControlRegion( ControlType nType
, ControlPart nPart
, const tools::Rectangle
& rControlRegion
, ControlState nState
,
274 const ImplControlValue
& aValue
, const OUString
& aCaption
,
275 tools::Rectangle
&rNativeBoundingRegion
, tools::Rectangle
&rNativeContentRegion
) override
;
278 virtual bool blendBitmap( const SalTwoRect
&,
279 const SalBitmap
& rBitmap
) override
;
281 virtual bool blendAlphaBitmap( const SalTwoRect
&,
282 const SalBitmap
& rSrcBitmap
,
283 const SalBitmap
& rMaskBitmap
,
284 const SalBitmap
& rAlphaBitmap
) override
;
286 virtual bool drawAlphaBitmap( const SalTwoRect
&,
287 const SalBitmap
& rSourceBitmap
,
288 const SalBitmap
& rAlphaBitmap
) override
;
289 virtual bool drawTransformedBitmap(
290 const basegfx::B2DPoint
& rNull
,
291 const basegfx::B2DPoint
& rX
,
292 const basegfx::B2DPoint
& rY
,
293 const SalBitmap
& rSourceBitmap
,
294 const SalBitmap
* pAlphaBitmap
,
295 double fAlpha
) override
;
297 virtual bool hasFastDrawTransformedBitmap() const override
;
299 virtual bool drawAlphaRect( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, sal_uInt8 nTransparency
) override
;
304 void DrawTextLayout(const GenericSalLayout
&, HDC
, bool bUseDWrite
);
307 // public SalGraphics methods, the interface to the independent vcl part
309 // get device resolution
310 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
311 // get the depth of the device
312 virtual sal_uInt16
GetBitCount() const override
;
313 // get the width of the device
314 virtual tools::Long
GetGraphicsWidth() const override
;
316 // set the clip region to empty
317 virtual void ResetClipRegion() override
;
319 // set the line color to transparent (= don't draw lines)
320 virtual void SetLineColor() override
;
321 // set the line color to a specific color
322 virtual void SetLineColor( Color nColor
) override
;
323 // set the fill color to transparent (= don't fill)
324 virtual void SetFillColor() override
;
325 // set the fill color to a specific color, shapes will be
326 // filled accordingly
327 virtual void SetFillColor( Color nColor
) override
;
328 // enable/disable XOR drawing
329 virtual void SetXORMode( bool bSet
, bool ) override
;
330 // set line color for raster operations
331 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
332 // set fill color for raster operations
333 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
334 // set the text color to a specific color
335 virtual void SetTextColor( Color nColor
) override
;
337 virtual void SetFont( LogicalFontInstance
*, int nFallbackLevel
) override
;
338 // get the current font's metrics
339 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) override
;
340 // get the repertoire of the current font
341 virtual FontCharMapRef
GetFontCharMap() const override
;
342 // get the layout capabilities of the current font
343 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rGetFontCapabilities
) const override
;
344 // graphics must fill supplied font list
345 virtual void GetDevFontList( PhysicalFontCollection
* ) override
;
346 // graphics must drop any cached font info
347 virtual void ClearDevFontCache() override
;
348 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) override
;
349 // CreateFontSubset: a method to get a subset of glyhps of a font
350 // inside a new valid font file
351 // returns TRUE if creation of subset was successful
352 // parameters: rToFile: contains an osl file URL to write the subset to
353 // pFont: describes from which font to create a subset
354 // pGlyphIDs: the glyph ids to be extracted
355 // pEncoding: the character code corresponding to each glyph
356 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
357 // nGlyphs: the number of glyphs
358 // rInfo: additional outgoing information
359 // implementation note: encoding 0 with glyph id 0 should be added implicitly
360 // as "undefined character"
361 virtual bool CreateFontSubset( const OUString
& rToFile
,
362 const PhysicalFontFace
*,
363 const sal_GlyphId
* pGlyphIDs
,
364 const sal_uInt8
* pEncoding
,
367 FontSubsetInfo
& rInfo
// out parameter
370 // GetEmbedFontData: gets the font data for a font marked
371 // embeddable by GetDevFontList or NULL in case of error
372 // parameters: pFont: describes the font in question
373 // pDataLen: out parameter, contains the byte length of the returned buffer
374 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, tools::Long
* pDataLen
) override
;
375 // frees the font data again
376 virtual void FreeEmbedFontData( const void* pData
, tools::Long nDataLen
) override
;
377 virtual void GetGlyphWidths( const PhysicalFontFace
*,
379 std::vector
< sal_Int32
>& rWidths
,
380 Ucs2UIntMap
& rUnicodeEnc
) override
;
382 virtual std::unique_ptr
<GenericSalLayout
>
383 GetTextLayout(int nFallbackLevel
) override
;
384 virtual void DrawTextLayout( const GenericSalLayout
& ) override
;
386 virtual bool supportsOperation( OutDevSupportType
) const override
;
388 virtual SystemGraphicsData
GetGraphicsData() const override
;
390 /// Update settings based on the platform values
391 static void updateSettingsNative( AllSettings
& rSettings
);
394 // Init/Deinit Graphics
395 void ImplUpdateSysColorEntries();
396 int ImplIsSysColorEntry( Color nColor
);
397 void ImplGetLogFontFromFontSelect( const FontSelectPattern
&,
398 const PhysicalFontFace
*, LOGFONTW
& );
400 #define MAX_64KSALPOINTS ((((sal_uInt16)0xFFFF)-8)/sizeof(POINTS))
402 // called extremely often from just one spot => inline
403 inline bool WinFontFace::HasChar( sal_uInt32 cChar
) const
405 if( mxUnicodeMap
->HasChar( cChar
) )
407 // second chance to allow symbol aliasing
408 if( mbAliasSymbolsLow
&& ((cChar
-0xF000) <= 0xFF) )
410 else if( mbAliasSymbolsHigh
&& (cChar
<= 0xFF) )
414 return mxUnicodeMap
->HasChar( cChar
);
417 #endif // INCLUDED_VCL_INC_WIN_SALGDI_H
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */