QPdfWriter: Fix setting of paper size.
Introduce setter for converting mm to Postscript points. Task-number: QTBUG-31443 Change-Id: I032118322657ae2a8b3b457010218d6ea3f3e720 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
aae0a2144d
commit
3dde073269
@ -1469,7 +1469,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),
|
||||
@ -1477,7 +1482,7 @@ QPdfEnginePrivate::QPdfEnginePrivate()
|
||||
fullPage(false), embedFonts(true),
|
||||
landscape(false),
|
||||
grayscale(false),
|
||||
paperSize(Q_MM(210), Q_MM(297)), // A4
|
||||
paperSize(pageSizeToPostScriptPoints(QSizeF(210, 297))), // A4
|
||||
leftMargin(10), topMargin(10), rightMargin(10), bottomMargin(10) // ~3.5 mm
|
||||
{
|
||||
resolution = 1200;
|
||||
@ -1491,6 +1496,11 @@ QPdfEnginePrivate::QPdfEnginePrivate()
|
||||
stream = new QDataStream;
|
||||
}
|
||||
|
||||
void QPdfEnginePrivate::setPaperSize(const QSizeF &pageSizeMM)
|
||||
{
|
||||
paperSize = pageSizeToPostScriptPoints(pageSizeMM);
|
||||
}
|
||||
|
||||
bool QPdfEngine::begin(QPaintDevice *pdev)
|
||||
{
|
||||
Q_D(QPdfEngine);
|
||||
|
@ -226,6 +226,7 @@ public:
|
||||
|
||||
QRect paperRect() const;
|
||||
QRect pageRect() const;
|
||||
void setPaperSize(const QSizeF &pageSizeMM);
|
||||
|
||||
int width() const {
|
||||
QRect r = paperRect();
|
||||
|
@ -166,7 +166,7 @@ void QPdfWriter::setPageSize(PageSize size)
|
||||
Q_D(const QPdfWriter);
|
||||
|
||||
QPagedPaintDevice::setPageSize(size);
|
||||
d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
|
||||
d->engine->d_func()->setPaperSize(pageSizeMM());
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -177,7 +177,7 @@ void QPdfWriter::setPageSizeMM(const QSizeF &size)
|
||||
Q_D(const QPdfWriter);
|
||||
|
||||
QPagedPaintDevice::setPageSizeMM(size);
|
||||
d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
|
||||
d->engine->d_func()->setPaperSize(pageSizeMM());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user