Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QPdfEnginePrivate Class Reference

#include <qprintengine_pdf_p.h>

Inheritance diagram for QPdfEnginePrivate:
QPdfBaseEnginePrivate QAlphaPaintEnginePrivate QPaintEnginePrivate

Public Functions

int addBrushPattern (const QTransform &matrix, bool *specifyColor, int *gStateObject)
 
int addConstantAlphaObject (int brushAlpha, int penAlpha=255)
 
int addImage (const QImage &image, bool *bitmap, qint64 serial_no)
 Adds an image to the pdf and return the pdf-object id. More...
 
void drawTextItem (const QPointF &p, const QTextItemInt &ti)
 
int height () const
 
void newPage ()
 
QTransform pageMatrix () const
 
 QPdfEnginePrivate (QPrinter::PrinterMode m)
 
int width () const
 
void writeHeader ()
 
void writeTail ()
 
 ~QPdfEnginePrivate ()
 
- Public Functions inherited from QPdfBaseEnginePrivate
void closePrintDevice ()
 
bool openPrintDevice ()
 
QRect pageRect () const
 
QRect paperRect () const
 
 QPdfBaseEnginePrivate (QPrinter::PrinterMode m)
 
uint requestObject ()
 
 ~QPdfBaseEnginePrivate ()
 
- Public Functions inherited from QAlphaPaintEnginePrivate
void addAlphaRect (const QRectF &rect)
 
QRectF addPenWidth (const QPainterPath &path)
 
void drawAlphaImage (const QRectF &rect)
 
bool fullyContained (const QRectF &rect) const
 
 QAlphaPaintEnginePrivate ()
 
void resetState (QPainter *p)
 
QRect toRect (const QRectF &rect) const
 
 ~QAlphaPaintEnginePrivate ()
 
- Public Functions inherited from QPaintEnginePrivate
void drawBoxTextItem (const QPointF &p, const QTextItemInt &ti)
 
 QPaintEnginePrivate ()
 
void setSystemTransform (const QTransform &xform)
 
void setSystemViewport (const QRegion &region)
 
virtual void systemStateChanged ()
 
void transformSystemClip ()
 
virtual ~QPaintEnginePrivate ()
 

Private Functions

int addXrefEntry (int object, bool printostr=true)
 
void embedFont (QFontSubset *font)
 
void printString (const QString &string)
 
void write (const QByteArray &data)
 
int writeCompressed (const char *src, int len)
 
int writeCompressed (const QByteArray &data)
 
int writeCompressed (QIODevice *dev)
 
void writeFonts ()
 
int writeImage (const QByteArray &data, int width, int height, int depth, int maskObject, int softMaskObject, bool dct=false)
 
void writeInfo ()
 
void writePage ()
 
void writePageRoot ()
 
void xprintf (const char *fmt,...)
 

Properties

QHash< QPair< uint, uint >, uintalphaCache
 
int catalog
 
int graphicsState
 
QHash< qint64, uintimageCache
 
int info
 
int pageRoot
 
QVector< uintpages
 
int patternColorSpace
 
QDataStreamstream
 
int streampos
 
QVector< int > xrefPositions
 

Additional Inherited Members

- Public Variables inherited from QPdfBaseEnginePrivate
bool allClipped
 
qreal bottomMargin
 
QBrush brush
 
QPointF brushOrigin
 
bool clipEnabled
 
QList< QPainterPathclips
 
bool collate
 
QPrinter::ColorMode colorMode
 
int copies
 
QString creator
 
QStringList cupsOptions
 
QRect cupsPageRect
 
QRect cupsPaperRect
 
QString cupsStringPageSize
 
QString cupsTempFile
 
int currentObject
 
QPdfPagecurrentPage
 
QSizeF customPaperSize
 
QPrinter::DuplexMode duplex
 
bool embedFonts
 
int fd
 
QHash< QFontEngine::FaceId, QFontSubset * > fonts
 
bool fullPage
 
bool hasBrush
 
bool hasCustomPageMargins
 
bool hasPen
 
qreal leftMargin
 
qreal opacity
 
QPrinter::Orientation orientation
 
QIODeviceoutDevice
 
QString outputFileName
 
QPrinter::PageOrder pageOrder
 
QPrinter::PaperSize paperSize
 
