Qt 4.8
Public Functions | Public Variables | List of all members
QWin32PrintEnginePrivate Class Reference

#include <qprintengine_win_p.h>

Inheritance diagram for QWin32PrintEnginePrivate:
QAlphaPaintEnginePrivate QPaintEnginePrivate

Public Functions

void composeGdiPath (const QPainterPath &path)
 
HGLOBAL * createDevNames ()
 
void doReinit ()
 
void fillPath (const QPainterPath &path, const QColor &color)
 
void fillPath_dev (const QPainterPath &path, const QColor &color)
 
QRect getPageMargins () const
 
void initDevRects ()
 
void initHDC ()
 
void initialize ()
 
void queryDefault ()
 
QList< QVariantqueryResolutions () const
 
 QWin32PrintEnginePrivate ()
 
void readDevmode (HGLOBAL globalDevmode)
 
void readDevnames (HGLOBAL globalDevnames)
 
void release ()
 
bool resetDC ()
 
void setPageMargins (int margin_left, int margin_top, int margin_right, int margin_bottom)
 
void strokePath (const QPainterPath &path, const QColor &color)
 
void strokePath_dev (const QPainterPath &path, const QColor &color, qreal width)
 
void updateCustomPaperSize ()
 
void updateOrigin ()
 
 ~QWin32PrintEnginePrivate ()
 
- Public Functions inherited from QAlphaPaintEnginePrivate
void addAlphaRect (const QRectF &rect)
 
QRectF addPenWidth (const QPainterPath &path)
 
void drawAlphaImage (const QRectF &rect)
 
bool fullyContained (const QRectF &rect) const
 
 QAlphaPaintEnginePrivate ()
 
void resetState (QPainter *p)
 
QRect toRect (const QRectF &rect) const
 
 ~QAlphaPaintEnginePrivate ()
 
- Public Functions inherited from QPaintEnginePrivate
void drawBoxTextItem (const QPointF &p, const QTextItemInt &ti)
 
 QPaintEnginePrivate ()
 
void setSystemTransform (const QTransform &xform)
 
void setSystemViewport (const QRegion &region)
 
virtual void systemStateChanged ()
 
void transformSystemClip ()
 
virtual ~QPaintEnginePrivate ()
 

Public Variables

QColor brush_color
 
uint complex_xform: 1
 
DEVMODE * devMode
 
QRect devPageRect
 
QRect devPaperRect
 
QRect devPhysicalPageRect
 
QString docName
 
int dpi_display
 
int dpi_x
 
int dpi_y
 
QString fileName
 
uint fullPage: 1
 
HGLOBAL globalDevMode
 
uint has_brush: 1
 
uint has_custom_paper_size: 1
 
uint has_pen: 1
 
HDC hdc
 
HGLOBAL hMem
 
HANDLE hPrinter
 
QTransform matrix
 
QPrinter::PrinterMode mode
 
QString name
 
int num_copies
 
int origin_x
 
int origin_y
 
bool pageMarginsSet
 
QTransform painterMatrix
 
QSizeF paper_size
 
QPen pen
 
QColor pen_color
 
PRINTER_INFO_2 * pInfo
 
QString port
 
QRect previousDialogMargins
 
uint printToFile: 1
 
QString program
 
uint reinit: 1
 
int resolution
 
QPrinter::PrinterState state
 
qreal stretch_x
 
qreal stretch_y
 
uint txop
 
- Public Variables inherited from QAlphaPaintEnginePrivate
bool m_advancedBrush
 
bool m_advancedPen
 
bool m_alphaBrush
 
bool m_alphaOpacity
 
bool m_alphaPen
 
QRegion m_alphargn
 
QRegion m_cliprgn
 
bool m_complexTransform
 
bool m_continueCall
 
bool m_emulateProjectiveTransforms
 
bool m_hasalpha
 
int m_pass
 
QPaintDevicem_pdev
 
QPen m_pen
 
QPicturem_pic
 
QPaintEnginem_picengine
 
QPainterm_picpainter
 
QPaintEngine::PaintEngineFeatures m_savedcaps
 
QTransform m_transform
 
