Qt 4.8
Public Functions | Friends | List of all members
QWin32PrintEngine Class Reference

#include <qprintengine_win_p.h>

Inheritance diagram for QWin32PrintEngine:
QAlphaPaintEngine QPrintEngine QPaintEngine

Public Functions

bool abort ()
 Instructs the print engine to abort the printing process. More...
 
bool begin (QPaintDevice *dev)
 Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. More...
 
void drawPath (const QPainterPath &path)
 The default implementation ignores the path and does nothing. More...
 
void drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr)
 Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r. 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 drawTextItem (const QPointF &p, const QTextItem &textItem)
 This function draws the text item textItem at position p. More...
 
void drawTiledPixmap (const QRectF &r, const QPixmap &pm, const QPointF &p)
 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...
 
HDC getDC () const
 Empty default implementation. More...
 
HDC getPrinterDC () const
 
int metric (QPaintDevice::PaintDeviceMetric) const
 Returns the metric for the given id. 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...
 
QVariant property (PrintEnginePropertyKey key) const
 Returns the print engine's property specified by key. More...
 
 QWin32PrintEngine (QPrinter::PrinterMode mode)
 
void releaseDC (HDC) const
 Empty default implementation. More...
 
void releasePrinterDC (HDC dc) const
 
void setProperty (PrintEnginePropertyKey key, const QVariant &value)
 Sets the print engine's property specified by key to the given value. More...
 
QPaintEngine::Type type () const
 Reimplement this function to return the paint engine Type. More...
 
void updateClipPath (const QPainterPath &clip, Qt::ClipOperation op)
 
void updateMatrix (const QTransform &matrix)
 
void updateState (const QPaintEngineState &state)
 Reimplement this function to update the state of a paint engine. More...
 
- 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 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...
 
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 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...
 
virtual void drawPoints (const QPointF *points, int pointCount)
 Draws the first pointCount points in the buffer points. 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...
 
virtual void drawRects (const QRectF *rects, int rectCount)
 Draws the first rectCount rectangles in the buffer rects. More...
 
void fix_neg_rect (int *x, int *y, int *w, int *h)
 
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...
 
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 ~QPrintEngine ()
 Destroys the print engine. More...
 

Friends

class QPageSetupDialog
 
class QPrintDialog
 

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 70 of file qprintengine_win_p.h.

Constructors and Destructors

◆ QWin32PrintEngine()

QWin32PrintEngine::QWin32PrintEngine ( QPrinter::PrinterMode  mode)

Definition at line 162 of file qprintengine_win.cpp.

164  PaintEngineFeatures(PrimitiveTransform
167  | PainterPaths
168  | Antialiasing
170 {
172  d->docName = QLatin1String("document1");
173  d->mode = mode;
174  d->queryDefault();
175  d->initialize();
176 }
double d
Definition: qnumeric_p.h:62
QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482

Functions

◆ abort()

bool QWin32PrintEngine::abort ( )
virtual

Instructs the print engine to abort the printing process.

Returns true if successful; otherwise returns false.

Implements QPrintEngine.

Definition at line 328 of file qprintengine_win.cpp.

329 {
330  // do nothing loop.
331  return false;
332 }

◆ begin()

bool QWin32PrintEngine::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 QAlphaPaintEngine.

Definition at line 178 of file qprintengine_win.cpp.

179 {
181 
183  if (!continueCall())
184  return true;
185 
186  if (d->reinit) {
187  d->resetDC();
188  d->reinit = false;
189  }
190 
191  // ### set default colors and stuff...
192 
193  bool ok = d->state == QPrinter::Idle;
194 
195  if (!d->hdc)
196  return false;
197 
198  // Assign the FILE: to get the query...
199  if (d->printToFile && d->fileName.isEmpty())
200  d->fileName = d->port;
201 
202  d->devMode->dmCopies = d->num_copies;
203 
204  DOCINFO di;
205  memset(&di, 0, sizeof(DOCINFO));
206  di.cbSize = sizeof(DOCINFO);
207  di.lpszDocName = reinterpret_cast<const wchar_t *>(d->docName.utf16());
208  if (d->printToFile && !d->fileName.isEmpty())
209  di.lpszOutput = reinterpret_cast<const wchar_t *>(d->fileName.utf16());
210  if (ok && StartDoc(d->hdc, &di) == SP_ERROR) {
211  qErrnoWarning("QWin32PrintEngine::begin: StartDoc failed");
212  ok = false;
213  }
214 
215  if (StartPage(d->hdc) <= 0) {
216  qErrnoWarning("QWin32PrintEngine::begin: StartPage failed");
217  ok = false;
218  }
219 
220  if (!ok) {
221  d->state = QPrinter::Idle;
222  } else {
223  d->state = QPrinter::Active;
224  }
225 
226  d->matrix = QTransform();
227  d->has_pen = true;
228  d->pen = QColor(Qt::black);
229  d->has_brush = false;
230 
231  d->complex_xform = false;
232 
233  updateMatrix(d->matrix);
234 
235  if (!ok)
236  cleanUp();
237 
238  return ok;
239 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void updateMatrix(const QTransform &matrix)
virtual bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ drawPath()

void QWin32PrintEngine::drawPath ( const QPainterPath path)
virtual

The default implementation ignores the path and does nothing.

Reimplemented from QAlphaPaintEngine.

Definition at line 902 of file qprintengine_win.cpp.

Referenced by drawPolygon().

903 {
904 #ifdef QT_DEBUG_DRAW
905  qDebug() << " - QWin32PrintEngine::drawPath(), bounds: " << path.boundingRect();
906 #endif
907 
909 
911  if (!continueCall())
912  return;
913 
914  if (d->has_brush)
915  d->fillPath(path, d->brush_color);
916 
917  if (d->has_pen)
918  d->strokePath(path, d->pen.color());
919 }
double d
Definition: qnumeric_p.h:62
virtual void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
#define Q_D(Class)
Definition: qglobal.h:2482
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
Q_CORE_EXPORT void qDebug(const char *,...)

◆ drawPixmap()

void QWin32PrintEngine::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 616 of file qprintengine_win.cpp.

619 {
621 
622  QAlphaPaintEngine::drawPixmap(targetRect, originalPixmap, sourceRect);
623  if (!continueCall())
624  return;
625 
626  const int tileSize = 2048;
627 
628  QRectF r = targetRect;
629  QRectF sr = sourceRect;
630 
631  QPixmap pixmap = originalPixmap;
632  if (sr.size() != pixmap.size()) {
633  pixmap = pixmap.copy(sr.toRect());
634  }
635 
636  qreal scaleX = 1.0f;
637  qreal scaleY = 1.0f;
638 
639  QTransform scaleMatrix = QTransform::fromScale(r.width() / pixmap.width(), r.height() / pixmap.height());
640  QTransform adapted = QPixmap::trueMatrix(d->painterMatrix * scaleMatrix,
641  pixmap.width(), pixmap.height());
642 
643  qreal xform_offset_x = adapted.dx();
644  qreal xform_offset_y = adapted.dy();
645 
646  if (d->complex_xform) {
647  pixmap = pixmap.transformed(adapted);
648  scaleX = d->stretch_x;
649  scaleY = d->stretch_y;
650  } else {
651  scaleX = d->stretch_x * (r.width() / pixmap.width()) * d->painterMatrix.m11();
652  scaleY = d->stretch_y * (r.height() / pixmap.height()) * d->painterMatrix.m22();
653  }
654 
655  QPointF topLeft = r.topLeft() * d->painterMatrix;
656  int tx = int(topLeft.x() * d->stretch_x + d->origin_x);
657  int ty = int(topLeft.y() * d->stretch_y + d->origin_y);
658  int tw = qAbs(int(pixmap.width() * scaleX));
659  int th = qAbs(int(pixmap.height() * scaleY));
660 
661  xform_offset_x *= d->stretch_x;
662  xform_offset_y *= d->stretch_y;
663 
664  int dc_state = SaveDC(d->hdc);
665 
666  int tilesw = pixmap.width() / tileSize;
667  int tilesh = pixmap.height() / tileSize;
668  ++tilesw;
669  ++tilesh;
670 
671  int txinc = tileSize*scaleX;
672  int tyinc = tileSize*scaleY;
673 
674  for (int y = 0; y < tilesh; ++y) {
675  int tposy = ty + (y * tyinc);
676  int imgh = tileSize;
677  int height = tyinc;
678  if (y == (tilesh - 1)) {
679  imgh = pixmap.height() - (y * tileSize);
680  height = (th - (y * tyinc));
681  }
682  for (int x = 0; x < tilesw; ++x) {
683  int tposx = tx + (x * txinc);
684  int imgw = tileSize;
685  int width = txinc;
686  if (x == (tilesw - 1)) {
687  imgw = pixmap.width() - (x * tileSize);
688  width = (tw - (x * txinc));
689  }
690 
691  QPixmap p = pixmap.copy(tileSize * x, tileSize * y, imgw, imgh);
692  HBITMAP hbitmap = p.toWinHBITMAP(QPixmap::NoAlpha);
693  HDC display_dc = GetDC(0);
694  HDC hbitmap_hdc = CreateCompatibleDC(display_dc);
695  HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap);
696 
697  ReleaseDC(0, display_dc);
698 
699  if (!StretchBlt(d->hdc, qRound(tposx - xform_offset_x), qRound(tposy - xform_offset_y), width, height,
700  hbitmap_hdc, 0, 0, p.width(), p.height(), SRCCOPY))
701  qErrnoWarning("QWin32PrintEngine::drawPixmap, StretchBlt failed");
702 
703  SelectObject(hbitmap_hdc, null_bitmap);
704  DeleteObject(hbitmap);
705  DeleteDC(hbitmap_hdc);
706  }
707  }
708 
709  RestoreDC(d->hdc, dc_state);
710 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
static QMatrix trueMatrix(const QMatrix &m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with...
Definition: qpixmap.cpp:584
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
Definition: qpixmap.cpp:1723
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
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
HBITMAP toWinHBITMAP(HBitmapFormat format=NoAlpha) const
It is the caller&#39;s responsibility to free the HBITMAP data after use.
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
static const int tileSize
Definition: qmemrotate.cpp:47
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...

◆ drawPolygon()

void QWin32PrintEngine::drawPolygon ( const QPointF points,
int  pointCount,
PolygonDrawMode  mode 
)
virtual

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

Note
At least one of the drawPolygon() functions must be reimplemented.

Reimplemented from QAlphaPaintEngine.

Definition at line 922 of file qprintengine_win.cpp.

923 {
924 #ifdef QT_DEBUG_DRAW
925  qDebug() << " - QWin32PrintEngine::drawPolygon(), pointCount: " << pointCount;
926 #endif
927 
928  QAlphaPaintEngine::drawPolygon(points, pointCount, mode);
929  if (!continueCall())
930  return;
931 
932  Q_ASSERT(pointCount > 1);
933 
934  QPainterPath path(points[0]);
935 
936  for (int i=1; i<pointCount; ++i) {
937  path.lineTo(points[i]);
938  }
939 
941 
942  bool has_brush = d->has_brush;
943 
944  if (mode == PolylineMode)
945  d->has_brush = false; // No brush for polylines
946  else
947  path.closeSubpath(); // polygons are should always be closed.
948 
949  drawPath(path);
950  d->has_brush = has_brush;
951 }
double d
Definition: qnumeric_p.h:62
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.

◆ drawTextItem()

void QWin32PrintEngine::drawTextItem ( const QPointF p,
const QTextItem textItem 
)
virtual

This function draws the text item textItem at position p.

The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

Reimplemented from QAlphaPaintEngine.

Definition at line 334 of file qprintengine_win.cpp.

335 {
336  Q_D(const QWin32PrintEngine);
337 
338  QAlphaPaintEngine::drawTextItem(p, textItem);
339  if (!continueCall())
340  return;
341 
342  const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
343  QRgb brushColor = state->pen().brush().color().rgb();
344  bool fallBack = state->pen().brush().style() != Qt::SolidPattern
345  || qAlpha(brushColor) != 0xff
346  || d->txop >= QTransform::TxProject
347  || ti.fontEngine->type() != QFontEngine::Win;
348 
349 
350  if (!fallBack) {
351  QFontEngineWin *fe = static_cast<QFontEngineWin *>(ti.fontEngine);
352 
353  // Try selecting the font to see if we get a substitution font
354  SelectObject(d->hdc, fe->hfont);
355 
356  if (GetDeviceCaps(d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
357  wchar_t n[64];
358  GetTextFace(d->hdc, 64, n);
359  fallBack = QString::fromWCharArray(n)
360  != QString::fromWCharArray(fe->logfont.lfFaceName);
361  }
362  }
363 
364 
365  if (fallBack) {
366  QPaintEngine::drawTextItem(p, textItem);
367  return ;
368  }
369 
370  // We only want to convert the glyphs to text if the entire string is compatible with ASCII
371  // and if we actually have access to the chars.
372  bool convertToText = ti.chars != 0;
373  for (int i=0; i < ti.num_chars; ++i) {
374  if (ti.chars[i].unicode() >= 0x80) {
375  convertToText = false;
376  break;
377  }
378 
379  if (ti.logClusters[i] != i) {
380  convertToText = false;
381  break;
382  }
383  }
384 
385  COLORREF cf = RGB(qRed(brushColor), qGreen(brushColor), qBlue(brushColor));
386  SelectObject(d->hdc, CreateSolidBrush(cf));
387  SelectObject(d->hdc, CreatePen(PS_SOLID, 1, cf));
388  SetTextColor(d->hdc, cf);
389 
390  draw_text_item_win(p, ti, d->hdc, convertToText, d->matrix, d->devPaperRect.topLeft());
391  DeleteObject(SelectObject(d->hdc,GetStockObject(HOLLOW_BRUSH)));
392  DeleteObject(SelectObject(d->hdc,GetStockObject(BLACK_PEN)));
393 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
double d
Definition: qnumeric_p.h:62
QFontEngine * fontEngine
unsigned int QRgb
Definition: qrgb.h:53
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
const QChar * chars
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
QPaintEngineState * state
Definition: qpaintengine.h:239
static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc, bool convertToText, const QTransform &xform, const QPointF &topLeft)
const unsigned short * logClusters
#define Q_D(Class)
Definition: qglobal.h:2482
virtual Type type() const =0
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
Internal QTextItem.
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
return(isPopup||isToolTip)
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.

◆ drawTiledPixmap()

void QWin32PrintEngine::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 713 of file qprintengine_win.cpp.

714 {
716 
718  if (!continueCall())
719  return;
720 
721  if (d->complex_xform || !pos.isNull()) {
722  QPaintEngine::drawTiledPixmap(r, pm, pos);
723  } else {
724  int dc_state = SaveDC(d->hdc);
725 
726  HDC display_dc = GetDC(0);
727  HBITMAP hbitmap = pm.toWinHBITMAP(QPixmap::NoAlpha);
728  HDC hbitmap_hdc = CreateCompatibleDC(display_dc);
729  HGDIOBJ null_bitmap = SelectObject(hbitmap_hdc, hbitmap);
730 
731  ReleaseDC(0, display_dc);
732 
733  QRectF trect = d->painterMatrix.mapRect(r);
734  int tx = int(trect.left() * d->stretch_x + d->origin_x);
735  int ty = int(trect.top() * d->stretch_y + d->origin_y);
736 
737  int xtiles = int(trect.width() / pm.width()) + 1;
738  int ytiles = int(trect.height() / pm.height()) + 1;
739  int xinc = int(pm.width() * d->stretch_x);
740  int yinc = int(pm.height() * d->stretch_y);
741 
742  for (int y = 0; y < ytiles; ++y) {
743  int ity = ty + (yinc * y);
744  int ith = pm.height();
745  if (y == (ytiles - 1)) {
746  ith = int(trect.height() - (pm.height() * y));
747  }
748 
749  for (int x = 0; x < xtiles; ++x) {
750  int itx = tx + (xinc * x);
751  int itw = pm.width();
752  if (x == (xtiles - 1)) {
753  itw = int(trect.width() - (pm.width() * x));
754  }
755 
756  if (!StretchBlt(d->hdc, itx, ity, int(itw * d->stretch_x), int(ith * d->stretch_y),
757  hbitmap_hdc, 0, 0, itw, ith, SRCCOPY))
758  qErrnoWarning("QWin32PrintEngine::drawPixmap, StretchBlt failed");
759 
760  }
761  }
762 
763  SelectObject(hbitmap_hdc, null_bitmap);
764  DeleteObject(hbitmap);
765  DeleteDC(hbitmap_hdc);
766 
767  RestoreDC(d->hdc, dc_state);
768  }
769 }
double d
Definition: qnumeric_p.h:62
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ end()

bool QWin32PrintEngine::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 QAlphaPaintEngine.

Definition at line 241 of file qprintengine_win.cpp.

242 {
244 
245  if (d->hdc) {
246  if (d->state == QPrinter::Aborted) {
247  cleanUp();
248  AbortDoc(d->hdc);
249  return true;
250  }
251  }
252 
254  if (!continueCall())
255  return true;
256 
257  if (d->hdc) {
258  EndPage(d->hdc); // end; printing done
259  EndDoc(d->hdc);
260  }
261 
262  d->state = QPrinter::Idle;
263  d->reinit = true;
264  return true;
265 }
double d
Definition: qnumeric_p.h:62
virtual bool end()
Reimplement this function to finish painting on the current paint device.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ getDC()

HDC QWin32PrintEngine::getDC ( ) const
virtual

Empty default implementation.

Warning
This function is not part of the public interface.

Reimplemented from QPaintEngine.

Definition at line 1560 of file qprintengine_win.cpp.

Referenced by getPrinterDC(), and type().

1561 {
1562  return d_func()->hdc;
1563 }

◆ getPrinterDC()

HDC QWin32PrintEngine::getPrinterDC ( ) const
inlinevirtual
Warning
This function is not part of the public interface.

Reimplemented from QPrintEngine.

Definition at line 105 of file qprintengine_win_p.h.

105 { return getDC(); }
HDC getDC() const
Empty default implementation.

◆ metric()

int QWin32PrintEngine::metric ( QPaintDevice::PaintDeviceMetric  id) const
virtual

Returns the metric for the given id.

Implements QPrintEngine.

Definition at line 405 of file qprintengine_win.cpp.

406 {
407  Q_D(const QWin32PrintEngine);
408 
409  if (!d->hdc)
410  return 0;
411 
412  int val;
413  int res = d->resolution;
414 
415  switch (m) {
417  if (d->has_custom_paper_size) {
418  val = qRound(d->paper_size.width() * res / 72.0);
419  } else {
420  int logPixelsX = GetDeviceCaps(d->hdc, LOGPIXELSX);
421  if (logPixelsX == 0) {
422  qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
423  "might be a driver problem");
424  logPixelsX = 600; // Reasonable default
425  }
426  val = res
427  * GetDeviceCaps(d->hdc, d->fullPage ? PHYSICALWIDTH : HORZRES)
428  / logPixelsX;
429  }
430  if (d->pageMarginsSet)
431  val -= int(mmToInches((d->previousDialogMargins.left() +
432  d->previousDialogMargins.width()) / 100.0) * res);
433  break;
435  if (d->has_custom_paper_size) {
436  val = qRound(d->paper_size.height() * res / 72.0);
437  } else {
438  int logPixelsY = GetDeviceCaps(d->hdc, LOGPIXELSY);
439  if (logPixelsY == 0) {
440  qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
441  "might be a driver problem");
442  logPixelsY = 600; // Reasonable default
443  }
444  val = res
445  * GetDeviceCaps(d->hdc, d->fullPage ? PHYSICALHEIGHT : VERTRES)
446  / logPixelsY;
447  }
448  if (d->pageMarginsSet)
449  val -= int(mmToInches((d->previousDialogMargins.top() +
450  d->previousDialogMargins.height()) / 100.0) * res);
451  break;
453  val = res;
454  break;
456  val = res;
457  break;
459  val = GetDeviceCaps(d->hdc, LOGPIXELSX);
460  break;
462  val = GetDeviceCaps(d->hdc, LOGPIXELSY);
463  break;
465  if (d->has_custom_paper_size) {
466  val = qRound(d->paper_size.width()*25.4/72);
467  } else {
468  if (!d->fullPage) {
469  val = GetDeviceCaps(d->hdc, HORZSIZE);
470  } else {
471  float wi = 25.4 * GetDeviceCaps(d->hdc, PHYSICALWIDTH);
472  int logPixelsX = GetDeviceCaps(d->hdc, LOGPIXELSX);
473  if (logPixelsX == 0) {
474  qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
475  "might be a driver problem");
476  logPixelsX = 600; // Reasonable default
477  }
478  val = qRound(wi / logPixelsX);
479  }
480  }
481  if (d->pageMarginsSet)
482  val -= (d->previousDialogMargins.left() +
483  d->previousDialogMargins.width()) / 100.0;
484  break;
486  if (d->has_custom_paper_size) {
487  val = qRound(d->paper_size.height()*25.4/72);
488  } else {
489  if (!d->fullPage) {
490  val = GetDeviceCaps(d->hdc, VERTSIZE);
491  } else {
492  float hi = 25.4 * GetDeviceCaps(d->hdc, PHYSICALHEIGHT);
493  int logPixelsY = GetDeviceCaps(d->hdc, LOGPIXELSY);
494  if (logPixelsY == 0) {
495  qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
496  "might be a driver problem");
497  logPixelsY = 600; // Reasonable default
498  }
499  val = qRound(hi / logPixelsY);
500  }
501  }
502  if (d->pageMarginsSet)
503  val -= (d->previousDialogMargins.top() +
504  d->previousDialogMargins.height()) / 100.0;
505  break;
507  {
508  int bpp = GetDeviceCaps(d->hdc, BITSPIXEL);
509  if(bpp==32)
510  val = INT_MAX;
511  else if(bpp<=8)
512  val = GetDeviceCaps(d->hdc, NUMCOLORS);
513  else
514  val = 1 << (bpp * GetDeviceCaps(d->hdc, PLANES));
515  }
516  break;
518  val = GetDeviceCaps(d->hdc, PLANES);
519  break;
520  default:
521  qWarning("QPrinter::metric: Invalid metric command");
522  return 0;
523  }
524  return val;
525 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
static qreal mmToInches(double mm)
#define INT_MAX
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ newPage()

bool QWin32PrintEngine::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.

Implements QPrintEngine.

Definition at line 267 of file qprintengine_win.cpp.

268 {
270  Q_ASSERT(isActive());
271 
272  Q_ASSERT(d->hdc);
273 
274  flushAndInit();
275 
276  bool transparent = GetBkMode(d->hdc) == TRANSPARENT;
277 
278  if (!EndPage(d->hdc)) {
279  qErrnoWarning("QWin32PrintEngine::newPage: EndPage failed");
280  return false;
281  }
282 
283  if (d->reinit) {
284  if (!d->resetDC()) {
285  qErrnoWarning("QWin32PrintEngine::newPage: ResetDC failed");
286  return false;
287  }
288  d->reinit = false;
289  }
290 
291  if (!StartPage(d->hdc)) {
292  qErrnoWarning("Win32PrintEngine::newPage: StartPage failed");
293  return false;
294  }
295 
296  SetTextAlign(d->hdc, TA_BASELINE);
297  if (transparent)
298  SetBkMode(d->hdc, TRANSPARENT);
299 
300  // ###
301  return true;
302 
303  bool success = false;
304  if (d->hdc && d->state == QPrinter::Active) {
305  if (EndPage(d->hdc) != SP_ERROR) {
306  // reinitialize the DC before StartPage if needed,
307  // because resetdc is disabled between calls to the StartPage and EndPage functions
308  // (see StartPage documentation in the Platform SDK:Windows GDI)
309 // state = PST_ACTIVEDOC;
310 // reinit();
311 // state = PST_ACTIVE;
312  // start the new page now
313  if (d->reinit) {
314  if (!d->resetDC())
315  qErrnoWarning("QWin32PrintEngine::newPage(), ResetDC failed (2)");
316  d->reinit = false;
317  }
318  success = (StartPage(d->hdc) != SP_ERROR);
319  }
320  if (!success) {
321  d->state = QPrinter::Aborted;
322  return false;
323  }
324  }
325  return true;
326 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
void flushAndInit(bool init=true)
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ printerState()

QPrinter::PrinterState QWin32PrintEngine::printerState ( ) const
virtual

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

Implements QPrintEngine.

Definition at line 1555 of file qprintengine_win.cpp.

1556 {
1557  return d_func()->state;
1558 }

◆ property()

QVariant QWin32PrintEngine::property ( PrintEnginePropertyKey  key) const
virtual

Returns the print engine's property specified by key.

See also
setProperty()

Implements QPrintEngine.

Definition at line 1384 of file qprintengine_win.cpp.

Referenced by setProperty().

1385 {
1386  Q_D(const QWin32PrintEngine);
1387  QVariant value;
1388  switch (key) {
1389 
1390  case PPK_CollateCopies:
1391  value = false;
1392  break;
1393 
1394  case PPK_ColorMode:
1395  {
1396  if (!d->devMode) {
1397  value = QPrinter::Color;
1398  } else {
1399  value = (d->devMode->dmColor == DMCOLOR_COLOR) ? QPrinter::Color : QPrinter::GrayScale;
1400  }
1401  }
1402  break;
1403 
1404  case PPK_DocumentName:
1405  value = d->docName;
1406  break;
1407 
1408  case PPK_FullPage:
1409  value = d->fullPage;
1410  break;
1411 
1412  case PPK_CopyCount:
1413  value = d->num_copies;
1414  break;
1415 
1417  value = true;
1418  break;
1419 
1420  case PPK_NumberOfCopies:
1421  value = 1;
1422  break;
1423 
1424  case PPK_Orientation:
1425  {
1426  if (!d->devMode) {
1427  value = QPrinter::Portrait;
1428  } else {
1429  value = (d->devMode->dmOrientation == DMORIENT_LANDSCAPE) ? QPrinter::Landscape : QPrinter::Portrait;
1430  }
1431  }
1432  break;
1433 
1434  case PPK_OutputFileName:
1435  value = d->fileName;
1436  break;
1437 
1438  case PPK_PageRect:
1439  if (d->has_custom_paper_size) {
1440  QRect rect(0, 0,
1441  qRound(d->paper_size.width() * d->resolution / 72.0),
1442  qRound(d->paper_size.height() * d->resolution / 72.0));
1443  if (d->pageMarginsSet) {
1444  rect = rect.adjusted(qRound(mmToInches(d->previousDialogMargins.left()/100.0) * d->resolution),
1445  qRound(mmToInches(d->previousDialogMargins.top()/100.0) * d->resolution),
1446  -qRound(mmToInches(d->previousDialogMargins.width()/100.0) * d->resolution),
1447  -qRound(mmToInches(d->previousDialogMargins.height()/100.0) * d->resolution));
1448  }
1449  value = rect;
1450  } else {
1451  value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0)
1452  .mapRect(d->fullPage ? d->devPhysicalPageRect : d->devPageRect);
1453  }
1454  break;
1455 
1456  case PPK_PaperSize:
1457  if (d->has_custom_paper_size) {
1458  value = QPrinter::Custom;
1459  } else {
1460  if (!d->devMode) {
1461  value = QPrinter::A4;
1462  } else {
1463  value = mapDevmodePaperSize(d->devMode->dmPaperSize);
1464  }
1465  }
1466  break;
1467 
1468  case PPK_PaperRect:
1469  if (d->has_custom_paper_size) {
1470  value = QRect(0, 0,
1471  qRound(d->paper_size.width() * d->resolution / 72.0),
1472  qRound(d->paper_size.height() * d->resolution / 72.0));
1473  } else {
1474  value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0).mapRect(d->devPaperRect);
1475  }
1476  break;
1477 
1478  case PPK_PaperSource:
1479  if (!d->devMode) {
1480  value = QPrinter::Auto;
1481  } else {
1482  value = mapDevmodePaperSource(d->devMode->dmDefaultSource);
1483  }
1484  break;
1485 
1486  case PPK_PrinterName:
1487  value = d->name;
1488  break;
1489 
1490  case PPK_Resolution:
1491  if (d->resolution || !d->name.isEmpty())
1492  value = d->resolution;
1493  break;
1494 
1496  value = d->queryResolutions();
1497  break;
1498 
1499  case PPK_WindowsPageSize:
1500  if (!d->devMode) {
1501  value = -1;
1502  } else {
1503  value = d->devMode->dmPaperSize;
1504  }
1505  break;
1506 
1507  case PPK_PaperSources:
1508  {
1509  int available = DeviceCapabilities((const wchar_t *)d->name.utf16(),
1510  (const wchar_t *)d->port.utf16(), DC_BINS, 0, d->devMode);
1511 
1512  if (available <= 0)
1513  break;
1514 
1515  wchar_t *data = new wchar_t[available];
1516  int count = DeviceCapabilities((const wchar_t *)d->name.utf16(),
1517  (const wchar_t *)d->port.utf16(), DC_BINS, data, d->devMode);
1518 
1519  QList<QVariant> out;
1520  for (int i=0; i<count; ++i) {
1522  if (src != -1)
1523  out << (int) src;
1524  }
1525  value = out;
1526 
1527  delete [] data;
1528  }
1529  break;
1530 
1531  case PPK_CustomPaperSize:
1532  value = d->paper_size;
1533  break;
1534 
1535  case PPK_PageMargins:
1536  {
1537  QList<QVariant> margins;
1538  QRect pageMargins(d->getPageMargins());
1539 
1540  // specified in 1/100 mm
1541  margins << (mmToInches(pageMargins.left()/100.0) * 72)
1542  << (mmToInches(pageMargins.top()/100.0) * 72)
1543  << (mmToInches(pageMargins.width()/100.0) * 72)
1544  << (mmToInches(pageMargins.height()/100.0) * 72);
1545  value = margins;
1546  break;
1547  }
1548  default:
1549  // Do nothing
1550  break;
1551  }
1552  return value;
1553 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
static QPrinter::PaperSource mapDevmodePaperSource(int s)
#define Q_D(Class)
Definition: qglobal.h:2482
QPrinter::PaperSize mapDevmodePaperSize(int s)
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
static const char * data(const QByteArray &arr)
int key
static qreal mmToInches(double mm)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ releaseDC()

void QWin32PrintEngine::releaseDC ( HDC  hdc) const
virtual

Empty default implementation.

Warning
This function is not part of the public interface.

Reimplemented from QPaintEngine.

Definition at line 1565 of file qprintengine_win.cpp.

Referenced by releasePrinterDC(), and type().

1566 {
1567 
1568 }

◆ releasePrinterDC()

void QWin32PrintEngine::releasePrinterDC ( HDC  ) const
inlinevirtual
Warning
This function is not part of the public interface.

Reimplemented from QPrintEngine.

Definition at line 106 of file qprintengine_win_p.h.

106 { releaseDC(dc); }
void releaseDC(HDC) const
Empty default implementation.

◆ setProperty()

void QWin32PrintEngine::setProperty ( PrintEnginePropertyKey  key,
const QVariant value 
)
virtual

Sets the print engine's property specified by key to the given value.

See also
property()

Implements QPrintEngine.

Definition at line 1206 of file qprintengine_win.cpp.

1207 {
1209  switch (key) {
1210  case PPK_CollateCopies:
1211  {
1212  if (!d->devMode)
1213  break;
1214  d->devMode->dmCollate = value.toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
1215  d->doReinit();
1216  }
1217  break;
1218 
1219  case PPK_ColorMode:
1220  {
1221  if (!d->devMode)
1222  break;
1223  d->devMode->dmColor = (value.toInt() == QPrinter::Color) ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
1224  d->doReinit();
1225  }
1226  break;
1227 
1228  case PPK_Creator:
1229 
1230  break;
1231 
1232  case PPK_DocumentName:
1233  if (isActive()) {
1234  qWarning("QWin32PrintEngine: Cannot change document name while printing is active");
1235  return;
1236  }
1237  d->docName = value.toString();
1238  break;
1239 
1240  case PPK_FullPage:
1241  d->fullPage = value.toBool();
1242  d->updateOrigin();
1243  break;
1244 
1245  case PPK_CopyCount: // fallthrough
1246  case PPK_NumberOfCopies:
1247  if (!d->devMode)
1248  break;
1249  d->num_copies = value.toInt();
1250  d->devMode->dmCopies = d->num_copies;
1251  d->doReinit();
1252  break;
1253 
1254  case PPK_Orientation:
1255  {
1256  if (!d->devMode)
1257  break;
1258  int orientation = value.toInt() == QPrinter::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
1259  int old_orientation = d->devMode->dmOrientation;
1260  d->devMode->dmOrientation = orientation;
1261  if (d->has_custom_paper_size && old_orientation != orientation)
1262  d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width());
1263  d->doReinit();
1264  }
1265  break;
1266 
1267  case PPK_OutputFileName:
1268  if (isActive()) {
1269  qWarning("QWin32PrintEngine: Cannot change filename while printing");
1270  } else {
1271  d->fileName = value.toString();
1272  d->printToFile = !value.toString().isEmpty();
1273  }
1274  break;
1275 
1276  case PPK_PaperSize:
1277  if (!d->devMode)
1278  break;
1279  d->devMode->dmPaperSize = mapPaperSizeDevmode(QPrinter::PaperSize(value.toInt()));
1280  d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom);
1281  d->doReinit();
1282  break;
1283 
1284  case PPK_PaperSource:
1285  {
1286  if (!d->devMode)
1287  break;
1288  int dmMapped = DMBIN_AUTO;
1289 
1291  if (v.contains(value))
1292  dmMapped = mapPaperSourceDevmode(QPrinter::PaperSource(value.toInt()));
1293 
1294  d->devMode->dmDefaultSource = dmMapped;
1295  d->doReinit();
1296  }
1297  break;
1298 
1299  case PPK_PrinterName:
1300  d->name = value.toString();
1301  if(d->name.isEmpty())
1302  d->queryDefault();
1303  d->initialize();
1304  break;
1305 
1306  case PPK_Resolution:
1307  {
1308  d->resolution = value.toInt();
1309 
1310  d->stretch_x = d->dpi_x / double(d->resolution);
1311  d->stretch_y = d->dpi_y / double(d->resolution);
1312  }
1313  break;
1314 
1315  case PPK_SelectionOption:
1316 
1317  break;
1318 
1320 
1321  break;
1322 
1323 
1324  case PPK_WindowsPageSize:
1325  if (!d->devMode)
1326  break;
1327  d->has_custom_paper_size = false;
1328  d->devMode->dmPaperSize = value.toInt();
1329  d->doReinit();
1330  break;
1331 
1332  case PPK_CustomPaperSize:
1333  {
1334  d->has_custom_paper_size = true;
1335  d->paper_size = value.toSizeF();
1336  if (!d->devMode)
1337  break;
1338  int orientation = d->devMode->dmOrientation;
1339  DWORD needed = 0;
1340  DWORD returned = 0;
1341  if (!EnumForms(d->hPrinter, 1, 0, 0, &needed, &returned)) {
1342  BYTE *forms = (BYTE *) malloc(needed);
1343  if (EnumForms(d->hPrinter, 1, forms, needed, &needed, &returned)) {
1344  for (DWORD i=0; i< returned; ++i) {
1345  FORM_INFO_1 *formArray = reinterpret_cast<FORM_INFO_1 *>(forms);
1346  // the form sizes are specified in 1000th of a mm,
1347  // convert the size to Points
1348  QSizeF size((formArray[i].Size.cx * 72/25.4)/1000.0,
1349  (formArray[i].Size.cy * 72/25.4)/1000.0);
1350  if (qAbs(d->paper_size.width() - size.width()) <= 2
1351  && qAbs(d->paper_size.height() - size.height()) <= 2)
1352  {
1353  d->devMode->dmPaperSize = i + 1;
1354  break;
1355  }
1356  }
1357  }
1358  free(forms);
1359  }
1360  if (orientation != DMORIENT_PORTRAIT)
1361  d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width());
1362  break;
1363  }
1364 
1365  case PPK_PageMargins:
1366  {
1367  QList<QVariant> margins(value.toList());
1368  Q_ASSERT(margins.size() == 4);
1369  int left, top, right, bottom;
1370  // specified in 1/100 mm
1371  left = (margins.at(0).toReal()*25.4/72.0) * 100;
1372  top = (margins.at(1).toReal()*25.4/72.0) * 100;
1373  right = (margins.at(2).toReal()*25.4/72.0) * 100;
1374  bottom = (margins.at(3).toReal()*25.4/72.0) * 100;
1375  d->setPageMargins(left, top, right, bottom);
1376  break;
1377  }
1378  default:
1379  // Do nothing
1380  break;
1381  }
1382 }
double d
Definition: qnumeric_p.h:62
#define BYTE
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine&#39;s property specified by key.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static int mapPaperSizeDevmode(QPrinter::PaperSize s)
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
Definition: qvariant.cpp:2447
static int mapPaperSourceDevmode(QPrinter::PaperSource s)
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
int key
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103

