/src/qt/qtbase/src/gui/painting/qemulationpaintengine.cpp
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | |
4 | | #include <private/qemulationpaintengine_p.h> |
5 | | #include <private/qpainter_p.h> |
6 | | #include <private/qtextengine_p.h> |
7 | | #include <qdebug.h> |
8 | | |
9 | | QT_BEGIN_NAMESPACE |
10 | | |
11 | | QEmulationPaintEngine::QEmulationPaintEngine(QPaintEngineEx *engine) |
12 | 2.47k | : real_engine(engine) |
13 | 2.47k | { |
14 | 2.47k | QPaintEngine::state = real_engine->state(); |
15 | 2.47k | } |
16 | | |
17 | | |
18 | | QPaintEngine::Type QEmulationPaintEngine::type() const |
19 | 0 | { |
20 | 0 | return real_engine->type(); |
21 | 0 | } |
22 | | |
23 | | bool QEmulationPaintEngine::begin(QPaintDevice *) |
24 | 0 | { |
25 | 0 | return true; |
26 | 0 | } |
27 | | |
28 | | bool QEmulationPaintEngine::end() |
29 | 0 | { |
30 | 0 | return true; |
31 | 0 | } |
32 | | |
33 | | |
34 | | QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const |
35 | 528 | { |
36 | 528 | return real_engine->createState(orig); |
37 | 528 | } |
38 | | |
39 | | static inline void combineXForm(QBrush *brush, const QRectF &r) |
40 | 58.5k | { |
41 | 58.5k | QTransform t(r.width(), 0, 0, r.height(), r.x(), r.y()); |
42 | 58.5k | if (brush->gradient() && brush->gradient()->coordinateMode() != QGradient::ObjectMode) |
43 | 0 | brush->setTransform(t * brush->transform()); // compat mode |
44 | 58.5k | else |
45 | 58.5k | brush->setTransform(brush->transform() * t); |
46 | 58.5k | } |
47 | | |
48 | | void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush) |
49 | 42.4k | { |
50 | 42.4k | QPainterState *s = state(); |
51 | | |
52 | 42.4k | if (s->bgMode == Qt::OpaqueMode) { |
53 | 0 | Qt::BrushStyle style = brush.style(); |
54 | 0 | if ((style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern) || (style == Qt::TexturePattern )) |
55 | 0 | real_engine->fill(path, s->bgBrush); |
56 | 0 | } |
57 | | |
58 | 42.4k | Qt::BrushStyle style = qbrush_style(brush); |
59 | 42.4k | if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { |
60 | 165 | QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode(); |
61 | 165 | if (coMode > QGradient::LogicalMode) { |
62 | 165 | QBrush copy = brush; |
63 | 165 | const QPaintDevice *d = real_engine->painter()->device(); |
64 | 165 | QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect(); |
65 | 165 | combineXForm(©, r); |
66 | 165 | real_engine->fill(path, copy); |
67 | 165 | return; |
68 | 165 | } |
69 | 42.3k | } else if (style == Qt::TexturePattern) { |
70 | 0 | qreal dpr = qHasPixmapTexture(brush) ? brush.texture().devicePixelRatio() : brush.textureImage().devicePixelRatio(); |
71 | 0 | if (!qFuzzyCompare(dpr, qreal(1.0))) { |
72 | 0 | QBrush copy = brush; |
73 | 0 | combineXForm(©, QRectF(0, 0, 1.0/dpr, 1.0/dpr)); |
74 | 0 | real_engine->fill(path, copy); |
75 | 0 | return; |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | 42.3k | real_engine->fill(path, brush); |
80 | 42.3k | } |
81 | | |
82 | | void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) |
83 | 44.6k | { |
84 | 44.6k | QPainterState *s = state(); |
85 | | |
86 | 44.6k | if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) { |
87 | 0 | QPen bgPen = pen; |
88 | 0 | bgPen.setBrush(s->bgBrush); |
89 | 0 | bgPen.setStyle(Qt::SolidLine); |
90 | 0 | real_engine->stroke(path, bgPen); |
91 | 0 | } |
92 | | |
93 | 44.6k | QBrush brush = pen.brush(); |
94 | 44.6k | QPen copy = pen; |
95 | 44.6k | Qt::BrushStyle style = qbrush_style(brush); |
96 | 44.6k | if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern ) { |
97 | 43.5k | QGradient::CoordinateMode coMode = brush.gradient()->coordinateMode(); |
98 | 43.5k | if (coMode > QGradient::LogicalMode) { |
99 | 43.5k | const QPaintDevice *d = real_engine->painter()->device(); |
100 | 43.5k | QRectF r = (coMode == QGradient::StretchToDeviceMode) ? QRectF(0, 0, d->width(), d->height()) : path.controlPointRect(); |
101 | 43.5k | combineXForm(&brush, r); |
102 | 43.5k | copy.setBrush(brush); |
103 | 43.5k | real_engine->stroke(path, copy); |
104 | 43.5k | return; |
105 | 43.5k | } |
106 | 43.5k | } |
107 | | |
108 | 1.16k | real_engine->stroke(path, pen); |
109 | 1.16k | } |
110 | | |
111 | | void QEmulationPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) |
112 | 490 | { |
113 | 490 | real_engine->clip(path, op); |
114 | 490 | } |
115 | | |
116 | | void QEmulationPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) |
117 | 0 | { |
118 | 0 | if (state()->bgMode == Qt::OpaqueMode && pm.isQBitmap()) |
119 | 0 | fillBGRect(r); |
120 | 0 | real_engine->drawPixmap(r, pm, sr); |
121 | 0 | } |
122 | | |
123 | | void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) |
124 | 14.8k | { |
125 | 14.8k | if (state()->bgMode == Qt::OpaqueMode) { |
126 | 0 | const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); |
127 | 0 | QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent).toReal()); |
128 | 0 | fillBGRect(rect); |
129 | 0 | } |
130 | | |
131 | 14.8k | QPainterState *s = state(); |
132 | 14.8k | Qt::BrushStyle style = qbrush_style(s->pen.brush()); |
133 | 14.8k | if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) |
134 | 14.8k | { |
135 | 14.8k | QPen savedPen = s->pen; |
136 | 14.8k | QGradient g = *s->pen.brush().gradient(); |
137 | | |
138 | 14.8k | if (g.coordinateMode() > QGradient::LogicalMode) { |
139 | 14.8k | QBrush copy = s->pen.brush(); |
140 | 14.8k | const QPaintDevice *d = real_engine->painter()->device(); |
141 | 14.8k | const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); |
142 | 14.8k | QRectF r = (g.coordinateMode() == QGradient::StretchToDeviceMode) ? |
143 | 0 | QRectF(0, 0, d->width(), d->height()) : |
144 | 14.8k | QRectF(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); |
145 | 14.8k | combineXForm(©, r); |
146 | 14.8k | g.setCoordinateMode(QGradient::LogicalMode); |
147 | 14.8k | QBrush brush(g); |
148 | 14.8k | brush.setTransform(copy.transform()); |
149 | 14.8k | s->pen.setBrush(brush); |
150 | 14.8k | penChanged(); |
151 | 14.8k | real_engine->drawTextItem(p, textItem); |
152 | 14.8k | s->pen = savedPen; |
153 | 14.8k | penChanged(); |
154 | 14.8k | return; |
155 | 14.8k | } |
156 | 14.8k | } |
157 | | |
158 | 0 | real_engine->drawTextItem(p, textItem); |
159 | 0 | } |
160 | | |
161 | | void QEmulationPaintEngine::drawStaticTextItem(QStaticTextItem *item) |
162 | 0 | { |
163 | 0 | real_engine->drawStaticTextItem(item); |
164 | 0 | } |
165 | | |
166 | | void QEmulationPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) |
167 | 0 | { |
168 | 0 | if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) |
169 | 0 | fillBGRect(r); |
170 | 0 | real_engine->drawTiledPixmap(r, pixmap, s); |
171 | 0 | } |
172 | | |
173 | | void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags) |
174 | 0 | { |
175 | 0 | real_engine->drawImage(r, pm, sr, flags); |
176 | 0 | } |
177 | | |
178 | | void QEmulationPaintEngine::clipEnabledChanged() |
179 | 0 | { |
180 | 0 | real_engine->clipEnabledChanged(); |
181 | 0 | } |
182 | | |
183 | | void QEmulationPaintEngine::penChanged() |
184 | 144k | { |
185 | 144k | real_engine->penChanged(); |
186 | 144k | } |
187 | | |
188 | | void QEmulationPaintEngine::brushChanged() |
189 | 25.2k | { |
190 | 25.2k | real_engine->brushChanged(); |
191 | 25.2k | } |
192 | | |
193 | | void QEmulationPaintEngine::brushOriginChanged() |
194 | 0 | { |
195 | 0 | real_engine->brushOriginChanged(); |
196 | 0 | } |
197 | | |
198 | | void QEmulationPaintEngine::opacityChanged() |
199 | 424 | { |
200 | 424 | real_engine->opacityChanged(); |
201 | 424 | } |
202 | | |
203 | | void QEmulationPaintEngine::compositionModeChanged() |
204 | 0 | { |
205 | 0 | real_engine->compositionModeChanged(); |
206 | 0 | } |
207 | | |
208 | | void QEmulationPaintEngine::renderHintsChanged() |
209 | 0 | { |
210 | 0 | real_engine->renderHintsChanged(); |
211 | 0 | } |
212 | | |
213 | | void QEmulationPaintEngine::transformChanged() |
214 | 451k | { |
215 | 451k | real_engine->transformChanged(); |
216 | 451k | } |
217 | | |
218 | | void QEmulationPaintEngine::setState(QPainterState *s) |
219 | 102k | { |
220 | 102k | QPaintEngine::state = s; |
221 | 102k | real_engine->setState(s); |
222 | 102k | } |
223 | | |
224 | | void QEmulationPaintEngine::beginNativePainting() |
225 | 0 | { |
226 | 0 | real_engine->beginNativePainting(); |
227 | 0 | } |
228 | | |
229 | | void QEmulationPaintEngine::endNativePainting() |
230 | 0 | { |
231 | 0 | real_engine->endNativePainting(); |
232 | 0 | } |
233 | | |
234 | | void QEmulationPaintEngine::fillBGRect(const QRectF &r) |
235 | 0 | { |
236 | 0 | qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(), |
237 | 0 | r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() }; |
238 | 0 | QVectorPath vp(pts, 4, nullptr, QVectorPath::RectangleHint); |
239 | 0 | real_engine->fill(vp, state()->bgBrush); |
240 | 0 | } |
241 | | |
242 | | QT_END_NAMESPACE |