- Public Variables inherited from QPaintEnginePrivate
QWidgetcurrentClipWidget
 
uint hasSystemTransform: 1
 
uint hasSystemViewport: 1
 
QPaintDevicepdev
 
QPaintEngineq_ptr
 
QRegion systemClip
 
QRect systemRect
 
QTransform systemTransform
 
QRegion systemViewport
 

Detailed Description

Definition at line 113 of file qprintengine_win_p.h.

Constructors and Destructors

◆ QWin32PrintEnginePrivate()

QWin32PrintEnginePrivate::QWin32PrintEnginePrivate ( )
inline

Definition at line 117 of file qprintengine_win_p.h.

117  :
118  hPrinter(0),
119  globalDevMode(0),
120  devMode(0),
121  pInfo(0),
122  hdc(0),
125  resolution(0),
126  pageMarginsSet(false),
127  num_copies(1),
128  printToFile(false),
129  fullPage(false),
130  reinit(false),
131  has_custom_paper_size(false)
132  {
133  }
QPrinter::PrinterMode mode
QPrinter::PrinterState state

◆ ~QWin32PrintEnginePrivate()

QWin32PrintEnginePrivate::~QWin32PrintEnginePrivate ( )

Definition at line 979 of file qprintengine_win.cpp.

980 {
981  if (hdc)
982  release();
983 }

Functions

◆ composeGdiPath()

void QWin32PrintEnginePrivate::composeGdiPath ( const QPainterPath path)

Definition at line 772 of file qprintengine_win.cpp.

773 {
774  if (!BeginPath(hdc))
775  qErrnoWarning("QWin32PrintEnginePrivate::drawPath: BeginPath failed");
776 
777  // Drawing the subpaths
778  int start = -1;
779  for (int i=0; i<path.elementCount(); ++i) {
780  const QPainterPath::Element &elm = path.elementAt(i);
781  switch (elm.type) {
783  if (start >= 0
784  && path.elementAt(start).x == path.elementAt(i-1).x
785  && path.elementAt(start).y == path.elementAt(i-1).y)
786  CloseFigure(hdc);
787  start = i;
788  MoveToEx(hdc, qRound(elm.x), qRound(elm.y), 0);
789  break;
791  LineTo(hdc, qRound(elm.x), qRound(elm.y));
792  break;
794  POINT pts[3] = {
795  { qRound(elm.x), qRound(elm.y) },
796  { qRound(path.elementAt(i+1).x), qRound(path.elementAt(i+1).y) },
797  { qRound(path.elementAt(i+2).x), qRound(path.elementAt(i+2).y) }
798  };
799  i+=2;
800  PolyBezierTo(hdc, pts, 3);
801  break;
802  }
803  default:
804  qFatal("QWin32PaintEngine::drawPath: Unhandled type: %d", elm.type);
805  }
806  }
807 
808  if (start >= 0
809  && path.elementAt(start).x == path.elementAt(path.elementCount()-1).x
810  && path.elementAt(start).y == path.elementAt(path.elementCount()-1).y)
811  CloseFigure(hdc);
812 
813  if (!EndPath(hdc))
814  qErrnoWarning("QWin32PaintEngine::drawPath: EndPath failed");
815 
816  SetPolyFillMode(hdc, path.fillRule() == Qt::WindingFill ? WINDING : ALTERNATE);
817 }
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
#define WINDING
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define ALTERNATE
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
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
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ createDevNames()

HGLOBAL * QWin32PrintEnginePrivate::createDevNames ( )

Definition at line 1570 of file qprintengine_win.cpp.

1571 {
1572  int size = sizeof(DEVNAMES)
1573  + program.length() * 2 + 2
1574  + name.length() * 2 + 2
1575  + port.length() * 2 + 2;
1576  HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size);
1577  DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
1578 
1579  dn->wDriverOffset = sizeof(DEVNAMES) / sizeof(wchar_t);
1580  dn->wDeviceOffset = dn->wDriverOffset + program.length() + 1;
1581  dn->wOutputOffset = dn->wDeviceOffset + name.length() + 1;
1582 
1583  memcpy((ushort*)dn + dn->wDriverOffset, program.utf16(), program.length() * 2 + 2);
1584  memcpy((ushort*)dn + dn->wDeviceOffset, name.utf16(), name.length() * 2 + 2);
1585  memcpy((ushort*)dn + dn->wOutputOffset, port.utf16(), port.length() * 2 + 2);
1586  dn->wDefault = 0;
1587 
1588  GlobalUnlock(hGlobal);
1589 
1590 // printf("QPrintDialogWinPrivate::createDevNames()\n"
1591 // " -> wDriverOffset: %d\n"
1592 // " -> wDeviceOffset: %d\n"
1593 // " -> wOutputOffset: %d\n",
1594 // dn->wDriverOffset,
1595 // dn->wDeviceOffset,
1596 // dn->wOutputOffset);
1597 
1598 // printf("QPrintDialogWinPrivate::createDevNames(): %s, %s, %s\n",
1599 // QString::fromWCharArray((wchar_t*)(dn) + dn->wDriverOffset).latin1(),
1600 // QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset).latin1(),
1601 // QString::fromWCharArray((wchar_t*)(dn) + dn->wOutputOffset).latin1());
1602 
1603  return hGlobal;
1604 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
unsigned short ushort
Definition: qglobal.h:995
#define GMEM_MOVEABLE
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ doReinit()

void QWin32PrintEnginePrivate::doReinit ( )

Definition at line 1174 of file qprintengine_win.cpp.

1175 {
1176  if (state == QPrinter::Active) {
1177  reinit = true;
1178  } else {
1179  resetDC();
1180  initDevRects();
1181  reinit = false;
1182  }
1183 }
QPrinter::PrinterState state

◆ fillPath()

void QWin32PrintEnginePrivate::fillPath ( const QPainterPath path,
const QColor color 
)

Definition at line 862 of file qprintengine_win.cpp.

863 {
864  fillPath_dev(path * matrix, color);
865 }
void fillPath_dev(const QPainterPath &path, const QColor &color)

◆ fillPath_dev()

void QWin32PrintEnginePrivate::fillPath_dev ( const QPainterPath path,
const QColor color 
)

Definition at line 820 of file qprintengine_win.cpp.

821 {
822 #ifdef QT_DEBUG_DRAW
823  qDebug() << " --- QWin32PrintEnginePrivate::fillPath() bound:" << path.boundingRect() << color;
824 #endif
825 
826  composeGdiPath(path);
827 
828  HBRUSH brush = CreateSolidBrush(RGB(color.red(), color.green(), color.blue()));
829  HGDIOBJ old_brush = SelectObject(hdc, brush);
830  FillPath(hdc);
831  DeleteObject(SelectObject(hdc, old_brush));
832 }
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
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 *,...)
void composeGdiPath(const QPainterPath &path)
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244

◆ getPageMargins()

QRect QWin32PrintEnginePrivate::getPageMargins ( ) const

Definition at line 1113 of file qprintengine_win.cpp.

1114 {
1115  if (pageMarginsSet)
1116  return previousDialogMargins;
1117  else
1118  return QRect(qRound(inchesToMM(devPhysicalPageRect.left()) * 100.0 / dpi_x),
1122 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static qreal inchesToMM(double in)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ initDevRects()

void QWin32PrintEnginePrivate::initDevRects ( )

Definition at line 1082 of file qprintengine_win.cpp.

1083 {
1084  devPaperRect = QRect(0, 0,
1085  GetDeviceCaps(hdc, PHYSICALWIDTH),
1086  GetDeviceCaps(hdc, PHYSICALHEIGHT));
1087  devPhysicalPageRect = QRect(GetDeviceCaps(hdc, PHYSICALOFFSETX),
1088  GetDeviceCaps(hdc, PHYSICALOFFSETY),
1089  GetDeviceCaps(hdc, HORZRES),
1090  GetDeviceCaps(hdc, VERTRES));
1091  if (!pageMarginsSet)
1093  else
1098  updateOrigin();
1099 }
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
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
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

◆ initHDC()

void QWin32PrintEnginePrivate::initHDC ( )

Definition at line 1048 of file qprintengine_win.cpp.

1049 {
1050  Q_ASSERT(hdc);
1051 
1052  HDC display_dc = GetDC(0);
1053  dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1054  dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1055  dpi_display = GetDeviceCaps(display_dc, LOGPIXELSY);
1056  ReleaseDC(0, display_dc);
1057  if (dpi_display == 0) {
1058  qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
1059  "might be a driver problem");
1060  dpi_display = 96; // Reasonable default
1061  }
1062 
1063  switch(mode) {
1066  stretch_x = dpi_x / double(dpi_display);
1067  stretch_y = dpi_y / double(dpi_display);
1068  break;
1071  resolution = dpi_y;
1072  stretch_x = 1;
1073  stretch_y = 1;
1074  break;
1075  default:
1076  break;
1077  }
1078 
1079  initDevRects();
1080 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPrinter::PrinterMode mode
Q_CORE_EXPORT void qWarning(const char *,...)

◆ initialize()

void QWin32PrintEnginePrivate::initialize ( )

Definition at line 985 of file qprintengine_win.cpp.

986 {
987  if (hdc)
988  release();
989  Q_ASSERT(!hPrinter);
990  Q_ASSERT(!hdc);
991  Q_ASSERT(!devMode);
992  Q_ASSERT(!pInfo);
993 
994  if (name.isEmpty())
995  return;
996 
998 
999  bool ok = OpenPrinter((LPWSTR)name.utf16(), (LPHANDLE)&hPrinter, 0);
1000  if (!ok) {
1001  qErrnoWarning("QWin32PrintEngine::initialize: OpenPrinter failed");
1002  return;
1003  }
1004 
1005  // Fetch the PRINTER_INFO_2 with DEVMODE data containing the
1006  // printer settings.
1007  DWORD infoSize, numBytes;
1008  GetPrinter(hPrinter, 2, NULL, 0, &infoSize);
1009  hMem = GlobalAlloc(GHND, infoSize);
1010  pInfo = (PRINTER_INFO_2*) GlobalLock(hMem);
1011  ok = GetPrinter(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes);
1012 
1013  if (!ok) {
1014  qErrnoWarning("QWin32PrintEngine::initialize: GetPrinter failed");
1015  GlobalUnlock(pInfo);
1016  GlobalFree(hMem);
1017  ClosePrinter(hPrinter);
1018  pInfo = 0;
1019  hMem = 0;
1020  hPrinter = 0;
1021  return;
1022  }
1023 
1024  devMode = pInfo->pDevMode;
1025  hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
1026  reinterpret_cast<const wchar_t *>(name.utf16()), 0, devMode);
1027 
1028  Q_ASSERT(hPrinter);
1029  Q_ASSERT(pInfo);
1030 
1031  if (devMode) {
1032  num_copies = devMode->dmCopies;
1033  }
1034 
1035  initHDC();
1036 
1037 #ifdef QT_DEBUG_DRAW
1038  qDebug() << "QWin32PrintEngine::initialize()" << endl
1039  << " - paperRect" << devPaperRect << endl
1040  << " - pageRect" << devPageRect << endl
1041  << " - stretch_x" << stretch_x << endl
1042  << " - stretch_y" << stretch_y << endl
1043  << " - origin_x" << origin_x << endl
1044  << " - origin_y" << origin_y << endl;
1045 #endif
1046 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ queryDefault()

void QWin32PrintEnginePrivate::queryDefault ( )

Definition at line 953 of file qprintengine_win.cpp.

954 {
955  /* Read the default printer name, driver and port with the intuitive function
956  * Strings "windows" and "device" are specified in the MSDN under EnumPrinters()
957  */
958  QString noPrinters(QLatin1String("qt_no_printers"));
959  wchar_t buffer[256];
960  GetProfileString(L"windows", L"device",
961  reinterpret_cast<const wchar_t *>(noPrinters.utf16()),
962  buffer, 256);
963  QString output = QString::fromWCharArray(buffer);
964  if (output.isEmpty() || output == noPrinters) // no printers
965  return;
966 
967  QStringList info = output.split(QLatin1Char(','));
968  int infoSize = info.size();
969  if (infoSize > 0) {
970  if (name.isEmpty())
971  name = info.at(0);
972  if (program.isEmpty() && infoSize > 1)
973  program = info.at(1);
974  if (port.isEmpty() && infoSize > 2)
975  port = info.at(2);
976  }
977 }
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
static mach_timebase_info_data_t info
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ queryResolutions()

QList< QVariant > QWin32PrintEnginePrivate::queryResolutions ( ) const

Definition at line 1147 of file qprintengine_win.cpp.

1148 {
1149  // Read the supported resolutions of the printer.
1150  QList<QVariant> list;
1151 
1152  DWORD numRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
1153  reinterpret_cast<const wchar_t *>(port.utf16()),
1154  DC_ENUMRESOLUTIONS, 0, 0);
1155  if (numRes == (DWORD)-1)
1156  return list;
1157 
1158  LONG *enumRes = (LONG*)malloc(numRes * 2 * sizeof(LONG));
1159  DWORD errRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()),
1160  reinterpret_cast<const wchar_t *>(port.utf16()),
1161  DC_ENUMRESOLUTIONS, (LPWSTR)enumRes, 0);
1162 
1163  if (errRes == (DWORD)-1) {
1164  qErrnoWarning("QWin32PrintEngine::queryResolutions: DeviceCapabilities failed");
1165  return list;
1166  }
1167 
1168  for (uint i=0; i<numRes; ++i)
1169  list.append(int(enumRes[i * 2]));
1170 
1171  return list;
1172 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
unsigned int uint
Definition: qglobal.h:996
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ readDevmode()

void QWin32PrintEnginePrivate::readDevmode ( HGLOBAL  globalDevmode)

Definition at line 1617 of file qprintengine_win.cpp.

1618 {
1619  if (globalDevmode) {
1620  DEVMODE *dm = (DEVMODE*) GlobalLock(globalDevmode);
1621  release();
1622  globalDevMode = globalDevmode;
1623  devMode = dm;
1624  hdc = CreateDC(reinterpret_cast<const wchar_t *>(program.utf16()),
1625  reinterpret_cast<const wchar_t *>(name.utf16()), 0, dm);
1626 
1627  num_copies = devMode->dmCopies;
1628  if (!OpenPrinter((wchar_t*)name.utf16(), &hPrinter, 0))
1629  qWarning("QPrinter: OpenPrinter() failed after reading DEVMODE.");
1630  }
1631 
1632  if (hdc)
1633  initHDC();
1634 }
Q_CORE_EXPORT void qWarning(const char *,...)
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ readDevnames()

void QWin32PrintEnginePrivate::readDevnames ( HGLOBAL  globalDevnames)

Definition at line 1606 of file qprintengine_win.cpp.

1607 {
1608  if (globalDevnames) {
1609  DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevnames);
1610  name = QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset);
1611  port = QString::fromWCharArray((wchar_t*)(dn) + dn->wOutputOffset);
1612  program = QString::fromWCharArray((wchar_t*)(dn) + dn->wDriverOffset);
1613  GlobalUnlock(globalDevnames);
1614  }
1615 }
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

◆ release()

void QWin32PrintEnginePrivate::release ( )

Definition at line 1124 of file qprintengine_win.cpp.

1125 {
1126  if (hdc == 0)
1127  return;
1128 
1129  if (globalDevMode) { // Devmode comes from print dialog
1130  GlobalUnlock(globalDevMode);
1131  } else { // Devmode comes from initialize...
1132  // devMode is a part of the same memory block as pInfo so one free is enough...
1133  GlobalUnlock(hMem);
1134  GlobalFree(hMem);
1135  }
1136  if (hPrinter)
1137  ClosePrinter(hPrinter);
1138  DeleteDC(hdc);
1139 
1140  hdc = 0;
1141  hPrinter = 0;
1142  pInfo = 0;
1143  hMem = 0;
1144  devMode = 0;
1145 }

◆ resetDC()

bool QWin32PrintEnginePrivate::resetDC ( )
inline

Definition at line 171 of file qprintengine_win_p.h.

171  {
172  hdc = ResetDC(hdc, devMode);
173  return hdc != 0;
174  }

◆ setPageMargins()

void QWin32PrintEnginePrivate::setPageMargins ( int  margin_left,
int  margin_top,
int  margin_right,
int  margin_bottom 
)

Definition at line 1101 of file qprintengine_win.cpp.

1102 {
1103  pageMarginsSet = true;
1104  previousDialogMargins = QRect(marginLeft, marginTop, marginRight, marginBottom);
1105 
1106  devPageRect = devPaperRect.adjusted(qRound(mmToInches(marginLeft / 100.0) * dpi_x),
1107  qRound(mmToInches(marginTop / 100.0) * dpi_y),
1108  - qRound(mmToInches(marginRight / 100.0) * dpi_x),
1109  - qRound(mmToInches(marginBottom / 100.0) * dpi_y));
1110  updateOrigin();
1111 }
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 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

◆ strokePath()

void QWin32PrintEnginePrivate::strokePath ( const QPainterPath path,
const QColor color 
)

Definition at line 867 of file qprintengine_win.cpp.

868 {
869  QPainterPathStroker stroker;
870  if (pen.style() == Qt::CustomDashLine) {
871  stroker.setDashPattern(pen.dashPattern());
872  stroker.setDashOffset(pen.dashOffset());
873  } else {
874  stroker.setDashPattern(pen.style());
875  }
876  stroker.setCapStyle(pen.capStyle());
877  stroker.setJoinStyle(pen.joinStyle());
878  stroker.setMiterLimit(pen.miterLimit());
879 
880  QPainterPath stroke;
881  qreal width = pen.widthF();
883  strokePath_dev(path * matrix, color, width);
884  } else {
885  stroker.setWidth(width);
886  if (pen.isCosmetic()) {
887  stroke = stroker.createStroke(path * matrix);
888  } else {
889  stroke = stroker.createStroke(path) * painterMatrix;
890  QTransform stretch(stretch_x, 0, 0, stretch_y, origin_x, origin_y);
891  stroke = stroke * stretch;
892  }
893 
894  if (stroke.isEmpty())
895  return;
896 
897  fillPath_dev(stroke, color);
898  }
899 }
void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width)
void setDashOffset(qreal offset)
Sets the dash offset for the generated outlines to offset.
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
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
void setCapStyle(Qt::PenCapStyle style)
Sets the cap style of the generated outlines to style.
TransformationType type() const
Returns the transformation type of this matrix.
void setMiterLimit(qreal length)
Sets the miter limit of the generated outlines to limit.
QVector< qreal > dashPattern() const
Returns the dash pattern of this pen.
Definition: qpen.cpp:466
void setDashPattern(Qt::PenStyle)
Sets the dash pattern for the generated outlines to style.
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path...
bool isCosmetic() const
Returns true if the pen is cosmetic; otherwise returns false.
Definition: qpen.cpp:840
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
Definition: qpainterpath.h:264
qreal miterLimit() const
Returns the miter limit of the pen.
Definition: qpen.cpp:589
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style of the generated outlines to style.
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
qreal dashOffset() const
Returns the dash offset for the pen.
Definition: qpen.cpp:547
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706
void fillPath_dev(const QPainterPath &path, const QColor &color)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.

◆ strokePath_dev()

void QWin32PrintEnginePrivate::strokePath_dev ( const QPainterPath path,
const QColor color,
qreal  width 
)

Definition at line 834 of file qprintengine_win.cpp.

835 {
836  composeGdiPath(path);
837  LOGBRUSH brush;
838  brush.lbStyle = BS_SOLID;
839  brush.lbColor = RGB(color.red(), color.green(), color.blue());
840  DWORD capStyle = PS_ENDCAP_SQUARE;
841  DWORD joinStyle = PS_JOIN_BEVEL;
842  if (pen.capStyle() == Qt::FlatCap)
843  capStyle = PS_ENDCAP_FLAT;
844  else if (pen.capStyle() == Qt::RoundCap)
845  capStyle = PS_ENDCAP_ROUND;
846 
847  if (pen.joinStyle() == Qt::MiterJoin)
848  joinStyle = PS_JOIN_MITER;
849  else if (pen.joinStyle() == Qt::RoundJoin)
850  joinStyle = PS_JOIN_ROUND;
851 
852  HPEN pen = ExtCreatePen(((penWidth == 0) ? PS_COSMETIC : PS_GEOMETRIC)
853  | PS_SOLID | capStyle | joinStyle,
854  (penWidth == 0) ? 1 : penWidth, &brush, 0, 0);
855 
856  HGDIOBJ old_pen = SelectObject(hdc, pen);
857  StrokePath(hdc);
858  DeleteObject(SelectObject(hdc, old_pen));
859 }
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
void composeGdiPath(const QPainterPath &path)
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244

◆ updateCustomPaperSize()

void QWin32PrintEnginePrivate::updateCustomPaperSize ( )

Definition at line 1748 of file qprintengine_win.cpp.

1749 {
1750  uint paperSize = devMode->dmPaperSize;
1751  if (paperSize > 0 && mapDevmodePaperSize(paperSize) == QPrinter::Custom) {
1752  has_custom_paper_size = true;
1753  DWORD needed = 0;
1754  DWORD returned = 0;
1755  if (!EnumForms(hPrinter, 1, 0, 0, &needed, &returned)) {
1756  BYTE *forms = (BYTE *) malloc(needed);
1757  if (EnumForms(hPrinter, 1, forms, needed, &needed, &returned)) {
1758  if (paperSize <= returned) {
1759  FORM_INFO_1 *formArray = (FORM_INFO_1 *) forms;
1760  int width = formArray[paperSize - 1].Size.cx; // 1/1000 of a mm
1761  int height = formArray[paperSize - 1].Size.cy; // 1/1000 of a mm
1762  paper_size = QSizeF((width * 72 /25.4) / 1000.0, (height * 72 / 25.4) / 1000.0);
1763  } else {
1764  has_custom_paper_size = false;
1765  }
1766  }
1767  free(forms);
1768  }
1769  } else {
1770  has_custom_paper_size = false;
1771  }
1772 }
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
#define BYTE
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QPrinter::PaperSize mapDevmodePaperSize(int s)
unsigned int uint
Definition: qglobal.h:996

◆ updateOrigin()

void QWin32PrintEnginePrivate::updateOrigin ( )

Definition at line 1185 of file qprintengine_win.cpp.

