From b4856c3eaf304f146c6d65e39b4d5183aa68c75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Wed, 29 May 2024 20:40:27 +0200 Subject: [PATCH] Canvas: add SVG compatibility checks Adds a function that returns a informational warning if the canvas contains any boxes and/or effects not compatible with SVG export. Can also include notes or recommendations. This will be used by the SVG exporter to give the user feedback on the project compatibility before exporting. It's not perfect, but should give the user enough information to adjust the project for export. Ref: #174 --- src/core/canvas.h | 3 ++ src/core/canvasselectedboxesactions.cpp | 57 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/core/canvas.h b/src/core/canvas.h index bbe78f5b0..a9afcde45 100644 --- a/src/core/canvas.h +++ b/src/core/canvas.h @@ -217,6 +217,9 @@ class CORE_EXPORT Canvas : public CanvasBase void removeBoxFromSelection(BoundingBox* const box); void clearBoxesSelection(); void clearBoxesSelectionList(); + const QString checkForUnsupportedBoxSVG(BoundingBox* const box); + const QString checkForUnsupportedBoxesSVG(const QList boxes); + const QString checkForUnsupportedSVG(); void addPointToSelection(MovablePoint * const point); void removePointFromSelection(MovablePoint * const point); diff --git a/src/core/canvasselectedboxesactions.cpp b/src/core/canvasselectedboxesactions.cpp index bdd4bdfc2..ab124975c 100644 --- a/src/core/canvasselectedboxesactions.cpp +++ b/src/core/canvasselectedboxesactions.cpp @@ -23,6 +23,8 @@ // Fork of enve - Copyright (C) 2016-2020 Maurycy Liebner +#include "Boxes/svglinkbox.h" +#include "Boxes/videobox.h" #include "canvas.h" #include "MovablePoints/pathpivot.h" #include "PathEffects/patheffectsinclude.h" @@ -485,6 +487,61 @@ void Canvas::clearBoxesSelectionList() { emit objectSelectionChanged(); } +const QString Canvas::checkForUnsupportedBoxSVG(BoundingBox * const box) +{ + QString result; + if (!box) { return result; } + qDebug() << "check" << box->prp_getName() << "for SVG support"; + if (box->hasTransformEffects()) { + result.append(QString("- %1 => %2 : %3\n").arg(prp_getName(), + box->prp_getName(), + tr("Transform effects are unsupported"))); + } + if (box->hasEnabledBlendEffects()) { + result.append(QString("- %1 => %2 : %3\n").arg(prp_getName(), + box->prp_getName(), + tr("Blend effects are unsupported"))); + } + const auto rasterEffects = box->checkRasterEffectsForSVGSupport(); + if (rasterEffects.size() > 0) { + result.append(QString("- %1 => %2 : %3 %4\n").arg(prp_getName(), + box->prp_getName(), + rasterEffects.join(", "), + tr("is unsupported"))); + } + if (const auto bbox = enve_cast(box)) { + if (bbox->hasTextEffects()) { + result.append(QString("- %1 => %2 : %3\n").arg(prp_getName(), + box->prp_getName(), + tr("Text effects are unsupported"))); + } + result.append(QString("- %1 => %2 : %3\n").arg(prp_getName(), + box->prp_getName(), + tr("For best compatibility convert text to path"))); + } + return result; +} + +const QString Canvas::checkForUnsupportedBoxesSVG(const QList boxes) +{ + QString result; + for (const auto &box : boxes) { + if (!box->isVisible()) { continue; } + if (const auto bbox = enve_cast(box)) { + const auto warnings = checkForUnsupportedBoxesSVG(bbox->getContainedBoxes()); + if (!warnings.isEmpty()) { result.append(warnings); } + } + const auto warnings = checkForUnsupportedBoxSVG(box); + if (!warnings.isEmpty()) { result.append(warnings); } + } + return result; +} + +const QString Canvas::checkForUnsupportedSVG() +{ + return checkForUnsupportedBoxesSVG(getContainedBoxes()); +} + void Canvas::applyCurrentTransformToSelected() { }