Fixed: #2461 SVG export - incorrect clipping / missing shapes

This commit is contained in:
Jindra Petřík
2025-05-27 09:36:27 +02:00
parent fe516a04d6
commit b2961e21e3
3 changed files with 24 additions and 15 deletions

View File

@@ -95,19 +95,22 @@ public class SVGExporter {
private final Tag tag;
public final ColorTransform colorTransform;
public final int ratio;
public final boolean clipped;
public ExportKey(Tag tag, ColorTransform colorTransform, int ratio) {
public ExportKey(Tag tag, ColorTransform colorTransform, int ratio, boolean clipped) {
this.tag = tag;
this.colorTransform = colorTransform;
this.ratio = ratio;
this.clipped = clipped;
}
@Override
public int hashCode() {
int hash = 7;
hash = 43 * hash + Objects.hashCode(this.tag);
hash = 43 * hash + Objects.hashCode(this.colorTransform);
hash = 43 * hash + this.ratio;
hash = 79 * hash + Objects.hashCode(this.tag);
hash = 79 * hash + Objects.hashCode(this.colorTransform);
hash = 79 * hash + this.ratio;
hash = 79 * hash + (this.clipped ? 1 : 0);
return hash;
}
@@ -126,11 +129,14 @@ public class SVGExporter {
if (this.ratio != other.ratio) {
return false;
}
if (this.clipped != other.clipped) {
return false;
}
if (!Objects.equals(this.tag, other.tag)) {
return false;
}
return Objects.equals(this.colorTransform, other.colorTransform);
}
}
}
public SVGExporter(ExportRectangle bounds, double zoom, String objectType) {

View File

@@ -1623,7 +1623,7 @@ public class Timeline {
clipGroup = null;
}
if (clips.size() > 0) {
if (!clips.isEmpty()) {
String clip = clips.get(clips.size() - 1).shape; // todo: merge clip areas
clipGroup = exporter.createSubGroup(null, null);
clipGroup.setAttribute("clip-path", "url(#" + clip + ")");
@@ -1656,16 +1656,7 @@ public class Timeline {
String assetName;
Tag drawableTag = (Tag) drawable;
RECT boundRect = drawable.getRect();
boolean createNew = false;
SVGExporter.ExportKey exportKey = new SVGExporter.ExportKey(drawableTag, clrTrans, layer.ratio);
if (exporter.exportedTags.containsKey(exportKey)) {
assetName = exporter.exportedTags.get(exportKey);
} else {
assetName = getTagIdPrefix(drawableTag, exporter);
exporter.exportedTags.put(exportKey, assetName);
createNew = true;
}
ExportRectangle rect = new ExportRectangle(boundRect);
DefineScalingGridTag scalingGrid = character.getScalingGridTag();
@@ -1681,6 +1672,16 @@ public class Timeline {
drawable.toSVG(exporter, layer.ratio, clrTrans, level + 1);
exporter.endGroup();
} else {
boolean createNew = false;
SVGExporter.ExportKey exportKey = new SVGExporter.ExportKey(drawableTag, clrTrans, layer.ratio, layer.clipDepth > -1);
if (exporter.exportedTags.containsKey(exportKey)) {
assetName = exporter.exportedTags.get(exportKey);
} else {
assetName = getTagIdPrefix(drawableTag, exporter);
exporter.exportedTags.put(exportKey, assetName);
createNew = true;
}
if (createNew) {
exporter.createDefGroup(new ExportRectangle(boundRect), assetName);
drawable.toSVG(exporter, layer.ratio, clrTrans, level + 1);