Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix Advanced Export of the image with filter masks or layer styles
Dmitry Kazakov9c5277ffe06b
diff --git a/libs/ui/KisImportExportManager.cpp b/libs/ui/KisImportExportManager.cppindex ca64c2ed10..5443682067 100644--- a/libs/ui/KisImportExportManager.cpp+++ b/libs/ui/KisImportExportManager.cpp@@ -59,6 +59,8 @@#include "kis_config.h"#include "kis_grid_config.h"#include "kis_guides_config.h"+#include <kis_adjustment_layer.h>+#include <kis_filter_mask.h>#include <KisImportUserFeedbackInterface.h>@@ -591,6 +593,41 @@ bool KisImportExportManager::askUserAboutExportConfiguration(warnings.append(i18nc("image conversion warning", "The image contains a <b>custom grid configuration</b>. The configuration will not be saved."));}+ bool shouldFlattenTheImageBeforeScaling = false;++ if (isAdvancedExporting) {+ QMap<QString, KisExportCheckBase *> exportChecks = filter->exportChecks();++ const bool filterSupportsMultilayerExport =+ exportChecks.contains("MultiLayerCheck") &&+ exportChecks["MultiLayerCheck"]->checkNeeded(m_document->image()) &&+ exportChecks["MultiLayerCheck"]->check(m_document->image()) == KisExportCheckBase::SUPPORTED;++ if (!filterSupportsMultilayerExport) {+ shouldFlattenTheImageBeforeScaling = true;+ } else {+ if (KisLayerUtils::findNodeByType<KisAdjustmentLayer>(m_document->image()->root())) {+ shouldFlattenTheImageBeforeScaling = true;+ warnings.append(i18nc("image conversion warning", "Trying to perform an Advanced Export with the image containing a <b>filter layer</b>. The image will be <b>flattened<b> before resizing."));+ }+ if (KisLayerUtils::findNodeByType<KisFilterMask>(m_document->image()->root())) {+ shouldFlattenTheImageBeforeScaling = true;+ warnings.append(i18nc("image conversion warning", "Trying to perform an Advanced Export with the image containing a <b>filter mask</b>. The image will be <b>flattened<b> before resizing."));+ }+ bool hasLayerStyles =+ KisLayerUtils::recursiveFindNode(m_document->image()->root(),+ [] (KisNodeSP node) {+ KisLayer *layer = dynamic_cast<KisLayer*>(node.data());+ return layer && layer->layerStyle();+ });++ if (hasLayerStyles) {+ shouldFlattenTheImageBeforeScaling = true;+ warnings.append(i18nc("image conversion warning", "Trying to perform an Advanced Export with the image containing a <b>layer style</b>. The image will be <b>flattened<b> before resizing."));+ }+ }+ }+if (!batchMode && !errors.isEmpty()) {QString error = "<html><body><p><b>"+ i18n("Error: cannot save this image as a %1.", mimeUserDescription)@@ -690,6 +727,11 @@ bool KisImportExportManager::askUserAboutExportConfiguration(}if(isAdvancedExporting) {+ if (shouldFlattenTheImageBeforeScaling) {+ m_document->savingImage()->flatten(KisNodeSP());+ m_document->savingImage()->waitForDone();+ }+const QSize desiredSize(dlgImageSize->desiredWidth(), dlgImageSize->desiredHeight());double res = dlgImageSize->desiredResolution();m_document->savingImage()->scaleImage(desiredSize,res,res,dlgImageSize->filterType());diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cppindex 27e6e828ff..4d4fa3500d 100644--- a/libs/ui/KisMainWindow.cpp+++ b/libs/ui/KisMainWindow.cpp@@ -1430,7 +1430,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo}}else { // Export- ret = document->exportDocument(newFilePath, outputFormat, isAdvancedExporting);+ ret = document->exportDocument(newFilePath, outputFormat, isAdvancedExporting, true);if (ret) {d->lastExportLocation = newFilePath;d->lastExportedFormat = outputFormat;