diff options
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qpagesize.h | 1 | ||||
-rw-r--r-- | src/gui/painting/qpdf.cpp | 104 | ||||
-rw-r--r-- | src/gui/painting/qpdf_p.h | 39 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.cpp | 10 |
4 files changed, 72 insertions, 82 deletions
diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h index c8a472747d..2e88d497a9 100644 --- a/src/gui/painting/qpagesize.h +++ b/src/gui/painting/qpagesize.h @@ -290,6 +290,7 @@ public: private: friend class QPageSizePrivate; friend class QPlatformPrintDevice; + friend class QCupsPrintEnginePrivate; QPageSize(const QString &key, const QSize &pointSize, const QString &name); QPageSize(int windowsId, const QSize &pointSize, const QString &name); QPageSize(QPageSizePrivate &dd); diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 147fa3f561..56cfc0f707 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1425,19 +1425,60 @@ QPaintEngine::Type QPdfEngine::type() const return QPaintEngine::Pdf; } +void QPdfEngine::setResolution(int resolution) +{ + Q_D(QPdfEngine); + d->resolution = resolution; +} + +int QPdfEngine::resolution() const +{ + Q_D(const QPdfEngine); + return d->resolution; +} + +void QPdfEngine::setPageLayout(const QPageLayout &pageLayout) +{ + Q_D(QPdfEngine); + d->m_pageLayout = pageLayout; +} +void QPdfEngine::setPageSize(const QPageSize &pageSize) +{ + Q_D(QPdfEngine); + d->m_pageLayout.setPageSize(pageSize); +} + +void QPdfEngine::setPageOrientation(QPageLayout::Orientation orientation) +{ + Q_D(QPdfEngine); + d->m_pageLayout.setOrientation(orientation); +} + +void QPdfEngine::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) +{ + Q_D(QPdfEngine); + d->m_pageLayout.setUnits(units); + d->m_pageLayout.setMargins(margins); +} +QPageLayout QPdfEngine::pageLayout() const +{ + Q_D(const QPdfEngine); + return d->m_pageLayout; +} + +// Metrics are in Device Pixels int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const { Q_D(const QPdfEngine); int val; - QRect r = d->pageRect(); switch (metricType) { case QPaintDevice::PdmWidth: - val = r.width(); + val = d->m_pageLayout.paintRectPixels(d->resolution).width(); break; case QPaintDevice::PdmHeight: - val = r.height(); + val = d->m_pageLayout.paintRectPixels(d->resolution).height(); break; case QPaintDevice::PdmDpiX: case QPaintDevice::PdmDpiY: @@ -1448,10 +1489,10 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const val = 1200; break; case QPaintDevice::PdmWidthMM: - val = qRound(r.width()*25.4/d->resolution); + val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).width()); break; case QPaintDevice::PdmHeightMM: - val = qRound(r.height()*25.4/d->resolution); + val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).height()); break; case QPaintDevice::PdmNumColors: val = INT_MAX; @@ -1469,21 +1510,12 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const return val; } -static inline QSizeF pageSizeToPostScriptPoints(const QSizeF &pageSizeMM) -{ -#define Q_MM(n) int((n * 720 + 127) / 254) - return QSizeF(Q_MM(pageSizeMM.width()), Q_MM(pageSizeMM.height())); -#undef Q_MM -} - QPdfEnginePrivate::QPdfEnginePrivate() : clipEnabled(false), allClipped(false), hasPen(true), hasBrush(false), simplePen(false), outDevice(0), ownsDevice(false), - fullPage(false), embedFonts(true), - landscape(false), + embedFonts(true), grayscale(false), - paperSize(pageSizeToPostScriptPoints(QSizeF(210, 297))), // A4 - leftMargin(10), topMargin(10), rightMargin(10), bottomMargin(10) // ~3.5 mm + m_pageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(10, 10, 10, 10)) { resolution = 1200; currentObject = 1; @@ -1495,11 +1527,6 @@ QPdfEnginePrivate::QPdfEnginePrivate() stream = new QDataStream; } -void QPdfEnginePrivate::setPaperSize(const QSizeF &pageSizeMM) -{ - paperSize = pageSizeToPostScriptPoints(pageSizeMM); -} - bool QPdfEngine::begin(QPaintDevice *pdev) { Q_D(QPdfEngine); @@ -1581,31 +1608,6 @@ QPdfEnginePrivate::~QPdfEnginePrivate() delete stream; } -QRect QPdfEnginePrivate::paperRect() const -{ - 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); -} - -QRect QPdfEnginePrivate::pageRect() const -{ - QRect r = paperRect(); - - if(!fullPage) - r.adjust(qRound(leftMargin*(resolution/72.)), - qRound(topMargin*(resolution/72.)), - -qRound(rightMargin*(resolution/72.)), - -qRound(bottomMargin*(resolution/72.))); - - return r; -} - - void QPdfEnginePrivate::writeHeader() { addXrefEntry(0,false); @@ -2615,9 +2617,9 @@ void QPdfEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &ti) QTransform QPdfEnginePrivate::pageMatrix() const { qreal scale = 72./resolution; - QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, height()); - if (!fullPage) { - QRect r = pageRect(); + QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, m_pageLayout.fullRectPoints().height()); + if (m_pageLayout.mode() != QPageLayout::FullPageMode) { + QRect r = m_pageLayout.paintRectPixels(resolution); tmp.translate(r.left(), r.top()); } return tmp; @@ -2626,12 +2628,12 @@ QTransform QPdfEnginePrivate::pageMatrix() const void QPdfEnginePrivate::newPage() { if (currentPage && currentPage->pageSize.isEmpty()) - currentPage->pageSize = QSize(width(), height()); + currentPage->pageSize = m_pageLayout.fullRectPoints().size(); writePage(); delete currentPage; currentPage = new QPdfPage; - currentPage->pageSize = QSize(width(), height()); + currentPage->pageSize = m_pageLayout.fullRectPoints().size(); stroker.stream = currentPage; pages.append(requestObject()); diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index ae2d4b00ac..e9459eff83 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -64,6 +64,7 @@ #include "private/qpaintengine_p.h" #include "private/qfontengine_p.h" #include "private/qfontsubset_p.h" +#include "qpagelayout.h" // #define USE_NATIVE_GRADIENTS @@ -179,7 +180,9 @@ public: ~QPdfEngine() {} void setOutputFilename(const QString &filename); - inline void setResolution(int resolution); + + void setResolution(int resolution); + int resolution() const; // reimplementations QPaintEngine bool begin(QPaintDevice *pdev); @@ -207,6 +210,14 @@ public: // Printer stuff... bool newPage(); + // Page layout stuff + void setPageLayout(const QPageLayout &pageLayout); + void setPageSize(const QPageSize &pageSize); + void setPageOrientation(QPageLayout::Orientation orientation); + void setPageMargins(const QMarginsF &margins, QPageLayout::Unit units = QPageLayout::Point); + + QPageLayout pageLayout() const; + void setPen(); void setBrush(); void setupGraphicsState(QPaintEngine::DirtyFlags flags); @@ -224,19 +235,6 @@ public: inline uint requestObject() { return currentObject++; } - QRect paperRect() const; - QRect pageRect() const; - void setPaperSize(const QSizeF &pageSizeMM); - - int width() const { - QRect r = paperRect(); - return qRound(r.width()*72./resolution); - } - int height() const { - QRect r = paperRect(); - return qRound(r.height()*72./resolution); - } - void writeHeader(); void writeTail(); @@ -278,15 +276,12 @@ public: QString outputFileName; QString title; QString creator; - bool fullPage; bool embedFonts; int resolution; - bool landscape; bool grayscale; - // in postscript points - QSizeF paperSize; - qreal leftMargin, topMargin, rightMargin, bottomMargin; + // Page layout: size, orientation and margins + QPageLayout m_pageLayout; private: #ifdef USE_NATIVE_GRADIENTS @@ -325,12 +320,6 @@ private: QHash<QPair<uint, uint>, uint > alphaCache; }; -void QPdfEngine::setResolution(int resolution) -{ - Q_D(QPdfEngine); - d->resolution = resolution; -} - QT_END_NAMESPACE #endif // QT_NO_PDF diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 27fb8b1646..a6f752b129 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -166,7 +166,7 @@ void QPdfWriter::setPageSize(PageSize size) Q_D(const QPdfWriter); QPagedPaintDevice::setPageSize(size); - d->engine->d_func()->setPaperSize(pageSizeMM()); + d->engine->setPageSize(QPageSize(QPageSize::PageSizeId(size))); } /*! @@ -177,7 +177,7 @@ void QPdfWriter::setPageSizeMM(const QSizeF &size) Q_D(const QPdfWriter); QPagedPaintDevice::setPageSizeMM(size); - d->engine->d_func()->setPaperSize(pageSizeMM()); + d->engine->setPageSize(QPageSize(size, QPageSize::Millimeter)); } /*! @@ -212,10 +212,8 @@ void QPdfWriter::setMargins(const Margins &m) QPagedPaintDevice::setMargins(m); const qreal multiplier = 72./25.4; - d->engine->d_func()->leftMargin = m.left*multiplier; - d->engine->d_func()->rightMargin = m.right*multiplier; - d->engine->d_func()->topMargin = m.top*multiplier; - d->engine->d_func()->bottomMargin = m.bottom*multiplier; + d->engine->setPageMargins(QMarginsF(m.left * multiplier, m.top * multiplier, + m.right * multiplier, m.bottom * multiplier), QPageLayout::Point); } QT_END_NAMESPACE |