LibreOffice Module vcl (master)  1
svpgdi.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
21 #define INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
22 
23 #ifdef IOS
24 #error This file is not for iOS
25 #endif
26 
27 #include <osl/endian.h>
28 #include <vcl/sysdata.hxx>
29 #include <config_cairo_canvas.h>
30 
31 #include <salgdi.hxx>
32 #include <sallayout.hxx>
33 #include "svpcairotextrender.hxx"
34 #include <impfontmetricdata.hxx>
35 
36 #include <cairo.h>
37 
38 //Using formats that match cairo's formats. For android we patch cairo,
39 //which is internal in that case, to swap the rgb components so that
40 //cairo then matches the OpenGL GL_RGBA format so we can use it there
41 //where we don't have GL_BGRA support.
42 // SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory.
43 #if defined ANDROID
44 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
45 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown)
46 # define SVP_CAIRO_BLUE 1
47 # define SVP_CAIRO_GREEN 2
48 # define SVP_CAIRO_RED 0
49 # define SVP_CAIRO_ALPHA 3
50 #elif defined OSL_BIGENDIAN
51 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
52 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown)
53 # define SVP_CAIRO_BLUE 3
54 # define SVP_CAIRO_GREEN 2
55 # define SVP_CAIRO_RED 1
56 # define SVP_CAIRO_ALPHA 0
57 #else
58 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown)
59 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown)
60 # define SVP_CAIRO_BLUE 0
61 # define SVP_CAIRO_GREEN 1
62 # define SVP_CAIRO_RED 2
63 # define SVP_CAIRO_ALPHA 3
64 #endif
65 
66 struct BitmapBuffer;
67 class GlyphCache;
68 class FreetypeFont;
69 typedef struct _cairo cairo_t;
70 typedef struct _cairo_surface cairo_surface_t;
71 typedef struct _cairo_user_data_key cairo_user_data_key_t;
72 
73 VCL_DLLPUBLIC void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale);
74 VCL_DLLPUBLIC void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double *x_scale, double *y_scale);
75 
76 enum class PaintMode { Over, Xor };
77 
78 typedef void (*damageHandler)(void* handle,
79  sal_Int32 nExtentsX, sal_Int32 nExtentsY,
80  sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight);
81 
83 {
84  void *handle;
86 };
87 
89 {
92  double m_fScale;
96 
97 public:
98  static GlyphCache& getPlatformGlyphCache();
99  void setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize);
100  cairo_surface_t* getSurface() const { return m_pSurface; }
101  static cairo_user_data_key_t* getDamageKey();
102 
103  static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion);
104 
105  // need this static version of ::drawPolyLine for usage from
106  // vcl/unx/generic/gdi/salgdi.cxx. It gets wrapped by
107  // ::drawPolyLine with some added parameters (see there)
108  static bool drawPolyLine(
109  cairo_t* cr,
110  basegfx::B2DRange* pExtents,
111  const Color& rLineColor,
112  bool bAntiAliasB2DDraw,
113  const basegfx::B2DHomMatrix& rObjectToDevice,
114  const basegfx::B2DPolygon& rPolyLine,
115  double fTransparency,
116  const basegfx::B2DVector& rLineWidths,
117  basegfx::B2DLineJoin eLineJoin,
118  css::drawing::LineCap eLineCap,
119  double fMiterMinimumAngle,
120  bool bPixelSnapHairline);
121 
122  void copySource(const SalTwoRect& rTR, cairo_surface_t* source);
123  void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source,
124  cairo_operator_t eOp = CAIRO_OPERATOR_SOURCE);
125 
126 private:
127  void invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags);
128  void applyColor(cairo_t *cr, Color rColor, double fTransparency = 0.0);
129 
130 protected:
133 
134 protected:
135  virtual bool blendBitmap( const SalTwoRect&, const SalBitmap& rBitmap ) override;
136  virtual bool blendAlphaBitmap( const SalTwoRect&,
137  const SalBitmap& rSrcBitmap,
138  const SalBitmap& rMaskBitmap,
139  const SalBitmap& rAlphaBitmap ) override;
140  virtual bool drawAlphaBitmap( const SalTwoRect&, const SalBitmap& rSourceBitmap, const SalBitmap& rAlphaBitmap ) override;
141  virtual bool drawTransformedBitmap(
142  const basegfx::B2DPoint& rNull,
143  const basegfx::B2DPoint& rX,
144  const basegfx::B2DPoint& rY,
145  const SalBitmap& rSourceBitmap,
146  const SalBitmap* pAlphaBitmap) override;
147  virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) override;
148 
149  cairo_t* createTmpCompatibleCairoContext() const;
150 
151 public:
152  SvpSalGraphics();
153  virtual ~SvpSalGraphics() override;
154 
155  virtual SalGraphicsImpl* GetImpl() const override { return nullptr; };
156  virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
157  virtual sal_uInt16 GetBitCount() const override;
158  virtual long GetGraphicsWidth() const override;
159 
160  virtual void ResetClipRegion() override;
161  virtual bool setClipRegion( const vcl::Region& ) override;
162 
163  virtual void SetLineColor() override;
164  virtual void SetLineColor( Color nColor ) override;
165  virtual void SetFillColor() override;
166  virtual void SetFillColor( Color nColor ) override;
167 
168  virtual void SetXORMode( bool bSet, bool ) override;
169 
170  virtual void SetROPLineColor( SalROPColor nROPColor ) override;
171  virtual void SetROPFillColor( SalROPColor nROPColor ) override;
172 
173  virtual void SetTextColor( Color nColor ) override;
174  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
175  virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) override;
176  virtual FontCharMapRef GetFontCharMap() const override;
177  virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override;
178  virtual void GetDevFontList( PhysicalFontCollection* ) override;
179  virtual void ClearDevFontCache() override;
180  virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
181  virtual bool CreateFontSubset( const OUString& rToFile,
182  const PhysicalFontFace*,
183  const sal_GlyphId* pGlyphIds,
184  const sal_uInt8* pEncoding,
185  sal_Int32* pWidths,
186  int nGlyphs,
187  FontSubsetInfo& rInfo
188  ) override;
189  virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override;
190  virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override;
191  virtual void GetGlyphWidths( const PhysicalFontFace*,
192  bool bVertical,
193  std::vector< sal_Int32 >& rWidths,
194  Ucs2UIntMap& rUnicodeEnc ) override;
195  virtual std::unique_ptr<GenericSalLayout>
196  GetTextLayout(int nFallbackLevel) override;
197  virtual void DrawTextLayout( const GenericSalLayout& ) override;
198  virtual bool supportsOperation( OutDevSupportType ) const override;
199  virtual void drawPixel( long nX, long nY ) override;
200  virtual void drawPixel( long nX, long nY, Color nColor ) override;
201  virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
202  virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
203 
204  virtual bool drawPolyPolygon(
205  const basegfx::B2DHomMatrix& rObjectToDevice,
207  double fTransparency ) override;
208 
209  virtual bool drawPolyLine(
210  const basegfx::B2DHomMatrix& rObjectToDevice,
211  const basegfx::B2DPolygon&,
212  double fTransparency,
213  const basegfx::B2DVector& rLineWidths,
215  css::drawing::LineCap,
216  double fMiterMinimumAngle,
217  bool bPixelSnapHairline) override;
218  virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
219  virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
220  virtual void drawPolyPolygon( sal_uInt32 nPoly,
221  const sal_uInt32* pPoints,
222  PCONSTSALPOINT* pPtAry ) override;
223  virtual bool drawPolyLineBezier( sal_uInt32 nPoints,
224  const SalPoint* pPtAry,
225  const PolyFlags* pFlgAry ) override;
226  virtual bool drawPolygonBezier( sal_uInt32 nPoints,
227  const SalPoint* pPtAry,
228  const PolyFlags* pFlgAry ) override;
229  virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly,
230  const sal_uInt32* pPoints,
231  const SalPoint* const* pPtAry,
232  const PolyFlags* const* pFlgAry ) override;
233  virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) override { return false; };
234 
235  virtual bool implDrawGradient(basegfx::B2DPolyPolygon const & rPolyPolygon, SalGradient const & rGradient) override;
236 
237  virtual void copyArea( long nDestX,
238  long nDestY,
239  long nSrcX,
240  long nSrcY,
241  long nSrcWidth,
242  long nSrcHeight,
243  bool bWindowInvalidate) override;
244  virtual void copyBits( const SalTwoRect& rPosAry,
245  SalGraphics* pSrcGraphics ) override;
246  virtual void drawBitmap( const SalTwoRect& rPosAry,
247  const SalBitmap& rSalBitmap ) override;
248  void drawBitmap( const SalTwoRect& rPosAry,
249  const BitmapBuffer* pBuffer,
250  cairo_operator_t eOp );
251  virtual void drawBitmap( const SalTwoRect& rPosAry,
252  const SalBitmap& rSalBitmap,
253  const SalBitmap& rTransparentBitmap ) override;
254  virtual void drawMask( const SalTwoRect& rPosAry,
255  const SalBitmap& rSalBitmap,
256  Color nMaskColor ) override;
257  virtual std::shared_ptr<SalBitmap> getBitmap( long nX, long nY, long nWidth, long nHeight ) override;
258  virtual Color getPixel( long nX, long nY ) override;
259  virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags ) override;
260  virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
261 
262  virtual bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uInt32 nSize ) override;
263 
264  virtual SystemGraphicsData GetGraphicsData() const override;
265 
266 
267 #if ENABLE_CAIRO_CANVAS
268  virtual bool SupportsCairo() const override;
269  virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
270  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
271  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const override;
272  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const basegfx::B2ISize& rSize) const override;
273  virtual SystemFontData GetSysFontData( int nFallbacklevel ) const override;
274 #endif // ENABLE_CAIRO_CANVAS
275 
276  cairo_t* getCairoContext(bool bXorModeAllowed) const;
277  void releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, const basegfx::B2DRange& rExtents) const;
278  static cairo_surface_t* createCairoSurface(const BitmapBuffer *pBuffer);
279  void clipRegion(cairo_t* cr);
280 };
281 
282 #endif // INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool drawAlphaBitmap(const SalTwoRect &, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap)=0
Render bitmap with alpha channel.
virtual long GetGraphicsWidth() const =0
virtual void ClearDevFontCache()=0
virtual bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap)=0
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
virtual void DrawTextLayout(const GenericSalLayout &)=0
PaintMode m_ePaintMode
Definition: svpgdi.hxx:95
SalROPColor
Definition: salgtype.hxx:80
basegfx::B2IVector m_aFrameSize
Definition: svpgdi.hxx:91
virtual bool blendAlphaBitmap(const SalTwoRect &, const SalBitmap &rSrcBitmap, const SalBitmap &rMaskBitmap, const SalBitmap &rAlphaBitmap)=0
Draw the bitmap by blending using the mask and alpha channel.
virtual const void * GetEmbedFontData(const PhysicalFontFace *pFont, long *pDataLen)=0
cairo_surface_t * getSurface() const
Definition: svpgdi.hxx:100
virtual bool supportsOperation(OutDevSupportType) const =0
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, bool bWindowInvalidate)=0
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const =0
virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags)=0
virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const SalPoint *const *pPtAry, const PolyFlags *const *pFlgAry)=0
virtual bool blendBitmap(const SalTwoRect &, const SalBitmap &rBitmap)=0
Blend the bitmap with the current buffer.
virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint *pPtAry)=0
virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry)=0
virtual bool CreateFontSubset(const OUString &rToFile, const PhysicalFontFace *pFont, const sal_GlyphId *pGlyphIDs, const sal_uInt8 *pEncoding, sal_Int32 *pWidths, int nGlyphs, FontSubsetInfo &rInfo)=0
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel)=0
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
void * handle
Definition: svpgdi.hxx:84
OutDevSupportType
Definition: vclenum.hxx:195
virtual FontCharMapRef GetFontCharMap() const =0
virtual bool implDrawGradient(basegfx::B2DPolyPolygon const &, SalGradient const &)
Definition: salgdi.hxx:492
SvpCairoTextRender m_aTextRenderImpl
Definition: svpgdi.hxx:132
virtual bool drawGradient(const tools::PolyPolygon &, const Gradient &) override
Definition: svpgdi.hxx:233
virtual void SetROPLineColor(SalROPColor nROPColor)=0
void(* damageHandler)(void *handle, sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight)
Definition: svpgdi.hxx:78
Color m_aFillColor
Definition: svpgdi.hxx:94
virtual void FreeEmbedFontData(const void *pData, long nDataLen)=0
virtual void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap)=0
abstract base class for physical font faces
std::shared_ptr< Surface > SurfaceSharedPtr
Definition: cairo.hxx:36
virtual void SetFillColor()=0
virtual Color getPixel(long nX, long nY)=0
virtual bool setClipRegion(const vcl::Region &)=0
virtual void GetResolution(sal_Int32 &rDPIX, sal_Int32 &rDPIY)=0
VCL_DLLPUBLIC void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double *x_scale, double *y_scale)
virtual void SetLineColor()=0
double m_fScale
Definition: svpgdi.hxx:92
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
damageHandler damaged
Definition: svpgdi.hxx:85
virtual std::shared_ptr< SalBitmap > getBitmap(long nX, long nY, long nWidth, long nHeight)=0
SalInvert
Definition: salgtype.hxx:84
struct _cairo_user_data_key cairo_user_data_key_t
Definition: svpgdi.hxx:71
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
struct _cairo cairo_t
Definition: svpgdi.hxx:69
virtual SystemGraphicsData GetGraphicsData() const =0
virtual void copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcGraphics)=0
virtual void GetGlyphWidths(const PhysicalFontFace *pFont, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc)=0
virtual void SetXORMode(bool bSet, bool bInvertOnly)=0
virtual sal_uInt16 GetBitCount() const =0
vcl::Region m_aClipRegion
Definition: svpgdi.hxx:131
virtual void drawRect(long nX, long nY, long nWidth, long nHeight)=0
virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry)=0
virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, PCONSTSALPOINT *pPtAry)=0
unsigned char sal_uInt8
virtual void SetROPFillColor(SalROPColor nROPColor)=0
virtual void drawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor)=0
virtual void drawLine(long nX1, long nY1, long nX2, long nY2)=0
virtual void drawPixel(long nX, long nY)=0
virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint *pPtAry)=0
VCL_DLLPUBLIC void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale)
virtual SalGraphicsImpl * GetImpl() const override
Definition: svpgdi.hxx:155
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel)=0
virtual bool AddTempDevFont(PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName)=0
virtual void SetFont(LogicalFontInstance *, int nFallbackLevel)=0
virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency)=0
Render solid rectangle with given transparency.
PaintMode
Definition: svpgdi.hxx:76
std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap
Definition: salgdi.hxx:62
virtual void ResetClipRegion()=0
struct _cairo_surface cairo_surface_t
Definition: svpgdi.hxx:70
virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void *pPtr, sal_uInt32 nSize)=0
cairo_surface_t * m_pSurface
Definition: svpgdi.hxx:90
virtual void SetTextColor(Color nColor)=0
Color m_aLineColor
Definition: svpgdi.hxx:93
PolyFlags
virtual void GetDevFontList(PhysicalFontCollection *)=0
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo