Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpicture.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 "qpicture.h" | - | ||||||||||||||||||
35 | #include <private/qpicture_p.h> | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | #include <private/qfactoryloader_p.h> | - | ||||||||||||||||||
40 | #include <private/qpaintengine_pic_p.h> | - | ||||||||||||||||||
41 | #include <private/qfont_p.h> | - | ||||||||||||||||||
42 | #include <qguiapplication.h> | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #include "qdatastream.h" | - | ||||||||||||||||||
45 | #include "qfile.h" | - | ||||||||||||||||||
46 | #include "qimage.h" | - | ||||||||||||||||||
47 | #include "qmutex.h" | - | ||||||||||||||||||
48 | #include "qpainter.h" | - | ||||||||||||||||||
49 | #include "qpainterpath.h" | - | ||||||||||||||||||
50 | #include "qpixmap.h" | - | ||||||||||||||||||
51 | #include "qregion.h" | - | ||||||||||||||||||
52 | #include "qdebug.h" | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | #include <algorithm> | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | void qt_format_text(const QFont &fnt, const QRectF &_r, | - | ||||||||||||||||||
59 | int tf, const QTextOption *opt, const QString& str, QRectF *brect, | - | ||||||||||||||||||
60 | int tabstops, int *, int tabarraylen, | - | ||||||||||||||||||
61 | QPainter *painter); | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | /*! | - | ||||||||||||||||||
64 | \class QPicture | - | ||||||||||||||||||
65 | \brief The QPicture class is a paint device that records and | - | ||||||||||||||||||
66 | replays QPainter commands. | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | \inmodule QtGui | - | ||||||||||||||||||
69 | \ingroup shared | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | - | |||||||||||||||||||
72 | A picture serializes painter commands to an IO device in a | - | ||||||||||||||||||
73 | platform-independent format. They are sometimes referred to as meta-files. | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | Qt pictures use a proprietary binary format. Unlike native picture | - | ||||||||||||||||||
76 | (meta-file) formats on many window systems, Qt pictures have no | - | ||||||||||||||||||
77 | limitations regarding their contents. Everything that can be | - | ||||||||||||||||||
78 | painted on a widget or pixmap (e.g., fonts, pixmaps, regions, | - | ||||||||||||||||||
79 | transformed graphics, etc.) can also be stored in a picture. | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | QPicture is resolution independent, i.e. a QPicture can be | - | ||||||||||||||||||
82 | displayed on different devices (for example svg, pdf, ps, printer | - | ||||||||||||||||||
83 | and screen) looking the same. This is, for instance, needed for | - | ||||||||||||||||||
84 | WYSIWYG print preview. QPicture runs in the default system dpi, | - | ||||||||||||||||||
85 | and scales the painter to match differences in resolution | - | ||||||||||||||||||
86 | depending on the window system. | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | Example of how to record a picture: | - | ||||||||||||||||||
89 | \snippet picture/picture.cpp 0 | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | Note that the list of painter commands is reset on each call to | - | ||||||||||||||||||
92 | the QPainter::begin() function. | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | Example of how to replay a picture: | - | ||||||||||||||||||
95 | \snippet picture/picture.cpp 1 | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | Pictures can also be drawn using play(). Some basic data about a | - | ||||||||||||||||||
98 | picture is available, for example, size(), isNull() and | - | ||||||||||||||||||
99 | boundingRect(). | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | \sa QMovie | - | ||||||||||||||||||
102 | */ | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | /*! | - | ||||||||||||||||||
105 | \fn QPicture &QPicture::operator=(QPicture &&other) | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | Move-assigns \a other to this QPicture instance. | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | \since 5.2 | - | ||||||||||||||||||
110 | */ | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | const char *qt_mfhdr_tag = "QPIC"; // header tag | - | ||||||||||||||||||
113 | static const quint16 mfhdr_maj = QDataStream::Qt_DefaultCompiledVersion; // major version # | - | ||||||||||||||||||
114 | static const quint16 mfhdr_min = 0; // minor version # | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | /*! | - | ||||||||||||||||||
117 | Constructs an empty picture. | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | The \a formatVersion parameter may be used to \e create a QPicture | - | ||||||||||||||||||
120 | that can be read by applications that are compiled with earlier | - | ||||||||||||||||||
121 | versions of Qt. | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | Note that the default formatVersion is -1 which signifies the | - | ||||||||||||||||||
124 | current release, i.e. for Qt 4.0 a formatVersion of 7 is the same | - | ||||||||||||||||||
125 | as the default formatVersion of -1. | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | Reading pictures generated by earlier versions of Qt is not | - | ||||||||||||||||||
128 | supported in Qt 4.0. | - | ||||||||||||||||||
129 | */ | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | QPicture::QPicture(int formatVersion) | - | ||||||||||||||||||
132 | : QPaintDevice(), | - | ||||||||||||||||||
133 | d_ptr(new QPicturePrivate) | - | ||||||||||||||||||
134 | { | - | ||||||||||||||||||
135 | Q_D(QPicture); | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | if (formatVersion == 0)
| 0 | ||||||||||||||||||
138 | qWarning("QPicture: invalid format version 0"); never executed: QMessageLogger(__FILE__, 138, __PRETTY_FUNCTION__).warning("QPicture: invalid format version 0"); | 0 | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | // still accept the 0 default from before Qt 3.0. | - | ||||||||||||||||||
141 | if (formatVersion > 0 && formatVersion != (int)mfhdr_maj) {
| 0 | ||||||||||||||||||
142 | d->formatMajor = formatVersion; | - | ||||||||||||||||||
143 | d->formatMinor = 0; | - | ||||||||||||||||||
144 | d->formatOk = false; | - | ||||||||||||||||||
145 | } else { never executed: end of block | 0 | ||||||||||||||||||
146 | d->resetFormat(); | - | ||||||||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||||||||
148 | } | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | /*! | - | ||||||||||||||||||
151 | Constructs a copy of \a pic. | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | This constructor is fast thanks to \l{implicit sharing}. | - | ||||||||||||||||||
154 | */ | - | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | QPicture::QPicture(const QPicture &pic) | - | ||||||||||||||||||
157 | : QPaintDevice(), d_ptr(pic.d_ptr) | - | ||||||||||||||||||
158 | { | - | ||||||||||||||||||
159 | } never executed: end of block | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | /*! \internal */ | - | ||||||||||||||||||
162 | QPicture::QPicture(QPicturePrivate &dptr) | - | ||||||||||||||||||
163 | : QPaintDevice(), | - | ||||||||||||||||||
164 | d_ptr(&dptr) | - | ||||||||||||||||||
165 | { | - | ||||||||||||||||||
166 | } never executed: end of block | 0 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | /*! | - | ||||||||||||||||||
169 | Destroys the picture. | - | ||||||||||||||||||
170 | */ | - | ||||||||||||||||||
171 | QPicture::~QPicture() | - | ||||||||||||||||||
172 | { | - | ||||||||||||||||||
173 | } | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | /*! | - | ||||||||||||||||||
176 | \internal | - | ||||||||||||||||||
177 | */ | - | ||||||||||||||||||
178 | int QPicture::devType() const | - | ||||||||||||||||||
179 | { | - | ||||||||||||||||||
180 | return QInternal::Picture; never executed: return QInternal::Picture; | 0 | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | /*! | - | ||||||||||||||||||
184 | \fn bool QPicture::isNull() const | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | Returns \c true if the picture contains no data; otherwise returns | - | ||||||||||||||||||
187 | false. | - | ||||||||||||||||||
188 | */ | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | /*! | - | ||||||||||||||||||
191 | \fn uint QPicture::size() const | - | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | Returns the size of the picture data. | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | \sa data() | - | ||||||||||||||||||
196 | */ | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | /*! | - | ||||||||||||||||||
199 | \fn const char* QPicture::data() const | - | ||||||||||||||||||
200 | - | |||||||||||||||||||
201 | Returns a pointer to the picture data. The pointer is only valid | - | ||||||||||||||||||
202 | until the next non-const function is called on this picture. The | - | ||||||||||||||||||
203 | returned pointer is 0 if the picture contains no data. | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | \sa size(), isNull() | - | ||||||||||||||||||
206 | */ | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | - | |||||||||||||||||||
209 | bool QPicture::isNull() const | - | ||||||||||||||||||
210 | { | - | ||||||||||||||||||
211 | return d_func()->pictb.buffer().isNull(); never executed: return d_func()->pictb.buffer().isNull(); | 0 | ||||||||||||||||||
212 | } | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | uint QPicture::size() const | - | ||||||||||||||||||
215 | { | - | ||||||||||||||||||
216 | return d_func()->pictb.buffer().size(); never executed: return d_func()->pictb.buffer().size(); | 0 | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | const char* QPicture::data() const | - | ||||||||||||||||||
220 | { | - | ||||||||||||||||||
221 | return d_func()->pictb.buffer(); never executed: return d_func()->pictb.buffer(); | 0 | ||||||||||||||||||
222 | } | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | void QPicture::detach() | - | ||||||||||||||||||
225 | { | - | ||||||||||||||||||
226 | d_ptr.detach(); | - | ||||||||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | bool QPicture::isDetached() const | - | ||||||||||||||||||
230 | { | - | ||||||||||||||||||
231 | return d_func()->ref.load() == 1; never executed: return d_func()->ref.load() == 1; | 0 | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | /*! | - | ||||||||||||||||||
235 | Sets the picture data directly from \a data and \a size. This | - | ||||||||||||||||||
236 | function copies the input data. | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | \sa data(), size() | - | ||||||||||||||||||
239 | */ | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | void QPicture::setData(const char* data, uint size) | - | ||||||||||||||||||
242 | { | - | ||||||||||||||||||
243 | detach(); | - | ||||||||||||||||||
244 | d_func()->pictb.setData(data, size); | - | ||||||||||||||||||
245 | d_func()->resetFormat(); // we'll have to check | - | ||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | - | |||||||||||||||||||
249 | /*! | - | ||||||||||||||||||
250 | Loads a picture from the file specified by \a fileName and returns | - | ||||||||||||||||||
251 | true if successful; otherwise invalidates the picture and returns \c false. | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | Please note that the \a format parameter has been deprecated and | - | ||||||||||||||||||
254 | will have no effect. | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | \sa save() | - | ||||||||||||||||||
257 | */ | - | ||||||||||||||||||
258 | - | |||||||||||||||||||
259 | bool QPicture::load(const QString &fileName, const char *format) | - | ||||||||||||||||||
260 | { | - | ||||||||||||||||||
261 | QFile f(fileName); | - | ||||||||||||||||||
262 | if (!f.open(QIODevice::ReadOnly)) {
| 0 | ||||||||||||||||||
263 | operator=(QPicture()); | - | ||||||||||||||||||
264 | return false; never executed: return false; | 0 | ||||||||||||||||||
265 | } | - | ||||||||||||||||||
266 | return load(&f, format); never executed: return load(&f, format); | 0 | ||||||||||||||||||
267 | } | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | /*! | - | ||||||||||||||||||
270 | \overload | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | \a dev is the device to use for loading. | - | ||||||||||||||||||
273 | */ | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | bool QPicture::load(QIODevice *dev, const char *format) | - | ||||||||||||||||||
276 | { | - | ||||||||||||||||||
277 | if(format) {
| 0 | ||||||||||||||||||
278 | #ifndef QT_NO_PICTUREIO | - | ||||||||||||||||||
279 | QPictureIO io(dev, format); | - | ||||||||||||||||||
280 | if (io.read()) {
| 0 | ||||||||||||||||||
281 | operator=(io.picture()); | - | ||||||||||||||||||
282 | return true; never executed: return true; | 0 | ||||||||||||||||||
283 | } | - | ||||||||||||||||||
284 | #endif | - | ||||||||||||||||||
285 | qWarning("QPicture::load: No such picture format: %s", format); | - | ||||||||||||||||||
286 | operator=(QPicture()); | - | ||||||||||||||||||
287 | return false; never executed: return false; | 0 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | detach(); | - | ||||||||||||||||||
291 | QByteArray a = dev->readAll(); | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | d_func()->pictb.setData(a); // set byte array in buffer | - | ||||||||||||||||||
294 | return d_func()->checkFormat(); never executed: return d_func()->checkFormat(); | 0 | ||||||||||||||||||
295 | } | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | /*! | - | ||||||||||||||||||
298 | Saves a picture to the file specified by \a fileName and returns | - | ||||||||||||||||||
299 | true if successful; otherwise returns \c false. | - | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | Please note that the \a format parameter has been deprecated and | - | ||||||||||||||||||
302 | will have no effect. | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | \sa load() | - | ||||||||||||||||||
305 | */ | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | bool QPicture::save(const QString &fileName, const char *format) | - | ||||||||||||||||||
308 | { | - | ||||||||||||||||||
309 | if (paintingActive()) {
| 0 | ||||||||||||||||||
310 | qWarning("QPicture::save: still being painted on. " | - | ||||||||||||||||||
311 | "Call QPainter::end() first"); | - | ||||||||||||||||||
312 | return false; never executed: return false; | 0 | ||||||||||||||||||
313 | } | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | - | |||||||||||||||||||
316 | if(format) {
| 0 | ||||||||||||||||||
317 | #ifndef QT_NO_PICTUREIO | - | ||||||||||||||||||
318 | QPictureIO io(fileName, format); | - | ||||||||||||||||||
319 | bool result = io.write(); | - | ||||||||||||||||||
320 | if (result) {
| 0 | ||||||||||||||||||
321 | operator=(io.picture()); | - | ||||||||||||||||||
322 | } else if (format) never executed: end of block
| 0 | ||||||||||||||||||
323 | #else | - | ||||||||||||||||||
324 | bool result = false; | - | ||||||||||||||||||
325 | #endif | - | ||||||||||||||||||
326 | { | - | ||||||||||||||||||
327 | qWarning("QPicture::save: No such picture format: %s", format); | - | ||||||||||||||||||
328 | } never executed: end of block | 0 | ||||||||||||||||||
329 | return result; never executed: return result; | 0 | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | QFile f(fileName); | - | ||||||||||||||||||
333 | if (!f.open(QIODevice::WriteOnly))
| 0 | ||||||||||||||||||
334 | return false; never executed: return false; | 0 | ||||||||||||||||||
335 | return save(&f, format); never executed: return save(&f, format); | 0 | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | /*! | - | ||||||||||||||||||
339 | \overload | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | \a dev is the device to use for saving. | - | ||||||||||||||||||
342 | */ | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | bool QPicture::save(QIODevice *dev, const char *format) | - | ||||||||||||||||||
345 | { | - | ||||||||||||||||||
346 | if (paintingActive()) {
| 0 | ||||||||||||||||||
347 | qWarning("QPicture::save: still being painted on. " | - | ||||||||||||||||||
348 | "Call QPainter::end() first"); | - | ||||||||||||||||||
349 | return false; never executed: return false; | 0 | ||||||||||||||||||
350 | } | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | if(format) {
| 0 | ||||||||||||||||||
353 | #ifndef QT_NO_PICTUREIO | - | ||||||||||||||||||
354 | QPictureIO io(dev, format); | - | ||||||||||||||||||
355 | bool result = io.write(); | - | ||||||||||||||||||
356 | if (result) {
| 0 | ||||||||||||||||||
357 | operator=(io.picture()); | - | ||||||||||||||||||
358 | } else if (format) never executed: end of block
| 0 | ||||||||||||||||||
359 | #else | - | ||||||||||||||||||
360 | bool result = false; | - | ||||||||||||||||||
361 | #endif | - | ||||||||||||||||||
362 | { | - | ||||||||||||||||||
363 | qWarning("QPicture::save: No such picture format: %s", format); | - | ||||||||||||||||||
364 | } never executed: end of block | 0 | ||||||||||||||||||
365 | return result; never executed: return result; | 0 | ||||||||||||||||||
366 | } | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size()); | - | ||||||||||||||||||
369 | return true; never executed: return true; | 0 | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | /*! | - | ||||||||||||||||||
373 | Returns the picture's bounding rectangle or an invalid rectangle | - | ||||||||||||||||||
374 | if the picture contains no data. | - | ||||||||||||||||||
375 | */ | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | QRect QPicture::boundingRect() const | - | ||||||||||||||||||
378 | { | - | ||||||||||||||||||
379 | Q_D(const QPicture); | - | ||||||||||||||||||
380 | // Use override rect where possible. | - | ||||||||||||||||||
381 | if (!d->override_rect.isEmpty())
| 0 | ||||||||||||||||||
382 | return d->override_rect; never executed: return d->override_rect; | 0 | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | if (!d->formatOk)
| 0 | ||||||||||||||||||
385 | d_ptr->checkFormat(); never executed: d_ptr->checkFormat(); | 0 | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | return d->brect; never executed: return d->brect; | 0 | ||||||||||||||||||
388 | } | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | /*! | - | ||||||||||||||||||
391 | Sets the picture's bounding rectangle to \a r. The automatically | - | ||||||||||||||||||
392 | calculated value is overridden. | - | ||||||||||||||||||
393 | */ | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | void QPicture::setBoundingRect(const QRect &r) | - | ||||||||||||||||||
396 | { | - | ||||||||||||||||||
397 | d_func()->override_rect = r; | - | ||||||||||||||||||
398 | } never executed: end of block | 0 | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | /*! | - | ||||||||||||||||||
401 | Replays the picture using \a painter, and returns \c true if | - | ||||||||||||||||||
402 | successful; otherwise returns \c false. | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | This function does exactly the same as QPainter::drawPicture() | - | ||||||||||||||||||
405 | with (x, y) = (0, 0). | - | ||||||||||||||||||
406 | */ | - | ||||||||||||||||||
407 | - | |||||||||||||||||||
408 | bool QPicture::play(QPainter *painter) | - | ||||||||||||||||||
409 | { | - | ||||||||||||||||||
410 | Q_D(QPicture); | - | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | if (d->pictb.size() == 0) // nothing recorded
| 0 | ||||||||||||||||||
413 | return true; never executed: return true; | 0 | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | if (!d->formatOk && !d->checkFormat())
| 0 | ||||||||||||||||||
416 | return false; never executed: return false; | 0 | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | d->pictb.open(QIODevice::ReadOnly); // open buffer device | - | ||||||||||||||||||
419 | QDataStream s; | - | ||||||||||||||||||
420 | s.setDevice(&d->pictb); // attach data stream to buffer | - | ||||||||||||||||||
421 | s.device()->seek(10); // go directly to the data | - | ||||||||||||||||||
422 | s.setVersion(d->formatMajor == 4 ? 3 : d->formatMajor); | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | quint8 c, clen; | - | ||||||||||||||||||
425 | quint32 nrecords; | - | ||||||||||||||||||
426 | s >> c >> clen; | - | ||||||||||||||||||
427 | Q_ASSERT(c == QPicturePrivate::PdcBegin); | - | ||||||||||||||||||
428 | // bounding rect was introduced in ver 4. Read in checkFormat(). | - | ||||||||||||||||||
429 | if (d->formatMajor >= 4) {
| 0 | ||||||||||||||||||
430 | qint32 dummy; | - | ||||||||||||||||||
431 | s >> dummy >> dummy >> dummy >> dummy; | - | ||||||||||||||||||
432 | } never executed: end of block | 0 | ||||||||||||||||||
433 | s >> nrecords; | - | ||||||||||||||||||
434 | if (!exec(painter, s, nrecords)) {
| 0 | ||||||||||||||||||
435 | qWarning("QPicture::play: Format error"); | - | ||||||||||||||||||
436 | d->pictb.close(); | - | ||||||||||||||||||
437 | return false; never executed: return false; | 0 | ||||||||||||||||||
438 | } | - | ||||||||||||||||||
439 | d->pictb.close(); | - | ||||||||||||||||||
440 | return true; // no end-command never executed: return true; | 0 | ||||||||||||||||||
441 | } | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | - | |||||||||||||||||||
444 | // | - | ||||||||||||||||||
445 | // QFakeDevice is used to create fonts with a custom DPI | - | ||||||||||||||||||
446 | // | - | ||||||||||||||||||
447 | class QFakeDevice : public QPaintDevice | - | ||||||||||||||||||
448 | { | - | ||||||||||||||||||
449 | public: | - | ||||||||||||||||||
450 | QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); } never executed: end of block | 0 | ||||||||||||||||||
451 | void setDpiX(int dpi) { dpi_x = dpi; } never executed: end of block | 0 | ||||||||||||||||||
452 | void setDpiY(int dpi) { dpi_y = dpi; } never executed: end of block | 0 | ||||||||||||||||||
453 | QPaintEngine *paintEngine() const Q_DECL_OVERRIDE { return 0; } never executed: return 0; | 0 | ||||||||||||||||||
454 | int metric(PaintDeviceMetric m) const Q_DECL_OVERRIDE | - | ||||||||||||||||||
455 | { | - | ||||||||||||||||||
456 | switch(m) { | - | ||||||||||||||||||
457 | case PdmPhysicalDpiX: never executed: case PdmPhysicalDpiX: | 0 | ||||||||||||||||||
458 | case PdmDpiX: never executed: case PdmDpiX: | 0 | ||||||||||||||||||
459 | return dpi_x; never executed: return dpi_x; | 0 | ||||||||||||||||||
460 | case PdmPhysicalDpiY: never executed: case PdmPhysicalDpiY: | 0 | ||||||||||||||||||
461 | case PdmDpiY: never executed: case PdmDpiY: | 0 | ||||||||||||||||||
462 | return dpi_y; never executed: return dpi_y; | 0 | ||||||||||||||||||
463 | default: never executed: default: | 0 | ||||||||||||||||||
464 | return QPaintDevice::metric(m); never executed: return QPaintDevice::metric(m); | 0 | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | } | - | ||||||||||||||||||
467 | - | |||||||||||||||||||
468 | private: | - | ||||||||||||||||||
469 | int dpi_x; | - | ||||||||||||||||||
470 | int dpi_y; | - | ||||||||||||||||||
471 | }; | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | /*! | - | ||||||||||||||||||
474 | \internal | - | ||||||||||||||||||
475 | Iterates over the internal picture data and draws the picture using | - | ||||||||||||||||||
476 | \a painter. | - | ||||||||||||||||||
477 | */ | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) | - | ||||||||||||||||||
480 | { | - | ||||||||||||||||||
481 | Q_D(QPicture); | - | ||||||||||||||||||
482 | #if defined(QT_DEBUG) | - | ||||||||||||||||||
483 | int strm_pos; | - | ||||||||||||||||||
484 | #endif | - | ||||||||||||||||||
485 | quint8 c; // command id | - | ||||||||||||||||||
486 | quint8 tiny_len; // 8-bit length descriptor | - | ||||||||||||||||||
487 | qint32 len; // 32-bit length descriptor | - | ||||||||||||||||||
488 | qint16 i_16, i1_16, i2_16; // parameters... | - | ||||||||||||||||||
489 | qint8 i_8; | - | ||||||||||||||||||
490 | quint32 ul; | - | ||||||||||||||||||
491 | double dbl; | - | ||||||||||||||||||
492 | bool bl; | - | ||||||||||||||||||
493 | QByteArray str1; | - | ||||||||||||||||||
494 | QString str; | - | ||||||||||||||||||
495 | QPointF p, p1, p2; | - | ||||||||||||||||||
496 | QPoint ip, ip1, ip2; | - | ||||||||||||||||||
497 | QRect ir; | - | ||||||||||||||||||
498 | QRectF r; | - | ||||||||||||||||||
499 | QPolygonF a; | - | ||||||||||||||||||
500 | QPolygon ia; | - | ||||||||||||||||||
501 | QColor color; | - | ||||||||||||||||||
502 | QFont font; | - | ||||||||||||||||||
503 | QPen pen; | - | ||||||||||||||||||
504 | QBrush brush; | - | ||||||||||||||||||
505 | QRegion rgn; | - | ||||||||||||||||||
506 | QMatrix wmatrix; | - | ||||||||||||||||||
507 | QTransform matrix; | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | QTransform worldMatrix = painter->transform(); | - | ||||||||||||||||||
510 | worldMatrix.scale(qreal(painter->device()->logicalDpiX()) / qreal(qt_defaultDpiX()), | - | ||||||||||||||||||
511 | qreal(painter->device()->logicalDpiY()) / qreal(qt_defaultDpiY())); | - | ||||||||||||||||||
512 | painter->setTransform(worldMatrix); | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | while (nrecords-- && !s.atEnd()) {
| 0 | ||||||||||||||||||
515 | s >> c; // read cmd | - | ||||||||||||||||||
516 | s >> tiny_len; // read param length | - | ||||||||||||||||||
517 | if (tiny_len == 255) // longer than 254 bytes
| 0 | ||||||||||||||||||
518 | s >> len; never executed: s >> len; | 0 | ||||||||||||||||||
519 | else | - | ||||||||||||||||||
520 | len = tiny_len; never executed: len = tiny_len; | 0 | ||||||||||||||||||
521 | #if defined(QT_DEBUG) | - | ||||||||||||||||||
522 | strm_pos = s.device()->pos(); | - | ||||||||||||||||||
523 | #endif | - | ||||||||||||||||||
524 | switch (c) { // exec cmd | - | ||||||||||||||||||
525 | case QPicturePrivate::PdcNOP: never executed: case QPicturePrivate::PdcNOP: | 0 | ||||||||||||||||||
526 | break; never executed: break; | 0 | ||||||||||||||||||
527 | case QPicturePrivate::PdcDrawPoint: never executed: case QPicturePrivate::PdcDrawPoint: | 0 | ||||||||||||||||||
528 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
529 | s >> ip; | - | ||||||||||||||||||
530 | painter->drawPoint(ip); | - | ||||||||||||||||||
531 | } else { never executed: end of block | 0 | ||||||||||||||||||
532 | s >> p; | - | ||||||||||||||||||
533 | painter->drawPoint(p); | - | ||||||||||||||||||
534 | } never executed: end of block | 0 | ||||||||||||||||||
535 | break; never executed: break; | 0 | ||||||||||||||||||
536 | case QPicturePrivate::PdcDrawPoints: never executed: case QPicturePrivate::PdcDrawPoints: | 0 | ||||||||||||||||||
537 | // ## implement me in the picture paint engine | - | ||||||||||||||||||
538 | // s >> a >> i1_32 >> i2_32; | - | ||||||||||||||||||
539 | // painter->drawPoints(a.mid(i1_32, i2_32)); | - | ||||||||||||||||||
540 | break; never executed: break; | 0 | ||||||||||||||||||
541 | case QPicturePrivate::PdcDrawPath: { never executed: case QPicturePrivate::PdcDrawPath: | 0 | ||||||||||||||||||
542 | QPainterPath path; | - | ||||||||||||||||||
543 | s >> path; | - | ||||||||||||||||||
544 | painter->drawPath(path); | - | ||||||||||||||||||
545 | break; never executed: break; | 0 | ||||||||||||||||||
546 | } | - | ||||||||||||||||||
547 | case QPicturePrivate::PdcDrawLine: never executed: case QPicturePrivate::PdcDrawLine: | 0 | ||||||||||||||||||
548 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
549 | s >> ip1 >> ip2; | - | ||||||||||||||||||
550 | painter->drawLine(ip1, ip2); | - | ||||||||||||||||||
551 | } else { never executed: end of block | 0 | ||||||||||||||||||
552 | s >> p1 >> p2; | - | ||||||||||||||||||
553 | painter->drawLine(p1, p2); | - | ||||||||||||||||||
554 | } never executed: end of block | 0 | ||||||||||||||||||
555 | break; never executed: break; | 0 | ||||||||||||||||||
556 | case QPicturePrivate::PdcDrawRect: never executed: case QPicturePrivate::PdcDrawRect: | 0 | ||||||||||||||||||
557 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
558 | s >> ir; | - | ||||||||||||||||||
559 | painter->drawRect(ir); | - | ||||||||||||||||||
560 | } else { never executed: end of block | 0 | ||||||||||||||||||
561 | s >> r; | - | ||||||||||||||||||
562 | painter->drawRect(r); | - | ||||||||||||||||||
563 | } never executed: end of block | 0 | ||||||||||||||||||
564 | break; never executed: break; | 0 | ||||||||||||||||||
565 | case QPicturePrivate::PdcDrawRoundRect: never executed: case QPicturePrivate::PdcDrawRoundRect: | 0 | ||||||||||||||||||
566 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
567 | s >> ir >> i1_16 >> i2_16; | - | ||||||||||||||||||
568 | painter->drawRoundedRect(ir, i1_16, i2_16, Qt::RelativeSize); | - | ||||||||||||||||||
569 | } else { never executed: end of block | 0 | ||||||||||||||||||
570 | s >> r >> i1_16 >> i2_16; | - | ||||||||||||||||||
571 | painter->drawRoundedRect(r, i1_16, i2_16, Qt::RelativeSize); | - | ||||||||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||||||||
573 | break; never executed: break; | 0 | ||||||||||||||||||
574 | case QPicturePrivate::PdcDrawEllipse: never executed: case QPicturePrivate::PdcDrawEllipse: | 0 | ||||||||||||||||||
575 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
576 | s >> ir; | - | ||||||||||||||||||
577 | painter->drawEllipse(ir); | - | ||||||||||||||||||
578 | } else { never executed: end of block | 0 | ||||||||||||||||||
579 | s >> r; | - | ||||||||||||||||||
580 | painter->drawEllipse(r); | - | ||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||
582 | break; never executed: break; | 0 | ||||||||||||||||||
583 | case QPicturePrivate::PdcDrawArc: never executed: case QPicturePrivate::PdcDrawArc: | 0 | ||||||||||||||||||
584 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
585 | s >> ir; | - | ||||||||||||||||||
586 | r = ir; | - | ||||||||||||||||||
587 | } else { never executed: end of block | 0 | ||||||||||||||||||
588 | s >> r; | - | ||||||||||||||||||
589 | } never executed: end of block | 0 | ||||||||||||||||||
590 | s >> i1_16 >> i2_16; | - | ||||||||||||||||||
591 | painter->drawArc(r, i1_16, i2_16); | - | ||||||||||||||||||
592 | break; never executed: break; | 0 | ||||||||||||||||||
593 | case QPicturePrivate::PdcDrawPie: never executed: case QPicturePrivate::PdcDrawPie: | 0 | ||||||||||||||||||
594 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
595 | s >> ir; | - | ||||||||||||||||||
596 | r = ir; | - | ||||||||||||||||||
597 | } else { never executed: end of block | 0 | ||||||||||||||||||
598 | s >> r; | - | ||||||||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||||||||
600 | s >> i1_16 >> i2_16; | - | ||||||||||||||||||
601 | painter->drawPie(r, i1_16, i2_16); | - | ||||||||||||||||||
602 | break; never executed: break; | 0 | ||||||||||||||||||
603 | case QPicturePrivate::PdcDrawChord: never executed: case QPicturePrivate::PdcDrawChord: | 0 | ||||||||||||||||||
604 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
605 | s >> ir; | - | ||||||||||||||||||
606 | r = ir; | - | ||||||||||||||||||
607 | } else { never executed: end of block | 0 | ||||||||||||||||||
608 | s >> r; | - | ||||||||||||||||||
609 | } never executed: end of block | 0 | ||||||||||||||||||
610 | s >> i1_16 >> i2_16; | - | ||||||||||||||||||
611 | painter->drawChord(r, i1_16, i2_16); | - | ||||||||||||||||||
612 | break; never executed: break; | 0 | ||||||||||||||||||
613 | case QPicturePrivate::PdcDrawLineSegments: never executed: case QPicturePrivate::PdcDrawLineSegments: | 0 | ||||||||||||||||||
614 | s >> ia; | - | ||||||||||||||||||
615 | painter->drawLines(ia); | - | ||||||||||||||||||
616 | ia.clear(); | - | ||||||||||||||||||
617 | break; never executed: break; | 0 | ||||||||||||||||||
618 | case QPicturePrivate::PdcDrawPolyline: never executed: case QPicturePrivate::PdcDrawPolyline: | 0 | ||||||||||||||||||
619 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
620 | s >> ia; | - | ||||||||||||||||||
621 | painter->drawPolyline(ia); | - | ||||||||||||||||||
622 | ia.clear(); | - | ||||||||||||||||||
623 | } else { never executed: end of block | 0 | ||||||||||||||||||
624 | s >> a; | - | ||||||||||||||||||
625 | painter->drawPolyline(a); | - | ||||||||||||||||||
626 | a.clear(); | - | ||||||||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||||||||
628 | break; never executed: break; | 0 | ||||||||||||||||||
629 | case QPicturePrivate::PdcDrawPolygon: never executed: case QPicturePrivate::PdcDrawPolygon: | 0 | ||||||||||||||||||
630 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
631 | s >> ia >> i_8; | - | ||||||||||||||||||
632 | painter->drawPolygon(ia, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - | ||||||||||||||||||
633 | a.clear(); | - | ||||||||||||||||||
634 | } else { never executed: end of block | 0 | ||||||||||||||||||
635 | s >> a >> i_8; | - | ||||||||||||||||||
636 | painter->drawPolygon(a, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - | ||||||||||||||||||
637 | a.clear(); | - | ||||||||||||||||||
638 | } never executed: end of block | 0 | ||||||||||||||||||
639 | break; never executed: break; | 0 | ||||||||||||||||||
640 | case QPicturePrivate::PdcDrawCubicBezier: { never executed: case QPicturePrivate::PdcDrawCubicBezier: | 0 | ||||||||||||||||||
641 | s >> ia; | - | ||||||||||||||||||
642 | QPainterPath path; | - | ||||||||||||||||||
643 | Q_ASSERT(ia.size() == 4); | - | ||||||||||||||||||
644 | path.moveTo(ia.at(0)); | - | ||||||||||||||||||
645 | path.cubicTo(ia.at(1), ia.at(2), ia.at(3)); | - | ||||||||||||||||||
646 | painter->strokePath(path, painter->pen()); | - | ||||||||||||||||||
647 | a.clear(); | - | ||||||||||||||||||
648 | } | - | ||||||||||||||||||
649 | break; never executed: break; | 0 | ||||||||||||||||||
650 | case QPicturePrivate::PdcDrawText: never executed: case QPicturePrivate::PdcDrawText: | 0 | ||||||||||||||||||
651 | s >> ip >> str1; | - | ||||||||||||||||||
652 | painter->drawText(ip, QString::fromLatin1(str1)); | - | ||||||||||||||||||
653 | break; never executed: break; | 0 | ||||||||||||||||||
654 | case QPicturePrivate::PdcDrawTextFormatted: never executed: case QPicturePrivate::PdcDrawTextFormatted: | 0 | ||||||||||||||||||
655 | s >> ir >> i_16 >> str1; | - | ||||||||||||||||||
656 | painter->drawText(ir, i_16, QString::fromLatin1(str1)); | - | ||||||||||||||||||
657 | break; never executed: break; | 0 | ||||||||||||||||||
658 | case QPicturePrivate::PdcDrawText2: never executed: case QPicturePrivate::PdcDrawText2: | 0 | ||||||||||||||||||
659 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
660 | s >> ip >> str; | - | ||||||||||||||||||
661 | painter->drawText(ip, str); | - | ||||||||||||||||||
662 | } else { never executed: end of block | 0 | ||||||||||||||||||
663 | s >> p >> str; | - | ||||||||||||||||||
664 | painter->drawText(p, str); | - | ||||||||||||||||||
665 | } never executed: end of block | 0 | ||||||||||||||||||
666 | break; never executed: break; | 0 | ||||||||||||||||||
667 | case QPicturePrivate::PdcDrawText2Formatted: never executed: case QPicturePrivate::PdcDrawText2Formatted: | 0 | ||||||||||||||||||
668 | s >> ir; | - | ||||||||||||||||||
669 | s >> i_16; | - | ||||||||||||||||||
670 | s >> str; | - | ||||||||||||||||||
671 | painter->drawText(ir, i_16, str); | - | ||||||||||||||||||
672 | break; never executed: break; | 0 | ||||||||||||||||||
673 | case QPicturePrivate::PdcDrawTextItem: { never executed: case QPicturePrivate::PdcDrawTextItem: | 0 | ||||||||||||||||||
674 | s >> p >> str >> font >> ul; | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | // the text layout direction is not used here because it's already | - | ||||||||||||||||||
677 | // aligned when QPicturePaintEngine::drawTextItem() serializes the | - | ||||||||||||||||||
678 | // drawText() call, therefore ul is unsed in this context | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | if (d->formatMajor >= 9) {
| 0 | ||||||||||||||||||
681 | s >> dbl; | - | ||||||||||||||||||
682 | QFont fnt(font); | - | ||||||||||||||||||
683 | if (dbl != 1.0) {
| 0 | ||||||||||||||||||
684 | QFakeDevice fake; | - | ||||||||||||||||||
685 | fake.setDpiX(qRound(dbl*qt_defaultDpiX())); | - | ||||||||||||||||||
686 | fake.setDpiY(qRound(dbl*qt_defaultDpiY())); | - | ||||||||||||||||||
687 | fnt = QFont(font, &fake); | - | ||||||||||||||||||
688 | } never executed: end of block | 0 | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | qreal justificationWidth; | - | ||||||||||||||||||
691 | s >> justificationWidth; | - | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | int flags = Qt::TextSingleLine | Qt::TextDontClip | Qt::TextForceLeftToRight; | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | QSizeF size(1, 1); | - | ||||||||||||||||||
696 | if (justificationWidth > 0) {
| 0 | ||||||||||||||||||
697 | size.setWidth(justificationWidth); | - | ||||||||||||||||||
698 | flags |= Qt::TextJustificationForced; | - | ||||||||||||||||||
699 | flags |= Qt::AlignJustify; | - | ||||||||||||||||||
700 | } never executed: end of block | 0 | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | QFontMetrics fm(fnt); | - | ||||||||||||||||||
703 | QPointF pt(p.x(), p.y() - fm.ascent()); | - | ||||||||||||||||||
704 | qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/0, | - | ||||||||||||||||||
705 | str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); | - | ||||||||||||||||||
706 | } else { never executed: end of block | 0 | ||||||||||||||||||
707 | qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/0, | - | ||||||||||||||||||
708 | str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); | - | ||||||||||||||||||
709 | } never executed: end of block | 0 | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | break; never executed: break; | 0 | ||||||||||||||||||
712 | } | - | ||||||||||||||||||
713 | case QPicturePrivate::PdcDrawPixmap: { never executed: case QPicturePrivate::PdcDrawPixmap: | 0 | ||||||||||||||||||
714 | QPixmap pixmap; | - | ||||||||||||||||||
715 | if (d->formatMajor < 4) {
| 0 | ||||||||||||||||||
716 | s >> ip >> pixmap; | - | ||||||||||||||||||
717 | painter->drawPixmap(ip, pixmap); | - | ||||||||||||||||||
718 | } else if (d->formatMajor <= 5) { never executed: end of block
| 0 | ||||||||||||||||||
719 | s >> ir >> pixmap; | - | ||||||||||||||||||
720 | painter->drawPixmap(ir, pixmap); | - | ||||||||||||||||||
721 | } else { never executed: end of block | 0 | ||||||||||||||||||
722 | QRectF sr; | - | ||||||||||||||||||
723 | if (d->in_memory_only) {
| 0 | ||||||||||||||||||
724 | int index; | - | ||||||||||||||||||
725 | s >> r >> index >> sr; | - | ||||||||||||||||||
726 | Q_ASSERT(index < d->pixmap_list.size()); | - | ||||||||||||||||||
727 | pixmap = d->pixmap_list.at(index); | - | ||||||||||||||||||
728 | } else { never executed: end of block | 0 | ||||||||||||||||||
729 | s >> r >> pixmap >> sr; | - | ||||||||||||||||||
730 | } never executed: end of block | 0 | ||||||||||||||||||
731 | painter->drawPixmap(r, pixmap, sr); | - | ||||||||||||||||||
732 | } never executed: end of block | 0 | ||||||||||||||||||
733 | } | - | ||||||||||||||||||
734 | break; never executed: break; | 0 | ||||||||||||||||||
735 | case QPicturePrivate::PdcDrawTiledPixmap: { never executed: case QPicturePrivate::PdcDrawTiledPixmap: | 0 | ||||||||||||||||||
736 | QPixmap pixmap; | - | ||||||||||||||||||
737 | if (d->in_memory_only) {
| 0 | ||||||||||||||||||
738 | int index; | - | ||||||||||||||||||
739 | s >> r >> index >> p; | - | ||||||||||||||||||
740 | Q_ASSERT(index < d->pixmap_list.size()); | - | ||||||||||||||||||
741 | pixmap = d->pixmap_list.at(index); | - | ||||||||||||||||||
742 | } else { never executed: end of block | 0 | ||||||||||||||||||
743 | s >> r >> pixmap >> p; | - | ||||||||||||||||||
744 | } never executed: end of block | 0 | ||||||||||||||||||
745 | painter->drawTiledPixmap(r, pixmap, p); | - | ||||||||||||||||||
746 | } | - | ||||||||||||||||||
747 | break; never executed: break; | 0 | ||||||||||||||||||
748 | case QPicturePrivate::PdcDrawImage: { never executed: case QPicturePrivate::PdcDrawImage: | 0 | ||||||||||||||||||
749 | QImage image; | - | ||||||||||||||||||
750 | if (d->formatMajor < 4) {
| 0 | ||||||||||||||||||
751 | s >> p >> image; | - | ||||||||||||||||||
752 | painter->drawImage(p, image); | - | ||||||||||||||||||
753 | } else if (d->formatMajor <= 5){ never executed: end of block
| 0 | ||||||||||||||||||
754 | s >> ir >> image; | - | ||||||||||||||||||
755 | painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height())); | - | ||||||||||||||||||
756 | } else { never executed: end of block | 0 | ||||||||||||||||||
757 | QRectF sr; | - | ||||||||||||||||||
758 | if (d->in_memory_only) {
| 0 | ||||||||||||||||||
759 | int index; | - | ||||||||||||||||||
760 | s >> r >> index >> sr >> ul; | - | ||||||||||||||||||
761 | Q_ASSERT(index < d->image_list.size()); | - | ||||||||||||||||||
762 | image = d->image_list.at(index); | - | ||||||||||||||||||
763 | } else { never executed: end of block | 0 | ||||||||||||||||||
764 | s >> r >> image >> sr >> ul; | - | ||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||
766 | painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul)); | - | ||||||||||||||||||
767 | } never executed: end of block | 0 | ||||||||||||||||||
768 | } | - | ||||||||||||||||||
769 | break; never executed: break; | 0 | ||||||||||||||||||
770 | case QPicturePrivate::PdcBegin: never executed: case QPicturePrivate::PdcBegin: | 0 | ||||||||||||||||||
771 | s >> ul; // number of records | - | ||||||||||||||||||
772 | if (!exec(painter, s, ul))
| 0 | ||||||||||||||||||
773 | return false; never executed: return false; | 0 | ||||||||||||||||||
774 | break; never executed: break; | 0 | ||||||||||||||||||
775 | case QPicturePrivate::PdcEnd: never executed: case QPicturePrivate::PdcEnd: | 0 | ||||||||||||||||||
776 | if (nrecords == 0)
| 0 | ||||||||||||||||||
777 | return true; never executed: return true; | 0 | ||||||||||||||||||
778 | break; never executed: break; | 0 | ||||||||||||||||||
779 | case QPicturePrivate::PdcSave: never executed: case QPicturePrivate::PdcSave: | 0 | ||||||||||||||||||
780 | painter->save(); | - | ||||||||||||||||||
781 | break; never executed: break; | 0 | ||||||||||||||||||
782 | case QPicturePrivate::PdcRestore: never executed: case QPicturePrivate::PdcRestore: | 0 | ||||||||||||||||||
783 | painter->restore(); | - | ||||||||||||||||||
784 | break; never executed: break; | 0 | ||||||||||||||||||
785 | case QPicturePrivate::PdcSetBkColor: never executed: case QPicturePrivate::PdcSetBkColor: | 0 | ||||||||||||||||||
786 | s >> color; | - | ||||||||||||||||||
787 | painter->setBackground(color); | - | ||||||||||||||||||
788 | break; never executed: break; | 0 | ||||||||||||||||||
789 | case QPicturePrivate::PdcSetBkMode: never executed: case QPicturePrivate::PdcSetBkMode: | 0 | ||||||||||||||||||
790 | s >> i_8; | - | ||||||||||||||||||
791 | painter->setBackgroundMode((Qt::BGMode)i_8); | - | ||||||||||||||||||
792 | break; never executed: break; | 0 | ||||||||||||||||||
793 | case QPicturePrivate::PdcSetROP: // NOP never executed: case QPicturePrivate::PdcSetROP: | 0 | ||||||||||||||||||
794 | s >> i_8; | - | ||||||||||||||||||
795 | break; never executed: break; | 0 | ||||||||||||||||||
796 | case QPicturePrivate::PdcSetBrushOrigin: never executed: case QPicturePrivate::PdcSetBrushOrigin: | 0 | ||||||||||||||||||
797 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
798 | s >> ip; | - | ||||||||||||||||||
799 | painter->setBrushOrigin(ip); | - | ||||||||||||||||||
800 | } else { never executed: end of block | 0 | ||||||||||||||||||
801 | s >> p; | - | ||||||||||||||||||
802 | painter->setBrushOrigin(p); | - | ||||||||||||||||||
803 | } never executed: end of block | 0 | ||||||||||||||||||
804 | break; never executed: break; | 0 | ||||||||||||||||||
805 | case QPicturePrivate::PdcSetFont: never executed: case QPicturePrivate::PdcSetFont: | 0 | ||||||||||||||||||
806 | s >> font; | - | ||||||||||||||||||
807 | painter->setFont(font); | - | ||||||||||||||||||
808 | break; never executed: break; | 0 | ||||||||||||||||||
809 | case QPicturePrivate::PdcSetPen: never executed: case QPicturePrivate::PdcSetPen: | 0 | ||||||||||||||||||
810 | if (d->in_memory_only) {
| 0 | ||||||||||||||||||
811 | int index; | - | ||||||||||||||||||
812 | s >> index; | - | ||||||||||||||||||
813 | Q_ASSERT(index < d->pen_list.size()); | - | ||||||||||||||||||
814 | pen = d->pen_list.at(index); | - | ||||||||||||||||||
815 | } else { never executed: end of block | 0 | ||||||||||||||||||
816 | s >> pen; | - | ||||||||||||||||||
817 | } never executed: end of block | 0 | ||||||||||||||||||
818 | painter->setPen(pen); | - | ||||||||||||||||||
819 | break; never executed: break; | 0 | ||||||||||||||||||
820 | case QPicturePrivate::PdcSetBrush: never executed: case QPicturePrivate::PdcSetBrush: | 0 | ||||||||||||||||||
821 | if (d->in_memory_only) {
| 0 | ||||||||||||||||||
822 | int index; | - | ||||||||||||||||||
823 | s >> index; | - | ||||||||||||||||||
824 | Q_ASSERT(index < d->brush_list.size()); | - | ||||||||||||||||||
825 | brush = d->brush_list.at(index); | - | ||||||||||||||||||
826 | } else { never executed: end of block | 0 | ||||||||||||||||||
827 | s >> brush; | - | ||||||||||||||||||
828 | } never executed: end of block | 0 | ||||||||||||||||||
829 | painter->setBrush(brush); | - | ||||||||||||||||||
830 | break; never executed: break; | 0 | ||||||||||||||||||
831 | case QPicturePrivate::PdcSetVXform: never executed: case QPicturePrivate::PdcSetVXform: | 0 | ||||||||||||||||||
832 | s >> i_8; | - | ||||||||||||||||||
833 | painter->setViewTransformEnabled(i_8); | - | ||||||||||||||||||
834 | break; never executed: break; | 0 | ||||||||||||||||||
835 | case QPicturePrivate::PdcSetWindow: never executed: case QPicturePrivate::PdcSetWindow: | 0 | ||||||||||||||||||
836 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
837 | s >> ir; | - | ||||||||||||||||||
838 | painter->setWindow(ir); | - | ||||||||||||||||||
839 | } else { never executed: end of block | 0 | ||||||||||||||||||
840 | s >> r; | - | ||||||||||||||||||
841 | painter->setWindow(r.toRect()); | - | ||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||
843 | break; never executed: break; | 0 | ||||||||||||||||||
844 | case QPicturePrivate::PdcSetViewport: never executed: case QPicturePrivate::PdcSetViewport: | 0 | ||||||||||||||||||
845 | if (d->formatMajor <= 5) {
| 0 | ||||||||||||||||||
846 | s >> ir; | - | ||||||||||||||||||
847 | painter->setViewport(ir); | - | ||||||||||||||||||
848 | } else { never executed: end of block | 0 | ||||||||||||||||||
849 | s >> r; | - | ||||||||||||||||||
850 | painter->setViewport(r.toRect()); | - | ||||||||||||||||||
851 | } never executed: end of block | 0 | ||||||||||||||||||
852 | break; never executed: break; | 0 | ||||||||||||||||||
853 | case QPicturePrivate::PdcSetWXform: never executed: case QPicturePrivate::PdcSetWXform: | 0 | ||||||||||||||||||
854 | s >> i_8; | - | ||||||||||||||||||
855 | painter->setMatrixEnabled(i_8); | - | ||||||||||||||||||
856 | break; never executed: break; | 0 | ||||||||||||||||||
857 | case QPicturePrivate::PdcSetWMatrix: never executed: case QPicturePrivate::PdcSetWMatrix: | 0 | ||||||||||||||||||
858 | if (d->formatMajor >= 8) {
| 0 | ||||||||||||||||||
859 | s >> matrix >> i_8; | - | ||||||||||||||||||
860 | } else { never executed: end of block | 0 | ||||||||||||||||||
861 | s >> wmatrix >> i_8; | - | ||||||||||||||||||
862 | matrix = QTransform(wmatrix); | - | ||||||||||||||||||
863 | } never executed: end of block | 0 | ||||||||||||||||||
864 | // i_8 is always false due to updateXForm() in qpaintengine_pic.cpp | - | ||||||||||||||||||
865 | painter->setTransform(matrix * worldMatrix, i_8); | - | ||||||||||||||||||
866 | break; never executed: break; | 0 | ||||||||||||||||||
867 | case QPicturePrivate::PdcSetClip: never executed: case QPicturePrivate::PdcSetClip: | 0 | ||||||||||||||||||
868 | s >> i_8; | - | ||||||||||||||||||
869 | painter->setClipping(i_8); | - | ||||||||||||||||||
870 | break; never executed: break; | 0 | ||||||||||||||||||
871 | case QPicturePrivate::PdcSetClipRegion: never executed: case QPicturePrivate::PdcSetClipRegion: | 0 | ||||||||||||||||||
872 | s >> rgn >> i_8; | - | ||||||||||||||||||
873 | if (d->formatMajor >= 9) {
| 0 | ||||||||||||||||||
874 | painter->setClipRegion(rgn, Qt::ClipOperation(i_8)); | - | ||||||||||||||||||
875 | } else { never executed: end of block | 0 | ||||||||||||||||||
876 | painter->setClipRegion(rgn); | - | ||||||||||||||||||
877 | } never executed: end of block | 0 | ||||||||||||||||||
878 | break; never executed: break; | 0 | ||||||||||||||||||
879 | case QPicturePrivate::PdcSetClipPath: never executed: case QPicturePrivate::PdcSetClipPath: | 0 | ||||||||||||||||||
880 | { | - | ||||||||||||||||||
881 | QPainterPath path; | - | ||||||||||||||||||
882 | s >> path >> i_8; | - | ||||||||||||||||||
883 | painter->setClipPath(path, Qt::ClipOperation(i_8)); | - | ||||||||||||||||||
884 | break; never executed: break; | 0 | ||||||||||||||||||
885 | } | - | ||||||||||||||||||
886 | case QPicturePrivate::PdcSetRenderHint: never executed: case QPicturePrivate::PdcSetRenderHint: | 0 | ||||||||||||||||||
887 | s >> ul; | - | ||||||||||||||||||
888 | painter->setRenderHint(QPainter::Antialiasing, | - | ||||||||||||||||||
889 | bool(ul & QPainter::Antialiasing)); | - | ||||||||||||||||||
890 | painter->setRenderHint(QPainter::SmoothPixmapTransform, | - | ||||||||||||||||||
891 | bool(ul & QPainter::SmoothPixmapTransform)); | - | ||||||||||||||||||
892 | break; never executed: break; | 0 | ||||||||||||||||||
893 | case QPicturePrivate::PdcSetCompositionMode: never executed: case QPicturePrivate::PdcSetCompositionMode: | 0 | ||||||||||||||||||
894 | s >> ul; | - | ||||||||||||||||||
895 | painter->setCompositionMode((QPainter::CompositionMode)ul); | - | ||||||||||||||||||
896 | break; never executed: break; | 0 | ||||||||||||||||||
897 | case QPicturePrivate::PdcSetClipEnabled: never executed: case QPicturePrivate::PdcSetClipEnabled: | 0 | ||||||||||||||||||
898 | s >> bl; | - | ||||||||||||||||||
899 | painter->setClipping(bl); | - | ||||||||||||||||||
900 | break; never executed: break; | 0 | ||||||||||||||||||
901 | case QPicturePrivate::PdcSetOpacity: never executed: case QPicturePrivate::PdcSetOpacity: | 0 | ||||||||||||||||||
902 | s >> dbl; | - | ||||||||||||||||||
903 | painter->setOpacity(qreal(dbl)); | - | ||||||||||||||||||
904 | break; never executed: break; | 0 | ||||||||||||||||||
905 | default: never executed: default: | 0 | ||||||||||||||||||
906 | qWarning("QPicture::play: Invalid command %d", c); | - | ||||||||||||||||||
907 | if (len) // skip unknown command
| 0 | ||||||||||||||||||
908 | s.device()->seek(s.device()->pos()+len); never executed: s.device()->seek(s.device()->pos()+len); | 0 | ||||||||||||||||||
909 | } never executed: end of block | 0 | ||||||||||||||||||
910 | #if defined(QT_DEBUG) | - | ||||||||||||||||||
911 | //qDebug("device->at(): %i, strm_pos: %i len: %i", (int)s.device()->pos(), strm_pos, len); | - | ||||||||||||||||||
912 | Q_ASSERT(qint32(s.device()->pos() - strm_pos) == len); | - | ||||||||||||||||||
913 | #endif | - | ||||||||||||||||||
914 | } never executed: end of block | 0 | ||||||||||||||||||
915 | return false; never executed: return false; | 0 | ||||||||||||||||||
916 | } | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | /*! | - | ||||||||||||||||||
919 | \internal | - | ||||||||||||||||||
920 | - | |||||||||||||||||||
921 | Internal implementation of the virtual QPaintDevice::metric() | - | ||||||||||||||||||
922 | function. | - | ||||||||||||||||||
923 | - | |||||||||||||||||||
924 | A picture has the following hard-coded values: numcolors=16777216 | - | ||||||||||||||||||
925 | and depth=24. | - | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | \a m is the metric to get. | - | ||||||||||||||||||
928 | */ | - | ||||||||||||||||||
929 | - | |||||||||||||||||||
930 | int QPicture::metric(PaintDeviceMetric m) const | - | ||||||||||||||||||
931 | { | - | ||||||||||||||||||
932 | int val; | - | ||||||||||||||||||
933 | QRect brect = boundingRect(); | - | ||||||||||||||||||
934 | switch (m) { | - | ||||||||||||||||||
935 | case PdmWidth: never executed: case PdmWidth: | 0 | ||||||||||||||||||
936 | val = brect.width(); | - | ||||||||||||||||||
937 | break; never executed: break; | 0 | ||||||||||||||||||
938 | case PdmHeight: never executed: case PdmHeight: | 0 | ||||||||||||||||||
939 | val = brect.height(); | - | ||||||||||||||||||
940 | break; never executed: break; | 0 | ||||||||||||||||||
941 | case PdmWidthMM: never executed: case PdmWidthMM: | 0 | ||||||||||||||||||
942 | val = int(25.4/qt_defaultDpiX()*brect.width()); | - | ||||||||||||||||||
943 | break; never executed: break; | 0 | ||||||||||||||||||
944 | case PdmHeightMM: never executed: case PdmHeightMM: | 0 | ||||||||||||||||||
945 | val = int(25.4/qt_defaultDpiY()*brect.height()); | - | ||||||||||||||||||
946 | break; never executed: break; | 0 | ||||||||||||||||||
947 | case PdmDpiX: never executed: case PdmDpiX: | 0 | ||||||||||||||||||
948 | case PdmPhysicalDpiX: never executed: case PdmPhysicalDpiX: | 0 | ||||||||||||||||||
949 | val = qt_defaultDpiX(); | - | ||||||||||||||||||
950 | break; never executed: break; | 0 | ||||||||||||||||||
951 | case PdmDpiY: never executed: case PdmDpiY: | 0 | ||||||||||||||||||
952 | case PdmPhysicalDpiY: never executed: case PdmPhysicalDpiY: | 0 | ||||||||||||||||||
953 | val = qt_defaultDpiY(); | - | ||||||||||||||||||
954 | break; never executed: break; | 0 | ||||||||||||||||||
955 | case PdmNumColors: never executed: case PdmNumColors: | 0 | ||||||||||||||||||
956 | val = 16777216; | - | ||||||||||||||||||
957 | break; never executed: break; | 0 | ||||||||||||||||||
958 | case PdmDepth: never executed: case PdmDepth: | 0 | ||||||||||||||||||
959 | val = 24; | - | ||||||||||||||||||
960 | break; never executed: break; | 0 | ||||||||||||||||||
961 | case PdmDevicePixelRatio: never executed: case PdmDevicePixelRatio: | 0 | ||||||||||||||||||
962 | val = 1; | - | ||||||||||||||||||
963 | break; never executed: break; | 0 | ||||||||||||||||||
964 | case PdmDevicePixelRatioScaled: never executed: case PdmDevicePixelRatioScaled: | 0 | ||||||||||||||||||
965 | val = 1 * QPaintDevice::devicePixelRatioFScale(); | - | ||||||||||||||||||
966 | break; never executed: break; | 0 | ||||||||||||||||||
967 | default: never executed: default: | 0 | ||||||||||||||||||
968 | val = 0; | - | ||||||||||||||||||
969 | qWarning("QPicture::metric: Invalid metric command"); | - | ||||||||||||||||||
970 | } never executed: end of block | 0 | ||||||||||||||||||
971 | return val; never executed: return val; | 0 | ||||||||||||||||||
972 | } | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | /*! | - | ||||||||||||||||||
975 | \fn void QPicture::detach() | - | ||||||||||||||||||
976 | \internal | - | ||||||||||||||||||
977 | Detaches from shared picture data and makes sure that this picture | - | ||||||||||||||||||
978 | is the only one referring to the data. | - | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | If multiple pictures share common data, this picture makes a copy | - | ||||||||||||||||||
981 | of the data and detaches itself from the sharing mechanism. | - | ||||||||||||||||||
982 | Nothing is done if there is just a single reference. | - | ||||||||||||||||||
983 | */ | - | ||||||||||||||||||
984 | - | |||||||||||||||||||
985 | /*! \fn bool QPicture::isDetached() const | - | ||||||||||||||||||
986 | \internal | - | ||||||||||||||||||
987 | */ | - | ||||||||||||||||||
988 | - | |||||||||||||||||||
989 | /*! | - | ||||||||||||||||||
990 | Assigns picture \a p to this picture and returns a reference to | - | ||||||||||||||||||
991 | this picture. | - | ||||||||||||||||||
992 | */ | - | ||||||||||||||||||
993 | QPicture& QPicture::operator=(const QPicture &p) | - | ||||||||||||||||||
994 | { | - | ||||||||||||||||||
995 | d_ptr = p.d_ptr; | - | ||||||||||||||||||
996 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
997 | } | - | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | /*! | - | ||||||||||||||||||
1000 | \fn void QPicture::swap(QPicture &other) | - | ||||||||||||||||||
1001 | \since 4.8 | - | ||||||||||||||||||
1002 | - | |||||||||||||||||||
1003 | Swaps picture \a other with this picture. This operation is very | - | ||||||||||||||||||
1004 | fast and never fails. | - | ||||||||||||||||||
1005 | */ | - | ||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | /*! | - | ||||||||||||||||||
1008 | \internal | - | ||||||||||||||||||
1009 | - | |||||||||||||||||||
1010 | Constructs a QPicturePrivate | - | ||||||||||||||||||
1011 | */ | - | ||||||||||||||||||
1012 | QPicturePrivate::QPicturePrivate() | - | ||||||||||||||||||
1013 | : in_memory_only(false) | - | ||||||||||||||||||
1014 | { | - | ||||||||||||||||||
1015 | } never executed: end of block | 0 | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | /*! | - | ||||||||||||||||||
1018 | \internal | - | ||||||||||||||||||
1019 | - | |||||||||||||||||||
1020 | Copy-Constructs a QPicturePrivate. Needed when detaching. | - | ||||||||||||||||||
1021 | */ | - | ||||||||||||||||||
1022 | QPicturePrivate::QPicturePrivate(const QPicturePrivate &other) | - | ||||||||||||||||||
1023 | : trecs(other.trecs), | - | ||||||||||||||||||
1024 | formatOk(other.formatOk), | - | ||||||||||||||||||
1025 | formatMinor(other.formatMinor), | - | ||||||||||||||||||
1026 | brect(other.brect), | - | ||||||||||||||||||
1027 | override_rect(other.override_rect), | - | ||||||||||||||||||
1028 | in_memory_only(false) | - | ||||||||||||||||||
1029 | { | - | ||||||||||||||||||
1030 | pictb.setData(other.pictb.data(), other.pictb.size()); | - | ||||||||||||||||||
1031 | if (other.pictb.isOpen()) {
| 0 | ||||||||||||||||||
1032 | pictb.open(other.pictb.openMode()); | - | ||||||||||||||||||
1033 | pictb.seek(other.pictb.pos()); | - | ||||||||||||||||||
1034 | } never executed: end of block | 0 | ||||||||||||||||||
1035 | } never executed: end of block | 0 | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | /*! | - | ||||||||||||||||||
1038 | \internal | - | ||||||||||||||||||
1039 | - | |||||||||||||||||||
1040 | Sets formatOk to false and resets the format version numbers to default | - | ||||||||||||||||||
1041 | */ | - | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | void QPicturePrivate::resetFormat() | - | ||||||||||||||||||
1044 | { | - | ||||||||||||||||||
1045 | formatOk = false; | - | ||||||||||||||||||
1046 | formatMajor = mfhdr_maj; | - | ||||||||||||||||||
1047 | formatMinor = mfhdr_min; | - | ||||||||||||||||||
1048 | } never executed: end of block | 0 | ||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | /*! | - | ||||||||||||||||||
1052 | \internal | - | ||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | Checks data integrity and format version number. Set formatOk to | - | ||||||||||||||||||
1055 | true on success, to false otherwise. Returns the resulting formatOk | - | ||||||||||||||||||
1056 | value. | - | ||||||||||||||||||
1057 | */ | - | ||||||||||||||||||
1058 | bool QPicturePrivate::checkFormat() | - | ||||||||||||||||||
1059 | { | - | ||||||||||||||||||
1060 | resetFormat(); | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | // can't check anything in an empty buffer | - | ||||||||||||||||||
1063 | if (pictb.size() == 0 || pictb.isOpen())
| 0 | ||||||||||||||||||
1064 | return false; never executed: return false; | 0 | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | pictb.open(QIODevice::ReadOnly); // open buffer device | - | ||||||||||||||||||
1067 | QDataStream s; | - | ||||||||||||||||||
1068 | s.setDevice(&pictb); // attach data stream to buffer | - | ||||||||||||||||||
1069 | - | |||||||||||||||||||
1070 | char mf_id[4]; // picture header tag | - | ||||||||||||||||||
1071 | s.readRawData(mf_id, 4); // read actual tag | - | ||||||||||||||||||
1072 | if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0) { // wrong header id
| 0 | ||||||||||||||||||
1073 | qWarning("QPicturePaintEngine::checkFormat: Incorrect header"); | - | ||||||||||||||||||
1074 | pictb.close(); | - | ||||||||||||||||||
1075 | return false; never executed: return false; | 0 | ||||||||||||||||||
1076 | } | - | ||||||||||||||||||
1077 | - | |||||||||||||||||||
1078 | int cs_start = sizeof(quint32); // pos of checksum word | - | ||||||||||||||||||
1079 | int data_start = cs_start + sizeof(quint16); | - | ||||||||||||||||||
1080 | quint16 cs,ccs; | - | ||||||||||||||||||
1081 | QByteArray buf = pictb.buffer(); // pointer to data | - | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | s >> cs; // read checksum | - | ||||||||||||||||||
1084 | ccs = (quint16) qChecksum(buf.constData() + data_start, buf.size() - data_start); | - | ||||||||||||||||||
1085 | if (ccs != cs) {
| 0 | ||||||||||||||||||
1086 | qWarning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected", | - | ||||||||||||||||||
1087 | ccs, cs); | - | ||||||||||||||||||
1088 | pictb.close(); | - | ||||||||||||||||||
1089 | return false; never executed: return false; | 0 | ||||||||||||||||||
1090 | } | - | ||||||||||||||||||
1091 | - | |||||||||||||||||||
1092 | quint16 major, minor; | - | ||||||||||||||||||
1093 | s >> major >> minor; // read version number | - | ||||||||||||||||||
1094 | if (major > mfhdr_maj) { // new, incompatible version
| 0 | ||||||||||||||||||
1095 | qWarning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d", | - | ||||||||||||||||||
1096 | major, minor); | - | ||||||||||||||||||
1097 | pictb.close(); | - | ||||||||||||||||||
1098 | return false; never executed: return false; | 0 | ||||||||||||||||||
1099 | } | - | ||||||||||||||||||
1100 | s.setVersion(major != 4 ? major : 3); | - | ||||||||||||||||||
1101 | - | |||||||||||||||||||
1102 | quint8 c, clen; | - | ||||||||||||||||||
1103 | s >> c >> clen; | - | ||||||||||||||||||
1104 | if (c == QPicturePrivate::PdcBegin) {
| 0 | ||||||||||||||||||
1105 | if (!(major >= 1 && major <= 3)) {
| 0 | ||||||||||||||||||
1106 | qint32 l, t, w, h; | - | ||||||||||||||||||
1107 | s >> l >> t >> w >> h; | - | ||||||||||||||||||
1108 | brect = QRect(l, t, w, h); | - | ||||||||||||||||||
1109 | } never executed: end of block | 0 | ||||||||||||||||||
1110 | } else { never executed: end of block | 0 | ||||||||||||||||||
1111 | qWarning("QPicturePaintEngine::checkFormat: Format error"); | - | ||||||||||||||||||
1112 | pictb.close(); | - | ||||||||||||||||||
1113 | return false; never executed: return false; | 0 | ||||||||||||||||||
1114 | } | - | ||||||||||||||||||
1115 | pictb.close(); | - | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | formatOk = true; // picture seems to be ok | - | ||||||||||||||||||
1118 | formatMajor = major; | - | ||||||||||||||||||
1119 | formatMinor = minor; | - | ||||||||||||||||||
1120 | return true; never executed: return true; | 0 | ||||||||||||||||||
1121 | } | - | ||||||||||||||||||
1122 | - | |||||||||||||||||||
1123 | /*! \internal */ | - | ||||||||||||||||||
1124 | QPaintEngine *QPicture::paintEngine() const | - | ||||||||||||||||||
1125 | { | - | ||||||||||||||||||
1126 | if (!d_func()->paintEngine)
| 0 | ||||||||||||||||||
1127 | const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); never executed: const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); | 0 | ||||||||||||||||||
1128 | return d_func()->paintEngine.data(); never executed: return d_func()->paintEngine.data(); | 0 | ||||||||||||||||||
1129 | } | - | ||||||||||||||||||
1130 | - | |||||||||||||||||||
1131 | /***************************************************************************** | - | ||||||||||||||||||
1132 | QPicture stream functions | - | ||||||||||||||||||
1133 | *****************************************************************************/ | - | ||||||||||||||||||
1134 | - | |||||||||||||||||||
1135 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||
1136 | /*! | - | ||||||||||||||||||
1137 | \relates QPicture | - | ||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | Writes picture \a r to the stream \a s and returns a reference to | - | ||||||||||||||||||
1140 | the stream. | - | ||||||||||||||||||
1141 | */ | - | ||||||||||||||||||
1142 | - | |||||||||||||||||||
1143 | QDataStream &operator<<(QDataStream &s, const QPicture &r) | - | ||||||||||||||||||
1144 | { | - | ||||||||||||||||||
1145 | quint32 size = r.d_func()->pictb.buffer().size(); | - | ||||||||||||||||||
1146 | s << size; | - | ||||||||||||||||||
1147 | // null picture ? | - | ||||||||||||||||||
1148 | if (size == 0)
| 0 | ||||||||||||||||||
1149 | return s; never executed: return s; | 0 | ||||||||||||||||||
1150 | // just write the whole buffer to the stream | - | ||||||||||||||||||
1151 | s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size()); | - | ||||||||||||||||||
1152 | return s; never executed: return s; | 0 | ||||||||||||||||||
1153 | } | - | ||||||||||||||||||
1154 | - | |||||||||||||||||||
1155 | /*! | - | ||||||||||||||||||
1156 | \relates QPicture | - | ||||||||||||||||||
1157 | - | |||||||||||||||||||
1158 | Reads a picture from the stream \a s into picture \a r and returns | - | ||||||||||||||||||
1159 | a reference to the stream. | - | ||||||||||||||||||
1160 | */ | - | ||||||||||||||||||
1161 | - | |||||||||||||||||||
1162 | QDataStream &operator>>(QDataStream &s, QPicture &r) | - | ||||||||||||||||||
1163 | { | - | ||||||||||||||||||
1164 | QDataStream sr; | - | ||||||||||||||||||
1165 | - | |||||||||||||||||||
1166 | // "init"; this code is similar to the beginning of QPicture::cmd() | - | ||||||||||||||||||
1167 | sr.setDevice(&r.d_func()->pictb); | - | ||||||||||||||||||
1168 | sr.setVersion(r.d_func()->formatMajor); | - | ||||||||||||||||||
1169 | quint32 len; | - | ||||||||||||||||||
1170 | s >> len; | - | ||||||||||||||||||
1171 | QByteArray data; | - | ||||||||||||||||||
1172 | if (len > 0) {
| 0 | ||||||||||||||||||
1173 | data.resize(len); | - | ||||||||||||||||||
1174 | s.readRawData(data.data(), len); | - | ||||||||||||||||||
1175 | } never executed: end of block | 0 | ||||||||||||||||||
1176 | - | |||||||||||||||||||
1177 | r.d_func()->pictb.setData(data); | - | ||||||||||||||||||
1178 | r.d_func()->resetFormat(); | - | ||||||||||||||||||
1179 | return s; never executed: return s; | 0 | ||||||||||||||||||
1180 | } | - | ||||||||||||||||||
1181 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
1182 | - | |||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | #ifndef QT_NO_PICTUREIO | - | ||||||||||||||||||
1185 | - | |||||||||||||||||||
1186 | QT_BEGIN_INCLUDE_NAMESPACE | - | ||||||||||||||||||
1187 | #include "qregexp.h" | - | ||||||||||||||||||
1188 | #include "qpictureformatplugin.h" | - | ||||||||||||||||||
1189 | QT_END_INCLUDE_NAMESPACE | - | ||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | /*! | - | ||||||||||||||||||
1192 | \obsolete | - | ||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | Returns a string that specifies the picture format of the file \a | - | ||||||||||||||||||
1195 | fileName, or 0 if the file cannot be read or if the format is not | - | ||||||||||||||||||
1196 | recognized. | - | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | \sa load(), save() | - | ||||||||||||||||||
1199 | */ | - | ||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | const char* QPicture::pictureFormat(const QString &fileName) | - | ||||||||||||||||||
1202 | { | - | ||||||||||||||||||
1203 | return QPictureIO::pictureFormat(fileName); never executed: return QPictureIO::pictureFormat(fileName); | 0 | ||||||||||||||||||
1204 | } | - | ||||||||||||||||||
1205 | - | |||||||||||||||||||
1206 | /*! | - | ||||||||||||||||||
1207 | \obsolete | - | ||||||||||||||||||
1208 | - | |||||||||||||||||||
1209 | Returns a list of picture formats that are supported for picture | - | ||||||||||||||||||
1210 | input. | - | ||||||||||||||||||
1211 | - | |||||||||||||||||||
1212 | \sa outputFormats(), inputFormatList(), QPictureIO | - | ||||||||||||||||||
1213 | */ | - | ||||||||||||||||||
1214 | QList<QByteArray> QPicture::inputFormats() | - | ||||||||||||||||||
1215 | { | - | ||||||||||||||||||
1216 | return QPictureIO::inputFormats(); never executed: return QPictureIO::inputFormats(); | 0 | ||||||||||||||||||
1217 | } | - | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | static QStringList qToStringList(const QList<QByteArray> &arr) | - | ||||||||||||||||||
1220 | { | - | ||||||||||||||||||
1221 | QStringList list; | - | ||||||||||||||||||
1222 | const int count = arr.count(); | - | ||||||||||||||||||
1223 | list.reserve(count); | - | ||||||||||||||||||
1224 | for (int i = 0; i < count; ++i)
| 0 | ||||||||||||||||||
1225 | list.append(QString::fromLatin1(arr.at(i))); never executed: list.append(QString::fromLatin1(arr.at(i))); | 0 | ||||||||||||||||||
1226 | return list; never executed: return list; | 0 | ||||||||||||||||||
1227 | } | - | ||||||||||||||||||
1228 | - | |||||||||||||||||||
1229 | /*! | - | ||||||||||||||||||
1230 | \obsolete | - | ||||||||||||||||||
1231 | - | |||||||||||||||||||
1232 | Returns a list of picture formats that are supported for picture | - | ||||||||||||||||||
1233 | input. | - | ||||||||||||||||||
1234 | - | |||||||||||||||||||
1235 | Note that if you want to iterate over the list, you should iterate | - | ||||||||||||||||||
1236 | over a copy, e.g. | - | ||||||||||||||||||
1237 | \snippet picture/picture.cpp 2 | - | ||||||||||||||||||
1238 | - | |||||||||||||||||||
1239 | \sa outputFormatList(), inputFormats(), QPictureIO | - | ||||||||||||||||||
1240 | */ | - | ||||||||||||||||||
1241 | QStringList QPicture::inputFormatList() | - | ||||||||||||||||||
1242 | { | - | ||||||||||||||||||
1243 | return qToStringList(QPictureIO::inputFormats()); never executed: return qToStringList(QPictureIO::inputFormats()); | 0 | ||||||||||||||||||
1244 | } | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | - | |||||||||||||||||||
1247 | /*! | - | ||||||||||||||||||
1248 | \obsolete | - | ||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | Returns a list of picture formats that are supported for picture | - | ||||||||||||||||||
1251 | output. | - | ||||||||||||||||||
1252 | - | |||||||||||||||||||
1253 | Note that if you want to iterate over the list, you should iterate | - | ||||||||||||||||||
1254 | over a copy, e.g. | - | ||||||||||||||||||
1255 | \snippet picture/picture.cpp 3 | - | ||||||||||||||||||
1256 | - | |||||||||||||||||||
1257 | \sa inputFormatList(), outputFormats(), QPictureIO | - | ||||||||||||||||||
1258 | */ | - | ||||||||||||||||||
1259 | QStringList QPicture::outputFormatList() | - | ||||||||||||||||||
1260 | { | - | ||||||||||||||||||
1261 | return qToStringList(QPictureIO::outputFormats()); never executed: return qToStringList(QPictureIO::outputFormats()); | 0 | ||||||||||||||||||
1262 | } | - | ||||||||||||||||||
1263 | - | |||||||||||||||||||
1264 | /*! | - | ||||||||||||||||||
1265 | \obsolete | - | ||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | Returns a list of picture formats that are supported for picture | - | ||||||||||||||||||
1268 | output. | - | ||||||||||||||||||
1269 | - | |||||||||||||||||||
1270 | \sa inputFormats(), outputFormatList(), QPictureIO | - | ||||||||||||||||||
1271 | */ | - | ||||||||||||||||||
1272 | QList<QByteArray> QPicture::outputFormats() | - | ||||||||||||||||||
1273 | { | - | ||||||||||||||||||
1274 | return QPictureIO::outputFormats(); never executed: return QPictureIO::outputFormats(); | 0 | ||||||||||||||||||
1275 | } | - | ||||||||||||||||||
1276 | - | |||||||||||||||||||
1277 | /***************************************************************************** | - | ||||||||||||||||||
1278 | QPictureIO member functions | - | ||||||||||||||||||
1279 | *****************************************************************************/ | - | ||||||||||||||||||
1280 | - | |||||||||||||||||||
1281 | /*! | - | ||||||||||||||||||
1282 | \obsolete | - | ||||||||||||||||||
1283 | - | |||||||||||||||||||
1284 | \class QPictureIO | - | ||||||||||||||||||
1285 | - | |||||||||||||||||||
1286 | \brief The QPictureIO class contains parameters for loading and | - | ||||||||||||||||||
1287 | saving pictures. | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | \ingroup painting | - | ||||||||||||||||||
1290 | \ingroup io | - | ||||||||||||||||||
1291 | \inmodule QtGui | - | ||||||||||||||||||
1292 | - | |||||||||||||||||||
1293 | QPictureIO contains a QIODevice object that is used for picture data | - | ||||||||||||||||||
1294 | I/O. The programmer can install new picture file formats in addition | - | ||||||||||||||||||
1295 | to those that Qt provides. | - | ||||||||||||||||||
1296 | - | |||||||||||||||||||
1297 | You don't normally need to use this class; QPicture::load(), | - | ||||||||||||||||||
1298 | QPicture::save(). | - | ||||||||||||||||||
1299 | - | |||||||||||||||||||
1300 | \sa QPicture, QPixmap, QFile | - | ||||||||||||||||||
1301 | */ | - | ||||||||||||||||||
1302 | - | |||||||||||||||||||
1303 | struct QPictureIOData | - | ||||||||||||||||||
1304 | { | - | ||||||||||||||||||
1305 | QPicture pi; // picture | - | ||||||||||||||||||
1306 | int iostat; // IO status | - | ||||||||||||||||||
1307 | QByteArray frmt; // picture format | - | ||||||||||||||||||
1308 | QIODevice *iodev; // IO device | - | ||||||||||||||||||
1309 | QString fname; // file name | - | ||||||||||||||||||
1310 | QString descr; // picture description | - | ||||||||||||||||||
1311 | const char *parameters; | - | ||||||||||||||||||
1312 | int quality; | - | ||||||||||||||||||
1313 | float gamma; | - | ||||||||||||||||||
1314 | }; | - | ||||||||||||||||||
1315 | - | |||||||||||||||||||
1316 | /*! | - | ||||||||||||||||||
1317 | Constructs a QPictureIO object with all parameters set to zero. | - | ||||||||||||||||||
1318 | */ | - | ||||||||||||||||||
1319 | - | |||||||||||||||||||
1320 | QPictureIO::QPictureIO() | - | ||||||||||||||||||
1321 | { | - | ||||||||||||||||||
1322 | init(); | - | ||||||||||||||||||
1323 | } never executed: end of block | 0 | ||||||||||||||||||
1324 | - | |||||||||||||||||||
1325 | /*! | - | ||||||||||||||||||
1326 | Constructs a QPictureIO object with the I/O device \a ioDevice and a | - | ||||||||||||||||||
1327 | \a format tag. | - | ||||||||||||||||||
1328 | */ | - | ||||||||||||||||||
1329 | - | |||||||||||||||||||
1330 | QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format) | - | ||||||||||||||||||
1331 | { | - | ||||||||||||||||||
1332 | init(); | - | ||||||||||||||||||
1333 | d->iodev = ioDevice; | - | ||||||||||||||||||
1334 | d->frmt = format; | - | ||||||||||||||||||
1335 | } never executed: end of block | 0 | ||||||||||||||||||
1336 | - | |||||||||||||||||||
1337 | /*! | - | ||||||||||||||||||
1338 | Constructs a QPictureIO object with the file name \a fileName and a | - | ||||||||||||||||||
1339 | \a format tag. | - | ||||||||||||||||||
1340 | */ | - | ||||||||||||||||||
1341 | - | |||||||||||||||||||
1342 | QPictureIO::QPictureIO(const QString &fileName, const char* format) | - | ||||||||||||||||||
1343 | { | - | ||||||||||||||||||
1344 | init(); | - | ||||||||||||||||||
1345 | d->frmt = format; | - | ||||||||||||||||||
1346 | d->fname = fileName; | - | ||||||||||||||||||
1347 | } never executed: end of block | 0 | ||||||||||||||||||
1348 | - | |||||||||||||||||||
1349 | /*! | - | ||||||||||||||||||
1350 | Contains initialization common to all QPictureIO constructors. | - | ||||||||||||||||||
1351 | */ | - | ||||||||||||||||||
1352 | - | |||||||||||||||||||
1353 | void QPictureIO::init() | - | ||||||||||||||||||
1354 | { | - | ||||||||||||||||||
1355 | d = new QPictureIOData(); | - | ||||||||||||||||||
1356 | d->parameters = 0; | - | ||||||||||||||||||
1357 | d->quality = -1; // default quality of the current format | - | ||||||||||||||||||
1358 | d->gamma=0.0f; | - | ||||||||||||||||||
1359 | d->iostat = 0; | - | ||||||||||||||||||
1360 | d->iodev = 0; | - | ||||||||||||||||||
1361 | } never executed: end of block | 0 | ||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | /*! | - | ||||||||||||||||||
1364 | Destroys the object and all related data. | - | ||||||||||||||||||
1365 | */ | - | ||||||||||||||||||
1366 | - | |||||||||||||||||||
1367 | QPictureIO::~QPictureIO() | - | ||||||||||||||||||
1368 | { | - | ||||||||||||||||||
1369 | if (d->parameters)
| 0 | ||||||||||||||||||
1370 | delete [] d->parameters; never executed: delete [] d->parameters; | 0 | ||||||||||||||||||
1371 | delete d; | - | ||||||||||||||||||
1372 | } never executed: end of block | 0 | ||||||||||||||||||
1373 | - | |||||||||||||||||||
1374 | - | |||||||||||||||||||
1375 | /***************************************************************************** | - | ||||||||||||||||||
1376 | QPictureIO picture handler functions | - | ||||||||||||||||||
1377 | *****************************************************************************/ | - | ||||||||||||||||||
1378 | - | |||||||||||||||||||
1379 | class QPictureHandler | - | ||||||||||||||||||
1380 | { | - | ||||||||||||||||||
1381 | public: | - | ||||||||||||||||||
1382 | QPictureHandler(const char *f, const char *h, const QByteArray& fl, | - | ||||||||||||||||||
1383 | picture_io_handler r, picture_io_handler w); | - | ||||||||||||||||||
1384 | QByteArray format; // picture format | - | ||||||||||||||||||
1385 | QRegExp header; // picture header pattern | - | ||||||||||||||||||
1386 | enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode; | - | ||||||||||||||||||
1387 | picture_io_handler read_picture; // picture read function | - | ||||||||||||||||||
1388 | picture_io_handler write_picture; // picture write function | - | ||||||||||||||||||
1389 | bool obsolete; // support not "published" | - | ||||||||||||||||||
1390 | }; | - | ||||||||||||||||||
1391 | - | |||||||||||||||||||
1392 | QPictureHandler::QPictureHandler(const char *f, const char *h, const QByteArray& fl, | - | ||||||||||||||||||
1393 | picture_io_handler r, picture_io_handler w) | - | ||||||||||||||||||
1394 | : format(f), header(QString::fromLatin1(h)) | - | ||||||||||||||||||
1395 | { | - | ||||||||||||||||||
1396 | text_mode = Untranslated; | - | ||||||||||||||||||
1397 | if (fl.contains('t'))
| 0 | ||||||||||||||||||
1398 | text_mode = TranslateIn; never executed: text_mode = TranslateIn; | 0 | ||||||||||||||||||
1399 | else if (fl.contains('T'))
| 0 | ||||||||||||||||||
1400 | text_mode = TranslateInOut; never executed: text_mode = TranslateInOut; | 0 | ||||||||||||||||||
1401 | obsolete = fl.contains('O'); | - | ||||||||||||||||||
1402 | read_picture = r; | - | ||||||||||||||||||
1403 | write_picture = w; | - | ||||||||||||||||||
1404 | } never executed: end of block | 0 | ||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | typedef QList<QPictureHandler *> QPHList; | - | ||||||||||||||||||
1407 | Q_GLOBAL_STATIC(QPHList, pictureHandlers) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
1408 | - | |||||||||||||||||||
1409 | void qt_init_picture_plugins() | - | ||||||||||||||||||
1410 | { | - | ||||||||||||||||||
1411 | #ifndef QT_NO_LIBRARY | - | ||||||||||||||||||
1412 | typedef QMultiMap<int, QString> PluginKeyMap; | - | ||||||||||||||||||
1413 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; | - | ||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | static QBasicMutex mutex; | - | ||||||||||||||||||
1416 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
1417 | static QFactoryLoader loader(QPictureFormatInterface_iid, | - | ||||||||||||||||||
1418 | QStringLiteral("/pictureformats")); | - | ||||||||||||||||||
1419 | - | |||||||||||||||||||
1420 | const PluginKeyMap keyMap = loader.keyMap(); | - | ||||||||||||||||||
1421 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); | - | ||||||||||||||||||
1422 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
| 0 | ||||||||||||||||||
1423 | if (QPictureFormatPlugin *format = qobject_cast<QPictureFormatPlugin*>(loader.instance(it.key())))
| 0 | ||||||||||||||||||
1424 | format->installIOHandler(it.value()); never executed: format->installIOHandler(it.value()); | 0 | ||||||||||||||||||
1425 | } never executed: end of block | 0 | ||||||||||||||||||
1426 | #endif | - | ||||||||||||||||||
1427 | } never executed: end of block | 0 | ||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | static void cleanup() | - | ||||||||||||||||||
1430 | { | - | ||||||||||||||||||
1431 | // make sure that picture handlers are delete before plugin manager | - | ||||||||||||||||||
1432 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1433 | qDeleteAll(*list); | - | ||||||||||||||||||
1434 | list->clear(); | - | ||||||||||||||||||
1435 | } never executed: end of block | 0 | ||||||||||||||||||
1436 | } never executed: end of block | 0 | ||||||||||||||||||
1437 | - | |||||||||||||||||||
1438 | void qt_init_picture_handlers() // initialize picture handlers | - | ||||||||||||||||||
1439 | { | - | ||||||||||||||||||
1440 | static QBasicAtomicInt done = Q_BASIC_ATOMIC_INITIALIZER(0); | - | ||||||||||||||||||
1441 | if (done.testAndSetRelaxed(0, 1)) {
| 0 | ||||||||||||||||||
1442 | qAddPostRoutine(cleanup); | - | ||||||||||||||||||
1443 | } never executed: end of block | 0 | ||||||||||||||||||
1444 | } never executed: end of block | 0 | ||||||||||||||||||
1445 | - | |||||||||||||||||||
1446 | static QPictureHandler *get_picture_handler(const char *format) | - | ||||||||||||||||||
1447 | { // get pointer to handler | - | ||||||||||||||||||
1448 | qt_init_picture_handlers(); | - | ||||||||||||||||||
1449 | qt_init_picture_plugins(); | - | ||||||||||||||||||
1450 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1451 | for (int i = 0; i < list->size(); ++i) {
| 0 | ||||||||||||||||||
1452 | if (list->at(i)->format == format)
| 0 | ||||||||||||||||||
1453 | return list->at(i); never executed: return list->at(i); | 0 | ||||||||||||||||||
1454 | } never executed: end of block | 0 | ||||||||||||||||||
1455 | } never executed: end of block | 0 | ||||||||||||||||||
1456 | return 0; // no such handler never executed: return 0; | 0 | ||||||||||||||||||
1457 | } | - | ||||||||||||||||||
1458 | - | |||||||||||||||||||
1459 | - | |||||||||||||||||||
1460 | /*! | - | ||||||||||||||||||
1461 | Defines a picture I/O handler for the picture format called \a | - | ||||||||||||||||||
1462 | format, which is recognized using the regular | - | ||||||||||||||||||
1463 | expression defined in \a header, read using \a readPicture and | - | ||||||||||||||||||
1464 | written using \a writePicture. | - | ||||||||||||||||||
1465 | - | |||||||||||||||||||
1466 | \a flags is a string of single-character flags for this format. | - | ||||||||||||||||||
1467 | The only flag defined currently is T (upper case), so the only | - | ||||||||||||||||||
1468 | legal value for \a flags are "T" and the empty string. The "T" | - | ||||||||||||||||||
1469 | flag means that the picture file is a text file, and Qt should treat | - | ||||||||||||||||||
1470 | all newline conventions as equivalent. (XPM files and some PPM | - | ||||||||||||||||||
1471 | files are text files for example.) | - | ||||||||||||||||||
1472 | - | |||||||||||||||||||
1473 | \a format is used to select a handler to write a QPicture; \a header | - | ||||||||||||||||||
1474 | is used to select a handler to read an picture file. | - | ||||||||||||||||||
1475 | - | |||||||||||||||||||
1476 | If \a readPicture is a null pointer, the QPictureIO will not be able | - | ||||||||||||||||||
1477 | to read pictures in \a format. If \a writePicture is a null pointer, | - | ||||||||||||||||||
1478 | the QPictureIO will not be able to write pictures in \a format. If | - | ||||||||||||||||||
1479 | both are null, the QPictureIO object is valid but useless. | - | ||||||||||||||||||
1480 | - | |||||||||||||||||||
1481 | Example: | - | ||||||||||||||||||
1482 | \snippet picture/picture.cpp 6 | - | ||||||||||||||||||
1483 | \codeline | - | ||||||||||||||||||
1484 | \snippet picture/picture.cpp 7 | - | ||||||||||||||||||
1485 | \codeline | - | ||||||||||||||||||
1486 | \snippet picture/picture.cpp 8 | - | ||||||||||||||||||
1487 | - | |||||||||||||||||||
1488 | Before the regular expression test, all the 0 bytes in the file header are | - | ||||||||||||||||||
1489 | converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp | - | ||||||||||||||||||
1490 | could not handle 0 bytes in strings. | - | ||||||||||||||||||
1491 | - | |||||||||||||||||||
1492 | The regexp is only applied on the first 14 bytes of the file. | - | ||||||||||||||||||
1493 | - | |||||||||||||||||||
1494 | (Note that if one handlerIO supports writing a format and another | - | ||||||||||||||||||
1495 | supports reading it, Qt supports both reading and writing. If two | - | ||||||||||||||||||
1496 | handlers support the same operation, Qt chooses one arbitrarily.) | - | ||||||||||||||||||
1497 | */ | - | ||||||||||||||||||
1498 | - | |||||||||||||||||||
1499 | void QPictureIO::defineIOHandler(const char *format, | - | ||||||||||||||||||
1500 | const char *header, | - | ||||||||||||||||||
1501 | const char *flags, | - | ||||||||||||||||||
1502 | picture_io_handler readPicture, | - | ||||||||||||||||||
1503 | picture_io_handler writePicture) | - | ||||||||||||||||||
1504 | { | - | ||||||||||||||||||
1505 | qt_init_picture_handlers(); | - | ||||||||||||||||||
1506 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1507 | QPictureHandler *p; | - | ||||||||||||||||||
1508 | p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture); | - | ||||||||||||||||||
1509 | list->prepend(p); | - | ||||||||||||||||||
1510 | } never executed: end of block | 0 | ||||||||||||||||||
1511 | } never executed: end of block | 0 | ||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | /***************************************************************************** | - | ||||||||||||||||||
1515 | QPictureIO normal member functions | - | ||||||||||||||||||
1516 | *****************************************************************************/ | - | ||||||||||||||||||
1517 | - | |||||||||||||||||||
1518 | /*! | - | ||||||||||||||||||
1519 | Returns the picture currently set. | - | ||||||||||||||||||
1520 | - | |||||||||||||||||||
1521 | \sa setPicture() | - | ||||||||||||||||||
1522 | */ | - | ||||||||||||||||||
1523 | const never executed: QPicture &QPictureIO::picture() const { return d->pi; }return d->pi; never executed: return d->pi; | 0 | ||||||||||||||||||
1524 | - | |||||||||||||||||||
1525 | /*! | - | ||||||||||||||||||
1526 | Returns the picture's IO status. A non-zero value indicates an | - | ||||||||||||||||||
1527 | error, whereas 0 means that the IO operation was successful. | - | ||||||||||||||||||
1528 | - | |||||||||||||||||||
1529 | \sa setStatus() | - | ||||||||||||||||||
1530 | */ | - | ||||||||||||||||||
1531 | int QPictureIO::status() const { return d->iostat; } never executed: return d->iostat; | 0 | ||||||||||||||||||
1532 | - | |||||||||||||||||||
1533 | /*! | - | ||||||||||||||||||
1534 | Returns the picture format string or 0 if no format has been | - | ||||||||||||||||||
1535 | explicitly set. | - | ||||||||||||||||||
1536 | */ | - | ||||||||||||||||||
1537 | const never executed: char *QPictureIO::format() const { return d->frmt; }return d->frmt; never executed: return d->frmt; | 0 | ||||||||||||||||||
1538 | - | |||||||||||||||||||
1539 | /*! | - | ||||||||||||||||||
1540 | Returns the IO device currently set. | - | ||||||||||||||||||
1541 | - | |||||||||||||||||||
1542 | \sa setIODevice() | - | ||||||||||||||||||
1543 | */ | - | ||||||||||||||||||
1544 | QIODevice *QPictureIO::ioDevice() const { return d->iodev; } never executed: return d->iodev; | 0 | ||||||||||||||||||
1545 | - | |||||||||||||||||||
1546 | /*! | - | ||||||||||||||||||
1547 | Returns the file name currently set. | - | ||||||||||||||||||
1548 | - | |||||||||||||||||||
1549 | \sa setFileName() | - | ||||||||||||||||||
1550 | */ | - | ||||||||||||||||||
1551 | QString QPictureIO::fileName() const { return d->fname; } never executed: return d->fname; | 0 | ||||||||||||||||||
1552 | - | |||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | /*! | - | ||||||||||||||||||
1555 | Returns the picture description string. | - | ||||||||||||||||||
1556 | - | |||||||||||||||||||
1557 | \sa setDescription() | - | ||||||||||||||||||
1558 | */ | - | ||||||||||||||||||
1559 | QString QPictureIO::description() const { return d->descr; } never executed: return d->descr; | 0 | ||||||||||||||||||
1560 | - | |||||||||||||||||||
1561 | /*! | - | ||||||||||||||||||
1562 | Sets the picture to \a picture. | - | ||||||||||||||||||
1563 | - | |||||||||||||||||||
1564 | \sa picture() | - | ||||||||||||||||||
1565 | */ | - | ||||||||||||||||||
1566 | void QPictureIO::setPicture(const QPicture &picture) | - | ||||||||||||||||||
1567 | { | - | ||||||||||||||||||
1568 | d->pi = picture; | - | ||||||||||||||||||
1569 | } never executed: end of block | 0 | ||||||||||||||||||
1570 | - | |||||||||||||||||||
1571 | /*! | - | ||||||||||||||||||
1572 | Sets the picture IO status to \a status. A non-zero value indicates | - | ||||||||||||||||||
1573 | an error, whereas 0 means that the IO operation was successful. | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | \sa status() | - | ||||||||||||||||||
1576 | */ | - | ||||||||||||||||||
1577 | void QPictureIO::setStatus(int status) | - | ||||||||||||||||||
1578 | { | - | ||||||||||||||||||
1579 | d->iostat = status; | - | ||||||||||||||||||
1580 | } never executed: end of block | 0 | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | /*! | - | ||||||||||||||||||
1583 | Sets the picture format to \a format for the picture to be read or | - | ||||||||||||||||||
1584 | written. | - | ||||||||||||||||||
1585 | - | |||||||||||||||||||
1586 | It is necessary to specify a format before writing an picture, but | - | ||||||||||||||||||
1587 | it is not necessary to specify a format before reading an picture. | - | ||||||||||||||||||
1588 | - | |||||||||||||||||||
1589 | If no format has been set, Qt guesses the picture format before | - | ||||||||||||||||||
1590 | reading it. If a format is set the picture will only be read if it | - | ||||||||||||||||||
1591 | has that format. | - | ||||||||||||||||||
1592 | - | |||||||||||||||||||
1593 | \sa read(), write(), format() | - | ||||||||||||||||||
1594 | */ | - | ||||||||||||||||||
1595 | void QPictureIO::setFormat(const char *format) | - | ||||||||||||||||||
1596 | { | - | ||||||||||||||||||
1597 | d->frmt = format; | - | ||||||||||||||||||
1598 | } never executed: end of block | 0 | ||||||||||||||||||
1599 | - | |||||||||||||||||||
1600 | /*! | - | ||||||||||||||||||
1601 | Sets the IO device to be used for reading or writing an picture. | - | ||||||||||||||||||
1602 | - | |||||||||||||||||||
1603 | Setting the IO device allows pictures to be read/written to any | - | ||||||||||||||||||
1604 | block-oriented QIODevice. | - | ||||||||||||||||||
1605 | - | |||||||||||||||||||
1606 | If \a ioDevice is not null, this IO device will override file name | - | ||||||||||||||||||
1607 | settings. | - | ||||||||||||||||||
1608 | - | |||||||||||||||||||
1609 | \sa setFileName() | - | ||||||||||||||||||
1610 | */ | - | ||||||||||||||||||
1611 | void QPictureIO::setIODevice(QIODevice *ioDevice) | - | ||||||||||||||||||
1612 | { | - | ||||||||||||||||||
1613 | d->iodev = ioDevice; | - | ||||||||||||||||||
1614 | } never executed: end of block | 0 | ||||||||||||||||||
1615 | - | |||||||||||||||||||
1616 | /*! | - | ||||||||||||||||||
1617 | Sets the name of the file to read or write an picture from to \a | - | ||||||||||||||||||
1618 | fileName. | - | ||||||||||||||||||
1619 | - | |||||||||||||||||||
1620 | \sa setIODevice() | - | ||||||||||||||||||
1621 | */ | - | ||||||||||||||||||
1622 | void QPictureIO::setFileName(const QString &fileName) | - | ||||||||||||||||||
1623 | { | - | ||||||||||||||||||
1624 | d->fname = fileName; | - | ||||||||||||||||||
1625 | } never executed: end of block | 0 | ||||||||||||||||||
1626 | - | |||||||||||||||||||
1627 | /*! | - | ||||||||||||||||||
1628 | Returns the quality of the written picture, related to the | - | ||||||||||||||||||
1629 | compression ratio. | - | ||||||||||||||||||
1630 | - | |||||||||||||||||||
1631 | \sa setQuality(), QPicture::save() | - | ||||||||||||||||||
1632 | */ | - | ||||||||||||||||||
1633 | int QPictureIO::quality() const | - | ||||||||||||||||||
1634 | { | - | ||||||||||||||||||
1635 | return d->quality; never executed: return d->quality; | 0 | ||||||||||||||||||
1636 | } | - | ||||||||||||||||||
1637 | - | |||||||||||||||||||
1638 | /*! | - | ||||||||||||||||||
1639 | Sets the quality of the written picture to \a q, related to the | - | ||||||||||||||||||
1640 | compression ratio. | - | ||||||||||||||||||
1641 | - | |||||||||||||||||||
1642 | \a q must be in the range -1..100. Specify 0 to obtain small | - | ||||||||||||||||||
1643 | compressed files, 100 for large uncompressed files. (-1 signifies | - | ||||||||||||||||||
1644 | the default compression.) | - | ||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | \sa quality(), QPicture::save() | - | ||||||||||||||||||
1647 | */ | - | ||||||||||||||||||
1648 | - | |||||||||||||||||||
1649 | void QPictureIO::setQuality(int q) | - | ||||||||||||||||||
1650 | { | - | ||||||||||||||||||
1651 | d->quality = q; | - | ||||||||||||||||||
1652 | } never executed: end of block | 0 | ||||||||||||||||||
1653 | - | |||||||||||||||||||
1654 | /*! | - | ||||||||||||||||||
1655 | Returns the picture's parameters string. | - | ||||||||||||||||||
1656 | - | |||||||||||||||||||
1657 | \sa setParameters() | - | ||||||||||||||||||
1658 | */ | - | ||||||||||||||||||
1659 | - | |||||||||||||||||||
1660 | const char *QPictureIO::parameters() const | - | ||||||||||||||||||
1661 | { | - | ||||||||||||||||||
1662 | return d->parameters; never executed: return d->parameters; | 0 | ||||||||||||||||||
1663 | } | - | ||||||||||||||||||
1664 | - | |||||||||||||||||||
1665 | /*! | - | ||||||||||||||||||
1666 | Sets the picture's parameter string to \a parameters. This is for | - | ||||||||||||||||||
1667 | picture handlers that require special parameters. | - | ||||||||||||||||||
1668 | - | |||||||||||||||||||
1669 | Although the current picture formats supported by Qt ignore the | - | ||||||||||||||||||
1670 | parameters string, it may be used in future extensions or by | - | ||||||||||||||||||
1671 | contributions (for example, JPEG). | - | ||||||||||||||||||
1672 | - | |||||||||||||||||||
1673 | \sa parameters() | - | ||||||||||||||||||
1674 | */ | - | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | void QPictureIO::setParameters(const char *parameters) | - | ||||||||||||||||||
1677 | { | - | ||||||||||||||||||
1678 | if (d->parameters)
| 0 | ||||||||||||||||||
1679 | delete [] d->parameters; never executed: delete [] d->parameters; | 0 | ||||||||||||||||||
1680 | d->parameters = qstrdup(parameters); | - | ||||||||||||||||||
1681 | } never executed: end of block | 0 | ||||||||||||||||||
1682 | - | |||||||||||||||||||
1683 | /*! | - | ||||||||||||||||||
1684 | Sets the gamma value at which the picture will be viewed to \a | - | ||||||||||||||||||
1685 | gamma. If the picture format stores a gamma value for which the | - | ||||||||||||||||||
1686 | picture is intended to be used, then this setting will be used to | - | ||||||||||||||||||
1687 | modify the picture. Setting to 0.0 will disable gamma correction | - | ||||||||||||||||||
1688 | (i.e. any specification in the file will be ignored). | - | ||||||||||||||||||
1689 | - | |||||||||||||||||||
1690 | The default value is 0.0. | - | ||||||||||||||||||
1691 | - | |||||||||||||||||||
1692 | \sa gamma() | - | ||||||||||||||||||
1693 | */ | - | ||||||||||||||||||
1694 | void QPictureIO::setGamma(float gamma) | - | ||||||||||||||||||
1695 | { | - | ||||||||||||||||||
1696 | d->gamma=gamma; | - | ||||||||||||||||||
1697 | } never executed: end of block | 0 | ||||||||||||||||||
1698 | - | |||||||||||||||||||
1699 | /*! | - | ||||||||||||||||||
1700 | Returns the gamma value at which the picture will be viewed. | - | ||||||||||||||||||
1701 | - | |||||||||||||||||||
1702 | \sa setGamma() | - | ||||||||||||||||||
1703 | */ | - | ||||||||||||||||||
1704 | float QPictureIO::gamma() const | - | ||||||||||||||||||
1705 | { | - | ||||||||||||||||||
1706 | return d->gamma; never executed: return d->gamma; | 0 | ||||||||||||||||||
1707 | } | - | ||||||||||||||||||
1708 | - | |||||||||||||||||||
1709 | /*! | - | ||||||||||||||||||
1710 | Sets the picture description string for picture handlers that support | - | ||||||||||||||||||
1711 | picture descriptions to \a description. | - | ||||||||||||||||||
1712 | - | |||||||||||||||||||
1713 | Currently, no picture format supported by Qt uses the description | - | ||||||||||||||||||
1714 | string. | - | ||||||||||||||||||
1715 | */ | - | ||||||||||||||||||
1716 | - | |||||||||||||||||||
1717 | void QPictureIO::setDescription(const QString &description) | - | ||||||||||||||||||
1718 | { | - | ||||||||||||||||||
1719 | d->descr = description; | - | ||||||||||||||||||
1720 | } never executed: end of block | 0 | ||||||||||||||||||
1721 | - | |||||||||||||||||||
1722 | - | |||||||||||||||||||
1723 | /*! | - | ||||||||||||||||||
1724 | Returns a string that specifies the picture format of the file \a | - | ||||||||||||||||||
1725 | fileName, or null if the file cannot be read or if the format is | - | ||||||||||||||||||
1726 | not recognized. | - | ||||||||||||||||||
1727 | */ | - | ||||||||||||||||||
1728 | - | |||||||||||||||||||
1729 | QByteArray QPictureIO::pictureFormat(const QString &fileName) | - | ||||||||||||||||||
1730 | { | - | ||||||||||||||||||
1731 | QFile file(fileName); | - | ||||||||||||||||||
1732 | QByteArray format; | - | ||||||||||||||||||
1733 | if (!file.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
1734 | return format; never executed: return format; | 0 | ||||||||||||||||||
1735 | format = pictureFormat(&file); | - | ||||||||||||||||||
1736 | file.close(); | - | ||||||||||||||||||
1737 | return format; never executed: return format; | 0 | ||||||||||||||||||
1738 | } | - | ||||||||||||||||||
1739 | - | |||||||||||||||||||
1740 | /*! | - | ||||||||||||||||||
1741 | \overload | - | ||||||||||||||||||
1742 | - | |||||||||||||||||||
1743 | Returns a string that specifies the picture format of the picture read | - | ||||||||||||||||||
1744 | from IO device \a d, or 0 if the device cannot be read or if the | - | ||||||||||||||||||
1745 | format is not recognized. | - | ||||||||||||||||||
1746 | - | |||||||||||||||||||
1747 | Make sure that \a d is at the right position in the device (for | - | ||||||||||||||||||
1748 | example, at the beginning of the file). | - | ||||||||||||||||||
1749 | - | |||||||||||||||||||
1750 | \sa QIODevice::pos() | - | ||||||||||||||||||
1751 | */ | - | ||||||||||||||||||
1752 | - | |||||||||||||||||||
1753 | QByteArray QPictureIO::pictureFormat(QIODevice *d) | - | ||||||||||||||||||
1754 | { | - | ||||||||||||||||||
1755 | // if you change this change the documentation for defineIOHandler() | - | ||||||||||||||||||
1756 | const int buflen = 14; | - | ||||||||||||||||||
1757 | - | |||||||||||||||||||
1758 | char buf[buflen]; | - | ||||||||||||||||||
1759 | char buf2[buflen]; | - | ||||||||||||||||||
1760 | qt_init_picture_handlers(); | - | ||||||||||||||||||
1761 | qt_init_picture_plugins(); | - | ||||||||||||||||||
1762 | int pos = d->pos(); // save position | - | ||||||||||||||||||
1763 | int rdlen = d->read(buf, buflen); // read a few bytes | - | ||||||||||||||||||
1764 | - | |||||||||||||||||||
1765 | QByteArray format; | - | ||||||||||||||||||
1766 | if (rdlen != buflen)
| 0 | ||||||||||||||||||
1767 | return format; never executed: return format; | 0 | ||||||||||||||||||
1768 | - | |||||||||||||||||||
1769 | memcpy(buf2, buf, buflen); | - | ||||||||||||||||||
1770 | - | |||||||||||||||||||
1771 | for (int n = 0; n < rdlen; n++)
| 0 | ||||||||||||||||||
1772 | if (buf[n] == '\0')
| 0 | ||||||||||||||||||
1773 | buf[n] = '\001'; never executed: buf[n] = '\001'; | 0 | ||||||||||||||||||
1774 | if (rdlen > 0) {
| 0 | ||||||||||||||||||
1775 | buf[rdlen - 1] = '\0'; | - | ||||||||||||||||||
1776 | QString bufStr = QString::fromLatin1(buf); | - | ||||||||||||||||||
1777 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1778 | for (int i = 0; i < list->size(); ++i) {
| 0 | ||||||||||||||||||
1779 | if (list->at(i)->header.indexIn(bufStr) != -1) { // try match with headers
| 0 | ||||||||||||||||||
1780 | format = list->at(i)->format; | - | ||||||||||||||||||
1781 | break; never executed: break; | 0 | ||||||||||||||||||
1782 | } | - | ||||||||||||||||||
1783 | } never executed: end of block | 0 | ||||||||||||||||||
1784 | } never executed: end of block | 0 | ||||||||||||||||||
1785 | } never executed: end of block | 0 | ||||||||||||||||||
1786 | d->seek(pos); // restore position | - | ||||||||||||||||||
1787 | return format; never executed: return format; | 0 | ||||||||||||||||||
1788 | } | - | ||||||||||||||||||
1789 | - | |||||||||||||||||||
1790 | /*! | - | ||||||||||||||||||
1791 | Returns a sorted list of picture formats that are supported for | - | ||||||||||||||||||
1792 | picture input. | - | ||||||||||||||||||
1793 | */ | - | ||||||||||||||||||
1794 | QList<QByteArray> QPictureIO::inputFormats() | - | ||||||||||||||||||
1795 | { | - | ||||||||||||||||||
1796 | QList<QByteArray> result; | - | ||||||||||||||||||
1797 | - | |||||||||||||||||||
1798 | qt_init_picture_handlers(); | - | ||||||||||||||||||
1799 | qt_init_picture_plugins(); | - | ||||||||||||||||||
1800 | - | |||||||||||||||||||
1801 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1802 | for (int i = 0; i < list->size(); ++i) {
| 0 | ||||||||||||||||||
1803 | QPictureHandler *p = list->at(i); | - | ||||||||||||||||||
1804 | if (p->read_picture && !p->obsolete && !result.contains(p->format))
| 0 | ||||||||||||||||||
1805 | result.append(p->format); never executed: result.append(p->format); | 0 | ||||||||||||||||||
1806 | } never executed: end of block | 0 | ||||||||||||||||||
1807 | } never executed: end of block | 0 | ||||||||||||||||||
1808 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
1809 | - | |||||||||||||||||||
1810 | return result; never executed: return result; | 0 | ||||||||||||||||||
1811 | } | - | ||||||||||||||||||
1812 | - | |||||||||||||||||||
1813 | /*! | - | ||||||||||||||||||
1814 | Returns a sorted list of picture formats that are supported for | - | ||||||||||||||||||
1815 | picture output. | - | ||||||||||||||||||
1816 | */ | - | ||||||||||||||||||
1817 | QList<QByteArray> QPictureIO::outputFormats() | - | ||||||||||||||||||
1818 | { | - | ||||||||||||||||||
1819 | qt_init_picture_handlers(); | - | ||||||||||||||||||
1820 | qt_init_picture_plugins(); | - | ||||||||||||||||||
1821 | - | |||||||||||||||||||
1822 | QList<QByteArray> result; | - | ||||||||||||||||||
1823 | if (QPHList *list = pictureHandlers()) {
| 0 | ||||||||||||||||||
1824 | for (int i = 0; i < list->size(); ++i) {
| 0 | ||||||||||||||||||
1825 | QPictureHandler *p = list->at(i); | - | ||||||||||||||||||
1826 | if (p->write_picture && !p->obsolete && !result.contains(p->format))
| 0 | ||||||||||||||||||
1827 | result.append(p->format); never executed: result.append(p->format); | 0 | ||||||||||||||||||
1828 | } never executed: end of block | 0 | ||||||||||||||||||
1829 | } never executed: end of block | 0 | ||||||||||||||||||
1830 | return result; never executed: return result; | 0 | ||||||||||||||||||
1831 | } | - | ||||||||||||||||||
1832 | - | |||||||||||||||||||
1833 | - | |||||||||||||||||||
1834 | - | |||||||||||||||||||
1835 | /*! | - | ||||||||||||||||||
1836 | Reads an picture into memory and returns \c true if the picture was | - | ||||||||||||||||||
1837 | successfully read; otherwise returns \c false. | - | ||||||||||||||||||
1838 | - | |||||||||||||||||||
1839 | Before reading an picture you must set an IO device or a file name. | - | ||||||||||||||||||
1840 | If both an IO device and a file name have been set, the IO device | - | ||||||||||||||||||
1841 | will be used. | - | ||||||||||||||||||
1842 | - | |||||||||||||||||||
1843 | Setting the picture file format string is optional. | - | ||||||||||||||||||
1844 | - | |||||||||||||||||||
1845 | Note that this function does \e not set the \l{format()}{format} used to read the picture. If you need that | - | ||||||||||||||||||
1846 | information, use the pictureFormat() static functions. | - | ||||||||||||||||||
1847 | - | |||||||||||||||||||
1848 | Example: | - | ||||||||||||||||||
1849 | - | |||||||||||||||||||
1850 | \snippet picture/picture.cpp 4 | - | ||||||||||||||||||
1851 | - | |||||||||||||||||||
1852 | \sa setIODevice(), setFileName(), setFormat(), write(), QPixmap::load() | - | ||||||||||||||||||
1853 | */ | - | ||||||||||||||||||
1854 | bool QPictureIO::read() | - | ||||||||||||||||||
1855 | { | - | ||||||||||||||||||
1856 | QFile file; | - | ||||||||||||||||||
1857 | const char *picture_format; | - | ||||||||||||||||||
1858 | QPictureHandler *h; | - | ||||||||||||||||||
1859 | - | |||||||||||||||||||
1860 | if (d->iodev) { // read from io device
| 0 | ||||||||||||||||||
1861 | // ok, already open | - | ||||||||||||||||||
1862 | } else if (!d->fname.isEmpty()) { // read from file never executed: end of block
| 0 | ||||||||||||||||||
1863 | file.setFileName(d->fname); | - | ||||||||||||||||||
1864 | if (!file.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
1865 | return false; // cannot open file never executed: return false; | 0 | ||||||||||||||||||
1866 | d->iodev = &file; | - | ||||||||||||||||||
1867 | } else { // no file name or io device never executed: end of block | 0 | ||||||||||||||||||
1868 | return false; never executed: return false; | 0 | ||||||||||||||||||
1869 | } | - | ||||||||||||||||||
1870 | if (d->frmt.isEmpty()) {
| 0 | ||||||||||||||||||
1871 | // Try to guess format | - | ||||||||||||||||||
1872 | picture_format = pictureFormat(d->iodev); // get picture format | - | ||||||||||||||||||
1873 | if (!picture_format) {
| 0 | ||||||||||||||||||
1874 | if (file.isOpen()) { // unknown format
| 0 | ||||||||||||||||||
1875 | file.close(); | - | ||||||||||||||||||
1876 | d->iodev = 0; | - | ||||||||||||||||||
1877 | } never executed: end of block | 0 | ||||||||||||||||||
1878 | return false; never executed: return false; | 0 | ||||||||||||||||||
1879 | } | - | ||||||||||||||||||
1880 | } else { never executed: end of block | 0 | ||||||||||||||||||
1881 | picture_format = d->frmt; | - | ||||||||||||||||||
1882 | } never executed: end of block | 0 | ||||||||||||||||||
1883 | - | |||||||||||||||||||
1884 | h = get_picture_handler(picture_format); | - | ||||||||||||||||||
1885 | if (file.isOpen()) {
| 0 | ||||||||||||||||||
1886 | #if !defined(Q_OS_UNIX) | - | ||||||||||||||||||
1887 | if (h && h->text_mode) { // reopen in translated mode | - | ||||||||||||||||||
1888 | file.close(); | - | ||||||||||||||||||
1889 | file.open(QIODevice::ReadOnly | QIODevice::Text); | - | ||||||||||||||||||
1890 | } | - | ||||||||||||||||||
1891 | else | - | ||||||||||||||||||
1892 | #endif | - | ||||||||||||||||||
1893 | file.seek(0); // position to start | - | ||||||||||||||||||
1894 | } never executed: end of block | 0 | ||||||||||||||||||
1895 | d->iostat = 1; // assume error | - | ||||||||||||||||||
1896 | - | |||||||||||||||||||
1897 | if (h && h->read_picture)
| 0 | ||||||||||||||||||
1898 | (*h->read_picture)(this); never executed: (*h->read_picture)(this); | 0 | ||||||||||||||||||
1899 | - | |||||||||||||||||||
1900 | if (file.isOpen()) { // picture was read using file
| 0 | ||||||||||||||||||
1901 | file.close(); | - | ||||||||||||||||||
1902 | d->iodev = 0; | - | ||||||||||||||||||
1903 | } never executed: end of block | 0 | ||||||||||||||||||
1904 | return d->iostat == 0; // picture successfully read? never executed: return d->iostat == 0; | 0 | ||||||||||||||||||
1905 | } | - | ||||||||||||||||||
1906 | - | |||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | /*! | - | ||||||||||||||||||
1909 | Writes an picture to an IO device and returns \c true if the picture was | - | ||||||||||||||||||
1910 | successfully written; otherwise returns \c false. | - | ||||||||||||||||||
1911 | - | |||||||||||||||||||
1912 | Before writing an picture you must set an IO device or a file name. | - | ||||||||||||||||||
1913 | If both an IO device and a file name have been set, the IO device | - | ||||||||||||||||||
1914 | will be used. | - | ||||||||||||||||||
1915 | - | |||||||||||||||||||
1916 | The picture will be written using the specified picture format. | - | ||||||||||||||||||
1917 | - | |||||||||||||||||||
1918 | Example: | - | ||||||||||||||||||
1919 | \snippet picture/picture.cpp 5 | - | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | \sa setIODevice(), setFileName(), setFormat(), read(), QPixmap::save() | - | ||||||||||||||||||
1922 | */ | - | ||||||||||||||||||
1923 | bool QPictureIO::write() | - | ||||||||||||||||||
1924 | { | - | ||||||||||||||||||
1925 | if (d->frmt.isEmpty())
| 0 | ||||||||||||||||||
1926 | return false; never executed: return false; | 0 | ||||||||||||||||||
1927 | QPictureHandler *h = get_picture_handler(d->frmt); | - | ||||||||||||||||||
1928 | if (!h || !h->write_picture) {
| 0 | ||||||||||||||||||
1929 | qWarning("QPictureIO::write: No such picture format handler: %s", | - | ||||||||||||||||||
1930 | format()); | - | ||||||||||||||||||
1931 | return false; never executed: return false; | 0 | ||||||||||||||||||
1932 | } | - | ||||||||||||||||||
1933 | QFile file; | - | ||||||||||||||||||
1934 | if (!d->iodev && !d->fname.isEmpty()) {
| 0 | ||||||||||||||||||
1935 | file.setFileName(d->fname); | - | ||||||||||||||||||
1936 | bool translate = h->text_mode==QPictureHandler::TranslateInOut; | - | ||||||||||||||||||
1937 | QIODevice::OpenMode fmode = translate ? QIODevice::WriteOnly | QIODevice::Text : QIODevice::OpenMode(QIODevice::WriteOnly);
| 0 | ||||||||||||||||||
1938 | if (!file.open(fmode)) // couldn't create file
| 0 | ||||||||||||||||||
1939 | return false; never executed: return false; | 0 | ||||||||||||||||||
1940 | d->iodev = &file; | - | ||||||||||||||||||
1941 | } never executed: end of block | 0 | ||||||||||||||||||
1942 | d->iostat = 1; | - | ||||||||||||||||||
1943 | (*h->write_picture)(this); | - | ||||||||||||||||||
1944 | if (file.isOpen()) { // picture was written using file
| 0 | ||||||||||||||||||
1945 | file.close(); | - | ||||||||||||||||||
1946 | d->iodev = 0; | - | ||||||||||||||||||
1947 | } never executed: end of block | 0 | ||||||||||||||||||
1948 | return d->iostat == 0; // picture successfully written? never executed: return d->iostat == 0; | 0 | ||||||||||||||||||
1949 | } | - | ||||||||||||||||||
1950 | #endif //QT_NO_PICTUREIO | - | ||||||||||||||||||
1951 | - | |||||||||||||||||||
1952 | QT_END_NAMESPACE | - | ||||||||||||||||||
1953 | - | |||||||||||||||||||
1954 | #endif // QT_NO_PICTURE | - | ||||||||||||||||||
1955 | - | |||||||||||||||||||
1956 | /*! | - | ||||||||||||||||||
1957 | \typedef QPicture::DataPtr | - | ||||||||||||||||||
1958 | \internal | - | ||||||||||||||||||
1959 | */ | - | ||||||||||||||||||
1960 | - | |||||||||||||||||||
1961 | /*! | - | ||||||||||||||||||
1962 | \fn DataPtr &QPicture::data_ptr() | - | ||||||||||||||||||
1963 | \internal | - | ||||||||||||||||||
1964 | */ | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |