OpenCoverage

qpicture.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9