Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
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 | | - |
62 | QT_BEGIN_NAMESPACE | - |
63 | | - |
64 | void 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 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | | - |
117 | | - |
118 | const char *qt_mfhdr_tag = "QPIC"; | - |
119 | static const quint16 mfhdr_maj = QDataStream::Qt_DefaultCompiledVersion; | - |
120 | static const quint16 mfhdr_min = 0; | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | | - |
132 | | - |
133 | | - |
134 | | - |
135 | | - |
136 | | - |
137 | QPicture::QPicture(int formatVersion) | - |
138 | : QPaintDevice(), | - |
139 | d_ptr(new QPicturePrivate) | - |
140 | { | - |
141 | Q_D(QPicture); | - |
142 | | - |
143 | if (formatVersion == 0) | - |
144 | qWarning("QPicture: invalid format version 0"); | - |
145 | | - |
146 | | - |
147 | if (formatVersion > 0 && formatVersion != (int)mfhdr_maj) { | - |
148 | d->formatMajor = formatVersion; | - |
149 | d->formatMinor = 0; | - |
150 | d->formatOk = false; | - |
151 | } else { | - |
152 | d->resetFormat(); | - |
153 | } | - |
154 | } | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | QPicture::QPicture(const QPicture &pic) | - |
163 | : QPaintDevice(), d_ptr(pic.d_ptr) | - |
164 | { | - |
165 | } | - |
166 | | - |
167 | | - |
168 | QPicture::QPicture(QPicturePrivate &dptr) | - |
169 | : QPaintDevice(), | - |
170 | d_ptr(&dptr) | - |
171 | { | - |
172 | } | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | QPicture::~QPicture() | - |
178 | { | - |
179 | } | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | int QPicture::devType() const | - |
185 | { | - |
186 | return QInternal::Picture; | - |
187 | } | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | bool QPicture::isNull() const | - |
216 | { | - |
217 | return d_func()->pictb.buffer().isNull(); | - |
218 | } | - |
219 | | - |
220 | uint QPicture::size() const | - |
221 | { | - |
222 | return d_func()->pictb.buffer().size(); | - |
223 | } | - |
224 | | - |
225 | const char* QPicture::data() const | - |
226 | { | - |
227 | return d_func()->pictb.buffer(); | - |
228 | } | - |
229 | | - |
230 | void QPicture::detach() | - |
231 | { | - |
232 | d_ptr.detach(); | - |
233 | } | - |
234 | | - |
235 | bool QPicture::isDetached() const | - |
236 | { | - |
237 | return d_func()->ref.load() == 1; | - |
238 | } | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | void QPicture::setData(const char* data, uint size) | - |
248 | { | - |
249 | detach(); | - |
250 | d_func()->pictb.setData(data, size); | - |
251 | d_func()->resetFormat(); | - |
252 | } | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | bool QPicture::load(const QString &fileName, const char *format) | - |
266 | { | - |
267 | QFile f(fileName); | - |
268 | if (!f.open(QIODevice::ReadOnly)) { | - |
269 | operator=(QPicture()); | - |
270 | return false; | - |
271 | } | - |
272 | return load(&f, format); | - |
273 | } | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | bool QPicture::load(QIODevice *dev, const char *format) | - |
282 | { | - |
283 | if(format) { | - |
284 | #ifndef QT_NO_PICTUREIO | - |
285 | QPictureIO io(dev, format); | - |
286 | if (io.read()) { | - |
287 | operator=(io.picture()); | - |
288 | return true; | - |
289 | } | - |
290 | #endif | - |
291 | qWarning("QPicture::load: No such picture format: %s", format); | - |
292 | operator=(QPicture()); | - |
293 | return false; | - |
294 | } | - |
295 | | - |
296 | detach(); | - |
297 | QByteArray a = dev->readAll(); | - |
298 | | - |
299 | d_func()->pictb.setData(a); | - |
300 | return d_func()->checkFormat(); | - |
301 | } | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | | - |
312 | | - |
313 | bool QPicture::save(const QString &fileName, const char *format) | - |
314 | { | - |
315 | if (paintingActive()) { | - |
316 | qWarning("QPicture::save: still being painted on. " | - |
317 | "Call QPainter::end() first"); | - |
318 | return false; | - |
319 | } | - |
320 | | - |
321 | | - |
322 | if(format) { | - |
323 | #ifndef QT_NO_PICTUREIO | - |
324 | QPictureIO io(fileName, format); | - |
325 | bool result = io.write(); | - |
326 | if (result) { | - |
327 | operator=(io.picture()); | - |
328 | } else if (format) | - |
329 | #else | - |
330 | bool result = false; | - |
331 | #endif | - |
332 | { | - |
333 | qWarning("QPicture::save: No such picture format: %s", format); | - |
334 | } | - |
335 | return result; | - |
336 | } | - |
337 | | - |
338 | QFile f(fileName); | - |
339 | if (!f.open(QIODevice::WriteOnly)) | - |
340 | return false; | - |
341 | return save(&f, format); | - |
342 | } | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | bool QPicture::save(QIODevice *dev, const char *format) | - |
351 | { | - |
352 | if (paintingActive()) { | - |
353 | qWarning("QPicture::save: still being painted on. " | - |
354 | "Call QPainter::end() first"); | - |
355 | return false; | - |
356 | } | - |
357 | | - |
358 | if(format) { | - |
359 | #ifndef QT_NO_PICTUREIO | - |
360 | QPictureIO io(dev, format); | - |
361 | bool result = io.write(); | - |
362 | if (result) { | - |
363 | operator=(io.picture()); | - |
364 | } else if (format) | - |
365 | #else | - |
366 | bool result = false; | - |
367 | #endif | - |
368 | { | - |
369 | qWarning("QPicture::save: No such picture format: %s", format); | - |
370 | } | - |
371 | return result; | - |
372 | } | - |
373 | | - |
374 | dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size()); | - |
375 | return true; | - |
376 | } | - |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | QRect QPicture::boundingRect() const | - |
384 | { | - |
385 | Q_D(const QPicture); | - |
386 | | - |
387 | if (!d->override_rect.isEmpty()) | - |
388 | return d->override_rect; | - |
389 | | - |
390 | if (!d->formatOk) | - |
391 | d_ptr->checkFormat(); | - |
392 | | - |
393 | return d->brect; | - |
394 | } | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | void QPicture::setBoundingRect(const QRect &r) | - |
402 | { | - |
403 | d_func()->override_rect = r; | - |
404 | } | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | bool QPicture::play(QPainter *painter) | - |
415 | { | - |
416 | Q_D(QPicture); | - |
417 | | - |
418 | if (d->pictb.size() == 0) | - |
419 | return true; | - |
420 | | - |
421 | if (!d->formatOk && !d->checkFormat()) | - |
422 | return false; | - |
423 | | - |
424 | d->pictb.open(QIODevice::ReadOnly); | - |
425 | QDataStream s; | - |
426 | s.setDevice(&d->pictb); | - |
427 | s.device()->seek(10); | - |
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 | | - |
435 | if (d->formatMajor >= 4) { | - |
436 | qint32 dummy; | - |
437 | s >> dummy >> dummy >> dummy >> dummy; | - |
438 | } | - |
439 | s >> nrecords; | - |
440 | if (!exec(painter, s, nrecords)) { | - |
441 | qWarning("QPicture::play: Format error"); | - |
442 | d->pictb.close(); | - |
443 | return false; | - |
444 | } | - |
445 | d->pictb.close(); | - |
446 | return true; | - |
447 | } | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | class QFakeDevice : public QPaintDevice | - |
454 | { | - |
455 | public: | - |
456 | QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); } | - |
457 | void setDpiX(int dpi) { dpi_x = dpi; } | - |
458 | void setDpiY(int dpi) { dpi_y = dpi; } | - |
459 | QPaintEngine *paintEngine() const Q_DECL_OVERRIDE { return 0; } | - |
460 | int metric(PaintDeviceMetric m) const Q_DECL_OVERRIDE | - |
461 | { | - |
462 | switch(m) { | - |
463 | case PdmPhysicalDpiX: | - |
464 | case PdmDpiX: | - |
465 | return dpi_x; | - |
466 | case PdmPhysicalDpiY: | - |
467 | case PdmDpiY: | - |
468 | return dpi_y; | - |
469 | default: | - |
470 | return QPaintDevice::metric(m); | - |
471 | } | - |
472 | } | - |
473 | | - |
474 | private: | - |
475 | int dpi_x; | - |
476 | int dpi_y; | - |
477 | }; | - |
478 | | - |
479 | | - |
480 | | - |
481 | | - |
482 | | - |
483 | | - |
484 | | - |
485 | bool 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; | - |
492 | quint8 tiny_len; | - |
493 | qint32 len; | - |
494 | qint16 i_16, i1_16, i2_16; | - |
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()) { | - |
521 | s >> c; | - |
522 | s >> tiny_len; | - |
523 | if (tiny_len == 255) | - |
524 | s >> len; | - |
525 | else | - |
526 | len = tiny_len; | - |
527 | #if defined(QT_DEBUG) | - |
528 | strm_pos = s.device()->pos(); | - |
529 | #endif | - |
530 | switch (c) { | - |
531 | case QPicturePrivate::PdcNOP: | - |
532 | break; | - |
533 | case QPicturePrivate::PdcDrawPoint: | - |
534 | if (d->formatMajor <= 5) { | - |
535 | s >> ip; | - |
536 | painter->drawPoint(ip); | - |
537 | } else { | - |
538 | s >> p; | - |
539 | painter->drawPoint(p); | - |
540 | } | - |
541 | break; | - |
542 | case QPicturePrivate::PdcDrawPoints: | - |
543 | | - |
544 | | - |
545 | | - |
546 | break; | - |
547 | case QPicturePrivate::PdcDrawPath: { | - |
548 | QPainterPath path; | - |
549 | s >> path; | - |
550 | painter->drawPath(path); | - |
551 | break; | - |
552 | } | - |
553 | case QPicturePrivate::PdcDrawLine: | - |
554 | if (d->formatMajor <= 5) { | - |
555 | s >> ip1 >> ip2; | - |
556 | painter->drawLine(ip1, ip2); | - |
557 | } else { | - |
558 | s >> p1 >> p2; | - |
559 | painter->drawLine(p1, p2); | - |
560 | } | - |
561 | break; | - |
562 | case QPicturePrivate::PdcDrawRect: | - |
563 | if (d->formatMajor <= 5) { | - |
564 | s >> ir; | - |
565 | painter->drawRect(ir); | - |
566 | } else { | - |
567 | s >> r; | - |
568 | painter->drawRect(r); | - |
569 | } | - |
570 | break; | - |
571 | case QPicturePrivate::PdcDrawRoundRect: | - |
572 | if (d->formatMajor <= 5) { | - |
573 | s >> ir >> i1_16 >> i2_16; | - |
574 | painter->drawRoundedRect(ir, i1_16, i2_16, Qt::RelativeSize); | - |
575 | } else { | - |
576 | s >> r >> i1_16 >> i2_16; | - |
577 | painter->drawRoundedRect(r, i1_16, i2_16, Qt::RelativeSize); | - |
578 | } | - |
579 | break; | - |
580 | case QPicturePrivate::PdcDrawEllipse: | - |
581 | if (d->formatMajor <= 5) { | - |
582 | s >> ir; | - |
583 | painter->drawEllipse(ir); | - |
584 | } else { | - |
585 | s >> r; | - |
586 | painter->drawEllipse(r); | - |
587 | } | - |
588 | break; | - |
589 | case QPicturePrivate::PdcDrawArc: | - |
590 | if (d->formatMajor <= 5) { | - |
591 | s >> ir; | - |
592 | r = ir; | - |
593 | } else { | - |
594 | s >> r; | - |
595 | } | - |
596 | s >> i1_16 >> i2_16; | - |
597 | painter->drawArc(r, i1_16, i2_16); | - |
598 | break; | - |
599 | case QPicturePrivate::PdcDrawPie: | - |
600 | if (d->formatMajor <= 5) { | - |
601 | s >> ir; | - |
602 | r = ir; | - |
603 | } else { | - |
604 | s >> r; | - |
605 | } | - |
606 | s >> i1_16 >> i2_16; | - |
607 | painter->drawPie(r, i1_16, i2_16); | - |
608 | break; | - |
609 | case QPicturePrivate::PdcDrawChord: | - |
610 | if (d->formatMajor <= 5) { | - |
611 | s >> ir; | - |
612 | r = ir; | - |
613 | } else { | - |
614 | s >> r; | - |
615 | } | - |
616 | s >> i1_16 >> i2_16; | - |
617 | painter->drawChord(r, i1_16, i2_16); | - |
618 | break; | - |
619 | case QPicturePrivate::PdcDrawLineSegments: | - |
620 | s >> ia; | - |
621 | painter->drawLines(ia); | - |
622 | ia.clear(); | - |
623 | break; | - |
624 | case QPicturePrivate::PdcDrawPolyline: | - |
625 | if (d->formatMajor <= 5) { | - |
626 | s >> ia; | - |
627 | painter->drawPolyline(ia); | - |
628 | ia.clear(); | - |
629 | } else { | - |
630 | s >> a; | - |
631 | painter->drawPolyline(a); | - |
632 | a.clear(); | - |
633 | } | - |
634 | break; | - |
635 | case QPicturePrivate::PdcDrawPolygon: | - |
636 | if (d->formatMajor <= 5) { | - |
637 | s >> ia >> i_8; | - |
638 | painter->drawPolygon(ia, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - |
639 | a.clear(); | - |
640 | } else { | - |
641 | s >> a >> i_8; | - |
642 | painter->drawPolygon(a, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - |
643 | a.clear(); | - |
644 | } | - |
645 | break; | - |
646 | case QPicturePrivate::PdcDrawCubicBezier: { | - |
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; | - |
656 | case QPicturePrivate::PdcDrawText: | - |
657 | s >> ip >> str1; | - |
658 | painter->drawText(ip, QString::fromLatin1(str1)); | - |
659 | break; | - |
660 | case QPicturePrivate::PdcDrawTextFormatted: | - |
661 | s >> ir >> i_16 >> str1; | - |
662 | painter->drawText(ir, i_16, QString::fromLatin1(str1)); | - |
663 | break; | - |
664 | case QPicturePrivate::PdcDrawText2: | - |
665 | if (d->formatMajor <= 5) { | - |
666 | s >> ip >> str; | - |
667 | painter->drawText(ip, str); | - |
668 | } else { | - |
669 | s >> p >> str; | - |
670 | painter->drawText(p, str); | - |
671 | } | - |
672 | break; | - |
673 | case QPicturePrivate::PdcDrawText2Formatted: | - |
674 | s >> ir; | - |
675 | s >> i_16; | - |
676 | s >> str; | - |
677 | painter->drawText(ir, i_16, str); | - |
678 | break; | - |
679 | case QPicturePrivate::PdcDrawTextItem: { | - |
680 | s >> p >> str >> font >> ul; | - |
681 | | - |
682 | | - |
683 | | - |
684 | | - |
685 | | - |
686 | if (d->formatMajor >= 9) { | - |
687 | s >> dbl; | - |
688 | QFont fnt(font); | - |
689 | if (dbl != 1.0) { | - |
690 | QFakeDevice fake; | - |
691 | fake.setDpiX(qRound(dbl*qt_defaultDpiX())); | - |
692 | fake.setDpiY(qRound(dbl*qt_defaultDpiY())); | - |
693 | fnt = QFont(font, &fake); | - |
694 | } | - |
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) { | - |
703 | size.setWidth(justificationWidth); | - |
704 | flags |= Qt::TextJustificationForced; | - |
705 | flags |= Qt::AlignJustify; | - |
706 | } | - |
707 | | - |
708 | QFontMetrics fm(fnt); | - |
709 | QPointF pt(p.x(), p.y() - fm.ascent()); | - |
710 | qt_format_text(fnt, QRectF(pt, size), flags, 0, | - |
711 | str, 0, 0, 0, 0, painter); | - |
712 | } else { | - |
713 | qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, 0, | - |
714 | str, 0, 0, 0, 0, painter); | - |
715 | } | - |
716 | | - |
717 | break; | - |
718 | } | - |
719 | case QPicturePrivate::PdcDrawPixmap: { | - |
720 | QPixmap pixmap; | - |
721 | if (d->formatMajor < 4) { | - |
722 | s >> ip >> pixmap; | - |
723 | painter->drawPixmap(ip, pixmap); | - |
724 | } else if (d->formatMajor <= 5) { | - |
725 | s >> ir >> pixmap; | - |
726 | painter->drawPixmap(ir, pixmap); | - |
727 | } else { | - |
728 | QRectF sr; | - |
729 | if (d->in_memory_only) { | - |
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 { | - |
735 | s >> r >> pixmap >> sr; | - |
736 | } | - |
737 | painter->drawPixmap(r, pixmap, sr); | - |
738 | } | - |
739 | } | - |
740 | break; | - |
741 | case QPicturePrivate::PdcDrawTiledPixmap: { | - |
742 | QPixmap pixmap; | - |
743 | if (d->in_memory_only) { | - |
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 { | - |
749 | s >> r >> pixmap >> p; | - |
750 | } | - |
751 | painter->drawTiledPixmap(r, pixmap, p); | - |
752 | } | - |
753 | break; | - |
754 | case QPicturePrivate::PdcDrawImage: { | - |
755 | QImage image; | - |
756 | if (d->formatMajor < 4) { | - |
757 | s >> p >> image; | - |
758 | painter->drawImage(p, image); | - |
759 | } else if (d->formatMajor <= 5){ | - |
760 | s >> ir >> image; | - |
761 | painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height())); | - |
762 | } else { | - |
763 | QRectF sr; | - |
764 | if (d->in_memory_only) { | - |
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 { | - |
770 | s >> r >> image >> sr >> ul; | - |
771 | } | - |
772 | painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul)); | - |
773 | } | - |
774 | } | - |
775 | break; | - |
776 | case QPicturePrivate::PdcBegin: | - |
777 | s >> ul; | - |
778 | if (!exec(painter, s, ul)) | - |
779 | return false; | - |
780 | break; | - |
781 | case QPicturePrivate::PdcEnd: | - |
782 | if (nrecords == 0) | - |
783 | return true; | - |
784 | break; | - |
785 | case QPicturePrivate::PdcSave: | - |
786 | painter->save(); | - |
787 | break; | - |
788 | case QPicturePrivate::PdcRestore: | - |
789 | painter->restore(); | - |
790 | break; | - |
791 | case QPicturePrivate::PdcSetBkColor: | - |
792 | s >> color; | - |
793 | painter->setBackground(color); | - |
794 | break; | - |
795 | case QPicturePrivate::PdcSetBkMode: | - |
796 | s >> i_8; | - |
797 | painter->setBackgroundMode((Qt::BGMode)i_8); | - |
798 | break; | - |
799 | case QPicturePrivate::PdcSetROP: | - |
800 | s >> i_8; | - |
801 | break; | - |
802 | case QPicturePrivate::PdcSetBrushOrigin: | - |
803 | if (d->formatMajor <= 5) { | - |
804 | s >> ip; | - |
805 | painter->setBrushOrigin(ip); | - |
806 | } else { | - |
807 | s >> p; | - |
808 | painter->setBrushOrigin(p); | - |
809 | } | - |
810 | break; | - |
811 | case QPicturePrivate::PdcSetFont: | - |
812 | s >> font; | - |
813 | painter->setFont(font); | - |
814 | break; | - |
815 | case QPicturePrivate::PdcSetPen: | - |
816 | if (d->in_memory_only) { | - |
817 | int index; | - |
818 | s >> index; | - |
819 | Q_ASSERT(index < d->pen_list.size()); | - |
820 | pen = d->pen_list.at(index); | - |
821 | } else { | - |
822 | s >> pen; | - |
823 | } | - |
824 | painter->setPen(pen); | - |
825 | break; | - |
826 | case QPicturePrivate::PdcSetBrush: | - |
827 | if (d->in_memory_only) { | - |
828 | int index; | - |
829 | s >> index; | - |
830 | Q_ASSERT(index < d->brush_list.size()); | - |
831 | brush = d->brush_list.at(index); | - |
832 | } else { | - |
833 | s >> brush; | - |
834 | } | - |
835 | painter->setBrush(brush); | - |
836 | break; | - |
837 | case QPicturePrivate::PdcSetVXform: | - |
838 | s >> i_8; | - |
839 | painter->setViewTransformEnabled(i_8); | - |
840 | break; | - |
841 | case QPicturePrivate::PdcSetWindow: | - |
842 | if (d->formatMajor <= 5) { | - |
843 | s >> ir; | - |
844 | painter->setWindow(ir); | - |
845 | } else { | - |
846 | s >> r; | - |
847 | painter->setWindow(r.toRect()); | - |
848 | } | - |
849 | break; | - |
850 | case QPicturePrivate::PdcSetViewport: | - |
851 | if (d->formatMajor <= 5) { | - |
852 | s >> ir; | - |
853 | painter->setViewport(ir); | - |
854 | } else { | - |
855 | s >> r; | - |
856 | painter->setViewport(r.toRect()); | - |
857 | } | - |
858 | break; | - |
859 | case QPicturePrivate::PdcSetWXform: | - |
860 | s >> i_8; | - |
861 | painter->setMatrixEnabled(i_8); | - |
862 | break; | - |
863 | case QPicturePrivate::PdcSetWMatrix: | - |
864 | if (d->formatMajor >= 8) { | - |
865 | s >> matrix >> i_8; | - |
866 | } else { | - |
867 | s >> wmatrix >> i_8; | - |
868 | matrix = QTransform(wmatrix); | - |
869 | } | - |
870 | | - |
871 | painter->setTransform(matrix * worldMatrix, i_8); | - |
872 | break; | - |
873 | case QPicturePrivate::PdcSetClip: | - |
874 | s >> i_8; | - |
875 | painter->setClipping(i_8); | - |
876 | break; | - |
877 | case QPicturePrivate::PdcSetClipRegion: | - |
878 | s >> rgn >> i_8; | - |
879 | if (d->formatMajor >= 9) { | - |
880 | painter->setClipRegion(rgn, Qt::ClipOperation(i_8)); | - |
881 | } else { | - |
882 | painter->setClipRegion(rgn); | - |
883 | } | - |
884 | break; | - |
885 | case QPicturePrivate::PdcSetClipPath: | - |
886 | { | - |
887 | QPainterPath path; | - |
888 | s >> path >> i_8; | - |
889 | painter->setClipPath(path, Qt::ClipOperation(i_8)); | - |
890 | break; | - |
891 | } | - |
892 | case QPicturePrivate::PdcSetRenderHint: | - |
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; | - |
899 | case QPicturePrivate::PdcSetCompositionMode: | - |
900 | s >> ul; | - |
901 | painter->setCompositionMode((QPainter::CompositionMode)ul); | - |
902 | break; | - |
903 | case QPicturePrivate::PdcSetClipEnabled: | - |
904 | s >> bl; | - |
905 | painter->setClipping(bl); | - |
906 | break; | - |
907 | case QPicturePrivate::PdcSetOpacity: | - |
908 | s >> dbl; | - |
909 | painter->setOpacity(qreal(dbl)); | - |
910 | break; | - |
911 | default: | - |
912 | qWarning("QPicture::play: Invalid command %d", c); | - |
913 | if (len) | - |
914 | s.device()->seek(s.device()->pos()+len); | - |
915 | } | - |
916 | #if defined(QT_DEBUG) | - |
917 | | - |
918 | Q_ASSERT(qint32(s.device()->pos() - strm_pos) == len); | - |
919 | #endif | - |
920 | } | - |
921 | return false; | - |
922 | } | - |
923 | | - |
924 | | - |
925 | | - |
926 | | - |
927 | | - |
928 | | - |
929 | | - |
930 | | - |
931 | | - |
932 | | - |
933 | | - |
934 | | - |
935 | | - |
936 | int QPicture::metric(PaintDeviceMetric m) const | - |
937 | { | - |
938 | int val; | - |
939 | QRect brect = boundingRect(); | - |
940 | switch (m) { | - |
941 | case PdmWidth: | - |
942 | val = brect.width(); | - |
943 | break; | - |
944 | case PdmHeight: | - |
945 | val = brect.height(); | - |
946 | break; | - |
947 | case PdmWidthMM: | - |
948 | val = int(25.4/qt_defaultDpiX()*brect.width()); | - |
949 | break; | - |
950 | case PdmHeightMM: | - |
951 | val = int(25.4/qt_defaultDpiY()*brect.height()); | - |
952 | break; | - |
953 | case PdmDpiX: | - |
954 | case PdmPhysicalDpiX: | - |
955 | val = qt_defaultDpiX(); | - |
956 | break; | - |
957 | case PdmDpiY: | - |
958 | case PdmPhysicalDpiY: | - |
959 | val = qt_defaultDpiY(); | - |
960 | break; | - |
961 | case PdmNumColors: | - |
962 | val = 16777216; | - |
963 | break; | - |
964 | case PdmDepth: | - |
965 | val = 24; | - |
966 | break; | - |
967 | case PdmDevicePixelRatio: | - |
968 | val = 1; | - |
969 | break; | - |
970 | case PdmDevicePixelRatioScaled: | - |
971 | val = 1 * QPaintDevice::devicePixelRatioFScale(); | - |
972 | break; | - |
973 | default: | - |
974 | val = 0; | - |
975 | qWarning("QPicture::metric: Invalid metric command"); | - |
976 | } | - |
977 | return val; | - |
978 | } | - |
979 | | - |
980 | | - |
981 | | - |
982 | | - |
983 | | - |
984 | | - |
985 | | - |
986 | | - |
987 | | - |
988 | | - |
989 | | - |
990 | | - |
991 | | - |
992 | | - |
993 | | - |
994 | | - |
995 | | - |
996 | | - |
997 | | - |
998 | | - |
999 | QPicture& QPicture::operator=(const QPicture &p) | - |
1000 | { | - |
1001 | d_ptr = p.d_ptr; | - |
1002 | return *this; | - |
1003 | } | - |
1004 | | - |
1005 | | - |
1006 | | - |
1007 | | - |
1008 | | - |
1009 | | - |
1010 | | - |
1011 | | - |
1012 | | - |
1013 | | - |
1014 | | - |
1015 | | - |
1016 | | - |
1017 | | - |
1018 | QPicturePrivate::QPicturePrivate() | - |
1019 | : in_memory_only(false) | - |
1020 | { | - |
1021 | } | - |
1022 | | - |
1023 | | - |
1024 | | - |
1025 | | - |
1026 | | - |
1027 | | - |
1028 | QPicturePrivate::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()) { | - |
1038 | pictb.open(other.pictb.openMode()); | - |
1039 | pictb.seek(other.pictb.pos()); | - |
1040 | } | - |
1041 | } | - |
1042 | | - |
1043 | | - |
1044 | | - |
1045 | | - |
1046 | | - |
1047 | | - |
1048 | | - |
1049 | void QPicturePrivate::resetFormat() | - |
1050 | { | - |
1051 | formatOk = false; | - |
1052 | formatMajor = mfhdr_maj; | - |
1053 | formatMinor = mfhdr_min; | - |
1054 | } | - |
1055 | | - |
1056 | | - |
1057 | | - |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | - |
1062 | | - |
1063 | | - |
1064 | bool QPicturePrivate::checkFormat() | - |
1065 | { | - |
1066 | resetFormat(); | - |
1067 | | - |
1068 | | - |
1069 | if (pictb.size() == 0 || pictb.isOpen()) | - |
1070 | return false; | - |
1071 | | - |
1072 | pictb.open(QIODevice::ReadOnly); | - |
1073 | QDataStream s; | - |
1074 | s.setDevice(&pictb); | - |
1075 | | - |
1076 | char mf_id[4]; | - |
1077 | s.readRawData(mf_id, 4); | - |
1078 | if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0) { | - |
1079 | qWarning("QPicturePaintEngine::checkFormat: Incorrect header"); | - |
1080 | pictb.close(); | - |
1081 | return false; | - |
1082 | } | - |
1083 | | - |
1084 | int cs_start = sizeof(quint32); | - |
1085 | int data_start = cs_start + sizeof(quint16); | - |
1086 | quint16 cs,ccs; | - |
1087 | QByteArray buf = pictb.buffer(); | - |
1088 | | - |
1089 | s >> cs; | - |
1090 | ccs = (quint16) qChecksum(buf.constData() + data_start, buf.size() - data_start); | - |
1091 | if (ccs != cs) { | - |
1092 | qWarning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected", | - |
1093 | ccs, cs); | - |
1094 | pictb.close(); | - |
1095 | return false; | - |
1096 | } | - |
1097 | | - |
1098 | quint16 major, minor; | - |
1099 | s >> major >> minor; | - |
1100 | if (major > mfhdr_maj) { | - |
1101 | qWarning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d", | - |
1102 | major, minor); | - |
1103 | pictb.close(); | - |
1104 | return false; | - |
1105 | } | - |
1106 | s.setVersion(major != 4 ? major : 3); | - |
1107 | | - |
1108 | quint8 c, clen; | - |
1109 | s >> c >> clen; | - |
1110 | if (c == QPicturePrivate::PdcBegin) { | - |
1111 | if (!(major >= 1 && major <= 3)) { | - |
1112 | qint32 l, t, w, h; | - |
1113 | s >> l >> t >> w >> h; | - |
1114 | brect = QRect(l, t, w, h); | - |
1115 | } | - |
1116 | } else { | - |
1117 | qWarning("QPicturePaintEngine::checkFormat: Format error"); | - |
1118 | pictb.close(); | - |
1119 | return false; | - |
1120 | } | - |
1121 | pictb.close(); | - |
1122 | | - |
1123 | formatOk = true; | - |
1124 | formatMajor = major; | - |
1125 | formatMinor = minor; | - |
1126 | return true; | - |
1127 | } | - |
1128 | | - |
1129 | | - |
1130 | QPaintEngine *QPicture::paintEngine() const | - |
1131 | { | - |
1132 | if (!d_func()->paintEngine) | - |
1133 | const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); | - |
1134 | return d_func()->paintEngine.data(); | - |
1135 | } | - |
1136 | | - |
1137 | | - |
1138 | | - |
1139 | | - |
1140 | | - |
1141 | #ifndef QT_NO_DATASTREAM | - |
1142 | | - |
1143 | | - |
1144 | | - |
1145 | | - |
1146 | | - |
1147 | | - |
1148 | | - |
1149 | QDataStream &operator<<(QDataStream &s, const QPicture &r) | - |
1150 | { | - |
1151 | quint32 size = r.d_func()->pictb.buffer().size(); | - |
1152 | s << size; | - |
1153 | | - |
1154 | if (size == 0) | - |
1155 | return s; | - |
1156 | | - |
1157 | s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size()); | - |
1158 | return s; | - |
1159 | } | - |
1160 | | - |
1161 | | - |
1162 | | - |
1163 | | - |
1164 | | - |
1165 | | - |
1166 | | - |
1167 | | - |
1168 | QDataStream &operator>>(QDataStream &s, QPicture &r) | - |
1169 | { | - |
1170 | QDataStream sr; | - |
1171 | | - |
1172 | | - |
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) { | - |
1179 | data.resize(len); | - |
1180 | s.readRawData(data.data(), len); | - |
1181 | } | - |
1182 | | - |
1183 | r.d_func()->pictb.setData(data); | - |
1184 | r.d_func()->resetFormat(); | - |
1185 | return s; | - |
1186 | } | - |
1187 | #endif // QT_NO_DATASTREAM | - |
1188 | | - |
1189 | | - |
1190 | #ifndef QT_NO_PICTUREIO | - |
1191 | | - |
1192 | QT_BEGIN_INCLUDE_NAMESPACE | - |
1193 | #include "qregexp.h" | - |
1194 | #include "qpictureformatplugin.h" | - |
1195 | QT_END_INCLUDE_NAMESPACE | - |
1196 | | - |
1197 | | - |
1198 | | - |
1199 | | - |
1200 | | - |
1201 | | - |
1202 | | - |
1203 | | - |
1204 | | - |
1205 | | - |
1206 | | - |
1207 | const char* QPicture::pictureFormat(const QString &fileName) | - |
1208 | { | - |
1209 | return QPictureIO::pictureFormat(fileName); | - |
1210 | } | - |
1211 | | - |
1212 | | - |
1213 | | - |
1214 | | - |
1215 | | - |
1216 | | - |
1217 | | - |
1218 | | - |
1219 | | - |
1220 | QList<QByteArray> QPicture::inputFormats() | - |
1221 | { | - |
1222 | return QPictureIO::inputFormats(); | - |
1223 | } | - |
1224 | | - |
1225 | static 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) | - |
1231 | list.append(QString::fromLatin1(arr.at(i))); | - |
1232 | return list; | - |
1233 | } | - |
1234 | | - |
1235 | | - |
1236 | | - |
1237 | | - |
1238 | | - |
1239 | | - |
1240 | | - |
1241 | | - |
1242 | | - |
1243 | | - |
1244 | | - |
1245 | | - |
1246 | | - |
1247 | QStringList QPicture::inputFormatList() | - |
1248 | { | - |
1249 | return qToStringList(QPictureIO::inputFormats()); | - |
1250 | } | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | | - |
1255 | | - |
1256 | | - |
1257 | | - |
1258 | | - |
1259 | | - |
1260 | | - |
1261 | | - |
1262 | | - |
1263 | | - |
1264 | | - |
1265 | QStringList QPicture::outputFormatList() | - |
1266 | { | - |
1267 | return qToStringList(QPictureIO::outputFormats()); | - |
1268 | } | - |
1269 | | - |
1270 | | - |
1271 | | - |
1272 | | - |
1273 | | - |
1274 | | - |
1275 | | - |
1276 | | - |
1277 | | - |
1278 | QList<QByteArray> QPicture::outputFormats() | - |
1279 | { | - |
1280 | return QPictureIO::outputFormats(); | - |
1281 | } | - |
1282 | | - |
1283 | | - |
1284 | | - |
1285 | | - |
1286 | | - |
1287 | | - |
1288 | | - |
1289 | | - |
1290 | | - |
1291 | | - |
1292 | | - |
1293 | | - |
1294 | | - |
1295 | | - |
1296 | | - |
1297 | | - |
1298 | | - |
1299 | | - |
1300 | | - |
1301 | | - |
1302 | | - |
1303 | | - |
1304 | | - |
1305 | | - |
1306 | | - |
1307 | | - |
1308 | | - |
1309 | struct QPictureIOData | - |
1310 | { | - |
1311 | QPicture pi; | - |
1312 | int iostat; | - |
1313 | QByteArray frmt; | - |
1314 | QIODevice *iodev; | - |
1315 | QString fname; | - |
1316 | QString descr; | - |
1317 | const char *parameters; | - |
1318 | int quality; | - |
1319 | float gamma; | - |
1320 | }; | - |
1321 | | - |
1322 | | - |
1323 | | - |
1324 | | - |
1325 | | - |
1326 | QPictureIO::QPictureIO() | - |
1327 | { | - |
1328 | init(); | - |
1329 | } | - |
1330 | | - |
1331 | | - |
1332 | | - |
1333 | | - |
1334 | | - |
1335 | | - |
1336 | QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format) | - |
1337 | { | - |
1338 | init(); | - |
1339 | d->iodev = ioDevice; | - |
1340 | d->frmt = format; | - |
1341 | } | - |
1342 | | - |
1343 | | - |
1344 | | - |
1345 | | - |
1346 | | - |
1347 | | - |
1348 | QPictureIO::QPictureIO(const QString &fileName, const char* format) | - |
1349 | { | - |
1350 | init(); | - |
1351 | d->frmt = format; | - |
1352 | d->fname = fileName; | - |
1353 | } | - |
1354 | | - |
1355 | | - |
1356 | | - |
1357 | | - |
1358 | | - |
1359 | void QPictureIO::init() | - |
1360 | { | - |
1361 | d = new QPictureIOData(); | - |
1362 | d->parameters = 0; | - |
1363 | d->quality = -1; | - |
1364 | d->gamma=0.0f; | - |
1365 | d->iostat = 0; | - |
1366 | d->iodev = 0; | - |
1367 | } | - |
1368 | | - |
1369 | | - |
1370 | | - |
1371 | | - |
1372 | | - |
1373 | QPictureIO::~QPictureIO() | - |
1374 | { | - |
1375 | if (d->parameters) | - |
1376 | delete [] d->parameters; | - |
1377 | delete d; | - |
1378 | } | - |
1379 | | - |
1380 | | - |
1381 | | - |
1382 | | - |
1383 | | - |
1384 | | - |
1385 | class QPictureHandler | - |
1386 | { | - |
1387 | public: | - |
1388 | QPictureHandler(const char *f, const char *h, const QByteArray& fl, | - |
1389 | picture_io_handler r, picture_io_handler w); | - |
1390 | QByteArray format; | - |
1391 | QRegExp header; | - |
1392 | enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode; | - |
1393 | picture_io_handler read_picture; | - |
1394 | picture_io_handler write_picture; | - |
1395 | bool obsolete; | - |
1396 | }; | - |
1397 | | - |
1398 | QPictureHandler::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')) | - |
1404 | text_mode = TranslateIn; | - |
1405 | else if (fl.contains('T')) | - |
1406 | text_mode = TranslateInOut; | - |
1407 | obsolete = fl.contains('O'); | - |
1408 | read_picture = r; | - |
1409 | write_picture = w; | - |
1410 | } | - |
1411 | | - |
1412 | typedef QList<QPictureHandler *> QPHList; | - |
1413 | Q_GLOBAL_STATIC(QPHList, pictureHandlers) | - |
1414 | | - |
1415 | void qt_init_picture_plugins() | - |
1416 | { | - |
1417 | #ifndef QT_NO_LIBRARYtypedef 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) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1428 | if (QPictureFormatPlugin *format = qobject_cast<QPictureFormatPlugin*>(loader.instance(it.key())))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1429 | format->installIOHandler(it.value()); never executed: format->installIOHandler(it.value()); | 0 |
1430 | }#endif never executed: end of block | 0 |
1431 | } never executed: end of block | 0 |
1432 | | - |
1433 | static void cleanup() | - |
1434 | { | - |
1435 | | - |
1436 | if (QPHList *list = pictureHandlers()) { | - |
1437 | qDeleteAll(*list); | - |
1438 | list->clear(); | - |
1439 | } | - |
1440 | } | - |
1441 | | - |
1442 | void qt_init_picture_handlers() | - |
1443 | { | - |
1444 | static QBasicAtomicInt done = Q_BASIC_ATOMIC_INITIALIZER(0); | - |
1445 | if (done.testAndSetRelaxed(0, 1)) { | - |
1446 | qAddPostRoutine(cleanup); | - |
1447 | } | - |
1448 | } | - |
1449 | | - |
1450 | static QPictureHandler *get_picture_handler(const char *format) | - |
1451 | { | - |
1452 | qt_init_picture_handlers(); | - |
1453 | qt_init_picture_plugins(); | - |
1454 | if (QPHList *list = pictureHandlers()) { | - |
1455 | for (int i = 0; i < list->size(); ++i) { | - |
1456 | if (list->at(i)->format == format) | - |
1457 | return list->at(i); | - |
1458 | } | - |
1459 | } | - |
1460 | return 0; | - |
1461 | } | - |
1462 | | - |
1463 | | - |
1464 | | - |
1465 | | - |
1466 | | - |
1467 | | - |
1468 | | - |
1469 | | - |
1470 | | - |
1471 | | - |
1472 | | - |
1473 | | - |
1474 | | - |
1475 | | - |
1476 | | - |
1477 | | - |
1478 | | - |
1479 | | - |
1480 | | - |
1481 | | - |
1482 | | - |
1483 | | - |
1484 | | - |
1485 | | - |
1486 | | - |
1487 | | - |
1488 | | - |
1489 | | - |
1490 | | - |
1491 | | - |
1492 | | - |
1493 | | - |
1494 | | - |
1495 | | - |
1496 | | - |
1497 | | - |
1498 | | - |
1499 | | - |
1500 | | - |
1501 | | - |
1502 | | - |
1503 | void 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()) { | - |
1511 | QPictureHandler *p; | - |
1512 | p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture); | - |
1513 | list->prepend(p); | - |
1514 | } | - |
1515 | } | - |
1516 | | - |
1517 | | - |
1518 | | - |
1519 | | - |
1520 | | - |
1521 | | - |
1522 | | - |
1523 | | - |
1524 | | - |
1525 | | - |
1526 | | - |
1527 | const QPicture &QPictureIO::picture() const { return d->pi; } | - |
1528 | | - |
1529 | | - |
1530 | | - |
1531 | | - |
1532 | | - |
1533 | | - |
1534 | | - |
1535 | int QPictureIO::status() const { return d->iostat; } | - |
1536 | | - |
1537 | | - |
1538 | | - |
1539 | | - |
1540 | | - |
1541 | const char *QPictureIO::format() const { return d->frmt; } | - |
1542 | | - |
1543 | | - |
1544 | | - |
1545 | | - |
1546 | | - |
1547 | | - |
1548 | QIODevice *QPictureIO::ioDevice() const { return d->iodev; } | - |
1549 | | - |
1550 | | - |
1551 | | - |
1552 | | - |
1553 | | - |
1554 | | - |
1555 | QString QPictureIO::fileName() const { return d->fname; } | - |
1556 | | - |
1557 | | - |
1558 | | - |
1559 | | - |
1560 | | - |
1561 | | - |
1562 | | - |
1563 | QString QPictureIO::description() const { return d->descr; } | - |
1564 | | - |
1565 | | - |
1566 | | - |
1567 | | - |
1568 | | - |
1569 | | - |
1570 | void QPictureIO::setPicture(const QPicture &picture) | - |
1571 | { | - |
1572 | d->pi = picture; | - |
1573 | } | - |
1574 | | - |
1575 | | - |
1576 | | - |
1577 | | - |
1578 | | - |
1579 | | - |
1580 | | - |
1581 | void QPictureIO::setStatus(int status) | - |
1582 | { | - |
1583 | d->iostat = status; | - |
1584 | } | - |
1585 | | - |
1586 | | - |
1587 | | - |
1588 | | - |
1589 | | - |
1590 | | - |
1591 | | - |
1592 | | - |
1593 | | - |
1594 | | - |
1595 | | - |
1596 | | - |
1597 | | - |
1598 | | - |
1599 | void QPictureIO::setFormat(const char *format) | - |
1600 | { | - |
1601 | d->frmt = format; | - |
1602 | } | - |
1603 | | - |
1604 | | - |
1605 | | - |
1606 | | - |
1607 | | - |
1608 | | - |
1609 | | - |
1610 | | - |
1611 | | - |
1612 | | - |
1613 | | - |
1614 | | - |
1615 | void QPictureIO::setIODevice(QIODevice *ioDevice) | - |
1616 | { | - |
1617 | d->iodev = ioDevice; | - |
1618 | } | - |
1619 | | - |
1620 | | - |
1621 | | - |
1622 | | - |
1623 | | - |
1624 | | - |
1625 | | - |
1626 | void QPictureIO::setFileName(const QString &fileName) | - |
1627 | { | - |
1628 | d->fname = fileName; | - |
1629 | } | - |
1630 | | - |
1631 | | - |
1632 | | - |
1633 | | - |
1634 | | - |
1635 | | - |
1636 | | - |
1637 | int QPictureIO::quality() const | - |
1638 | { | - |
1639 | return d->quality; | - |
1640 | } | - |
1641 | | - |
1642 | | - |
1643 | | - |
1644 | | - |
1645 | | - |
1646 | | - |
1647 | | - |
1648 | | - |
1649 | | - |
1650 | | - |
1651 | | - |
1652 | | - |
1653 | void QPictureIO::setQuality(int q) | - |
1654 | { | - |
1655 | d->quality = q; | - |
1656 | } | - |
1657 | | - |
1658 | | - |
1659 | | - |
1660 | | - |
1661 | | - |
1662 | | - |
1663 | | - |
1664 | const char *QPictureIO::parameters() const | - |
1665 | { | - |
1666 | return d->parameters; | - |
1667 | } | - |
1668 | | - |
1669 | | - |
1670 | | - |
1671 | | - |
1672 | | - |
1673 | | - |
1674 | | - |
1675 | | - |
1676 | | - |
1677 | | - |
1678 | | - |
1679 | | - |
1680 | void QPictureIO::setParameters(const char *parameters) | - |
1681 | { | - |
1682 | if (d->parameters) | - |
1683 | delete [] d->parameters; | - |
1684 | d->parameters = qstrdup(parameters); | - |
1685 | } | - |
1686 | | - |
1687 | | - |
1688 | | - |
1689 | | - |
1690 | | - |
1691 | | - |
1692 | | - |
1693 | | - |
1694 | | - |
1695 | | - |
1696 | | - |
1697 | | - |
1698 | void QPictureIO::setGamma(float gamma) | - |
1699 | { | - |
1700 | d->gamma=gamma; | - |
1701 | } | - |
1702 | | - |
1703 | | - |
1704 | | - |
1705 | | - |
1706 | | - |
1707 | | - |
1708 | float QPictureIO::gamma() const | - |
1709 | { | - |
1710 | return d->gamma; | - |
1711 | } | - |
1712 | | - |
1713 | | - |
1714 | | - |
1715 | | - |
1716 | | - |
1717 | | - |
1718 | | - |
1719 | | - |
1720 | | - |
1721 | void QPictureIO::setDescription(const QString &description) | - |
1722 | { | - |
1723 | d->descr = description; | - |
1724 | } | - |
1725 | | - |
1726 | | - |
1727 | | - |
1728 | | - |
1729 | | - |
1730 | | - |
1731 | | - |
1732 | | - |
1733 | QByteArray QPictureIO::pictureFormat(const QString &fileName) | - |
1734 | { | - |
1735 | QFile file(fileName); | - |
1736 | QByteArray format; | - |
1737 | if (!file.open(QIODevice::ReadOnly)) | - |
1738 | return format; | - |
1739 | format = pictureFormat(&file); | - |
1740 | file.close(); | - |
1741 | return format; | - |
1742 | } | - |
1743 | | - |
1744 | | - |
1745 | | - |
1746 | | - |
1747 | | - |
1748 | | - |
1749 | | - |
1750 | | - |
1751 | | - |
1752 | | - |
1753 | | - |
1754 | | - |
1755 | | - |
1756 | | - |
1757 | QByteArray QPictureIO::pictureFormat(QIODevice *d) | - |
1758 | { | - |
1759 | | - |
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(); | - |
1767 | int rdlen = d->read(buf, buflen); | - |
1768 | | - |
1769 | QByteArray format; | - |
1770 | if (rdlen != buflen) | - |
1771 | return format; | - |
1772 | | - |
1773 | memcpy(buf2, buf, buflen); | - |
1774 | | - |
1775 | for (int n = 0; n < rdlen; n++) | - |
1776 | if (buf[n] == '\0') | - |
1777 | buf[n] = '\001'; | - |
1778 | if (rdlen > 0) { | - |
1779 | buf[rdlen - 1] = '\0'; | - |
1780 | QString bufStr = QString::fromLatin1(buf); | - |
1781 | if (QPHList *list = pictureHandlers()) { | - |
1782 | for (int i = 0; i < list->size(); ++i) { | - |
1783 | if (list->at(i)->header.indexIn(bufStr) != -1) { | - |
1784 | format = list->at(i)->format; | - |
1785 | break; | - |
1786 | } | - |
1787 | } | - |
1788 | } | - |
1789 | } | - |
1790 | d->seek(pos); | - |
1791 | return format; | - |
1792 | } | - |
1793 | | - |
1794 | | - |
1795 | | - |
1796 | | - |
1797 | | - |
1798 | QList<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()) { | - |
1806 | for (int i = 0; i < list->size(); ++i) { | - |
1807 | QPictureHandler *p = list->at(i); | - |
1808 | if (p->read_picture && !p->obsolete && !result.contains(p->format)) | - |
1809 | result.append(p->format); | - |
1810 | } | - |
1811 | } | - |
1812 | std::sort(result.begin(), result.end()); | - |
1813 | | - |
1814 | return result; | - |
1815 | } | - |
1816 | | - |
1817 | | - |
1818 | | - |
1819 | | - |
1820 | | - |
1821 | QList<QByteArray> QPictureIO::outputFormats() | - |
1822 | { | - |
1823 | qt_init_picture_handlers(); | - |
1824 | qt_init_picture_plugins(); | - |
1825 | | - |
1826 | QList<QByteArray> result; | - |
1827 | if (QPHList *list = pictureHandlers()) { | - |
1828 | for (int i = 0; i < list->size(); ++i) { | - |
1829 | QPictureHandler *p = list->at(i); | - |
1830 | if (p->write_picture && !p->obsolete && !result.contains(p->format)) | - |
1831 | result.append(p->format); | - |
1832 | } | - |
1833 | } | - |
1834 | return result; | - |
1835 | } | - |
1836 | | - |
1837 | | - |
1838 | | - |
1839 | | - |
1840 | | - |
1841 | | - |
1842 | | - |
1843 | | - |
1844 | | - |
1845 | | - |
1846 | | - |
1847 | | - |
1848 | | - |
1849 | | - |
1850 | | - |
1851 | | - |
1852 | | - |
1853 | | - |
1854 | | - |
1855 | | - |
1856 | | - |
1857 | | - |
1858 | bool QPictureIO::read() | - |
1859 | { | - |
1860 | QFile file; | - |
1861 | const char *picture_format; | - |
1862 | QPictureHandler *h; | - |
1863 | | - |
1864 | if (d->iodev) { | - |
1865 | | - |
1866 | } else if (!d->fname.isEmpty()) { | - |
1867 | file.setFileName(d->fname); | - |
1868 | if (!file.open(QIODevice::ReadOnly)) | - |
1869 | return false; | - |
1870 | d->iodev = &file; | - |
1871 | } else { | - |
1872 | return false; | - |
1873 | } | - |
1874 | if (d->frmt.isEmpty()) { | - |
1875 | | - |
1876 | picture_format = pictureFormat(d->iodev); | - |
1877 | if (!picture_format) { | - |
1878 | if (file.isOpen()) { | - |
1879 | file.close(); | - |
1880 | d->iodev = 0; | - |
1881 | } | - |
1882 | return false; | - |
1883 | } | - |
1884 | } else { | - |
1885 | picture_format = d->frmt; | - |
1886 | } | - |
1887 | | - |
1888 | h = get_picture_handler(picture_format); | - |
1889 | if (file.isOpen()) { | - |
1890 | #if !defined(Q_OS_UNIX) | - |
1891 | if (h && h->text_mode) { | - |
1892 | file.close(); | - |
1893 | file.open(QIODevice::ReadOnly | QIODevice::Text); | - |
1894 | } | - |
1895 | else | - |
1896 | #endif | - |
1897 | file.seek(0); | - |
1898 | } | - |
1899 | d->iostat = 1; | - |
1900 | | - |
1901 | if (h && h->read_picture) | - |
1902 | (*h->read_picture)(this); | - |
1903 | | - |
1904 | if (file.isOpen()) { | - |
1905 | file.close(); | - |
1906 | d->iodev = 0; | - |
1907 | } | - |
1908 | return d->iostat == 0; | - |
1909 | } | - |
1910 | | - |
1911 | | - |
1912 | | - |
1913 | | - |
1914 | | - |
1915 | | - |
1916 | | - |
1917 | | - |
1918 | | - |
1919 | | - |
1920 | | - |
1921 | | - |
1922 | | - |
1923 | | - |
1924 | | - |
1925 | | - |
1926 | | - |
1927 | bool QPictureIO::write() | - |
1928 | { | - |
1929 | if (d->frmt.isEmpty()) | - |
1930 | return false; | - |
1931 | QPictureHandler *h = get_picture_handler(d->frmt); | - |
1932 | if (!h || !h->write_picture) { | - |
1933 | qWarning("QPictureIO::write: No such picture format handler: %s", | - |
1934 | format()); | - |
1935 | return false; | - |
1936 | } | - |
1937 | QFile file; | - |
1938 | if (!d->iodev && !d->fname.isEmpty()) { | - |
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); | - |
1942 | if (!file.open(fmode)) | - |
1943 | return false; | - |
1944 | d->iodev = &file; | - |
1945 | } | - |
1946 | d->iostat = 1; | - |
1947 | (*h->write_picture)(this); | - |
1948 | if (file.isOpen()) { | - |
1949 | file.close(); | - |
1950 | d->iodev = 0; | - |
1951 | } | - |
1952 | return d->iostat == 0; | - |
1953 | } | - |
1954 | #endif //QT_NO_PICTUREIO | - |
1955 | | - |
1956 | QT_END_NAMESPACE | - |
1957 | | - |
1958 | #endif // QT_NO_PICTURE | - |
1959 | | - |
1960 | | - |
1961 | | - |
1962 | | - |
1963 | | - |
1964 | | - |
1965 | | - |
1966 | | - |
1967 | | - |
1968 | | - |
| | |