QPrinter::PaperSource paperSource
 
QPaintDevicepdev
 
QPen pen
 
bool postscript
 
QString printerName
 
QString printProgram
 
int resolution
 
qreal rightMargin
 
QString selectionOption
 
bool simplePen
 
QPdf::Stroker stroker
 
QString title
 
qreal topMargin
 
bool useAlphaEngine
 
- Public Variables inherited from QAlphaPaintEnginePrivate
bool m_advancedBrush
 
bool m_advancedPen
 
bool m_alphaBrush
 
bool m_alphaOpacity
 
bool m_alphaPen
 
QRegion m_alphargn
 
QRegion m_cliprgn
 
bool m_complexTransform
 
bool m_continueCall
 
bool m_emulateProjectiveTransforms
 
bool m_hasalpha
 
int m_pass
 
QPaintDevicem_pdev
 
QPen m_pen
 
QPicturem_pic
 
QPaintEnginem_picengine
 
QPainterm_picpainter
 
QPaintEngine::PaintEngineFeatures m_savedcaps
 
QTransform m_transform
 
- Public Variables inherited from QPaintEnginePrivate
QWidgetcurrentClipWidget
 
uint hasSystemTransform: 1
 
uint hasSystemViewport: 1
 
QPaintDevicepdev
 
QPaintEngineq_ptr
 
QRegion systemClip
 
QRect systemRect
 
QTransform systemTransform
 
QRegion systemViewport
 

Detailed Description

Definition at line 123 of file qprintengine_pdf_p.h.

Constructors and Destructors

◆ QPdfEnginePrivate()

QPdfEnginePrivate::QPdfEnginePrivate ( QPrinter::PrinterMode  m)

Definition at line 300 of file qprintengine_pdf.cpp.

302 {
303  streampos = 0;
304 
305  stream = new QDataStream;
308  fullPage = false;
309 }
QPrinter::Orientation orientation
Definition: qpdf_p.h:276
QPdfBaseEnginePrivate(QPrinter::PrinterMode m)
Definition: qpdf.cpp:1595
QPrinter::PageOrder pageOrder
Definition: qpdf_p.h:275
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ ~QPdfEnginePrivate()

QPdfEnginePrivate::~QPdfEnginePrivate ( )

Definition at line 311 of file qprintengine_pdf.cpp.

312 {
313  delete stream;
314 }

Functions

◆ addBrushPattern()

int QPdfEnginePrivate::addBrushPattern ( const QTransform matrix,
bool *  specifyColor,
int *  gStateObject 
)

Definition at line 437 of file qprintengine_pdf.cpp.

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 }
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 dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
BrushStyle
Definition: qnamespace.h:1162
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
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
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF brushOrigin
Definition: qpdf_p.h:242
int addXrefEntry(int object, bool printostr=true)
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
void write(const QByteArray &data)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QVector< uint > patterns
Definition: qpdf_p.h:169
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
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
int length() const
Same as size().
Definition: qbytearray.h:356
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
QByteArray patternForBrush(const QBrush &b)
Definition: qpdf.cpp:524
int addConstantAlphaObject(int brushAlpha, int penAlpha=255)
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QPdfPage * currentPage
Definition: qpdf_p.h:239
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qint64 qt_pixmap_id(const QPixmap &pixmap)
Definition: qpixmap.cpp:94
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QTransform pageMatrix() const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ addConstantAlphaObject()

int QPdfEnginePrivate::addConstantAlphaObject ( int  brushAlpha,
int  penAlpha = 255 
)

Definition at line 417 of file qprintengine_pdf.cpp.

Referenced by addBrushPattern(), and ~QPdfEnginePrivate().

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 }
QVector< uint > graphicStates
Definition: qpdf_p.h:168
double qreal
Definition: qglobal.h:1193
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QHash< QPair< uint, uint >, uint > alphaCache
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
int addXrefEntry(int object, bool printostr=true)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
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
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QPdfPage * currentPage
Definition: qpdf_p.h:239
void xprintf(const char *fmt,...)

◆ addImage()

int QPdfEnginePrivate::addImage ( const QImage img,
bool *  bitmap,
qint64  serial_no 
)

Adds an image to the pdf and return the pdf-object id.

Returns -1 if adding the image failed.

Definition at line 526 of file qprintengine_pdf.cpp.

Referenced by addBrushPattern().

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 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
Format
The following image formats are available in Qt.
Definition: qimage.h:91
unsigned int QRgb
Definition: qrgb.h:53
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
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
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
unsigned char uchar
Definition: qglobal.h:994
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
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)
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
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
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QPrinter::ColorMode colorMode
Definition: qpdf_p.h:278
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
QHash< qint64, uint > imageCache
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
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 resize(int size)
Sets the size of the byte array to size bytes.
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
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.
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
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ addXrefEntry()

int QPdfEnginePrivate::addXrefEntry ( int  object,
bool  printostr = true 
)
private

Definition at line 1212 of file qprintengine_pdf.cpp.

Referenced by addBrushPattern(), addConstantAlphaObject(), drawTextItem(), embedFont(), writeHeader(), writeImage(), writeInfo(), writePage(), writePageRoot(), writeTail(), and ~QPdfEnginePrivate().

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 }
QVector< int > xrefPositions
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
uint requestObject()
Definition: qpdf_p.h:231
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void xprintf(const char *fmt,...)

◆ drawTextItem()

void QPdfEnginePrivate::drawTextItem ( const QPointF p,
const QTextItemInt ti 
)
virtual

Reimplemented from QPdfBaseEnginePrivate.

Definition at line 654 of file qprintengine_pdf.cpp.

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 }
QFontEngine * fontEngine
double qreal
Definition: qglobal.h:1193
QTransform matrix
Definition: qpdf_p.h:139
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual int synthesized() const
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
virtual Type type() const =0
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
int addXrefEntry(int object, bool printostr=true)
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
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
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...
unsigned int uint
Definition: qglobal.h:996
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
qreal pixelSize
Definition: qfont_p.h:90
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
virtual void drawTextItem(const QPointF &p, const QTextItemInt &ti)
Definition: qpdf.cpp:1909
QVector< uint > annotations
Definition: qpdf_p.h:171
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
qreal toReal() const
Definition: qfixed_p.h:77
uint stretch
Definition: qfont_p.h:98
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
QPdfPage * currentPage
Definition: qpdf_p.h:239
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QTransform pageMatrix() const
QFontDef fontDef
const QTextCharFormat charFormat
void xprintf(const char *fmt,...)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ embedFont()

void QPdfEnginePrivate::embedFont ( QFontSubset font)
private

Definition at line 983 of file qprintengine_pdf.cpp.

Referenced by writeFonts().

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);
993  ff.open(QFile::WriteOnly);
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 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QByteArray createToUnicodeMap() const
double qreal
Definition: qglobal.h:1193
int writeCompressed(const char *src, int len)
QByteArray toTruetype() const
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray widthArray() const
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
The QString class provides a Unicode character string.
Definition: qstring.h:83
int addXrefEntry(int object, bool printostr=true)
void write(const QByteArray &data)
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
uint requestObject()
Definition: qpdf_p.h:231
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
static const bool do_compress
static QString toUnicode(QTextCodec *tc, const char *str)
Definition: qsql_mysql.cpp:95
int length() const
Same as size().
Definition: qbytearray.h:356
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
virtual Properties properties() const
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
qreal toReal() const
Definition: qfixed_p.h:77
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
static QString fileName(const QString &fileUrl)
void xprintf(const char *fmt,...)
const int object_id
Definition: qfontsubset_p.h:84

◆ height()

int QPdfEnginePrivate::height ( ) const
inline

Definition at line 136 of file qprintengine_pdf_p.h.

Referenced by newPage(), and pageMatrix().

136  {
137  QRect r = paperRect();
138  return qRound(r.height()*72./resolution);
139  }
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect paperRect() const
Definition: qpdf.cpp:2028
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ newPage()

void QPdfEnginePrivate::newPage ( )

Definition at line 719 of file qprintengine_pdf.cpp.

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 }
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
QVector< uint > pages
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
uint requestObject()
Definition: qpdf_p.h:231
QSize pageSize
Definition: qpdf_p.h:175
QPdfPage * currentPage
Definition: qpdf_p.h:239
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QTransform pageMatrix() const
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
ByteStream * stream
Definition: qpdf_p.h:137

◆ pageMatrix()

QTransform QPdfEnginePrivate::pageMatrix ( ) const

Definition at line 708 of file qprintengine_pdf.cpp.

Referenced by addBrushPattern(), drawTextItem(), and newPage().

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 }
double qreal
Definition: qglobal.h:1193
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QRect pageRect() const
Definition: qpdf.cpp:2057
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ printString()

void QPdfEnginePrivate::printString ( const QString string)
private

Definition at line 1227 of file qprintengine_pdf.cpp.

Referenced by writeInfo().

1227  {
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 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void write(const QByteArray &data)
unsigned short ushort
Definition: qglobal.h:995

◆ width()

int QPdfEnginePrivate::width ( ) const
inline

Definition at line 132 of file qprintengine_pdf_p.h.

Referenced by newPage().

132  {
133  QRect r = paperRect();
134  return qRound(r.width()*72./resolution);
135  }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect paperRect() const
Definition: qpdf.cpp:2028
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ write()

void QPdfEnginePrivate::write ( const QByteArray data)
inlineprivate

Definition at line 175 of file qprintengine_pdf_p.h.

Referenced by addBrushPattern(), embedFont(), printString(), writeImage(), and ~QPdfEnginePrivate().

175  {
176  stream->writeRawData(data.constData(), data.size());
177  streampos += data.size();
178  }
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.

◆ writeCompressed() [1/3]

int QPdfEnginePrivate::writeCompressed ( const char *  src,
int  len 
)
private

Definition at line 832 of file qprintengine_pdf.cpp.

Referenced by embedFont(), writeImage(), and writePage().

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 }
Q_CORE_EXPORT void qWarning(const char *,...)
static const bool do_compress
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.

◆ writeCompressed() [2/3]

int QPdfEnginePrivate::writeCompressed ( const QByteArray data)
inlineprivate

Definition at line 181 of file qprintengine_pdf_p.h.

Referenced by writeCompressed().

181 { return writeCompressed(data.constData(), data.length()); }
int writeCompressed(const char *src, int len)
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

◆ writeCompressed() [3/3]

int QPdfEnginePrivate::writeCompressed ( QIODevice dev)
private

Definition at line 758 of file qprintengine_pdf.cpp.

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 }
static int chunkSize()
Definition: qpdf_p.h:102
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
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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
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
Q_CORE_EXPORT void qWarning(const char *,...)
static const bool do_compress
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.

◆ writeFonts()

void QPdfEnginePrivate::writeFonts ( )
private

Definition at line 1095 of file qprintengine_pdf.cpp.

Referenced by writeTail().

1096 {
1098  embedFont(*it);
1099  delete *it;
1100  }
1101  fonts.clear();
1102 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
void embedFont(QFontSubset *font)
QHash< QFontEngine::FaceId, QFontSubset * > fonts
Definition: qpdf_p.h:254
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464

◆ writeHeader()

void QPdfEnginePrivate::writeHeader ( )

Definition at line 903 of file qprintengine_pdf.cpp.

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 }
int addXrefEntry(int object, bool printostr=true)
uint requestObject()
Definition: qpdf_p.h:231
void xprintf(const char *fmt,...)

◆ writeImage()

int QPdfEnginePrivate::writeImage ( const QByteArray data,
int  width,
int  height,
int  depth,
int  maskObject,
int  softMaskObject,
bool  dct = false 
)
private

Definition at line 855 of file qprintengine_pdf.cpp.

Referenced by addImage().

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 }
int writeCompressed(const char *src, int len)
int addXrefEntry(int object, bool printostr=true)
void write(const QByteArray &data)
static const bool interpolateImages
uint requestObject()
Definition: qpdf_p.h:231
static const bool do_compress
int length() const
Same as size().
Definition: qbytearray.h:356
void xprintf(const char *fmt,...)

◆ writeInfo()

void QPdfEnginePrivate::writeInfo ( )
private

Definition at line 938 of file qprintengine_pdf.cpp.

Referenced by writeHeader().

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 }
double d
Definition: qnumeric_p.h:62
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
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
void printString(const QString &string)
int addXrefEntry(int object, bool printostr=true)
The QTime class provides clock time functions.
Definition: qdatetime.h:148
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
#define QT_VERSION_STR
This macro expands to a string that specifies Qt&#39;s version number (for example, "4.
Definition: qglobal.h:47
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:251
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
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
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
void xprintf(const char *fmt,...)
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ writePage()

void QPdfEnginePrivate::writePage ( )
private

Definition at line 1104 of file qprintengine_pdf.cpp.

Referenced by newPage(), and writeTail().

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 }
QVector< uint > graphicStates
Definition: qpdf_p.h:168
int writeCompressed(const char *src, int len)
QVector< uint > pages
QVector< uint > fonts
Definition: qpdf_p.h:170
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
QVector< uint > images
Definition: qpdf_p.h:167
int addXrefEntry(int object, bool printostr=true)
int width() const
Returns the width.
Definition: qsize.h:126
unsigned int uint
Definition: qglobal.h:996
uint requestObject()
Definition: qpdf_p.h:231
QVector< uint > patterns
Definition: qpdf_p.h:169
QIODevice * stream()
Definition: qpdf.cpp:225
static const bool do_compress
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< uint > annotations
Definition: qpdf_p.h:171
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
int height() const
Returns the height.
Definition: qsize.h:129
QSize pageSize
Definition: qpdf_p.h:175
QPdfPage * currentPage
Definition: qpdf_p.h:239
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void xprintf(const char *fmt,...)

◆ writePageRoot()

void QPdfEnginePrivate::writePageRoot ( )
private

Definition at line 961 of file qprintengine_pdf.cpp.

Referenced by writeTail().

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 }
QVector< uint > pages
int addXrefEntry(int object, bool printostr=true)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void xprintf(const char *fmt,...)

◆ writeTail()

void QPdfEnginePrivate::writeTail ( )

Definition at line 1188 of file qprintengine_pdf.cpp.

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 }
QVector< int > xrefPositions
int addXrefEntry(int object, bool printostr=true)
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void xprintf(const char *fmt,...)

◆ xprintf()

void QPdfEnginePrivate::xprintf ( const char *  fmt,
  ... 
)
private

Definition at line 738 of file qprintengine_pdf.cpp.

Referenced by addConstantAlphaObject(), addXrefEntry(), drawTextItem(), embedFont(), writeHeader(), writeImage(), writeInfo(), writePage(), writePageRoot(), writeTail(), and ~QPdfEnginePrivate().

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 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.

Properties

◆ alphaCache

QHash<QPair<uint, uint>, uint > QPdfEnginePrivate::alphaCache
private

Definition at line 188 of file qprintengine_pdf_p.h.

Referenced by addConstantAlphaObject().

◆ catalog

int QPdfEnginePrivate::catalog
private

Definition at line 185 of file qprintengine_pdf_p.h.

Referenced by writeHeader(), and writeTail().

◆ graphicsState

int QPdfEnginePrivate::graphicsState
private

Definition at line 185 of file qprintengine_pdf_p.h.

Referenced by writeHeader(), and writePage().

◆ imageCache

QHash<qint64, uint> QPdfEnginePrivate::imageCache
private

Definition at line 187 of file qprintengine_pdf_p.h.

Referenced by addImage().

◆ info

int QPdfEnginePrivate::info
private

Definition at line 185 of file qprintengine_pdf_p.h.

Referenced by writeInfo(), and writeTail().

◆ pageRoot

int QPdfEnginePrivate::pageRoot
private

Definition at line 185 of file qprintengine_pdf_p.h.

Referenced by writeHeader(), writePage(), and writePageRoot().

◆ pages

QVector<uint> QPdfEnginePrivate::pages
private

Definition at line 186 of file qprintengine_pdf_p.h.

Referenced by newPage(), writePage(), and writePageRoot().

◆ patternColorSpace

int QPdfEnginePrivate::patternColorSpace
private

Definition at line 185 of file qprintengine_pdf_p.h.

Referenced by writeHeader(), and writePage().

◆ stream

QDataStream* QPdfEnginePrivate::stream
private

◆ streampos

int QPdfEnginePrivate::streampos
private

Definition at line 166 of file qprintengine_pdf_p.h.

Referenced by addXrefEntry(), QPdfEnginePrivate(), writeCompressed(), and xprintf().

◆ xrefPositions

QVector<int> QPdfEnginePrivate::xrefPositions
private

Definition at line 164 of file qprintengine_pdf_p.h.

Referenced by addXrefEntry(), and writeTail().


The documentation for this class was generated from the following files: