| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | void qt_format_text(const QFont &fnt, const QRectF &_r, | - |
| 11 | int tf, const QTextOption *opt, const QString& str, QRectF *brect, | - |
| 12 | int tabstops, int *, int tabarraylen, | - |
| 13 | QPainter *painter); | - |
| 14 | const char *qt_mfhdr_tag = "QPIC"; | - |
| 15 | static const quint16 mfhdr_maj = QDataStream::Qt_DefaultCompiledVersion; | - |
| 16 | static const quint16 mfhdr_min = 0; | - |
| 17 | QPicture::QPicture(int formatVersion) | - |
| 18 | : QPaintDevice(), | - |
| 19 | d_ptr(new QPicturePrivate) | - |
| 20 | { | - |
| 21 | QPicturePrivate * const d = d_func(); | - |
| 22 | | - |
| 23 | if (formatVersion == 0) | - |
| 24 | QMessageLogger(__FILE__, 138144, __PRETTY_FUNCTION__).warning("QPicture: invalid format version 0"); | - |
| 25 | | - |
| 26 | | - |
| 27 | if (formatVersion > 0 && formatVersion != (int)mfhdr_maj) { | - |
| 28 | d->formatMajor = formatVersion; | - |
| 29 | d->formatMinor = 0; | - |
| 30 | d->formatOk = false; | - |
| 31 | } else { | - |
| 32 | d->resetFormat(); | - |
| 33 | } | - |
| 34 | } | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | QPicture::QPicture(const QPicture &pic) | - |
| 43 | : QPaintDevice(), d_ptr(pic.d_ptr) | - |
| 44 | { | - |
| 45 | } | - |
| 46 | | - |
| 47 | | - |
| 48 | QPicture::QPicture(QPicturePrivate &dptr) | - |
| 49 | : QPaintDevice(), | - |
| 50 | d_ptr(&dptr) | - |
| 51 | { | - |
| 52 | } | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | QPicture::~QPicture() | - |
| 58 | { | - |
| 59 | } | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | | - |
| 64 | int QPicture::devType() const | - |
| 65 | { | - |
| 66 | return QInternal::Picture; | - |
| 67 | } | - |
| 68 | bool QPicture::isNull() const | - |
| 69 | { | - |
| 70 | return d_func()->pictb.buffer().isNull(); | - |
| 71 | } | - |
| 72 | | - |
| 73 | uint QPicture::size() const | - |
| 74 | { | - |
| 75 | return d_func()->pictb.buffer().size(); | - |
| 76 | } | - |
| 77 | | - |
| 78 | const char* QPicture::data() const | - |
| 79 | { | - |
| 80 | return d_func()->pictb.buffer(); | - |
| 81 | } | - |
| 82 | | - |
| 83 | void QPicture::detach() | - |
| 84 | { | - |
| 85 | d_ptr.detach(); | - |
| 86 | } | - |
| 87 | | - |
| 88 | bool QPicture::isDetached() const | - |
| 89 | { | - |
| 90 | return d_func()->ref.load() == 1; | - |
| 91 | } | - |
| 92 | void QPicture::setData(const char* data, uint size) | - |
| 93 | { | - |
| 94 | detach(); | - |
| 95 | d_func()->pictb.setData(data, size); | - |
| 96 | d_func()->resetFormat(); | - |
| 97 | } | - |
| 98 | bool QPicture::load(const QString &fileName, const char *format) | - |
| 99 | { | - |
| 100 | QFile f(fileName); | - |
| 101 | if (!f.open(QIODevice::ReadOnly)) { | - |
| 102 | operator=(QPicture()); | - |
| 103 | return false; | - |
| 104 | } | - |
| 105 | return load(&f, format); | - |
| 106 | } | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | bool QPicture::load(QIODevice *dev, const char *format) | - |
| 115 | { | - |
| 116 | if(format) { | - |
| 117 | | - |
| 118 | QPictureIO io(dev, format); | - |
| 119 | if (io.read()) { | - |
| 120 | operator=(io.picture()); | - |
| 121 | return true; | - |
| 122 | } | - |
| 123 | | - |
| 124 | QMessageLogger(__FILE__, 285291, __PRETTY_FUNCTION__).warning("QPicture::load: No such picture format: %s", format); | - |
| 125 | operator=(QPicture()); | - |
| 126 | return false; | - |
| 127 | } | - |
| 128 | | - |
| 129 | detach(); | - |
| 130 | QByteArray a = dev->readAll(); | - |
| 131 | | - |
| 132 | d_func()->pictb.setData(a); | - |
| 133 | return d_func()->checkFormat(); | - |
| 134 | } | - |
| 135 | bool QPicture::save(const QString &fileName, const char *format) | - |
| 136 | { | - |
| 137 | if (paintingActive()) { | - |
| 138 | QMessageLogger(__FILE__, 310316, __PRETTY_FUNCTION__).warning("QPicture::save: still being painted on. " | - |
| 139 | "Call QPainter::end() first"); | - |
| 140 | return false; | - |
| 141 | } | - |
| 142 | | - |
| 143 | | - |
| 144 | if(format) { | - |
| 145 | | - |
| 146 | QPictureIO io(fileName, format); | - |
| 147 | bool result = io.write(); | - |
| 148 | if (result) { | - |
| 149 | operator=(io.picture()); | - |
| 150 | } else if (format) | - |
| 151 | | - |
| 152 | | - |
| 153 | | - |
| 154 | { | - |
| 155 | QMessageLogger(__FILE__, 327333, __PRETTY_FUNCTION__).warning("QPicture::save: No such picture format: %s", format); | - |
| 156 | } | - |
| 157 | return result; | - |
| 158 | } | - |
| 159 | | - |
| 160 | QFile f(fileName); | - |
| 161 | if (!f.open(QIODevice::WriteOnly)) | - |
| 162 | return false; | - |
| 163 | return save(&f, format); | - |
| 164 | } | - |
| 165 | | - |
| 166 | | - |
| 167 | | - |
| 168 | | - |
| 169 | | - |
| 170 | | - |
| 171 | | - |
| 172 | bool QPicture::save(QIODevice *dev, const char *format) | - |
| 173 | { | - |
| 174 | if (paintingActive()) { | - |
| 175 | QMessageLogger(__FILE__, 347353, __PRETTY_FUNCTION__).warning("QPicture::save: still being painted on. " | - |
| 176 | "Call QPainter::end() first"); | - |
| 177 | return false; | - |
| 178 | } | - |
| 179 | | - |
| 180 | if(format) { | - |
| 181 | | - |
| 182 | QPictureIO io(dev, format); | - |
| 183 | bool result = io.write(); | - |
| 184 | if (result) { | - |
| 185 | operator=(io.picture()); | - |
| 186 | } else if (format) | - |
| 187 | | - |
| 188 | | - |
| 189 | | - |
| 190 | { | - |
| 191 | QMessageLogger(__FILE__, 363369, __PRETTY_FUNCTION__).warning("QPicture::save: No such picture format: %s", format); | - |
| 192 | } | - |
| 193 | return result; | - |
| 194 | } | - |
| 195 | | - |
| 196 | dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size()); | - |
| 197 | return true; | - |
| 198 | } | - |
| 199 | | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | QRect QPicture::boundingRect() const | - |
| 206 | { | - |
| 207 | const QPicturePrivate * const d = d_func(); | - |
| 208 | | - |
| 209 | if (!d->override_rect.isEmpty()) | - |
| 210 | return d->override_rect; | - |
| 211 | | - |
| 212 | if (!d->formatOk) | - |
| 213 | d_ptr->checkFormat(); | - |
| 214 | | - |
| 215 | return d->brect; | - |
| 216 | } | - |
| 217 | | - |
| 218 | | - |
| 219 | | - |
| 220 | | - |
| 221 | | - |
| 222 | | - |
| 223 | void QPicture::setBoundingRect(const QRect &r) | - |
| 224 | { | - |
| 225 | d_func()->override_rect = r; | - |
| 226 | } | - |
| 227 | bool QPicture::play(QPainter *painter) | - |
| 228 | { | - |
| 229 | QPicturePrivate * const d = d_func(); | - |
| 230 | | - |
| 231 | if (d->pictb.size() == 0) | - |
| 232 | return true; | - |
| 233 | | - |
| 234 | if (!d->formatOk && !d->checkFormat()) | - |
| 235 | return false; | - |
| 236 | | - |
| 237 | d->pictb.open(QIODevice::ReadOnly); | - |
| 238 | QDataStream s; | - |
| 239 | s.setDevice(&d->pictb); | - |
| 240 | s.device()->seek(10); | - |
| 241 | s.setVersion(d->formatMajor == 4 ? 3 : d->formatMajor); | - |
| 242 | | - |
| 243 | quint8 c, clen; | - |
| 244 | quint32 nrecords; | - |
| 245 | s >> c >> clen; | - |
| 246 | ((!(c == QPicturePrivate::PdcBegin)) ? qt_assert("c == QPicturePrivate::PdcBegin",__FILE__,427433) : qt_noop()); | - |
| 247 | | - |
| 248 | if (d->formatMajor >= 4) { | - |
| 249 | qint32 dummy; | - |
| 250 | s >> dummy >> dummy >> dummy >> dummy; | - |
| 251 | } | - |
| 252 | s >> nrecords; | - |
| 253 | if (!exec(painter, s, nrecords)) { | - |
| 254 | QMessageLogger(__FILE__, 435441, __PRETTY_FUNCTION__).warning("QPicture::play: Format error"); | - |
| 255 | d->pictb.close(); | - |
| 256 | return false; | - |
| 257 | } | - |
| 258 | d->pictb.close(); | - |
| 259 | return true; | - |
| 260 | } | - |
| 261 | | - |
| 262 | | - |
| 263 | | - |
| 264 | | - |
| 265 | | - |
| 266 | class QFakeDevice : public QPaintDevice | - |
| 267 | { | - |
| 268 | public: | - |
| 269 | QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); } | - |
| 270 | void setDpiX(int dpi) { dpi_x = dpi; } | - |
| 271 | void setDpiY(int dpi) { dpi_y = dpi; } | - |
| 272 | QPaintEngine *paintEngine() const override { return 0; } | - |
| 273 | int metric(PaintDeviceMetric m) const override | - |
| 274 | { | - |
| 275 | switch(m) { | - |
| 276 | case PdmPhysicalDpiX: | - |
| 277 | case PdmDpiX: | - |
| 278 | return dpi_x; | - |
| 279 | case PdmPhysicalDpiY: | - |
| 280 | case PdmDpiY: | - |
| 281 | return dpi_y; | - |
| 282 | default: | - |
| 283 | return QPaintDevice::metric(m); | - |
| 284 | } | - |
| 285 | } | - |
| 286 | | - |
| 287 | private: | - |
| 288 | int dpi_x; | - |
| 289 | int dpi_y; | - |
| 290 | }; | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | | - |
| 295 | | - |
| 296 | | - |
| 297 | | - |
| 298 | bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) | - |
| 299 | { | - |
| 300 | QPicturePrivate * const d = d_func(); | - |
| 301 | | - |
| 302 | int strm_pos; | - |
| 303 | | - |
| 304 | quint8 c; | - |
| 305 | quint8 tiny_len; | - |
| 306 | qint32 len; | - |
| 307 | qint16 i_16, i1_16, i2_16; | - |
| 308 | qint8 i_8; | - |
| 309 | quint32 ul; | - |
| 310 | double dbl; | - |
| 311 | bool bl; | - |
| 312 | QByteArray str1; | - |
| 313 | QString str; | - |
| 314 | QPointF p, p1, p2; | - |
| 315 | QPoint ip, ip1, ip2; | - |
| 316 | QRect ir; | - |
| 317 | QRectF r; | - |
| 318 | QPolygonF a; | - |
| 319 | QPolygon ia; | - |
| 320 | QColor color; | - |
| 321 | QFont font; | - |
| 322 | QPen pen; | - |
| 323 | QBrush brush; | - |
| 324 | QRegion rgn; | - |
| 325 | QMatrix wmatrix; | - |
| 326 | QTransform matrix; | - |
| 327 | | - |
| 328 | QTransform worldMatrix = painter->transform(); | - |
| 329 | worldMatrix.scale(qreal(painter->device()->logicalDpiX()) / qreal(qt_defaultDpiX()), | - |
| 330 | qreal(painter->device()->logicalDpiY()) / qreal(qt_defaultDpiY())); | - |
| 331 | painter->setTransform(worldMatrix); | - |
| 332 | | - |
| 333 | while (nrecords-- && !s.atEnd()) { | - |
| 334 | s >> c; | - |
| 335 | s >> tiny_len; | - |
| 336 | if (tiny_len == 255) | - |
| 337 | s >> len; | - |
| 338 | else | - |
| 339 | len = tiny_len; | - |
| 340 | | - |
| 341 | strm_pos = s.device()->pos(); | - |
| 342 | | - |
| 343 | switch (c) { | - |
| 344 | case QPicturePrivate::PdcNOP: | - |
| 345 | break; | - |
| 346 | case QPicturePrivate::PdcDrawPoint: | - |
| 347 | if (d->formatMajor <= 5) { | - |
| 348 | s >> ip; | - |
| 349 | painter->drawPoint(ip); | - |
| 350 | } else { | - |
| 351 | s >> p; | - |
| 352 | painter->drawPoint(p); | - |
| 353 | } | - |
| 354 | break; | - |
| 355 | case QPicturePrivate::PdcDrawPoints: | - |
| 356 | | - |
| 357 | | - |
| 358 | | - |
| 359 | break; | - |
| 360 | case QPicturePrivate::PdcDrawPath: { | - |
| 361 | QPainterPath path; | - |
| 362 | s >> path; | - |
| 363 | painter->drawPath(path); | - |
| 364 | break; | - |
| 365 | } | - |
| 366 | case QPicturePrivate::PdcDrawLine: | - |
| 367 | if (d->formatMajor <= 5) { | - |
| 368 | s >> ip1 >> ip2; | - |
| 369 | painter->drawLine(ip1, ip2); | - |
| 370 | } else { | - |
| 371 | s >> p1 >> p2; | - |
| 372 | painter->drawLine(p1, p2); | - |
| 373 | } | - |
| 374 | break; | - |
| 375 | case QPicturePrivate::PdcDrawRect: | - |
| 376 | if (d->formatMajor <= 5) { | - |
| 377 | s >> ir; | - |
| 378 | painter->drawRect(ir); | - |
| 379 | } else { | - |
| 380 | s >> r; | - |
| 381 | painter->drawRect(r); | - |
| 382 | } | - |
| 383 | break; | - |
| 384 | case QPicturePrivate::PdcDrawRoundRect: | - |
| 385 | if (d->formatMajor <= 5) { | - |
| 386 | s >> ir >> i1_16 >> i2_16; | - |
| 387 | painter->drawRoundedRect(ir, i1_16, i2_16, Qt::RelativeSize); | - |
| 388 | } else { | - |
| 389 | s >> r >> i1_16 >> i2_16; | - |
| 390 | painter->drawRoundedRect(r, i1_16, i2_16, Qt::RelativeSize); | - |
| 391 | } | - |
| 392 | break; | - |
| 393 | case QPicturePrivate::PdcDrawEllipse: | - |
| 394 | if (d->formatMajor <= 5) { | - |
| 395 | s >> ir; | - |
| 396 | painter->drawEllipse(ir); | - |
| 397 | } else { | - |
| 398 | s >> r; | - |
| 399 | painter->drawEllipse(r); | - |
| 400 | } | - |
| 401 | break; | - |
| 402 | case QPicturePrivate::PdcDrawArc: | - |
| 403 | if (d->formatMajor <= 5) { | - |
| 404 | s >> ir; | - |
| 405 | r = ir; | - |
| 406 | } else { | - |
| 407 | s >> r; | - |
| 408 | } | - |
| 409 | s >> i1_16 >> i2_16; | - |
| 410 | painter->drawArc(r, i1_16, i2_16); | - |
| 411 | break; | - |
| 412 | case QPicturePrivate::PdcDrawPie: | - |
| 413 | if (d->formatMajor <= 5) { | - |
| 414 | s >> ir; | - |
| 415 | r = ir; | - |
| 416 | } else { | - |
| 417 | s >> r; | - |
| 418 | } | - |
| 419 | s >> i1_16 >> i2_16; | - |
| 420 | painter->drawPie(r, i1_16, i2_16); | - |
| 421 | break; | - |
| 422 | case QPicturePrivate::PdcDrawChord: | - |
| 423 | if (d->formatMajor <= 5) { | - |
| 424 | s >> ir; | - |
| 425 | r = ir; | - |
| 426 | } else { | - |
| 427 | s >> r; | - |
| 428 | } | - |
| 429 | s >> i1_16 >> i2_16; | - |
| 430 | painter->drawChord(r, i1_16, i2_16); | - |
| 431 | break; | - |
| 432 | case QPicturePrivate::PdcDrawLineSegments: | - |
| 433 | s >> ia; | - |
| 434 | painter->drawLines(ia); | - |
| 435 | ia.clear(); | - |
| 436 | break; | - |
| 437 | case QPicturePrivate::PdcDrawPolyline: | - |
| 438 | if (d->formatMajor <= 5) { | - |
| 439 | s >> ia; | - |
| 440 | painter->drawPolyline(ia); | - |
| 441 | ia.clear(); | - |
| 442 | } else { | - |
| 443 | s >> a; | - |
| 444 | painter->drawPolyline(a); | - |
| 445 | a.clear(); | - |
| 446 | } | - |
| 447 | break; | - |
| 448 | case QPicturePrivate::PdcDrawPolygon: | - |
| 449 | if (d->formatMajor <= 5) { | - |
| 450 | s >> ia >> i_8; | - |
| 451 | painter->drawPolygon(ia, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - |
| 452 | a.clear(); | - |
| 453 | } else { | - |
| 454 | s >> a >> i_8; | - |
| 455 | painter->drawPolygon(a, i_8 ? Qt::WindingFill : Qt::OddEvenFill); | - |
| 456 | a.clear(); | - |
| 457 | } | - |
| 458 | break; | - |
| 459 | case QPicturePrivate::PdcDrawCubicBezier: { | - |
| 460 | s >> ia; | - |
| 461 | QPainterPath path; | - |
| 462 | ((!(ia.size() == 4)) ? qt_assert("ia.size() == 4",__FILE__,643649) : qt_noop()); | - |
| 463 | path.moveTo(ia.at(0)); | - |
| 464 | path.cubicTo(ia.at(1), ia.at(2), ia.at(3)); | - |
| 465 | painter->strokePath(path, painter->pen()); | - |
| 466 | a.clear(); | - |
| 467 | } | - |
| 468 | break; | - |
| 469 | case QPicturePrivate::PdcDrawText: | - |
| 470 | s >> ip >> str1; | - |
| 471 | painter->drawText(ip, QString::fromLatin1(str1)); | - |
| 472 | break; | - |
| 473 | case QPicturePrivate::PdcDrawTextFormatted: | - |
| 474 | s >> ir >> i_16 >> str1; | - |
| 475 | painter->drawText(ir, i_16, QString::fromLatin1(str1)); | - |
| 476 | break; | - |
| 477 | case QPicturePrivate::PdcDrawText2: | - |
| 478 | if (d->formatMajor <= 5) { | - |
| 479 | s >> ip >> str; | - |
| 480 | painter->drawText(ip, str); | - |
| 481 | } else { | - |
| 482 | s >> p >> str; | - |
| 483 | painter->drawText(p, str); | - |
| 484 | } | - |
| 485 | break; | - |
| 486 | case QPicturePrivate::PdcDrawText2Formatted: | - |
| 487 | s >> ir; | - |
| 488 | s >> i_16; | - |
| 489 | s >> str; | - |
| 490 | painter->drawText(ir, i_16, str); | - |
| 491 | break; | - |
| 492 | case QPicturePrivate::PdcDrawTextItem: { | - |
| 493 | s >> p >> str >> font >> ul; | - |
| 494 | | - |
| 495 | | - |
| 496 | | - |
| 497 | | - |
| 498 | | - |
| 499 | if (d->formatMajor >= 9) { | - |
| 500 | s >> dbl; | - |
| 501 | QFont fnt(font); | - |
| 502 | if (dbl != 1.0) { | - |
| 503 | QFakeDevice fake; | - |
| 504 | fake.setDpiX(qRound(dbl*qt_defaultDpiX())); | - |
| 505 | fake.setDpiY(qRound(dbl*qt_defaultDpiY())); | - |
| 506 | fnt = QFont(font, &fake); | - |
| 507 | } | - |
| 508 | | - |
| 509 | qreal justificationWidth; | - |
| 510 | s >> justificationWidth; | - |
| 511 | | - |
| 512 | int flags = Qt::TextSingleLine | Qt::TextDontClip | Qt::TextForceLeftToRight; | - |
| 513 | | - |
| 514 | QSizeF size(1, 1); | - |
| 515 | if (justificationWidth > 0) { | - |
| 516 | size.setWidth(justificationWidth); | - |
| 517 | flags |= Qt::TextJustificationForced; | - |
| 518 | flags |= Qt::AlignJustify; | - |
| 519 | } | - |
| 520 | | - |
| 521 | QFontMetrics fm(fnt); | - |
| 522 | QPointF pt(p.x(), p.y() - fm.ascent()); | - |
| 523 | qt_format_text(fnt, QRectF(pt, size), flags, 0, | - |
| 524 | str, 0, 0, 0, 0, painter); | - |
| 525 | } else { | - |
| 526 | qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, 0, | - |
| 527 | str, 0, 0, 0, 0, painter); | - |
| 528 | } | - |
| 529 | | - |
| 530 | break; | - |
| 531 | } | - |
| 532 | case QPicturePrivate::PdcDrawPixmap: { | - |
| 533 | QPixmap pixmap; | - |
| 534 | if (d->formatMajor < 4) { | - |
| 535 | s >> ip >> pixmap; | - |
| 536 | painter->drawPixmap(ip, pixmap); | - |
| 537 | } else if (d->formatMajor <= 5) { | - |
| 538 | s >> ir >> pixmap; | - |
| 539 | painter->drawPixmap(ir, pixmap); | - |
| 540 | } else { | - |
| 541 | QRectF sr; | - |
| 542 | if (d->in_memory_only) { | - |
| 543 | int index; | - |
| 544 | s >> r >> index >> sr; | - |
| 545 | ((!(index < d->pixmap_list.size())) ? qt_assert("index < d->pixmap_list.size()",__FILE__,726732) : qt_noop()); | - |
| 546 | pixmap = d->pixmap_list.at(index); | - |
| 547 | } else { | - |
| 548 | s >> r >> pixmap >> sr; | - |
| 549 | } | - |
| 550 | painter->drawPixmap(r, pixmap, sr); | - |
| 551 | } | - |
| 552 | } | - |
| 553 | break; | - |
| 554 | case QPicturePrivate::PdcDrawTiledPixmap: { | - |
| 555 | QPixmap pixmap; | - |
| 556 | if (d->in_memory_only) { | - |
| 557 | int index; | - |
| 558 | s >> r >> index >> p; | - |
| 559 | ((!(index < d->pixmap_list.size())) ? qt_assert("index < d->pixmap_list.size()",__FILE__,740746) : qt_noop()); | - |
| 560 | pixmap = d->pixmap_list.at(index); | - |
| 561 | } else { | - |
| 562 | s >> r >> pixmap >> p; | - |
| 563 | } | - |
| 564 | painter->drawTiledPixmap(r, pixmap, p); | - |
| 565 | } | - |
| 566 | break; | - |
| 567 | case QPicturePrivate::PdcDrawImage: { | - |
| 568 | QImage image; | - |
| 569 | if (d->formatMajor < 4) { | - |
| 570 | s >> p >> image; | - |
| 571 | painter->drawImage(p, image); | - |
| 572 | } else if (d->formatMajor <= 5){ | - |
| 573 | s >> ir >> image; | - |
| 574 | painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height())); | - |
| 575 | } else { | - |
| 576 | QRectF sr; | - |
| 577 | if (d->in_memory_only) { | - |
| 578 | int index; | - |
| 579 | s >> r >> index >> sr >> ul; | - |
| 580 | ((!(index < d->image_list.size())) ? qt_assert("index < d->image_list.size()",__FILE__,761767) : qt_noop()); | - |
| 581 | image = d->image_list.at(index); | - |
| 582 | } else { | - |
| 583 | s >> r >> image >> sr >> ul; | - |
| 584 | } | - |
| 585 | painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul)); | - |
| 586 | } | - |
| 587 | } | - |
| 588 | break; | - |
| 589 | case QPicturePrivate::PdcBegin: | - |
| 590 | s >> ul; | - |
| 591 | if (!exec(painter, s, ul)) | - |
| 592 | return false; | - |
| 593 | break; | - |
| 594 | case QPicturePrivate::PdcEnd: | - |
| 595 | if (nrecords == 0) | - |
| 596 | return true; | - |
| 597 | break; | - |
| 598 | case QPicturePrivate::PdcSave: | - |
| 599 | painter->save(); | - |
| 600 | break; | - |
| 601 | case QPicturePrivate::PdcRestore: | - |
| 602 | painter->restore(); | - |
| 603 | break; | - |
| 604 | case QPicturePrivate::PdcSetBkColor: | - |
| 605 | s >> color; | - |
| 606 | painter->setBackground(color); | - |
| 607 | break; | - |
| 608 | case QPicturePrivate::PdcSetBkMode: | - |
| 609 | s >> i_8; | - |
| 610 | painter->setBackgroundMode((Qt::BGMode)i_8); | - |
| 611 | break; | - |
| 612 | case QPicturePrivate::PdcSetROP: | - |
| 613 | s >> i_8; | - |
| 614 | break; | - |
| 615 | case QPicturePrivate::PdcSetBrushOrigin: | - |
| 616 | if (d->formatMajor <= 5) { | - |
| 617 | s >> ip; | - |
| 618 | painter->setBrushOrigin(ip); | - |
| 619 | } else { | - |
| 620 | s >> p; | - |
| 621 | painter->setBrushOrigin(p); | - |
| 622 | } | - |
| 623 | break; | - |
| 624 | case QPicturePrivate::PdcSetFont: | - |
| 625 | s >> font; | - |
| 626 | painter->setFont(font); | - |
| 627 | break; | - |
| 628 | case QPicturePrivate::PdcSetPen: | - |
| 629 | if (d->in_memory_only) { | - |
| 630 | int index; | - |
| 631 | s >> index; | - |
| 632 | ((!(index < d->pen_list.size())) ? qt_assert("index < d->pen_list.size()",__FILE__,813819) : qt_noop()); | - |
| 633 | pen = d->pen_list.at(index); | - |
| 634 | } else { | - |
| 635 | s >> pen; | - |
| 636 | } | - |
| 637 | painter->setPen(pen); | - |
| 638 | break; | - |
| 639 | case QPicturePrivate::PdcSetBrush: | - |
| 640 | if (d->in_memory_only) { | - |
| 641 | int index; | - |
| 642 | s >> index; | - |
| 643 | ((!(index < d->brush_list.size())) ? qt_assert("index < d->brush_list.size()",__FILE__,824830) : qt_noop()); | - |
| 644 | brush = d->brush_list.at(index); | - |
| 645 | } else { | - |
| 646 | s >> brush; | - |
| 647 | } | - |
| 648 | painter->setBrush(brush); | - |
| 649 | break; | - |
| 650 | case QPicturePrivate::PdcSetVXform: | - |
| 651 | s >> i_8; | - |
| 652 | painter->setViewTransformEnabled(i_8); | - |
| 653 | break; | - |
| 654 | case QPicturePrivate::PdcSetWindow: | - |
| 655 | if (d->formatMajor <= 5) { | - |
| 656 | s >> ir; | - |
| 657 | painter->setWindow(ir); | - |
| 658 | } else { | - |
| 659 | s >> r; | - |
| 660 | painter->setWindow(r.toRect()); | - |
| 661 | } | - |
| 662 | break; | - |
| 663 | case QPicturePrivate::PdcSetViewport: | - |
| 664 | if (d->formatMajor <= 5) { | - |
| 665 | s >> ir; | - |
| 666 | painter->setViewport(ir); | - |
| 667 | } else { | - |
| 668 | s >> r; | - |
| 669 | painter->setViewport(r.toRect()); | - |
| 670 | } | - |
| 671 | break; | - |
| 672 | case QPicturePrivate::PdcSetWXform: | - |
| 673 | s >> i_8; | - |
| 674 | painter->setMatrixEnabled(i_8); | - |
| 675 | break; | - |
| 676 | case QPicturePrivate::PdcSetWMatrix: | - |
| 677 | if (d->formatMajor >= 8) { | - |
| 678 | s >> matrix >> i_8; | - |
| 679 | } else { | - |
| 680 | s >> wmatrix >> i_8; | - |
| 681 | matrix = QTransform(wmatrix); | - |
| 682 | } | - |
| 683 | | - |
| 684 | painter->setTransform(matrix * worldMatrix, i_8); | - |
| 685 | break; | - |
| 686 | case QPicturePrivate::PdcSetClip: | - |
| 687 | s >> i_8; | - |
| 688 | painter->setClipping(i_8); | - |
| 689 | break; | - |
| 690 | case QPicturePrivate::PdcSetClipRegion: | - |
| 691 | s >> rgn >> i_8; | - |
| 692 | if (d->formatMajor >= 9) { | - |
| 693 | painter->setClipRegion(rgn, Qt::ClipOperation(i_8)); | - |
| 694 | } else { | - |
| 695 | painter->setClipRegion(rgn); | - |
| 696 | } | - |
| 697 | break; | - |
| 698 | case QPicturePrivate::PdcSetClipPath: | - |
| 699 | { | - |
| 700 | QPainterPath path; | - |
| 701 | s >> path >> i_8; | - |
| 702 | painter->setClipPath(path, Qt::ClipOperation(i_8)); | - |
| 703 | break; | - |
| 704 | } | - |
| 705 | case QPicturePrivate::PdcSetRenderHint: | - |
| 706 | s >> ul; | - |
| 707 | painter->setRenderHint(QPainter::Antialiasing, | - |
| 708 | bool(ul & QPainter::Antialiasing)); | - |
| 709 | painter->setRenderHint(QPainter::SmoothPixmapTransform, | - |
| 710 | bool(ul & QPainter::SmoothPixmapTransform)); | - |
| 711 | break; | - |
| 712 | case QPicturePrivate::PdcSetCompositionMode: | - |
| 713 | s >> ul; | - |
| 714 | painter->setCompositionMode((QPainter::CompositionMode)ul); | - |
| 715 | break; | - |
| 716 | case QPicturePrivate::PdcSetClipEnabled: | - |
| 717 | s >> bl; | - |
| 718 | painter->setClipping(bl); | - |
| 719 | break; | - |
| 720 | case QPicturePrivate::PdcSetOpacity: | - |
| 721 | s >> dbl; | - |
| 722 | painter->setOpacity(qreal(dbl)); | - |
| 723 | break; | - |
| 724 | default: | - |
| 725 | QMessageLogger(__FILE__, 906912, __PRETTY_FUNCTION__).warning("QPicture::play: Invalid command %d", c); | - |
| 726 | if (len) | - |
| 727 | s.device()->seek(s.device()->pos()+len); | - |
| 728 | } | - |
| 729 | | - |
| 730 | | - |
| 731 | ((!(qint32(s.device()->pos() - strm_pos) == len)) ? qt_assert("qint32(s.device()->pos() - strm_pos) == len",__FILE__,912918) : qt_noop()); | - |
| 732 | | - |
| 733 | } | - |
| 734 | return false; | - |
| 735 | } | - |
| 736 | int QPicture::metric(PaintDeviceMetric m) const | - |
| 737 | { | - |
| 738 | int val; | - |
| 739 | QRect brect = boundingRect(); | - |
| 740 | switch (m) { | - |
| 741 | case PdmWidth: | - |
| 742 | val = brect.width(); | - |
| 743 | break; | - |
| 744 | case PdmHeight: | - |
| 745 | val = brect.height(); | - |
| 746 | break; | - |
| 747 | case PdmWidthMM: | - |
| 748 | val = int(25.4/qt_defaultDpiX()*brect.width()); | - |
| 749 | break; | - |
| 750 | case PdmHeightMM: | - |
| 751 | val = int(25.4/qt_defaultDpiY()*brect.height()); | - |
| 752 | break; | - |
| 753 | case PdmDpiX: | - |
| 754 | case PdmPhysicalDpiX: | - |
| 755 | val = qt_defaultDpiX(); | - |
| 756 | break; | - |
| 757 | case PdmDpiY: | - |
| 758 | case PdmPhysicalDpiY: | - |
| 759 | val = qt_defaultDpiY(); | - |
| 760 | break; | - |
| 761 | case PdmNumColors: | - |
| 762 | val = 16777216; | - |
| 763 | break; | - |
| 764 | case PdmDepth: | - |
| 765 | val = 24; | - |
| 766 | break; | - |
| 767 | case PdmDevicePixelRatio: | - |
| 768 | val = 1; | - |
| 769 | break; | - |
| 770 | case PdmDevicePixelRatioScaled: | - |
| 771 | val = 1 * QPaintDevice::devicePixelRatioFScale(); | - |
| 772 | break; | - |
| 773 | default: | - |
| 774 | val = 0; | - |
| 775 | QMessageLogger(__FILE__, 969975, __PRETTY_FUNCTION__).warning("QPicture::metric: Invalid metric command"); | - |
| 776 | } | - |
| 777 | return val; | - |
| 778 | } | - |
| 779 | QPicture& QPicture::operator=(const QPicture &p) | - |
| 780 | { | - |
| 781 | d_ptr = p.d_ptr; | - |
| 782 | return *this; | - |
| 783 | } | - |
| 784 | QPicturePrivate::QPicturePrivate() | - |
| 785 | : in_memory_only(false) | - |
| 786 | { | - |
| 787 | } | - |
| 788 | | - |
| 789 | | - |
| 790 | | - |
| 791 | | - |
| 792 | | - |
| 793 | | - |
| 794 | QPicturePrivate::QPicturePrivate(const QPicturePrivate &other) | - |
| 795 | : trecs(other.trecs), | - |
| 796 | formatOk(other.formatOk), | - |
| 797 | formatMinor(other.formatMinor), | - |
| 798 | brect(other.brect), | - |
| 799 | override_rect(other.override_rect), | - |
| 800 | in_memory_only(false) | - |
| 801 | { | - |
| 802 | pictb.setData(other.pictb.data(), other.pictb.size()); | - |
| 803 | if (other.pictb.isOpen()) { | - |
| 804 | pictb.open(other.pictb.openMode()); | - |
| 805 | pictb.seek(other.pictb.pos()); | - |
| 806 | } | - |
| 807 | } | - |
| 808 | | - |
| 809 | | - |
| 810 | | - |
| 811 | | - |
| 812 | | - |
| 813 | | - |
| 814 | | - |
| 815 | void QPicturePrivate::resetFormat() | - |
| 816 | { | - |
| 817 | formatOk = false; | - |
| 818 | formatMajor = mfhdr_maj; | - |
| 819 | formatMinor = mfhdr_min; | - |
| 820 | } | - |
| 821 | bool QPicturePrivate::checkFormat() | - |
| 822 | { | - |
| 823 | resetFormat(); | - |
| 824 | | - |
| 825 | | - |
| 826 | if (pictb.size() == 0 || pictb.isOpen()) | - |
| 827 | return false; | - |
| 828 | | - |
| 829 | pictb.open(QIODevice::ReadOnly); | - |
| 830 | QDataStream s; | - |
| 831 | s.setDevice(&pictb); | - |
| 832 | | - |
| 833 | char mf_id[4]; | - |
| 834 | s.readRawData(mf_id, 4); | - |
| 835 | if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0) { | - |
| 836 | QMessageLogger(__FILE__, 10731079, __PRETTY_FUNCTION__).warning("QPicturePaintEngine::checkFormat: Incorrect header"); | - |
| 837 | pictb.close(); | - |
| 838 | return false; | - |
| 839 | } | - |
| 840 | | - |
| 841 | int cs_start = sizeof(quint32); | - |
| 842 | int data_start = cs_start + sizeof(quint16); | - |
| 843 | quint16 cs,ccs; | - |
| 844 | QByteArray buf = pictb.buffer(); | - |
| 845 | | - |
| 846 | s >> cs; | - |
| 847 | ccs = (quint16) qChecksum(buf.constData() + data_start, buf.size() - data_start); | - |
| 848 | if (ccs != cs) { | - |
| 849 | QMessageLogger(__FILE__, 10861092, __PRETTY_FUNCTION__).warning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected", | - |
| 850 | ccs, cs); | - |
| 851 | pictb.close(); | - |
| 852 | return false; | - |
| 853 | } | - |
| 854 | | - |
| 855 | quint16 major, minor; | - |
| 856 | s >> major >> minor; | - |
| 857 | if (major > mfhdr_maj) { | - |
| 858 | QMessageLogger(__FILE__, 10951101, __PRETTY_FUNCTION__).warning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d", | - |
| 859 | major, minor); | - |
| 860 | pictb.close(); | - |
| 861 | return false; | - |
| 862 | } | - |
| 863 | s.setVersion(major != 4 ? major : 3); | - |
| 864 | | - |
| 865 | quint8 c, clen; | - |
| 866 | s >> c >> clen; | - |
| 867 | if (c == QPicturePrivate::PdcBegin) { | - |
| 868 | if (!(major >= 1 && major <= 3)) { | - |
| 869 | qint32 l, t, w, h; | - |
| 870 | s >> l >> t >> w >> h; | - |
| 871 | brect = QRect(l, t, w, h); | - |
| 872 | } | - |
| 873 | } else { | - |
| 874 | QMessageLogger(__FILE__, 11111117, __PRETTY_FUNCTION__).warning("QPicturePaintEngine::checkFormat: Format error"); | - |
| 875 | pictb.close(); | - |
| 876 | return false; | - |
| 877 | } | - |
| 878 | pictb.close(); | - |
| 879 | | - |
| 880 | formatOk = true; | - |
| 881 | formatMajor = major; | - |
| 882 | formatMinor = minor; | - |
| 883 | return true; | - |
| 884 | } | - |
| 885 | | - |
| 886 | | - |
| 887 | QPaintEngine *QPicture::paintEngine() const | - |
| 888 | { | - |
| 889 | if (!d_func()->paintEngine) | - |
| 890 | const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); | - |
| 891 | return d_func()->paintEngine.data(); | - |
| 892 | } | - |
| 893 | QDataStream &operator<<(QDataStream &s, const QPicture &r) | - |
| 894 | { | - |
| 895 | quint32 size = r.d_func()->pictb.buffer().size(); | - |
| 896 | s << size; | - |
| 897 | | - |
| 898 | if (size == 0) | - |
| 899 | return s; | - |
| 900 | | - |
| 901 | s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size()); | - |
| 902 | return s; | - |
| 903 | } | - |
| 904 | QDataStream &operator>>(QDataStream &s, QPicture &r) | - |
| 905 | { | - |
| 906 | QDataStream sr; | - |
| 907 | | - |
| 908 | | - |
| 909 | sr.setDevice(&r.d_func()->pictb); | - |
| 910 | sr.setVersion(r.d_func()->formatMajor); | - |
| 911 | quint32 len; | - |
| 912 | s >> len; | - |
| 913 | QByteArray data; | - |
| 914 | if (len > 0) { | - |
| 915 | data.resize(len); | - |
| 916 | s.readRawData(data.data(), len); | - |
| 917 | } | - |
| 918 | | - |
| 919 | r.d_func()->pictb.setData(data); | - |
| 920 | r.d_func()->resetFormat(); | - |
| 921 | return s; | - |
| 922 | } | - |
| 923 | | - |
| 924 | | - |
| 925 | | - |
| 926 | | - |
| 927 | | - |
| 928 | | - |
| 929 | | - |
| 930 | const char* QPicture::pictureFormat(const QString &fileName) | - |
| 931 | { | - |
| 932 | return QPictureIO::pictureFormat(fileName); | - |
| 933 | } | - |
| 934 | QList<QByteArray> QPicture::inputFormats() | - |
| 935 | { | - |
| 936 | return QPictureIO::inputFormats(); | - |
| 937 | } | - |
| 938 | | - |
| 939 | static QStringList qToStringList(const QList<QByteArray> &arr) | - |
| 940 | { | - |
| 941 | QStringList list; | - |
| 942 | const int count = arr.count(); | - |
| 943 | list.reserve(count); | - |
| 944 | for (int i = 0; i < count; ++i) | - |
| 945 | list.append(QString::fromLatin1(arr.at(i))); | - |
| 946 | return list; | - |
| 947 | } | - |
| 948 | QStringList QPicture::inputFormatList() | - |
| 949 | { | - |
| 950 | return qToStringList(QPictureIO::inputFormats()); | - |
| 951 | } | - |
| 952 | QStringList QPicture::outputFormatList() | - |
| 953 | { | - |
| 954 | return qToStringList(QPictureIO::outputFormats()); | - |
| 955 | } | - |
| 956 | QList<QByteArray> QPicture::outputFormats() | - |
| 957 | { | - |
| 958 | return QPictureIO::outputFormats(); | - |
| 959 | } | - |
| 960 | struct QPictureIOData | - |
| 961 | { | - |
| 962 | QPicture pi; | - |
| 963 | int iostat; | - |
| 964 | QByteArray frmt; | - |
| 965 | QIODevice *iodev; | - |
| 966 | QString fname; | - |
| 967 | QString descr; | - |
| 968 | const char *parameters; | - |
| 969 | int quality; | - |
| 970 | float gamma; | - |
| 971 | }; | - |
| 972 | | - |
| 973 | | - |
| 974 | | - |
| 975 | | - |
| 976 | | - |
| 977 | QPictureIO::QPictureIO() | - |
| 978 | { | - |
| 979 | init(); | - |
| 980 | } | - |
| 981 | | - |
| 982 | | - |
| 983 | | - |
| 984 | | - |
| 985 | | - |
| 986 | | - |
| 987 | QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format) | - |
| 988 | { | - |
| 989 | init(); | - |
| 990 | d->iodev = ioDevice; | - |
| 991 | d->frmt = format; | - |
| 992 | } | - |
| 993 | | - |
| 994 | | - |
| 995 | | - |
| 996 | | - |
| 997 | | - |
| 998 | | - |
| 999 | QPictureIO::QPictureIO(const QString &fileName, const char* format) | - |
| 1000 | { | - |
| 1001 | init(); | - |
| 1002 | d->frmt = format; | - |
| 1003 | d->fname = fileName; | - |
| 1004 | } | - |
| 1005 | | - |
| 1006 | | - |
| 1007 | | - |
| 1008 | | - |
| 1009 | | - |
| 1010 | void QPictureIO::init() | - |
| 1011 | { | - |
| 1012 | d = new QPictureIOData(); | - |
| 1013 | d->parameters = 0; | - |
| 1014 | d->quality = -1; | - |
| 1015 | d->gamma=0.0f; | - |
| 1016 | d->iostat = 0; | - |
| 1017 | d->iodev = 0; | - |
| 1018 | } | - |
| 1019 | | - |
| 1020 | | - |
| 1021 | | - |
| 1022 | | - |
| 1023 | | - |
| 1024 | QPictureIO::~QPictureIO() | - |
| 1025 | { | - |
| 1026 | if (d->parameters) | - |
| 1027 | delete [] d->parameters; | - |
| 1028 | delete d; | - |
| 1029 | } | - |
| 1030 | | - |
| 1031 | | - |
| 1032 | | - |
| 1033 | | - |
| 1034 | | - |
| 1035 | | - |
| 1036 | class QPictureHandler | - |
| 1037 | { | - |
| 1038 | public: | - |
| 1039 | QPictureHandler(const char *f, const char *h, const QByteArray& fl, | - |
| 1040 | picture_io_handler r, picture_io_handler w); | - |
| 1041 | QByteArray format; | - |
| 1042 | QRegExp header; | - |
| 1043 | enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode; | - |
| 1044 | picture_io_handler read_picture; | - |
| 1045 | picture_io_handler write_picture; | - |
| 1046 | bool obsolete; | - |
| 1047 | }; | - |
| 1048 | | - |
| 1049 | QPictureHandler::QPictureHandler(const char *f, const char *h, const QByteArray& fl, | - |
| 1050 | picture_io_handler r, picture_io_handler w) | - |
| 1051 | : format(f), header(QString::fromLatin1(h)) | - |
| 1052 | { | - |
| 1053 | text_mode = Untranslated; | - |
| 1054 | if (fl.contains('t')) | - |
| 1055 | text_mode = TranslateIn; | - |
| 1056 | else if (fl.contains('T')) | - |
| 1057 | text_mode = TranslateInOut; | - |
| 1058 | obsolete = fl.contains('O'); | - |
| 1059 | read_picture = r; | - |
| 1060 | write_picture = w; | - |
| 1061 | } | - |
| 1062 | | - |
| 1063 | typedef QList<QPictureHandler *> QPHList; | - |
| 1064 | namespace { namespace Q_QGS_pictureHandlers { typedef QPHList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QPHList, Q_QGS_pictureHandlers::innerFunction, Q_QGS_pictureHandlers::guard> pictureHandlers; | - |
| 1065 | | - |
| 1066 | void qt_init_picture_plugins() | - |
| 1067 | { | - |
| 1068 | typedef QMultiMap<int, QString> PluginKeyMap; | - |
| 1069 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; | - |
| 1070 | | - |
| 1071 | static QBasicMutex mutex; | - |
| 1072 | QMutexLocker locker(&mutex); | - |
| 1073 | static QFactoryLoader loader("org.qt-project.Qt.QPictureFormatInterface", | - |
| 1074 | ([]() -> QString { enum { Size = sizeof(u"" "/pictureformats")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/pictureformats" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - |
| 1075 | | - |
| 1076 | const PluginKeyMap keyMap = loader.keyMap(); | - |
| 1077 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); | - |
| 1078 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend| TRUE | never evaluated | | FALSE | never evaluated |
; ++it) { | 0 |
| 1079 | if (QPictureFormatPlugin *format = qobject_cast<QPictureFormatPlugin*>(loader.instance(it.key()))| TRUE | never evaluated | | FALSE | never evaluated |
) | 0 |
| 1080 | format->installIOHandler(it.value()); never executed: format->installIOHandler(it.value()); | 0 |
| 1081 | } never executed: end of block | 0 |
| 1082 | } never executed: end of block | 0 |
| 1083 | | - |
| 1084 | static void cleanup() | - |
| 1085 | { | - |
| 1086 | | - |
| 1087 | if (QPHList *list = pictureHandlers()) { | - |
| 1088 | qDeleteAll(*list); | - |
| 1089 | list->clear(); | - |
| 1090 | } | - |
| 1091 | } | - |
| 1092 | | - |
| 1093 | void qt_init_picture_handlers() | - |
| 1094 | { | - |
| 1095 | static QBasicAtomicInt done = { 0 }; | - |
| 1096 | if (done.testAndSetRelaxed(0, 1)) { | - |
| 1097 | qAddPostRoutine(cleanup); | - |
| 1098 | } | - |
| 1099 | } | - |
| 1100 | | - |
| 1101 | static QPictureHandler *get_picture_handler(const char *format) | - |
| 1102 | { | - |
| 1103 | qt_init_picture_handlers(); | - |
| 1104 | qt_init_picture_plugins(); | - |
| 1105 | if (QPHList *list = pictureHandlers()) { | - |
| 1106 | for (int i = 0; i < list->size(); ++i) { | - |
| 1107 | if (list->at(i)->format == format) | - |
| 1108 | return list->at(i); | - |
| 1109 | } | - |
| 1110 | } | - |
| 1111 | return 0; | - |
| 1112 | } | - |
| 1113 | void QPictureIO::defineIOHandler(const char *format, | - |
| 1114 | const char *header, | - |
| 1115 | const char *flags, | - |
| 1116 | picture_io_handler readPicture, | - |
| 1117 | picture_io_handler writePicture) | - |
| 1118 | { | - |
| 1119 | qt_init_picture_handlers(); | - |
| 1120 | if (QPHList *list = pictureHandlers()) { | - |
| 1121 | QPictureHandler *p; | - |
| 1122 | p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture); | - |
| 1123 | list->prepend(p); | - |
| 1124 | } | - |
| 1125 | } | - |
| 1126 | const QPicture &QPictureIO::picture() const { return d->pi; } | - |
| 1127 | | - |
| 1128 | | - |
| 1129 | | - |
| 1130 | | - |
| 1131 | | - |
| 1132 | | - |
| 1133 | | - |
| 1134 | int QPictureIO::status() const { return d->iostat; } | - |
| 1135 | | - |
| 1136 | | - |
| 1137 | | - |
| 1138 | | - |
| 1139 | | - |
| 1140 | const char *QPictureIO::format() const { return d->frmt; } | - |
| 1141 | | - |
| 1142 | | - |
| 1143 | | - |
| 1144 | | - |
| 1145 | | - |
| 1146 | | - |
| 1147 | QIODevice *QPictureIO::ioDevice() const { return d->iodev; } | - |
| 1148 | | - |
| 1149 | | - |
| 1150 | | - |
| 1151 | | - |
| 1152 | | - |
| 1153 | | - |
| 1154 | QString QPictureIO::fileName() const { return d->fname; } | - |
| 1155 | | - |
| 1156 | | - |
| 1157 | | - |
| 1158 | | - |
| 1159 | | - |
| 1160 | | - |
| 1161 | | - |
| 1162 | QString QPictureIO::description() const { return d->descr; } | - |
| 1163 | | - |
| 1164 | | - |
| 1165 | | - |
| 1166 | | - |
| 1167 | | - |
| 1168 | | - |
| 1169 | void QPictureIO::setPicture(const QPicture &picture) | - |
| 1170 | { | - |
| 1171 | d->pi = picture; | - |
| 1172 | } | - |
| 1173 | | - |
| 1174 | | - |
| 1175 | | - |
| 1176 | | - |
| 1177 | | - |
| 1178 | | - |
| 1179 | | - |
| 1180 | void QPictureIO::setStatus(int status) | - |
| 1181 | { | - |
| 1182 | d->iostat = status; | - |
| 1183 | } | - |
| 1184 | void QPictureIO::setFormat(const char *format) | - |
| 1185 | { | - |
| 1186 | d->frmt = format; | - |
| 1187 | } | - |
| 1188 | void QPictureIO::setIODevice(QIODevice *ioDevice) | - |
| 1189 | { | - |
| 1190 | d->iodev = ioDevice; | - |
| 1191 | } | - |
| 1192 | | - |
| 1193 | | - |
| 1194 | | - |
| 1195 | | - |
| 1196 | | - |
| 1197 | | - |
| 1198 | | - |
| 1199 | void QPictureIO::setFileName(const QString &fileName) | - |
| 1200 | { | - |
| 1201 | d->fname = fileName; | - |
| 1202 | } | - |
| 1203 | | - |
| 1204 | | - |
| 1205 | | - |
| 1206 | | - |
| 1207 | | - |
| 1208 | | - |
| 1209 | | - |
| 1210 | int QPictureIO::quality() const | - |
| 1211 | { | - |
| 1212 | return d->quality; | - |
| 1213 | } | - |
| 1214 | void QPictureIO::setQuality(int q) | - |
| 1215 | { | - |
| 1216 | d->quality = q; | - |
| 1217 | } | - |
| 1218 | | - |
| 1219 | | - |
| 1220 | | - |
| 1221 | | - |
| 1222 | | - |
| 1223 | | - |
| 1224 | | - |
| 1225 | const char *QPictureIO::parameters() const | - |
| 1226 | { | - |
| 1227 | return d->parameters; | - |
| 1228 | } | - |
| 1229 | void QPictureIO::setParameters(const char *parameters) | - |
| 1230 | { | - |
| 1231 | if (d->parameters) | - |
| 1232 | delete [] d->parameters; | - |
| 1233 | d->parameters = qstrdup(parameters); | - |
| 1234 | } | - |
| 1235 | void QPictureIO::setGamma(float gamma) | - |
| 1236 | { | - |
| 1237 | d->gamma=gamma; | - |
| 1238 | } | - |
| 1239 | | - |
| 1240 | | - |
| 1241 | | - |
| 1242 | | - |
| 1243 | | - |
| 1244 | | - |
| 1245 | float QPictureIO::gamma() const | - |
| 1246 | { | - |
| 1247 | return d->gamma; | - |
| 1248 | } | - |
| 1249 | void QPictureIO::setDescription(const QString &description) | - |
| 1250 | { | - |
| 1251 | d->descr = description; | - |
| 1252 | } | - |
| 1253 | QByteArray QPictureIO::pictureFormat(const QString &fileName) | - |
| 1254 | { | - |
| 1255 | QFile file(fileName); | - |
| 1256 | QByteArray format; | - |
| 1257 | if (!file.open(QIODevice::ReadOnly)) | - |
| 1258 | return format; | - |
| 1259 | format = pictureFormat(&file); | - |
| 1260 | file.close(); | - |
| 1261 | return format; | - |
| 1262 | } | - |
| 1263 | QByteArray QPictureIO::pictureFormat(QIODevice *d) | - |
| 1264 | { | - |
| 1265 | | - |
| 1266 | const int buflen = 14; | - |
| 1267 | | - |
| 1268 | char buf[buflen]; | - |
| 1269 | char buf2[buflen]; | - |
| 1270 | qt_init_picture_handlers(); | - |
| 1271 | qt_init_picture_plugins(); | - |
| 1272 | int pos = d->pos(); | - |
| 1273 | int rdlen = d->read(buf, buflen); | - |
| 1274 | | - |
| 1275 | QByteArray format; | - |
| 1276 | if (rdlen != buflen) | - |
| 1277 | return format; | - |
| 1278 | | - |
| 1279 | memcpy(buf2, buf, buflen); | - |
| 1280 | | - |
| 1281 | for (int n = 0; n < rdlen; n++) | - |
| 1282 | if (buf[n] == '\0') | - |
| 1283 | buf[n] = '\001'; | - |
| 1284 | if (rdlen > 0) { | - |
| 1285 | buf[rdlen - 1] = '\0'; | - |
| 1286 | QString bufStr = QString::fromLatin1(buf); | - |
| 1287 | if (QPHList *list = pictureHandlers()) { | - |
| 1288 | for (int i = 0; i < list->size(); ++i) { | - |
| 1289 | if (list->at(i)->header.indexIn(bufStr) != -1) { | - |
| 1290 | format = list->at(i)->format; | - |
| 1291 | break; | - |
| 1292 | } | - |
| 1293 | } | - |
| 1294 | } | - |
| 1295 | } | - |
| 1296 | d->seek(pos); | - |
| 1297 | return format; | - |
| 1298 | } | - |
| 1299 | | - |
| 1300 | | - |
| 1301 | | - |
| 1302 | | - |
| 1303 | | - |
| 1304 | QList<QByteArray> QPictureIO::inputFormats() | - |
| 1305 | { | - |
| 1306 | QList<QByteArray> result; | - |
| 1307 | | - |
| 1308 | qt_init_picture_handlers(); | - |
| 1309 | qt_init_picture_plugins(); | - |
| 1310 | | - |
| 1311 | if (QPHList *list = pictureHandlers()) { | - |
| 1312 | for (int i = 0; i < list->size(); ++i) { | - |
| 1313 | QPictureHandler *p = list->at(i); | - |
| 1314 | if (p->read_picture && !p->obsolete && !result.contains(p->format)) | - |
| 1315 | result.append(p->format); | - |
| 1316 | } | - |
| 1317 | } | - |
| 1318 | std::sort(result.begin(), result.end()); | - |
| 1319 | | - |
| 1320 | return result; | - |
| 1321 | } | - |
| 1322 | | - |
| 1323 | | - |
| 1324 | | - |
| 1325 | | - |
| 1326 | | - |
| 1327 | QList<QByteArray> QPictureIO::outputFormats() | - |
| 1328 | { | - |
| 1329 | qt_init_picture_handlers(); | - |
| 1330 | qt_init_picture_plugins(); | - |
| 1331 | | - |
| 1332 | QList<QByteArray> result; | - |
| 1333 | if (QPHList *list = pictureHandlers()) { | - |
| 1334 | for (int i = 0; i < list->size(); ++i) { | - |
| 1335 | QPictureHandler *p = list->at(i); | - |
| 1336 | if (p->write_picture && !p->obsolete && !result.contains(p->format)) | - |
| 1337 | result.append(p->format); | - |
| 1338 | } | - |
| 1339 | } | - |
| 1340 | return result; | - |
| 1341 | } | - |
| 1342 | bool QPictureIO::read() | - |
| 1343 | { | - |
| 1344 | QFile file; | - |
| 1345 | const char *picture_format; | - |
| 1346 | QPictureHandler *h; | - |
| 1347 | | - |
| 1348 | if (d->iodev) { | - |
| 1349 | | - |
| 1350 | } else if (!d->fname.isEmpty()) { | - |
| 1351 | file.setFileName(d->fname); | - |
| 1352 | if (!file.open(QIODevice::ReadOnly)) | - |
| 1353 | return false; | - |
| 1354 | d->iodev = &file; | - |
| 1355 | } else { | - |
| 1356 | return false; | - |
| 1357 | } | - |
| 1358 | if (d->frmt.isEmpty()) { | - |
| 1359 | | - |
| 1360 | picture_format = pictureFormat(d->iodev); | - |
| 1361 | if (!picture_format) { | - |
| 1362 | if (file.isOpen()) { | - |
| 1363 | file.close(); | - |
| 1364 | d->iodev = 0; | - |
| 1365 | } | - |
| 1366 | return false; | - |
| 1367 | } | - |
| 1368 | } else { | - |
| 1369 | picture_format = d->frmt; | - |
| 1370 | } | - |
| 1371 | | - |
| 1372 | h = get_picture_handler(picture_format); | - |
| 1373 | if (file.isOpen()) { | - |
| 1374 | | - |
| 1375 | | - |
| 1376 | | - |
| 1377 | | - |
| 1378 | | - |
| 1379 | | - |
| 1380 | | - |
| 1381 | file.seek(0); | - |
| 1382 | } | - |
| 1383 | d->iostat = 1; | - |
| 1384 | | - |
| 1385 | if (h && h->read_picture) | - |
| 1386 | (*h->read_picture)(this); | - |
| 1387 | | - |
| 1388 | if (file.isOpen()) { | - |
| 1389 | file.close(); | - |
| 1390 | d->iodev = 0; | - |
| 1391 | } | - |
| 1392 | return d->iostat == 0; | - |
| 1393 | } | - |
| 1394 | bool QPictureIO::write() | - |
| 1395 | { | - |
| 1396 | if (d->frmt.isEmpty()) | - |
| 1397 | return false; | - |
| 1398 | QPictureHandler *h = get_picture_handler(d->frmt); | - |
| 1399 | if (!h || !h->write_picture) { | - |
| 1400 | QMessageLogger(__FILE__, 19291933, __PRETTY_FUNCTION__).warning("QPictureIO::write: No such picture format handler: %s", | - |
| 1401 | format()); | - |
| 1402 | return false; | - |
| 1403 | } | - |
| 1404 | QFile file; | - |
| 1405 | if (!d->iodev && !d->fname.isEmpty()) { | - |
| 1406 | file.setFileName(d->fname); | - |
| 1407 | bool translate = h->text_mode==QPictureHandler::TranslateInOut; | - |
| 1408 | QIODevice::OpenMode fmode = translate ? QIODevice::WriteOnly | QIODevice::Text : QIODevice::OpenMode(QIODevice::WriteOnly); | - |
| 1409 | if (!file.open(fmode)) | - |
| 1410 | return false; | - |
| 1411 | d->iodev = &file; | - |
| 1412 | } | - |
| 1413 | d->iostat = 1; | - |
| 1414 | (*h->write_picture)(this); | - |
| 1415 | if (file.isOpen()) { | - |
| 1416 | file.close(); | - |
| 1417 | d->iodev = 0; | - |
| 1418 | } | - |
| 1419 | return d->iostat == 0; | - |
| 1420 | } | - |
| 1421 | | - |
| 1422 | | - |
| 1423 | | - |
| | |