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 _SV_SALGDI_HXX
21 #define _SV_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 "sallayout.hxx"
34 class ImplDevFontList
;
36 class FontSelectPattern
;
37 class ImplFontMetricData
;
38 struct ImplKernPairData
;
39 class PhysicalFontFace
;
40 class ImplFontCharMap
;
46 class ServerFontLayout
;
47 struct SystemGraphicsData
;
48 struct SystemFontData
;
56 // ---------------------
57 // - SalGraphics-Codes -
58 // ---------------------
60 #define SAL_SETFONT_REMOVEANDMATCHNEW ((sal_uInt16)0x0001)
61 #define SAL_SETFONT_USEDRAWTEXT ((sal_uInt16)0x0002)
62 #define SAL_SETFONT_USEDRAWTEXTARRAY ((sal_uInt16)0x0004)
63 #define SAL_SETFONT_UNICODE ((sal_uInt16)0x0008)
64 #define SAL_SETFONT_BADFONT ((sal_uInt16)0x1000)
66 #define SAL_COPYAREA_WINDOWINVALIDATE ((sal_uInt16)0x0001)
68 typedef sal_Unicode sal_Ucs
; // TODO: use sal_UCS4 instead of sal_Unicode
69 typedef std::map
< sal_Ucs
, sal_Int32
> Ucs2SIntMap
;
70 typedef std::map
< sal_Ucs
, sal_uInt32
> Ucs2UIntMap
;
71 typedef std::map
< sal_Ucs
, OString
> Ucs2OStrMap
;
72 typedef std::vector
< sal_Int32
> Int32Vector
;
74 // note: if you add any new methods to class SalGraphics using coordinates
75 // make sure they have a corresponding protected pure virtual method
76 // which has to be implemented by the platform dependent part.
77 // Add a method that performs coordinate mirroring if required, (see
78 // existing methods as sample) and then calls the equivalent pure method.
80 // note: all positions are in pixel and relative to
81 // the top/left-position of the virtual output area
83 class VCL_PLUGIN_PUBLIC SalGraphics
85 int m_nLayout
; // 0: mirroring off, 1: mirror x-axis
88 // flags which hold the SetAntialiasing() value from OutputDevice
89 bool m_bAntiAliasB2DDraw
;
92 void setAntiAliasB2DDraw(bool bNew
) { m_bAntiAliasB2DDraw
= bNew
; }
93 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw
; }
96 virtual ~SalGraphics();
99 virtual bool setClipRegion( const Region
& ) = 0;
101 // draw --> LineColor and FillColor and RasterOp and ClipRegion
102 virtual void drawPixel( long nX
, long nY
) = 0;
103 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) = 0;
104 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) = 0;
105 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
106 virtual void drawPolyLine( sal_uLong nPoints
, const SalPoint
* pPtAry
) = 0;
107 virtual void drawPolygon( sal_uLong nPoints
, const SalPoint
* pPtAry
) = 0;
108 virtual void drawPolyPolygon( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, PCONSTSALPOINT
* pPtAry
) = 0;
109 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
) = 0;
110 virtual bool drawPolyLine( const ::basegfx::B2DPolygon
&,
111 double fTransparency
,
112 const ::basegfx::B2DVector
& rLineWidths
,
113 basegfx::B2DLineJoin
,
114 com::sun::star::drawing::LineCap
) = 0;
115 virtual sal_Bool
drawPolyLineBezier( sal_uLong nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) = 0;
116 virtual sal_Bool
drawPolygonBezier( sal_uLong nPoints
, const SalPoint
* pPtAry
, const sal_uInt8
* pFlgAry
) = 0;
117 virtual sal_Bool
drawPolyPolygonBezier( sal_uInt32 nPoly
, const sal_uInt32
* pPoints
, const SalPoint
* const* pPtAry
, const sal_uInt8
* const* pFlgAry
) = 0;
119 // CopyArea --> No RasterOp, but ClipRegion
120 virtual void copyArea( long nDestX
, long nDestY
, long nSrcX
, long nSrcY
, long nSrcWidth
,
121 long nSrcHeight
, sal_uInt16 nFlags
) = 0;
123 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
124 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
125 virtual void copyBits( const SalTwoRect
* pPosAry
, SalGraphics
* pSrcGraphics
) = 0;
126 virtual void drawBitmap( const SalTwoRect
* pPosAry
, const SalBitmap
& rSalBitmap
) = 0;
127 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
128 const SalBitmap
& rSalBitmap
,
129 SalColor nTransparentColor
) = 0;
130 virtual void drawBitmap( const SalTwoRect
* pPosAry
,
131 const SalBitmap
& rSalBitmap
,
132 const SalBitmap
& rMaskBitmap
) = 0;
133 virtual void drawMask( const SalTwoRect
* pPosAry
,
134 const SalBitmap
& rSalBitmap
,
135 SalColor nMaskColor
) = 0;
137 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) = 0;
138 virtual SalColor
getPixel( long nX
, long nY
) = 0;
140 // invert --> ClipRegion (only Windows or VirDevs)
141 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) = 0;
142 virtual void invert( sal_uLong nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) = 0;
144 virtual sal_Bool
drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uLong nSize
) = 0;
146 // native widget rendering methods that require mirroring
147 virtual sal_Bool
hitTestNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
148 const Point
& aPos
, sal_Bool
& rIsInside
);
149 virtual sal_Bool
drawNativeControl( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
,
150 ControlState nState
, const ImplControlValue
& aValue
,
151 const OUString
& aCaption
);
152 virtual sal_Bool
getNativeControlRegion( ControlType nType
, ControlPart nPart
, const Rectangle
& rControlRegion
, ControlState nState
,
153 const ImplControlValue
& aValue
, const OUString
& aCaption
,
154 Rectangle
&rNativeBoundingRegion
, Rectangle
&rNativeContentRegion
);
156 /** Render bitmap with alpha channel
159 Source bitmap to blit
162 Alpha channel to use for blitting
164 @return true, if the operation succeeded, and false
165 otherwise. In this case, clients should try to emulate alpha
166 compositing themselves
168 virtual bool drawAlphaBitmap( const SalTwoRect
&,
169 const SalBitmap
& rSourceBitmap
,
170 const SalBitmap
& rAlphaBitmap
) = 0;
171 /** Render solid rectangle with given transparency
174 Transparency value (0-255) to use. 0 blits and opaque, 255 a
175 fully transparent rectangle
177 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
) = 0;
180 // public SalGraphics methods, the interface to the independent vcl part
182 // get device resolution
183 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) = 0;
185 // get the depth of the device
186 virtual sal_uInt16
GetBitCount() const = 0;
188 // get the width of the device
189 virtual long GetGraphicsWidth() const = 0;
191 // set the clip region to empty
192 virtual void ResetClipRegion() = 0;
194 // set the line color to transparent (= don't draw lines)
196 virtual void SetLineColor() = 0;
198 // set the line color to a specific color
199 virtual void SetLineColor( SalColor nSalColor
) = 0;
201 // set the fill color to transparent (= don't fill)
202 virtual void SetFillColor() = 0;
204 // set the fill color to a specific color, shapes will be
205 // filled accordingly
206 virtual void SetFillColor( SalColor nSalColor
) = 0;
208 // enable/disable XOR drawing
209 virtual void SetXORMode( bool bSet
, bool bInvertOnly
) = 0;
211 // set line color for raster operations
212 virtual void SetROPLineColor( SalROPColor nROPColor
) = 0;
214 // set fill color for raster operations
215 virtual void SetROPFillColor( SalROPColor nROPColor
) = 0;
217 // set the text color to a specific color
218 virtual void SetTextColor( SalColor nSalColor
) = 0;
221 virtual sal_uInt16
SetFont( FontSelectPattern
*, int nFallbackLevel
) = 0;
224 void ReleaseFonts() { SetFont( NULL
, 0 ); }
226 // get the current font's metrics
227 virtual void GetFontMetric( ImplFontMetricData
*, int nFallbackLevel
= 0 ) = 0;
229 // get kerning pairs of the current font
230 // return only PairCount if (pKernPairs == NULL)
231 virtual sal_uLong
GetKernPairs( sal_uLong nMaxPairCount
, ImplKernPairData
* ) = 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( ImplDevFontList
* ) = 0;
243 // graphics must drop any cached font info
244 virtual void ClearDevFontCache() = 0;
246 // graphics should call ImplAddDevFontSubstitute on supplied
247 // OutputDevice for all its device specific preferred font substitutions
248 virtual void GetDevFontSubstList( OutputDevice
* ) = 0;
250 virtual bool AddTempDevFont( ImplDevFontList
*, const OUString
& rFileURL
, const OUString
& rFontName
) = 0;
252 // CreateFontSubset: a method to get a subset of glyhps of a font
253 // inside a new valid font file
254 // returns sal_True if creation of subset was successful
255 // parameters: rToFile: contains a osl file URL to write the subset to
256 // pFont: describes from which font to create a subset
257 // pGlyphIDs: the glyph ids to be extracted
258 // pEncoding: the character code corresponding to each glyph
259 // pWidths: the advance widths of the correspoding glyphs (in PS font units)
260 // nGlyphs: the number of glyphs
261 // rInfo: additional outgoing information
262 // implementation note: encoding 0 with glyph id 0 should be added implicitly
263 // as "undefined character"
264 virtual sal_Bool
CreateFontSubset( const OUString
& rToFile
,
265 const PhysicalFontFace
* pFont
,
266 sal_Int32
* pGlyphIDs
,
267 sal_uInt8
* pEncoding
,
270 FontSubsetInfo
& rInfo
) = 0;
272 // GetFontEncodingVector: a method to get the encoding map Unicode
273 // to font encoded character; this is only used for type1 fonts and
274 // may return NULL in case of unknown encoding vector
275 // if ppNonEncoded is set and non encoded characters (that is type1
276 // glyphs with only a name) exist it is set to the corresponding
277 // map for non encoded glyphs; the encoding vector contains -1
278 // as encoding for these cases
279 virtual const Ucs2SIntMap
*
280 GetFontEncodingVector( const PhysicalFontFace
*, const Ucs2OStrMap
** ppNonEncoded
) = 0;
282 // GetEmbedFontData: gets the font data for a font marked
283 // embeddable by GetDevFontList or NULL in case of error
284 // parameters: pFont: describes the font in question
285 // pUnicodes: contains the Unicodes assigned to
286 // code points 0 to 255; must contain at least 256 members
287 // pWidths: the widths of all glyphs from char code 0 to 255
288 // pWidths MUST support at least 256 members;
289 // rInfo: additional outgoing information
290 // pDataLen: out parameter, contains the byte length of the returned buffer
291 virtual const void* GetEmbedFontData( const PhysicalFontFace
* pFont
,
292 const sal_Ucs
* pUnicodes
,
294 FontSubsetInfo
& rInfo
,
295 long* pDataLen
) = 0;
296 // free the font data again
297 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) = 0;
299 // get the same widths as in CreateFontSubset and GetEmbedFontData
300 // in case of an embeddable font also fill the mapping
301 // between unicode and glyph id
302 // leave widths vector and mapping untouched in case of failure
303 virtual void GetGlyphWidths( const PhysicalFontFace
* pFont
,
305 Int32Vector
& rWidths
,
306 Ucs2UIntMap
& rUnicodeEnc
) = 0;
308 virtual sal_Bool
GetGlyphBoundRect( sal_GlyphId nIndex
, Rectangle
& ) = 0;
309 virtual sal_Bool
GetGlyphOutline( sal_GlyphId nIndex
, basegfx::B2DPolyPolygon
& ) = 0;
311 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) = 0;
312 virtual void DrawServerFontLayout( const ServerFontLayout
& ) = 0;
314 /** Filter text from DrawText commands in a device specific manner
316 This function allows a device (or rather the corresponding SalGraphics
317 implementation) to prevent text portions from being drawn. This currently
318 is used only for filtering out the fax number in a document that is printed
319 to one of psprint's specialized "fax" printers.
326 A String that will be filled with the adjusted version
329 The index inside <code>rOrigText</code> that marks the first draw character
332 in: length of text beginning at <code>nIndex</code> to be drawn
333 out: length of <code>rNewText</code> containing the substituted text
336 out: index at which the cutout portion of <code>rOrigText</code> begins
339 out: index at which the cutout portion of <code>rOrigText</code> ends
342 true: a substitution has taken place and rNewText rLen, rCutStart and rCutStop have been filled accordingly
343 false: no substitution has taken place, rNewText, rLen, rCutStart, rCutStop remain unchanged
345 virtual bool filterText( const OUString
& rOrigText
, OUString
& rNewText
,
346 sal_Int32 nIndex
, sal_Int32
& rLen
, sal_Int32
& rCutStart
, sal_Int32
& rCutStop
);
348 virtual bool supportsOperation( OutDevSupportType
) const = 0;
350 // mirroring specifica
351 int GetLayout() { return m_nLayout
; }
352 void SetLayout( int aLayout
) { m_nLayout
= aLayout
;}
354 void mirror( long& nX
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
355 void mirror( long& nX
, long& nWidth
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
356 sal_Bool
mirror( sal_uInt32 nPoints
, const SalPoint
*pPtAry
, SalPoint
*pPtAry2
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
357 void mirror( Rectangle
& rRect
, const OutputDevice
*, bool bBack
= false ) const;
358 void mirror( Region
& rRgn
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
359 void mirror( ImplControlValue
&, const OutputDevice
*, bool bBack
= false ) const;
360 basegfx::B2DPoint
mirror( const basegfx::B2DPoint
& i_rPoint
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
361 basegfx::B2DPolygon
mirror( const basegfx::B2DPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
362 basegfx::B2DPolyPolygon
mirror( const basegfx::B2DPolyPolygon
& i_rPoly
, const OutputDevice
*pOutDev
, bool bBack
= false ) const;
364 // non virtual methods; these do possible coordinate mirroring and
365 // then delegate to protected virtual methods
366 bool SetClipRegion( const Region
&, const OutputDevice
*pOutDev
);
368 // draw --> LineColor and FillColor and RasterOp and ClipRegion
369 void DrawPixel( long nX
, long nY
, const OutputDevice
*pOutDev
);
370 void DrawPixel( long nX
, long nY
, SalColor nSalColor
, const OutputDevice
*pOutDev
);
371 void DrawLine( long nX1
, long nY1
, long nX2
, long nY2
, const OutputDevice
*pOutDev
);
372 void DrawRect( long nX
, long nY
, long nWidth
, long nHeight
, const OutputDevice
*pOutDev
);
373 void DrawPolyLine( sal_uLong nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
374 void DrawPolygon( sal_uLong nPoints
, const SalPoint
* pPtAry
, const OutputDevice
*pOutDev
);
375 void DrawPolyPolygon( sal_uInt32 nPoly
,
376 const sal_uInt32
* pPoints
,
377 PCONSTSALPOINT
* pPtAry
,
378 const OutputDevice
*pOutDev
);
379 bool DrawPolyPolygon( const ::basegfx::B2DPolyPolygon
&, double fTransparency
, const OutputDevice
* );
381 bool DrawPolyLine( const basegfx::B2DPolygon
& i_rPolygon
,
382 double i_fTransparency
,
383 const basegfx::B2DVector
& i_rLineWidth
,
384 basegfx::B2DLineJoin i_eLineJoin
,
385 com::sun::star::drawing::LineCap i_eLineCap
,
386 const OutputDevice
* i_pOutDev
);
388 sal_Bool
DrawPolyLineBezier( sal_uLong nPoints
,
389 const SalPoint
* pPtAry
,
390 const sal_uInt8
* pFlgAry
,
391 const OutputDevice
*pOutDev
);
392 sal_Bool
DrawPolygonBezier( sal_uLong nPoints
,
393 const SalPoint
* pPtAry
,
394 const sal_uInt8
* pFlgAry
,
395 const OutputDevice
*pOutDev
);
396 sal_Bool
DrawPolyPolygonBezier( sal_uInt32 nPoly
,
397 const sal_uInt32
* pPoints
,
398 const SalPoint
* const* pPtAry
,
399 const sal_uInt8
* const* pFlgAry
,
400 const OutputDevice
*pOutDev
);
402 // CopyArea --> No RasterOp, but ClipRegion
403 void CopyArea( long nDestX
, long nDestY
,
404 long nSrcX
, long nSrcY
,
405 long nSrcWidth
, long nSrcHeight
,
407 const OutputDevice
*pOutDev
);
409 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
410 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
411 void CopyBits( const SalTwoRect
* pPosAry
,
412 SalGraphics
* pSrcGraphics
,
413 const OutputDevice
*pOutDev
,
414 const OutputDevice
*pSrcOutDev
);
415 void DrawBitmap( const SalTwoRect
* pPosAry
,
416 const SalBitmap
& rSalBitmap
,
417 const OutputDevice
*pOutDev
);
418 void DrawBitmap( const SalTwoRect
* pPosAry
,
419 const SalBitmap
& rSalBitmap
,
420 const SalBitmap
& rTransparentBitmap
,
421 const OutputDevice
*pOutDev
);
423 void DrawMask( const SalTwoRect
* pPosAry
,
424 const SalBitmap
& rSalBitmap
,
426 const OutputDevice
*pOutDev
);
428 SalBitmap
* GetBitmap( long nX
, long nY
,
429 long nWidth
, long nHeight
,
430 const OutputDevice
*pOutDev
);
432 SalColor
GetPixel( long nX
, long nY
,
433 const OutputDevice
*pOutDev
);
435 // invert --> ClipRegion (only Windows)
436 void Invert( long nX
, long nY
,
437 long nWidth
, long nHeight
,
439 const OutputDevice
*pOutDev
);
441 void Invert( sal_uLong nPoints
,
442 const SalPoint
* pPtAry
,
444 const OutputDevice
*pOutDev
);
446 sal_Bool
DrawEPS( long nX
, long nY
,
447 long nWidth
, long nHeight
,
450 const OutputDevice
*pOutDev
);
452 // native widget rendering functions
454 // Query the platform layer for control support
455 virtual sal_Bool
IsNativeControlSupported( ControlType nType
, ControlPart nPart
);
457 // Query the native control to determine if it was acted upon
458 sal_Bool
HitTestNativeControl( ControlType nType
,
460 const Rectangle
& rControlRegion
,
463 const OutputDevice
*pOutDev
);
465 // Request rendering of a particular control and/or part
466 sal_Bool
DrawNativeControl( ControlType nType
,
468 const Rectangle
& rControlRegion
,
470 const ImplControlValue
& aValue
,
471 const OUString
& aCaption
,
472 const OutputDevice
*pOutDev
);
474 // Query the native control's actual drawing region (including adornment)
475 sal_Bool
GetNativeControlRegion( ControlType nType
,
477 const Rectangle
& rControlRegion
,
479 const ImplControlValue
& aValue
,
480 const OUString
& aCaption
,
481 Rectangle
&rNativeBoundingRegion
,
482 Rectangle
&rNativeContentRegion
,
483 const OutputDevice
*pOutDev
);
485 bool DrawAlphaBitmap( const SalTwoRect
&,
486 const SalBitmap
& rSourceBitmap
,
487 const SalBitmap
& rAlphaBitmap
,
488 const OutputDevice
*pOutDev
);
490 bool DrawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
,
491 sal_uInt8 nTransparency
, const OutputDevice
*pOutDev
);
493 virtual SystemGraphicsData
494 GetGraphicsData() const = 0;
496 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const = 0;
499 #endif // _SV_SALGDI_HXX
501 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */