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

#include <qprintengine_pdf_p.h>

Inheritance diagram for QPdfEngine:
QPdfBaseEngine QAlphaPaintEngine QPrintEngine QPaintEngine

Public Functions

bool abort ()
 Instructs the print engine to abort the printing process. More...
 
QString author () const
 
bool begin (QPaintDevice *pdev)
 Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. More...
 
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 rectangle using the given conversion flags flags, to convert it to a pixmap. More...
 
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. More...
 
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. More...
 
bool end ()
 Reimplement this function to finish painting on the current paint device. More...
 
bool newPage ()
 Instructs the print engine to start a new page. More...
 
QPrinter::PrinterState printerState () const
 Returns the current state of the printer being used by the print engine. More...
 
 QPdfEngine (QPrinter::PrinterMode m)
 
void setAuthor (const QString &author)
 
void setBrush ()
 
void setDevice (QIODevice *dev)
 
Type type () const
 Reimplement this function to return the paint engine Type. More...
 
virtual ~QPdfEngine ()
 
- Public Functions inherited from QPdfBaseEngine
void drawLines (const QLineF *lines, int lineCount)
 The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine. More...
 
void drawPath (const QPainterPath &path)
 The default implementation ignores the path and does nothing. More...
 
void drawPoints (const QPointF *points, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
void drawPolygon (const QPointF *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
void drawRects (const QRectF *rects, int rectCount)
 Draws the first rectCount rectangles in the buffer rects. More...
 
void drawTextItem (const QPointF &p, const QTextItem &textItem)
 This function draws the text item textItem at position p. More...
 
int metric (QPaintDevice::PaintDeviceMetric metricType) const
 Returns the metric for the given id. More...
 
QVariant property (PrintEnginePropertyKey key) const
 Returns the print engine's property specified by key. More...
 
 QPdfBaseEngine (QPdfBaseEnginePrivate &d, PaintEngineFeatures f)
 
void setPen ()
 
void setProperty (PrintEnginePropertyKey key, const QVariant &value)
 Sets the print engine's property specified by key to the given value. More...
 
void setupGraphicsState (QPaintEngine::DirtyFlags flags)
 
void updateState (const QPaintEngineState &state)
 Reimplement this function to update the state of a paint engine. More...
 
 ~QPdfBaseEngine ()
 
- Public Functions inherited from QAlphaPaintEngine
virtual void drawImage (const QRectF &r, const QImage &image, const QRectF &sr)
 
 ~QAlphaPaintEngine ()
 
- Public Functions inherited from QPaintEngine
void clearDirty (DirtyFlags df)
 
virtual QPoint coordinateOffset () const
 Returns the offset from the painters origo to the engines origo. More...
 
virtual void drawEllipse (const QRectF &r)
 Reimplement this function to draw the largest ellipse that can be contained within rectangle rect. More...
 
virtual void drawEllipse (const QRect &r)
 The default implementation of this function calls the floating point version of this function. More...
 
virtual void drawLines (const QLine *lines, int lineCount)
 The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function. More...
 
virtual void drawPoints (const QPoint *points, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
virtual void drawPolygon (const QPoint *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
virtual void drawRects (const QRect *rects, int rectCount)
 The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function. More...
 
void fix_neg_rect (int *x, int *y, int *w, int *h)
 
virtual HDC getDC () const
 Empty default implementation. More...
 
bool hasFeature (PaintEngineFeatures feature) const
 Returns true if the paint engine supports the specified feature; otherwise returns false. More...
 
bool isActive () const
 Returns true if the paint engine is actively drawing; otherwise returns false. More...
 
bool isExtended () const
 Returns true if the paint engine is a QPaintEngineEx derivative. More...
 
QPaintDevicepaintDevice () const
 Returns the device that this engine is painting on, if painting is active; otherwise returns 0. More...
 
QPainterpainter () const
 Returns the paint engine's painter. More...
 
 QPaintEngine (PaintEngineFeatures features=0)
 Creates a paint engine with the featureset specified by caps. More...
 
virtual void releaseDC (HDC hdc) const
 Empty default implementation. More...
 
void setActive (bool newState)
 Sets the active state of the paint engine to state. More...
 
void setDirty (DirtyFlags df)
 
void setPaintDevice (QPaintDevice *device)
 
void setSystemClip (const QRegion &baseClip)
 Sets the system clip for this engine. More...
 
void setSystemRect (const QRect &rect)
 Sets the target rect for drawing within the backing store. More...
 
void syncState ()
 Updates all dirty states in this engine. More...
 
QRegion systemClip () const
 Returns the system clip. More...
 
QRect systemRect () const
 Retrieves the rect for drawing within the backing store. More...
 
bool testDirty (DirtyFlags df)
 
virtual ~QPaintEngine ()
 Destroys the paint engine. More...
 
- Public Functions inherited from QPrintEngine
virtual HDC getPrinterDC () const
 
virtual void releasePrinterDC (HDC) const
 
virtual ~QPrintEngine ()
 Destroys the print engine. More...
 

Properties

QPrinter::PrinterState state
 

Additional Inherited Members

- Public Types inherited from QPaintEngine
enum  DirtyFlag {
  DirtyPen = 0x0001, DirtyBrush = 0x0002, DirtyBrushOrigin = 0x0004, DirtyFont = 0x0008,
  DirtyBackground = 0x0010, DirtyBackgroundMode = 0x0020, DirtyTransform = 0x0040, DirtyClipRegion = 0x0080,
  DirtyClipPath = 0x0100, DirtyHints = 0x0200, DirtyCompositionMode = 0x0400, DirtyClipEnabled = 0x0800,
  DirtyOpacity = 0x1000, AllDirty = 0xffff
}
 QPaintEngine::updateState(). More...
 
enum  PaintEngineFeature {
  PrimitiveTransform = 0x00000001, PatternTransform = 0x00000002, PixmapTransform = 0x00000004, PatternBrush = 0x00000008,
  LinearGradientFill = 0x00000010, RadialGradientFill = 0x00000020, ConicalGradientFill = 0x00000040, AlphaBlend = 0x00000080,
  PorterDuff = 0x00000100, PainterPaths = 0x00000200, Antialiasing = 0x00000400, BrushStroke = 0x00000800,
  ConstantOpacity = 0x00001000, MaskedBrush = 0x00002000, PerspectiveTransform = 0x00004000, BlendModes = 0x00008000,
  ObjectBoundingModeGradients = 0x00010000, RasterOpModes = 0x00020000, PaintOutsidePaintEvent = 0x20000000, AllFeatures = 0xffffffff
}
 This enum is used to describe the features or capabilities that the paint engine has. More...
 
enum  PolygonDrawMode { OddEvenMode, WindingMode, ConvexMode, PolylineMode }
 
enum  Type {
  X11, Windows, QuickDraw, CoreGraphics,
  MacPrinter, QWindowSystem, PostScript, OpenGL,
  Picture, SVG, Raster, Direct3D,
  Pdf, OpenVG, OpenGL2, PaintBuffer,
  Blitter, User = 50, MaxUser = 100
}
 
- Public Types inherited from QPrintEngine
enum  PrintEnginePropertyKey {
  PPK_CollateCopies, PPK_ColorMode, PPK_Creator, PPK_DocumentName,
  PPK_FullPage, PPK_NumberOfCopies, PPK_Orientation, PPK_OutputFileName,
  PPK_PageOrder, PPK_PageRect, PPK_PageSize, PPK_PaperRect,
  PPK_PaperSource, PPK_PrinterName, PPK_PrinterProgram, PPK_Resolution,
  PPK_SelectionOption, PPK_SupportedResolutions, PPK_WindowsPageSize, PPK_FontEmbedding,
  PPK_SuppressSystemPrintStatus, PPK_Duplex, PPK_PaperSources, PPK_CustomPaperSize,
  PPK_PageMargins, PPK_CopyCount, PPK_SupportsMultipleCopies, PPK_PaperSize = PPK_PageSize,
  PPK_CustomBase = 0xff00
}
 This enum is used to communicate properties between the print engine and QPrinter. More...
 
- Protected Functions inherited from QAlphaPaintEngine
QRegion alphaClipping () const
 
void cleanUp ()
 
bool continueCall () const
 
void flushAndInit (bool init=true)
 
 QAlphaPaintEngine (QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
 
- Protected Functions inherited from QPaintEngine
 QPaintEngine (QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
 
- Protected Variables inherited from QPaintEngine
uint active: 1
 
QScopedPointer< QPaintEnginePrivated_ptr
 
uint extended: 1
 
PaintEngineFeatures gccaps
 
uint selfDestruct: 1
 
QPaintEngineStatestate
 

Detailed Description

Definition at line 85 of file qprintengine_pdf_p.h.

Constructors and Destructors

◆ QPdfEngine()

QPdfEngine::QPdfEngine ( QPrinter::PrinterMode  m)

Definition at line 112 of file qprintengine_pdf.cpp.

114 {
116 }
QPrinter::PrinterState state
QPaintEngine::PaintEngineFeatures qt_pdf_decide_features()
QPdfBaseEngine(QPdfBaseEnginePrivate &d, PaintEngineFeatures f)
Definition: qpdf.cpp:919

◆ ~QPdfEngine()

QPdfEngine::~QPdfEngine ( )
virtual

Definition at line 118 of file qprintengine_pdf.cpp.

119 {
120 }

Functions

◆ abort()

bool QPdfEngine::abort ( )
inlinevirtual

Instructs the print engine to abort the printing process.

Returns true if successful; otherwise returns false.

Implements QPrintEngine.

Definition at line 104 of file qprintengine_pdf_p.h.

104 {return false;}

◆ author()

QString QPdfEngine::author ( ) const

Referenced by printerState().

◆ begin()

bool QPdfEngine::begin ( QPaintDevice pdev)
virtual

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev.

Return true if the initialization was successful; otherwise return false.

See also
end() isActive()

Reimplemented from QPdfBaseEngine.

Definition at line 122 of file qprintengine_pdf.cpp.

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 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
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
void setActive(bool newState)
Sets the active state of the paint engine to state.
Definition: qpaintengine.h:155
bool newPage()
Instructs the print engine to start a new page.
QPrinter::PrinterState state

◆ drawImage()

void QPdfEngine::drawImage ( const QRectF r,
const QImage pm,
const QRectF sr,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
virtual

Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.

Reimplemented from QPaintEngine.

Definition at line 200 of file qprintengine_pdf.cpp.

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 }
double d
Definition: qnumeric_p.h:62
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
#define Q_D(Class)
Definition: qglobal.h:2482
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawPixmap()

void QPdfEngine::drawPixmap ( const QRectF r,
const QPixmap pm,
const QRectF sr 
)
virtual

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.

Reimplemented from QAlphaPaintEngine.

Definition at line 169 of file qprintengine_pdf.cpp.

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 }
double d
Definition: qnumeric_p.h:62
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QByteArray generateMatrix(const QTransform &matrix)
Definition: qpdf.cpp:334
#define Q_D(Class)
Definition: qglobal.h:2482
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
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
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawTiledPixmap()

void QPdfEngine::drawTiledPixmap ( const QRectF rect,
const QPixmap pixmap,
const QPointF p 
)
virtual

Reimplement this function to draw the pixmap in the given rect, starting at the given p.

The pixmap will be drawn repeatedly until the rect is filled.

Reimplemented from QAlphaPaintEngine.

Definition at line 222 of file qprintengine_pdf.cpp.

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 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
#define Q_D(Class)
Definition: qglobal.h:2482
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
Definition: qpdf.cpp:984
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76

◆ end()

bool QPdfEngine::end ( )
virtual

Reimplement this function to finish painting on the current paint device.

Return true if painting was finished successfully; otherwise return false.

See also
begin() isActive()

Reimplemented from QPdfBaseEngine.

Definition at line 156 of file qprintengine_pdf.cpp.

157 {
158  Q_D(QPdfEngine);
159  d->writeTail();
160 
161  d->stream->unsetDevice();
163  setActive(false);
165  return true;
166 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool end()
Reimplement this function to finish painting on the current paint device.
Definition: qpdf.cpp:1632
void setActive(bool newState)
Sets the active state of the paint engine to state.
Definition: qpaintengine.h:155
QPrinter::PrinterState state

◆ newPage()

bool QPdfEngine::newPage ( )
virtual

Instructs the print engine to start a new page.

Returns true if the printer was able to create the new page; otherwise returns false.

Reimplemented from QPdfBaseEngine.

Definition at line 291 of file qprintengine_pdf.cpp.

Referenced by abort(), and begin().

292 {
293  Q_D(QPdfEngine);
294  if (!isActive())
295  return false;
296  d->newPage();
297  return QPdfBaseEngine::newPage();
298 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool newPage()
Instructs the print engine to start a new page.
Definition: qpdf.cpp:1340
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154

◆ printerState()

QPrinter::PrinterState QPdfEngine::printerState ( ) const
inlinevirtual

Returns the current state of the printer being used by the print engine.

Implements QPrintEngine.

Definition at line 106 of file qprintengine_pdf_p.h.

106 {return state;}
QPrinter::PrinterState state

◆ setAuthor()

void QPdfEngine::setAuthor ( const QString author)

Referenced by printerState().

◆ setBrush()

void QPdfEngine::setBrush ( )
virtual

Implements QPdfBaseEngine.

Definition at line 253 of file qprintengine_pdf.cpp.

Referenced by drawImage(), drawPixmap(), drawTiledPixmap(), and printerState().

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 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
BrushStyle
Definition: qnamespace.h:1162
double qreal
Definition: qglobal.h:1193
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
#define Q_D(Class)
Definition: qglobal.h:2482
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019

◆ setDevice()

void QPdfEngine::setDevice ( QIODevice dev)

Referenced by printerState().

◆ type()

QPaintEngine::Type QPdfEngine::type ( ) const
virtual

Reimplement this function to return the paint engine Type.

Implements QPaintEngine.

Definition at line 286 of file qprintengine_pdf.cpp.

287 {
288  return QPaintEngine::Pdf;
289 }

Properties

◆ state

QPrinter::PrinterState QPdfEngine::state
private

Definition at line 120 of file qprintengine_pdf_p.h.

Referenced by begin(), end(), printerState(), and QPdfEngine().


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