Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/kernel/qpaintengine_alpha.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include <qglobal.h> | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #ifndef QT_NO_PRINTER | - | ||||||||||||||||||
37 | #include <qdebug.h> | - | ||||||||||||||||||
38 | #include "private/qpaintengine_alpha_p.h" | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "private/qpainter_p.h" | - | ||||||||||||||||||
41 | #include "private/qpicture_p.h" | - | ||||||||||||||||||
42 | #include "private/qfont_p.h" | - | ||||||||||||||||||
43 | #include "QtGui/qpicture.h" | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | QAlphaPaintEngine::QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps) | - | ||||||||||||||||||
48 | : QPaintEngine(data, devcaps) | - | ||||||||||||||||||
49 | { | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | } never executed: end of block | 0 | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | QAlphaPaintEngine::~QAlphaPaintEngine() | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | bool QAlphaPaintEngine::begin(QPaintDevice *pdev) | - | ||||||||||||||||||
59 | { | - | ||||||||||||||||||
60 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | d->m_continueCall = true; | - | ||||||||||||||||||
63 | if (d->m_pass != 0) {
| 0 | ||||||||||||||||||
64 | return true; never executed: return true; | 0 | ||||||||||||||||||
65 | } | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | d->m_savedcaps = gccaps; | - | ||||||||||||||||||
68 | d->m_pdev = pdev; | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | d->m_alphaPen = false; | - | ||||||||||||||||||
71 | d->m_alphaBrush = false; | - | ||||||||||||||||||
72 | d->m_alphaOpacity = false; | - | ||||||||||||||||||
73 | d->m_hasalpha = false; | - | ||||||||||||||||||
74 | d->m_advancedPen = false; | - | ||||||||||||||||||
75 | d->m_advancedBrush = false; | - | ||||||||||||||||||
76 | d->m_complexTransform = false; | - | ||||||||||||||||||
77 | d->m_emulateProjectiveTransforms = false; | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | // clear alpha region | - | ||||||||||||||||||
80 | d->m_alphargn = QRegion(); | - | ||||||||||||||||||
81 | d->m_cliprgn = QRegion(); | - | ||||||||||||||||||
82 | d->m_pen = QPen(); | - | ||||||||||||||||||
83 | d->m_transform = QTransform(); | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | flushAndInit(); | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | return true; never executed: return true; | 0 | ||||||||||||||||||
88 | } | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | bool QAlphaPaintEngine::end() | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | d->m_continueCall = true; | - | ||||||||||||||||||
95 | if (d->m_pass != 0) {
| 0 | ||||||||||||||||||
96 | return true; never executed: return true; | 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | flushAndInit(false); | - | ||||||||||||||||||
100 | return true; never executed: return true; | 0 | ||||||||||||||||||
101 | } | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | void QAlphaPaintEngine::updateState(const QPaintEngineState &state) | - | ||||||||||||||||||
104 | { | - | ||||||||||||||||||
105 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | DirtyFlags flags = state.state(); | - | ||||||||||||||||||
108 | if (flags & QPaintEngine::DirtyTransform) {
| 0 | ||||||||||||||||||
109 | d->m_transform = state.transform(); | - | ||||||||||||||||||
110 | d->m_complexTransform = (d->m_transform.type() > QTransform::TxScale); | - | ||||||||||||||||||
111 | d->m_emulateProjectiveTransforms = !(d->m_savedcaps & QPaintEngine::PerspectiveTransform)
| 0 | ||||||||||||||||||
112 | && !(d->m_savedcaps & QPaintEngine::AlphaBlend)
| 0 | ||||||||||||||||||
113 | && (d->m_transform.type() >= QTransform::TxProject);
| 0 | ||||||||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||||||||
115 | if (flags & QPaintEngine::DirtyPen) {
| 0 | ||||||||||||||||||
116 | d->m_pen = state.pen(); | - | ||||||||||||||||||
117 | if (d->m_pen.style() == Qt::NoPen) {
| 0 | ||||||||||||||||||
118 | d->m_advancedPen = false; | - | ||||||||||||||||||
119 | d->m_alphaPen = false; | - | ||||||||||||||||||
120 | } else { never executed: end of block | 0 | ||||||||||||||||||
121 | d->m_advancedPen = (d->m_pen.brush().style() != Qt::SolidPattern); | - | ||||||||||||||||||
122 | d->m_alphaPen = !d->m_pen.brush().isOpaque(); | - | ||||||||||||||||||
123 | } never executed: end of block | 0 | ||||||||||||||||||
124 | } | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | if (d->m_pass != 0) {
| 0 | ||||||||||||||||||
127 | d->m_continueCall = true; | - | ||||||||||||||||||
128 | return; never executed: return; | 0 | ||||||||||||||||||
129 | } | - | ||||||||||||||||||
130 | d->m_continueCall = false; | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | if (flags & QPaintEngine::DirtyOpacity) {
| 0 | ||||||||||||||||||
133 | d->m_alphaOpacity = (state.opacity() != 1.0f); | - | ||||||||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | if (flags & QPaintEngine::DirtyBrush) {
| 0 | ||||||||||||||||||
137 | if (state.brush().style() == Qt::NoBrush) {
| 0 | ||||||||||||||||||
138 | d->m_advancedBrush = false; | - | ||||||||||||||||||
139 | d->m_alphaBrush = false; | - | ||||||||||||||||||
140 | } else { never executed: end of block | 0 | ||||||||||||||||||
141 | d->m_advancedBrush = (state.brush().style() != Qt::SolidPattern); | - | ||||||||||||||||||
142 | d->m_alphaBrush = !state.brush().isOpaque(); | - | ||||||||||||||||||
143 | } never executed: end of block | 0 | ||||||||||||||||||
144 | } | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | - | |||||||||||||||||||
147 | d->m_hasalpha = d->m_alphaOpacity || d->m_alphaBrush || d->m_alphaPen;
| 0 | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | if (d->m_picengine) {
| 0 | ||||||||||||||||||
150 | const QPainter *p = painter(); | - | ||||||||||||||||||
151 | d->m_picpainter->setPen(p->pen()); | - | ||||||||||||||||||
152 | d->m_picpainter->setBrush(p->brush()); | - | ||||||||||||||||||
153 | d->m_picpainter->setBrushOrigin(p->brushOrigin()); | - | ||||||||||||||||||
154 | d->m_picpainter->setFont(p->font()); | - | ||||||||||||||||||
155 | d->m_picpainter->setOpacity(p->opacity()); | - | ||||||||||||||||||
156 | d->m_picpainter->setTransform(p->combinedTransform()); | - | ||||||||||||||||||
157 | d->m_picengine->updateState(state); | - | ||||||||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||||||||
159 | } never executed: end of block | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | void QAlphaPaintEngine::drawPath(const QPainterPath &path) | - | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | QRectF tr = d->addPenWidth(path); | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | if (d->m_pass == 0) {
| 0 | ||||||||||||||||||
168 | d->m_continueCall = false; | - | ||||||||||||||||||
169 | if (d->canSeeTroughBackground(d->m_hasalpha, tr) || d->m_advancedPen || d->m_advancedBrush
| 0 | ||||||||||||||||||
170 | || d->m_emulateProjectiveTransforms)
| 0 | ||||||||||||||||||
171 | { | - | ||||||||||||||||||
172 | d->addAlphaRect(tr); | - | ||||||||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | d->addDirtyRect(tr); | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | if (d->m_picengine)
| 0 | ||||||||||||||||||
178 | d->m_picengine->drawPath(path); never executed: d->m_picengine->drawPath(path); | 0 | ||||||||||||||||||
179 | } else { never executed: end of block | 0 | ||||||||||||||||||
180 | d->m_continueCall = !d->fullyContained(tr); | - | ||||||||||||||||||
181 | } never executed: end of block | 0 | ||||||||||||||||||
182 | } | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) | - | ||||||||||||||||||
185 | { | - | ||||||||||||||||||
186 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | QPolygonF poly; | - | ||||||||||||||||||
189 | poly.reserve(pointCount); | - | ||||||||||||||||||
190 | for (int i = 0; i < pointCount; ++i)
| 0 | ||||||||||||||||||
191 | poly.append(points[i]); never executed: poly.append(points[i]); | 0 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | QPainterPath path; | - | ||||||||||||||||||
194 | path.addPolygon(poly); | - | ||||||||||||||||||
195 | QRectF tr = d->addPenWidth(path); | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | if (d->m_pass == 0) {
| 0 | ||||||||||||||||||
198 | d->m_continueCall = false; | - | ||||||||||||||||||
199 | if (d->canSeeTroughBackground(d->m_hasalpha, tr) || d->m_advancedPen || d->m_advancedBrush
| 0 | ||||||||||||||||||
200 | || d->m_emulateProjectiveTransforms)
| 0 | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | d->addAlphaRect(tr); | - | ||||||||||||||||||
203 | } never executed: end of block | 0 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | d->addDirtyRect(tr); | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | if (d->m_picengine)
| 0 | ||||||||||||||||||
208 | d->m_picengine->drawPolygon(points, pointCount, mode); never executed: d->m_picengine->drawPolygon(points, pointCount, mode); | 0 | ||||||||||||||||||
209 | } else { never executed: end of block | 0 | ||||||||||||||||||
210 | d->m_continueCall = !d->fullyContained(tr); | - | ||||||||||||||||||
211 | } never executed: end of block | 0 | ||||||||||||||||||
212 | } | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) | - | ||||||||||||||||||
215 | { | - | ||||||||||||||||||
216 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | QRectF tr = d->m_transform.mapRect(r); | - | ||||||||||||||||||
219 | if (d->m_pass == 0) {
| 0 | ||||||||||||||||||
220 | d->m_continueCall = false; | - | ||||||||||||||||||
221 | if (d->canSeeTroughBackground(pm.hasAlpha() || d->m_alphaOpacity, tr) || d->m_complexTransform || pm.isQBitmap()) {
| 0 | ||||||||||||||||||
222 | d->addAlphaRect(tr); | - | ||||||||||||||||||
223 | } never executed: end of block | 0 | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | d->addDirtyRect(tr); | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | if (d->m_picengine)
| 0 | ||||||||||||||||||
228 | d->m_picengine->drawPixmap(r, pm, sr); never executed: d->m_picengine->drawPixmap(r, pm, sr); | 0 | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | } else { never executed: end of block | 0 | ||||||||||||||||||
231 | d->m_continueCall = !d->fullyContained(tr); | - | ||||||||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||||||||
233 | } | - | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | void QAlphaPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) | - | ||||||||||||||||||
236 | { | - | ||||||||||||||||||
237 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | QRectF tr(p.x(), p.y() - textItem.ascent(), textItem.width() + 5, textItem.ascent() + textItem.descent() + 5); | - | ||||||||||||||||||
240 | tr = d->m_transform.mapRect(tr); | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | if (d->m_pass == 0) {
| 0 | ||||||||||||||||||
243 | d->m_continueCall = false; | - | ||||||||||||||||||
244 | if (d->canSeeTroughBackground(d->m_alphaPen || d->m_alphaOpacity, tr) || d->m_advancedPen) {
| 0 | ||||||||||||||||||
245 | d->addAlphaRect(tr); | - | ||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | d->addDirtyRect(tr); | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | if (d->m_picengine) {
| 0 | ||||||||||||||||||
251 | d->m_picengine->drawTextItem(p, textItem); | - | ||||||||||||||||||
252 | } never executed: end of block | 0 | ||||||||||||||||||
253 | } else { never executed: end of block | 0 | ||||||||||||||||||
254 | d->m_continueCall = !d->fullyContained(tr); | - | ||||||||||||||||||
255 | } never executed: end of block | 0 | ||||||||||||||||||
256 | } | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | void QAlphaPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) | - | ||||||||||||||||||
259 | { | - | ||||||||||||||||||
260 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | QRectF brect = d->m_transform.mapRect(r); | - | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | if (d->m_pass == 0) {
| 0 | ||||||||||||||||||
265 | d->m_continueCall = false; | - | ||||||||||||||||||
266 | if (d->canSeeTroughBackground(pixmap.hasAlpha() || d->m_alphaOpacity, brect) || d->m_complexTransform || pixmap.isQBitmap()) {
| 0 | ||||||||||||||||||
267 | d->addAlphaRect(brect); | - | ||||||||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | d->addDirtyRect(brect); | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | if (d->m_picengine)
| 0 | ||||||||||||||||||
273 | d->m_picengine->drawTiledPixmap(r, pixmap, s); never executed: d->m_picengine->drawTiledPixmap(r, pixmap, s); | 0 | ||||||||||||||||||
274 | } else { never executed: end of block | 0 | ||||||||||||||||||
275 | d->m_continueCall = !d->fullyContained(brect); | - | ||||||||||||||||||
276 | } never executed: end of block | 0 | ||||||||||||||||||
277 | } | - | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | QRegion QAlphaPaintEngine::alphaClipping() const | - | ||||||||||||||||||
280 | { | - | ||||||||||||||||||
281 | Q_D(const QAlphaPaintEngine); | - | ||||||||||||||||||
282 | return d->m_cliprgn; never executed: return d->m_cliprgn; | 0 | ||||||||||||||||||
283 | } | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | bool QAlphaPaintEngine::continueCall() const | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | Q_D(const QAlphaPaintEngine); | - | ||||||||||||||||||
288 | return d->m_continueCall; never executed: return d->m_continueCall; | 0 | ||||||||||||||||||
289 | } | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | void QAlphaPaintEngine::flushAndInit(bool init) | - | ||||||||||||||||||
292 | { | - | ||||||||||||||||||
293 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
294 | Q_ASSERT(d->m_pass == 0); | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | if (d->m_pic) {
| 0 | ||||||||||||||||||
297 | d->m_picpainter->end(); | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | // set clip region | - | ||||||||||||||||||
300 | d->m_alphargn = d->m_alphargn.intersected(QRect(0, 0, d->m_pdev->width(), d->m_pdev->height())); | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | // just use the bounding rect if it's a complex region.. | - | ||||||||||||||||||
303 | QVector<QRect> rects = d->m_alphargn.rects(); | - | ||||||||||||||||||
304 | if (rects.size() > 10) {
| 0 | ||||||||||||||||||
305 | QRect br = d->m_alphargn.boundingRect(); | - | ||||||||||||||||||
306 | d->m_alphargn = QRegion(br); | - | ||||||||||||||||||
307 | rects.clear(); | - | ||||||||||||||||||
308 | rects.append(br); | - | ||||||||||||||||||
309 | } never executed: end of block | 0 | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | d->m_cliprgn = d->m_alphargn; | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | // now replay the QPicture | - | ||||||||||||||||||
314 | ++d->m_pass; // we are now doing pass #2 | - | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | // reset states | - | ||||||||||||||||||
317 | gccaps = d->m_savedcaps; | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | painter()->save(); | - | ||||||||||||||||||
320 | d->resetState(painter()); | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | // make sure the output from QPicture is unscaled | - | ||||||||||||||||||
323 | QTransform mtx; | - | ||||||||||||||||||
324 | mtx.scale(1.0f / (qreal(d->m_pdev->logicalDpiX()) / qreal(qt_defaultDpiX())), | - | ||||||||||||||||||
325 | 1.0f / (qreal(d->m_pdev->logicalDpiY()) / qreal(qt_defaultDpiY()))); | - | ||||||||||||||||||
326 | painter()->setTransform(mtx); | - | ||||||||||||||||||
327 | painter()->drawPicture(0, 0, *d->m_pic); | - | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | d->m_cliprgn = QRegion(); | - | ||||||||||||||||||
330 | d->resetState(painter()); | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | // fill in the alpha images | - | ||||||||||||||||||
333 | for (int i=0; i<rects.size(); ++i)
| 0 | ||||||||||||||||||
334 | d->drawAlphaImage(rects.at(i)); never executed: d->drawAlphaImage(rects.at(i)); | 0 | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | d->m_alphargn = QRegion(); | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | painter()->restore(); | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | --d->m_pass; // pass #2 finished | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | cleanUp(); | - | ||||||||||||||||||
343 | } never executed: end of block | 0 | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | if (init) {
| 0 | ||||||||||||||||||
346 | gccaps = PaintEngineFeatures(AllFeatures & ~QPaintEngine::ObjectBoundingModeGradients); | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | d->m_pic = new QPicture(); | - | ||||||||||||||||||
349 | d->m_pic->d_ptr->in_memory_only = true; | - | ||||||||||||||||||
350 | d->m_picpainter = new QPainter(d->m_pic); | - | ||||||||||||||||||
351 | d->m_picengine = d->m_picpainter->paintEngine(); | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | // When newPage() is called and the m_picpainter is recreated | - | ||||||||||||||||||
354 | // we have to copy the current state of the original printer | - | ||||||||||||||||||
355 | // painter back to the m_picpainter | - | ||||||||||||||||||
356 | d->m_picpainter->setPen(painter()->pen()); | - | ||||||||||||||||||
357 | d->m_picpainter->setBrush(painter()->brush()); | - | ||||||||||||||||||
358 | d->m_picpainter->setBrushOrigin(painter()->brushOrigin()); | - | ||||||||||||||||||
359 | d->m_picpainter->setFont(painter()->font()); | - | ||||||||||||||||||
360 | d->m_picpainter->setOpacity(painter()->opacity()); | - | ||||||||||||||||||
361 | d->m_picpainter->setTransform(painter()->combinedTransform()); | - | ||||||||||||||||||
362 | d->m_picengine->syncState(); | - | ||||||||||||||||||
363 | QPainterState &state = *d->m_picpainter->d_func()->state; | - | ||||||||||||||||||
364 | QPainter *oldPainter = state.painter; | - | ||||||||||||||||||
365 | state = *painter()->d_func()->state; | - | ||||||||||||||||||
366 | state.painter = oldPainter; | - | ||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||
368 | } never executed: end of block | 0 | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | void QAlphaPaintEngine::cleanUp() | - | ||||||||||||||||||
371 | { | - | ||||||||||||||||||
372 | Q_D(QAlphaPaintEngine); | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | delete d->m_picpainter; | - | ||||||||||||||||||
375 | delete d->m_pic; | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | d->m_picpainter = 0; | - | ||||||||||||||||||
378 | d->m_pic = 0; | - | ||||||||||||||||||
379 | d->m_picengine = 0; | - | ||||||||||||||||||
380 | } never executed: end of block | 0 | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | QAlphaPaintEnginePrivate::QAlphaPaintEnginePrivate() | - | ||||||||||||||||||
383 | : m_pass(0), | - | ||||||||||||||||||
384 | m_pic(0), | - | ||||||||||||||||||
385 | m_picengine(0), | - | ||||||||||||||||||
386 | m_picpainter(0), | - | ||||||||||||||||||
387 | m_numberOfCachedRects(0), | - | ||||||||||||||||||
388 | m_hasalpha(false), | - | ||||||||||||||||||
389 | m_alphaPen(false), | - | ||||||||||||||||||
390 | m_alphaBrush(false), | - | ||||||||||||||||||
391 | m_alphaOpacity(false), | - | ||||||||||||||||||
392 | m_advancedPen(false), | - | ||||||||||||||||||
393 | m_advancedBrush(false), | - | ||||||||||||||||||
394 | m_complexTransform(false) | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | } never executed: end of block | 0 | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | QAlphaPaintEnginePrivate::~QAlphaPaintEnginePrivate() | - | ||||||||||||||||||
400 | { | - | ||||||||||||||||||
401 | delete m_picpainter; | - | ||||||||||||||||||
402 | delete m_pic; | - | ||||||||||||||||||
403 | } never executed: end of block | 0 | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path) | - | ||||||||||||||||||
406 | { | - | ||||||||||||||||||
407 | Q_Q(QAlphaPaintEngine); | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | QPainterPath tmp = path; | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | if (m_pen.style() == Qt::NoPen)
| 0 | ||||||||||||||||||
412 | return (path.controlPointRect() * m_transform).boundingRect(); never executed: return (path.controlPointRect() * m_transform).boundingRect(); | 0 | ||||||||||||||||||
413 | bool cosmetic = qt_pen_is_cosmetic(m_pen, q->state->renderHints()); | - | ||||||||||||||||||
414 | if (cosmetic)
| 0 | ||||||||||||||||||
415 | tmp = path * m_transform; never executed: tmp = path * m_transform; | 0 | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | QPainterPathStroker stroker; | - | ||||||||||||||||||
418 | if (m_pen.widthF() == 0.0f)
| 0 | ||||||||||||||||||
419 | stroker.setWidth(1.0); never executed: stroker.setWidth(1.0); | 0 | ||||||||||||||||||
420 | else | - | ||||||||||||||||||
421 | stroker.setWidth(m_pen.widthF()); never executed: stroker.setWidth(m_pen.widthF()); | 0 | ||||||||||||||||||
422 | stroker.setJoinStyle(m_pen.joinStyle()); | - | ||||||||||||||||||
423 | stroker.setCapStyle(m_pen.capStyle()); | - | ||||||||||||||||||
424 | tmp = stroker.createStroke(tmp); | - | ||||||||||||||||||
425 | if (cosmetic)
| 0 | ||||||||||||||||||
426 | return tmp.controlPointRect(); never executed: return tmp.controlPointRect(); | 0 | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | return (tmp.controlPointRect() * m_transform).boundingRect(); never executed: return (tmp.controlPointRect() * m_transform).boundingRect(); | 0 | ||||||||||||||||||
429 | } | - | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect) | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | m_alphargn |= rect.toAlignedRect(); | - | ||||||||||||||||||
434 | } never executed: end of block | 0 | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | bool QAlphaPaintEnginePrivate::canSeeTroughBackground(bool somethingInRectHasAlpha, const QRectF &rect) const | - | ||||||||||||||||||
437 | { | - | ||||||||||||||||||
438 | if (somethingInRectHasAlpha) {
| 0 | ||||||||||||||||||
439 | if (m_dirtyRects.count() != m_numberOfCachedRects) {
| 0 | ||||||||||||||||||
440 | m_cachedDirtyRgn.setRects(m_dirtyRects.constData(), m_dirtyRects.count()); | - | ||||||||||||||||||
441 | m_numberOfCachedRects = m_dirtyRects.count(); | - | ||||||||||||||||||
442 | } never executed: end of block | 0 | ||||||||||||||||||
443 | return m_cachedDirtyRgn.intersects(rect.toAlignedRect()); never executed: return m_cachedDirtyRgn.intersects(rect.toAlignedRect()); | 0 | ||||||||||||||||||
444 | } | - | ||||||||||||||||||
445 | return false; never executed: return false; | 0 | ||||||||||||||||||
446 | } | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect) | - | ||||||||||||||||||
449 | { | - | ||||||||||||||||||
450 | Q_Q(QAlphaPaintEngine); | - | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | qreal dpiX = qMax(m_pdev->logicalDpiX(), 300); | - | ||||||||||||||||||
453 | qreal dpiY = qMax(m_pdev->logicalDpiY(), 300); | - | ||||||||||||||||||
454 | qreal xscale = (dpiX / m_pdev->logicalDpiX()); | - | ||||||||||||||||||
455 | qreal yscale = (dpiY / m_pdev->logicalDpiY()); | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | QTransform picscale; | - | ||||||||||||||||||
458 | picscale.scale(xscale, yscale); | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | const int tileSize = 2048; | - | ||||||||||||||||||
461 | QSize size((int(rect.width() * xscale)), int(rect.height() * yscale)); | - | ||||||||||||||||||
462 | int divw = (size.width() / tileSize); | - | ||||||||||||||||||
463 | int divh = (size.height() / tileSize); | - | ||||||||||||||||||
464 | divw += 1; | - | ||||||||||||||||||
465 | divh += 1; | - | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | int incx = int(rect.width() / divw); | - | ||||||||||||||||||
468 | int incy = int(rect.height() / divh); | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | for (int y=0; y<divh; ++y) {
| 0 | ||||||||||||||||||
471 | int ypos = int((incy * y) + rect.y()); | - | ||||||||||||||||||
472 | int height = int((y == (divh - 1)) ? (rect.height() - (incy * y)) : incy) + 1; | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | for (int x=0; x<divw; ++x) {
| 0 | ||||||||||||||||||
475 | int xpos = int((incx * x) + rect.x()); | - | ||||||||||||||||||
476 | int width = int((x == (divw - 1)) ? (rect.width() - (incx * x)) : incx) + 1; | - | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | QSize imgsize((int)(width * xscale), (int)(height * yscale)); | - | ||||||||||||||||||
479 | QImage img(imgsize, QImage::Format_RGB32); | - | ||||||||||||||||||
480 | img.fill(0xffffffff); | - | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | QPainter imgpainter(&img); | - | ||||||||||||||||||
483 | imgpainter.setTransform(picscale); | - | ||||||||||||||||||
484 | QPointF picpos(qreal(-xpos), qreal(-ypos)); | - | ||||||||||||||||||
485 | imgpainter.drawPicture(picpos, *m_pic); | - | ||||||||||||||||||
486 | imgpainter.end(); | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | q->painter()->setTransform(QTransform()); | - | ||||||||||||||||||
489 | QRect r(xpos, ypos, width, height); | - | ||||||||||||||||||
490 | q->painter()->drawImage(r, img); | - | ||||||||||||||||||
491 | } never executed: end of block | 0 | ||||||||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||||||||
493 | } never executed: end of block | 0 | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | bool QAlphaPaintEnginePrivate::fullyContained(const QRectF &rect) const | - | ||||||||||||||||||
496 | { | - | ||||||||||||||||||
497 | QRegion r(rect.toAlignedRect()); | - | ||||||||||||||||||
498 | return (m_cliprgn.intersected(r) == r); never executed: return (m_cliprgn.intersected(r) == r); | 0 | ||||||||||||||||||
499 | } | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | void QAlphaPaintEnginePrivate::resetState(QPainter *p) | - | ||||||||||||||||||
502 | { | - | ||||||||||||||||||
503 | p->setPen(QPen()); | - | ||||||||||||||||||
504 | p->setBrush(QBrush()); | - | ||||||||||||||||||
505 | p->setBrushOrigin(0,0); | - | ||||||||||||||||||
506 | p->setBackground(QBrush()); | - | ||||||||||||||||||
507 | p->setFont(QFont()); | - | ||||||||||||||||||
508 | p->setTransform(QTransform()); | - | ||||||||||||||||||
509 | // The view transform is already recorded and included in the | - | ||||||||||||||||||
510 | // picture we're about to replay. If we don't turn if off, | - | ||||||||||||||||||
511 | // the view matrix will be applied twice. | - | ||||||||||||||||||
512 | p->setViewTransformEnabled(false); | - | ||||||||||||||||||
513 | p->setClipRegion(QRegion(), Qt::NoClip); | - | ||||||||||||||||||
514 | p->setClipPath(QPainterPath(), Qt::NoClip); | - | ||||||||||||||||||
515 | p->setClipping(false); | - | ||||||||||||||||||
516 | p->setOpacity(1.0f); | - | ||||||||||||||||||
517 | } never executed: end of block | 0 | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | - | |||||||||||||||||||
520 | QT_END_NAMESPACE | - | ||||||||||||||||||
521 | - | |||||||||||||||||||
522 | #endif // QT_NO_PRINTER | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |