[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[651] | 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "private/qpaintengine_p.h"
|
---|
| 43 | #include "private/qpainter_p.h"
|
---|
| 44 | #include "private/qpicture_p.h"
|
---|
| 45 | #include "private/qfont_p.h"
|
---|
| 46 |
|
---|
| 47 | #ifndef QT_NO_PICTURE
|
---|
| 48 |
|
---|
| 49 | #include "qbuffer.h"
|
---|
| 50 | #include "qbytearray.h"
|
---|
| 51 | #include "qdatastream.h"
|
---|
| 52 | #include "qmath.h"
|
---|
| 53 | #include "qpaintengine_pic_p.h"
|
---|
| 54 | #include "qpicture.h"
|
---|
| 55 | #include "qpolygon.h"
|
---|
| 56 | #include "qrect.h"
|
---|
| 57 | #include <private/qtextengine_p.h>
|
---|
| 58 |
|
---|
| 59 | //#define QT_PICTURE_DEBUG
|
---|
| 60 | #include <qdebug.h>
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | QT_BEGIN_NAMESPACE
|
---|
| 64 |
|
---|
| 65 | class QPicturePaintEnginePrivate : public QPaintEnginePrivate
|
---|
| 66 | {
|
---|
| 67 | Q_DECLARE_PUBLIC(QPicturePaintEngine)
|
---|
| 68 | public:
|
---|
| 69 | QDataStream s;
|
---|
| 70 | QPainter *pt;
|
---|
| 71 | QPicturePrivate *pic_d;
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | QPicturePaintEngine::QPicturePaintEngine()
|
---|
| 75 | : QPaintEngine(*(new QPicturePaintEnginePrivate), AllFeatures)
|
---|
| 76 | {
|
---|
| 77 | Q_D(QPicturePaintEngine);
|
---|
| 78 | d->pt = 0;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | QPicturePaintEngine::QPicturePaintEngine(QPaintEnginePrivate &dptr)
|
---|
| 82 | : QPaintEngine(dptr, AllFeatures)
|
---|
| 83 | {
|
---|
| 84 | Q_D(QPicturePaintEngine);
|
---|
| 85 | d->pt = 0;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | QPicturePaintEngine::~QPicturePaintEngine()
|
---|
| 89 | {
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | bool QPicturePaintEngine::begin(QPaintDevice *pd)
|
---|
| 93 | {
|
---|
| 94 | Q_D(QPicturePaintEngine);
|
---|
| 95 | #ifdef QT_PICTURE_DEBUG
|
---|
| 96 | qDebug() << "QPicturePaintEngine::begin()";
|
---|
| 97 | #endif
|
---|
| 98 | Q_ASSERT(pd);
|
---|
| 99 | QPicture *pic = static_cast<QPicture *>(pd);
|
---|
| 100 |
|
---|
| 101 | d->pdev = pd;
|
---|
| 102 | d->pic_d = pic->d_func();
|
---|
| 103 | Q_ASSERT(d->pic_d);
|
---|
| 104 |
|
---|
| 105 | d->s.setDevice(&d->pic_d->pictb);
|
---|
| 106 | d->s.setVersion(d->pic_d->formatMajor);
|
---|
| 107 |
|
---|
| 108 | d->pic_d->pictb.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
---|
| 109 | d->s.writeRawData(qt_mfhdr_tag, 4);
|
---|
| 110 | d->s << (quint16) 0 << (quint16) d->pic_d->formatMajor << (quint16) d->pic_d->formatMinor;
|
---|
| 111 | d->s << (quint8) QPicturePrivate::PdcBegin << (quint8) sizeof(qint32);
|
---|
| 112 | d->pic_d->brect = QRect();
|
---|
| 113 | if (d->pic_d->formatMajor >= 4) {
|
---|
| 114 | QRect r = pic->boundingRect();
|
---|
| 115 | d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width()
|
---|
| 116 | << (qint32) r.height();
|
---|
| 117 | }
|
---|
| 118 | d->pic_d->trecs = 0;
|
---|
| 119 | d->s << (quint32)d->pic_d->trecs; // total number of records
|
---|
| 120 | d->pic_d->formatOk = false;
|
---|
| 121 | setActive(true);
|
---|
| 122 | return true;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | bool QPicturePaintEngine::end()
|
---|
| 126 | {
|
---|
| 127 | Q_D(QPicturePaintEngine);
|
---|
| 128 | #ifdef QT_PICTURE_DEBUG
|
---|
| 129 | qDebug() << "QPicturePaintEngine::end()";
|
---|
| 130 | #endif
|
---|
| 131 | d->pic_d->trecs++;
|
---|
| 132 | d->s << (quint8) QPicturePrivate::PdcEnd << (quint8) 0;
|
---|
| 133 | int cs_start = sizeof(quint32); // pos of checksum word
|
---|
| 134 | int data_start = cs_start + sizeof(quint16);
|
---|
| 135 | int brect_start = data_start + 2*sizeof(qint16) + 2*sizeof(quint8);
|
---|
| 136 | int pos = d->pic_d->pictb.pos();
|
---|
| 137 | d->pic_d->pictb.seek(brect_start);
|
---|
| 138 | if (d->pic_d->formatMajor >= 4) { // bounding rectangle
|
---|
| 139 | QRect r = static_cast<QPicture *>(d->pdev)->boundingRect();
|
---|
| 140 | d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width()
|
---|
| 141 | << (qint32) r.height();
|
---|
| 142 | }
|
---|
| 143 | d->s << (quint32) d->pic_d->trecs; // write number of records
|
---|
| 144 | d->pic_d->pictb.seek(cs_start);
|
---|
| 145 | QByteArray buf = d->pic_d->pictb.buffer();
|
---|
| 146 | quint16 cs = (quint16) qChecksum(buf.constData() + data_start, pos - data_start);
|
---|
| 147 | d->s << cs; // write checksum
|
---|
| 148 | d->pic_d->pictb.close();
|
---|
| 149 | setActive(false);
|
---|
| 150 | return true;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | #define SERIALIZE_CMD(c) \
|
---|
| 154 | d->pic_d->trecs++; \
|
---|
| 155 | d->s << (quint8) c; \
|
---|
| 156 | d->s << (quint8) 0; \
|
---|
| 157 | pos = d->pic_d->pictb.pos()
|
---|
| 158 |
|
---|
| 159 | void QPicturePaintEngine::updatePen(const QPen &pen)
|
---|
| 160 | {
|
---|
| 161 | Q_D(QPicturePaintEngine);
|
---|
| 162 | #ifdef QT_PICTURE_DEBUG
|
---|
| 163 | qDebug() << " -> updatePen(): width:" << pen.width() << "style:"
|
---|
| 164 | << pen.style() << "color:" << pen.color();
|
---|
| 165 | #endif
|
---|
| 166 | int pos;
|
---|
| 167 | SERIALIZE_CMD(QPicturePrivate::PdcSetPen);
|
---|
| 168 | if (d->pic_d->in_memory_only) {
|
---|
| 169 | int index = d->pic_d->pen_list.size();
|
---|
| 170 | d->pic_d->pen_list.append(pen);
|
---|
| 171 | d->s << index;
|
---|
| 172 | } else {
|
---|
| 173 | d->s << pen;
|
---|
| 174 | }
|
---|
| 175 | writeCmdLength(pos, QRect(), false);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void QPicturePaintEngine::updateCompositionMode(QPainter::CompositionMode cmode)
|
---|
| 179 | {
|
---|
| 180 | Q_D(QPicturePaintEngine);
|
---|
| 181 | #ifdef QT_PICTURE_DEBUG
|
---|
| 182 | qDebug() << " -> updateCompositionMode():" << cmode;
|
---|
| 183 | #endif
|
---|
| 184 | int pos;
|
---|
| 185 | SERIALIZE_CMD(QPicturePrivate::PdcSetCompositionMode);
|
---|
| 186 | d->s << (qint32)cmode;
|
---|
| 187 | writeCmdLength(pos, QRectF(), false);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | void QPicturePaintEngine::updateClipEnabled(bool enabled)
|
---|
| 191 | {
|
---|
| 192 | Q_D(QPicturePaintEngine);
|
---|
| 193 | #ifdef QT_PICTURE_DEBUG
|
---|
| 194 | qDebug() << " -> updateClipEnabled():" << enabled;
|
---|
| 195 | #endif
|
---|
| 196 | int pos;
|
---|
| 197 | SERIALIZE_CMD(QPicturePrivate::PdcSetClipEnabled);
|
---|
| 198 | d->s << enabled;
|
---|
| 199 | writeCmdLength(pos, QRectF(), false);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | void QPicturePaintEngine::updateOpacity(qreal opacity)
|
---|
| 203 | {
|
---|
| 204 | Q_D(QPicturePaintEngine);
|
---|
| 205 | #ifdef QT_PICTURE_DEBUG
|
---|
| 206 | qDebug() << " -> updateOpacity():" << opacity;
|
---|
| 207 | #endif
|
---|
| 208 | int pos;
|
---|
| 209 | SERIALIZE_CMD(QPicturePrivate::PdcSetOpacity);
|
---|
| 210 | d->s << double(opacity);
|
---|
| 211 | writeCmdLength(pos, QRectF(), false);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void QPicturePaintEngine::updateBrush(const QBrush &brush)
|
---|
| 215 | {
|
---|
| 216 | Q_D(QPicturePaintEngine);
|
---|
| |
---|