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_SALGDI_HXX
21 #define INCLUDED_VCL_INC_SALGDI_HXX
23 #include <vcl/outdev.hxx>
25 #include "impfontmetricdata.hxx"
26 #include "salgdiimpl.hxx"
27 #include "sallayout.hxx"
28 #include "SalGradient.hxx"
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include "WidgetDrawInterface.hxx"
32 #include <config_cairo_canvas.h>
37 class PhysicalFontCollection
;
39 class FontSelectPattern
;
41 class PhysicalFontFace
;
44 namespace tools
{ class Rectangle
; }
49 struct SystemGraphicsData
;
51 #if ENABLE_CAIRO_CANVAS
52 struct SystemFontData
;
53 #endif // ENABLE_CAIRO_CANVAS
61 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
62 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
64 // note: if you add any new methods to class SalGraphics using coordinates
65 // make sure they have a corresponding protected pure virtual method
66 // which has to be implemented by the platform dependent part.
67 // Add a method that performs coordinate mirroring if required, (see
68 // existing methods as sample) and then calls the equivalent pure method.
70 // note: all positions are in pixel and relative to
71 // the top/left-position of the virtual output area
73 class VCL_PLUGIN_PUBLIC SalGraphics
: protected vcl::WidgetDrawInterface
77 ~SalGraphics() COVERITY_NOEXCEPT_FALSE override
;
79 virtual SalGraphicsImpl
* GetImpl() const = 0;
81 /// Check that our mpImpl is OpenGL and return the context, otherwise NULL.
82 rtl::Reference
<OpenGLContext
> GetOpenGLContext() const;
84 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
85 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
87 // public SalGraphics methods, the interface to the independent vcl part
89 // get device resolution
90 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
92 // get the depth of the device
93 virtual sal_uInt16
GetBitCount() const = 0;
95 // get the width of the device
96 virtual long GetGraphicsWidth() const = 0;
98 // set the clip region to empty
99 virtual void ResetClipRegion() = 0;
101 // set the line color to transparent (= don't draw lines)
103 virtual void SetLineColor() = 0;
105 // set the line color to a specific color
106 virtual void SetLineColor( Color nColor
) = 0;
108 // set the fill color to transparent (= don't fill)
109 virtual void SetFillColor() = 0;
111 // set the fill color to a specific color, shapes will be
112 // filled accordingly
113 virtual void SetFillColor( Color nColor
) = 0;
115 // enable/disable XOR drawing
116 virtual void SetXORMode( bool bSet
, bool bInvertOnly
) = 0;
118 // set line color for raster operations
119 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
121 // set fill color for raster operations
122 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
124 // set the text color to a specific color
125 virtual void SetTextColor( Color nColor
) = 0;
128 virtual void SetFont(LogicalFontInstance
*, int nFallbackLevel
) = 0;
131 void ReleaseFonts() { SetFont( nullptr, 0 ); }
133 // get the current font's metrics
134 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) = 0;
136 // get the repertoire of the current font
137 virtual FontCharMapRef
GetFontCharMap() const = 0;
139 // get the layout capabilities of the current font
140 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
142 // graphics must fill supplied font list
143 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
145 // graphics must drop any cached font info
146 virtual void ClearDevFontCache() = 0;
148 virtual bool AddTempDevFont(
149 PhysicalFontCollection
*,
150 const OUString
& rFileURL
,
151 const OUString
& rFontName
) = 0;
153 // CreateFontSubset: a method to get a subset of glyhps of a font
154 // inside a new valid font file
155 // returns true if creation of subset was successful
156 // parameters: rToFile: contains an osl file URL to write the subset to
157 // pFont: describes from which font to create a subset
158 // pGlyphIDs: the glyph ids to be extracted
159 // pEncoding: the character code corresponding to each glyph
160 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
161 // nGlyphs: the number of glyphs
162 // rInfo: additional outgoing information
163 // implementation note: encoding 0 with glyph id 0 should be added implicitly
164 // as "undefined character"
165 virtual bool CreateFontSubset(
166 const OUString
& rToFile
,
167 const PhysicalFontFace
* pFont
,
168 const sal_GlyphId
* pGlyphIDs
,
169 const sal_uInt8
* pEncoding
,
172 FontSubsetInfo
& rInfo
) = 0;
174 // GetEmbedFontData: gets the font data for a font marked
175 // embeddable by GetDevFontList or NULL in case of error
176 // parameters: pFont: describes the font in question
177 // pDataLen: out parameter, contains the byte length of the returned buffer
178 virtual const void* GetEmbedFontData(const PhysicalFontFace
* pFont
, long* pDataLen
) = 0;
180 // free the font data again
181 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
183 // get the same widths as in CreateFontSubset
184 // in case of an embeddable font also fill the mapping
185 // between unicode and glyph id
186 // leave widths vector and mapping untouched in case of failure
187 virtual void GetGlyphWidths(
188 const PhysicalFontFace
* pFont
,
190 std::vector
< sal_Int32
>& rWidths
,
191 Ucs2UIntMap
& rUnicodeEnc
) = 0;
193 virtual std::unique_ptr
<GenericSalLayout
>
194 GetTextLayout(int nFallbackLevel
) = 0;
195 virtual void DrawTextLayout( const GenericSalLayout
& ) = 0;
197 virtual bool supportsOperation( OutDevSupportType
) const = 0;
199 // mirroring specifics
200 SalLayoutFlags
GetLayout() const { return m_nLayout
; }
201 void SetLayout( SalLayoutFlags aLayout
) { m_nLayout
= aLayout
;}
203 void mirror( long& nX
, const OutputDevice
*pOutDev
) const;
204 // only called mirror2 to avoid ambiguity
206 long mirror2( long nX
, const OutputDevice
*pOutDev
) const;
207 void mirror( long& nX
, long nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
208 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
) const;
209 void mirror( tools::Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
210 void mirror( vcl::Region
& rRgn
, const OutputDevice
*pOutDev
) const;
211 void mirror( ImplControlValue
&, const OutputDevice
* ) const;
212 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
) const;
213 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
214 const basegfx::B2DHomMatrix
& getMirror( const OutputDevice
*pOutDev
) const;
215 basegfx::B2DHomMatrix
mirror( const basegfx::B2DHomMatrix
& i_rMatrix
, const OutputDevice
*pOutDev
) const;
217 // non virtual methods; these do possible coordinate mirroring and
218 // then delegate to protected virtual methods
219 bool SetClipRegion( const vcl::Region
&, const OutputDevice
*pOutDev
);
221 // draw --> LineColor and FillColor and RasterOp and ClipRegion
222 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
223 void DrawPixel( long nX
, long nY
, Color nColor
, const OutputDevice
*pOutDev
);
225 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
227 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
229 void DrawPolyLine( sal_uInt32 nPoints
, SalPoint
const * pPtAry
, const OutputDevice
*pOutDev
);
231 void DrawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
233 void DrawPolyPolygon(
235 const sal_uInt32
* pPoints
,
236 PCONSTSALPOINT
* pPtAry
,
237 const OutputDevice
*pOutDev
);
239 bool DrawPolyPolygon(
240 const basegfx::B2DHomMatrix
& rObjectToDevice
,
241 const basegfx::B2DPolyPolygon
&i_rPolyPolygon
,
242 double i_fTransparency
,
243 const OutputDevice
*i_pOutDev
);
246 const basegfx::B2DHomMatrix
& rObjectToDevice
,
247 const basegfx::B2DPolygon
& i_rPolygon
,
248 double i_fTransparency
,
249 const basegfx::B2DVector
& i_rLineWidth
,
250 basegfx::B2DLineJoin i_eLineJoin
,
251 css::drawing::LineCap i_eLineCap
,
252 double i_fMiterMinimumAngle
,
253 bool bPixelSnapHairline
,
254 const OutputDevice
* i_pOutDev
);
256 bool DrawPolyLineBezier(
258 const SalPoint
* pPtAry
,
259 const PolyFlags
* pFlgAry
,
260 const OutputDevice
*pOutDev
);
262 bool DrawPolygonBezier(
264 const SalPoint
* pPtAry
,
265 const PolyFlags
* pFlgAry
,
266 const OutputDevice
*pOutDev
);
268 bool DrawPolyPolygonBezier(
270 const sal_uInt32
* pPoints
,
271 const SalPoint
* const* pPtAry
,
272 const PolyFlags
* const* pFlgAry
,
273 const OutputDevice
*pOutDev
);
276 const tools::PolyPolygon
& rPolyPoly
,
277 const Gradient
& rGradient
);
279 bool DrawGradient(basegfx::B2DPolyPolygon
const & rPolyPolygon
,
280 SalGradient
const & rGradient
);
282 // CopyArea --> No RasterOp, but ClipRegion
284 long nDestX
, long nDestY
,
285 long nSrcX
, long nSrcY
,
286 long nSrcWidth
, long nSrcHeight
,
287 const OutputDevice
*pOutDev
);
289 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
290 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
292 const SalTwoRect
& rPosAry
,
293 SalGraphics
* pSrcGraphics
,
294 const OutputDevice
*pOutDev
,
295 const OutputDevice
*pSrcOutDev
);
298 const SalTwoRect
& rPosAry
,
299 const SalBitmap
& rSalBitmap
,
300 const OutputDevice
*pOutDev
);
303 const SalTwoRect
& rPosAry
,
304 const SalBitmap
& rSalBitmap
,
305 const SalBitmap
& rTransparentBitmap
,
306 const OutputDevice
*pOutDev
);
309 const SalTwoRect
& rPosAry
,
310 const SalBitmap
& rSalBitmap
,
312 const OutputDevice
*pOutDev
);
314 std::shared_ptr
<SalBitmap
> GetBitmap(
316 long nWidth
, long nHeight
,
317 const OutputDevice
*pOutDev
);
321 const OutputDevice
*pOutDev
);
323 // invert --> ClipRegion (only Windows)
326 long nWidth
, long nHeight
,
328 const OutputDevice
*pOutDev
);
332 const SalPoint
* pPtAry
,
334 const OutputDevice
*pOutDev
);
338 long nWidth
, long nHeight
,
341 const OutputDevice
*pOutDev
);
343 // native widget rendering functions
346 * @see WidgetDrawInterface::isNativeControlSupported
348 inline bool IsNativeControlSupported(ControlType
, ControlPart
);
351 * @see WidgetDrawInterface::hitTestNativeControl
353 bool HitTestNativeScrollbar(
355 const tools::Rectangle
& rControlRegion
,
358 const OutputDevice
*pOutDev
);
361 * @see WidgetDrawInterface::drawNativeControl
363 bool DrawNativeControl(
366 const tools::Rectangle
& rControlRegion
,
368 const ImplControlValue
& aValue
,
369 const OUString
& aCaption
,
370 const OutputDevice
*pOutDev
);
373 * @see WidgetDrawInterface::getNativeControlRegion
375 bool GetNativeControlRegion(
378 const tools::Rectangle
& rControlRegion
,
380 const ImplControlValue
& aValue
,
381 tools::Rectangle
&rNativeBoundingRegion
,
382 tools::Rectangle
&rNativeContentRegion
,
383 const OutputDevice
*pOutDev
);
386 * @see WidgetDrawInterface::updateSettings
388 inline bool UpdateSettings(AllSettings
&);
391 const SalTwoRect
& rPosAry
,
392 const SalBitmap
& rSalBitmap
,
393 const OutputDevice
*pOutDev
);
395 bool BlendAlphaBitmap(
396 const SalTwoRect
& rPosAry
,
397 const SalBitmap
& rSalSrcBitmap
,
398 const SalBitmap
& rSalMaskBitmap
,
399 const SalBitmap
& rSalAlphaBitmap
,
400 const OutputDevice
*pOutDev
);
402 bool DrawAlphaBitmap(
404 const SalBitmap
& rSourceBitmap
,
405 const SalBitmap
& rAlphaBitmap
,
406 const OutputDevice
*pOutDev
);
408 bool DrawTransformedBitmap(
409 const basegfx::B2DPoint
& rNull
,
410 const basegfx::B2DPoint
& rX
,
411 const basegfx::B2DPoint
& rY
,
412 const SalBitmap
& rSourceBitmap
,
413 const SalBitmap
* pAlphaBitmap
,
414 const OutputDevice
* pOutDev
);
418 long nWidth
, long nHeight
,
419 sal_uInt8 nTransparency
,
420 const OutputDevice
*pOutDev
);
422 virtual SystemGraphicsData
GetGraphicsData() const = 0;
424 #if ENABLE_CAIRO_CANVAS
426 /// Check whether cairo will work
427 virtual bool SupportsCairo() const = 0;
428 /// Create Surface from given cairo surface
429 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const = 0;
430 /// Create surface with given dimensions
431 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const = 0;
432 /// Create Surface for given bitmap data
433 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const = 0;
434 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const = 0;
436 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
438 #endif // ENABLE_CAIRO_CANVAS
441 virtual bool setClipRegion( const vcl::Region
& ) = 0;
443 // draw --> LineColor and FillColor and RasterOp and ClipRegion
444 virtual void drawPixel( long nX
, long nY
) = 0;
445 virtual void drawPixel( long nX
, long nY
, Color nColor
) = 0;
447 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
449 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
451 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
453 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
455 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
457 virtual bool drawPolyPolygon(
458 const basegfx::B2DHomMatrix
& rObjectToDevice
,
459 const basegfx::B2DPolyPolygon
&,
460 double fTransparency
) = 0;
462 virtual bool drawPolyLine(
463 const basegfx::B2DHomMatrix
& rObjectToDevice
,
464 const basegfx::B2DPolygon
&,
465 double fTransparency
,
466 const basegfx::B2DVector
& rLineWidths
,
467 basegfx::B2DLineJoin
,
468 css::drawing::LineCap
,
469 double fMiterMinimumAngle
,
470 bool bPixelSnapHairline
) = 0;
472 virtual bool drawPolyLineBezier(
474 const SalPoint
* pPtAry
,
475 const PolyFlags
* pFlgAry
) = 0;
477 virtual bool drawPolygonBezier(
479 const SalPoint
* pPtAry
,
480 const PolyFlags
* pFlgAry
) = 0;
482 virtual bool drawPolyPolygonBezier(
484 const sal_uInt32
* pPoints
,
485 const SalPoint
* const* pPtAry
,
486 const PolyFlags
* const* pFlgAry
) = 0;
488 virtual bool drawGradient(
489 const tools::PolyPolygon
& rPolyPoly
,
490 const Gradient
& rGradient
) = 0;
492 virtual bool implDrawGradient(basegfx::B2DPolyPolygon
const & /*rPolyPolygon*/,
493 SalGradient
const & /*rGradient*/)
498 // CopyArea --> No RasterOp, but ClipRegion
499 virtual void copyArea(
500 long nDestX
, long nDestY
,
501 long nSrcX
, long nSrcY
,
502 long nSrcWidth
, long nSrcHeight
,
503 bool bWindowInvalidate
) = 0;
505 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
506 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
507 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) = 0;
509 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) = 0;
511 virtual void drawBitmap(
512 const SalTwoRect
& rPosAry
,
513 const SalBitmap
& rSalBitmap
,
514 const SalBitmap
& rMaskBitmap
) = 0;
516 virtual void drawMask(
517 const SalTwoRect
& rPosAry
,
518 const SalBitmap
& rSalBitmap
,
519 Color nMaskColor
) = 0;
521 virtual std::shared_ptr
<SalBitmap
> getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
523 virtual Color
getPixel( long nX
, long nY
) = 0;
525 // invert --> ClipRegion (only Windows or VirDevs)
528 long nWidth
, long nHeight
,
529 SalInvert nFlags
) = 0;
531 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
533 virtual bool drawEPS(
535 long nWidth
, long nHeight
,
537 sal_uInt32 nSize
) = 0;
539 /** Blend the bitmap with the current buffer */
540 virtual bool blendBitmap(
542 const SalBitmap
& rBitmap
) = 0;
544 /** Draw the bitmap by blending using the mask and alpha channel */
545 virtual bool blendAlphaBitmap(
547 const SalBitmap
& rSrcBitmap
,
548 const SalBitmap
& rMaskBitmap
,
549 const SalBitmap
& rAlphaBitmap
) = 0;
551 /** Render bitmap with alpha channel
554 Source bitmap to blit
557 Alpha channel to use for blitting
559 @return true, if the operation succeeded, and false
560 otherwise. In this case, clients should try to emulate alpha
561 compositing themselves
563 virtual bool drawAlphaBitmap(
565 const SalBitmap
& rSourceBitmap
,
566 const SalBitmap
& rAlphaBitmap
) = 0;
568 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
569 virtual bool drawTransformedBitmap(
570 const basegfx::B2DPoint
& rNull
,
571 const basegfx::B2DPoint
& rX
,
572 const basegfx::B2DPoint
& rY
,
573 const SalBitmap
& rSourceBitmap
,
574 const SalBitmap
* pAlphaBitmap
) = 0;
576 /** Render solid rectangle with given transparency
578 * @param nX Top left coordinate of rectangle
579 * @param nY Bottom right coordinate of rectangle
580 * @param nWidth Width of rectangle
581 * @param nHeight Height of rectangle
582 * @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a
583 * fully transparent rectangle
584 * @returns true if successfully drawn, false if not able to draw rectangle
586 virtual bool drawAlphaRect(
588 long nWidth
, long nHeight
,
589 sal_uInt8 nTransparency
) = 0;
592 SalLayoutFlags m_nLayout
; //< 0: mirroring off, 1: mirror x-axis
594 // for buffering the Mirror-Matrix, see ::getMirror
595 basegfx::B2DHomMatrix m_aLastMirror
;
599 /// flags which hold the SetAntialiasing() value from OutputDevice
600 bool m_bAntiAliasB2DDraw
: 1;
602 inline long GetDeviceWidth(const OutputDevice
* pOutDev
) const;
605 * Handle damage done by drawing with a widget draw override
607 * If a m_pWidgetDraw is set and successfully draws using drawNativeControl,
608 * this function is called to handle the damage done to the graphics buffer.
610 * @param rDamagedRegion the region damaged by drawNativeControl.
612 virtual inline void handleDamage(const tools::Rectangle
& rDamagedRegion
);
615 bool initWidgetDrawBackends(bool bForce
= false);
617 std::unique_ptr
<vcl::WidgetDrawInterface
> m_pWidgetDraw
;
618 vcl::WidgetDrawInterface
* forWidget() { return m_pWidgetDraw
? m_pWidgetDraw
.get() : this; }
621 bool SalGraphics::IsNativeControlSupported(ControlType eType
, ControlPart ePart
)
623 return forWidget()->isNativeControlSupported(eType
, ePart
);
626 bool SalGraphics::UpdateSettings(AllSettings
& rSettings
)
628 return forWidget()->updateSettings(rSettings
);
631 void SalGraphics::handleDamage(const tools::Rectangle
&) {}
633 #endif // INCLUDED_VCL_INC_SALGDI_HXX
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */