Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / qt5 / QtGraphics.hxx
blobfce2b0d9b56debf9dbbb9c74a870c5ae8ab78dcb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <salgdi.hxx>
26 #include <memory>
27 #include <optional>
29 #include <QtGui/QPainter>
30 #include <QtGui/QPainterPath>
31 #include <QtGui/QRegion>
33 #include "QtGraphicsBase.hxx"
35 namespace vcl::font
37 class PhysicalFontCollection;
39 class QImage;
40 class QPushButton;
41 class QtFont;
42 class QtFontFace;
43 class QtFrame;
44 class QtPainter;
46 class QtGraphicsBackend final : public SalGraphicsImpl, public QtGraphicsBase
48 friend class QtPainter;
50 QtFrame* m_pFrame;
51 QImage* m_pQImage;
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;
58 public:
59 QtGraphicsBackend(QtFrame* pFrame, QImage* pQImage);
60 ~QtGraphicsBackend() override;
62 void Init() override {}
64 QImage* getQImage() { return m_pQImage; }
66 void setQImage(QImage* pQImage) { m_pQImage = pQImage; }
68 void freeResources() override {}
70 OUString getRenderBackendName() const override { return "qt5"; }
72 void setClipRegion(vcl::Region const& rRegion) override;
73 void ResetClipRegion() override;
75 sal_uInt16 GetBitCount() const override;
77 tools::Long GetGraphicsWidth() const override;
79 void SetLineColor() override;
80 void SetLineColor(Color nColor) override;
81 void SetFillColor() override;
82 void SetFillColor(Color nColor) override;
83 void SetXORMode(bool bSet, bool bInvertOnly) override;
84 void SetROPLineColor(SalROPColor nROPColor) override;
85 void SetROPFillColor(SalROPColor nROPColor) override;
87 void drawPixel(tools::Long nX, tools::Long nY) override;
88 void drawPixel(tools::Long nX, tools::Long nY, Color nColor) override;
90 void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override;
91 void drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override;
92 void drawPolyLine(sal_uInt32 nPoints, const Point* pPointArray) override;
93 void drawPolygon(sal_uInt32 nPoints, const Point* pPointArray) override;
94 void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints,
95 const Point** pPointArray) override;
97 void drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
98 const basegfx::B2DPolyPolygon&, double fTransparency) override;
100 bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, const basegfx::B2DPolygon&,
101 double fTransparency, double fLineWidth, const std::vector<double>* pStroke,
102 basegfx::B2DLineJoin, css::drawing::LineCap, double fMiterMinimumAngle,
103 bool bPixelSnapHairline) override;
105 bool drawPolyLineBezier(sal_uInt32 nPoints, const Point* pPointArray,
106 const PolyFlags* pFlagArray) override;
108 bool drawPolygonBezier(sal_uInt32 nPoints, const Point* pPointArray,
109 const PolyFlags* pFlagArray) override;
111 bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints,
112 const Point* const* pPointArray,
113 const PolyFlags* const* pFlagArray) override;
115 void copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY,
116 tools::Long nSrcWidth, tools::Long nSrcHeight, bool bWindowInvalidate) override;
118 void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override;
120 void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override;
122 void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
123 const SalBitmap& rMaskBitmap) override;
125 void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
126 Color nMaskColor) override;
128 std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth,
129 tools::Long nHeight) override;
131 Color getPixel(tools::Long nX, tools::Long nY) override;
133 void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
134 SalInvert nFlags) override;
136 void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags) override;
138 bool drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
139 void* pPtr, sal_uInt32 nSize) override;
141 bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override;
143 bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap,
144 const SalBitmap& rMaskBitmap, const SalBitmap& rAlphaBitmap) override;
146 bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap,
147 const SalBitmap& rAlphaBitmap) override;
149 bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX,
150 const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
151 const SalBitmap* pAlphaBitmap, double fAlpha) override;
153 bool hasFastDrawTransformedBitmap() const override;
155 bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight,
156 sal_uInt8 nTransparency) override;
158 bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
159 bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon,
160 SalGradient const& rGradient) override;
162 bool supportsOperation(OutDevSupportType eType) const override;
164 private:
165 void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage);
168 class QtGraphics final : public SalGraphicsAutoDelegateToImpl, public QtGraphicsBase
170 friend class QtBitmap;
172 std::unique_ptr<QtGraphicsBackend> m_pBackend;
174 QtFrame* m_pFrame;
176 rtl::Reference<QtFont> m_pTextStyle[MAX_FALLBACK];
177 Color m_aTextColor;
179 QtGraphics(QtFrame* pFrame, QImage* pQImage);
181 void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage);
183 void handleDamage(const tools::Rectangle&) override;
185 public:
186 QtGraphics(QtFrame* pFrame)
187 : QtGraphics(pFrame, nullptr)
190 QtGraphics(QImage* pQImage)
191 : QtGraphics(nullptr, pQImage)
194 virtual ~QtGraphics() override;
196 QImage* getQImage() { return m_pBackend->getQImage(); }
198 void ChangeQImage(QImage* pImage);
200 virtual SalGraphicsImpl* GetImpl() const override;
201 virtual SystemGraphicsData GetGraphicsData() const override;
202 virtual OUString getRenderBackendName() const override
204 return m_pBackend->getRenderBackendName();
207 #if ENABLE_CAIRO_CANVAS
208 virtual bool SupportsCairo() const override;
209 virtual cairo::SurfaceSharedPtr
210 CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
211 virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y,
212 int width, int height) const override;
213 virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice,
214 const BitmapSystemData& rData,
215 const Size& rSize) const override;
216 virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface,
217 const basegfx::B2ISize& rSize) const override;
218 #endif // ENABLE_CAIRO_CANVAS
220 // GDI
222 virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override;
224 // Text rendering + font support
226 virtual void SetTextColor(Color nColor) override;
227 virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
228 virtual void GetFontMetric(FontMetricDataRef&, int nFallbackLevel) override;
229 virtual FontCharMapRef GetFontCharMap() const override;
230 virtual bool GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const override;
231 virtual void GetDevFontList(vcl::font::PhysicalFontCollection*) override;
232 virtual void ClearDevFontCache() override;
233 virtual bool AddTempDevFont(vcl::font::PhysicalFontCollection*, const OUString& rFileURL,
234 const OUString& rFontName) override;
236 virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override;
237 virtual void DrawTextLayout(const GenericSalLayout&) override;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */