From 2df117b8ad0b0726cd6d7a084a9dced4710617a7 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 16 Aug 2011 11:34:01 +0200 Subject: Move the remaining QPrinter dependencies out of qpf.* Change-Id: I4fd0158d65afad1bc67c52eff17ce2e12ff60641 Reviewed-on: http://codereview.qt.nokia.com/3203 Reviewed-by: Gunnar Sletta --- src/gui/kernel/qwindowdefs.h | 1 - src/gui/painting/qpdf.cpp | 179 +++++++++++++++------------------- src/gui/painting/qpdf_p.h | 52 ++++------ src/gui/painting/qpdfwriter.cpp | 8 +- src/gui/painting/qprintengine_pdf.cpp | 119 ++++++++++++---------- src/gui/painting/qprintengine_pdf_p.h | 34 ++++++- 6 files changed, 197 insertions(+), 196 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qwindowdefs.h b/src/gui/kernel/qwindowdefs.h index 3414c8cfc5..165b62da8f 100644 --- a/src/gui/kernel/qwindowdefs.h +++ b/src/gui/kernel/qwindowdefs.h @@ -76,7 +76,6 @@ class QBitmap; class QMovie; class QImage; class QPicture; -class QPrinter; class QTimer; class QTime; class QClipboard; diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index c5e93116eb..5f496777af 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -66,7 +66,20 @@ static const bool interpolateImages = false; QT_BEGIN_NAMESPACE -extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size); +inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features() +{ + QPaintEngine::PaintEngineFeatures f = QPaintEngine::AllFeatures; + f &= ~(QPaintEngine::PorterDuff | QPaintEngine::PerspectiveTransform + | QPaintEngine::ObjectBoundingModeGradients +#ifndef USE_NATIVE_GRADIENTS + | QPaintEngine::LinearGradientFill +#endif + | QPaintEngine::RadialGradientFill + | QPaintEngine::ConicalGradientFill); + return f; +} + + /* also adds a space at the end of the number */ const char *qt_real_to_string(qreal val, char *buf) { @@ -900,28 +913,6 @@ const char *QPdf::toHex(uchar u, char *buffer) return buffer; } -#define Q_MM(n) int((n * 720 + 127) / 254) -#define Q_IN(n) int(n * 72) - -static const char * const psToStr[QPrinter::NPaperSize+1] = -{ - "A4", "B5", "Letter", "Legal", "Executive", - "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1", - "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E", - "DLE", "Folio", "Ledger", "Tabloid", 0 -}; - -QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize) -{ - QSizeF s = qt_paperSizeToQSizeF(paperSize); - PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) }; - return p; -} - -const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize) -{ - return psToStr[paperSize]; -} QPdfPage::QPdfPage() : QPdf::ByteStream(true) // Enable file backing @@ -936,11 +927,23 @@ void QPdfPage::streamImage(int w, int h, int object) } -QPdfEngine::QPdfEngine(QPdfEnginePrivate &dd, PaintEngineFeatures f) - : QAlphaPaintEngine(dd, f) +QPdfEngine::QPdfEngine(QPdfEnginePrivate &dd) + : QAlphaPaintEngine(dd, qt_pdf_decide_features()) +{ +} + +QPdfEngine::QPdfEngine() + : QAlphaPaintEngine(*new QPdfEnginePrivate(), qt_pdf_decide_features()) +{ +} + +void QPdfEngine::setOutputFilename(const QString &filename) { + Q_D(QPdfEngine); + d->outputFileName = filename; } + void QPdfEngine::drawPoints (const QPointF *points, int pointCount) { if (!points) @@ -1368,7 +1371,7 @@ void QPdfEngine::setPen() Q_ASSERT(b.style() == Qt::SolidPattern && b.isOpaque()); QColor rgba = b.color(); - if (d->colorMode == QPrinter::GrayScale) { + if (d->grayscale) { qreal gray = qGray(rgba.rgba())/255.; *d->currentPage << gray << gray << gray; } else { @@ -1430,7 +1433,7 @@ void QPdfEngine::setBrush() *d->currentPage << (patternObject ? "/PCSp cs " : "/CSp cs "); if (specifyColor) { QColor rgba = d->brush.color(); - if (d->colorMode == QPrinter::GrayScale) { + if (d->grayscale) { qreal gray = qGray(rgba.rgba())/255.; *d->currentPage << gray << gray << gray; } else { @@ -1475,7 +1478,7 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const { Q_D(const QPdfEngine); int val; - QRect r = d->fullPage ? d->paperRect() : d->pageRect(); + QRect r = d->pageRect(); switch (metricType) { case QPaintDevice::PdmWidth: val = r.width(); @@ -1504,29 +1507,25 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const val = 32; break; default: - qWarning("QPrinter::metric: Invalid metric command"); + qWarning("QPdfWriter::metric: Invalid metric command"); return 0; } return val; } +#define Q_MM(n) int((n * 720 + 127) / 254) -QPdfEnginePrivate::QPdfEnginePrivate(QPrinter::PrinterMode m) +QPdfEnginePrivate::QPdfEnginePrivate() : clipEnabled(false), allClipped(false), hasPen(true), hasBrush(false), simplePen(false), useAlphaEngine(false), outDevice(0), fd(-1), - duplex(QPrinter::DuplexNone), collate(false), fullPage(false), embedFonts(true), copies(1), - pageOrder(QPrinter::FirstPageFirst), orientation(QPrinter::Portrait), - paperSize(QPrinter::A4), colorMode(QPrinter::Color), paperSource(QPrinter::Auto), - hasCustomPageMargins(false), - leftMargin(0), topMargin(0), rightMargin(0), bottomMargin(0) + fullPage(false), embedFonts(true), + landscape(false), + grayscale(false), + paperSize(Q_MM(210), Q_MM(297)), // A4 + leftMargin(10), topMargin(10), rightMargin(10), bottomMargin(10) // ~3.5 mm { - resolution = 72; - if (m == QPrinter::HighResolution) - resolution = 1200; - else if (m == QPrinter::ScreenResolution) - resolution = qt_defaultDpi(); - + resolution = 1200; postscript = false; currentObject = 1; currentPage = 0; @@ -1535,9 +1534,6 @@ QPdfEnginePrivate::QPdfEnginePrivate(QPrinter::PrinterMode m) streampos = 0; stream = new QDataStream; - pageOrder = QPrinter::FirstPageFirst; - orientation = QPrinter::Portrait; - fullPage = false; } bool QPdfEngine::begin(QPaintDevice *pdev) @@ -1545,6 +1541,19 @@ bool QPdfEngine::begin(QPaintDevice *pdev) Q_D(QPdfEngine); d->pdev = pdev; + if (!d->outDevice) { + if (!d->outputFileName.isEmpty()) { + QFile *file = new QFile(d->outputFileName); + if (!file->open(QFile::WriteOnly|QFile::Truncate)) { + delete file; + return false; + } + d->outDevice = file; + } else { + return false; + } + } + d->postscript = false; d->currentObject = 1; @@ -1589,6 +1598,19 @@ bool QPdfEngine::end() delete d->currentPage; d->currentPage = 0; + if (d->outDevice) { + d->outDevice->close(); + if (d->fd >= 0) + #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400 + ::_close(d->fd); + #else + ::close(d->fd); + #endif + d->fd = -1; + delete d->outDevice; + d->outDevice = 0; + } + setActive(false); return true; } @@ -1602,25 +1624,10 @@ QPdfEnginePrivate::~QPdfEnginePrivate() QRect QPdfEnginePrivate::paperRect() const { - int w; - int h; - if (paperSize == QPrinter::Custom) { - w = qRound(customPaperSize.width()*resolution/72.); - h = qRound(customPaperSize.height()*resolution/72.); - } else { - if (!cupsPaperRect.isNull()) { - QRect r = cupsPaperRect; - w = r.width(); - h = r.height(); - } else{ - QPdf::PaperSize s = QPdf::paperSize(paperSize); - w = s.width; - h = s.height; - } - w = qRound(w*resolution/72.); - h = qRound(h*resolution/72.); - } - if (orientation == QPrinter::Portrait) + int w = qRound(paperSize.width()*resolution/72.); + int h = qRound(paperSize.height()*resolution/72.); + + if (!landscape) return QRect(0, 0, w, h); else return QRect(0, 0, h, w); @@ -1628,46 +1635,14 @@ QRect QPdfEnginePrivate::paperRect() const QRect QPdfEnginePrivate::pageRect() const { - if(fullPage) - return paperRect(); + QRect r = paperRect(); - QRect r; - - if (!hasCustomPageMargins && !cupsPageRect.isNull()) { - r = cupsPageRect; - if (r == cupsPaperRect) { - // if cups doesn't define any margins, give it at least approx 3.5 mm - r = QRect(10, 10, r.width() - 20, r.height() - 20); - } - } else { - QPdf::PaperSize s; - if (paperSize == QPrinter::Custom) { - s.width = qRound(customPaperSize.width()); - s.height = qRound(customPaperSize.height()); - } else { - s = QPdf::paperSize(paperSize); - } - if (hasCustomPageMargins) - r = QRect(0, 0, s.width, s.height); - else - r = QRect(72/3, 72/3, s.width - 2*72/3, s.height - 2*72/3); - } - - int x = qRound(r.left()*resolution/72.); - int y = qRound(r.top()*resolution/72.); - int w = qRound(r.width()*resolution/72.); - int h = qRound(r.height()*resolution/72.); - if (orientation == QPrinter::Portrait) - r = QRect(x, y, w, h); - else - r = QRect(y, x, h, w); - - if (hasCustomPageMargins) { + if(!fullPage) r.adjust(qRound(leftMargin*(resolution/72.)), qRound(topMargin*(resolution/72.)), -qRound(rightMargin*(resolution/72.)), -qRound(bottomMargin*(resolution/72.))); - } + return r; } @@ -2437,7 +2412,7 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n bool hasAlpha = false; bool hasMask = false; - if (QImageWriter::supportedImageFormats().contains("jpeg") && colorMode != QPrinter::GrayScale) { + if (QImageWriter::supportedImageFormats().contains("jpeg") && !grayscale) { QBuffer buffer(&imageData); QImageWriter writer(&buffer, "jpeg"); writer.setQuality(94); @@ -2459,13 +2434,13 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n } } } else { - imageData.resize(colorMode == QPrinter::GrayScale ? w * h : 3 * w * h); + imageData.resize(grayscale ? w * h : 3 * w * h); uchar *data = (uchar *)imageData.data(); softMaskData.resize(w * h); uchar *sdata = (uchar *)softMaskData.data(); for (int y = 0; y < h; ++y) { const QRgb *rgb = (const QRgb *)image.scanLine(y); - if (colorMode == QPrinter::GrayScale) { + if (grayscale) { for (int x = 0; x < w; ++x) { *(data++) = qGray(*rgb); uchar alpha = qAlpha(*rgb); @@ -2511,7 +2486,7 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n } maskObject = writeImage(mask, w, h, 1, 0, 0); } - object = writeImage(imageData, w, h, colorMode == QPrinter::GrayScale ? 8 : 32, + object = writeImage(imageData, w, h, grayscale ? 8 : 32, maskObject, softMaskObject, dct); } imageCache.insert(serial_no, object); diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index e8d8dd9ef3..6cd0700554 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -60,16 +60,10 @@ #include "private/qfontengine_p.h" #include "private/qfontsubset_p.h" -// ### remove! -#include +// #define USE_NATIVE_GRADIENTS QT_BEGIN_NAMESPACE -#define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00) -#define PPK_CupsPageRect QPrintEngine::PrintEnginePropertyKey(0xfe01) -#define PPK_CupsPaperRect QPrintEngine::PrintEnginePropertyKey(0xfe02) -#define PPK_CupsStringPageSize QPrintEngine::PrintEnginePropertyKey(0xfe03) - const char *qt_real_to_string(qreal val, char *buf); const char *qt_int_to_string(int val, char *buf); @@ -147,13 +141,6 @@ namespace QPdf { const char *toHex(ushort u, char *buffer); const char *toHex(uchar u, char *buffer); - - struct PaperSize { - int width, height; // in postscript points - }; - Q_GUI_EXPORT PaperSize paperSize(QPrinter::PaperSize paperSize); - Q_GUI_EXPORT const char *paperSizeToString(QPrinter::PaperSize paperSize); - } @@ -181,9 +168,13 @@ class QPdfEngine : public QAlphaPaintEngine { Q_DECLARE_PRIVATE(QPdfEngine) public: - QPdfEngine(QPdfEnginePrivate &d, PaintEngineFeatures f); + QPdfEngine(); + QPdfEngine(QPdfEnginePrivate &d); ~QPdfEngine() {} + void setOutputFilename(const QString &filename); + inline void setResolution(int resolution); + // reimplementations QPaintEngine bool begin(QPaintDevice *pdev); bool end(); @@ -222,7 +213,7 @@ class QPdfEnginePrivate : public QAlphaPaintEnginePrivate { Q_DECLARE_PUBLIC(QPdfEngine) public: - QPdfEnginePrivate(QPrinter::PrinterMode m); + QPdfEnginePrivate(); ~QPdfEnginePrivate(); inline uint requestObject() { return currentObject++; } @@ -280,29 +271,16 @@ public: // printer options QString outputFileName; - QString printerName; - QString printProgram; - QString selectionOption; QString title; QString creator; - QPrinter::DuplexMode duplex; - bool collate; bool fullPage; bool embedFonts; - int copies; int resolution; - QPrinter::PageOrder pageOrder; - QPrinter::Orientation orientation; - QPrinter::PaperSize paperSize; - QPrinter::ColorMode colorMode; - QPrinter::PaperSource paperSource; - - QStringList cupsOptions; - QRect cupsPaperRect; - QRect cupsPageRect; - QString cupsStringPageSize; - QSizeF customPaperSize; // in postscript points - bool hasCustomPageMargins; + bool landscape; + bool grayscale; + + // in postscript points + QSizeF paperSize; qreal leftMargin, topMargin, rightMargin, bottomMargin; #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) @@ -346,6 +324,12 @@ private: QHash, uint > alphaCache; }; +void QPdfEngine::setResolution(int resolution) +{ + Q_D(QPdfEngine); + d->resolution = resolution; +} + QT_END_NAMESPACE #endif // QPDF_P_H diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 628dad38cd..7faebd6e83 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -41,7 +41,7 @@ #include #include -#include "private/qprintengine_pdf_p.h" +#include "private/qpdf_p.h" #include @@ -51,7 +51,7 @@ public: QPdfWriterPrivate() : QObjectPrivate() { - engine = new QPdfPrintEngine(QPrinter::HighResolution); + engine = new QPdfEngine(); output = 0; } ~QPdfWriterPrivate() @@ -60,7 +60,7 @@ public: delete output; } - QPdfPrintEngine *engine; + QPdfEngine *engine; QFile *output; }; @@ -69,7 +69,7 @@ QPdfWriter::QPdfWriter(const QString &filename) { Q_D(QPdfWriter); - d->engine->setProperty(QPrintEngine::PPK_OutputFileName, filename); + d->engine->setOutputFilename(filename); } QPdfWriter::QPdfWriter(QIODevice *device) diff --git a/src/gui/painting/qprintengine_pdf.cpp b/src/gui/painting/qprintengine_pdf.cpp index 2c1301c65a..df9a939e4b 100644 --- a/src/gui/painting/qprintengine_pdf.cpp +++ b/src/gui/painting/qprintengine_pdf.cpp @@ -52,12 +52,7 @@ #include #include -#if defined(Q_OS_WINCE) -#include "qwinfunctions_wince.h" -#endif - #include "qprintengine_pdf_p.h" -#include "private/qdrawhelper_p.h" #ifdef Q_OS_UNIX #include "private/qcore_unix_p.h" // overrides QT_OPEN @@ -67,22 +62,34 @@ QT_BEGIN_NAMESPACE //#define FONT_DUMP +extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size); + +#define Q_MM(n) int((n * 720 + 127) / 254) +#define Q_IN(n) int(n * 72) -inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features() +static const char * const psToStr[QPrinter::NPaperSize+1] = { - QPaintEngine::PaintEngineFeatures f = QPaintEngine::AllFeatures; - f &= ~(QPaintEngine::PorterDuff | QPaintEngine::PerspectiveTransform - | QPaintEngine::ObjectBoundingModeGradients -#ifndef USE_NATIVE_GRADIENTS - | QPaintEngine::LinearGradientFill -#endif - | QPaintEngine::RadialGradientFill - | QPaintEngine::ConicalGradientFill); - return f; + "A4", "B5", "Letter", "Legal", "Executive", + "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1", + "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E", + "DLE", "Folio", "Ledger", "Tabloid", 0 +}; + +QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize) +{ + QSizeF s = qt_paperSizeToQSizeF(paperSize); + PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) }; + return p; } +const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize) +{ + return psToStr[paperSize]; +} + + QPdfPrintEngine::QPdfPrintEngine(QPrinter::PrinterMode m) - : QPdfEngine(*new QPdfPrintEnginePrivate(m), qt_pdf_decide_features()) + : QPdfEngine(*new QPdfPrintEnginePrivate(m)) { Q_D(QPdfPrintEngine); #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) @@ -154,13 +161,14 @@ int QPdfPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { - Q_D(QPdfEngine); + Q_D(QPdfPrintEngine); + switch (int(key)) { case PPK_CollateCopies: d->collate = value.toBool(); break; case PPK_ColorMode: - d->colorMode = QPrinter::ColorMode(value.toInt()); + d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); break; case PPK_Creator: d->creator = value.toString(); @@ -176,7 +184,7 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->copies = value.toInt(); break; case PPK_Orientation: - d->orientation = QPrinter::Orientation(value.toInt()); + d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape); break; case PPK_OutputFileName: d->outputFileName = value.toString(); @@ -185,7 +193,8 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->pageOrder = QPrinter::PageOrder(value.toInt()); break; case PPK_PaperSize: - d->paperSize = QPrinter::PaperSize(value.toInt()); + d->printerPaperSize = QPrinter::PaperSize(value.toInt()); + d->updatePaperSize(); break; case PPK_PaperSource: d->paperSource = QPrinter::PaperSource(value.toInt()); @@ -221,8 +230,9 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->cupsStringPageSize = value.toString(); break; case PPK_CustomPaperSize: - d->paperSize = QPrinter::Custom; + d->printerPaperSize = QPrinter::Custom; d->customPaperSize = value.toSizeF(); + d->updatePaperSize(); break; case PPK_PageMargins: { @@ -232,7 +242,6 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->topMargin = margins.at(1).toReal(); d->rightMargin = margins.at(2).toReal(); d->bottomMargin = margins.at(3).toReal(); - d->hasCustomPageMargins = true; break; } default: @@ -242,7 +251,7 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const { - Q_D(const QPdfEngine); + Q_D(const QPdfPrintEngine); QVariant ret; switch (int(key)) { @@ -250,7 +259,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const ret = d->collate; break; case PPK_ColorMode: - ret = d->colorMode; + ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color; break; case PPK_Creator: ret = d->creator; @@ -281,7 +290,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const ret = d->copies; break; case PPK_Orientation: - ret = d->orientation; + ret = d->landscape ? QPrinter::Landscape : QPrinter::Portrait; break; case PPK_OutputFileName: ret = d->outputFileName; @@ -340,14 +349,8 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const case PPK_PageMargins: { QList margins; - if (d->hasCustomPageMargins) { - margins << d->leftMargin << d->topMargin - << d->rightMargin << d->bottomMargin; - } else { - const qreal defaultMargin = 10; // ~3.5 mm - margins << defaultMargin << defaultMargin - << defaultMargin << defaultMargin; - } + margins << d->leftMargin << d->topMargin + << d->rightMargin << d->bottomMargin; ret = margins; break; } @@ -382,7 +385,7 @@ static void closeAllOpenFds() bool QPdfPrintEnginePrivate::openPrintDevice() { - if(outDevice) + if (outDevice) return false; if (!outputFileName.isEmpty()) { @@ -470,13 +473,13 @@ bool QPdfPrintEnginePrivate::openPrintDevice() for (i = 0; i < lphack.size(); ++i) lpargs[i+1] = (char *)lphack.at(i).constData(); #ifndef Q_OS_OSF - if (QPdf::paperSizeToString(paperSize)) { + if (QPdf::paperSizeToString(printerPaperSize)) { char dash_o[] = "-o"; lpargs[++i] = dash_o; - lpargs[++i] = const_cast(QPdf::paperSizeToString(paperSize)); + lpargs[++i] = const_cast(QPdf::paperSizeToString(printerPaperSize)); lpargs[++i] = dash_o; media = "media="; - media += QPdf::paperSizeToString(paperSize); + media += QPdf::paperSizeToString(printerPaperSize); lpargs[++i] = media.data(); } #endif @@ -523,19 +526,6 @@ bool QPdfPrintEnginePrivate::openPrintDevice() void QPdfPrintEnginePrivate::closePrintDevice() { - if (!outDevice) - return; - outDevice->close(); - if (fd >= 0) -#if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400 - ::_close(fd); -#else - ::close(fd); -#endif - fd = -1; - delete outDevice; - outDevice = 0; - #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) if (!cupsTempFile.isEmpty()) { QString tempFile = cupsTempFile; @@ -575,7 +565,7 @@ void QPdfPrintEnginePrivate::closePrintDevice() switch(duplex) { case QPrinter::DuplexNone: break; case QPrinter::DuplexAuto: - if (orientation == QPrinter::Portrait) + if (!landscape) options.append(QPair("sides", "two-sided-long-edge")); else options.append(QPair("sides", "two-sided-short-edge")); @@ -589,7 +579,7 @@ void QPdfPrintEnginePrivate::closePrintDevice() } } - if (QCUPSSupport::cupsVersion() >= 10300 && orientation == QPrinter::Landscape) { + if (QCUPSSupport::cupsVersion() >= 10300 && landscape) { options.append(QPair("landscape", "")); } @@ -619,8 +609,19 @@ void QPdfPrintEnginePrivate::closePrintDevice() QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m) - : QPdfEnginePrivate(m) + : QPdfEnginePrivate(), + duplex(QPrinter::DuplexNone), + collate(false), + copies(1), + pageOrder(QPrinter::FirstPageFirst), + paperSource(QPrinter::Auto), + printerPaperSize(QPrinter::A4) { + resolution = 72; + if (m == QPrinter::HighResolution) + resolution = 1200; + else if (m == QPrinter::ScreenResolution) + resolution = qt_defaultDpi(); } QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate() @@ -628,6 +629,18 @@ QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate() } +void QPdfPrintEnginePrivate::updatePaperSize() +{ + if (printerPaperSize == QPrinter::Custom) { + paperSize = customPaperSize; + } else if (!cupsPaperRect.isNull()) { + QRect r = cupsPaperRect; + paperSize = r.size(); + } else{ + QPdf::PaperSize s = QPdf::paperSize(printerPaperSize); + paperSize = QSize(s.width, s.height); + } +} QT_END_NAMESPACE diff --git a/src/gui/painting/qprintengine_pdf_p.h b/src/gui/painting/qprintengine_pdf_p.h index 022f414ef8..367e3aebab 100644 --- a/src/gui/painting/qprintengine_pdf_p.h +++ b/src/gui/painting/qprintengine_pdf_p.h @@ -71,8 +71,6 @@ QT_BEGIN_NAMESPACE -// #define USE_NATIVE_GRADIENTS - class QImage; class QDataStream; class QPen; @@ -81,6 +79,20 @@ class QRegion; class QFile; class QPdfPrintEngine; +#define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00) +#define PPK_CupsPageRect QPrintEngine::PrintEnginePropertyKey(0xfe01) +#define PPK_CupsPaperRect QPrintEngine::PrintEnginePropertyKey(0xfe02) +#define PPK_CupsStringPageSize QPrintEngine::PrintEnginePropertyKey(0xfe03) + +namespace QPdf { + + struct PaperSize { + int width, height; // in postscript points + }; + Q_GUI_EXPORT PaperSize paperSize(QPrinter::PaperSize paperSize); + Q_GUI_EXPORT const char *paperSizeToString(QPrinter::PaperSize paperSize); +} + class QPdfPrintEnginePrivate; class QPdfPrintEngine : public QPdfEngine, public QPrintEngine @@ -121,9 +133,27 @@ public: bool openPrintDevice(); void closePrintDevice(); + void updatePaperSize(); + private: Q_DISABLE_COPY(QPdfPrintEnginePrivate) + QString printerName; + QString printProgram; + QString selectionOption; + QStringList cupsOptions; + QString cupsStringPageSize; + + QPrinter::DuplexMode duplex; + bool collate; + int copies; + QPrinter::PageOrder pageOrder; + QPrinter::PaperSource paperSource; + + QPrinter::PaperSize printerPaperSize; + QRect cupsPaperRect; + QRect cupsPageRect; + QSizeF customPaperSize; // in postscript points }; QT_END_NAMESPACE -- cgit v1.2.3