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 class CommonSalLayout
;
48 struct SystemGraphicsData
;
50 #if ENABLE_CAIRO_CANVAS
51 struct SystemFontData
;
52 #endif // ENABLE_CAIRO_CANVAS
60 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
61 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
63 // note: if you add any new methods to class SalGraphics using coordinates
64 // make sure they have a corresponding protected pure virtual method
65 // which has to be implemented by the platform dependent part.
66 // Add a method that performs coordinate mirroring if required, (see
67 // existing methods as sample) and then calls the equivalent pure method.
69 // note: all positions are in pixel and relative to
70 // the top/left-position of the virtual output area
72 class VCL_PLUGIN_PUBLIC SalGraphics
76 virtual ~SalGraphics();
78 virtual SalGraphicsImpl
* GetImpl() const = 0;
80 /// Check that our mpImpl is OpenGL and return the context, otherwise NULL.
81 rtl::Reference
<OpenGLContext
> GetOpenGLContext() const;
83 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
84 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
86 // public SalGraphics methods, the interface to the independent vcl part
88 // get device resolution
89 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
91 // get the depth of the device
92 virtual sal_uInt16
GetBitCount() const = 0;
94 // get the width of the device
95 virtual long GetGraphicsWidth() const = 0;
97 // set the clip region to empty
98 virtual void ResetClipRegion() = 0;
100 // set the line color to transparent (= don't draw lines)
102 virtual void SetLineColor() = 0;
104 // set the line color to a specific color
105 virtual void SetLineColor( SalColor nSalColor
) = 0;
107 // set the fill color to transparent (= don't fill)
108 virtual void SetFillColor() = 0;
110 // set the fill color to a specific color, shapes will be
111 // filled accordingly
112 virtual void SetFillColor( SalColor nSalColor
) = 0;
114 // enable/disable XOR drawing
115 virtual void SetXORMode( bool bSet
) = 0;
117 // set line color for raster operations
118 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
120 // set fill color for raster operations
121 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
123 // set the text color to a specific color
124 virtual void SetTextColor( SalColor nSalColor
) = 0;
127 virtual void SetFont( FontSelectPattern
*, int nFallbackLevel
) = 0;
130 void ReleaseFonts() { SetFont( nullptr, 0 ); }
132 // get the current font's metrics
133 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) = 0;
135 // get the repertoire of the current font
136 virtual const FontCharMapRef
GetFontCharMap() const = 0;
138 // get the layout capabilities of the current font
139 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
141 // graphics must fill supplied font list
142 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
144 // graphics must drop any cached font info
145 virtual void ClearDevFontCache() = 0;
147 virtual bool AddTempDevFont(
148 PhysicalFontCollection
*,
149 const OUString
& rFileURL
,
150 const OUString
& rFontName
) = 0;
152 // CreateFontSubset: a method to get a subset of glyhps of a font
153 // inside a new valid font file
154 // returns true if creation of subset was successful
155 // parameters: rToFile: contains a osl file URL to write the subset to
156 // pFont: describes from which font to create a subset
157 // pGlyphIDs: the glyph ids to be extracted
158 // pEncoding: the character code corresponding to each glyph
159 // pWidths: the advance widths of the corresponding glyphs (in PS font units)
160 // nGlyphs: the number of glyphs
161 // rInfo: additional outgoing information
162 // implementation note: encoding 0 with glyph id 0 should be added implicitly
163 // as "undefined character"
164 virtual bool CreateFontSubset(
165 const OUString
& rToFile
,
166 const PhysicalFontFace
* pFont
,
167 const sal_GlyphId
* pGlyphIDs
,
168 const sal_uInt8
* pEncoding
,
171 FontSubsetInfo
& rInfo
) = 0;
173 // GetEmbedFontData: gets the font data for a font marked
174 // embeddable by GetDevFontList or NULL in case of error
175 // parameters: pFont: describes the font in question
176 // pDataLen: out parameter, contains the byte length of the returned buffer
177 virtual const void* GetEmbedFontData(const PhysicalFontFace
* pFont
, long* pDataLen
) = 0;
179 // free the font data again
180 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
182 // get the same widths as in CreateFontSubset
183 // in case of an embeddable font also fill the mapping
184 // between unicode and glyph id
185 // leave widths vector and mapping untouched in case of failure
186 virtual void GetGlyphWidths(
187 const PhysicalFontFace
* pFont
,
189 std::vector
< sal_Int32
>& rWidths
,
190 Ucs2UIntMap
& rUnicodeEnc
) = 0;
192 virtual bool GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) = 0;
193 virtual bool GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) = 0;
195 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
196 virtual void DrawTextLayout( const CommonSalLayout
& ) = 0;
198 virtual bool supportsOperation( OutDevSupportType
) const = 0;
200 // mirroring specifics
201 SalLayoutFlags
GetLayout() { return m_nLayout
; }
202 void SetLayout( SalLayoutFlags aLayout
) { m_nLayout
= aLayout
;}
204 void mirror( long& nX
, const OutputDevice
*pOutDev
) const;
205 void mirror( long& nX
, long& nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
206 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
) const;
207 void mirror( tools::Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
208 void mirror( vcl::Region
& rRgn
, const OutputDevice
*pOutDev
) const;
209 void mirror( ImplControlValue
&, const OutputDevice
* ) const;
210 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
) const;
211 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
212 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
214 // non virtual methods; these do possible coordinate mirroring and
215 // then delegate to protected virtual methods
216 bool SetClipRegion( const vcl::Region
&, const OutputDevice
*pOutDev
);
218 // draw --> LineColor and FillColor and RasterOp and ClipRegion
219 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
220 void DrawPixel( long nX
, long nY
, SalColor nSalColor
, const OutputDevice
*pOutDev
);
222 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
224 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
226 void DrawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
228 void DrawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
230 void DrawPolyPolygon(
232 const sal_uInt32
* pPoints
,
233 PCONSTSALPOINT
* pPtAry
,
234 const OutputDevice
*pOutDev
);
236 bool DrawPolyPolygon(
237 const basegfx::B2DPolyPolygon
&i_rPolyPolygon
,
238 double i_fTransparency
,
239 const OutputDevice
*i_pOutDev
);
242 const basegfx::B2DPolygon
& i_rPolygon
,
243 double i_fTransparency
,
244 const basegfx::B2DVector
& i_rLineWidth
,
245 basegfx::B2DLineJoin i_eLineJoin
,
246 css::drawing::LineCap i_eLineCap
,
247 double i_fMiterMinimumAngle
,
248 const OutputDevice
* i_pOutDev
);
250 bool DrawPolyLineBezier(
252 const SalPoint
* pPtAry
,
253 const PolyFlags
* pFlgAry
,
254 const OutputDevice
*pOutDev
);
256 bool DrawPolygonBezier(
258 const SalPoint
* pPtAry
,
259 const PolyFlags
* pFlgAry
,
260 const OutputDevice
*pOutDev
);
262 bool DrawPolyPolygonBezier(
264 const sal_uInt32
* pPoints
,
265 const SalPoint
* const* pPtAry
,
266 const PolyFlags
* const* pFlgAry
,
267 const OutputDevice
*pOutDev
);
270 const tools::PolyPolygon
& rPolyPoly
,
271 const Gradient
& rGradient
);
274 // CopyArea --> No RasterOp, but ClipRegion
276 long nDestX
, long nDestY
,
277 long nSrcX
, long nSrcY
,
278 long nSrcWidth
, long nSrcHeight
,
279 const OutputDevice
*pOutDev
);
281 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
282 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
284 const SalTwoRect
& rPosAry
,
285 SalGraphics
* pSrcGraphics
,
286 const OutputDevice
*pOutDev
,
287 const OutputDevice
*pSrcOutDev
);
290 const SalTwoRect
& rPosAry
,
291 const SalBitmap
& rSalBitmap
,
292 const OutputDevice
*pOutDev
);
295 const SalTwoRect
& rPosAry
,
296 const SalBitmap
& rSalBitmap
,
297 const SalBitmap
& rTransparentBitmap
,
298 const OutputDevice
*pOutDev
);
301 const SalTwoRect
& rPosAry
,
302 const SalBitmap
& rSalBitmap
,
304 const OutputDevice
*pOutDev
);
306 SalBitmap
* GetBitmap(
308 long nWidth
, long nHeight
,
309 const OutputDevice
*pOutDev
);
313 const OutputDevice
*pOutDev
);
315 // invert --> ClipRegion (only Windows)
318 long nWidth
, long nHeight
,
320 const OutputDevice
*pOutDev
);
324 const SalPoint
* pPtAry
,
326 const OutputDevice
*pOutDev
);
330 long nWidth
, long nHeight
,
333 const OutputDevice
*pOutDev
);
335 // native widget rendering functions
338 * Query the platform layer for native control support.
340 * @param [in] eType The widget type.
341 * @param [in] ePart The part of the widget.
342 * @return true if the platform supports native drawing of the widget type defined by part.
344 virtual bool IsNativeControlSupported(
345 ControlType eType
, ControlPart ePart
);
349 * Query the native control to determine if it was acted upon
351 * @see hitTestNativeControl
353 bool HitTestNativeScrollbar(
355 const tools::Rectangle
& rControlRegion
,
358 const OutputDevice
*pOutDev
);
361 * Request rendering of a particular control and/or part
363 * @see drawNativeControl
365 bool DrawNativeControl(
368 const tools::Rectangle
& rControlRegion
,
370 const ImplControlValue
& aValue
,
371 const OUString
& aCaption
,
372 const OutputDevice
*pOutDev
);
375 * Query the native control's actual drawing region (including adornment)
377 * @see getNativeControlRegion
379 bool GetNativeControlRegion(
382 const tools::Rectangle
& rControlRegion
,
384 const ImplControlValue
& aValue
,
385 tools::Rectangle
&rNativeBoundingRegion
,
386 tools::Rectangle
&rNativeContentRegion
,
387 const OutputDevice
*pOutDev
);
390 const SalTwoRect
& rPosAry
,
391 const SalBitmap
& rSalBitmap
,
392 const OutputDevice
*pOutDev
);
394 bool BlendAlphaBitmap(
395 const SalTwoRect
& rPosAry
,
396 const SalBitmap
& rSalSrcBitmap
,
397 const SalBitmap
& rSalMaskBitmap
,
398 const SalBitmap
& rSalAlphaBitmap
,
399 const OutputDevice
*pOutDev
);
401 bool DrawAlphaBitmap(
403 const SalBitmap
& rSourceBitmap
,
404 const SalBitmap
& rAlphaBitmap
,
405 const OutputDevice
*pOutDev
);
407 bool DrawTransformedBitmap(
408 const basegfx::B2DPoint
& rNull
,
409 const basegfx::B2DPoint
& rX
,
410 const basegfx::B2DPoint
& rY
,
411 const SalBitmap
& rSourceBitmap
,
412 const SalBitmap
* pAlphaBitmap
,
413 const OutputDevice
* pOutDev
);
417 long nWidth
, long nHeight
,
418 sal_uInt8 nTransparency
,
419 const OutputDevice
*pOutDev
);
421 virtual SystemGraphicsData
GetGraphicsData() const = 0;
423 #if ENABLE_CAIRO_CANVAS
425 /// Check whether cairo will work
426 virtual bool SupportsCairo() const = 0;
427 /// Create Surface from given cairo surface
428 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const = 0;
429 /// Create surface with given dimensions
430 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const = 0;
431 /// Create Surface for given bitmap data
432 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const = 0;
433 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const = 0;
435 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
437 #endif // ENABLE_CAIRO_CANVAS
440 virtual bool setClipRegion( const vcl::Region
& ) = 0;
442 // draw --> LineColor and FillColor and RasterOp and ClipRegion
443 virtual void drawPixel( long nX
, long nY
) = 0;
444 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) = 0;
446 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
448 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
450 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
452 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
454 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
455 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
457 virtual bool drawPolyLine(
458 const basegfx::B2DPolygon
&,
459 double fTransparency
,
460 const basegfx::B2DVector
& rLineWidths
,
461 basegfx::B2DLineJoin
,
462 css::drawing::LineCap
,
463 double fMiterMinimumAngle
) = 0;
465 virtual bool drawPolyLineBezier(
467 const SalPoint
* pPtAry
,
468 const PolyFlags
* pFlgAry
) = 0;
470 virtual bool drawPolygonBezier(
472 const SalPoint
* pPtAry
,
473 const PolyFlags
* pFlgAry
) = 0;
475 virtual bool drawPolyPolygonBezier(
477 const sal_uInt32
* pPoints
,
478 const SalPoint
* const* pPtAry
,
479 const PolyFlags
* const* pFlgAry
) = 0;
481 virtual bool drawGradient(
482 const tools::PolyPolygon
& rPolyPoly
,
483 const Gradient
& rGradient
) = 0;
485 // CopyArea --> No RasterOp, but ClipRegion
486 virtual void copyArea(
487 long nDestX
, long nDestY
,
488 long nSrcX
, long nSrcY
,
489 long nSrcWidth
, long nSrcHeight
,
490 bool bWindowInvalidate
) = 0;
492 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
493 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
494 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) = 0;
496 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) = 0;
498 virtual void drawBitmap(
499 const SalTwoRect
& rPosAry
,
500 const SalBitmap
& rSalBitmap
,
501 const SalBitmap
& rMaskBitmap
) = 0;
503 virtual void drawMask(
504 const SalTwoRect
& rPosAry
,
505 const SalBitmap
& rSalBitmap
,
506 SalColor nMaskColor
) = 0;
508 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
510 virtual SalColor
getPixel( long nX
, long nY
) = 0;
512 // invert --> ClipRegion (only Windows or VirDevs)
515 long nWidth
, long nHeight
,
516 SalInvert nFlags
) = 0;
518 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
520 virtual bool drawEPS(
522 long nWidth
, long nHeight
,
524 sal_uLong nSize
) = 0;
527 * Query if a position is inside the native widget part.
529 * Mainly used for scrollbars.
531 * @param [in] eType The widget type.
532 * @param [in] ePart The part of the widget.
533 * @param [in] rBoundingControlRegion The bounding Rectangle of
534 the complete control in VCL frame coordinates.
535 * @param [in] aPos The position to check the hit.
536 * @param [out] rIsInside true, if \a aPos was inside the native widget.
537 * @return true, if the query was successful.
539 virtual bool hitTestNativeControl(
540 ControlType eType
, ControlPart ePart
,
541 const tools::Rectangle
& rBoundingControlRegion
,
542 const Point
& aPos
, bool& rIsInside
);
545 * Draw the requested control.
547 * @param [in] eType The widget type.
548 * @param [in] ePart The part of the widget.
549 * @param [in] rBoundingControlRegion The bounding rectangle of
550 * the complete control in VCL frame coordinates.
551 * @param [in] eState The general state of the control (enabled, focused, etc.).
552 * @param [in] aValue Addition control specific information.
553 * @param [in] aCaption A caption or title string (like button text etc.).
554 * @return true, if the control could be drawn.
556 virtual bool drawNativeControl(
557 ControlType eType
, ControlPart ePart
,
558 const tools::Rectangle
& rBoundingControlRegion
,
560 const ImplControlValue
& aValue
,
561 const OUString
& aCaption
);
564 * Get the native control regions for the control part.
566 * If the return value is true, \a rNativeBoundingRegion contains
567 * the true bounding region covered by the control including any
568 * adornment, while \a rNativeContentRegion contains the area
569 * within the control that can be safely drawn into without drawing over
570 * the borders of the control.
572 * @param [in] eType Type of the widget.
573 * @param [in] ePart Specification of the widget's part if it consists of more than one.
574 * @param [in] rBoundingControlRegion The bounding region of the control in VCL frame coordinates.
575 * @param [in] eState The general state of the control (enabled, focused, etc.).
576 * @param [in] aValue Addition control specific information.
577 * @param [in] aCaption A caption or title string (like button text etc.).
578 * @param [out] rNativeBoundingRegion The region covered by the control including any adornment.
579 * @param [out] rNativeContentRegion The region within the control that can be safely drawn into.
580 * @return true, if the regions are filled.
582 virtual bool getNativeControlRegion(
583 ControlType eType
, ControlPart ePart
,
584 const tools::Rectangle
& rBoundingControlRegion
,
586 const ImplControlValue
& aValue
,
587 const OUString
& aCaption
,
588 tools::Rectangle
&rNativeBoundingRegion
,
589 tools::Rectangle
&rNativeContentRegion
);
591 /** Blend the bitmap with the current buffer */
592 virtual bool blendBitmap(
594 const SalBitmap
& rBitmap
) = 0;
596 /** Draw the bitmap by blending using the mask and alpha channel */
597 virtual bool blendAlphaBitmap(
599 const SalBitmap
& rSrcBitmap
,
600 const SalBitmap
& rMaskBitmap
,
601 const SalBitmap
& rAlphaBitmap
) = 0;
603 /** Render bitmap with alpha channel
606 Source bitmap to blit
609 Alpha channel to use for blitting
611 @return true, if the operation succeeded, and false
612 otherwise. In this case, clients should try to emulate alpha
613 compositing themselves
615 virtual bool drawAlphaBitmap(
617 const SalBitmap
& rSourceBitmap
,
618 const SalBitmap
& rAlphaBitmap
) = 0;
620 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
621 virtual bool drawTransformedBitmap(
622 const basegfx::B2DPoint
& rNull
,
623 const basegfx::B2DPoint
& rX
,
624 const basegfx::B2DPoint
& rY
,
625 const SalBitmap
& rSourceBitmap
,
626 const SalBitmap
* pAlphaBitmap
) = 0;
628 /** Render solid rectangle with given transparency
630 * @param nX Top left coordinate of rectangle
631 * @param nY Bottom right coordinate of rectangle
632 * @param nWidth Width of rectangle
633 * @param nHeight Height of rectangle
634 * @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a
635 * fully transparent rectangle
636 * @returns true if successfully drawn, false if not able to draw rectangle
638 virtual bool drawAlphaRect(
640 long nWidth
, long nHeight
,
641 sal_uInt8 nTransparency
) = 0;
644 SalLayoutFlags m_nLayout
; //< 0: mirroring off, 1: mirror x-axis
647 /// flags which hold the SetAntialiasing() value from OutputDevice
648 bool m_bAntiAliasB2DDraw
: 1;
652 #endif // INCLUDED_VCL_INC_SALGDI_HXX
654 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */