Skip to content

Commit

Permalink
Canvas: add SVG compatibility checks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rodlie committed May 29, 2024
1 parent c512050 commit b4856c3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoundingBox*> boxes);
const QString checkForUnsupportedSVG();

void addPointToSelection(MovablePoint * const point);
void removePointFromSelection(MovablePoint * const point);
Expand Down
57 changes: 57 additions & 0 deletions src/core/canvasselectedboxesactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<TextBox*>(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<BoundingBox *> boxes)
{
QString result;
for (const auto &box : boxes) {
if (!box->isVisible()) { continue; }
if (const auto bbox = enve_cast<ContainerBox*>(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() {
}

Expand Down

0 comments on commit b4856c3

Please sign in to comment.