From c768caf972725dae9cef841dca3bacf9f060721c Mon Sep 17 00:00:00 2001 From: Alexander Mishunin Date: Thu, 18 Jul 2024 05:49:44 +0300 Subject: [PATCH 1/2] Rename Set- to Push- and handle relative transform matrices where possible --- src/Avalonia.Svg/AvaloniaPicture.cs | 10 +++++----- ...sformDrawCommand.cs => PushTransformDrawCommand.cs} | 4 ++-- src/ShimSkiaSharp/SKCanvas.cs | 8 ++++---- src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs | 4 ++-- src/Svg.Model/Drawables/DrawableBase.cs | 4 +--- src/Svg.Model/Drawables/Elements/ImageDrawable.cs | 4 +--- src/Svg.Model/Drawables/Elements/TextDrawable.cs | 4 +--- src/Svg.Model/SvgExtensions.Painting.cs | 2 +- src/Svg.Skia/SkiaModel.cs | 4 ++-- 9 files changed, 19 insertions(+), 25 deletions(-) rename src/Avalonia.Svg/Commands/{SetTransformDrawCommand.cs => PushTransformDrawCommand.cs} (54%) diff --git a/src/Avalonia.Svg/AvaloniaPicture.cs b/src/Avalonia.Svg/AvaloniaPicture.cs index d9e7bc161..fcd577247 100644 --- a/src/Avalonia.Svg/AvaloniaPicture.cs +++ b/src/Avalonia.Svg/AvaloniaPicture.cs @@ -150,10 +150,10 @@ private static void RecordCommand(CanvasCommand canvasCommand, List commands.Add(new RestoreDrawCommand()); break; } - case SetMatrixCanvasCommand setMatrixCanvasCommand: + case PushMatrixCanvasCommand pushMatrixCanvasCommand: { - var matrix = setMatrixCanvasCommand.Matrix.ToMatrix(); - commands.Add(new SetTransformDrawCommand(matrix)); + var matrix = pushMatrixCanvasCommand.DeltaMatrix.ToMatrix(); + commands.Add(new PushTransformDrawCommand(matrix)); break; } case SaveLayerCanvasCommand saveLayerCanvasCommand: @@ -267,9 +267,9 @@ private void Draw(AM.DrawingContext context, DrawCommand command, Stack Date: Thu, 18 Jul 2024 20:44:21 +0200 Subject: [PATCH 2/2] Rename --- src/Avalonia.Svg/AvaloniaPicture.cs | 4 ++-- src/ShimSkiaSharp/SKCanvas.cs | 6 +++--- src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs | 4 ++-- src/Svg.Model/Drawables/DrawableBase.cs | 2 +- src/Svg.Model/Drawables/Elements/ImageDrawable.cs | 2 +- src/Svg.Model/Drawables/Elements/TextDrawable.cs | 2 +- src/Svg.Model/SvgExtensions.Painting.cs | 2 +- src/Svg.Skia/SkiaModel.cs | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Svg/AvaloniaPicture.cs b/src/Avalonia.Svg/AvaloniaPicture.cs index fcd577247..8999585ae 100644 --- a/src/Avalonia.Svg/AvaloniaPicture.cs +++ b/src/Avalonia.Svg/AvaloniaPicture.cs @@ -150,9 +150,9 @@ private static void RecordCommand(CanvasCommand canvasCommand, List commands.Add(new RestoreDrawCommand()); break; } - case PushMatrixCanvasCommand pushMatrixCanvasCommand: + case SetMatrixCanvasCommand setMatrixCanvasCommand: { - var matrix = pushMatrixCanvasCommand.DeltaMatrix.ToMatrix(); + var matrix = setMatrixCanvasCommand.DeltaMatrix.ToMatrix(); commands.Add(new PushTransformDrawCommand(matrix)); break; } diff --git a/src/ShimSkiaSharp/SKCanvas.cs b/src/ShimSkiaSharp/SKCanvas.cs index 4da9b5de3..0e446912a 100644 --- a/src/ShimSkiaSharp/SKCanvas.cs +++ b/src/ShimSkiaSharp/SKCanvas.cs @@ -25,7 +25,7 @@ public record SaveCanvasCommand(int Count) : CanvasCommand; public record SaveLayerCanvasCommand(int Count, SKPaint? Paint = null) : CanvasCommand; -public record PushMatrixCanvasCommand(SKMatrix DeltaMatrix, SKMatrix TotalMatrix) : CanvasCommand; +public record SetMatrixCanvasCommand(SKMatrix DeltaMatrix, SKMatrix TotalMatrix) : CanvasCommand; public class SKCanvas { @@ -77,10 +77,10 @@ public void DrawTextOnPath(string text, SKPath path, float hOffset, float vOffse Commands?.Add(new DrawTextOnPathCanvasCommand(text, path, hOffset, vOffset, paint)); } - public void PushMatrix(SKMatrix deltaMatrix) + public void SetMatrix(SKMatrix deltaMatrix) { TotalMatrix = TotalMatrix.PreConcat(deltaMatrix); - Commands?.Add(new PushMatrixCanvasCommand(deltaMatrix, TotalMatrix)); + Commands?.Add(new SetMatrixCanvasCommand(deltaMatrix, TotalMatrix)); } public int Save() diff --git a/src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs b/src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs index 3e330c1d6..bc0e9c3f5 100644 --- a/src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs +++ b/src/Svg.CodeGen.Skia/SkiaCSharpModelExtensions.cs @@ -1778,9 +1778,9 @@ public static void ToSKPicture(this SKPicture? picture, SkiaCSharpCodeGenCounter sb.AppendLine($"{indent}{counter.CanvasVarName}{counterCanvas}.Restore();"); break; } - case PushMatrixCanvasCommand pushMatrixCanvasCommand: + case SetMatrixCanvasCommand setMatrixCanvasCommand: { - sb.AppendLine($"{indent}{counter.CanvasVarName}{counterCanvas}.SetMatrix({pushMatrixCanvasCommand.TotalMatrix.ToSKMatrix()});"); + sb.AppendLine($"{indent}{counter.CanvasVarName}{counterCanvas}.SetMatrix({setMatrixCanvasCommand.TotalMatrix.ToSKMatrix()});"); break; } case SaveLayerCanvasCommand saveLayerCanvasCommand: diff --git a/src/Svg.Model/Drawables/DrawableBase.cs b/src/Svg.Model/Drawables/DrawableBase.cs index 3151b90dd..23abb558b 100644 --- a/src/Svg.Model/Drawables/DrawableBase.cs +++ b/src/Svg.Model/Drawables/DrawableBase.cs @@ -114,7 +114,7 @@ public virtual void Draw(SKCanvas canvas, DrawAttributes ignoreAttributes, Drawa if (!Transform.IsIdentity && enableTransform) { - canvas.PushMatrix(Transform); + canvas.SetMatrix(Transform); } if (Clip is { }) diff --git a/src/Svg.Model/Drawables/Elements/ImageDrawable.cs b/src/Svg.Model/Drawables/Elements/ImageDrawable.cs index aaafcc6a6..340424142 100644 --- a/src/Svg.Model/Drawables/Elements/ImageDrawable.cs +++ b/src/Svg.Model/Drawables/Elements/ImageDrawable.cs @@ -162,7 +162,7 @@ public override void OnDraw(SKCanvas canvas, DrawAttributes ignoreAttributes, Dr { canvas.Save(); - canvas.PushMatrix(FragmentTransform); + canvas.SetMatrix(FragmentTransform); FragmentDrawable.Draw(canvas, ignoreAttributes, until, true); diff --git a/src/Svg.Model/Drawables/Elements/TextDrawable.cs b/src/Svg.Model/Drawables/Elements/TextDrawable.cs index 4b39e5a70..c36e221aa 100644 --- a/src/Svg.Model/Drawables/Elements/TextDrawable.cs +++ b/src/Svg.Model/Drawables/Elements/TextDrawable.cs @@ -137,7 +137,7 @@ internal void BeginDraw(SvgTextBase svgTextBase, SKCanvas skCanvas, SKRect skBou if (!skMatrix.IsIdentity && enableTransform) { - skCanvas.PushMatrix(skMatrix); + skCanvas.SetMatrix(skMatrix); } if (enableClip) diff --git a/src/Svg.Model/SvgExtensions.Painting.cs b/src/Svg.Model/SvgExtensions.Painting.cs index d94e41ef4..170961879 100644 --- a/src/Svg.Model/SvgExtensions.Painting.cs +++ b/src/Svg.Model/SvgExtensions.Painting.cs @@ -588,7 +588,7 @@ internal static SKPicture RecordPicture(SvgElementCollection svgElementCollectio var skPictureRecorder = new SKPictureRecorder(); var skCanvas = skPictureRecorder.BeginRecording(skBounds); - skCanvas.PushMatrix(skMatrix); + skCanvas.SetMatrix(skMatrix); var skPaintOpacity = ignoreAttributes.HasFlag(DrawAttributes.Opacity) ? null : GetOpacityPaint(opacity); if (skPaintOpacity is { }) diff --git a/src/Svg.Skia/SkiaModel.cs b/src/Svg.Skia/SkiaModel.cs index f30f63c39..c0344519a 100644 --- a/src/Svg.Skia/SkiaModel.cs +++ b/src/Svg.Skia/SkiaModel.cs @@ -1217,9 +1217,9 @@ public void Draw(CanvasCommand canvasCommand, SkiaSharp.SKCanvas skCanvas) skCanvas.Restore(); break; } - case PushMatrixCanvasCommand pushMatrixCanvasCommand: + case SetMatrixCanvasCommand setMatrixCanvasCommand: { - var matrix = ToSKMatrix(pushMatrixCanvasCommand.TotalMatrix); + var matrix = ToSKMatrix(setMatrixCanvasCommand.TotalMatrix); skCanvas.SetMatrix(matrix); break; }