◆ type()

QPaintEngine::Type QWin32PrintEngine::type ( ) const
inlinevirtual

Reimplement this function to return the paint engine Type.

Implements QPaintEngine.

Definition at line 100 of file qprintengine_win_p.h.

100 { return Windows; }

◆ updateClipPath()

void QWin32PrintEngine::updateClipPath ( const QPainterPath clip,
Qt::ClipOperation  op 
)

Definition at line 568 of file qprintengine_win.cpp.

Referenced by updateState().

569 {
571 
572  bool doclip = true;
573  if (op == Qt::NoClip) {
574  SelectClipRgn(d->hdc, 0);
575  doclip = false;
576  }
577 
578  if (doclip) {
579  QPainterPath xformed = clipPath * d->matrix;
580 
581  if (xformed.isEmpty()) {
582  QRegion empty(-0x1000000, -0x1000000, 1, 1);
583  SelectClipRgn(d->hdc, empty.handle());
584  } else {
585  d->composeGdiPath(xformed);
586  const int ops[] = {
587  -1, // Qt::NoClip, covered above
588  RGN_COPY, // Qt::ReplaceClip
589  RGN_AND, // Qt::IntersectClip
590  RGN_OR // Qt::UniteClip
591  };
592  Q_ASSERT(op > 0 && unsigned(op) <= sizeof(ops) / sizeof(int));
593  SelectClipPath(d->hdc, ops[op]);
594  }
595  }
596 
598  if (!aclip.isEmpty()) {
599  QTransform tx(d->stretch_x, 0, 0, d->stretch_y, d->origin_x, d->origin_y);
600  d->composeGdiPath(tx.map(aclip));
601  SelectClipPath(d->hdc, RGN_DIFF);
602  }
603 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
QRegion alphaClipping() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ updateMatrix()

void QWin32PrintEngine::updateMatrix ( const QTransform matrix)

Definition at line 605 of file qprintengine_win.cpp.

Referenced by begin(), and updateState().

606 {
608 
609  QTransform stretch(d->stretch_x, 0, 0, d->stretch_y, d->origin_x, d->origin_y);
610  d->painterMatrix = m;
611  d->matrix = d->painterMatrix * stretch;
612  d->txop = d->matrix.type();
613  d->complex_xform = (d->txop > QTransform::TxScale);
614 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ updateState()

void QWin32PrintEngine::updateState ( const QPaintEngineState state)
virtual

Reimplement this function to update the state of a paint engine.

When implemented, this function is responsible for checking the paint engine's current state and update the properties that are changed. Use the QPaintEngineState::state() function to find out which properties that must be updated, then use the corresponding GetFunction{get function} to retrieve the current values for the given properties.

See also
QPaintEngineState

Reimplemented from QAlphaPaintEngine.

Definition at line 527 of file qprintengine_win.cpp.

528 {
530 
532  if (!continueCall())
533  return;
534 
535  if (state.state() & DirtyTransform) {
536  updateMatrix(state.transform());
537  }
538 
539  if (state.state() & DirtyPen) {
540  d->pen = state.pen();
541  d->has_pen = d->pen.style() != Qt::NoPen && d->pen.isSolid();
542  }
543 
544  if (state.state() & DirtyBrush) {
545  QBrush brush = state.brush();
546  d->has_brush = brush.style() == Qt::SolidPattern;
547  d->brush_color = brush.color();
548  }
549 
550  if (state.state() & DirtyClipEnabled) {
551  if (state.isClipEnabled())
553  else
555  }
556 
557  if (state.state() & DirtyClipPath) {
558  updateClipPath(state.clipPath(), state.clipOperation());
559  }
560 
561  if (state.state() & DirtyClipRegion) {
562  QRegion clipRegion = state.clipRegion();
563  QPainterPath clipPath = qt_regionToPath(clipRegion);
564  updateClipPath(clipPath, state.clipOperation());
565  }
566 }
QPainterPath clipPath() const
Returns the currently clip as a path.
Definition: qpainter.cpp:2690
double d
Definition: qnumeric_p.h:62
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
Definition: qpaintengine.h:292
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QTransform transform() const
Returns the matrix in the current paint engine state.
Definition: qpainter.cpp:9377
bool isClipEnabled() const
Returns whether clipping is enabled or not in the current paint engine state.
Definition: qpainter.cpp:9473
#define Q_D(Class)
Definition: qglobal.h:2482
void updateMatrix(const QTransform &matrix)
QPainter * painter() const
Returns the paint engine&#39;s painter.
QBrush brush() const
Returns the brush in the current paint engine state.
Definition: qpainter.cpp:9273
Qt::ClipOperation clipOperation() const
Returns the clip operation in the current paint engine state.
Definition: qpainter.cpp:9396
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPainterPath clipPath() const
Returns the clip path in the current paint engine state.
Definition: qpainter.cpp:9457
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op)
QRegion clipRegion() const
Returns the clip region in the current paint engine state.
Definition: qpainter.cpp:9443
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
virtual void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.

Friends and Related Functions

◆ QPageSetupDialog

friend class QPageSetupDialog
friend

Definition at line 110 of file qprintengine_win_p.h.

◆ QPrintDialog

friend class QPrintDialog
friend

Definition at line 109 of file qprintengine_win_p.h.


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