1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 .
22 #include <sal/config.h>
29 #include <QtGui/QPainter>
30 #include <QtGui/QPainterPath>
31 #include <QtGui/QRegion>
33 #include "QtGraphicsBase.hxx"
37 class PhysicalFontCollection
;
46 class QtGraphicsBackend final
: public SalGraphicsImpl
, public QtGraphicsBase
48 friend class QtPainter
;
52 QRegion m_aClipRegion
;
53 QPainterPath m_aClipPath
;
54 std::optional
<Color
> m_oLineColor
;
55 std::optional
<Color
> m_oFillColor
;
56 QPainter::CompositionMode m_eCompositionMode
;
59 QtGraphicsBackend(QtFrame
* pFrame
, QImage
* pQImage
);
60 ~QtGraphicsBackend() override
;
62 QImage
* getQImage() { return m_pQImage
; }
64 void setQImage(QImage
* pQImage
) { m_pQImage
= pQImage
; }
66 OUString
getRenderBackendName() const override
{ return u
"qt"_ustr
; }
68 void setClipRegion(vcl::Region
const& rRegion
) override
;
69 void ResetClipRegion() override
;
71 sal_uInt16
GetBitCount() const override
;
73 tools::Long
GetGraphicsWidth() const override
;
75 void SetLineColor() override
;
76 void SetLineColor(Color nColor
) override
;
77 void SetFillColor() override
;
78 void SetFillColor(Color nColor
) override
;
79 void SetXORMode(bool bSet
, bool bInvertOnly
) override
;
80 void SetROPLineColor(SalROPColor nROPColor
) override
;
81 void SetROPFillColor(SalROPColor nROPColor
) override
;
83 void drawPixel(tools::Long nX
, tools::Long nY
) override
;
84 void drawPixel(tools::Long nX
, tools::Long nY
, Color nColor
) override
;
86 void drawLine(tools::Long nX1
, tools::Long nY1
, tools::Long nX2
, tools::Long nY2
) override
;
87 void drawRect(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
) override
;
88 void drawPolyLine(sal_uInt32 nPoints
, const Point
* pPointArray
) override
;
89 void drawPolygon(sal_uInt32 nPoints
, const Point
* pPointArray
) override
;
90 void drawPolyPolygon(sal_uInt32 nPoly
, const sal_uInt32
* pPoints
,
91 const Point
** pPointArray
) override
;
93 void drawPolyPolygon(const basegfx::B2DHomMatrix
& rObjectToDevice
,
94 const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
96 bool drawPolyLine(const basegfx::B2DHomMatrix
& rObjectToDevice
, const basegfx::B2DPolygon
&,
97 double fTransparency
, double fLineWidth
, const std::vector
<double>* pStroke
,
98 basegfx::B2DLineJoin
, css::drawing::LineCap
, double fMiterMinimumAngle
,
99 bool bPixelSnapHairline
) override
;
101 bool drawPolyLineBezier(sal_uInt32 nPoints
, const Point
* pPointArray
,
102 const PolyFlags
* pFlagArray
) override
;
104 bool drawPolygonBezier(sal_uInt32 nPoints
, const Point
* pPointArray
,
105 const PolyFlags
* pFlagArray
) override
;
107 bool drawPolyPolygonBezier(sal_uInt32 nPoly
, const sal_uInt32
* pPoints
,
108 const Point
* const* pPointArray
,
109 const PolyFlags
* const* pFlagArray
) override
;
111 void copyArea(tools::Long nDestX
, tools::Long nDestY
, tools::Long nSrcX
, tools::Long nSrcY
,
112 tools::Long nSrcWidth
, tools::Long nSrcHeight
, bool bWindowInvalidate
) override
;
114 void copyBits(const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
) override
;
116 void drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
) override
;
118 void drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
,
119 const SalBitmap
& rMaskBitmap
) override
;
121 void drawMask(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
,
122 Color nMaskColor
) override
;
124 std::shared_ptr
<SalBitmap
> getBitmap(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
125 tools::Long nHeight
) override
;
127 Color
getPixel(tools::Long nX
, tools::Long nY
) override
;
129 void invert(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
130 SalInvert nFlags
) override
;
132 void invert(sal_uInt32 nPoints
, const Point
* pPtAry
, SalInvert nFlags
) override
;
134 bool blendBitmap(const SalTwoRect
&, const SalBitmap
& rBitmap
) override
;
136 bool blendAlphaBitmap(const SalTwoRect
&, const SalBitmap
& rSrcBitmap
,
137 const SalBitmap
& rMaskBitmap
, const SalBitmap
& rAlphaBitmap
) override
;
139 bool drawAlphaBitmap(const SalTwoRect
&, const SalBitmap
& rSourceBitmap
,
140 const SalBitmap
& rAlphaBitmap
) override
;
142 bool drawTransformedBitmap(const basegfx::B2DPoint
& rNull
, const basegfx::B2DPoint
& rX
,
143 const basegfx::B2DPoint
& rY
, const SalBitmap
& rSourceBitmap
,
144 const SalBitmap
* pAlphaBitmap
, double fAlpha
) override
;
146 bool drawAlphaRect(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
,
147 sal_uInt8 nTransparency
) override
;
149 bool drawGradient(const tools::PolyPolygon
& rPolygon
, const Gradient
& rGradient
) override
;
150 bool implDrawGradient(basegfx::B2DPolyPolygon
const& rPolyPolygon
,
151 SalGradient
const& rGradient
) override
;
153 bool supportsOperation(OutDevSupportType eType
) const override
;
156 void drawScaledImage(const SalTwoRect
& rPosAry
, const QImage
& rImage
);
159 class QtGraphics final
: public SalGraphicsAutoDelegateToImpl
, public QtGraphicsBase
161 friend class QtBitmap
;
163 std::unique_ptr
<QtGraphicsBackend
> m_pBackend
;
167 rtl::Reference
<QtFont
> m_pTextStyle
[MAX_FALLBACK
];
170 QtGraphics(QtFrame
* pFrame
, QImage
* pQImage
);
172 void drawScaledImage(const SalTwoRect
& rPosAry
, const QImage
& rImage
);
174 void handleDamage(const tools::Rectangle
&) override
;
177 QtGraphics(QtFrame
* pFrame
)
178 : QtGraphics(pFrame
, nullptr)
181 QtGraphics(QImage
* pQImage
)
182 : QtGraphics(nullptr, pQImage
)
185 virtual ~QtGraphics() override
;
187 QImage
* getQImage() { return m_pBackend
->getQImage(); }
189 void ChangeQImage(QImage
* pImage
);
191 virtual SalGraphicsImpl
* GetImpl() const override
;
192 virtual SystemGraphicsData
GetGraphicsData() const override
;
193 virtual OUString
getRenderBackendName() const override
195 return m_pBackend
->getRenderBackendName();
198 #if ENABLE_CAIRO_CANVAS
199 virtual bool SupportsCairo() const override
;
200 virtual cairo::SurfaceSharedPtr
201 CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const override
;
202 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
,
203 int width
, int height
) const override
;
204 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
,
205 const BitmapSystemData
& rData
,
206 const Size
& rSize
) const override
;
207 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
,
208 const basegfx::B2ISize
& rSize
) const override
;
209 #endif // ENABLE_CAIRO_CANVAS
213 virtual void GetResolution(sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
215 // Text rendering + font support
217 virtual void SetTextColor(Color nColor
) override
;
218 virtual void SetFont(LogicalFontInstance
*, int nFallbackLevel
) override
;
219 virtual void GetFontMetric(FontMetricDataRef
&, int nFallbackLevel
) override
;
220 virtual FontCharMapRef
GetFontCharMap() const override
;
221 virtual bool GetFontCapabilities(vcl::FontCapabilities
& rFontCapabilities
) const override
;
222 virtual void GetDevFontList(vcl::font::PhysicalFontCollection
*) override
;
223 virtual void ClearDevFontCache() override
;
224 virtual bool AddTempDevFont(vcl::font::PhysicalFontCollection
*, const OUString
& rFileURL
,
225 const OUString
& rFontName
) override
;
227 virtual std::unique_ptr
<GenericSalLayout
> GetTextLayout(int nFallbackLevel
) override
;
228 virtual void DrawTextLayout(const GenericSalLayout
&) override
;
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */