Qt 4.8
Classes | Enumerations | Functions
QPdf Namespace Reference

Classes

class  ByteStream
 
struct  PaperSize
 
struct  Stroker
 

Enumerations

enum  PathFlags { ClipPath, FillPath, StrokePath, FillAndStrokePath }
 

Functions

QByteArray ascii85Encode (const QByteArray &input)
 
QByteArray generateDashes (const QPen &pen)
 
QByteArray generateMatrix (const QTransform &matrix)
 
QByteArray generatePath (const QPainterPath &path, const QTransform &matrix, PathFlags flags)
 
PaperSize paperSize (QPrinter::PaperSize paperSize)
 
const char * paperSizeToString (QPrinter::PaperSize paperSize)
 
QByteArray patternForBrush (const QBrush &b)
 
const char * toHex (ushort u, char *buffer)
 
const char * toHex (uchar u, char *buffer)
 

Enumeration Type Documentation

◆ PathFlags

Enumerator
ClipPath 
FillPath 
StrokePath 
FillAndStrokePath 

Definition at line 119 of file qpdf_p.h.

Function Documentation

◆ ascii85Encode()

QByteArray QPdf::ascii85Encode ( const QByteArray input)

Definition at line 806 of file qpdf.cpp.

Referenced by compressHelper().

807 {
808  int isize = input.size()/4*4;
809  QByteArray output;
810  output.resize(input.size()*5/4+7);
811  char *out = output.data();
812  const uchar *in = (const uchar *)input.constData();
813  for (int i = 0; i < isize; i += 4) {
814  uint val = (((uint)in[i])<<24) + (((uint)in[i+1])<<16) + (((uint)in[i+2])<<8) + (uint)in[i+3];
815  if (val == 0) {
816  *out = 'z';
817  ++out;
818  } else {
819  char base[5];
820  base[4] = val % 85;
821  val /= 85;
822  base[3] = val % 85;
823  val /= 85;
824  base[2] = val % 85;
825  val /= 85;
826  base[1] = val % 85;
827  val /= 85;
828  base[0] = val % 85;
829  *(out++) = base[0] + '!';
830  *(out++) = base[1] + '!';
831  *(out++) = base[2] + '!';
832  *(out++) = base[3] + '!';
833  *(out++) = base[4] + '!';
834  }
835  }
836  //write the last few bytes
837  int remaining = input.size() - isize;
838  if (remaining) {
839  uint val = 0;
840  for (int i = isize; i < input.size(); ++i)
841  val = (val << 8) + in[i];
842  val <<= 8*(4-remaining);
843  char base[5];
844  base[4] = val % 85;
845  val /= 85;
846  base[3] = val % 85;
847  val /= 85;
848  base[2] = val % 85;
849  val /= 85;
850  base[1] = val % 85;
851  val /= 85;
852  base[0] = val % 85;
853  for (int i = 0; i < remaining+1; ++i)
854  *(out++) = base[i] + '!';
855  }
856  *(out++) = '~';
857  *(out++) = '>';
858  output.resize(out-output.data());
859  return output;
860 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const uint base
Definition: qurl.cpp:268
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
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

◆ generateDashes()

QByteArray QPdf::generateDashes ( const QPen pen)

Definition at line 348 of file qpdf.cpp.

Referenced by QPdfBaseEngine::setPen().

349 {
350  QByteArray result;
351  ByteStream s(&result);
352  s << '[';
353 
354  QVector<qreal> dasharray = pen.dashPattern();
355  qreal w = pen.widthF();
356  if (w < 0.001)
357  w = 1;
358  for (int i = 0; i < dasharray.size(); ++i) {
359  qreal dw = dasharray.at(i)*w;
360  if (dw < 0.0001) dw = 0.0001;
361  s << dw;
362  }
363  s << ']';
364  //qDebug() << "dasharray: pen has" << dasharray;
365  //qDebug() << " => " << result;
366  return result;
367 }
double qreal
Definition: qglobal.h:1193
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QVector< qreal > dashPattern() const
Returns the dash pattern of this pen.
Definition: qpen.cpp:466
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ generateMatrix()

QByteArray QPdf::generateMatrix ( const QTransform matrix)

Definition at line 334 of file qpdf.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QPdfEngine::drawImage(), QPSPrintEngine::drawImageInternal(), QPdfEngine::drawPixmap(), QPdfBaseEngine::drawRects(), QPdfBaseEngine::drawTextItem(), QPdfEnginePrivate::newPage(), and QPdfBaseEngine::setupGraphicsState().

335 {
336  QByteArray result;
337  ByteStream s(&result);
338  s << matrix.m11()
339  << matrix.m12()
340  << matrix.m21()
341  << matrix.m22()
342  << matrix.dx()
343  << matrix.dy()
344  << "cm\n";
345  return result;
346 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
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
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ generatePath()

QByteArray QPdf::generatePath ( const QPainterPath path,
const QTransform matrix,
PathFlags  flags 
)

Definition at line 272 of file qpdf.cpp.

Referenced by QPdfBaseEngine::drawPath(), and QPdfBaseEngine::setupGraphicsState().

273 {
274  QByteArray result;
275  if (!path.elementCount())
276  return result;
277 
278  ByteStream s(&result);
279 
280  int start = -1;
281  for (int i = 0; i < path.elementCount(); ++i) {
282  const QPainterPath::Element &elm = path.elementAt(i);
283  switch (elm.type) {
285  if (start >= 0
286  && path.elementAt(start).x == path.elementAt(i-1).x
287  && path.elementAt(start).y == path.elementAt(i-1).y)
288  s << "h\n";
289  s << matrix.map(QPointF(elm.x, elm.y)) << "m\n";
290  start = i;
291  break;
293  s << matrix.map(QPointF(elm.x, elm.y)) << "l\n";
294  break;
298  s << matrix.map(QPointF(elm.x, elm.y))
299  << matrix.map(QPointF(path.elementAt(i+1).x, path.elementAt(i+1).y))
300  << matrix.map(QPointF(path.elementAt(i+2).x, path.elementAt(i+2).y))
301  << "c\n";
302  i += 2;
303  break;
304  default:
305  qFatal("QPdf::generatePath(), unhandled type: %d", elm.type);
306  }
307  }
308  if (start >= 0
309  && path.elementAt(start).x == path.elementAt(path.elementCount()-1).x
310  && path.elementAt(start).y == path.elementAt(path.elementCount()-1).y)
311  s << "h\n";
312 
313  Qt::FillRule fillRule = path.fillRule();
314 
315  const char *op = "";
316  switch (flags) {
317  case ClipPath:
318  op = (fillRule == Qt::WindingFill) ? "W n\n" : "W* n\n";
319  break;
320  case FillPath:
321  op = (fillRule == Qt::WindingFill) ? "f\n" : "f*\n";
322  break;
323  case StrokePath:
324  op = "S\n";
325  break;
326  case FillAndStrokePath:
327  op = (fillRule == Qt::WindingFill) ? "B\n" : "B*\n";
328  break;
329  }
330  s << op;
331  return result;
332 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
FillRule
Definition: qnamespace.h:1485
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
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...
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
Q_CORE_EXPORT void qFatal(const char *,...)
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ paperSize()

QPdf::PaperSize QPdf::paperSize ( QPrinter::PaperSize  paperSize)

Definition at line 905 of file qpdf.cpp.

Referenced by QPdfBaseEnginePrivate::pageRect(), QtopiaPrintEngine::paperRect(), QPdfBaseEnginePrivate::paperRect(), paperSizeToString(), QPrintPreviewWidgetPrivate::populateScene(), QMacPrintEnginePrivate::QMacPrintEnginePrivate(), QUnixPrintWidgetPrivate::setCupsProperties(), QPageSetupWidget::setupPrinter(), and QWin32PrintEnginePrivate::updateCustomPaperSize().

906 {
908  PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) };
909  return p;
910 }
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define Q_MM(n)
Definition: qpdf.cpp:894
QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
Definition: qprinter.cpp:2615

◆ paperSizeToString()

const char * QPdf::paperSizeToString ( QPrinter::PaperSize  paperSize)

Definition at line 912 of file qpdf.cpp.

913 {
914  return psToStr[paperSize];
915 }
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
static const char *const psToStr[QPrinter::NPaperSize+1]
Definition: qpdf.cpp:897

◆ patternForBrush()

QByteArray QPdf::patternForBrush ( const QBrush b)

Definition at line 524 of file qpdf.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern().

525 {
526  int style = b.style();
527  if (style > Qt::DiagCrossPattern)
528  return QByteArray();
529  return pattern_for_brush[style];
530 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const char * pattern_for_brush[]
Definition: qpdf.cpp:371
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182

◆ toHex() [1/2]

const char * QPdf::toHex ( ushort  u,
char *  buffer 
)

Definition at line 862 of file qpdf.cpp.

Referenced by QFontSubset::createToUnicodeMap(), QPdfBaseEnginePrivate::drawTextItem(), encodeNumber(), and QFontSubset::glyphName().

863 {
864  int i = 3;
865  while (i >= 0) {
866  ushort hex = (u & 0x000f);
867  if (hex < 0x0a)
868  buffer[i] = '0'+hex;
869  else
870  buffer[i] = 'A'+(hex-0x0a);
871  u = u >> 4;
872  i--;
873  }
874  buffer[4] = '\0';
875  return buffer;
876 }
quint16 u
unsigned short ushort
Definition: qglobal.h:995
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.

◆ toHex() [2/2]

const char * QPdf::toHex ( uchar  u,
char *  buffer 
)

Definition at line 878 of file qpdf.cpp.

879 {
880  int i = 1;
881  while (i >= 0) {
882  ushort hex = (u & 0x000f);
883  if (hex < 0x0a)
884  buffer[i] = '0'+hex;
885  else
886  buffer[i] = 'A'+(hex-0x0a);
887  u = u >> 4;
888  i--;
889  }
890  buffer[2] = '\0';
891  return buffer;
892 }
quint16 u
unsigned short ushort
Definition: qglobal.h:995
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.