From a7332adc7510733439f657ce53f3f43b51d8800e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 3 Jan 2019 19:33:15 +0200 Subject: [PATCH] When export to SVG or PNG file apply margins. --HG-- branch : develop --- src/app/valentina/mainwindowsnogui.cpp | 29 ++++++++++++++++---------- src/app/valentina/mainwindowsnogui.h | 4 ++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 3a6e49e03..711e434ca 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -913,22 +913,26 @@ QList MainWindowsNoGUI::CreateScenes(const QListrect(); QSvgGenerator generator; generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setViewBox(paper->rect()); + generator.setSize(QSize(qFloor(r.width() + margins.left() + margins.right()), + qFloor(r.height() + margins.top() + margins.bottom()))); + generator.setViewBox(QRectF(0, 0, r.width() + margins.left() + margins.right(), + r.height() + margins.top() + margins.bottom())); generator.setTitle(tr("Pattern")); generator.setDescription(doc->GetDescription().toHtmlEscaped()); generator.setResolution(static_cast(PrintDPI)); QPainter painter; painter.begin(&generator); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.translate(margins.left(), margins.top()); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); + scene->render(&painter, r, r, Qt::IgnoreAspectRatio); painter.end(); } @@ -937,14 +941,17 @@ void MainWindowsNoGUI::SvgFile(const QString &name, QGraphicsRectItem *paper, QG * @brief PngFile save layout to png file. * @param name name layout file. */ -void MainWindowsNoGUI::PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene) const +void MainWindowsNoGUI::PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, + const QMarginsF &margins) const { const QRectF r = paper->rect(); // Create the image with the exact size of the shrunk scene - QImage image(r.size().toSize(), QImage::Format_ARGB32); - image.fill(Qt::transparent); // Start all pixels transparent + QImage image(QSize(qFloor(r.width() + margins.left() + margins.right()), + qFloor(r.height() + margins.top() + margins.bottom())), + QImage::Format_ARGB32); + image.fill(Qt::white); QPainter painter(&image); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.translate(margins.left(), margins.top()); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); @@ -1572,14 +1579,14 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, { case LayoutExportFormats::SVG: paper->setVisible(false); - SvgFile(name, paper, scene); + SvgFile(name, paper, scene, margins); paper->setVisible(true); break; case LayoutExportFormats::PDF: PdfFile(name, paper, scene, ignorePrinterFields, margins); break; case LayoutExportFormats::PNG: - PngFile(name, paper, scene); + PngFile(name, paper, scene, margins); break; case LayoutExportFormats::OBJ: paper->setVisible(false); diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index e9f6b6380..5892d2f61 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -139,8 +139,8 @@ private: const QList &shadows, const QList > &details); - void SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; - void PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; + void SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const; + void PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const; void PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, const QMarginsF &margins)const; void PdfTiledFile(const QString &name);