LibreOffice Module vcl (master)  1
Qt5Graphics.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 #pragma once
21 
22 #include <salgdi.hxx>
23 
24 #include <memory>
25 
26 #include <QtGui/QPainter>
27 #include <QtGui/QPainterPath>
28 #include <QtGui/QRegion>
29 
30 #include "Qt5GraphicsBase.hxx"
31 
33 class QImage;
34 class QPushButton;
35 class Qt5Font;
36 class Qt5FontFace;
37 class Qt5Frame;
38 class Qt5Painter;
39 
41 {
42  friend class Qt5Painter;
43 
45  QImage* m_pQImage;
46  QRegion m_aClipRegion;
47  QPainterPath m_aClipPath;
50  QPainter::CompositionMode m_eCompositionMode;
51 
52 public:
53  Qt5GraphicsBackend(Qt5Frame* pFrame, QImage* pQImage);
54  ~Qt5GraphicsBackend() override;
55 
56  void Init() override {}
57 
58  QImage* getQImage() { return m_pQImage; }
59 
60  void setQImage(QImage* pQImage) { m_pQImage = pQImage; }
61 
62  void freeResources() override {}
63 
64  OUString getRenderBackendName() const override { return "qt5"; }
65 
66  bool setClipRegion(vcl::Region const& rRegion) override;
67  void ResetClipRegion() override;
68 
69  sal_uInt16 GetBitCount() const override;
70 
71  tools::Long GetGraphicsWidth() const override;
72 
73  void SetLineColor() override;
74  void SetLineColor(Color nColor) override;
75  void SetFillColor() override;
76  void SetFillColor(Color nColor) override;
77  void SetXORMode(bool bSet, bool bInvertOnly) override;
78  void SetROPLineColor(SalROPColor nROPColor) override;
79  void SetROPFillColor(SalROPColor nROPColor) override;
80 
81  void drawPixel(tools::Long nX, tools::Long nY) override;
82  void drawPixel(tools::Long nX, tools::Long nY, Color nColor) override;
83 
84  void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override;
85  void drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override;
86  void drawPolyLine(sal_uInt32 nPoints, const Point* pPointArray) override;
87  void drawPolygon(sal_uInt32 nPoints, const Point* pPointArray) override;
88  void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints,
89  const Point** pPointArray) override;
90 
91  bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
92  const basegfx::B2DPolyPolygon&, double fTransparency) override;
93 
94  bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolygon&,
95  double fTransparency, double fLineWidth, const std::vector<double>* pStroke,
96  basegfx::B2DLineJoin, css::drawing::LineCap, double fMiterMinimumAngle,
97  bool bPixelSnapHairline) override;
98 
99  bool drawPolyLineBezier(sal_uInt32 nPoints, const Point* pPointArray,
100  const PolyFlags* pFlagArray) override;
101 
102  bool drawPolygonBezier(sal_uInt32 nPoints, const Point* pPointArray,
103  const PolyFlags* pFlagArray) override;
104 
105  bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints,
106  const Point* const* pPointArray,
107  const PolyFlags* const* pFlagArray) override;
108 
109  void copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY,
110  tools::Long nSrcWidth, tools::Long nSrcHeight, bool bWindowInvalidate) override;
111 
112  void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override;
113 
114  void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override;
115 
116  void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
117  const SalBitmap& rMaskBitmap) override;
118 
119  void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
120  Color nMaskColor) override;
121 
122  std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth,
123  tools::Long nHeight) override;
124 
125  Color getPixel(tools::Long nX, tools::Long nY) override;
126 
127  void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
128  SalInvert nFlags) override;
129 
130  void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags) override;
131 
132  bool drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
133  void* pPtr, sal_uInt32 nSize) override;
134 
135  bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override;
136 
137  bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap,
138  const SalBitmap& rMaskBitmap, const SalBitmap& rAlphaBitmap) override;
139 
140  bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap,
141  const SalBitmap& rAlphaBitmap) override;
142 
143  bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX,
144  const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
145  const SalBitmap* pAlphaBitmap, double fAlpha) override;
146 
147  bool hasFastDrawTransformedBitmap() const override;
148 
149  bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
150  sal_uInt8 nTransparency) override;
151 
152  bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
153  bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon,
154  SalGradient const& rGradient) override;
155 
156  bool supportsOperation(OutDevSupportType eType) const override;
157 
158 private:
159  void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage);
160 };
161 
163 {
164  friend class Qt5Bitmap;
165 
166  std::unique_ptr<Qt5GraphicsBackend> m_pBackend;
167 
169 
172 
173  Qt5Graphics(Qt5Frame* pFrame, QImage* pQImage);
174 
175  void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage);
176 
177  void handleDamage(const tools::Rectangle&) override;
178 
179 public:
181  : Qt5Graphics(pFrame, nullptr)
182  {
183  }
184  Qt5Graphics(QImage* pQImage)
185  : Qt5Graphics(nullptr, pQImage)
186  {
187  }
188  virtual ~Qt5Graphics() override;
189 
190  QImage* getQImage() { return m_pBackend->getQImage(); }
191 
192  void ChangeQImage(QImage* pImage);
193 
194  virtual SalGraphicsImpl* GetImpl() const override;
195  virtual SystemGraphicsData GetGraphicsData() const override;
196  virtual OUString getRenderBackendName() const override
197  {
198  return m_pBackend->getRenderBackendName();
199  }
200 
201 #if ENABLE_CAIRO_CANVAS
202  virtual bool SupportsCairo() const override;
204  CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
205  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y,
206  int width, int height) const override;
207  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice,
208  const BitmapSystemData& rData,
209  const Size& rSize) const override;
210  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface,
211  const basegfx::B2ISize& rSize) const override;
212 #endif // ENABLE_CAIRO_CANVAS
213 
214  // GDI
215 
216  virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override;
217 
218  // Text rendering + font support
219 
220  virtual void SetTextColor(Color nColor) override;
221  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
222  virtual void GetFontMetric(ImplFontMetricDataRef&, int nFallbackLevel) override;
223  virtual FontCharMapRef GetFontCharMap() const override;
224  virtual bool GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const override;
225  virtual void GetDevFontList(PhysicalFontCollection*) override;
226  virtual void ClearDevFontCache() override;
227  virtual bool AddTempDevFont(PhysicalFontCollection*, const OUString& rFileURL,
228  const OUString& rFontName) override;
229  virtual bool CreateFontSubset(const OUString& rToFile, const PhysicalFontFace* pFont,
230  const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
231  sal_Int32* pWidths, int nGlyphs,
232  FontSubsetInfo& rInfo // out parameter
233  ) override;
234 
235  virtual const void* GetEmbedFontData(const PhysicalFontFace*, tools::Long* pDataLen) override;
236  virtual void FreeEmbedFontData(const void* pData, tools::Long nDataLen) override;
237 
238  virtual void GetGlyphWidths(const PhysicalFontFace*, bool bVertical,
239  std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc) override;
240 
241  virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override;
242  virtual void DrawTextLayout(const GenericSalLayout&) override;
243 };
244 
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
QImage * getQImage()
bool blendBitmap(const SalTwoRect &, const SalBitmap &rBitmap) override
void SetLineColor() override
QPainterPath m_aClipPath
Definition: Qt5Graphics.hxx:47
Color getPixel(tools::Long nX, tools::Long nY) override
virtual void GetGlyphWidths(const PhysicalFontFace *, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc) override
void drawScaledImage(const SalTwoRect &rPosAry, const QImage &rImage)
bool drawPolygonBezier(sal_uInt32 nPoints, const Point *pPointArray, const PolyFlags *pFlagArray) override
bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point *const *pPointArray, const PolyFlags *const *pFlagArray) override
virtual bool AddTempDevFont(PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName) override
SalROPColor
Definition: salgtype.hxx:70
bool hasFastDrawTransformedBitmap() const override
Used e.g.
void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point **pPointArray) override
#define MAX_FALLBACK
Definition: sallayout.hxx:42
long Long
bool drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, void *pPtr, sal_uInt32 nSize) override
void ResetClipRegion() override
sal_uInt16 GetBitCount() const override
virtual FontCharMapRef GetFontCharMap() const override
virtual void SetFont(LogicalFontInstance *, int nFallbackLevel) override
bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency) override
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel) override
virtual void ClearDevFontCache() override
void drawPolyLine(sal_uInt32 nPoints, const Point *pPointArray) override
~Qt5GraphicsBackend() override
bool drawGradient(const tools::PolyPolygon &rPolygon, const Gradient &rGradient) override
bool drawPolyLineBezier(sal_uInt32 nPoints, const Point *pPointArray, const PolyFlags *pFlagArray) override
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:29
OutDevSupportType
Definition: vclenum.hxx:196
Qt5Graphics(Qt5Frame *pFrame)
Qt5Frame * m_pFrame
bool implDrawGradient(basegfx::B2DPolyPolygon const &rPolyPolygon, SalGradient const &rGradient) override
tools::Long GetGraphicsWidth() const override
virtual void GetDevFontList(PhysicalFontCollection *) override
virtual SalGraphicsImpl * GetImpl() const override
virtual ~Qt5Graphics() override
OUString getRenderBackendName() const override
Definition: Qt5Graphics.hxx:64
std::unique_ptr< Qt5GraphicsBackend > m_pBackend
abstract base class for physical font faces
std::shared_ptr< Surface > SurfaceSharedPtr
Definition: cairo.hxx:36
QPainter::CompositionMode m_eCompositionMode
Definition: Qt5Graphics.hxx:50
void ChangeQImage(QImage *pImage)
void Init() override
Definition: Qt5Graphics.hxx:56
bool blendAlphaBitmap(const SalTwoRect &, const SalBitmap &rSrcBitmap, const SalBitmap &rMaskBitmap, const SalBitmap &rAlphaBitmap) override
void copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcGraphics) override
void copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY, tools::Long nSrcWidth, tools::Long nSrcHeight, bool bWindowInvalidate) override
void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override
bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap, double fAlpha) override
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
virtual OUString getRenderBackendName() const override
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:162
void SetROPFillColor(SalROPColor nROPColor) override
void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap) override
void freeResources() override
Definition: Qt5Graphics.hxx:62
SalInvert
Definition: salgtype.hxx:74
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
void drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override
void drawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor) override
virtual const void * GetEmbedFontData(const PhysicalFontFace *, tools::Long *pDataLen) override
virtual SystemGraphicsData GetGraphicsData() const override
Qt5Frame * m_pFrame
Definition: Qt5Graphics.hxx:44
Qt5GraphicsBackend(Qt5Frame *pFrame, QImage *pQImage)
void SetFillColor() override
QImage * getQImage()
Definition: Qt5Graphics.hxx:58
Color m_aTextColor
bool drawAlphaBitmap(const SalTwoRect &, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap) override
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel) override
void handleDamage(const tools::Rectangle &) override
Handle damage done by drawing with a widget draw override.
void SetXORMode(bool bSet, bool bInvertOnly) override
unsigned char sal_uInt8
virtual void DrawTextLayout(const GenericSalLayout &) override
bool setClipRegion(vcl::Region const &rRegion) override
void drawPixel(tools::Long nX, tools::Long nY) override
virtual void GetResolution(sal_Int32 &rDPIX, sal_Int32 &rDPIY) override
std::shared_ptr< SalBitmap > getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override
bool supportsOperation(OutDevSupportType eType) const override
Qt5Graphics(Qt5Frame *pFrame, QImage *pQImage)
virtual void SetTextColor(Color nColor) override
void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags) override
void drawPolygon(sal_uInt32 nPoints, const Point *pPointArray) override
std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap
Definition: salgdi.hxx:64
rtl::Reference< Qt5Font > m_pTextStyle[MAX_FALLBACK]
void setQImage(QImage *pQImage)
Definition: Qt5Graphics.hxx:60
void SetROPLineColor(SalROPColor nROPColor) override
virtual void FreeEmbedFontData(const void *pData, tools::Long nDataLen) override
Qt5Graphics(QImage *pQImage)
virtual bool CreateFontSubset(const OUString &rToFile, const PhysicalFontFace *pFont, const sal_GlyphId *pGlyphIds, const sal_uInt8 *pEncoding, sal_Int32 *pWidths, int nGlyphs, FontSubsetInfo &rInfo) override
PolyFlags
void drawScaledImage(const SalTwoRect &rPosAry, const QImage &rImage)
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override