Browse Source

Merge pull request #969 from PixiEditor/text-on-path-offset

Added path offset to text path
Krzysztof Krysiński 2 months ago
parent
commit
acdbd3fd08

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 3b9c90113ed6b7600d1b80828d3ddf1d70ead90a
+Subproject commit 34ce7ab4d8e14f5dbad86dea076fe4c7cda15da3

+ 14 - 8
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/TextVectorData.cs

@@ -153,6 +153,7 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
 
     public FontFamilyName? MissingFontFamily { get; set; }
     public string MissingFontText { get; set; }
+    public VecD PathOffset { get; set; }
 
     private RichText richText;
     private RectD lastBounds;
@@ -226,7 +227,7 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
 
     private void PaintText(Canvas canvas, Paint paint)
     {
-        richText.Paint(canvas, Position, Font, paint, Path);
+        richText.Paint(canvas, Position, Font, paint, Path, PathOffset);
     }
 
     public override bool IsValid()
@@ -239,11 +240,14 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
         if (copy is TextVectorData textData)
         {
             textData.Font = Font.FromFontFamily(Font.Family);
-            textData.Font.Size = Font.Size;
-            textData.Font.Edging = Font.Edging;
-            textData.Font.SubPixel = Font.SubPixel;
-            textData.Font.Bold = Font.Bold;
-            textData.Font.Italic = Font.Italic;
+            if (textData.Font != null)
+            {
+                textData.Font.Size = Font.Size;
+                textData.Font.Edging = Font.Edging;
+                textData.Font.SubPixel = Font.SubPixel;
+                textData.Font.Bold = Font.Bold;
+                textData.Font.Italic = Font.Italic;
+            }
 
             textData.lastBounds = lastBounds;
         }
@@ -262,6 +266,7 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
         hash.Add(MaxWidth);
         hash.Add(Bold);
         hash.Add(Italic);
+        hash.Add(PathOffset);
 
         return hash.ToHashCode();
     }
@@ -288,7 +293,8 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
     protected bool Equals(TextVectorData other)
     {
         return base.Equals(other) && Position.Equals(other.Position) && MaxWidth.Equals(other.MaxWidth) && AntiAlias == other.AntiAlias && Nullable.Equals(MissingFontFamily, other.MissingFontFamily) && MissingFontText == other.MissingFontText
-            && Text == other.Text && Font.Equals(other.Font) && Spacing.Equals(other.Spacing) && Path == other.Path && Bold == other.Bold && Italic == other.Italic;
+            && Text == other.Text && Font.Equals(other.Font) && Spacing.Equals(other.Spacing) && Path == other.Path && Bold == other.Bold && Italic == other.Italic
+            && PathOffset.Equals(other.PathOffset);
     }
 
     public override bool Equals(object? obj)
@@ -313,6 +319,6 @@ public class TextVectorData : ShapeVectorData, IReadOnlyTextData, IScalable
 
     public override int GetHashCode()
     {
-        return HashCode.Combine(base.GetHashCode(), Position, MaxWidth, AntiAlias, MissingFontFamily, MissingFontText, Font, HashCode.Combine(Text, Spacing, Path));
+        return HashCode.Combine(base.GetHashCode(), Position, MaxWidth, AntiAlias, MissingFontFamily, MissingFontText, Font, HashCode.Combine(Text, Spacing, Path, PathOffset));
     }
 }

+ 4 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/TextOnPathNode.cs

@@ -1,4 +1,5 @@
 using Drawie.Backend.Core.Vector;
+using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
 using PixiEditor.ChangeableDocument.Rendering;
 
@@ -9,6 +10,7 @@ public class TextOnPathNode : Node
 {
     public InputProperty<TextVectorData> TextData { get; }
     public InputProperty<ShapeVectorData> PathData { get; }
+    public InputProperty<VecD> Offset { get; }
 
     public OutputProperty<TextVectorData> Output { get; }
 
@@ -18,6 +20,7 @@ public class TextOnPathNode : Node
     {
         TextData = CreateInput<TextVectorData>("Text", "TEXT_LABEL", null);
         PathData = CreateInput<ShapeVectorData>("Path", "SHAPE_LABEL", null);
+        Offset = CreateInput<VecD>("Offset", "OFFSET", VecD.Zero);
 
         Output = CreateOutput<TextVectorData>("Output", "TEXT_LABEL", null);
     }
@@ -40,6 +43,7 @@ public class TextOnPathNode : Node
         lastPath.Transform(pathData.TransformationMatrix);
 
         cloned.Path = lastPath;
+        cloned.PathOffset = Offset.Value;
 
         Output.Value = cloned;
     }

+ 10 - 1
src/PixiEditor/Models/Serialization/Factories/TextSerializationFactory.cs

@@ -39,6 +39,8 @@ internal class TextSerializationFactory : VectorShapeSerializationFactory<TextVe
         {
             builder.AddString(original.Path.ToSvgPathData());
         }
+
+        builder.AddVecD(original.PathOffset);
     }
 
     protected override bool DeserializeVectorData(ByteExtractor extractor, Matrix3X3 matrix, Paintable strokePaintable,
@@ -71,6 +73,12 @@ internal class TextSerializationFactory : VectorShapeSerializationFactory<TextVe
             path = VectorPath.FromSvgPath(DeserializeStringCompatible(extractor, serializerData));
         }
 
+        VecD pathOffset = VecD.Zero;
+        if (!IsFilePreVersion(serializerData, new Version(2, 0, 0, 95)))
+        {
+            pathOffset = extractor.GetVecD();
+        }
+
         FontFamilyName family =
             new FontFamilyName(fontFamily) { FontUri = isFontFromFile ? new Uri(fontPath, UriKind.Absolute) : null };
         Font font = Font.FromFontFamily(family);
@@ -107,7 +115,8 @@ internal class TextSerializationFactory : VectorShapeSerializationFactory<TextVe
             Path = path,
             MissingFontFamily = missingFamily,
             MissingFontText = new LocalizedString("MISSING_FONT"),
-            AntiAlias = antiAlias
+            AntiAlias = antiAlias,
+            PathOffset = pathOffset
         };
 
         return true;

+ 2 - 2
src/PixiEditor/Properties/AssemblyInfo.cs

@@ -43,5 +43,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.0.0.94")]
-[assembly: AssemblyFileVersion("2.0.0.94")]
+[assembly: AssemblyVersion("2.0.0.95")]
+[assembly: AssemblyFileVersion("2.0.0.95")]

+ 4 - 0
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -401,7 +401,11 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
                         SerializationUtil.DeserializeDict(serializedNode.AdditionalData, config, allFactories,
                             serializerData)));
                 }
+            }
 
+            foreach (var node in graph.AllNodes)
+            {
+                Guid nodeGuid = mappedNodeIds[node.Id];
                 if (node.InputConnections != null)
                 {
                     foreach (var connections in node.InputConnections)