Don't set PdfWriter margins to 0
(just for plaintext for now)
This commit is contained in:
parent
be390c450c
commit
45da184f53
1 changed files with 14 additions and 3 deletions
|
@ -461,8 +461,11 @@ try {
|
||||||
QPageSize pageSize(QSizeF {wh.first, wh.second}, QPageSize::Millimeter);
|
QPageSize pageSize(QSizeF {wh.first, wh.second}, QPageSize::Millimeter);
|
||||||
pdfWriter.setPageSize(pageSize);
|
pdfWriter.setPageSize(pageSize);
|
||||||
pdfWriter.setResolution(resolution);
|
pdfWriter.setResolution(resolution);
|
||||||
// Needs to be before painter
|
|
||||||
pdfWriter.setMargins({0, 0, 0, 0});
|
QPagedPaintDevice::Margins tmpMargins = pdfWriter.margins();
|
||||||
|
qDebug() << tmpMargins.top << tmpMargins.right << tmpMargins.bottom << tmpMargins.left;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qreal docHeight = pageSize.sizePixels(resolution).height();
|
qreal docHeight = pageSize.sizePixels(resolution).height();
|
||||||
|
|
||||||
|
@ -494,17 +497,25 @@ try {
|
||||||
|
|
||||||
int textHeight = 60*charHeight;
|
int textHeight = 60*charHeight;
|
||||||
qreal margin = ((docHeight-textHeight)/2);
|
qreal margin = ((docHeight-textHeight)/2);
|
||||||
|
qreal mmMargin = margin/(resolution/25.4);
|
||||||
|
|
||||||
doc.setDefaultFont(font);
|
doc.setDefaultFont(font);
|
||||||
(void)doc.documentLayout(); // wat
|
(void)doc.documentLayout(); // wat
|
||||||
|
|
||||||
|
|
||||||
|
// Needs to be before painter
|
||||||
|
pdfWriter.setMargins({mmMargin, mmMargin, mmMargin, mmMargin});
|
||||||
|
|
||||||
QPainter painter(&pdfWriter);
|
QPainter painter(&pdfWriter);
|
||||||
|
|
||||||
doc.documentLayout()->setPaintDevice(painter.device());
|
doc.documentLayout()->setPaintDevice(painter.device());
|
||||||
doc.setDocumentMargin(margin);
|
doc.setDocumentMargin(margin);
|
||||||
|
|
||||||
QRectF body = QRectF(0, 0, pdfWriter.width(), pdfWriter.height());
|
// Hack to make the document and pdfWriter margins overlap
|
||||||
|
// Apparently calls to painter.translate() stack... who knew!
|
||||||
|
painter.translate(-margin, -margin);
|
||||||
|
|
||||||
|
QRectF body = pageSize.rectPixels(resolution);
|
||||||
doc.setPageSize(body.size());
|
doc.setPageSize(body.size());
|
||||||
|
|
||||||
QString allText = inFile.readAll();
|
QString allText = inFile.readAll();
|
||||||
|
|
Loading…
Reference in a new issue