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