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 
40 class Qt5Graphics final : public SalGraphics, public Qt5GraphicsBase
41 {
42  friend class Qt5Bitmap;
43  friend class Qt5Painter;
44 
46  QImage* m_pQImage;
47  QRegion m_aClipRegion;
48  QPainterPath m_aClipPath;
51  QPainter::CompositionMode m_eCompositionMode;
52 
56  std::unique_ptr<QPushButton> m_focusedButton;
57  std::unique_ptr<QImage> m_image;
59 
60  Qt5Graphics(Qt5Frame* pFrame, QImage* pQImage);
61 
62  void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage);
63 
64  void handleDamage(const tools::Rectangle&) override;
65 
66 public:
68  : Qt5Graphics(pFrame, nullptr)
69  {
70  }
71  Qt5Graphics(QImage* pQImage)
72  : Qt5Graphics(nullptr, pQImage)
73  {
74  }
75  virtual ~Qt5Graphics() override;
76 
77  void ChangeQImage(QImage* pImage);
78 
79  virtual SalGraphicsImpl* GetImpl() const override;
80  virtual SystemGraphicsData GetGraphicsData() const override;
81  virtual bool supportsOperation(OutDevSupportType) const override;
82  virtual OUString getRenderBackendName() const override { return "qt5"; }
83 
84 #if ENABLE_CAIRO_CANVAS
85  virtual bool SupportsCairo() const override;
87  CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
88  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y,
89  int width, int height) const override;
90  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice,
91  const BitmapSystemData& rData,
92  const Size& rSize) const override;
93  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface,
94  const basegfx::B2ISize& rSize) const override;
95 #endif // ENABLE_CAIRO_CANVAS
96 
97  // GDI
98 
99  virtual bool setClipRegion(const vcl::Region&) override;
100  virtual void ResetClipRegion() override;
101 
102  virtual void drawPixel(long nX, long nY) override;
103  virtual void drawPixel(long nX, long nY, Color nColor) override;
104  virtual void drawLine(long nX1, long nY1, long nX2, long nY2) override;
105  virtual void drawRect(long nX, long nY, long nWidth, long nHeight) override;
106  virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint* pPtAry) override;
107  virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry) override;
108  virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints,
109  PCONSTSALPOINT* pPtAry) override;
110  virtual bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
111  const basegfx::B2DPolyPolygon&, double fTransparency) override;
112  virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint* pPtAry,
113  const PolyFlags* pFlgAry) override;
114  virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint* pPtAry,
115  const PolyFlags* pFlgAry) override;
116  virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints,
117  const SalPoint* const* pPtAry,
118  const PolyFlags* const* pFlgAry) override;
119  virtual bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice,
120  const basegfx::B2DPolygon&, double fTransparency, double fLineWidths,
121  const std::vector<double>* pStroke, // MM01
122  basegfx::B2DLineJoin, css::drawing::LineCap eLineCap,
123  double fMiterMinimumAngle, bool bPixelSnapHairline) override;
124  virtual bool drawGradient(const tools::PolyPolygon&, const Gradient&) override;
125 
126  virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth,
127  long nSrcHeight, bool bWindowInvalidate) override;
128 
129  virtual void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override;
130  virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override;
131  virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
132  const SalBitmap& rTransparentBitmap) override;
133  virtual void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
134  Color nMaskColor) override;
135 
136  virtual std::shared_ptr<SalBitmap> getBitmap(long nX, long nY, long nWidth,
137  long nHeight) override;
138  virtual Color getPixel(long nX, long nY) override;
139 
140  virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override;
141  virtual void invert(sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags) override;
142 
143  virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void* pPtr,
144  sal_uInt32 nSize) override;
145 
146  virtual bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override;
147 
148  virtual bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap,
149  const SalBitmap& rMaskBitmap,
150  const SalBitmap& rAlphaBitmap) override;
151 
152  virtual bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap,
153  const SalBitmap& rAlphaBitmap) override;
154 
155  bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX,
156  const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
157  const SalBitmap* pAlphaBitmap) override;
158 
159  virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight,
160  sal_uInt8 nTransparency) override;
161 
162  virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override;
163  virtual sal_uInt16 GetBitCount() const override;
164  virtual long GetGraphicsWidth() const override;
165 
166  virtual void SetLineColor() override;
167  virtual void SetLineColor(Color nColor) override;
168  virtual void SetFillColor() override;
169  virtual void SetFillColor(Color nColor) override;
170  virtual void SetXORMode(bool bSet, bool bInvertOnly) override;
171  virtual void SetROPLineColor(SalROPColor nROPColor) override;
172  virtual void SetROPFillColor(SalROPColor nROPColor) override;
173 
174  // Text rendering + font support
175 
176  virtual void SetTextColor(Color nColor) override;
177  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
178  virtual void GetFontMetric(ImplFontMetricDataRef&, int nFallbackLevel) override;
179  virtual FontCharMapRef GetFontCharMap() const override;
180  virtual bool GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const override;
181  virtual void GetDevFontList(PhysicalFontCollection*) override;
182  virtual void ClearDevFontCache() override;
183  virtual bool AddTempDevFont(PhysicalFontCollection*, const OUString& rFileURL,
184  const OUString& rFontName) override;
185  virtual bool CreateFontSubset(const OUString& rToFile, const PhysicalFontFace* pFont,
186  const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding,
187  sal_Int32* pWidths, int nGlyphs,
188  FontSubsetInfo& rInfo // out parameter
189  ) override;
190 
191  virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override;
192  virtual void FreeEmbedFontData(const void* pData, long nDataLen) override;
193 
194  virtual void GetGlyphWidths(const PhysicalFontFace*, bool bVertical,
195  std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc) override;
196 
197  virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override;
198  virtual void DrawTextLayout(const GenericSalLayout&) override;
199 };
200 
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ResetClipRegion() override
virtual void GetGlyphWidths(const PhysicalFontFace *, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc) override
void drawScaledImage(const SalTwoRect &rPosAry, const QImage &rImage)
virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry) override
virtual const void * GetEmbedFontData(const PhysicalFontFace *, long *pDataLen) override
virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry) override
virtual bool AddTempDevFont(PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName) override
SalROPColor
Definition: salgtype.hxx:80
#define MAX_FALLBACK
Definition: sallayout.hxx:41
virtual sal_uInt16 GetBitCount() const override
virtual FontCharMapRef GetFontCharMap() const override
virtual void SetFont(LogicalFontInstance *, int nFallbackLevel) override
std::unique_ptr< QImage > m_image
Definition: Qt5Graphics.hxx:57
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel) override
virtual void ClearDevFontCache() override
bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap) override
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
virtual bool blendAlphaBitmap(const SalTwoRect &, const SalBitmap &rSrcBitmap, const SalBitmap &rMaskBitmap, const SalBitmap &rAlphaBitmap) override
Draw the bitmap by blending using the mask and alpha channel.
Color m_aLineColor
Definition: Qt5Graphics.hxx:49
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
OutDevSupportType
Definition: vclenum.hxx:198
Qt5Graphics(Qt5Frame *pFrame)
Definition: Qt5Graphics.hxx:67
Qt5Frame * m_pFrame
Definition: Qt5Graphics.hxx:45
QRegion m_aClipRegion
Definition: Qt5Graphics.hxx:47
virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint *pPtAry) override
virtual long GetGraphicsWidth() const override
virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency) override
Render solid rectangle with given transparency.
virtual void GetDevFontList(PhysicalFontCollection *) override
virtual SalGraphicsImpl * GetImpl() const override
virtual ~Qt5Graphics() override
virtual void copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcGraphics) override
abstract base class for physical font faces
virtual void drawPixel(long nX, long nY) override
std::shared_ptr< Surface > SurfaceSharedPtr
Definition: cairo.hxx:36
virtual void SetXORMode(bool bSet, bool bInvertOnly) override
void ChangeQImage(QImage *pImage)
virtual void drawRect(long nX, long nY, long nWidth, long nHeight) override
QRect m_lastPopupRect
Definition: Qt5Graphics.hxx:58
virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override
PhysicalFontCollection * m_pFontCollection
Definition: Qt5Graphics.hxx:53
virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const SalPoint *const *pPtAry, const PolyFlags *const *pFlgAry) override
virtual OUString getRenderBackendName() const override
Definition: Qt5Graphics.hxx:82
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
SalInvert
Definition: salgtype.hxx:84
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
virtual SystemGraphicsData GetGraphicsData() const override
virtual void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap) override
virtual bool drawAlphaBitmap(const SalTwoRect &, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap) override
Render bitmap with alpha channel.
QImage * m_pQImage
Definition: Qt5Graphics.hxx:46
Color m_aFillColor
Definition: Qt5Graphics.hxx:50
virtual std::shared_ptr< SalBitmap > getBitmap(long nX, long nY, long nWidth, long nHeight) override
Color m_aTextColor
Definition: Qt5Graphics.hxx:55
virtual void drawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor) override
virtual bool drawGradient(const tools::PolyPolygon &, const Gradient &) override
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel) override
virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, PCONSTSALPOINT *pPtAry) override
virtual void drawLine(long nX1, long nY1, long nX2, long nY2) override
void handleDamage(const tools::Rectangle &) override
Handle damage done by drawing with a widget draw override.
unsigned char sal_uInt8
virtual void DrawTextLayout(const GenericSalLayout &) override
virtual void GetResolution(sal_Int32 &rDPIX, sal_Int32 &rDPIY) override
virtual Color getPixel(long nX, long nY) override
virtual void FreeEmbedFontData(const void *pData, long nDataLen) override
Qt5Graphics(Qt5Frame *pFrame, QImage *pQImage)
virtual void SetTextColor(Color nColor) override
virtual void SetROPLineColor(SalROPColor nROPColor) override
QPainterPath m_aClipPath
Definition: Qt5Graphics.hxx:48
virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, bool bWindowInvalidate) override
virtual void SetROPFillColor(SalROPColor nROPColor) override
virtual bool setClipRegion(const vcl::Region &) override
virtual void SetFillColor() override
std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap
Definition: salgdi.hxx:58
virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void *pPtr, sal_uInt32 nSize) override
rtl::Reference< Qt5Font > m_pTextStyle[MAX_FALLBACK]
Definition: Qt5Graphics.hxx:54
QPainter::CompositionMode m_eCompositionMode
Definition: Qt5Graphics.hxx:51
virtual void SetLineColor() override
virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint *pPtAry) override
std::unique_ptr< QPushButton > m_focusedButton
Definition: Qt5Graphics.hxx:56
virtual bool supportsOperation(OutDevSupportType) const override
Qt5Graphics(QImage *pQImage)
Definition: Qt5Graphics.hxx:71
virtual bool blendBitmap(const SalTwoRect &, const SalBitmap &rBitmap) override
Blend the bitmap with the current buffer.
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
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override