1186 {
1187  if (fullPage) {
1188  // subtract physical margins to make (0,0) absolute top corner of paper
1189  // then add user defined margins
1192  if (pageMarginsSet) {
1193  origin_x += devPageRect.left();
1194  origin_y += devPageRect.top();
1195  }
1196  } else {
1197  origin_x = 0;
1198  origin_y = 0;
1199  if (pageMarginsSet) {
1202  }
1203  }
1204 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

Properties

◆ brush_color

QColor QWin32PrintEnginePrivate::brush_color

Definition at line 248 of file qprintengine_win_p.h.

◆ complex_xform

uint QWin32PrintEnginePrivate::complex_xform

Definition at line 241 of file qprintengine_win_p.h.

◆ devMode

DEVMODE* QWin32PrintEnginePrivate::devMode

Definition at line 194 of file qprintengine_win_p.h.

◆ devPageRect

QRect QWin32PrintEnginePrivate::devPageRect

Definition at line 224 of file qprintengine_win_p.h.

◆ devPaperRect

QRect QWin32PrintEnginePrivate::devPaperRect

Definition at line 226 of file qprintengine_win_p.h.

◆ devPhysicalPageRect

QRect QWin32PrintEnginePrivate::devPhysicalPageRect

Definition at line 225 of file qprintengine_win_p.h.

◆ docName

QString QWin32PrintEnginePrivate::docName

Definition at line 208 of file qprintengine_win_p.h.

◆ dpi_display

int QWin32PrintEnginePrivate::dpi_display

Definition at line 234 of file qprintengine_win_p.h.

◆ dpi_x

int QWin32PrintEnginePrivate::dpi_x

Definition at line 232 of file qprintengine_win_p.h.

◆ dpi_y

int QWin32PrintEnginePrivate::dpi_y

Definition at line 233 of file qprintengine_win_p.h.

◆ fileName

QString QWin32PrintEnginePrivate::fileName

Definition at line 209 of file qprintengine_win_p.h.

◆ fullPage

uint QWin32PrintEnginePrivate::fullPage

Definition at line 238 of file qprintengine_win_p.h.

◆ globalDevMode

HGLOBAL QWin32PrintEnginePrivate::globalDevMode

Definition at line 193 of file qprintengine_win_p.h.

◆ has_brush

uint QWin32PrintEnginePrivate::has_brush

Definition at line 243 of file qprintengine_win_p.h.

◆ has_custom_paper_size

uint QWin32PrintEnginePrivate::has_custom_paper_size

Definition at line 244 of file qprintengine_win_p.h.

◆ has_pen

uint QWin32PrintEnginePrivate::has_pen

Definition at line 242 of file qprintengine_win_p.h.

◆ hdc

HDC QWin32PrintEnginePrivate::hdc

Definition at line 198 of file qprintengine_win_p.h.

◆ hMem

HGLOBAL QWin32PrintEnginePrivate::hMem

Definition at line 196 of file qprintengine_win_p.h.

◆ hPrinter

HANDLE QWin32PrintEnginePrivate::hPrinter

Definition at line 191 of file qprintengine_win_p.h.

◆ matrix

QTransform QWin32PrintEnginePrivate::matrix

Definition at line 254 of file qprintengine_win_p.h.

◆ mode

QPrinter::PrinterMode QWin32PrintEnginePrivate::mode

Definition at line 200 of file qprintengine_win_p.h.

◆ name

QString QWin32PrintEnginePrivate::name

Definition at line 203 of file qprintengine_win_p.h.

◆ num_copies

int QWin32PrintEnginePrivate::num_copies

Definition at line 235 of file qprintengine_win_p.h.

◆ origin_x

int QWin32PrintEnginePrivate::origin_x

Definition at line 229 of file qprintengine_win_p.h.

◆ origin_y

int QWin32PrintEnginePrivate::origin_y

Definition at line 230 of file qprintengine_win_p.h.

◆ pageMarginsSet

bool QWin32PrintEnginePrivate::pageMarginsSet

Definition at line 223 of file qprintengine_win_p.h.

◆ painterMatrix

QTransform QWin32PrintEnginePrivate::painterMatrix

Definition at line 253 of file qprintengine_win_p.h.

◆ paper_size

QSizeF QWin32PrintEnginePrivate::paper_size

Definition at line 251 of file qprintengine_win_p.h.

◆ pen

QPen QWin32PrintEnginePrivate::pen

Definition at line 249 of file qprintengine_win_p.h.

◆ pen_color

QColor QWin32PrintEnginePrivate::pen_color

Definition at line 250 of file qprintengine_win_p.h.

◆ pInfo

PRINTER_INFO_2* QWin32PrintEnginePrivate::pInfo

Definition at line 195 of file qprintengine_win_p.h.

◆ port

QString QWin32PrintEnginePrivate::port

Definition at line 205 of file qprintengine_win_p.h.

◆ previousDialogMargins

QRect QWin32PrintEnginePrivate::previousDialogMargins

Definition at line 221 of file qprintengine_win_p.h.

◆ printToFile

uint QWin32PrintEnginePrivate::printToFile

Definition at line 237 of file qprintengine_win_p.h.

◆ program

QString QWin32PrintEnginePrivate::program

Definition at line 204 of file qprintengine_win_p.h.

◆ reinit

uint QWin32PrintEnginePrivate::reinit

Definition at line 239 of file qprintengine_win_p.h.

◆ resolution

int QWin32PrintEnginePrivate::resolution

Definition at line 212 of file qprintengine_win_p.h.

◆ state

QPrinter::PrinterState QWin32PrintEnginePrivate::state

Definition at line 211 of file qprintengine_win_p.h.

◆ stretch_x

qreal QWin32PrintEnginePrivate::stretch_x

Definition at line 227 of file qprintengine_win_p.h.

◆ stretch_y

qreal QWin32PrintEnginePrivate::stretch_y

Definition at line 228 of file qprintengine_win_p.h.

◆ txop

uint QWin32PrintEnginePrivate::txop

Definition at line 246 of file qprintengine_win_p.h.


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