Qt 4.8
Namespaces | Macros | Functions | Variables
qpdf.cpp File Reference
#include "qplatformdefs.h"
#include <qdebug.h>
#include "qpdf_p.h"
#include <qfile.h>
#include <qtemporaryfile.h>
#include <private/qmath_p.h>
#include "private/qcups_p.h"
#include "qprinterinfo.h"
#include <qnumeric.h>
#include "private/qfont_p.h"
#include "private/qcore_unix_p.h"

Go to the source code of this file.

Namespaces

 QPdf
 

Macros

#define Q_IN(n)   int(n * 72)
 
#define Q_MM(n)   int((n * 720 + 127) / 254)
 
#define QT_PATH_ELEMENT(elm)
 

Functions

static void closeAllOpenFds ()
 
static void cubicToHook (qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
 
static void lineToHook (qfixed x, qfixed y, void *data)
 
static void moveToHook (qfixed x, qfixed y, void *data)
 
const char * qt_int_to_string (int val, char *buf)
 
QSizeF qt_paperSizeToQSizeF (QPrinter::PaperSize size)
 
const char * qt_real_to_string (qreal val, char *buf)
 
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath (const QRegion &region)
 

Variables

static const char * pattern_for_brush []
 
static const char *const psToStr [QPrinter::NPaperSize+1]
 

Macro Definition Documentation

◆ Q_IN

#define Q_IN (   n)    int(n * 72)

Definition at line 895 of file qpdf.cpp.

◆ Q_MM

#define Q_MM (   n)    int((n * 720 + 127) / 254)

Definition at line 894 of file qpdf.cpp.

Referenced by QPdf::paperSize().

◆ QT_PATH_ELEMENT

#define QT_PATH_ELEMENT (   elm)

Definition at line 270 of file qpdf.cpp.

Function Documentation

◆ closeAllOpenFds()

static void closeAllOpenFds ( )
static

Definition at line 1645 of file qpdf.cpp.

Referenced by QPdfBaseEnginePrivate::openPrintDevice().

1646 {
1647  // hack time... getting the maximum number of open
1648  // files, if possible. if not we assume it's the
1649  // larger of 256 and the fd we got
1650  int i;
1651 #if defined(_SC_OPEN_MAX)
1652  i = (int)sysconf(_SC_OPEN_MAX);
1653 #elif defined(_POSIX_OPEN_MAX)
1654  i = (int)_POSIX_OPEN_MAX;
1655 #elif defined(OPEN_MAX)
1656  i = (int)OPEN_MAX;
1657 #else
1658  i = 256;
1659 #endif
1660  // leave stdin/out/err untouched
1661  while(--i > 2)
1662  QT_CLOSE(i);
1663 }
#define QT_CLOSE
Definition: qcore_unix_p.h:304

◆ cubicToHook()

static void cubicToHook ( qfixed  c1x,
qfixed  c1y,
qfixed  c2x,
qfixed  c2y,
qfixed  ex,
qfixed  ey,
void *  data 
)
static

Definition at line 735 of file qpdf.cpp.

Referenced by QStrokerOps::setCubicToHook(), and QPdf::Stroker::Stroker().

739 {
741  if (!t->cosmeticPen) {
742  t->matrix.map(c1x, c1y, &c1x, &c1y);
743  t->matrix.map(c2x, c2y, &c2x, &c2y);
744  t->matrix.map(ex, ey, &ex, &ey);
745  }
746  *t->stream << c1x << c1y
747  << c2x << c2y
748  << ex << ey
749  << "c\n";
750 }
QTransform matrix
Definition: qpdf_p.h:139
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...
static const char * data(const QByteArray &arr)
bool cosmeticPen
Definition: qpdf_p.h:140
ByteStream * stream
Definition: qpdf_p.h:137

◆ lineToHook()

static void lineToHook ( qfixed  x,
qfixed  y,
void *  data 
)
static

Definition at line 727 of file qpdf.cpp.

Referenced by QStrokerOps::setLineToHook(), and QPdf::Stroker::Stroker().

728 {
730  if (!t->cosmeticPen)
731  t->matrix.map(x, y, &x, &y);
732  *t->stream << x << y << "l\n";
733 }
QTransform matrix
Definition: qpdf_p.h:139
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...
static const char * data(const QByteArray &arr)
bool cosmeticPen
Definition: qpdf_p.h:140
ByteStream * stream
Definition: qpdf_p.h:137

◆ moveToHook()

static void moveToHook ( qfixed  x,
qfixed  y,
void *  data 
)
static

Definition at line 716 of file qpdf.cpp.

Referenced by QStrokerOps::setMoveToHook(), and QPdf::Stroker::Stroker().

717 {
719  if (!t->first)
720  *t->stream << "h\n";
721  if (!t->cosmeticPen)
722  t->matrix.map(x, y, &x, &y);
723  *t->stream << x << y << "m\n";
724  t->first = false;
725 }
QTransform matrix
Definition: qpdf_p.h:139
bool first
Definition: qpdf_p.h:138
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...
static const char * data(const QByteArray &arr)
bool cosmeticPen
Definition: qpdf_p.h:140
ByteStream * stream
Definition: qpdf_p.h:137

◆ qt_int_to_string()

const char* qt_int_to_string ( int  val,
char *  buf 
)

Definition at line 115 of file qpdf.cpp.

Referenced by QPdf::ByteStream::operator<<().

115  {
116  const char *ret = buf;
117  if (val < 0) {
118  *(buf++) = '-';
119  val = -val;
120  }
121  char output[256];
122  int i = 0;
123  while (val) {
124  output[i] = '0' + (val % 10);
125  ++i;
126  val /= 10;
127  }
128  if (i == 0) {
129  *(buf++) = '0';
130  } else {
131  while (i)
132  *(buf++) = output[--i];
133  }
134  *(buf++) = ' ';
135  *buf = 0;
136  return ret;
137 }

◆ qt_paperSizeToQSizeF()

QSizeF qt_paperSizeToQSizeF ( QPrinter::PaperSize  size)

Definition at line 2615 of file qprinter.cpp.

Referenced by QPdf::paperSize().

2616 {
2617  if (size == QPrinter::Custom) return QSizeF(0, 0);
2618  return QSizeF(qt_paperSizes[size][0], qt_paperSizes[size][1]);
2619 }
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
static const float qt_paperSizes[][2]
Definition: qprinter.cpp:89

◆ qt_real_to_string()

const char* qt_real_to_string ( qreal  val,
char *  buf 
)

Definition at line 63 of file qpdf.cpp.

Referenced by QPdf::ByteStream::operator<<().

63  {
64  const char *ret = buf;
65 
66  if (qIsNaN(val)) {
67  *(buf++) = '0';
68  *(buf++) = ' ';
69  *buf = 0;
70  return ret;
71  }
72 
73  if (val < 0) {
74  *(buf++) = '-';
75  val = -val;
76  }
77  unsigned int ival = (unsigned int) val;
78  qreal frac = val - (qreal)ival;
79 
80  int ifrac = (int)(frac * 1000000000);
81  if (ifrac == 1000000000) {
82  ++ival;
83  ifrac = 0;
84  }
85  char output[256];
86  int i = 0;
87  while (ival) {
88  output[i] = '0' + (ival % 10);
89  ++i;
90  ival /= 10;
91  }
92  int fact = 100000000;
93  if (i == 0) {
94  *(buf++) = '0';
95  } else {
96  while (i) {
97  *(buf++) = output[--i];
98  fact /= 10;
99  ifrac /= 10;
100  }
101  }
102 
103  if (ifrac) {
104  *(buf++) = '.';
105  while (fact) {
106  *(buf++) = '0' + ((ifrac/fact) % 10);
107  fact /= 10;
108  }
109  }
110  *(buf++) = ' ';
111  *buf = 0;
112  return ret;
113 }
double qreal
Definition: qglobal.h:1193
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55

◆ qt_regionToPath()

Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath ( const QRegion region)

Definition at line 1160 of file qregion.cpp.

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

1161 {
1162  QPainterPath result;
1163  if (region.rectCount() == 1) {
1164  result.addRect(region.boundingRect());
1165  return result;
1166  }
1167 
1168  const QVector<QRect> rects = region.rects();
1169 
1170  QVarLengthArray<Segment> segments;
1171  segments.resize(4 * rects.size());
1172 
1173  const QRect *rect = rects.constData();
1174  const QRect *end = rect + rects.size();
1175 
1176  int lastRowSegmentCount = 0;
1177  Segment *lastRowSegments = 0;
1178 
1179  int lastSegment = 0;
1180  int lastY = 0;
1181  while (rect != end) {
1182  const int y = rect[0].y();
1183  int count = 0;
1184  while (&rect[count] != end && rect[count].y() == y)
1185  ++count;
1186 
1187  for (int i = 0; i < count; ++i) {
1188  int offset = lastSegment + i;
1189  segments[offset] = Segment(rect[i].topLeft());
1190  segments[offset += count] = Segment(rect[i].topRight() + QPoint(1, 0));
1191  segments[offset += count] = Segment(rect[i].bottomRight() + QPoint(1, 1));
1192  segments[offset += count] = Segment(rect[i].bottomLeft() + QPoint(0, 1));
1193 
1194  offset = lastSegment + i;
1195  for (int j = 0; j < 4; ++j)
1196  segments[offset + j * count].connect(segments[offset + ((j + 1) % 4) * count]);
1197  }
1198 
1199  if (lastRowSegments && lastY == y)
1200  mergeSegments(lastRowSegments, lastRowSegmentCount, &segments[lastSegment], count);
1201 
1202  lastRowSegments = &segments[lastSegment + 2 * count];
1203  lastRowSegmentCount = count;
1204  lastSegment += 4 * count;
1205  lastY = y + rect[0].height();
1206  rect += count;
1207  }
1208 
1209  for (int i = 0; i < lastSegment; ++i) {
1210  Segment *segment = &segments[i];
1211  if (!segment->added)
1212  addSegmentsToPath(segment, result);
1213  }
1214 
1215  return result;
1216 }
void resize(int size)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

Variable Documentation

◆ pattern_for_brush

const char* pattern_for_brush[]
static

Definition at line 371 of file qpdf.cpp.

Referenced by QPdf::patternForBrush().

◆ psToStr

const char* const psToStr[QPrinter::NPaperSize+1]
static
Initial value:
=
{
"A4", "B5", "Letter", "Legal", "Executive",
"A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1",
"B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E",
"DLE", "Folio", "Ledger", "Tabloid", 0
}

Definition at line 897 of file qpdf.cpp.

Referenced by QPdf::paperSizeToString().