Qt 4.8
qprintengine_pdf.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <QtGui/qprintengine.h>
43 
44 #include <qiodevice.h>
45 #include <qpainter.h>
46 #include <qbitmap.h>
47 #include <qpainterpath.h>
48 #include <qpaintdevice.h>
49 #include <qfile.h>
50 #include <qdebug.h>
51 #include <qimagewriter.h>
52 #include <qbuffer.h>
53 #include <qdatetime.h>
54 
55 #ifndef QT_NO_PRINTER
56 #include <limits.h>
57 #include <math.h>
58 #ifndef QT_NO_COMPRESS
59 #include <zlib.h>
60 #endif
61 
62 #if defined(Q_OS_WINCE)
63 #include "qwinfunctions_wince.h"
64 #endif
65 
66 #include "qprintengine_pdf_p.h"
67 #include "private/qdrawhelper_p.h"
68 
70 
71 extern qint64 qt_pixmap_id(const QPixmap &pixmap);
72 extern qint64 qt_image_id(const QImage &image);
73 
74 //#define FONT_DUMP
75 
76 // might be helpful for smooth transforms of images
77 // Can't use it though, as gs generates completely wrong images if this is true.
78 static const bool interpolateImages = false;
79 
80 #ifdef QT_NO_COMPRESS
81 static const bool do_compress = false;
82 #else
83 static const bool do_compress = true;
84 #endif
85 
87  : QPdf::ByteStream(true) // Enable file backing
88 {
89 }
90 
91 void QPdfPage::streamImage(int w, int h, int object)
92 {
93  *this << w << "0 0 " << -h << "0 " << h << "cm /Im" << object << " Do\n";
94  if (!images.contains(object))
95  images.append(object);
96 }
97 
98 
99 inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features()
100 {
101  QPaintEngine::PaintEngineFeatures f = QPaintEngine::AllFeatures;
104 #ifndef USE_NATIVE_GRADIENTS
106 #endif
109  return f;
110 }
111 
114 {
116 }
117 
119 {
120 }
121 
123 {
124  Q_D(QPdfEngine);
125 
126  if(!QPdfBaseEngine::begin(pdev)) {
128  return false;
129  }
130  d->stream->setDevice(d->outDevice);
131 
132  d->streampos = 0;
133  d->hasPen = true;
134  d->hasBrush = false;
135  d->clipEnabled = false;
136  d->allClipped = false;
137 
138  d->xrefPositions.clear();
139  d->pageRoot = 0;
140  d->catalog = 0;
141  d->info = 0;
142  d->graphicsState = 0;
143  d->patternColorSpace = 0;
144 
145  d->pages.clear();
146  d->imageCache.clear();
147  d->alphaCache.clear();
148  setActive(true);
150  d->writeHeader();
151  newPage();
152 
153  return true;
154 }
155 
157 {
158  Q_D(QPdfEngine);
159  d->writeTail();
160 
161  d->stream->unsetDevice();
163  setActive(false);
165  return true;
166 }
167 
168 
169 void QPdfEngine::drawPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr)
170 {
171  if (sr.isEmpty() || rectangle.isEmpty() || pixmap.isNull())
172  return;
173  Q_D(QPdfEngine);
174 
175  QBrush b = d->brush;
176 
177  QRect sourceRect = sr.toRect();
178  QPixmap pm = sourceRect != pixmap.rect() ? pixmap.copy(sourceRect) : pixmap;
179  QImage image = pm.toImage();
180  bool bitmap = true;
181  const int object = d->addImage(image, &bitmap, pm.cacheKey());
182  if (object < 0)
183  return;
184 
185  *d->currentPage << "q\n/GSa gs\n";
186  *d->currentPage
187  << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(),
188  rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix));
189  if (bitmap) {
190  // set current pen as d->brush
191  d->brush = d->pen.brush();
192  }
193  setBrush();
194  d->currentPage->streamImage(image.width(), image.height(), object);
195  *d->currentPage << "Q\n";
196 
197  d->brush = b;
198 }
199 
200 void QPdfEngine::drawImage(const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags)
201 {
202  if (sr.isEmpty() || rectangle.isEmpty() || image.isNull())
203  return;
204  Q_D(QPdfEngine);
205 
206  QRect sourceRect = sr.toRect();
207  QImage im = sourceRect != image.rect() ? image.copy(sourceRect) : image;
208  bool bitmap = true;
209  const int object = d->addImage(im, &bitmap, im.cacheKey());
210  if (object < 0)
211  return;
212 
213  *d->currentPage << "q\n/GSa gs\n";
214  *d->currentPage
215  << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(),
216  rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix));
217  setBrush();
218  d->currentPage->streamImage(im.width(), im.height(), object);
219  *d->currentPage << "Q\n";
220 }
221 
222 void QPdfEngine::drawTiledPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QPointF &point)
223 {
224  Q_D(QPdfEngine);
225 
226  bool bitmap = (pixmap.depth() == 1);
227  QBrush b = d->brush;
228  QPointF bo = d->brushOrigin;
229  bool hp = d->hasPen;
230  d->hasPen = false;
231  bool hb = d->hasBrush;
232  d->hasBrush = true;
233 
234  d->brush = QBrush(pixmap);
235  if (bitmap)
236  // #### fix bitmap case where we have a brush pen
237  d->brush.setColor(d->pen.color());
238 
239  d->brushOrigin = -point;
240  *d->currentPage << "q\n";
241  setBrush();
242 
243  drawRects(&rectangle, 1);
244  *d->currentPage << "Q\n";
245 
246  d->hasPen = hp;
247  d->hasBrush = hb;
248  d->brush = b;
249  d->brushOrigin = bo;
250 }
251 
252 
254 {
255  Q_D(QPdfEngine);
256  Qt::BrushStyle style = d->brush.style();
257  if (style == Qt::NoBrush)
258  return;
259 
260  bool specifyColor;
261  int gStateObject = 0;
262  int patternObject = d->addBrushPattern(d->stroker.matrix, &specifyColor, &gStateObject);
263 
264  *d->currentPage << (patternObject ? "/PCSp cs " : "/CSp cs ");
265  if (specifyColor) {
266  QColor rgba = d->brush.color();
267  if (d->colorMode == QPrinter::GrayScale) {
268  qreal gray = qGray(rgba.rgba())/255.;
269  *d->currentPage << gray << gray << gray;
270  } else {
271  *d->currentPage << rgba.redF()
272  << rgba.greenF()
273  << rgba.blueF();
274  }
275  }
276  if (patternObject)
277  *d->currentPage << "/Pat" << patternObject;
278  *d->currentPage << "scn\n";
279 
280  if (gStateObject)
281  *d->currentPage << "/GState" << gStateObject << "gs\n";
282  else
283  *d->currentPage << "/GSa gs\n";
284 }
285 
287 {
288  return QPaintEngine::Pdf;
289 }
290 
292 {
293  Q_D(QPdfEngine);
294  if (!isActive())
295  return false;
296  d->newPage();
297  return QPdfBaseEngine::newPage();
298 }
299 
302 {
303  streampos = 0;
304 
305  stream = new QDataStream;
308  fullPage = false;
309 }
310 
312 {
313  delete stream;
314 }
315 
316 
317 #ifdef USE_NATIVE_GRADIENTS
318 int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject)
319 {
320  const QGradient *gradient = b.gradient();
321  if (!gradient)
322  return 0;
323 
324  QTransform inv = matrix.inverted();
325  QPointF page_rect[4] = { inv.map(QPointF(0, 0)),
326  inv.map(QPointF(width_, 0)),
327  inv.map(QPointF(0, height_)),
328  inv.map(QPointF(width_, height_)) };
329 
330  bool opaque = b.isOpaque();
331 
332  QByteArray shader;
333  QByteArray alphaShader;
334  if (gradient->type() == QGradient::LinearGradient) {
335  const QLinearGradient *lg = static_cast<const QLinearGradient *>(gradient);
336  shader = QPdf::generateLinearGradientShader(lg, page_rect);
337  if (!opaque)
338  alphaShader = QPdf::generateLinearGradientShader(lg, page_rect, true);
339  } else {
340  // #############
341  return 0;
342  }
343  int shaderObject = addXrefEntry(-1);
344  write(shader);
345 
346  QByteArray str;
347  QPdf::ByteStream s(&str);
348  s << "<<\n"
349  "/Type /Pattern\n"
350  "/PatternType 2\n"
351  "/Shading " << shaderObject << "0 R\n"
352  "/Matrix ["
353  << matrix.m11()
354  << matrix.m12()
355  << matrix.m21()
356  << matrix.m22()
357  << matrix.dx()
358  << matrix.dy() << "]\n";
359  s << ">>\n"
360  "endobj\n";
361 
362  int patternObj = addXrefEntry(-1);
363  write(str);
364  currentPage->patterns.append(patternObj);
365 
366  if (!opaque) {
367  bool ca = true;
368  QGradientStops stops = gradient->stops();
369  int a = stops.at(0).second.alpha();
370  for (int i = 1; i < stops.size(); ++i) {
371  if (stops.at(i).second.alpha() != a) {
372  ca = false;
373  break;
374  }
375  }
376  if (ca) {
377  *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha());
378  } else {
379  int alphaShaderObject = addXrefEntry(-1);
380  write(alphaShader);
381 
382  QByteArray content;
383  QPdf::ByteStream c(&content);
384  c << "/Shader" << alphaShaderObject << "sh\n";
385 
386  QByteArray form;
387  QPdf::ByteStream f(&form);
388  f << "<<\n"
389  "/Type /XObject\n"
390  "/Subtype /Form\n"
391  "/BBox [0 0 " << width_ << height_ << "]\n"
392  "/Group <</S /Transparency >>\n"
393  "/Resources <<\n"
394  "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n"
395  ">>\n";
396 
397  f << "/Length " << content.length() << "\n"
398  ">>\n"
399  "stream\n"
400  << content
401  << "endstream\n"
402  "endobj\n";
403 
404  int softMaskFormObject = addXrefEntry(-1);
405  write(form);
406  *gStateObject = addXrefEntry(-1);
407  xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n"
408  "endobj\n", softMaskFormObject);
409  currentPage->graphicStates.append(*gStateObject);
410  }
411  }
412 
413  return patternObj;
414 }
415 #endif
416 
417 int QPdfEnginePrivate::addConstantAlphaObject(int brushAlpha, int penAlpha)
418 {
419  if (brushAlpha == 255 && penAlpha == 255)
420  return 0;
421  int object = alphaCache.value(QPair<uint, uint>(brushAlpha, penAlpha), 0);
422  if (!object) {
423  object = addXrefEntry(-1);
424  QByteArray alphaDef;
425  QPdf::ByteStream s(&alphaDef);
426  s << "<<\n/ca " << (brushAlpha/qreal(255.)) << '\n';
427  s << "/CA " << (penAlpha/qreal(255.)) << "\n>>";
428  xprintf("%s\nendobj\n", alphaDef.constData());
429  alphaCache.insert(QPair<uint, uint>(brushAlpha, penAlpha), object);
430  }
431  if (currentPage->graphicStates.indexOf(object) < 0)
433 
434  return object;
435 }
436 
437 int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor, int *gStateObject)
438 {
439  int paintType = 2; // Uncolored tiling
440  int w = 8;
441  int h = 8;
442 
443  *specifyColor = true;
444  *gStateObject = 0;
445 
446  QTransform matrix = m;
447  matrix.translate(brushOrigin.x(), brushOrigin.y());
448  matrix = matrix * pageMatrix();
449  //qDebug() << brushOrigin << matrix;
450 
451  Qt::BrushStyle style = brush.style();
452  if (style == Qt::LinearGradientPattern) {// && style <= Qt::ConicalGradientPattern) {
453 #ifdef USE_NATIVE_GRADIENTS
454  *specifyColor = false;
455  return gradientBrush(b, matrix, gStateObject);
456 #else
457  return 0;
458 #endif
459  }
460 
461  if ((!brush.isOpaque() && brush.style() < Qt::LinearGradientPattern) || opacity != 1.0)
462  *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity),
463  qRound(pen.color().alpha() * opacity));
464 
465  int imageObject = -1;
467  if (pattern.isEmpty()) {
468  if (brush.style() != Qt::TexturePattern)
469  return 0;
470  QImage image = brush.texture().toImage();
471  bool bitmap = true;
472  imageObject = addImage(image, &bitmap, qt_pixmap_id(brush.texture()));
473  if (imageObject != -1) {
474  QImage::Format f = image.format();
475  if (f != QImage::Format_MonoLSB && f != QImage::Format_Mono) {
476  paintType = 1; // Colored tiling
477  *specifyColor = false;
478  }
479  w = image.width();
480  h = image.height();
481  QTransform m(w, 0, 0, -h, 0, h);
482  QPdf::ByteStream s(&pattern);
483  s << QPdf::generateMatrix(m);
484  s << "/Im" << imageObject << " Do\n";
485  }
486  }
487 
488  QByteArray str;
489  QPdf::ByteStream s(&str);
490  s << "<<\n"
491  "/Type /Pattern\n"
492  "/PatternType 1\n"
493  "/PaintType " << paintType << "\n"
494  "/TilingType 1\n"
495  "/BBox [0 0 " << w << h << "]\n"
496  "/XStep " << w << "\n"
497  "/YStep " << h << "\n"
498  "/Matrix ["
499  << matrix.m11()
500  << matrix.m12()
501  << matrix.m21()
502  << matrix.m22()
503  << matrix.dx()
504  << matrix.dy() << "]\n"
505  "/Resources \n<< "; // open resource tree
506  if (imageObject > 0) {
507  s << "/XObject << /Im" << imageObject << ' ' << imageObject << "0 R >> ";
508  }
509  s << ">>\n"
510  "/Length " << pattern.length() << "\n"
511  ">>\n"
512  "stream\n"
513  << pattern
514  << "endstream\n"
515  "endobj\n";
516 
517  int patternObj = addXrefEntry(-1);
518  write(str);
519  currentPage->patterns.append(patternObj);
520  return patternObj;
521 }
522 
526 int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_no)
527 {
528  if (img.isNull())
529  return -1;
530 
531  int object = imageCache.value(serial_no);
532  if(object)
533  return object;
534 
535  QImage image = img;
536  QImage::Format format = image.format();
537  if (image.depth() == 1 && *bitmap && img.colorTable().size() == 2
538  && img.colorTable().at(0) == QColor(Qt::black).rgba()
539  && img.colorTable().at(1) == QColor(Qt::white).rgba())
540  {
541  if (format == QImage::Format_MonoLSB)
542  image = image.convertToFormat(QImage::Format_Mono);
543  format = QImage::Format_Mono;
544  } else {
545  *bitmap = false;
546  if (format != QImage::Format_RGB32 && format != QImage::Format_ARGB32) {
547  image = image.convertToFormat(QImage::Format_ARGB32);
548  format = QImage::Format_ARGB32;
549  }
550  }
551 
552  int w = image.width();
553  int h = image.height();
554  int d = image.depth();
555 
556  if (format == QImage::Format_Mono) {
557  int bytesPerLine = (w + 7) >> 3;
559  data.resize(bytesPerLine * h);
560  char *rawdata = data.data();
561  for (int y = 0; y < h; ++y) {
562  memcpy(rawdata, image.scanLine(y), bytesPerLine);
563  rawdata += bytesPerLine;
564  }
565  object = writeImage(data, w, h, d, 0, 0);
566  } else {
567  QByteArray softMaskData;
568  bool dct = false;
569  QByteArray imageData;
570  bool hasAlpha = false;
571  bool hasMask = false;
572 
574  QBuffer buffer(&imageData);
575  QImageWriter writer(&buffer, "jpeg");
576  writer.setQuality(94);
577  writer.write(image);
578  dct = true;
579 
580  if (format != QImage::Format_RGB32) {
581  softMaskData.resize(w * h);
582  uchar *sdata = (uchar *)softMaskData.data();
583  for (int y = 0; y < h; ++y) {
584  const QRgb *rgb = (const QRgb *)image.scanLine(y);
585  for (int x = 0; x < w; ++x) {
586  uchar alpha = qAlpha(*rgb);
587  *sdata++ = alpha;
588  hasMask |= (alpha < 255);
589  hasAlpha |= (alpha != 0 && alpha != 255);
590  ++rgb;
591  }
592  }
593  }
594  } else {
595  imageData.resize(colorMode == QPrinter::GrayScale ? w * h : 3 * w * h);
596  uchar *data = (uchar *)imageData.data();
597  softMaskData.resize(w * h);
598  uchar *sdata = (uchar *)softMaskData.data();
599  for (int y = 0; y < h; ++y) {
600  const QRgb *rgb = (const QRgb *)image.scanLine(y);
602  for (int x = 0; x < w; ++x) {
603  *(data++) = qGray(*rgb);
604  uchar alpha = qAlpha(*rgb);
605  *sdata++ = alpha;
606  hasMask |= (alpha < 255);
607  hasAlpha |= (alpha != 0 && alpha != 255);
608  ++rgb;
609  }
610  } else {
611  for (int x = 0; x < w; ++x) {
612  *(data++) = qRed(*rgb);
613  *(data++) = qGreen(*rgb);
614  *(data++) = qBlue(*rgb);
615  uchar alpha = qAlpha(*rgb);
616  *sdata++ = alpha;
617  hasMask |= (alpha < 255);
618  hasAlpha |= (alpha != 0 && alpha != 255);
619  ++rgb;
620  }
621  }
622  }
623  if (format == QImage::Format_RGB32)
624  hasAlpha = hasMask = false;
625  }
626  int maskObject = 0;
627  int softMaskObject = 0;
628  if (hasAlpha) {
629  softMaskObject = writeImage(softMaskData, w, h, 8, 0, 0);
630  } else if (hasMask) {
631  // dither the soft mask to 1bit and add it. This also helps PDF viewers
632  // without transparency support
633  int bytesPerLine = (w + 7) >> 3;
634  QByteArray mask(bytesPerLine * h, 0);
635  uchar *mdata = (uchar *)mask.data();
636  const uchar *sdata = (const uchar *)softMaskData.constData();
637  for (int y = 0; y < h; ++y) {
638  for (int x = 0; x < w; ++x) {
639  if (*sdata)
640  mdata[x>>3] |= (0x80 >> (x&7));
641  ++sdata;
642  }
643  mdata += bytesPerLine;
644  }
645  maskObject = writeImage(mask, w, h, 1, 0, 0);
646  }
647  object = writeImage(imageData, w, h, colorMode == QPrinter::GrayScale ? 8 : 32,
648  maskObject, softMaskObject, dct);
649  }
650  imageCache.insert(serial_no, object);
651  return object;
652 }
653 
655 {
656  if (ti.charFormat.isAnchor()) {
657  qreal size = ti.fontEngine->fontDef.pixelSize;
658 #ifdef Q_WS_WIN
659  if (ti.fontEngine->type() == QFontEngine::Win) {
660  QFontEngineWin *fe = static_cast<QFontEngineWin *>(ti.fontEngine);
661  size = fe->tm.tmHeight;
662  }
663 #endif
664  int synthesized = ti.fontEngine->synthesized();
665  qreal stretch = synthesized & QFontEngine::SynthesizedStretch ? ti.fontEngine->fontDef.stretch/100. : 1.;
666 
667  QTransform trans;
668  // Build text rendering matrix (Trm). We need it to map the text area to user
669  // space units on the PDF page.
670  trans = QTransform(size*stretch, 0, 0, size, 0, 0);
671  // Apply text matrix (Tm).
672  trans *= QTransform(1,0,0,-1,p.x(),p.y());
673  // Apply page displacement (Identity for first page).
674  trans *= stroker.matrix;
675  // Apply Current Transformation Matrix (CTM)
676  trans *= pageMatrix();
677  qreal x1, y1, x2, y2;
678  trans.map(0, 0, &x1, &y1);
679  trans.map(ti.width.toReal()/size, (ti.ascent.toReal()-ti.descent.toReal())/size, &x2, &y2);
680 
681  uint annot = addXrefEntry(-1);
682  QByteArray x1s, y1s, x2s, y2s;
683  x1s.setNum(static_cast<double>(x1), 'f');
684  y1s.setNum(static_cast<double>(y1), 'f');
685  x2s.setNum(static_cast<double>(x2), 'f');
686  y2s.setNum(static_cast<double>(y2), 'f');
687  QByteArray rectData = x1s + ' ' + y1s + ' ' + x2s + ' ' + y2s;
688  xprintf("<<\n/Type /Annot\n/Subtype /Link\n/Rect [");
689  xprintf(rectData.constData());
690 #ifdef Q_DEBUG_PDF_LINKS
691  xprintf("]\n/Border [16 16 1]\n/A <<\n");
692 #else
693  xprintf("]\n/Border [0 0 0]\n/A <<\n");
694 #endif
695  xprintf("/Type /Action\n/S /URI\n/URI (%s)\n",
697  xprintf(">>\n>>\n");
698  xprintf("endobj\n");
699 
700  if (!currentPage->annotations.contains(annot)) {
702  }
703  }
704 
706 }
707 
709 {
710  qreal scale = 72./resolution;
711  QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, height());
712  if (!fullPage) {
713  QRect r = pageRect();
714  tmp.translate(r.left(), r.top());
715  }
716  return tmp;
717 }
718 
720 {
723  writePage();
724 
725  delete currentPage;
726  currentPage = new QPdfPage;
730 
731  *currentPage << "/GSa gs /CSp cs /CSp CS\n"
733  << "q q\n";
734 }
735 
736 
737 // For strings up to 10000 bytes only !
738 void QPdfEnginePrivate::xprintf(const char* fmt, ...)
739 {
740  if (!stream)
741  return;
742 
743  const int msize = 10000;
744  char buf[msize];
745 
746  va_list args;
747  va_start(args, fmt);
748  int bufsize = qvsnprintf(buf, msize, fmt, args);
749 
750  Q_ASSERT(bufsize<msize);
751 
752  va_end(args);
753 
754  stream->writeRawData(buf, bufsize);
755  streampos += bufsize;
756 }
757 
759 {
760 #ifndef QT_NO_COMPRESS
761  if (do_compress) {
762  int size = QPdfPage::chunkSize();
763  int sum = 0;
764  ::z_stream zStruct;
765  zStruct.zalloc = Z_NULL;
766  zStruct.zfree = Z_NULL;
767  zStruct.opaque = Z_NULL;
768  if (::deflateInit(&zStruct, Z_DEFAULT_COMPRESSION) != Z_OK) {
769  qWarning("QPdfStream::writeCompressed: Error in deflateInit()");
770  return sum;
771  }
772  zStruct.avail_in = 0;
773  QByteArray in, out;
774  out.resize(size);
775  while (!dev->atEnd() || zStruct.avail_in != 0) {
776  if (zStruct.avail_in == 0) {
777  in = dev->read(size);
778  zStruct.avail_in = in.size();
779  zStruct.next_in = reinterpret_cast<unsigned char*>(in.data());
780  if (in.size() <= 0) {
781  qWarning("QPdfStream::writeCompressed: Error in read()");
782  ::deflateEnd(&zStruct);
783  return sum;
784  }
785  }
786  zStruct.next_out = reinterpret_cast<unsigned char*>(out.data());
787  zStruct.avail_out = out.size();
788  if (::deflate(&zStruct, 0) != Z_OK) {
789  qWarning("QPdfStream::writeCompressed: Error in deflate()");
790  ::deflateEnd(&zStruct);
791  return sum;
792  }
793  int written = out.size() - zStruct.avail_out;
794  stream->writeRawData(out.constData(), written);
795  streampos += written;
796  sum += written;
797  }
798  int ret;
799  do {
800  zStruct.next_out = reinterpret_cast<unsigned char*>(out.data());
801  zStruct.avail_out = out.size();
802  ret = ::deflate(&zStruct, Z_FINISH);
803  if (ret != Z_OK && ret != Z_STREAM_END) {
804  qWarning("QPdfStream::writeCompressed: Error in deflate()");
805  ::deflateEnd(&zStruct);
806  return sum;
807  }
808  int written = out.size() - zStruct.avail_out;
809  stream->writeRawData(out.constData(), written);
810  streampos += written;
811  sum += written;
812  } while (ret == Z_OK);
813 
814  ::deflateEnd(&zStruct);
815 
816  return sum;
817  } else
818 #endif
819  {
820  QByteArray arr;
821  int sum = 0;
822  while (!dev->atEnd()) {
823  arr = dev->read(QPdfPage::chunkSize());
824  stream->writeRawData(arr.constData(), arr.size());
825  streampos += arr.size();
826  sum += arr.size();
827  }
828  return sum;
829  }
830 }
831 
832 int QPdfEnginePrivate::writeCompressed(const char *src, int len)
833 {
834 #ifndef QT_NO_COMPRESS
835  if(do_compress) {
836  uLongf destLen = len + len/100 + 13; // zlib requirement
837  Bytef* dest = new Bytef[destLen];
838  if (Z_OK == ::compress(dest, &destLen, (const Bytef*) src, (uLongf)len)) {
839  stream->writeRawData((const char*)dest, destLen);
840  } else {
841  qWarning("QPdfStream::writeCompressed: Error in compress()");
842  destLen = 0;
843  }
844  delete [] dest;
845  len = destLen;
846  } else
847 #endif
848  {
849  stream->writeRawData(src,len);
850  }
851  streampos += len;
852  return len;
853 }
854 
855 int QPdfEnginePrivate::writeImage(const QByteArray &data, int width, int height, int depth,
856  int maskObject, int softMaskObject, bool dct)
857 {
858  int image = addXrefEntry(-1);
859  xprintf("<<\n"
860  "/Type /XObject\n"
861  "/Subtype /Image\n"
862  "/Width %d\n"
863  "/Height %d\n", width, height);
864 
865  if (depth == 1) {
866  xprintf("/ImageMask true\n"
867  "/Decode [1 0]\n");
868  } else {
869  xprintf("/BitsPerComponent 8\n"
870  "/ColorSpace %s\n", (depth == 32) ? "/DeviceRGB" : "/DeviceGray");
871  }
872  if (maskObject > 0)
873  xprintf("/Mask %d 0 R\n", maskObject);
874  if (softMaskObject > 0)
875  xprintf("/SMask %d 0 R\n", softMaskObject);
876 
877  int lenobj = requestObject();
878  xprintf("/Length %d 0 R\n", lenobj);
879  if (interpolateImages)
880  xprintf("/Interpolate true\n");
881  int len = 0;
882  if (dct) {
883  //qDebug() << "DCT";
884  xprintf("/Filter /DCTDecode\n>>\nstream\n");
885  write(data);
886  len = data.length();
887  } else {
888  if (do_compress)
889  xprintf("/Filter /FlateDecode\n>>\nstream\n");
890  else
891  xprintf(">>\nstream\n");
892  len = writeCompressed(data);
893  }
894  xprintf("endstream\n"
895  "endobj\n");
896  addXrefEntry(lenobj);
897  xprintf("%d\n"
898  "endobj\n", len);
899  return image;
900 }
901 
902 
904 {
905  addXrefEntry(0,false);
906 
907  xprintf("%%PDF-1.4\n");
908 
909  writeInfo();
910 
911  catalog = addXrefEntry(-1);
913  xprintf("<<\n"
914  "/Type /Catalog\n"
915  "/Pages %d 0 R\n"
916  ">>\n"
917  "endobj\n", pageRoot);
918 
919  // graphics state
921  xprintf("<<\n"
922  "/Type /ExtGState\n"
923  "/SA true\n"
924  "/SM 0.02\n"
925  "/ca 1.0\n"
926  "/CA 1.0\n"
927  "/AIS false\n"
928  "/SMask /None"
929  ">>\n"
930  "endobj\n");
931 
932  // color space for pattern
934  xprintf("[/Pattern /DeviceRGB]\n"
935  "endobj\n");
936 }
937 
939 {
940  info = addXrefEntry(-1);
941  xprintf("<<\n/Title ");
943  xprintf("\n/Creator ");
945  xprintf("\n/Producer ");
948  QTime t = now.time();
949  QDate d = now.date();
950  xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",
951  d.year(),
952  d.month(),
953  d.day(),
954  t.hour(),
955  t.minute(),
956  t.second());
957  xprintf(">>\n"
958  "endobj\n");
959 }
960 
962 {
964 
965  xprintf("<<\n"
966  "/Type /Pages\n"
967  "/Kids \n"
968  "[\n");
969  int size = pages.size();
970  for (int i = 0; i < size; ++i)
971  xprintf("%d 0 R\n", pages[i]);
972  xprintf("]\n");
973 
974  //xprintf("/Group <</S /Transparency /I true /K false>>\n");
975  xprintf("/Count %d\n", pages.size());
976 
977  xprintf("/ProcSet [/PDF /Text /ImageB /ImageC]\n"
978  ">>\n"
979  "endobj\n");
980 }
981 
982 
984 {
985  //qDebug() << "embedFont" << font->object_id;
986  int fontObject = font->object_id;
987  QByteArray fontData = font->toTruetype();
988 #ifdef FONT_DUMP
989  static int i = 0;
990  QString fileName("font%1.ttf");
991  fileName = fileName.arg(i++);
992  QFile ff(fileName);
994  ff.write(fontData);
995  ff.close();
996 #endif
997 
998  int fontDescriptor = requestObject();
999  int fontstream = requestObject();
1000  int cidfont = requestObject();
1001  int toUnicode = requestObject();
1002 
1004 
1005  {
1006  qreal scale = 1000/properties.emSquare.toReal();
1007  addXrefEntry(fontDescriptor);
1008  QByteArray descriptor;
1009  QPdf::ByteStream s(&descriptor);
1010  s << "<< /Type /FontDescriptor\n"
1011  "/FontName /Q";
1012  int tag = fontDescriptor;
1013  for (int i = 0; i < 5; ++i) {
1014  s << (char)('A' + (tag % 26));
1015  tag /= 26;
1016  }
1017  s << '+' << properties.postscriptName << "\n"
1018  "/Flags " << 4 << "\n"
1019  "/FontBBox ["
1020  << properties.boundingBox.x()*scale
1021  << -(properties.boundingBox.y() + properties.boundingBox.height())*scale
1022  << (properties.boundingBox.x() + properties.boundingBox.width())*scale
1023  << -properties.boundingBox.y()*scale << "]\n"
1024  "/ItalicAngle " << properties.italicAngle.toReal() << "\n"
1025  "/Ascent " << properties.ascent.toReal()*scale << "\n"
1026  "/Descent " << -properties.descent.toReal()*scale << "\n"
1027  "/CapHeight " << properties.capHeight.toReal()*scale << "\n"
1028  "/StemV " << properties.lineWidth.toReal()*scale << "\n"
1029  "/FontFile2 " << fontstream << "0 R\n"
1030  ">> endobj\n";
1031  write(descriptor);
1032  }
1033  {
1034  addXrefEntry(fontstream);
1035  QByteArray header;
1036  QPdf::ByteStream s(&header);
1037 
1038  int length_object = requestObject();
1039  s << "<<\n"
1040  "/Length1 " << fontData.size() << "\n"
1041  "/Length " << length_object << "0 R\n";
1042  if (do_compress)
1043  s << "/Filter /FlateDecode\n";
1044  s << ">>\n"
1045  "stream\n";
1046  write(header);
1047  int len = writeCompressed(fontData);
1048  write("endstream\n"
1049  "endobj\n");
1050  addXrefEntry(length_object);
1051  xprintf("%d\n"
1052  "endobj\n", len);
1053  }
1054  {
1055  addXrefEntry(cidfont);
1056  QByteArray cid;
1057  QPdf::ByteStream s(&cid);
1058  s << "<< /Type /Font\n"
1059  "/Subtype /CIDFontType2\n"
1060  "/BaseFont /" << properties.postscriptName << "\n"
1061  "/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>\n"
1062  "/FontDescriptor " << fontDescriptor << "0 R\n"
1063  "/CIDToGIDMap /Identity\n"
1064  << font->widthArray() <<
1065  ">>\n"
1066  "endobj\n";
1067  write(cid);
1068  }
1069  {
1070  addXrefEntry(toUnicode);
1071  QByteArray touc = font->createToUnicodeMap();
1072  xprintf("<< /Length %d >>\n"
1073  "stream\n", touc.length());
1074  write(touc);
1075  write("endstream\n"
1076  "endobj\n");
1077  }
1078  {
1079  addXrefEntry(fontObject);
1080  QByteArray font;
1081  QPdf::ByteStream s(&font);
1082  s << "<< /Type /Font\n"
1083  "/Subtype /Type0\n"
1084  "/BaseFont /" << properties.postscriptName << "\n"
1085  "/Encoding /Identity-H\n"
1086  "/DescendantFonts [" << cidfont << "0 R]\n"
1087  "/ToUnicode " << toUnicode << "0 R"
1088  ">>\n"
1089  "endobj\n";
1090  write(font);
1091  }
1092 }
1093 
1094 
1096 {
1098  embedFont(*it);
1099  delete *it;
1100  }
1101  fonts.clear();
1102 }
1103 
1105 {
1106  if (pages.empty())
1107  return;
1108 
1109  *currentPage << "Q Q\n";
1110 
1111  uint pageStream = requestObject();
1112  uint pageStreamLength = requestObject();
1113  uint resources = requestObject();
1114  uint annots = requestObject();
1115 
1116  addXrefEntry(pages.last());
1117  xprintf("<<\n"
1118  "/Type /Page\n"
1119  "/Parent %d 0 R\n"
1120  "/Contents %d 0 R\n"
1121  "/Resources %d 0 R\n"
1122  "/Annots %d 0 R\n"
1123  "/MediaBox [0 0 %d %d]\n"
1124  ">>\n"
1125  "endobj\n",
1126  pageRoot, pageStream, resources, annots,
1127  // make sure we use the pagesize from when we started the page, since the user may have changed it
1129 
1130  addXrefEntry(resources);
1131  xprintf("<<\n"
1132  "/ColorSpace <<\n"
1133  "/PCSp %d 0 R\n"
1134  "/CSp /DeviceRGB\n"
1135  "/CSpg /DeviceGray\n"
1136  ">>\n"
1137  "/ExtGState <<\n"
1138  "/GSa %d 0 R\n",
1140 
1141  for (int i = 0; i < currentPage->graphicStates.size(); ++i)
1142  xprintf("/GState%d %d 0 R\n", currentPage->graphicStates.at(i), currentPage->graphicStates.at(i));
1143  xprintf(">>\n");
1144 
1145  xprintf("/Pattern <<\n");
1146  for (int i = 0; i < currentPage->patterns.size(); ++i)
1147  xprintf("/Pat%d %d 0 R\n", currentPage->patterns.at(i), currentPage->patterns.at(i));
1148  xprintf(">>\n");
1149 
1150  xprintf("/Font <<\n");
1151  for (int i = 0; i < currentPage->fonts.size();++i)
1152  xprintf("/F%d %d 0 R\n", currentPage->fonts[i], currentPage->fonts[i]);
1153  xprintf(">>\n");
1154 
1155  xprintf("/XObject <<\n");
1156  for (int i = 0; i<currentPage->images.size(); ++i) {
1157  xprintf("/Im%d %d 0 R\n", currentPage->images.at(i), currentPage->images.at(i));
1158  }
1159  xprintf(">>\n");
1160 
1161  xprintf(">>\n"
1162  "endobj\n");
1163 
1164  addXrefEntry(annots);
1165  xprintf("[ ");
1166  for (int i = 0; i<currentPage->annotations.size(); ++i) {
1167  xprintf("%d 0 R ", currentPage->annotations.at(i));
1168  }
1169  xprintf("]\nendobj\n");
1170 
1171  addXrefEntry(pageStream);
1172  xprintf("<<\n"
1173  "/Length %d 0 R\n", pageStreamLength); // object number for stream length object
1174  if (do_compress)
1175  xprintf("/Filter /FlateDecode\n");
1176 
1177  xprintf(">>\n");
1178  xprintf("stream\n");
1179  QIODevice *content = currentPage->stream();
1180  int len = writeCompressed(content);
1181  xprintf("endstream\n"
1182  "endobj\n");
1183 
1184  addXrefEntry(pageStreamLength);
1185  xprintf("%d\nendobj\n",len);
1186 }
1187 
1189 {
1190  writePage();
1191  writeFonts();
1192  writePageRoot();
1193  addXrefEntry(xrefPositions.size(),false);
1194  xprintf("xref\n"
1195  "0 %d\n"
1196  "%010d 65535 f \n", xrefPositions.size()-1, xrefPositions[0]);
1197 
1198  for (int i = 1; i < xrefPositions.size()-1; ++i)
1199  xprintf("%010d 00000 n \n", xrefPositions[i]);
1200 
1201  xprintf("trailer\n"
1202  "<<\n"
1203  "/Size %d\n"
1204  "/Info %d 0 R\n"
1205  "/Root %d 0 R\n"
1206  ">>\n"
1207  "startxref\n%d\n"
1208  "%%%%EOF\n",
1210 }
1211 
1212 int QPdfEnginePrivate::addXrefEntry(int object, bool printostr)
1213 {
1214  if (object < 0)
1215  object = requestObject();
1216 
1217  if (object>=xrefPositions.size())
1218  xrefPositions.resize(object+1);
1219 
1220  xrefPositions[object] = streampos;
1221  if (printostr)
1222  xprintf("%d 0 obj\n",object);
1223 
1224  return object;
1225 }
1226 
1228  // The 'text string' type in PDF is encoded either as PDFDocEncoding, or
1229  // Unicode UTF-16 with a Unicode byte order mark as the first character
1230  // (0xfeff), with the high-order byte first.
1231  QByteArray array("(\xfe\xff");
1232  const ushort *utf16 = string.utf16();
1233 
1234  for (int i=0; i < string.size(); ++i) {
1235  char part[2] = {char((*(utf16 + i)) >> 8), char((*(utf16 + i)) & 0xff)};
1236  for(int j=0; j < 2; ++j) {
1237  if (part[j] == '(' || part[j] == ')' || part[j] == '\\')
1238  array.append('\\');
1239  array.append(part[j]);
1240  }
1241  }
1242  array.append(")");
1243  write(array);
1244 }
1245 
1247 
1248 #endif // QT_NO_PRINTER
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QFontEngine * fontEngine
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
Format
The following image formats are available in Qt.
Definition: qimage.h:91
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
unsigned int QRgb
Definition: qrgb.h:53
BrushStyle
Definition: qnamespace.h:1162
QVector< uint > graphicStates
Definition: qpdf_p.h:168
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QByteArray createToUnicodeMap() const
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static int chunkSize()
Definition: qpdf_p.h:102
void clear()
Removes all items from the hash.
Definition: qhash.h:574
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static int deflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
Definition: qzip.cpp:224
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
int writeCompressed(const char *src, int len)
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
#define it(className, varName)
QPrinter::Orientation orientation
Definition: qpdf_p.h:276
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QTransform matrix
Definition: qpdf_p.h:139
QByteArray & append(char c)
Appends the character ch to this byte array.
QByteArray toTruetype() const
static const uchar inv
Definition: qisciicodec.cpp:91
PrinterMode
This enum describes the mode the printer should work in.
Definition: qprinter.h:70
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QVector< uint > pages
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
virtual int synthesized() const
QHash< QPair< uint, uint >, uint > alphaCache
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
T2 second
Definition: qpair.h:66
void embedFont(QFontSubset *font)
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
void setQuality(int quality)
This is an image format specific function that sets the quality level of the image to quality...
QPdfEngine(QPrinter::PrinterMode m)
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QDate class provides date functions.
Definition: qdatetime.h:55
long ASN1_INTEGER_get ASN1_INTEGER * a
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
int addImage(const QImage &image, bool *bitmap, qint64 serial_no)
Adds an image to the pdf and return the pdf-object id.
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
qreal m12() const
Returns the vertical shearing factor.
Definition: qmatrix.h:74
QByteArray widthArray() const
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
The QString class provides a Unicode character string.
Definition: qstring.h:83
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
QVector< uint > fonts
Definition: qpdf_p.h:170
QVector< int > xrefPositions
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
void printString(const QString &string)
#define Q_D(Class)
Definition: qglobal.h:2482
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
virtual Type type() const =0
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QVector< uint > images
Definition: qpdf_p.h:167
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Type type() const
Reimplement this function to return the paint engine Type.
QPointF brushOrigin
Definition: qpdf_p.h:242
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
Definition: qpdf.cpp:984
qreal m11() const
Returns the horizontal scaling factor.
Definition: qmatrix.h:73
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
bool newPage()
Instructs the print engine to start a new page.
Definition: qpdf.cpp:1340
int addXrefEntry(int object, bool printostr=true)
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
qreal m21() const
Returns the horizontal shearing factor.
Definition: qmatrix.h:75
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
The QTime class provides clock time functions.
Definition: qdatetime.h:148
bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
Definition: qpdf.cpp:1617
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPrinter::PageOrder pageOrder
Definition: qpdf_p.h:275
int addBrushPattern(const QTransform &matrix, bool *specifyColor, int *gStateObject)
void write(const QByteArray &data)
bool end()
Reimplement this function to finish painting on the current paint device.
Definition: qpdf.cpp:1632
void drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &point)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
QRect pageRect() const
Definition: qpdf.cpp:2057
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
void setActive(bool newState)
Sets the active state of the paint engine to state.
Definition: qpaintengine.h:155
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QPdf::Stroker stroker
Definition: qpdf_p.h:240
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const bool interpolateImages
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
Internal QTextItem.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
#define QT_VERSION_STR
This macro expands to a string that specifies Qt&#39;s version number (for example, "4.
Definition: qglobal.h:47
uint requestObject()
Definition: qpdf_p.h:231
QVector< uint > patterns
Definition: qpdf_p.h:169
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
__int64 qint64
Definition: qglobal.h:942
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
Definition: qvector.h:698
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition: qbrush.cpp:910
QIODevice * stream()
Definition: qpdf.cpp:225
int writeImage(const QByteArray &data, int width, int height, int depth, int maskObject, int softMaskObject, bool dct=false)
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
static const bool do_compress
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
QHash< QFontEngine::FaceId, QFontSubset * > fonts
Definition: qpdf_p.h:254
qreal pixelSize
Definition: qfont_p.h:90
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:251
void drawPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
QPrinter::ColorMode colorMode
Definition: qpdf_p.h:278
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
virtual ~QPdfEngine()
QPdfEnginePrivate(QPrinter::PrinterMode m)
static QString toUnicode(QTextCodec *tc, const char *str)
Definition: qsql_mysql.cpp:95
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
QHash< qint64, uint > imageCache
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti)
Definition: qpdf.cpp:1909
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
void drawTextItem(const QPointF &p, const QTextItemInt &ti)
bool newPage()
Instructs the print engine to start a new page.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
virtual Properties properties() const
bool end()
Reimplement this function to finish painting on the current paint device.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
QVector< uint > annotations
Definition: qpdf_p.h:171
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
QByteArray patternForBrush(const QBrush &b)
Definition: qpdf.cpp:524
void resize(int size)
Sets the size of the byte array to size bytes.
QByteArray & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qbytearray.h:584
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int addConstantAlphaObject(int brushAlpha, int penAlpha=255)
int height() const
Returns the height.
Definition: qsize.h:129
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QSize pageSize
Definition: qpdf_p.h:175
qreal toReal() const
Definition: qfixed_p.h:77
uint stretch
Definition: qfont_p.h:98
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QPdfPage * currentPage
Definition: qpdf_p.h:239
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
Definition: qpdf.cpp:140
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
qint64 qt_pixmap_id(const QPixmap &pixmap)
Definition: qpixmap.cpp:94
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QTransform pageMatrix() const
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageWriter.
void streamImage(int w, int h, int object)
QFontDef fontDef
QPrinter::PrinterState state
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
const QTextCharFormat charFormat
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
ByteStream * stream
Definition: qpdf_p.h:137
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
bool write(const QImage &image)
Writes the image image to the assigned device or file name.
QPaintEngine::PaintEngineFeatures qt_pdf_decide_features()
static QString fileName(const QString &fileUrl)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
void xprintf(const char *fmt,...)
qint64 qt_image_id(const QImage &image)
Definition: qimage.cpp:117
const int object_id
Definition: qfontsubset_p.h:84
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282
qreal m22() const
Returns the vertical scaling factor.
Definition: qmatrix.h:76
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
QMatrix inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qmatrix.cpp:1066
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...