Browse Source

Fixed serializing stroke line join and cap

Krzysztof Krysiński 4 months ago
parent
commit
2680307794

+ 1 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/Shapes/IReadOnlyPathData.cs

@@ -3,9 +3,7 @@ using Drawie.Backend.Core.Vector;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
 
-public interface IReadOnlyPathData : IReadOnlyShapeVectorData
+public interface IReadOnlyPathData : IReadOnlyShapeVectorData, IReadOnlyStrokeJoinable
 {
     public VectorPath Path { get; }
-    public StrokeCap StrokeLineCap { get; }
-    public StrokeJoin StrokeLineJoin { get; }
 }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/Shapes/IReadOnlyRectangleData.cs

@@ -2,7 +2,7 @@
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
 
-public interface IReadOnlyRectangleData : IReadOnlyShapeVectorData
+public interface IReadOnlyRectangleData : IReadOnlyShapeVectorData // TODO: Add IReadOnlyStrokeJoinable
 {
     public VecD Center { get; }
     public VecD Size { get; }

+ 10 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/Shapes/IReadOnlyStrokeJoinable.cs

@@ -0,0 +1,10 @@
+using Drawie.Backend.Core.Surfaces.PaintImpl;
+using Drawie.Backend.Core.Vector;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
+
+public interface IReadOnlyStrokeJoinable
+{
+    public StrokeJoin StrokeLineJoin { get; }
+    public StrokeCap StrokeLineCap { get; }
+}

+ 7 - 0
src/PixiEditor/Models/Serialization/Factories/SerializationFactory.cs

@@ -35,6 +35,13 @@ public abstract class SerializationFactory
             _ => throw new InvalidOperationException("Value is not an array.")
         };
     }
+
+    protected bool IsFilePreVersion((string serializerName, string serializerVersion) serializerData, Version minSupportedVersion)
+    {
+        return serializerData.serializerName == "PixiEditor"
+               && Version.TryParse(serializerData.serializerVersion, out Version version)
+                && version < minSupportedVersion;
+    }
 }
 
 public abstract class SerializationFactory<TSerializable, TOriginal> : SerializationFactory

+ 16 - 1
src/PixiEditor/Models/Serialization/Factories/VectorPathSerializationFactory.cs

@@ -2,6 +2,7 @@
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.ColorsImpl.Paintables;
 using Drawie.Backend.Core.Numerics;
+using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Backend.Core.Vector;
 using Drawie.Numerics;
 using PixiEditor.Views.Overlays.PathOverlay;
@@ -21,6 +22,9 @@ internal class VectorPathSerializationFactory : VectorShapeSerializationFactory<
 
         EditableVectorPath path = new EditableVectorPath(original.Path);
 
+        builder.AddInt((int)original.StrokeLineJoin);
+        builder.AddInt((int)original.StrokeLineCap);
+
         builder.AddInt((int)path.Path.FillType);
         builder.AddInt(path.SubShapes.Count);
 
@@ -35,6 +39,15 @@ internal class VectorPathSerializationFactory : VectorShapeSerializationFactory<
         float strokeWidth, (string serializerName, string serializerVersion) serializerData,
         out PathVectorData original)
     {
+        StrokeJoin join = StrokeJoin.Round;
+        StrokeCap cap = StrokeCap.Round;
+
+        if (!IsFilePreVersion(serializerData, new Version(2, 0, 0, 62)))
+        {
+            join = (StrokeJoin)extractor.GetInt();
+            cap = (StrokeCap)extractor.GetInt();
+        }
+
         VectorPath path;
         if (IsOldSerializer(serializerData))
         {
@@ -52,7 +65,9 @@ internal class VectorPathSerializationFactory : VectorShapeSerializationFactory<
             FillPaintable = fillPaintable,
             StrokeWidth = strokeWidth,
             TransformationMatrix = matrix,
-            Fill = fill, // TODO: Check if stroke line cap and join are serialized
+            Fill = fill,
+            StrokeLineJoin = join,
+            StrokeLineCap = cap
         };
 
         return true;