From 2406e98350fe02105124fc3cfd6aa4e5bf67bf7e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 23 Jan 2021 18:47:41 +0200 Subject: [PATCH] Add support for TIFF format. Closes smart-pattern/valentina#87 --- ChangeLog.txt | 1 + dist/AppImage/appimage.yml | 7 ++-- dist/OBS_debian/debian.control | 2 +- dist/OBS_debian/debian.valentina.1 | 5 ++- dist/debian/control | 2 +- dist/debian/valentina.1 | 5 ++- dist/rpm/valentina.spec | 4 +++ .../valentina/dialogs/dialogsavelayout.cpp | 8 +++++ src/app/valentina/mainwindowsnogui.cpp | 5 +++ src/libs/vlayout/vlayoutdef.h | 1 + src/libs/vlayout/vlayoutexporter.cpp | 33 +++++++++++++++++++ src/libs/vlayout/vlayoutexporter.h | 1 + 12 files changed, 67 insertions(+), 7 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index fb3747ffa..1051c7182 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,7 @@ - Improve restrict dimension dialog. Disable not available combinations. - Improve multisize measurements format. Allow excluding combinations inside min/max range. - New warning. Grainline is not valid. +- [smart-pattern/valentina#87] Add support for TIFF format. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/dist/AppImage/appimage.yml b/dist/AppImage/appimage.yml index 4198e18cb..1b8e5073f 100644 --- a/dist/AppImage/appimage.yml +++ b/dist/AppImage/appimage.yml @@ -44,9 +44,9 @@ build: # OPTIONAL: ingredient packages are packages which become part of the AppImage. # you may want to remove parts of their content in script section. -# ingredients: -# packages: -# - xterm + ingredients: + packages: + - libqt5-qtimageformats script: # OPTIONAL: compile or modify the AppDir. The environment variables: @@ -59,6 +59,7 @@ script: # create the image file - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH + - rm -rf /usr/share/licenses/libqt5-qtimageformats # bundle icu's data - mkdir -p $BUILD_APPDIR/usr/share/icu - cp /usr/share/icu/*/icudt*.dat $BUILD_APPDIR/usr/share/icu/ diff --git a/dist/OBS_debian/debian.control b/dist/OBS_debian/debian.control index 31a0b8ca4..a7c77f343 100644 --- a/dist/OBS_debian/debian.control +++ b/dist/OBS_debian/debian.control @@ -16,7 +16,7 @@ Vcs-Browser: https://gitlab.com/smart-pattern/valentina Package: valentina Architecture: i386 amd64 -Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.4.0) | libqt5core5 (>= 5.4.0), libqt5gui5 (>= 5.4.0) | libqt5gui5-gles (>= 5.4.0), libqt5printsupport5 (>= 5.4.0), libqt5svg5 (>= 5.4.0), libqt5widgets5 (>= 5.4.0), libqt5xml5 (>= 5.4.0), libqt5xmlpatterns5 (>= 5.4.0), libqt5concurrent5(>= 5.4.0), libqt5opengl5 (>= 5.4.0), libstdc++6 (>= 4.8), poppler-utils +Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.4.0) | libqt5core5 (>= 5.4.0), libqt5gui5 (>= 5.4.0) | libqt5gui5-gles (>= 5.4.0), libqt5printsupport5 (>= 5.4.0), libqt5svg5 (>= 5.4.0), libqt5widgets5 (>= 5.4.0), libqt5xml5 (>= 5.4.0), libqt5xmlpatterns5 (>= 5.4.0), libqt5concurrent5(>= 5.4.0), libqt5opengl5 (>= 5.4.0), libstdc++6 (>= 4.8), poppler-utils, qt5-image-formats-plugins (>= 5.4.0) Conflicts: seamly2d Description: Pattern making program. Valentina is a cross-platform patternmaking program which allows designers diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 44803fad8..caa1bc4a8 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -129,7 +129,10 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2013 ASTM файли (*.dxf) = 32," .RE .RS -.BR "*" " PDF tiled files (*.pdf) = 33." +.BR "*" " PDF tiled files (*.pdf) = 33," +.RE +.RS +.BR "*" " TIFF файли (*.tif) = 35." .RE .IP "--bdxf" .RB "Export dxf in binary form." diff --git a/dist/debian/control b/dist/debian/control index 31a0b8ca4..a7c77f343 100644 --- a/dist/debian/control +++ b/dist/debian/control @@ -16,7 +16,7 @@ Vcs-Browser: https://gitlab.com/smart-pattern/valentina Package: valentina Architecture: i386 amd64 -Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.4.0) | libqt5core5 (>= 5.4.0), libqt5gui5 (>= 5.4.0) | libqt5gui5-gles (>= 5.4.0), libqt5printsupport5 (>= 5.4.0), libqt5svg5 (>= 5.4.0), libqt5widgets5 (>= 5.4.0), libqt5xml5 (>= 5.4.0), libqt5xmlpatterns5 (>= 5.4.0), libqt5concurrent5(>= 5.4.0), libqt5opengl5 (>= 5.4.0), libstdc++6 (>= 4.8), poppler-utils +Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.4.0) | libqt5core5 (>= 5.4.0), libqt5gui5 (>= 5.4.0) | libqt5gui5-gles (>= 5.4.0), libqt5printsupport5 (>= 5.4.0), libqt5svg5 (>= 5.4.0), libqt5widgets5 (>= 5.4.0), libqt5xml5 (>= 5.4.0), libqt5xmlpatterns5 (>= 5.4.0), libqt5concurrent5(>= 5.4.0), libqt5opengl5 (>= 5.4.0), libstdc++6 (>= 4.8), poppler-utils, qt5-image-formats-plugins (>= 5.4.0) Conflicts: seamly2d Description: Pattern making program. Valentina is a cross-platform patternmaking program which allows designers diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 44803fad8..caa1bc4a8 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -129,7 +129,10 @@ The path to output destination folder. By default the directory at which the app .BR "*" " AutoCAD DXF 2013 ASTM файли (*.dxf) = 32," .RE .RS -.BR "*" " PDF tiled files (*.pdf) = 33." +.BR "*" " PDF tiled files (*.pdf) = 33," +.RE +.RS +.BR "*" " TIFF файли (*.tif) = 35." .RE .IP "--bdxf" .RB "Export dxf in binary form." diff --git a/dist/rpm/valentina.spec b/dist/rpm/valentina.spec index 459fb1125..dbd956bba 100644 --- a/dist/rpm/valentina.spec +++ b/dist/rpm/valentina.spec @@ -43,6 +43,8 @@ BuildRequires: libproxy-pacrunner BuildRequires: qttools5 BuildRequires: qtbase5-common-devel >= 5.4.0 +Requires: qtimageformats5 + %if 0%{?mageia} == 6 BuildRequires: pkgconfig(openssl) %else @@ -58,6 +60,8 @@ BuildRequires: libqt5-qttools BuildRequires: libQt5Svg-devel BuildRequires: update-desktop-files +Requires: libqt5-qtimageformats + %if 0%{?suse_version} == 1310 BuildRequires: libQt5XmlPatterns-devel %endif diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index f40ed931f..295e6b48b 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -235,6 +235,7 @@ void DialogSaveLayout::SetBinaryDXFFormat(bool binary) case LayoutExportFormats::PS: case LayoutExportFormats::EPS: case LayoutExportFormats::NC: + case LayoutExportFormats::TIF: default: ui->checkBoxBinaryDXF->setChecked(false); break; @@ -282,6 +283,7 @@ bool DialogSaveLayout::IsBinaryDXFFormat() const case LayoutExportFormats::PS: case LayoutExportFormats::EPS: case LayoutExportFormats::NC: + case LayoutExportFormats::TIF: default: return false; } @@ -421,6 +423,8 @@ QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format) return QStringLiteral("PDF %1 %2 (*.pdf)").arg(tr("tiled"), filesStr); case LayoutExportFormats::NC: return QStringLiteral("%1 %2 (*.nc)").arg(tr("Numerical control"), filesStr); + case LayoutExportFormats::TIF: + return QStringLiteral("TIFF %1 (*.tif)").arg(filesStr); default: return QString(); } @@ -474,6 +478,8 @@ QString DialogSaveLayout::ExportFormatSuffix(LayoutExportFormats format) return QStringLiteral(".dxf"); case LayoutExportFormats::NC: return QStringLiteral(".nc"); + case LayoutExportFormats::TIF: + return QStringLiteral(".tif"); default: return QString(); } @@ -606,6 +612,7 @@ void DialogSaveLayout::ShowExample() case LayoutExportFormats::PS: case LayoutExportFormats::EPS: case LayoutExportFormats::NC: + case LayoutExportFormats::TIF: default: break; } @@ -843,6 +850,7 @@ QVector > DialogSaveLayout::InitFormats( InitFormat(LayoutExportFormats::DXF_AC1027_ASTM); InitFormat(LayoutExportFormats::PDFTiled); // InitFormat(LayoutExportFormats::NC); + InitFormat(LayoutExportFormats::TIF); return list; } diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 20f9ce3be..e099ce634 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1200,6 +1200,11 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; + case LayoutExportFormats::TIF: + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToTIF(scene); + break; default: qDebug() << "Can't recognize file type." << Q_FUNC_INFO; break; diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 17db1fa6f..f9d041cd1 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -73,6 +73,7 @@ enum class LayoutExportFormats : qint8 DXF_AC1027_ASTM = 32, /* ACAD 2013. */ PDFTiled = 33, NC = 34, /*G-code. Reserved for future*/ + TIF = 35, COUNT /*Use only for validation*/ }; diff --git a/src/libs/vlayout/vlayoutexporter.cpp b/src/libs/vlayout/vlayoutexporter.cpp index 381b74d5c..9ffceca45 100644 --- a/src/libs/vlayout/vlayoutexporter.cpp +++ b/src/libs/vlayout/vlayoutexporter.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "../vmisc/vmath.h" #include "../vmisc/defglobal.h" @@ -169,6 +170,38 @@ void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const image.save(m_fileName); } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToTIF(QGraphicsScene *scene) const +{ + // Create the image with the exact size of the shrunk scene + QSize drawingSize; + drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); + drawingSize.setHeight(qFloor(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom())); + + QImage image(drawingSize, QImage::Format_ARGB32); + image.fill(Qt::white); + + QPainter painter(&image); + painter.translate(m_margins.left(), m_margins.top()); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(m_pen); + painter.setBrush(QBrush(Qt::NoBrush)); + painter.scale(m_xScale, m_yScale); + + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + + QImageWriter writer; + writer.setFormat("TIF"); + writer.setCompression(1); // LZW-compression + writer.setFileName(m_fileName); + + if (not writer.write(image)) + { // failed to save file + qCritical() << qUtf8Printable(tr("Can't save file '%1'. Error: %2.").arg(m_fileName, writer.errorString())); + return; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutExporter::ExportToPDF(QGraphicsScene *scene) const { diff --git a/src/libs/vlayout/vlayoutexporter.h b/src/libs/vlayout/vlayoutexporter.h index 182e216dd..af7f8b85d 100644 --- a/src/libs/vlayout/vlayoutexporter.h +++ b/src/libs/vlayout/vlayoutexporter.h @@ -79,6 +79,7 @@ public: void ExportToSVG(QGraphicsScene *scene) const; void ExportToPNG(QGraphicsScene *scene) const; + void ExportToTIF(QGraphicsScene *scene) const; void ExportToPDF(QGraphicsScene *scene) const; void ExportToOBJ(QGraphicsScene *scene) const; void ExportToPS(QGraphicsScene *scene) const;