1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QPRINTENGINE_MAC_P_H
41 #define QPRINTENGINE_MAC_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtCore/qglobal.h>
55 
56 #ifndef QT_NO_PRINTER
57 
58 #include <QtPrintSupport/qprinter.h>
59 #include <QtPrintSupport/qprintengine.h>
60 #include <QtGui/private/qpainter_p.h>
61 #include <QtGui/qpagelayout.h>
62 
63 #include "qcocoaprintdevice.h"
64 
65 #include "qpaintengine_mac_p.h"
66 
67 Q_FORWARD_DECLARE_OBJC_CLASS(NSPrintInfo);
68 
69 QT_BEGIN_NAMESPACE
70 
71 class QPrinterPrivate;
72 class QMacPrintEnginePrivate;
73 class QMacPrintEngine : public QPaintEngine, public QPrintEngine
74 {
75     Q_DECLARE_PRIVATE(QMacPrintEngine)
76 public:
77     QMacPrintEngine(QPrinter::PrinterMode mode, const QString &deviceId);
78 
79     Qt::HANDLE handle() const;
80 
81     bool begin(QPaintDevice *dev);
82     bool end();
type()83     virtual QPaintEngine::Type type() const { return QPaintEngine::MacPrinter; }
84 
85     QPaintEngine *paintEngine() const;
86 
87     void setProperty(PrintEnginePropertyKey key, const QVariant &value);
88     QVariant property(PrintEnginePropertyKey key) const;
89 
90     QPrinter::PrinterState printerState() const;
91 
92     bool newPage();
93     bool abort();
94     int metric(QPaintDevice::PaintDeviceMetric) const;
95 
96     //forwarded functions
97 
98     void updateState(const QPaintEngineState &state);
99 
100     virtual void drawLines(const QLineF *lines, int lineCount);
101     virtual void drawRects(const QRectF *r, int num);
102     virtual void drawPoints(const QPointF *p, int pointCount);
103     virtual void drawEllipse(const QRectF &r);
104     virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
105     virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
106     virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags);
107     virtual void drawTextItem(const QPointF &p, const QTextItem &ti);
108     virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
109     virtual void drawPath(const QPainterPath &);
110 
111 private:
112     friend class QCocoaNativeInterface;
113 };
114 
115 class QMacPrintEnginePrivate : public QPaintEnginePrivate
116 {
117     Q_DECLARE_PUBLIC(QMacPrintEngine)
118 public:
119     QPrinter::PrinterMode mode;
120     QPrinter::PrinterState state;
121     QSharedPointer<QCocoaPrintDevice> m_printDevice;
122     QPageLayout m_pageLayout;
123     NSPrintInfo *printInfo;
124     PMResolution resolution;
125     QString outputFilename;
126     QString m_creator;
127     QPaintEngine *paintEngine;
128     QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache;
129     uint embedFonts;
130 
QMacPrintEnginePrivate()131     QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle),
132                                m_pageLayout(QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0))),
133                                printInfo(nullptr), paintEngine(nullptr), embedFonts(true) {}
134     ~QMacPrintEnginePrivate();
135 
136     void initialize();
137     void releaseSession();
138     bool newPage_helper();
139     void setPageSize(const QPageSize &pageSize);
isPrintSessionInitialized()140     inline bool isPrintSessionInitialized() const
141     {
142         return printInfo != 0;
143     }
144 
format()145     PMPageFormat format() const { return static_cast<PMPageFormat>([printInfo PMPageFormat]); }
session()146     PMPrintSession session() const { return static_cast<PMPrintSession>([printInfo PMPrintSession]); }
settings()147     PMPrintSettings settings() const { return static_cast<PMPrintSettings>([printInfo PMPrintSettings]); }
148 
aggregateEngine()149     QPaintEngine *aggregateEngine() override { return paintEngine; }
nativeHandle()150     Qt::HANDLE nativeHandle() override { return q_func()->handle(); }
151 };
152 
153 QT_END_NAMESPACE
154 
155 #endif // QT_NO_PRINTER
156 
157 #endif // QPRINTENGINE_WIN_P_H
158