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 "vcl/dllapi.h"
25 #include "vcl/salgtype.hxx"
26 #include "osl/thread.hxx"
27 #include "vcl/outdev.hxx"
28 #include "vcl/salnativewidgets.hxx"
29 #include "salglyphid.hxx"
30 #include "sallayout.hxx"
34 class PhysicalFontCollection
;
36 class FontSelectPattern
;
37 class ImplFontMetricData
;
38 class PhysicalFontFace
;
39 class ImplFontCharMap
;
45 class ServerFontLayout
;
46 struct SystemGraphicsData
;
47 struct SystemFontData
;
55 // - SalGraphics-Codes -
57 #define SAL_SETFONT_USEDRAWTEXTARRAY ((sal_uInt16)0x0004)
58 #define SAL_SETFONT_BADFONT ((sal_uInt16)0x1000)
60 #define SAL_COPYAREA_WINDOWINVALIDATE ((sal_uInt16)0x0001)
62 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
63 typedef std::map
< sal_Ucs
, sal_Int32
> Ucs2SIntMap
;
64 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
65 typedef std::map
< sal_Ucs
, OString
> Ucs2OStrMap
;
66 typedef std::vector
< sal_Int32
> Int32Vector
;
68 // note: if you add any new methods to class SalGraphics using coordinates
69 // make sure they have a corresponding protected pure virtual method
70 // which has to be implemented by the platform dependent part.
71 // Add a method that performs coordinate mirroring if required, (see
72 // existing methods as sample) and then calls the equivalent pure method.
74 // note: all positions are in pixel and relative to
75 // the top/left-position of the virtual output area
77 class VCL_PLUGIN_PUBLIC SalGraphics
79 int m_nLayout
; // 0: mirroring off, 1: mirror x-axis
83 // flags which hold the SetAntialiasing() value from OutputDevice
84 bool m_bAntiAliasB2DDraw
: 1;
87 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
88 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
91 virtual ~SalGraphics();
94 virtual bool setClipRegion( const Region
& ) = 0;
96 // draw --> LineColor and FillColor and RasterOp and ClipRegion
97 virtual void drawPixel( long nX
, long nY
) = 0;
98 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) = 0;
99 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
100 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
101 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
102 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) = 0;
103 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
104 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
105 virtual bool drawPolyLine( const ::basegfx::B2DPolygon
&,
106 double fTransparency
,
107 const ::basegfx::B2DVector
& rLineWidths
,
108 basegfx::B2DLineJoin
,
109 com::sun::star::drawing::LineCap
) = 0;
110 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) = 0;
111 virtual bool drawPolygonBezier( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) = 0;
112 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const sal_uInt8
* const* pFlgAry
) = 0;
114 // CopyArea --> No RasterOp, but ClipRegion
115 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
116 long nSrcHeight
, sal_uInt16 nFlags
) = 0;
118 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
119 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
120 virtual void copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) = 0;
121 virtual void drawBitmap( const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) = 0;
122 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
123 const SalBitmap
& rSalBitmap
,
124 SalColor nTransparentColor
) = 0;
125 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
126 const SalBitmap
& rSalBitmap
,
127 const SalBitmap
& rMaskBitmap
) = 0;
128 virtual void drawMask( const SalTwoRect
& rPosAry
,
129 const SalBitmap
& rSalBitmap
,
130 SalColor nMaskColor
) = 0;
132 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
133 virtual SalColor
getPixel( long nX
, long nY
) = 0;
135 // invert --> ClipRegion (only Windows or VirDevs)
136 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) = 0;
137 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
139 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uLong nSize
) = 0;
141 // native widget rendering methods that require mirroring
142 virtual bool hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
143 const Point
& aPos
, bool& rIsInside
);
144 virtual bool drawNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
145 ControlState nState
, const ImplControlValue
& aValue
,
146 const OUString
& aCaption
);
147 virtual bool getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
, ControlState nState
,
148 const ImplControlValue
& aValue
, const OUString
& aCaption
,
149 Rectangle
&rNativeBoundingRegion
, Rectangle
&rNativeContentRegion
);
151 /** Render bitmap with alpha channel
154 Source bitmap to blit
157 Alpha channel to use for blitting
159 @return true, if the operation succeeded, and false
160 otherwise. In this case, clients should try to emulate alpha
161 compositing themselves
163 virtual bool drawAlphaBitmap( const SalTwoRect
&,
164 const SalBitmap
& rSourceBitmap
,
165 const SalBitmap
& rAlphaBitmap
) = 0;
167 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
168 virtual bool drawTransformedBitmap(
169 const basegfx::B2DPoint
& rNull
,
170 const basegfx::B2DPoint
& rX
,
171 const basegfx::B2DPoint
& rY
,
172 const SalBitmap
& rSourceBitmap
,
173 const SalBitmap
* pAlphaBitmap
) = 0;
175 /** Render solid rectangle with given transparency
178 Transparency value (0-255) to use. 0 blits and opaque, 255 a
179 fully transparent rectangle
181 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
) = 0;
184 // public SalGraphics methods, the interface to the independent vcl part
186 // get device resolution
187 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
189 // get the depth of the device
190 virtual sal_uInt16
GetBitCount() const = 0;
192 // get the width of the device
193 virtual long GetGraphicsWidth() const = 0;
195 // set the clip region to empty
196 virtual void ResetClipRegion() = 0;
198 // set the line color to transparent (= don't draw lines)
200 virtual void SetLineColor() = 0;
202 // set the line color to a specific color
203 virtual void SetLineColor( SalColor nSalColor
) = 0;
205 // set the fill color to transparent (= don't fill)
206 virtual void SetFillColor() = 0;
208 // set the fill color to a specific color, shapes will be
209 // filled accordingly
210 virtual void SetFillColor( SalColor nSalColor
) = 0;
212 // enable/disable XOR drawing
213 virtual void SetXORMode( bool bSet
, bool bInvertOnly
) = 0;
215 // set line color for raster operations
216 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
218 // set fill color for raster operations
219 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
221 // set the text color to a specific color
222 virtual void SetTextColor( SalColor nSalColor
) = 0;
225 virtual sal_uInt16
SetFont( FontSelectPattern
*, int nFallbackLevel
) = 0;
228 void ReleaseFonts() { SetFont( NULL
, 0 ); }
230 // get the current font's metrics
231 virtual void GetFontMetric( ImplFontMetricData
*, int nFallbackLevel
= 0 ) = 0;
233 // get the repertoire of the current font
234 virtual const ImplFontCharMap
*
235 GetImplFontCharMap() const = 0;
237 // get the layout capabilities of the current font
238 virtual bool GetImplFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const = 0;
240 // graphics must fill supplied font list
241 virtual void GetDevFontList( PhysicalFontCollection
* ) = 0;
243 // graphics must drop any cached font info
244 virtual void ClearDevFontCache() = 0;
246 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) = 0;
248 // CreateFontSubset: a method to get a subset of glyhps of a font
249 // inside a new valid font file
250 // returns true if creation of subset was successful
251 // parameters: rToFile: contains a osl file URL to write the subset to
252 // pFont: describes from which font to create a subset
253 // pGlyphIDs: the glyph ids to be extracted
254 // pEncoding: the character code corresponding to each glyph
255 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
256 // nGlyphs: the number of glyphs
257 // rInfo: additional outgoing information
258 // implementation note: encoding 0 with glyph id 0 should be added implicitly
259 // as "undefined character"
260 virtual bool CreateFontSubset( const OUString
& rToFile
,
261 const PhysicalFontFace
* pFont
,
262 sal_GlyphId
* pGlyphIDs
,
263 sal_uInt8
* pEncoding
,
266 FontSubsetInfo
& rInfo
) = 0;
268 // GetFontEncodingVector: a method to get the encoding map Unicode
269 // to font encoded character; this is only used for type1 fonts and
270 // may return NULL in case of unknown encoding vector
271 // if ppNonEncoded is set and non encoded characters (that is type1
272 // glyphs with only a name) exist it is set to the corresponding
273 // map for non encoded glyphs; the encoding vector contains -1
274 // as encoding for these cases
275 virtual const Ucs2SIntMap
*
276 GetFontEncodingVector( const PhysicalFontFace
*, const Ucs2OStrMap
** ppNonEncoded
) = 0;
278 // GetEmbedFontData: gets the font data for a font marked
279 // embeddable by GetDevFontList or NULL in case of error
280 // parameters: pFont: describes the font in question
281 // pUnicodes: contains the Unicodes assigned to
282 // code points 0 to 255; must contain at least 256 members
283 // pWidths: the widths of all glyphs from char code 0 to 255
284 // pWidths MUST support at least 256 members;
285 // rInfo: additional outgoing information
286 // pDataLen: out parameter, contains the byte length of the returned buffer
287 virtual const void* GetEmbedFontData( const PhysicalFontFace
* pFont
,
288 const sal_Ucs
* pUnicodes
,
290 FontSubsetInfo
& rInfo
,
291 long* pDataLen
) = 0;
292 // free the font data again
293 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
295 // get the same widths as in CreateFontSubset and GetEmbedFontData
296 // in case of an embeddable font also fill the mapping
297 // between unicode and glyph id
298 // leave widths vector and mapping untouched in case of failure
299 virtual void GetGlyphWidths( const PhysicalFontFace
* pFont
,
301 Int32Vector
& rWidths
,
302 Ucs2UIntMap
& rUnicodeEnc
) = 0;
304 virtual bool GetGlyphBoundRect( sal_GlyphId
, Rectangle
& ) = 0;
305 virtual bool GetGlyphOutline( sal_GlyphId
, basegfx::B2DPolyPolygon
& ) = 0;
307 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
308 virtual void DrawServerFontLayout( const ServerFontLayout
& ) = 0;
310 virtual bool supportsOperation( OutDevSupportType
) const = 0;
312 // mirroring specifica
313 int GetLayout() { return m_nLayout
; }
314 void SetLayout( int aLayout
) { m_nLayout
= aLayout
;}
316 void mirror( long& nX
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
317 void mirror( long& nX
, long& nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
318 bool mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
319 void mirror( Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
320 void mirror( Region
& rRgn
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
321 void mirror( ImplControlValue
&, const OutputDevice
*, bool bBack
= false ) const;
322 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
323 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
324 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
326 // non virtual methods; these do possible coordinate mirroring and
327 // then delegate to protected virtual methods
328 bool SetClipRegion( const Region
&, const OutputDevice
*pOutDev
);
330 // draw --> LineColor and FillColor and RasterOp and ClipRegion
331 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
332 void DrawPixel( long nX
, long nY
, SalColor nSalColor
, const OutputDevice
*pOutDev
);
333 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
334 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
335 void DrawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
336 void DrawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
337 void DrawPolyPolygon( sal_uInt32 nPoly
,
338 const sal_uInt32
* pPoints
,
339 PCONSTSALPOINT
* pPtAry
,
340 const OutputDevice
*pOutDev
);
341 bool DrawPolyPolygon( const basegfx::B2DPolyPolygon
&i_rPolyPolygon
,
342 double i_fTransparency
,
343 const OutputDevice
*i_pOutDev
);
344 bool DrawPolyLine( const basegfx::B2DPolygon
& i_rPolygon
,
345 double i_fTransparency
,
346 const basegfx::B2DVector
& i_rLineWidth
,
347 basegfx::B2DLineJoin i_eLineJoin
,
348 com::sun::star::drawing::LineCap i_eLineCap
,
349 const OutputDevice
* i_pOutDev
);
351 bool DrawPolyLineBezier( sal_uInt32 nPoints
,
352 const SalPoint
* pPtAry
,
353 const sal_uInt8
* pFlgAry
,
354 const OutputDevice
*pOutDev
);
355 bool DrawPolygonBezier( sal_uInt32 nPoints
,
356 const SalPoint
* pPtAry
,
357 const sal_uInt8
* pFlgAry
,
358 const OutputDevice
*pOutDev
);
359 bool DrawPolyPolygonBezier( sal_uInt32 nPoly
,
360 const sal_uInt32
* pPoints
,
361 const SalPoint
* const* pPtAry
,
362 const sal_uInt8
* const* pFlgAry
,
363 const OutputDevice
*pOutDev
);
365 // CopyArea --> No RasterOp, but ClipRegion
366 void CopyArea( long nDestX
, long nDestY
,
367 long nSrcX
, long nSrcY
,
368 long nSrcWidth
, long nSrcHeight
,
370 const OutputDevice
*pOutDev
);
372 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
373 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
374 void CopyBits( const SalTwoRect
& rPosAry
,
375 SalGraphics
* pSrcGraphics
,
376 const OutputDevice
*pOutDev
,
377 const OutputDevice
*pSrcOutDev
);
378 void DrawBitmap( const SalTwoRect
& rPosAry
,
379 const SalBitmap
& rSalBitmap
,
380 const OutputDevice
*pOutDev
);
381 void DrawBitmap( const SalTwoRect
& rPosAry
,
382 const SalBitmap
& rSalBitmap
,
383 const SalBitmap
& rTransparentBitmap
,
384 const OutputDevice
*pOutDev
);
386 void DrawMask( const SalTwoRect
& rPosAry
,
387 const SalBitmap
& rSalBitmap
,
389 const OutputDevice
*pOutDev
);
391 SalBitmap
* GetBitmap( long nX
, long nY
,
392 long nWidth
, long nHeight
,
393 const OutputDevice
*pOutDev
);
395 SalColor
GetPixel( long nX
, long nY
,
396 const OutputDevice
*pOutDev
);
398 // invert --> ClipRegion (only Windows)
399 void Invert( long nX
, long nY
,
400 long nWidth
, long nHeight
,
402 const OutputDevice
*pOutDev
);
404 void Invert( sal_uInt32 nPoints
,
405 const SalPoint
* pPtAry
,
407 const OutputDevice
*pOutDev
);
409 bool DrawEPS( long nX
, long nY
,
410 long nWidth
, long nHeight
,
413 const OutputDevice
*pOutDev
);
415 // native widget rendering functions
417 // Query the platform layer for control support
418 virtual bool IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
420 // Query the native control to determine if it was acted upon
421 bool HitTestNativeControl( ControlType nType
,
423 const Rectangle
& rControlRegion
,
426 const OutputDevice
*pOutDev
);
428 // Request rendering of a particular control and/or part
429 bool DrawNativeControl( ControlType nType
,
431 const Rectangle
& rControlRegion
,
433 const ImplControlValue
& aValue
,
434 const OUString
& aCaption
,
435 const OutputDevice
*pOutDev
);
437 // Query the native control's actual drawing region (including adornment)
438 bool GetNativeControlRegion( ControlType nType
,
440 const Rectangle
& rControlRegion
,
442 const ImplControlValue
& aValue
,
443 const OUString
& aCaption
,
444 Rectangle
&rNativeBoundingRegion
,
445 Rectangle
&rNativeContentRegion
,
446 const OutputDevice
*pOutDev
);
448 bool DrawAlphaBitmap( const SalTwoRect
&,
449 const SalBitmap
& rSourceBitmap
,
450 const SalBitmap
& rAlphaBitmap
,
451 const OutputDevice
*pOutDev
);
453 bool DrawTransformedBitmap(
454 const basegfx::B2DPoint
& rNull
,
455 const basegfx::B2DPoint
& rX
,
456 const basegfx::B2DPoint
& rY
,
457 const SalBitmap
& rSourceBitmap
,
458 const SalBitmap
* pAlphaBitmap
,
459 const OutputDevice
* pOutDev
);
461 bool DrawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
,
462 sal_uInt8 nTransparency
, const OutputDevice
*pOutDev
);
464 virtual SystemGraphicsData
465 GetGraphicsData() const = 0;
467 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
470 #endif // INCLUDED_VCL_INC_SALGDI_HXX
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */