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/metric.hxx>
25 #include "impfontmetricdata.hxx"
26 #include "salgdiimpl.hxx"
27 #include "sallayout.hxx"
29 #include <config_cairo_canvas.h>
35 class PhysicalFontCollection
;
37 class FontSelectPattern
;
39 class PhysicalFontFace
;
42 namespace tools
{ class Rectangle
; }
47 struct SystemGraphicsData
;
49 #if ENABLE_CAIRO_CANVAS
50 struct SystemFontData
;
51 #endif // ENABLE_CAIRO_CANVAS
59 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
60 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
62 // note: if you add any new methods to class SalGraphics using coordinates
63 // make sure they have a corresponding protected pure virtual method
64 // which has to be implemented by the platform dependent part.
65 // Add a method that performs coordinate mirroring if required, (see
66 // existing methods as sample) and then calls the equivalent pure method.
68 // note: all positions are in pixel and relative to
69 // the top/left-position of the virtual output area
71 class VCL_PLUGIN_PUBLIC SalGraphics
75 virtual ~SalGraphics();
77 virtual SalGraphicsImpl
* GetImpl() const = 0;
79 /// Check that our mpImpl is OpenGL and return the context, otherwise NULL.
80 rtl::Reference
<OpenGLContext
> GetOpenGLContext() const;
82 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
83 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
85 // public SalGraphics methods, the interface to the independent vcl part
87 // get device resolution
88 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
90 // get the depth of the device
91 virtual sal_uInt16
GetBitCount() const = 0;
93 // get the width of the device
94 virtual long GetGraphicsWidth() const = 0;
96 // set the clip region to empty
97 virtual void ResetClipRegion() = 0;
99 // set the line color to transparent (= don't draw lines)
101 virtual void SetLineColor() = 0;
103 // set the line color to a specific color
104 virtual void SetLineColor( Color nColor
) = 0;
106 // set the fill color to transparent (= don't fill)
107 virtual void SetFillColor() = 0;
109 // set the fill color to a specific color, shapes will be
110 // filled accordingly
111 virtual void SetFillColor( Color nColor
) = 0;
113 // enable/disable XOR drawing
114 virtual void SetXORMode( bool bSet
) = 0;
116 // set line color for raster operations
117 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
119 // set fill color for raster operations
120 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
122 // set the text color to a specific color
123 virtual void SetTextColor( Color nColor
) = 0;
126 virtual void SetFont( const FontSelectPattern
*, int nFallbackLevel
) = 0;
129 void ReleaseFonts() { SetFont( nullptr, 0 ); }
131 // get the current font's metrics
132 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) = 0;
134 // get the repertoire of the current font
135 virtual const FontCharMapRef
GetFontCharMap() const = 0;
137 // get the layout capabilities of the current font
138 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
140 // graphics must fill supplied font list
141 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
143 // graphics must drop any cached font info
144 virtual void ClearDevFontCache() = 0;
146 virtual bool AddTempDevFont(
147 PhysicalFontCollection
*,
148 const OUString
& rFileURL
,
149 const OUString
& rFontName
) = 0;
151 // CreateFontSubset: a method to get a subset of glyhps of a font
152 // inside a new valid font file
153 // returns true if creation of subset was successful
154 // parameters: rToFile: contains a osl file URL to write the subset to
155 // pFont: describes from which font to create a subset
156 // pGlyphIDs: the glyph ids to be extracted
157 // pEncoding: the character code corresponding to each glyph
158 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
159 // nGlyphs: the number of glyphs
160 // rInfo: additional outgoing information
161 // implementation note: encoding 0 with glyph id 0 should be added implicitly
162 // as "undefined character"
163 virtual bool CreateFontSubset(
164 const OUString
& rToFile
,
165 const PhysicalFontFace
* pFont
,
166 const sal_GlyphId
* pGlyphIDs
,
167 const sal_uInt8
* pEncoding
,
170 FontSubsetInfo
& rInfo
) = 0;
172 // GetEmbedFontData: gets the font data for a font marked
173 // embeddable by GetDevFontList or NULL in case of error
174 // parameters: pFont: describes the font in question
175 // pDataLen: out parameter, contains the byte length of the returned buffer
176 virtual const void* GetEmbedFontData(const PhysicalFontFace
* pFont
, long* pDataLen
) = 0;
178 // free the font data again
179 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
181 // get the same widths as in CreateFontSubset
182 // in case of an embeddable font also fill the mapping
183 // between unicode and glyph id
184 // leave widths vector and mapping untouched in case of failure
185 virtual void GetGlyphWidths(
186 const PhysicalFontFace
* pFont
,
188 std::vector
< sal_Int32
>& rWidths
,
189 Ucs2UIntMap
& rUnicodeEnc
) = 0;
191 virtual bool GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) = 0;
192 virtual bool GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) = 0;
194 virtual std::unique_ptr
<SalLayout
>
195 GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
196 virtual void DrawTextLayout( const GenericSalLayout
& ) = 0;
198 virtual bool supportsOperation( OutDevSupportType
) const = 0;
200 // mirroring specifics
201 SalLayoutFlags
GetLayout() const { return m_nLayout
; }
202 void SetLayout( SalLayoutFlags aLayout
) { m_nLayout
= aLayout
;}
204 void mirror( long& nX
, const OutputDevice
*pOutDev
) const;
205 // only called mirror2 to avoid ambiguity
206 SAL_WARN_UNUSED_RESULT
207 long mirror2( long nX
, const OutputDevice
*pOutDev
) const;
208 void mirror( long& nX
, long nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
209 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
) const;
210 void mirror( tools::Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
211 void mirror( vcl::Region
& rRgn
, const OutputDevice
*pOutDev
) const;
212 void mirror( ImplControlValue
&, const OutputDevice
* ) const;
213 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
) const;
214 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
215 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, 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::B2DPolyPolygon
&i_rPolyPolygon
,
241 double i_fTransparency
,
242 const OutputDevice
*i_pOutDev
);
245 const basegfx::B2DPolygon
& i_rPolygon
,
246 double i_fTransparency
,
247 const basegfx::B2DVector
& i_rLineWidth
,
248 basegfx::B2DLineJoin i_eLineJoin
,
249 css::drawing::LineCap i_eLineCap
,
250 double i_fMiterMinimumAngle
,
251 const OutputDevice
* i_pOutDev
);
253 bool DrawPolyLineBezier(
255 const SalPoint
* pPtAry
,
256 const PolyFlags
* pFlgAry
,
257 const OutputDevice
*pOutDev
);
259 bool DrawPolygonBezier(
261 const SalPoint
* pPtAry
,
262 const PolyFlags
* pFlgAry
,
263 const OutputDevice
*pOutDev
);
265 bool DrawPolyPolygonBezier(
267 const sal_uInt32
* pPoints
,
268 const SalPoint
* const* pPtAry
,
269 const PolyFlags
* const* pFlgAry
,
270 const OutputDevice
*pOutDev
);
273 const tools::PolyPolygon
& rPolyPoly
,
274 const Gradient
& rGradient
);
277 // CopyArea --> No RasterOp, but ClipRegion
279 long nDestX
, long nDestY
,
280 long nSrcX
, long nSrcY
,
281 long nSrcWidth
, long nSrcHeight
,
282 const OutputDevice
*pOutDev
);
284 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
285 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
287 const SalTwoRect
& rPosAry
,
288 SalGraphics
* pSrcGraphics
,
289 const OutputDevice
*pOutDev
,
290 const OutputDevice
*pSrcOutDev
);
293 const SalTwoRect
& rPosAry
,
294 const SalBitmap
& rSalBitmap
,
295 const OutputDevice
*pOutDev
);
298 const SalTwoRect
& rPosAry
,
299 const SalBitmap
& rSalBitmap
,
300 const SalBitmap
& rTransparentBitmap
,
301 const OutputDevice
*pOutDev
);
304 const SalTwoRect
& rPosAry
,
305 const SalBitmap
& rSalBitmap
,
307 const OutputDevice
*pOutDev
);
309 SalBitmap
* GetBitmap(
311 long nWidth
, long nHeight
,
312 const OutputDevice
*pOutDev
);
316 const OutputDevice
*pOutDev
);
318 // invert --> ClipRegion (only Windows)
321 long nWidth
, long nHeight
,
323 const OutputDevice
*pOutDev
);
327 const SalPoint
* pPtAry
,
329 const OutputDevice
*pOutDev
);
333 long nWidth
, long nHeight
,
336 const OutputDevice
*pOutDev
);
338 // native widget rendering functions
341 * Query the platform layer for native control support.
343 * @param [in] eType The widget type.
344 * @param [in] ePart The part of the widget.
345 * @return true if the platform supports native drawing of the widget type defined by part.
347 virtual bool IsNativeControlSupported(
348 ControlType eType
, ControlPart ePart
);
352 * Query the native control to determine if it was acted upon
354 * @see hitTestNativeControl
356 bool HitTestNativeScrollbar(
358 const tools::Rectangle
& rControlRegion
,
361 const OutputDevice
*pOutDev
);
364 * Request rendering of a particular control and/or part
366 * @see drawNativeControl
368 bool DrawNativeControl(
371 const tools::Rectangle
& rControlRegion
,
373 const ImplControlValue
& aValue
,
374 const OUString
& aCaption
,
375 const OutputDevice
*pOutDev
);
378 * Query the native control's actual drawing region (including adornment)
380 * @see getNativeControlRegion
382 bool GetNativeControlRegion(
385 const tools::Rectangle
& rControlRegion
,
387 const ImplControlValue
& aValue
,
388 tools::Rectangle
&rNativeBoundingRegion
,
389 tools::Rectangle
&rNativeContentRegion
,
390 const OutputDevice
*pOutDev
);
393 const SalTwoRect
& rPosAry
,
394 const SalBitmap
& rSalBitmap
,
395 const OutputDevice
*pOutDev
);
397 bool BlendAlphaBitmap(
398 const SalTwoRect
& rPosAry
,
399 const SalBitmap
& rSalSrcBitmap
,
400 const SalBitmap
& rSalMaskBitmap
,
401 const SalBitmap
& rSalAlphaBitmap
,
402 const OutputDevice
*pOutDev
);
404 bool DrawAlphaBitmap(
406 const SalBitmap
& rSourceBitmap
,
407 const SalBitmap
& rAlphaBitmap
,
408 const OutputDevice
*pOutDev
);
410 bool DrawTransformedBitmap(
411 const basegfx::B2DPoint
& rNull
,
412 const basegfx::B2DPoint
& rX
,
413 const basegfx::B2DPoint
& rY
,
414 const SalBitmap
& rSourceBitmap
,
415 const SalBitmap
* pAlphaBitmap
,
416 const OutputDevice
* pOutDev
);
420 long nWidth
, long nHeight
,
421 sal_uInt8 nTransparency
,
422 const OutputDevice
*pOutDev
);
424 virtual SystemGraphicsData
GetGraphicsData() const = 0;
426 #if ENABLE_CAIRO_CANVAS
428 /// Check whether cairo will work
429 virtual bool SupportsCairo() const = 0;
430 /// Create Surface from given cairo surface
431 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const = 0;
432 /// Create surface with given dimensions
433 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const = 0;
434 /// Create Surface for given bitmap data
435 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const = 0;
436 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const = 0;
438 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
440 #endif // ENABLE_CAIRO_CANVAS
443 virtual bool setClipRegion( const vcl::Region
& ) = 0;
445 // draw --> LineColor and FillColor and RasterOp and ClipRegion
446 virtual void drawPixel( long nX
, long nY
) = 0;
447 virtual void drawPixel( long nX
, long nY
, Color nColor
) = 0;
449 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
451 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
453 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
455 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
457 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
458 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
460 virtual bool drawPolyLine(
461 const basegfx::B2DPolygon
&,
462 double fTransparency
,
463 const basegfx::B2DVector
& rLineWidths
,
464 basegfx::B2DLineJoin
,
465 css::drawing::LineCap
,
466 double fMiterMinimumAngle
) = 0;
468 virtual bool drawPolyLineBezier(
470 const SalPoint
* pPtAry
,
471 const PolyFlags
* pFlgAry
) = 0;
473 virtual bool drawPolygonBezier(
475 const SalPoint
* pPtAry
,
476 const PolyFlags
* pFlgAry
) = 0;
478 virtual bool drawPolyPolygonBezier(
480 const sal_uInt32
* pPoints
,
481 const SalPoint
* const* pPtAry
,
482 const PolyFlags
* const* pFlgAry
) = 0;
484 virtual bool drawGradient(
485 const tools::PolyPolygon
& rPolyPoly
,
486 const Gradient
& rGradient
) = 0;
488 // CopyArea --> No RasterOp, but ClipRegion
489 virtual void copyArea(
490 long nDestX
, long nDestY
,
491 long nSrcX
, long nSrcY
,
492 long nSrcWidth
, long nSrcHeight
,
493 bool bWindowInvalidate
) = 0;
495 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
496 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
497 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) = 0;
499 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) = 0;
501 virtual void drawBitmap(
502 const SalTwoRect
& rPosAry
,
503 const SalBitmap
& rSalBitmap
,
504 const SalBitmap
& rMaskBitmap
) = 0;
506 virtual void drawMask(
507 const SalTwoRect
& rPosAry
,
508 const SalBitmap
& rSalBitmap
,
509 Color nMaskColor
) = 0;
511 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
513 virtual Color
getPixel( long nX
, long nY
) = 0;
515 // invert --> ClipRegion (only Windows or VirDevs)
518 long nWidth
, long nHeight
,
519 SalInvert nFlags
) = 0;
521 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
523 virtual bool drawEPS(
525 long nWidth
, long nHeight
,
527 sal_uLong nSize
) = 0;
530 * Query if a position is inside the native widget part.
532 * Mainly used for scrollbars.
534 * @param [in] eType The widget type.
535 * @param [in] ePart The part of the widget.
536 * @param [in] rBoundingControlRegion The bounding Rectangle of
537 the complete control in VCL frame coordinates.
538 * @param [in] aPos The position to check the hit.
539 * @param [out] rIsInside true, if \a aPos was inside the native widget.
540 * @return true, if the query was successful.
542 virtual bool hitTestNativeControl(
543 ControlType eType
, ControlPart ePart
,
544 const tools::Rectangle
& rBoundingControlRegion
,
545 const Point
& aPos
, bool& rIsInside
);
548 * Draw the requested control.
550 * @param [in] eType The widget type.
551 * @param [in] ePart The part of the widget.
552 * @param [in] rBoundingControlRegion The bounding rectangle of
553 * the complete control in VCL frame coordinates.
554 * @param [in] eState The general state of the control (enabled, focused, etc.).
555 * @param [in] aValue Addition control specific information.
556 * @param [in] aCaption A caption or title string (like button text etc.).
557 * @return true, if the control could be drawn.
559 virtual bool drawNativeControl(
560 ControlType eType
, ControlPart ePart
,
561 const tools::Rectangle
& rBoundingControlRegion
,
563 const ImplControlValue
& aValue
,
564 const OUString
& aCaption
);
567 * Get the native control regions for the control part.
569 * If the return value is true, \a rNativeBoundingRegion contains
570 * the true bounding region covered by the control including any
571 * adornment, while \a rNativeContentRegion contains the area
572 * within the control that can be safely drawn into without drawing over
573 * the borders of the control.
575 * @param [in] eType Type of the widget.
576 * @param [in] ePart Specification of the widget's part if it consists of more than one.
577 * @param [in] rBoundingControlRegion The bounding region of the control in VCL frame coordinates.
578 * @param [in] eState The general state of the control (enabled, focused, etc.).
579 * @param [in] aValue Addition control specific information.
580 * @param [in] aCaption A caption or title string (like button text etc.).
581 * @param [out] rNativeBoundingRegion The region covered by the control including any adornment.
582 * @param [out] rNativeContentRegion The region within the control that can be safely drawn into.
583 * @return true, if the regions are filled.
585 virtual bool getNativeControlRegion(
586 ControlType eType
, ControlPart ePart
,
587 const tools::Rectangle
& rBoundingControlRegion
,
589 const ImplControlValue
& aValue
,
590 const OUString
& aCaption
,
591 tools::Rectangle
&rNativeBoundingRegion
,
592 tools::Rectangle
&rNativeContentRegion
);
594 /** Blend the bitmap with the current buffer */
595 virtual bool blendBitmap(
597 const SalBitmap
& rBitmap
) = 0;
599 /** Draw the bitmap by blending using the mask and alpha channel */
600 virtual bool blendAlphaBitmap(
602 const SalBitmap
& rSrcBitmap
,
603 const SalBitmap
& rMaskBitmap
,
604 const SalBitmap
& rAlphaBitmap
) = 0;
606 /** Render bitmap with alpha channel
609 Source bitmap to blit
612 Alpha channel to use for blitting
614 @return true, if the operation succeeded, and false
615 otherwise. In this case, clients should try to emulate alpha
616 compositing themselves
618 virtual bool drawAlphaBitmap(
620 const SalBitmap
& rSourceBitmap
,
621 const SalBitmap
& rAlphaBitmap
) = 0;
623 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
624 virtual bool drawTransformedBitmap(
625 const basegfx::B2DPoint
& rNull
,
626 const basegfx::B2DPoint
& rX
,
627 const basegfx::B2DPoint
& rY
,
628 const SalBitmap
& rSourceBitmap
,
629 const SalBitmap
* pAlphaBitmap
) = 0;
631 /** Render solid rectangle with given transparency
633 * @param nX Top left coordinate of rectangle
634 * @param nY Bottom right coordinate of rectangle
635 * @param nWidth Width of rectangle
636 * @param nHeight Height of rectangle
637 * @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a
638 * fully transparent rectangle
639 * @returns true if successfully drawn, false if not able to draw rectangle
641 virtual bool drawAlphaRect(
643 long nWidth
, long nHeight
,
644 sal_uInt8 nTransparency
) = 0;
647 SalLayoutFlags m_nLayout
; //< 0: mirroring off, 1: mirror x-axis
650 /// flags which hold the SetAntialiasing() value from OutputDevice
651 bool m_bAntiAliasB2DDraw
: 1;
655 #endif // INCLUDED_VCL_INC_SALGDI_HXX
657 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */