Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qprintengine_win_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QPRINTENGINE_WIN_P_H
6#define QPRINTENGINE_WIN_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtPrintSupport/private/qtprintsupportglobal_p.h>
20
21#ifndef QT_NO_PRINTER
22
23#include <QtGui/qpaintengine.h>
24#include <QtGui/qpagelayout.h>
25#include <QtPrintSupport/QPrintEngine>
26#include <QtPrintSupport/QPrinter>
27#include <private/qpaintengine_alpha_p.h>
28#include <private/qprintdevice_p.h>
29#include <QtCore/qt_windows.h>
30
31QT_BEGIN_NAMESPACE
32
33class QWin32PrintEnginePrivate;
34class QPrinterPrivate;
35class QPainterState;
36
37class Q_PRINTSUPPORT_EXPORT QWin32PrintEngine : public QAlphaPaintEngine, public QPrintEngine
38{
39 Q_DECLARE_PRIVATE(QWin32PrintEngine)
40public:
41 QWin32PrintEngine(QPrinter::PrinterMode mode, const QString &deviceId);
42
43 // override QWin32PaintEngine
44 bool begin(QPaintDevice *dev) override;
45 bool end() override;
46
47 void updateState(const QPaintEngineState &state) override;
48
49 void updateMatrix(const QTransform &matrix);
50 void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
51
52 void drawPath(const QPainterPath &path) override;
53 void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
54 void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
55
56 void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
57 void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p) override;
58 void setProperty(PrintEnginePropertyKey key, const QVariant &value) override;
59 QVariant property(PrintEnginePropertyKey key) const override;
60
61 bool newPage() override;
62 bool abort() override;
63 int metric(QPaintDevice::PaintDeviceMetric) const override;
64
65 QPrinter::PrinterState printerState() const override;
66
67 QPaintEngine::Type type() const override { return Windows; }
68
69 HDC getDC() const;
70 void releaseDC(HDC) const;
71
72 /* Used by print/page setup dialogs */
73 void setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalDevMode);
74 HGLOBAL *createGlobalDevNames();
75 HGLOBAL globalDevMode();
76
77private:
78 friend class QPrintDialog;
79 friend class QPageSetupDialog;
80};
81
83{
84 Q_DECLARE_PUBLIC(QWin32PrintEngine)
85public:
87 printToFile(false), reinit(false),
88 complex_xform(false), has_pen(false), has_brush(false), has_custom_paper_size(false),
89 embed_fonts(true)
90 {
91 }
92
94
95
96 /* Initializes the printer data based on the current printer name. This
97 function creates a DEVMODE struct, HDC and a printer handle. If these
98 structures are already in use, they are freed using release
99 */
100 void initialize();
101
102 /* Initializes data in the print engine whenever the HDC has been renewed
103 */
104 void initHDC();
105
106 /* Releases all the handles the printer currently holds, HDC, DEVMODE,
107 etc and resets the corresponding members to 0. */
108 void release();
109
110 /* Resets the DC with changes in devmode. If the printer is active
111 this function only sets the reinit variable to true so it
112 is handled in the next begin or newpage. */
113 void doReinit();
114
115 static void initializeDevMode(DEVMODE *);
116
117 bool resetDC();
118
119 void strokePath(const QPainterPath &path, const QColor &color);
120 void fillPath(const QPainterPath &path, const QColor &color);
121
122 void composeGdiPath(const QPainterPath &path);
123 void fillPath_dev(const QPainterPath &path, const QColor &color);
124 void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
125
126 void setPageSize(const QPageSize &pageSize);
127 void updatePageLayout();
128 void updateMetrics();
129 void debugMetrics() const;
130
131 // Windows GDI printer references.
132 HANDLE hPrinter = nullptr;
133
135 DEVMODE *devMode = nullptr;
137 HGLOBAL hMem = nullptr;
138
139 HDC hdc = nullptr;
140
141 // True if devMode was allocated separately from pInfo.
142 bool ownsDevMode = false;
143
145
146 // Print Device
148
149 // Document info
153
155 int resolution = 0;
156
157 // Page Layout
160 // Page metrics cache
163
164 // Windows painting
167 int origin_x = 0;
168 int origin_y = 0;
169
170 int dpi_x = 96;
171 int dpi_y = 96;
172 int dpi_display = 96;
173 int num_copies = 1;
174
177
183
184 uint txop = 0; // QTransform::TxNone
185
189 QSizeF paper_size; // In points
190
193};
194
195QT_END_NAMESPACE
196
197#endif // QT_NO_PRINTER
198
199#endif // QPRINTENGINE_WIN_P_H
QPrinter::PrinterState state
void fillPath_dev(const QPainterPath &path, const QColor &color)
void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width)
void composeGdiPath(const QPainterPath &path)
void strokePath(const QPainterPath &path, const QColor &color)
static void initializeDevMode(DEVMODE *)
void setPageSize(const QPageSize &pageSize)
void fillPath(const QPainterPath &path, const QColor &color)
QPrinter::PrinterMode mode
QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
HBitmapFormat
@ HBitmapPremultipliedAlpha
@ HBitmapNoAlpha
@ HBitmapAlpha
static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc, const QTransform &xform, const QPointF &topLeft)
static int indexOfWindowsId(const QList< QPrint::InputSlot > &inputSlots, int windowsId)
QT_BEGIN_NAMESPACE QPainterPath qt_regionToPath(const QRegion &region)
Definition qregion.cpp:1010
static QByteArray msgBeginFailed(const char *function, const DOCINFO &d)
static int indexOfId(const QList< QPrint::InputSlot > &inputSlots, QPrint::InputSlotId id)