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
;
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_Int32
> Ucs2SIntMap
;
62 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
63 typedef std::map
< sal_Ucs
, OString
> Ucs2OStrMap
;
65 // note: if you add any new methods to class SalGraphics using coordinates
66 // make sure they have a corresponding protected pure virtual method
67 // which has to be implemented by the platform dependent part.
68 // Add a method that performs coordinate mirroring if required, (see
69 // existing methods as sample) and then calls the equivalent pure method.
71 // note: all positions are in pixel and relative to
72 // the top/left-position of the virtual output area
74 class VCL_PLUGIN_PUBLIC SalGraphics
78 virtual ~SalGraphics();
80 virtual SalGraphicsImpl
* GetImpl() const = 0;
82 /// Check that our mpImpl is OpenGL and return the context, otherwise NULL.
83 rtl::Reference
<OpenGLContext
> GetOpenGLContext() const;
85 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
86 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
88 // public SalGraphics methods, the interface to the independent vcl part
90 // get device resolution
91 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
93 // get the depth of the device
94 virtual sal_uInt16
GetBitCount() const = 0;
96 // get the width of the device
97 virtual long GetGraphicsWidth() const = 0;
99 // set the clip region to empty
100 virtual void ResetClipRegion() = 0;
102 // set the line color to transparent (= don't draw lines)
104 virtual void SetLineColor() = 0;
106 // set the line color to a specific color
107 virtual void SetLineColor( SalColor nSalColor
) = 0;
109 // set the fill color to transparent (= don't fill)
110 virtual void SetFillColor() = 0;
112 // set the fill color to a specific color, shapes will be
113 // filled accordingly
114 virtual void SetFillColor( SalColor nSalColor
) = 0;
116 // enable/disable XOR drawing
117 virtual void SetXORMode( bool bSet
) = 0;
119 // set line color for raster operations
120 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
122 // set fill color for raster operations
123 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
125 // set the text color to a specific color
126 virtual void SetTextColor( SalColor nSalColor
) = 0;
129 virtual void SetFont( FontSelectPattern
*, int nFallbackLevel
) = 0;
132 void ReleaseFonts() { SetFont( nullptr, 0 ); }
134 // get the current font's metrics
135 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) = 0;
137 // get the repertoire of the current font
138 virtual const FontCharMapRef
GetFontCharMap() const = 0;
140 // get the layout capabilities of the current font
141 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
143 // graphics must fill supplied font list
144 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
146 // graphics must drop any cached font info
147 virtual void ClearDevFontCache() = 0;
149 virtual bool AddTempDevFont(
150 PhysicalFontCollection
*,
151 const OUString
& rFileURL
,
152 const OUString
& rFontName
) = 0;
154 // CreateFontSubset: a method to get a subset of glyhps of a font
155 // inside a new valid font file
156 // returns true if creation of subset was successful
157 // parameters: rToFile: contains a osl file URL to write the subset to
158 // pFont: describes from which font to create a subset
159 // pGlyphIDs: the glyph ids to be extracted
160 // pEncoding: the character code corresponding to each glyph
161 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
162 // nGlyphs: the number of glyphs
163 // rInfo: additional outgoing information
164 // implementation note: encoding 0 with glyph id 0 should be added implicitly
165 // as "undefined character"
166 virtual bool CreateFontSubset(
167 const OUString
& rToFile
,
168 const PhysicalFontFace
* pFont
,
169 const sal_GlyphId
* pGlyphIDs
,
170 const sal_uInt8
* pEncoding
,
173 FontSubsetInfo
& rInfo
) = 0;
175 // GetFontEncodingVector: a method to get the encoding map Unicode
176 // to font encoded character; this is only used for type1 fonts and
177 // may return NULL in case of unknown encoding vector
178 // if ppNonEncoded is set and non encoded characters (that is type1
179 // glyphs with only a name) exist it is set to the corresponding
180 // map for non encoded glyphs; the encoding vector contains -1
181 // as encoding for these cases
182 virtual const Ucs2SIntMap
* GetFontEncodingVector(
183 const PhysicalFontFace
*,
184 const Ucs2OStrMap
** ppNonEncoded
,
185 std::set
<sal_Unicode
> const** ppPriority
) = 0;
187 // GetEmbedFontData: gets the font data for a font marked
188 // embeddable by GetDevFontList or NULL in case of error
189 // parameters: pFont: describes the font in question
190 // pUnicodes: contains the Unicodes assigned to code points 0 to 255
191 // pWidths: the widths of all glyphs from char code 0 to 255
192 // nLen: the number of elements in each of pWidths and pUnicodes
193 // rInfo: additional outgoing information
194 // pDataLen: out parameter, contains the byte length of the returned buffer
195 virtual const void* GetEmbedFontData(
196 const PhysicalFontFace
* pFont
,
197 const sal_Ucs
* pUnicodes
,
200 FontSubsetInfo
& rInfo
,
201 long* pDataLen
) = 0;
203 // free the font data again
204 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
206 // get the same widths as in CreateFontSubset and GetEmbedFontData
207 // in case of an embeddable font also fill the mapping
208 // between unicode and glyph id
209 // leave widths vector and mapping untouched in case of failure
210 virtual void GetGlyphWidths(
211 const PhysicalFontFace
* pFont
,
213 std::vector
< sal_Int32
>& rWidths
,
214 Ucs2UIntMap
& rUnicodeEnc
) = 0;
216 virtual bool GetGlyphBoundRect( sal_GlyphId
, Rectangle
& ) = 0;
217 virtual bool GetGlyphOutline( sal_GlyphId
, basegfx::B2DPolyPolygon
& ) = 0;
219 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
220 virtual void DrawTextLayout( const CommonSalLayout
& ) = 0;
222 virtual bool supportsOperation( OutDevSupportType
) const = 0;
224 // mirroring specifics
225 SalLayoutFlags
GetLayout() { return m_nLayout
; }
226 void SetLayout( SalLayoutFlags aLayout
) { m_nLayout
= aLayout
;}
228 void mirror( long& nX
, const OutputDevice
*pOutDev
) const;
229 void mirror( long& nX
, long& nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
230 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
) const;
231 void mirror( Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
232 void mirror( vcl::Region
& rRgn
, const OutputDevice
*pOutDev
) const;
233 void mirror( ImplControlValue
&, const OutputDevice
* ) const;
234 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
) const;
235 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
236 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
) const;
238 // non virtual methods; these do possible coordinate mirroring and
239 // then delegate to protected virtual methods
240 bool SetClipRegion( const vcl::Region
&, const OutputDevice
*pOutDev
);
242 // draw --> LineColor and FillColor and RasterOp and ClipRegion
243 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
244 void DrawPixel( long nX
, long nY
, SalColor nSalColor
, const OutputDevice
*pOutDev
);
246 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
248 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
250 void DrawPolyLine( sal_uInt32 nPoints
, SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
252 void DrawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
254 void DrawPolyPolygon(
256 const sal_uInt32
* pPoints
,
257 PCONSTSALPOINT
* pPtAry
,
258 const OutputDevice
*pOutDev
);
260 bool DrawPolyPolygon(
261 const basegfx::B2DPolyPolygon
&i_rPolyPolygon
,
262 double i_fTransparency
,
263 const OutputDevice
*i_pOutDev
);
266 const basegfx::B2DPolygon
& i_rPolygon
,
267 double i_fTransparency
,
268 const basegfx::B2DVector
& i_rLineWidth
,
269 basegfx::B2DLineJoin i_eLineJoin
,
270 css::drawing::LineCap i_eLineCap
,
271 double i_fMiterMinimumAngle
,
272 const OutputDevice
* i_pOutDev
);
274 bool DrawPolyLineBezier(
276 const SalPoint
* pPtAry
,
277 const PolyFlags
* pFlgAry
,
278 const OutputDevice
*pOutDev
);
280 bool DrawPolygonBezier(
282 const SalPoint
* pPtAry
,
283 const PolyFlags
* pFlgAry
,
284 const OutputDevice
*pOutDev
);
286 bool DrawPolyPolygonBezier(
288 const sal_uInt32
* pPoints
,
289 const SalPoint
* const* pPtAry
,
290 const PolyFlags
* const* pFlgAry
,
291 const OutputDevice
*pOutDev
);
294 const tools::PolyPolygon
& rPolyPoly
,
295 const Gradient
& rGradient
,
299 // CopyArea --> No RasterOp, but ClipRegion
301 long nDestX
, long nDestY
,
302 long nSrcX
, long nSrcY
,
303 long nSrcWidth
, long nSrcHeight
,
304 const OutputDevice
*pOutDev
);
306 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
307 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
309 const SalTwoRect
& rPosAry
,
310 SalGraphics
* pSrcGraphics
,
311 const OutputDevice
*pOutDev
,
312 const OutputDevice
*pSrcOutDev
);
315 const SalTwoRect
& rPosAry
,
316 const SalBitmap
& rSalBitmap
,
317 const OutputDevice
*pOutDev
);
320 const SalTwoRect
& rPosAry
,
321 const SalBitmap
& rSalBitmap
,
322 const SalBitmap
& rTransparentBitmap
,
323 const OutputDevice
*pOutDev
);
326 const SalTwoRect
& rPosAry
,
327 const SalBitmap
& rSalBitmap
,
329 const OutputDevice
*pOutDev
);
331 SalBitmap
* GetBitmap(
333 long nWidth
, long nHeight
,
334 const OutputDevice
*pOutDev
);
338 const OutputDevice
*pOutDev
);
340 // invert --> ClipRegion (only Windows)
343 long nWidth
, long nHeight
,
345 const OutputDevice
*pOutDev
);
349 const SalPoint
* pPtAry
,
351 const OutputDevice
*pOutDev
);
355 long nWidth
, long nHeight
,
358 const OutputDevice
*pOutDev
);
360 // native widget rendering functions
362 // Query the platform layer for control support
363 virtual bool IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
365 // Query the native control to determine if it was acted upon
366 bool HitTestNativeScrollbar(
368 const Rectangle
& rControlRegion
,
371 const OutputDevice
*pOutDev
);
373 // Request rendering of a particular control and/or part
374 bool DrawNativeControl(
377 const Rectangle
& rControlRegion
,
379 const ImplControlValue
& aValue
,
380 const OUString
& aCaption
,
381 const OutputDevice
*pOutDev
);
383 // Query the native control's actual drawing region (including adornment)
384 bool GetNativeControlRegion(
387 const Rectangle
& rControlRegion
,
389 const ImplControlValue
& aValue
,
390 const OUString
& aCaption
,
391 Rectangle
&rNativeBoundingRegion
,
392 Rectangle
&rNativeContentRegion
,
393 const OutputDevice
*pOutDev
);
396 const SalTwoRect
& rPosAry
,
397 const SalBitmap
& rSalBitmap
,
398 const OutputDevice
*pOutDev
);
400 bool BlendAlphaBitmap(
401 const SalTwoRect
& rPosAry
,
402 const SalBitmap
& rSalSrcBitmap
,
403 const SalBitmap
& rSalMaskBitmap
,
404 const SalBitmap
& rSalAlphaBitmap
,
405 const OutputDevice
*pOutDev
);
407 bool DrawAlphaBitmap(
409 const SalBitmap
& rSourceBitmap
,
410 const SalBitmap
& rAlphaBitmap
,
411 const OutputDevice
*pOutDev
);
413 bool DrawTransformedBitmap(
414 const basegfx::B2DPoint
& rNull
,
415 const basegfx::B2DPoint
& rX
,
416 const basegfx::B2DPoint
& rY
,
417 const SalBitmap
& rSourceBitmap
,
418 const SalBitmap
* pAlphaBitmap
,
419 const OutputDevice
* pOutDev
);
423 long nWidth
, long nHeight
,
424 sal_uInt8 nTransparency
,
425 const OutputDevice
*pOutDev
);
427 virtual SystemGraphicsData
GetGraphicsData() const = 0;
429 #if ENABLE_CAIRO_CANVAS
431 /// Check whether cairo will work
432 virtual bool SupportsCairo() const = 0;
433 /// Create Surface from given cairo surface
434 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const = 0;
435 /// Create surface with given dimensions
436 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const = 0;
437 /// Create Surface for given bitmap data
438 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const = 0;
439 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const = 0;
441 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
443 #endif // ENABLE_CAIRO_CANVAS
446 virtual bool setClipRegion( const vcl::Region
& ) = 0;
448 // draw --> LineColor and FillColor and RasterOp and ClipRegion
449 virtual void drawPixel( long nX
, long nY
) = 0;
450 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) = 0;
452 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
454 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
456 virtual void drawPolyLine( sal_uInt32 nPoints
, SalPoint
* pPtAry
) = 0;
458 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
460 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
461 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
463 virtual bool drawPolyLine(
464 const basegfx::B2DPolygon
&,
465 double fTransparency
,
466 const basegfx::B2DVector
& rLineWidths
,
467 basegfx::B2DLineJoin
,
468 css::drawing::LineCap
,
469 double fMiterMinimumAngle
) = 0;
471 virtual bool drawPolyLineBezier(
473 const SalPoint
* pPtAry
,
474 const PolyFlags
* pFlgAry
) = 0;
476 virtual bool drawPolygonBezier(
478 const SalPoint
* pPtAry
,
479 const PolyFlags
* pFlgAry
) = 0;
481 virtual bool drawPolyPolygonBezier(
483 const sal_uInt32
* pPoints
,
484 const SalPoint
* const* pPtAry
,
485 const PolyFlags
* const* pFlgAry
) = 0;
488 virtual bool drawGradient(
489 const tools::PolyPolygon
& rPolyPoly
,
490 const Gradient
& rGradient
) = 0;
492 // CopyArea --> No RasterOp, but ClipRegion
493 virtual void copyArea(
494 long nDestX
, long nDestY
,
495 long nSrcX
, long nSrcY
,
496 long nSrcWidth
, long nSrcHeight
,
497 bool bWindowInvalidate
) = 0;
499 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
500 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
501 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) = 0;
503 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) = 0;
505 virtual void drawBitmap(
506 const SalTwoRect
& rPosAry
,
507 const SalBitmap
& rSalBitmap
,
508 const SalBitmap
& rMaskBitmap
) = 0;
510 virtual void drawMask(
511 const SalTwoRect
& rPosAry
,
512 const SalBitmap
& rSalBitmap
,
513 SalColor nMaskColor
) = 0;
515 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
517 virtual SalColor
getPixel( long nX
, long nY
) = 0;
519 // invert --> ClipRegion (only Windows or VirDevs)
522 long nWidth
, long nHeight
,
523 SalInvert nFlags
) = 0;
525 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
527 virtual bool drawEPS(
529 long nWidth
, long nHeight
,
531 sal_uLong nSize
) = 0;
533 // native widget rendering methods that require mirroring
534 virtual bool hitTestNativeControl(
535 ControlType nType
, ControlPart nPart
,
536 const Rectangle
& rControlRegion
,
540 virtual bool drawNativeControl(
541 ControlType nType
, ControlPart nPart
,
542 const Rectangle
& rControlRegion
,
544 const ImplControlValue
& aValue
,
545 const OUString
& aCaption
);
547 virtual bool getNativeControlRegion(
548 ControlType nType
, ControlPart nPart
,
549 const Rectangle
& rControlRegion
,
551 const ImplControlValue
& aValue
,
552 const OUString
& aCaption
,
553 Rectangle
&rNativeBoundingRegion
,
554 Rectangle
&rNativeContentRegion
);
556 /** Blend the bitmap with the current buffer */
557 virtual bool blendBitmap(
559 const SalBitmap
& rBitmap
) = 0;
561 /** Draw the bitmap by blending using the mask and alpha channel */
562 virtual bool blendAlphaBitmap(
564 const SalBitmap
& rSrcBitmap
,
565 const SalBitmap
& rMaskBitmap
,
566 const SalBitmap
& rAlphaBitmap
) = 0;
568 /** Render bitmap with alpha channel
571 Source bitmap to blit
574 Alpha channel to use for blitting
576 @return true, if the operation succeeded, and false
577 otherwise. In this case, clients should try to emulate alpha
578 compositing themselves
580 virtual bool drawAlphaBitmap(
582 const SalBitmap
& rSourceBitmap
,
583 const SalBitmap
& rAlphaBitmap
) = 0;
585 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
586 virtual bool drawTransformedBitmap(
587 const basegfx::B2DPoint
& rNull
,
588 const basegfx::B2DPoint
& rX
,
589 const basegfx::B2DPoint
& rY
,
590 const SalBitmap
& rSourceBitmap
,
591 const SalBitmap
* pAlphaBitmap
) = 0;
593 /** Render solid rectangle with given transparency
595 @param nX Top left coordinate of rectangle
597 @param nY Bottom right coordinate of rectangle
599 @param nWidth Width of rectangle
601 @param nHeight Height of rectangle
603 @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a
604 fully transparent rectangle
606 @returns true if successfully drawn, false if not able to draw rectangle
608 virtual bool drawAlphaRect(
610 long nWidth
, long nHeight
,
611 sal_uInt8 nTransparency
) = 0;
614 SalLayoutFlags m_nLayout
; //< 0: mirroring off, 1: mirror x-axis
617 /// flags which hold the SetAntialiasing() value from OutputDevice
618 bool m_bAntiAliasB2DDraw
: 1;
622 #endif // INCLUDED_VCL_INC_SALGDI_HXX
624 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */