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 .
26 #include <QtGui/QPainter>
27 #include <QtGui/QPainterPath>
28 #include <QtGui/QRegion>
30 #include "Qt5GraphicsBase.hxx"
32 class PhysicalFontCollection
;
40 class Qt5GraphicsBackend final
: public SalGraphicsImpl
, public Qt5GraphicsBase
42 friend class Qt5Painter
;
46 QRegion m_aClipRegion
;
47 QPainterPath m_aClipPath
;
50 QPainter::CompositionMode m_eCompositionMode
;
53 Qt5GraphicsBackend(Qt5Frame
* pFrame
, QImage
* pQImage
);
54 ~Qt5GraphicsBackend() override
;
56 void Init() override
{}
58 QImage
* getQImage() { return m_pQImage
; }
60 void setQImage(QImage
* pQImage
) { m_pQImage
= pQImage
; }
62 void freeResources() override
{}
64 OUString
getRenderBackendName() const override
{ return "qt5"; }
66 bool setClipRegion(vcl::Region
const& rRegion
) override
;
67 void ResetClipRegion() override
;
69 sal_uInt16
GetBitCount() const override
;
71 tools::Long
GetGraphicsWidth() const override
;
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
;
81 void drawPixel(tools::Long nX
, tools::Long nY
) override
;
82 void drawPixel(tools::Long nX
, tools::Long nY
, Color nColor
) override
;
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
;
91 bool drawPolyPolygon(const basegfx::B2DHomMatrix
& rObjectToDevice
,
92 const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
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
;
99 bool drawPolyLineBezier(sal_uInt32 nPoints
, const Point
* pPointArray
,
100 const PolyFlags
* pFlagArray
) override
;
102 bool drawPolygonBezier(sal_uInt32 nPoints
, const Point
* pPointArray
,
103 const PolyFlags
* pFlagArray
) override
;
105 bool drawPolyPolygonBezier(sal_uInt32 nPoly
, const sal_uInt32
* pPoints
,
106 const Point
* const* pPointArray
,
107 const PolyFlags
* const* pFlagArray
) override
;
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
;
112 void copyBits(const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) override
;
114 void drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) override
;
116 void drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
,
117 const SalBitmap
& rMaskBitmap
) override
;
119 void drawMask(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
,
120 Color nMaskColor
) override
;
122 std::shared_ptr
<SalBitmap
> getBitmap(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
123 tools::Long nHeight
) override
;
125 Color
getPixel(tools::Long nX
, tools::Long nY
) override
;
127 void invert(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
128 SalInvert nFlags
) override
;
130 void invert(sal_uInt32 nPoints
, const Point
* pPtAry
, SalInvert nFlags
) override
;
132 bool drawEPS(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
133 void* pPtr
, sal_uInt32 nSize
) override
;
135 bool blendBitmap(const SalTwoRect
&, const SalBitmap
& rBitmap
) override
;
137 bool blendAlphaBitmap(const SalTwoRect
&, const SalBitmap
& rSrcBitmap
,
138 const SalBitmap
& rMaskBitmap
, const SalBitmap
& rAlphaBitmap
) override
;
140 bool drawAlphaBitmap(const SalTwoRect
&, const SalBitmap
& rSourceBitmap
,
141 const SalBitmap
& rAlphaBitmap
) override
;
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
;
147 bool hasFastDrawTransformedBitmap() const override
;
149 bool drawAlphaRect(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
150 sal_uInt8 nTransparency
) override
;
152 bool drawGradient(const tools::PolyPolygon
& rPolygon
, const Gradient
& rGradient
) override
;
153 bool implDrawGradient(basegfx::B2DPolyPolygon
const& rPolyPolygon
,
154 SalGradient
const& rGradient
) override
;
156 bool supportsOperation(OutDevSupportType eType
) const override
;
159 void drawScaledImage(const SalTwoRect
& rPosAry
, const QImage
& rImage
);
162 class Qt5Graphics final
: public SalGraphicsAutoDelegateToImpl
, public Qt5GraphicsBase
164 friend class Qt5Bitmap
;
166 std::unique_ptr
<Qt5GraphicsBackend
> m_pBackend
;
170 rtl::Reference
<Qt5Font
> m_pTextStyle
[MAX_FALLBACK
];
173 Qt5Graphics(Qt5Frame
* pFrame
, QImage
* pQImage
);
175 void drawScaledImage(const SalTwoRect
& rPosAry
, const QImage
& rImage
);
177 void handleDamage(const tools::Rectangle
&) override
;
180 Qt5Graphics(Qt5Frame
* pFrame
)
181 : Qt5Graphics(pFrame
, nullptr)
184 Qt5Graphics(QImage
* pQImage
)
185 : Qt5Graphics(nullptr, pQImage
)
188 virtual ~Qt5Graphics() override
;
190 QImage
* getQImage() { return m_pBackend
->getQImage(); }
192 void ChangeQImage(QImage
* pImage
);
194 virtual SalGraphicsImpl
* GetImpl() const override
;
195 virtual SystemGraphicsData
GetGraphicsData() const override
;
196 virtual OUString
getRenderBackendName() const override
198 return m_pBackend
->getRenderBackendName();
201 #if ENABLE_CAIRO_CANVAS
202 virtual bool SupportsCairo() const override
;
203 virtual cairo::SurfaceSharedPtr
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
216 virtual void GetResolution(sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
218 // Text rendering + font support
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
235 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, tools::Long
* pDataLen
) override
;
236 virtual void FreeEmbedFontData(const void* pData
, tools::Long nDataLen
) override
;
238 virtual void GetGlyphWidths(const PhysicalFontFace
*, bool bVertical
,
239 std::vector
<sal_Int32
>& rWidths
, Ucs2UIntMap
& rUnicodeEnc
) override
;
241 virtual std::unique_ptr
<GenericSalLayout
> GetTextLayout(int nFallbackLevel
) override
;
242 virtual void DrawTextLayout(const GenericSalLayout
&) override
;
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */