Skip to content

armgit / krita

Public Imported from GitHub
0

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++

psd vectors: Implement export checks for shapes and guides.

Wolthera van Hövell tot Westerflierbc79224aa30f
diff --git a/libs/impex/KisExportCheckRegistry.cpp b/libs/impex/KisExportCheckRegistry.cpp
index 3a32020544..96ada1f17c 100644
--- a/libs/impex/KisExportCheckRegistry.cpp
+++ b/libs/impex/KisExportCheckRegistry.cpp
@@ -28,6 +28,7 @@
#include <NodeTypeCheck.h>
#include <PSDLayerStylesCheck.h>
#include <sRGBProfileCheck.h>
+#include <ShapeLayerTypeCheck.h>
#include <QGlobalStatic>
@@ -133,6 +134,24 @@ KisExportCheckRegistry::KisExportCheckRegistry ()
chkFactory = new FillLayerTypeCheckFactory(generatorId);
add(chkFactory->id(), chkFactory);
}
+
+ // Vector shapes
+ chkFactory = new ShapeLayerTypeCheckFactory("KoPathShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoPathShape", "RectangleShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoPathShape", "EllipseShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoPathShape", "StarShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoPathShape", "SpiralShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("ImageShape");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoShapeGroup");
+ add(chkFactory->id(), chkFactory);
+ chkFactory = new ShapeLayerTypeCheckFactory("KoSvgTextShapeID");
+ add(chkFactory->id(), chkFactory);
}
KisExportCheckRegistry::~KisExportCheckRegistry ()
diff --git a/libs/impex/ShapeLayerTypeCheck.h b/libs/impex/ShapeLayerTypeCheck.h
new file mode 100644
index 0000000000..e062ca3f8a
--- /dev/null
+++ b/libs/impex/ShapeLayerTypeCheck.h
@@ -0,0 +1,168 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: LGPL-2.0-or-later
+ */
+
+#ifndef SHAPELAYERTYPECHECK_H
+#define SHAPELAYERTYPECHECK_H
+
+
+#include "KisExportCheckRegistry.h"
+#include <KoID.h>
+#include <klocalizedstring.h>
+#include <kis_assert.h>
+#include <kis_image.h>
+#include <kis_generator_registry.h>
+#include <kis_node_visitor.h>
+#include <kis_group_layer.h>
+#include <KoShapeLayer.h>
+#include <KoShapeGroup.h>
+#include <KoPathShape.h>
+
+class ShapeLayerTypeCheckVisitor : public KisNodeVisitor
+{
+public:
+
+ using KisNodeVisitor::visit;
+
+ ShapeLayerTypeCheckVisitor (QString shapeId, QString pathId)
+ : m_count(0)
+ , m_shapeId(shapeId)
+ , m_pathShapeId(pathId)
+ {
+ }
+
+ quint32 count() {
+ return m_count;
+ }
+
+ bool visit(KisNode*) override {return true;}
+
+ bool visit(KisPaintLayer *) override {return true;}
+
+ bool visit(KisGroupLayer *layer) override {
+ return visitAll(layer);
+ }
+
+
+ bool visit(KisAdjustmentLayer *) override {return true;}
+
+ bool visit(KisExternalLayer * layer) override {
+ if (KoShapeLayer *shapeLayer = dynamic_cast<KoShapeLayer*>(layer)) {
+ check(shapeLayer->shapes());
+ }
+ return true;
+ }
+
+ bool visit(KisCloneLayer *) override {return true;}
+
+ bool visit(KisGeneratorLayer *) override {return true;}
+
+ bool visit(KisFilterMask *) override {return true;}
+
+ bool visit(KisTransformMask *) override {return true;}
+
+ bool visit(KisTransparencyMask *) override {return true;}
+
+ bool visit(KisSelectionMask *) override {return true;}
+
+ bool visit(KisColorizeMask *) override {return true;}
+
+
+
+private:
+ bool check(QList<KoShape*> shapes) {
+ Q_FOREACH(KoShape* shape, shapes) {
+ if (KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape)) {
+ // ShapeGroups have no id...
+ if (m_shapeId == "KoShapeGroup") {
+ m_count ++;
+ }
+ check(group->shapes());
+ } else if (KoPathShape *path = dynamic_cast<KoPathShape*>(shape)) {
+ if (!m_pathShapeId.isEmpty()) {
+ if (path->pathShapeId() == m_pathShapeId
+ && m_shapeId == path->shapeId()) {
+ m_count ++;
+ }
+ } else if (m_shapeId == path->shapeId()) {
+ m_count ++;
+ }
+ } else if (m_shapeId == shape->shapeId()) {
+ m_count ++;
+ }
+ }
+ return true;
+ }
+
+ quint32 m_count;
+ const QString m_shapeId;
+ const QString m_pathShapeId;
+
+};
+
+
+class ShapeLayerTypeCheck : public KisExportCheckBase
+{
+public:
+
+ ShapeLayerTypeCheck(const QString &ShapeId, const QString &PathShapeId, const QString &id, Level level, const QString &customWarning = QString())
+ : KisExportCheckBase(id, level, customWarning)
+ , m_shapeId(ShapeId)
+ , m_pathShapeId(PathShapeId)
+ {
+ if (customWarning.isEmpty()) {
+ if (m_pathShapeId.isEmpty()) {
+ QString name = m_shapeId;
+ m_warning = i18nc("image conversion warning", "The image contains a Vector Layer with Shapes of type <b>%1</b>, which is not supported, these will not be saved.", name);
+ } else {
+ m_warning = i18nc("image conversion warning", "The image contains a Vector Layer with Shapes of type <b>%1</b>, which is not supported, these will be saved as paths", m_pathShapeId);
+ }
+ }
+ }
+
+ bool checkNeeded(KisImageSP image) const override
+ {
+ ShapeLayerTypeCheckVisitor v(m_shapeId, m_pathShapeId);
+ image->rootLayer()->accept(v);
+ return (v.count() > 0);
+ }
+
+ Level check(KisImageSP /*image*/) const override
+ {
+ return m_level;
+ }
+
+ QString m_shapeId;
+ QString m_pathShapeId;
+};
+
+class ShapeLayerTypeCheckFactory : public KisExportCheckFactory
+{
+public:
+
+ ShapeLayerTypeCheckFactory(const QString &ShapeId, const QString &PathShapeId = "")
+ : m_shapeId(ShapeId)
+ , m_pathShapeId(PathShapeId)
+ {
+ }
+
+ ~ShapeLayerTypeCheckFactory() override {}
+
+ KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
+ {
+ return new ShapeLayerTypeCheck(m_shapeId, m_pathShapeId, id(), level, customWarning);
+ }
+
+ QString id() const override {
+ if (m_pathShapeId.isEmpty()) {
+ return "ShapeLayerTypeCheck/" + m_shapeId;
+ }
+ return "ShapeLayerTypeCheck/" + m_shapeId + "/" + m_pathShapeId;
+ }
+
+ const QString m_shapeId;
+ const QString m_pathShapeId;
+};
+#endif // SHAPELAYERTYPECHECK_H
diff --git a/libs/ui/KisImportExportFilter.cpp b/libs/ui/KisImportExportFilter.cpp
index 445f72420a..4efddda9b0 100644
--- a/libs/ui/KisImportExportFilter.cpp
+++ b/libs/ui/KisImportExportFilter.cpp
@@ -153,6 +153,11 @@ QMap<QString, KisExportCheckBase *> KisImportExportFilter::exportChecks()
return d->capabilities;
}
+bool KisImportExportFilter::exportSupportsGuides() const
+{
+ return false;
+}
+
QString KisImportExportFilter::verify(const QString &fileName) const
{
QFileInfo fi(fileName);
diff --git a/libs/ui/KisImportExportFilter.h b/libs/ui/KisImportExportFilter.h
index ae54d669c1..2090423cd5 100644
--- a/libs/ui/KisImportExportFilter.h
+++ b/libs/ui/KisImportExportFilter.h
@@ -116,6 +116,14 @@ public:
*/
virtual QMap<QString, KisExportCheckBase*> exportChecks();
+ /**
+ * @brief exportSupportsGuides
+ * Because guides are in the document and not the image,
+ * checking for guides cannot be made an exportCheck.
+ * @return whether this filter supports exporting guides
+ */
+ virtual bool exportSupportsGuides() const;
+
/// Override and return false for the filters that use a library that cannot handle file handles, only file names.
virtual bool supportsIO() const { return true; }
diff --git a/libs/ui/KisImportExportManager.cpp b/libs/ui/KisImportExportManager.cpp
index a2506d061d..01dbc87a90 100644
--- a/libs/ui/KisImportExportManager.cpp
+++ b/libs/ui/KisImportExportManager.cpp
@@ -565,7 +565,7 @@ bool KisImportExportManager::askUserAboutExportConfiguration(
if (m_document->referenceImagesLayer() && m_document->referenceImagesLayer()->shapeCount() > 0 && to != m_document->nativeFormatMimeType()) {
warnings.append(i18nc("image conversion warning", "The image contains <b>reference images</b>. The reference images will not be saved."));
}
- if (m_document->guidesConfig().hasGuides() && to != m_document->nativeFormatMimeType()) {
+ if (m_document->guidesConfig().hasGuides() && !filter->exportSupportsGuides()) {
warnings.append(i18nc("image conversion warning", "The image contains <b>guides</b>. The guides will not be saved."));
}
if (!m_document->gridConfig().isDefault() && to != m_document->nativeFormatMimeType()) {
diff --git a/plugins/impex/kra/kra_export.cpp b/plugins/impex/kra/kra_export.cpp
index 04b8016273..b951cac4ad 100644
--- a/plugins/impex/kra/kra_export.cpp
+++ b/plugins/impex/kra/kra_export.cpp
@@ -74,6 +74,10 @@ QString KraExport::verify(const QString &fileName) const
return error;
}
+bool KraExport::exportSupportsGuides() const {
+ return true;
+}
+
#include <kra_export.moc>
diff --git a/plugins/impex/kra/kra_export.h b/plugins/impex/kra/kra_export.h
index 15fbcc3c83..d2bdca0d4c 100644
--- a/plugins/impex/kra/kra_export.h
+++ b/plugins/impex/kra/kra_export.h
@@ -21,6 +21,7 @@ public:
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
void initializeCapabilities() override;
QString verify(const QString &fileName) const override;
+ bool exportSupportsGuides() const override;
};
#endif
diff --git a/plugins/impex/psd/psd_export.cc b/plugins/impex/psd/psd_export.cc
index fb8e75e491..7159159e7a 100644
--- a/plugins/impex/psd/psd_export.cc
+++ b/plugins/impex/psd/psd_export.cc
@@ -48,6 +48,7 @@ void psdExport::initializeCapabilities()
addCapability(KisExportCheckRegistry::instance()->get("PSDLayerStyleCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGroupLayer")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGeneratorLayer")->create(KisExportCheckBase::SUPPORTED));
+ addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisShapeLayer")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
@@ -77,6 +78,20 @@ void psdExport::initializeCapabilities()
addCapability(KisExportCheckRegistry::instance()->get("FillLayerTypeCheck/color")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("FillLayerTypeCheck/pattern")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("FillLayerTypeCheck/gradient")->create(KisExportCheckBase::SUPPORTED));
+
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoPathShape")->create(KisExportCheckBase::SUPPORTED));
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoPathShape/RectangleShape")->create(KisExportCheckBase::SUPPORTED));
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoPathShape/EllipseShape")->create(KisExportCheckBase::SUPPORTED));
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoPathShape/StarShape")->create(KisExportCheckBase::SUPPORTED));
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoShapeGroup")->create(KisExportCheckBase::SUPPORTED));
+
+ const QString textShapeWarning = i18nc("image conversion warning", "While text shapes can be saved to psd, only basic features are supported. Advanced features, like text-on-path and opentype features will not be saved.");
+ addCapability(KisExportCheckRegistry::instance()->get("ShapeLayerTypeCheck/KoSvgTextShapeID")->create(KisExportCheckBase::PARTIALLY, textShapeWarning));
+}
+
+bool psdExport::exportSupportsGuides() const
+{
+ return true;
}
#include <psd_export.moc>
diff --git a/plugins/impex/psd/psd_export.h b/plugins/impex/psd/psd_export.h
index 5dff8d2b57..36312c6db3 100644
--- a/plugins/impex/psd/psd_export.h
+++ b/plugins/impex/psd/psd_export.h
@@ -18,6 +18,7 @@ class psdExport : public KisImportExportFilter {
public:
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
void initializeCapabilities() override;
+ bool exportSupportsGuides() const override;
};
#endif