7#include <QtCore/qdebug.h>
32 LPWSTR printerIdUtf16 =
const_cast<LPWSTR
>(
reinterpret_cast<LPCWSTR
>(printerId.
utf16()));
34 LONG dmSize = DocumentProperties(
nullptr, hPrinter, printerIdUtf16,
nullptr,
nullptr, 0);
37 LPDEVMODE pDevMode =
reinterpret_cast<LPDEVMODE
>(malloc(dmSize));
39 LONG
result = DocumentProperties(
nullptr, hPrinter, printerIdUtf16, pDevMode,
nullptr, DM_OUT_BUFFER);
59 if (OpenPrinter(
const_cast<LPWSTR
>(wcharId()), &m_hPrinter,
nullptr)) {
61 GetPrinter(m_hPrinter, 2, 0, 0, &needed);
63 if (GetPrinter(m_hPrinter, 2,
buffer.data(), needed, &needed)) {
64 PPRINTER_INFO_2
info =
reinterpret_cast<PPRINTER_INFO_2
>(
buffer.data());
76 m_infoIndex = windowsDeviceLookup()->indexOf(m_info);
77 if (m_infoIndex != -1) {
78 m_info = windowsDeviceLookup()->at(m_infoIndex);
98 m_infoIndex = windowsDeviceLookup()->indexOf(m_info);
100 windowsDeviceLookup()->append(m_info);
101 m_infoIndex = windowsDeviceLookup()->count() - 1;
109 ClosePrinter(m_hPrinter);
125 GetPrinter(m_hPrinter, 6, 0, 0, &needed);
128 if (GetPrinter(m_hPrinter, 6,
buffer.data(), needed, &needed)) {
129 PPRINTER_INFO_6
info =
reinterpret_cast<PPRINTER_INFO_6
>(
buffer.data());
131 if (
info->dwStatus == 0
132 || (
info->dwStatus & PRINTER_STATUS_WAITING) == PRINTER_STATUS_WAITING
133 || (
info->dwStatus & PRINTER_STATUS_POWER_SAVE) == PRINTER_STATUS_POWER_SAVE) {
135 }
else if ((
info->dwStatus & PRINTER_STATUS_PRINTING) == PRINTER_STATUS_PRINTING
136 || (
info->dwStatus & PRINTER_STATUS_BUSY) == PRINTER_STATUS_BUSY
137 || (
info->dwStatus & PRINTER_STATUS_INITIALIZING) == PRINTER_STATUS_INITIALIZING
138 || (
info->dwStatus & PRINTER_STATUS_IO_ACTIVE) == PRINTER_STATUS_IO_ACTIVE
139 || (
info->dwStatus & PRINTER_STATUS_PROCESSING) == PRINTER_STATUS_PROCESSING
140 || (
info->dwStatus & PRINTER_STATUS_WARMING_UP) == PRINTER_STATUS_WARMING_UP) {
151 const int paperCount = DeviceCapabilities(wcharId(),
nullptr, DC_PAPERNAMES,
nullptr,
nullptr);
153 && DeviceCapabilities(wcharId(),
nullptr, DC_PAPERSIZE,
nullptr,
nullptr) == paperCount
154 && DeviceCapabilities(wcharId(),
nullptr, DC_PAPERS,
nullptr,
nullptr) == paperCount) {
161 if (DeviceCapabilities(wcharId(),
nullptr, DC_PAPERNAMES, paperNames.
data(),
nullptr) == paperCount
162 && DeviceCapabilities(wcharId(),
nullptr, DC_PAPERSIZE,
163 reinterpret_cast<wchar_t *
>(winSizes.
data()),
nullptr) == paperCount
164 && DeviceCapabilities(wcharId(),
nullptr, DC_PAPERS, papers.
data(),
nullptr) == paperCount) {
168 for (
int i = 0;
i < int(paperCount); ++
i) {
170 wchar_t *paper = paperNames.
data() + (
i * 64);
180 info[m_infoIndex].m_havePageSizes =
true;
193 if (pDevMode->dmFields & DM_PAPERSIZE) {
196 if (ps.windowsId() == pDevMode->dmPaperSize) {
211 int resolution)
const
217 GetPrinter(m_hPrinter, 2, 0, 0, &needed);
219 if (GetPrinter(m_hPrinter, 2,
buffer.data(), needed, &needed)) {
220 PPRINTER_INFO_2
info =
reinterpret_cast<PPRINTER_INFO_2
>(
buffer.data());
221 LPDEVMODE devMode =
info->pDevMode;
222 bool separateDevMode =
false;
228 separateDevMode =
true;
231 HDC pDC = CreateDC(
nullptr, wcharId(),
nullptr, devMode);
233 devMode->dmPaperSize = 0;
237 devMode->dmPaperSize = pageSize.
windowsId();
239 devMode->dmPrintQuality = resolution;
240 devMode->dmOrientation = orientation ==
QPageLayout::Portrait ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
241 ResetDC(pDC, devMode);
242 const int dpiWidth = GetDeviceCaps(pDC, LOGPIXELSX);
243 const int dpiHeight = GetDeviceCaps(pDC, LOGPIXELSY);
244 const qreal wMult = 72.0 / dpiWidth;
245 const qreal hMult = 72.0 / dpiHeight;
246 const qreal physicalWidth = GetDeviceCaps(pDC, PHYSICALWIDTH) * wMult;
247 const qreal physicalHeight = GetDeviceCaps(pDC, PHYSICALHEIGHT) * hMult;
248 const qreal printableWidth = GetDeviceCaps(pDC, HORZRES) * wMult;
249 const qreal printableHeight = GetDeviceCaps(pDC, VERTRES) * hMult;
250 const qreal leftMargin = GetDeviceCaps(pDC, PHYSICALOFFSETX)* wMult;
251 const qreal topMargin = GetDeviceCaps(pDC, PHYSICALOFFSETY) * hMult;
252 const qreal rightMargin = physicalWidth - leftMargin - printableWidth;
253 const qreal bottomMargin = physicalHeight - topMargin - printableHeight;
254 margins =
QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin);
264 const int resCount = DeviceCapabilities(wcharId(),
nullptr, DC_ENUMRESOLUTIONS,
nullptr,
nullptr);
268 if (DeviceCapabilities(wcharId(),
nullptr, DC_ENUMRESOLUTIONS,
269 reinterpret_cast<LPWSTR
>(resolutions.
data()),
nullptr) == resCount) {
270 for (
int i = 0;
i < int(resCount * 2);
i += 2)
276 info[m_infoIndex].m_haveResolutions =
true;
286 if (pDevMode->dmFields & DM_YRESOLUTION) {
287 if (pDevMode->dmPrintQuality > 0)
288 resolution = pDevMode->dmPrintQuality;
290 resolution = pDevMode->dmYResolution;
300 const auto printerId = wcharId();
301 const int binCount = DeviceCapabilities(printerId,
nullptr, DC_BINS,
nullptr,
nullptr);
303 && DeviceCapabilities(printerId,
nullptr, DC_BINNAMES,
nullptr,
nullptr) == binCount) {
309 if (DeviceCapabilities(printerId,
nullptr, DC_BINS,
310 reinterpret_cast<LPWSTR
>(bins.
data()),
nullptr) == binCount
311 && DeviceCapabilities(printerId,
nullptr, DC_BINNAMES, binNames.
data(),
312 nullptr) == binCount) {
314 for (
int i = 0;
i < int(binCount); ++
i) {
315 wchar_t *binName = binNames.
data() + (
i * 24);
325 info[m_infoIndex].m_haveInputSlots =
true;
335 if (pDevMode->dmFields & DM_DEFAULTSOURCE) {
340 if (slot.key == tempSlot.
key) {
357 info[m_infoIndex].m_haveOutputBins =
true;
364 DWORD duplex = DeviceCapabilities(wcharId(),
nullptr, DC_DUPLEX,
nullptr,
nullptr);
365 if (
int(duplex) == 1) {
373 info[m_infoIndex].m_haveDuplexModes =
true;
383 if (pDevMode->dmFields & DM_DUPLEX) {
384 if (pDevMode->dmDuplex == DMDUP_VERTICAL)
386 else if (pDevMode->dmDuplex == DMDUP_HORIZONTAL)
398 DWORD
color = DeviceCapabilities(wcharId(),
nullptr, DC_COLORDEVICE,
nullptr,
nullptr);
403 info[m_infoIndex].m_haveColorModes =
true;
418 if (pDevMode->dmFields & DM_COLOR && pDevMode->dmColor == DMCOLOR_COLOR)
431 if ((!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
nullptr, 4, 0, 0, &needed, &returned)
432 && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
437 if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
nullptr, 4,
buffer.data(), needed, &needed, &returned))
439 PPRINTER_INFO_4 infoList =
reinterpret_cast<PPRINTER_INFO_4
>(
buffer.data());
440 for (
uint i = 0;
i < returned; ++
i)
448 if (GetDefaultPrinter(
nullptr, &
size) == ERROR_FILE_NOT_FOUND ||
size < 2)
452 GetDefaultPrinter(
name.data(), &
size);
458 auto printerId = wcharId();
463 info[m_infoIndex].m_haveCopies =
true;
484 if (!m_haveMinMaxPageSizes)
491 if (!m_haveMinMaxPageSizes)
498 if (!m_haveMinMaxPageSizes)
507 auto printerId = wcharId();
508 DWORD min = DeviceCapabilities(printerId,
nullptr, DC_MINEXTENT,
nullptr,
nullptr);
510 DWORD max = DeviceCapabilities(printerId,
nullptr, DC_MAXEXTENT,
nullptr,
nullptr);
513 m_haveMinMaxPageSizes =
true;
515 info[m_infoIndex].m_haveCopies =
true;
void append(parameter_type t)
Unit
This enum type is used to specify the measurement unit for page layout and margins.
Orientation
This enum type defines the page orientation.
int windowsId() const
Returns the Windows DMPAPER enum value for the page size.
QSizeF size(Unit units) const
Returns the size of the page in the required units.
PageSizeId id() const
Returns the standard QPageSize::PageSizeId of the page, or QPageSize::Custom.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
void loadColorModes() const override
void loadInputSlots() const override
void loadOutputBins() const override
void loadResolutions() const override
static QString defaultPrintDeviceId()
void loadCopiesSupport() const
void loadMinMaxPageSizes() const
QPrint::InputSlot defaultInputSlot() const override
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const override
bool isDefault() const override
bool isValid() const override
virtual ~QWindowsPrintDevice()
QPrint::DeviceState state() const override
int defaultResolution() const override
void loadDuplexModes() const override
QSize maximumPhysicalPageSize() const override
bool supportsCollateCopies() const override
QSize minimumPhysicalPageSize() const override
bool supportsMultipleCopies() const override
QPrint::ColorMode defaultColorMode() const override
QPageSize defaultPageSize() const override
QPrint::DuplexMode defaultDuplexMode() const override
bool supportsCustomPageSizes() const override
static QStringList availablePrintDeviceIds()
void loadPageSizes() const override
QList< QPrint::OutputBin > m_outputBins
QList< int > m_resolutions
QList< QPrint::DuplexMode > m_duplexModes
bool m_haveMinMaxPageSizes
bool m_supportsCustomPageSizes
bool m_supportsCollateCopies
QList< QPrint::InputSlot > m_inputSlots
QSize m_minimumPhysicalPageSize
QList< QPrint::ColorMode > m_colorModes
QList< QPageSize > m_pageSizes
QSize m_maximumPhysicalPageSize
bool m_supportsMultipleCopies
QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name)
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
QT_BEGIN_NAMESPACE Q_GUI_EXPORT qreal qt_pointMultiplier(QPageLayout::Unit unit)
qreal qt_pointMultiplier(QPageLayout::Unit unit)
static LPDEVMODE getDevmode(HANDLE hPrinter, const QString &printerId)
static uint qwcsnlen(const wchar_t *str, uint maxlen)
QFileInfo info(fileName)
[8]
bool contains(const AT &t) const noexcept