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 <tools/solar.h>
24 #include <osl/thread.hxx>
26 #include <vcl/dllapi.h>
27 #include <vcl/salgtype.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/salnativewidgets.hxx>
30 #include <vcl/metric.hxx>
32 #include "salgdiimpl.hxx"
33 #include "salglyphid.hxx"
34 #include "sallayout.hxx"
39 class PhysicalFontCollection
;
41 class FontSelectPattern
;
42 class ImplFontMetricData
;
43 class PhysicalFontFace
;
50 class ServerFontLayout
;
51 struct SystemGraphicsData
;
52 struct SystemFontData
;
60 // - SalGraphics-Codes -
62 #define SAL_SETFONT_USEDRAWTEXTARRAY ((sal_uInt16)0x0004)
63 #define SAL_SETFONT_BADFONT ((sal_uInt16)0x1000)
65 #define SAL_COPYAREA_WINDOWINVALIDATE ((sal_uInt16)0x0001)
67 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
68 typedef std::map
< sal_Ucs
, sal_Int32
> Ucs2SIntMap
;
69 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
70 typedef std::map
< sal_Ucs
, OString
> Ucs2OStrMap
;
71 typedef std::vector
< sal_Int32
> Int32Vector
;
73 // note: if you add any new methods to class SalGraphics using coordinates
74 // make sure they have a corresponding protected pure virtual method
75 // which has to be implemented by the platform dependent part.
76 // Add a method that performs coordinate mirroring if required, (see
77 // existing methods as sample) and then calls the equivalent pure method.
79 // note: all positions are in pixel and relative to
80 // the top/left-position of the virtual output area
82 class VCL_PLUGIN_PUBLIC SalGraphics
86 virtual ~SalGraphics();
88 virtual SalGraphicsImpl
* GetImpl() const = 0;
90 /// Check that our mpImpl is OpenGL and return the context, otherwise NULL.
91 rtl::Reference
<OpenGLContext
> GetOpenGLContext() const;
93 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
94 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
96 // public SalGraphics methods, the interface to the independent vcl part
98 // get device resolution
99 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
101 // get the depth of the device
102 virtual sal_uInt16
GetBitCount() const = 0;
104 // get the width of the device
105 virtual long GetGraphicsWidth() const = 0;
107 // set the clip region to empty
108 virtual void ResetClipRegion() = 0;
110 // set the line color to transparent (= don't draw lines)
112 virtual void SetLineColor() = 0;
114 // set the line color to a specific color
115 virtual void SetLineColor( SalColor nSalColor
) = 0;
117 // set the fill color to transparent (= don't fill)
118 virtual void SetFillColor() = 0;
120 // set the fill color to a specific color, shapes will be
121 // filled accordingly
122 virtual void SetFillColor( SalColor nSalColor
) = 0;
124 // enable/disable XOR drawing
125 virtual void SetXORMode( bool bSet
, bool bInvertOnly
) = 0;
127 // set line color for raster operations
128 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
130 // set fill color for raster operations
131 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
133 // set the text color to a specific color
134 virtual void SetTextColor( SalColor nSalColor
) = 0;
137 virtual sal_uInt16
SetFont( FontSelectPattern
*, int nFallbackLevel
) = 0;
140 void ReleaseFonts() { SetFont( NULL
, 0 ); }
142 // get the current font's metrics
143 virtual void GetFontMetric( ImplFontMetricData
*, int nFallbackLevel
= 0 ) = 0;
145 // get the repertoire of the current font
146 virtual const FontCharMapPtr
GetFontCharMap() const = 0;
148 // get the layout capabilities of the current font
149 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
151 // graphics must fill supplied font list
152 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
154 // graphics must drop any cached font info
155 virtual void ClearDevFontCache() = 0;
157 virtual bool AddTempDevFont(
158 PhysicalFontCollection
*,
159 const OUString
& rFileURL
,
160 const OUString
& rFontName
) = 0;
162 // CreateFontSubset: a method to get a subset of glyhps of a font
163 // inside a new valid font file
164 // returns true if creation of subset was successful
165 // parameters: rToFile: contains a osl file URL to write the subset to
166 // pFont: describes from which font to create a subset
167 // pGlyphIDs: the glyph ids to be extracted
168 // pEncoding: the character code corresponding to each glyph
169 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
170 // nGlyphs: the number of glyphs
171 // rInfo: additional outgoing information
172 // implementation note: encoding 0 with glyph id 0 should be added implicitly
173 // as "undefined character"
174 virtual bool CreateFontSubset(
175 const OUString
& rToFile
,
176 const PhysicalFontFace
* pFont
,
177 const sal_GlyphId
* pGlyphIDs
,
178 const sal_uInt8
* pEncoding
,
181 FontSubsetInfo
& rInfo
) = 0;
183 // GetFontEncodingVector: a method to get the encoding map Unicode
184 // to font encoded character; this is only used for type1 fonts and
185 // may return NULL in case of unknown encoding vector
186 // if ppNonEncoded is set and non encoded characters (that is type1
187 // glyphs with only a name) exist it is set to the corresponding
188 // map for non encoded glyphs; the encoding vector contains -1
189 // as encoding for these cases
190 virtual const Ucs2SIntMap
* GetFontEncodingVector(
191 const PhysicalFontFace
*,
192 const Ucs2OStrMap
** ppNonEncoded
,
193 std::set
<sal_Unicode
> const** ppPriority
) = 0;
195 // GetEmbedFontData: gets the font data for a font marked
196 // embeddable by GetDevFontList or NULL in case of error
197 // parameters: pFont: describes the font in question
198 // pUnicodes: contains the Unicodes assigned to code points 0 to 255
199 // pWidths: the widths of all glyphs from char code 0 to 255
200 // nLen: the number of elements in each of pWidths and pUnicodes
201 // rInfo: additional outgoing information
202 // pDataLen: out parameter, contains the byte length of the returned buffer
203 virtual const void* GetEmbedFontData(
204 const PhysicalFontFace
* pFont
,
205 const sal_Ucs
* pUnicodes
,
208 FontSubsetInfo
& rInfo
,
209 long* pDataLen
) = 0;
211 // free the font data again
212 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
214 // get the same widths as in CreateFontSubset and GetEmbedFontData
215 // in case of an embeddable font also fill the mapping
216 // between unicode and glyph id
217 // leave widths vector and mapping untouched in case of failure
218 virtual void GetGlyphWidths(
219 const PhysicalFontFace
* pFont
,
221 Int32Vector
& rWidths
,
222 Ucs2UIntMap
& rUnicodeEnc
) = 0;
224 virtual bool GetGlyphBoundRect( sal_GlyphId
, Rectangle
& ) = 0;
225 virtual bool GetGlyphOutline( sal_GlyphId
, basegfx::B2DPolyPolygon
& ) = 0;
227 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
228 virtual void DrawServerFontLayout( const ServerFontLayout
& ) = 0;
230 virtual bool supportsOperation( OutDevSupportType
) const = 0;
232 // mirroring specifics
233 SalLayoutFlags
GetLayout() { return m_nLayout
; }
234 void SetLayout( SalLayoutFlags aLayout
) { m_nLayout
= aLayout
;}
236 void mirror( long& nX
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
237 void mirror( long& nX
, long& nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
238 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
239 void mirror( Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
240 void mirror( vcl::Region
& rRgn
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
241 void mirror( ImplControlValue
&, const OutputDevice
*, bool bBack
= false ) const;
242 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
243 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
244 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
246 // non virtual methods; these do possible coordinate mirroring and
247 // then delegate to protected virtual methods
248 bool SetClipRegion( const vcl::Region
&, const OutputDevice
*pOutDev
);
250 // draw --> LineColor and FillColor and RasterOp and ClipRegion
251 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
252 void DrawPixel( long nX
, long nY
, SalColor nSalColor
, const OutputDevice
*pOutDev
);
254 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
256 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
258 void DrawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
260 void DrawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
262 void DrawPolyPolygon(
264 const sal_uInt32
* pPoints
,
265 PCONSTSALPOINT
* pPtAry
,
266 const OutputDevice
*pOutDev
);
268 bool DrawPolyPolygon(
269 const basegfx::B2DPolyPolygon
&i_rPolyPolygon
,
270 double i_fTransparency
,
271 const OutputDevice
*i_pOutDev
);
274 const basegfx::B2DPolygon
& i_rPolygon
,
275 double i_fTransparency
,
276 const basegfx::B2DVector
& i_rLineWidth
,
277 basegfx::B2DLineJoin i_eLineJoin
,
278 com::sun::star::drawing::LineCap i_eLineCap
,
279 const OutputDevice
* i_pOutDev
);
281 bool DrawPolyLineBezier(
283 const SalPoint
* pPtAry
,
284 const sal_uInt8
* pFlgAry
,
285 const OutputDevice
*pOutDev
);
287 bool DrawPolygonBezier(
289 const SalPoint
* pPtAry
,
290 const sal_uInt8
* pFlgAry
,
291 const OutputDevice
*pOutDev
);
293 bool DrawPolyPolygonBezier(
295 const sal_uInt32
* pPoints
,
296 const SalPoint
* const* pPtAry
,
297 const sal_uInt8
* const* pFlgAry
,
298 const OutputDevice
*pOutDev
);
301 const tools::PolyPolygon
& rPolyPoly
,
302 const Gradient
& rGradient
,
306 // CopyArea --> No RasterOp, but ClipRegion
308 long nDestX
, long nDestY
,
309 long nSrcX
, long nSrcY
,
310 long nSrcWidth
, long nSrcHeight
,
312 const OutputDevice
*pOutDev
);
314 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
315 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
317 const SalTwoRect
& rPosAry
,
318 SalGraphics
* pSrcGraphics
,
319 const OutputDevice
*pOutDev
,
320 const OutputDevice
*pSrcOutDev
);
323 const SalTwoRect
& rPosAry
,
324 const SalBitmap
& rSalBitmap
,
325 const OutputDevice
*pOutDev
);
328 const SalTwoRect
& rPosAry
,
329 const SalBitmap
& rSalBitmap
,
330 const SalBitmap
& rTransparentBitmap
,
331 const OutputDevice
*pOutDev
);
334 const SalTwoRect
& rPosAry
,
335 const SalBitmap
& rSalBitmap
,
337 const OutputDevice
*pOutDev
);
339 SalBitmap
* GetBitmap(
341 long nWidth
, long nHeight
,
342 const OutputDevice
*pOutDev
);
346 const OutputDevice
*pOutDev
);
348 // invert --> ClipRegion (only Windows)
351 long nWidth
, long nHeight
,
353 const OutputDevice
*pOutDev
);
357 const SalPoint
* pPtAry
,
359 const OutputDevice
*pOutDev
);
363 long nWidth
, long nHeight
,
366 const OutputDevice
*pOutDev
);
368 // native widget rendering functions
370 // Query the platform layer for control support
371 virtual bool IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
373 // Query the native control to determine if it was acted upon
374 bool HitTestNativeControl(
377 const Rectangle
& rControlRegion
,
380 const OutputDevice
*pOutDev
);
382 // Request rendering of a particular control and/or part
383 bool DrawNativeControl(
386 const Rectangle
& rControlRegion
,
388 const ImplControlValue
& aValue
,
389 const OUString
& aCaption
,
390 const OutputDevice
*pOutDev
);
392 // Query the native control's actual drawing region (including adornment)
393 bool GetNativeControlRegion(
396 const Rectangle
& rControlRegion
,
398 const ImplControlValue
& aValue
,
399 const OUString
& aCaption
,
400 Rectangle
&rNativeBoundingRegion
,
401 Rectangle
&rNativeContentRegion
,
402 const OutputDevice
*pOutDev
);
405 const SalTwoRect
& rPosAry
,
406 const SalBitmap
& rSalBitmap
,
407 const OutputDevice
*pOutDev
);
409 bool BlendAlphaBitmap(
410 const SalTwoRect
& rPosAry
,
411 const SalBitmap
& rSalSrcBitmap
,
412 const SalBitmap
& rSalMaskBitmap
,
413 const SalBitmap
& rSalAlphaBitmap
,
414 const OutputDevice
*pOutDev
);
416 bool DrawAlphaBitmap(
418 const SalBitmap
& rSourceBitmap
,
419 const SalBitmap
& rAlphaBitmap
,
420 const OutputDevice
*pOutDev
);
422 bool DrawTransformedBitmap(
423 const basegfx::B2DPoint
& rNull
,
424 const basegfx::B2DPoint
& rX
,
425 const basegfx::B2DPoint
& rY
,
426 const SalBitmap
& rSourceBitmap
,
427 const SalBitmap
* pAlphaBitmap
,
428 const OutputDevice
* pOutDev
);
432 long nWidth
, long nHeight
,
433 sal_uInt8 nTransparency
,
434 const OutputDevice
*pOutDev
);
436 virtual OpenGLContext
*BeginPaint() { return NULL
; }
438 virtual SystemGraphicsData
GetGraphicsData() const = 0;
440 /// Check whether cairo will work
441 virtual bool SupportsCairo() const = 0;
442 /// Create Surface from given cairo surface
443 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const = 0;
444 /// Create surface with given dimensions
445 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const = 0;
446 /// Create Surface for given bitmap data
447 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const = 0;
448 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const ::basegfx::B2ISize
& rSize
) const = 0;
450 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
453 virtual bool setClipRegion( const vcl::Region
& ) = 0;
455 // draw --> LineColor and FillColor and RasterOp and ClipRegion
456 virtual void drawPixel( long nX
, long nY
) = 0;
457 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) = 0;
459 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
461 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
463 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
465 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
467 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
468 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
470 virtual bool drawPolyLine(
471 const ::basegfx::B2DPolygon
&,
472 double fTransparency
,
473 const ::basegfx::B2DVector
& rLineWidths
,
474 basegfx::B2DLineJoin
,
475 com::sun::star::drawing::LineCap
) = 0;
477 virtual bool drawPolyLineBezier(
479 const SalPoint
* pPtAry
,
480 const sal_uInt8
* pFlgAry
) = 0;
482 virtual bool drawPolygonBezier(
484 const SalPoint
* pPtAry
,
485 const sal_uInt8
* pFlgAry
) = 0;
487 virtual bool drawPolyPolygonBezier(
489 const sal_uInt32
* pPoints
,
490 const SalPoint
* const* pPtAry
,
491 const sal_uInt8
* const* pFlgAry
) = 0;
494 virtual bool drawGradient(
495 const tools::PolyPolygon
& rPolyPoly
,
496 const Gradient
& rGradient
) = 0;
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 sal_uInt16 nFlags
) = 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 SalColor nTransparentColor
) = 0;
516 virtual void drawBitmap(
517 const SalTwoRect
& rPosAry
,
518 const SalBitmap
& rSalBitmap
,
519 const SalBitmap
& rMaskBitmap
) = 0;
521 virtual void drawMask(
522 const SalTwoRect
& rPosAry
,
523 const SalBitmap
& rSalBitmap
,
524 SalColor nMaskColor
) = 0;
526 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
528 virtual SalColor
getPixel( long nX
, long nY
) = 0;
530 // invert --> ClipRegion (only Windows or VirDevs)
533 long nWidth
, long nHeight
,
534 SalInvert nFlags
) = 0;
536 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
538 virtual bool drawEPS(
540 long nWidth
, long nHeight
,
542 sal_uLong nSize
) = 0;
544 // native widget rendering methods that require mirroring
545 virtual bool hitTestNativeControl(
546 ControlType nType
, ControlPart nPart
,
547 const Rectangle
& rControlRegion
,
551 virtual bool drawNativeControl(
552 ControlType nType
, ControlPart nPart
,
553 const Rectangle
& rControlRegion
,
555 const ImplControlValue
& aValue
,
556 const OUString
& aCaption
);
558 virtual bool getNativeControlRegion(
559 ControlType nType
, ControlPart nPart
,
560 const Rectangle
& rControlRegion
,
562 const ImplControlValue
& aValue
,
563 const OUString
& aCaption
,
564 Rectangle
&rNativeBoundingRegion
,
565 Rectangle
&rNativeContentRegion
);
567 /** Blend the bitmap with the current buffer */
568 virtual bool blendBitmap(
570 const SalBitmap
& rBitmap
) = 0;
572 /** Draw the bitmap by blending using the mask and alpha channel */
573 virtual bool blendAlphaBitmap(
575 const SalBitmap
& rSrcBitmap
,
576 const SalBitmap
& rMaskBitmap
,
577 const SalBitmap
& rAlphaBitmap
) = 0;
579 /** Render bitmap with alpha channel
582 Source bitmap to blit
585 Alpha channel to use for blitting
587 @return true, if the operation succeeded, and false
588 otherwise. In this case, clients should try to emulate alpha
589 compositing themselves
591 virtual bool drawAlphaBitmap(
593 const SalBitmap
& rSourceBitmap
,
594 const SalBitmap
& rAlphaBitmap
) = 0;
596 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
597 virtual bool drawTransformedBitmap(
598 const basegfx::B2DPoint
& rNull
,
599 const basegfx::B2DPoint
& rX
,
600 const basegfx::B2DPoint
& rY
,
601 const SalBitmap
& rSourceBitmap
,
602 const SalBitmap
* pAlphaBitmap
) = 0;
604 /** Render solid rectangle with given transparency
607 Transparency value (0-255) to use. 0 blits and opaque, 255 a
608 fully transparent rectangle
610 virtual bool drawAlphaRect(
612 long nWidth
, long nHeight
,
613 sal_uInt8 nTransparency
) = 0;
616 SalLayoutFlags m_nLayout
; //< 0: mirroring off, 1: mirror x-axis
619 /// flags which hold the SetAntialiasing() value from OutputDevice
620 bool m_bAntiAliasB2DDraw
: 1;
624 #endif // INCLUDED_VCL_INC_SALGDI_HXX
626 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */