Skip to content

Commit 3aeae90

Browse files
trdthgjdupak
authored andcommitted
GUI: scale to fit page size when printing pdf
1 parent f951a99 commit 3aeae90

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/gui/mainwindow/mainwindow.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void MainWindow::print_action() {
370370
QRectF paint_rect = layout.paintRect(QPageLayout::Point);
371371
QSize pointsize = pagesize.sizePoints();
372372
qreal ratio = scene_rect.width() / scene_rect.height();
373+
// Cut off the excess
373374
if (paint_rect.height() * ratio > paint_rect.width()) {
374375
pointsize.setHeight(
375376
pointsize.height() - paint_rect.height() + paint_rect.width() / ratio);
@@ -383,6 +384,12 @@ void MainWindow::print_action() {
383384
}
384385

385386
QPainter painter(&printer);
387+
// scale to fit paint size
388+
QRectF paint_rect = printer.pageLayout().paintRect(QPageLayout::Millimeter);
389+
double xscale = paint_rect.width() / scene_as_vector.widthMM();
390+
double yscale = paint_rect.height() / scene_as_vector.heightMM();
391+
double scale = qMin(xscale, yscale);
392+
painter.scale(scale, scale);
386393
painter.drawPicture(0, 0, scene_as_vector);
387394
painter.end();
388395
}

0 commit comments

Comments
 (0)