5#include <ApplicationServices/ApplicationServices.h>
10#include <QtGui/qpagelayout.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qdebug.h>
14#include <QtCore/private/qcore_mac_p.h>
33 d->m_pageLayout.setPageSize(
d->m_printDevice->defaultPageSize());
42 if (!
static_cast<QPrinter *
>(dev)->isValid())
48 d->paintEngine->state =
state;
49 d->paintEngine->begin(dev);
52 if (PMSessionValidatePrintSettings(
d->session(),
d->settings(), kPMDontWantBoolean) != noErr
53 || PMSessionValidatePageFormat(
d->session(),
d->format(), kPMDontWantBoolean) != noErr) {
58 if (!
d->outputFilename.isEmpty()) {
59 QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault,
63 if (PMSessionSetDestination(
d->session(),
d->settings(), kPMDestinationFile,
64 kPMDocumentFormatPDF, outFile) != noErr) {
65 qWarning(
"QMacPrintEngine::begin: Problem setting file [%s]",
d->outputFilename.toUtf8().constData());
70 OSStatus status = PMSessionBeginCGDocumentNoDialog(
d->session(),
d->settings(),
d->format());
71 if (status != noErr) {
92 d->paintEngine->end();
102 return d_func()->paintEngine;
108 return cgEngine->d_func()->hd;
119 return d_func()->state;
126 OSStatus err = PMSessionEndPageNoDialog(
d->session());
128 if (err == kPMCancel) {
133 qWarning(
"QMacPrintEngine::newPage: Cannot end current page. %ld",
long(err));
138 return d->newPage_helper();
157 val =
d->m_pageLayout.paintRectPixels(
d->resolution.hRes).width();
160 val =
d->m_pageLayout.paintRectPixels(
d->resolution.hRes).height();
171 if (PMSessionGetCurrentPrinter(
d->session(), &printer) == noErr) {
172 PMResolution resolution;
173 PMPrinterGetOutputResolution(printer,
d->settings(), &resolution);
174 val = (int)resolution.vRes;
180 val = (int)
d->resolution.vRes;
183 val = (int)
d->resolution.hRes;
199 qWarning(
"QPrinter::metric: Invalid metric command");
220 std::sort(resolutions.
begin(), resolutions.
end());
235 q->setProperty(propC.
key(), propC.
value());
241 PMSessionEndPageNoDialog(
session());
242 PMSessionEndDocumentNoDialog(
session());
252 if (PMSessionError(
session()) != noErr) {
261 while (cgEngine->d_func()->stackCount > 0)
262 cgEngine->d_func()->restoreGraphicsState();
264 OSStatus status = PMSessionBeginPageNoDialog(
session(),
format(),
nullptr);
265 if (status != noErr) {
274 OSStatus err = noErr;
275 err = PMSessionGetCGGraphicsContext(
session(), &cgContext);
277 qWarning(
"QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld",
long(err));
281 cgEngine->d_func()->hd = cgContext;
286 CGContextScaleCTM(cgContext, 1, -1);
287 CGContextTranslateCTM(cgContext, 0, -paper.
height());
289 CGContextTranslateCTM(cgContext,
page.x() - paper.
x(),
page.y() - paper.
y());
290 cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext);
291 cgEngine->d_func()->setClip(
nullptr);
309 QPageSize usePageSize = printerPageSize.
isValid() ? printerPageSize : pageSize;
314 qWarning() <<
"QMacPrintEngine: Invalid PMPaper returned for " << pageSize;
322 PMPageFormat pageFormat;
323 PMCreatePageFormatWithPMPaper(&pageFormat, macPaper);
325 PMCopyPageFormat(pageFormat,
format());
326 if (PMSessionValidatePageFormat(
session(),
format(), kPMDontWantBoolean) != noErr)
327 qWarning(
"QMacPrintEngine: Invalid page format");
328 PMRelease(pageFormat);
333 d_func()->paintEngine->updateState(
state);
340 d->paintEngine->drawRects(
r,
num);
347 d->paintEngine->drawPoints(
points, pointCount);
354 d->paintEngine->drawEllipse(
r);
361 d->paintEngine->drawLines(lines, lineCount);
368 d->paintEngine->drawPolygon(
points, pointCount,
mode);
375 d->paintEngine->drawPixmap(
r, pm, sr);
382 d->paintEngine->drawImage(
r, pm, sr,
flags);
392 d->paintEngine->drawTextItem(
p, ti);
399 d->paintEngine->drawTiledPixmap(dr,
pixmap, sr);
406 d->paintEngine->drawPath(
path);
450 d->embedFonts =
value.toBool();
453 int bestResolution = 0;
454 int dpi =
value.toInt();
455 int bestDistance = INT_MAX;
456 for (
int resolution :
d->m_printDevice->supportedResolutions()) {
457 if (dpi == resolution) {
458 bestResolution = resolution;
464 bestResolution = resolution;
468 PMResolution resolution;
469 resolution.hRes = resolution.vRes = bestResolution;
470 if (PMPrinterSetOutputResolution(
d->m_printDevice->macPrinter(),
d->settings(), &resolution) == noErr) {
473 if (PMPrinterGetOutputResolution(
d->m_printDevice->macPrinter(),
d->settings(), &
d->resolution) != noErr) {
476 d->resolution = resolution;
482 PMSetCollate(
d->settings(),
value.toBool());
485 d->m_creator =
value.toString();
496 PMSetDuplex(
d->settings(), kPMDuplexNone);
499 PMSetDuplex(
d->settings(),
d->m_pageLayout.orientation() ==
QPageLayout::Landscape ? kPMDuplexTumble : kPMDuplexNoTumble);
502 PMSetDuplex(
d->settings(), kPMDuplexNoTumble);
505 PMSetDuplex(
d->settings(), kPMDuplexTumble);
521 PMSetCopies(
d->settings(),
value.toInt(),
false);
527 PMSetOrientation(
d->format(), macOrientation, kPMUnlocked);
528 PMSessionValidatePageFormat(
d->session(),
d->format(), kPMDontWantBoolean);
529 PMGetOrientation(
d->format(), &macOrientation);
534 d->outputFilename =
value.toString();
541 d->setPageSize(
d->m_printDevice->supportedPageSize(
value.toString()));
551 d->m_pageLayout.units()));
558 PMPrinter printer =
d->m_printDevice->macPrinter();
560 PMSessionSetCurrentPMPrinter(
d->session(), printer);
562 if (
d->m_printDevice->supportedPageSize(pageSize.
value<
QPageSize>()).isValid())
578 d->m_pageLayout.setMargins(
QMarginsF(margins.
at(0).toReal(), margins.
at(1).toReal(),
579 margins.
at(2).toReal(), margins.
at(3).toReal()));
587 d->m_pageLayout.setUnits(pair.second);
588 d->m_pageLayout.setMargins(pair.first);
593 if (pageLayout.
isValid() &&
d->m_printDevice->isValidPageLayout(pageLayout,
d->resolution.hRes)) {
597 d->m_pageLayout.setUnits(pageLayout.
units());
598 d->m_pageLayout.setMargins(pageLayout.
margins());
611 if (!
d->printInfo &&
d->valueCache.contains(
key))
612 return *
d->valueCache.find(
key);
652 PMGetCollate(
d->settings(), &status);
661 PMPrintSettingsGetJobName(
d->settings(), &
name);
662 ret = QString::fromCFString(
name);
666 PMDuplexMode
mode = kPMDuplexNone;
667 PMGetDuplex(
d->settings(), &
mode);
669 case kPMDuplexNoTumble:
672 case kPMDuplexTumble:
690 PMGetCopies(
d->settings(), &copies);
698 ret =
d->m_pageLayout.orientation();
701 ret =
d->outputFilename;
705 ret =
d->m_pageLayout.paintRectPixels(
d->resolution.hRes);
708 ret =
d->m_pageLayout.pageSize().id();
711 ret =
d->m_pageLayout.pageSize().name();
714 ret =
d->m_pageLayout.pageSize().windowsId();
718 ret =
d->m_pageLayout.fullRectPixels(
d->resolution.hRes);
721 return d->m_printDevice->id();
724 ret =
d->resolution.hRes;
729 for (
int resolution :
d->m_printDevice->supportedResolutions())
735 ret =
d->m_pageLayout.fullRectPoints().size();
745 ret.setValue(
d->m_pageLayout.pageSize());
753 ret.setValue(
d->m_pageLayout);
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const override
PMPaper macPaper(const QPageSize &pageSize) const
QString defaultPrintDeviceId() const override
const T & value() const noexcept
Returns the current item's value.
const Key & key() const noexcept
Returns the current item's key.
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
~QMacPrintEnginePrivate()
PMPrintSession session() const
QPrinter::PrinterState state
QSharedPointer< QCocoaPrintDevice > m_printDevice
QPaintEngine * paintEngine
PMPageFormat format() const
void setPageSize(const QPageSize &pageSize)
QHash< QMacPrintEngine::PrintEnginePropertyKey, QVariant > valueCache
virtual void drawPoints(const QPointF *p, int pointCount)
Draws the first pointCount points in the buffer points.
void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
QPaintEngine * paintEngine() const
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
virtual void drawTextItem(const QPointF &p, const QTextItem &ti)
This function draws the text item textItem at position p.
QVariant property(PrintEnginePropertyKey key) const
Returns the print engine's property specified by key.
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.
virtual void drawPath(const QPainterPath &)
The default implementation ignores the path and does nothing.
bool newPage()
Instructs the print engine to start a new page.
Qt::HANDLE handle() const
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...
QPrinter::PrinterState printerState() const
Returns the current state of the printer being used by the print engine.
virtual void drawRects(const QRectF *r, int num)
Draws the first rectCount rectangles in the buffer rects.
NSPrintInfo * printInfo()
bool end()
Reimplement this function to finish painting on the current paint device.
bool begin(QPaintDevice *dev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
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.
bool abort()
Instructs the print engine to abort the printing process.
int metric(QPaintDevice::PaintDeviceMetric) const
Returns the metric for the given id.
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.
void setProperty(PrintEnginePropertyKey key, const QVariant &value)
Sets the print engine's property specified by key to the given value.
virtual void drawLines(const QLineF *lines, int lineCount)
The default implementation splits the list of lines in lines into lineCount separate calls to drawPat...
constexpr qreal right() const noexcept
Returns the right margin.
constexpr qreal left() const noexcept
Returns the left margin.
constexpr qreal top() const noexcept
Returns the top margin.
constexpr qreal bottom() const noexcept
Returns the bottom margin.
Mode mode() const
Returns the page layout mode.
Unit units() const
Returns the units the page layout is currently defined in.
bool isValid() const
Returns true if this page layout is valid.
Unit
This enum type is used to specify the measurement unit for page layout and margins.
QMarginsF margins() const
Returns the margins of the page layout using the currently set units.
Orientation orientation() const
Returns the page orientation of the page layout.
QRect paintRectPixels(int resolution) const
Returns the paintable rectangle in rounded device pixels for the given resolution.
void setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins=QMarginsF(0, 0, 0, 0))
Sets the page size of the page layout to pageSize.
Orientation
This enum type defines the page orientation.
QRect fullRectPixels(int resolution) const
Returns the full page rectangle in device pixels for the given resolution.
QPageSize pageSize() const
Returns the page size of the page layout.
bool isValid() const
Returns true if this page size is valid.
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.
PageSizeId
This enum type lists the available page sizes as defined in the Postscript PPD standard.
@ PdmDevicePixelRatioScaled
virtual int devType() const
static qreal devicePixelRatioFScale()
The QPaintEngineState class provides information about the active paint engine's current state....
QPaintEngine::DirtyFlags dirtyFlags
void setActive(bool newState)
Sets the active state of the paint engine to state.
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
friend class QMacPrintEngine
QPainter * painter() const
Returns the paint engine's painter.
QPaintEngineState * state
PaintEngineFeatures gccaps
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\inmodule QtCore\reentrant
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
@ PPK_SupportedResolutions
@ PPK_SupportsMultipleCopies
PrinterMode
This enum describes the mode the printer should work in.
PrinterState
\value Idle \value Active \value Aborted \value Error
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
Q_GUI_EXPORT int qt_defaultDpi()
constexpr T qAbs(const T &t)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLsizei GLsizei GLfloat distance
GLfixed GLfixed GLint GLint GLfixed points
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
Q_GUI_EXPORT QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
struct CGContext * CGContextRef
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
QT_BEGIN_NAMESPACE QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
#define Q_ASSERT_X(cond, x, msg)
static int toInt(const QChar &qc, int R)
QFuture< QSet< QString > > dictionary
QTextStream out(stdout)
[7]