From 21cd5d06400081ece74cde4e32345765b1148467 Mon Sep 17 00:00:00 2001 From: Drobyshev Vladimir Date: Mon, 13 May 2024 19:54:24 +0300 Subject: [PATCH 1/3] Sample --- .../AvaloniaSvgSkiaSample/DrawControl.axaml | 8 ++++++ .../DrawControl.axaml.cs | 25 +++++++++++++++++++ .../AvaloniaSvgSkiaSample/MainWindow.axaml | 12 +++++++++ 3 files changed, 45 insertions(+) create mode 100644 samples/AvaloniaSvgSkiaSample/DrawControl.axaml create mode 100644 samples/AvaloniaSvgSkiaSample/DrawControl.axaml.cs diff --git a/samples/AvaloniaSvgSkiaSample/DrawControl.axaml b/samples/AvaloniaSvgSkiaSample/DrawControl.axaml new file mode 100644 index 00000000..bff55611 --- /dev/null +++ b/samples/AvaloniaSvgSkiaSample/DrawControl.axaml @@ -0,0 +1,8 @@ + + + diff --git a/samples/AvaloniaSvgSkiaSample/DrawControl.axaml.cs b/samples/AvaloniaSvgSkiaSample/DrawControl.axaml.cs new file mode 100644 index 00000000..9dcaf295 --- /dev/null +++ b/samples/AvaloniaSvgSkiaSample/DrawControl.axaml.cs @@ -0,0 +1,25 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Media; +using Avalonia.Svg.Skia; + +namespace AvaloniaSvgSkiaSample; + +public partial class DrawControl : UserControl +{ + public SvgImage Image { get; set; } + + public DrawControl() + { + InitializeComponent(); + } + + public override void Render(DrawingContext context) + { + var center = Bounds.Center; + var width = Image.Size.Width / 2; + var height = Image.Size.Width / 2; + context.DrawImage(Image, new Rect(center.X - 0.5 * width, center.Y - 0.5 * height, width, height)); + } +} + diff --git a/samples/AvaloniaSvgSkiaSample/MainWindow.axaml b/samples/AvaloniaSvgSkiaSample/MainWindow.axaml index 66b077a7..d9d83f41 100644 --- a/samples/AvaloniaSvgSkiaSample/MainWindow.axaml +++ b/samples/AvaloniaSvgSkiaSample/MainWindow.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia" + xmlns:local="clr-namespace:AvaloniaSvgSkiaSample" mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="600" x:Class="AvaloniaSvgSkiaSample.MainWindow" Width="900" Height="600" WindowStartupLocation="CenterScreen" @@ -146,6 +147,17 @@ + + + + + + From 2b17a917265b2978ec97c7292dd789afa16e665a Mon Sep 17 00:00:00 2001 From: Drobyshev Vladimir Date: Mon, 13 May 2024 19:54:35 +0300 Subject: [PATCH 2/3] fix --- src/Avalonia.Svg.Skia/SvgImage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Svg.Skia/SvgImage.cs b/src/Avalonia.Svg.Skia/SvgImage.cs index 87ea5d19..a30b4928 100644 --- a/src/Avalonia.Svg.Skia/SvgImage.cs +++ b/src/Avalonia.Svg.Skia/SvgImage.cs @@ -88,7 +88,7 @@ void IImage.Draw(DrawingContext context, Rect sourceRect, Rect destRect) -sourceRect.X + destRect.X - bounds.Top, -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom( new SvgSourceCustomDrawOperation( From 224c822cb27e20ddd7f281a63ee30a1541d33df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Thu, 29 Aug 2024 13:22:37 +0200 Subject: [PATCH 3/3] Fix transforms --- src/Avalonia.Controls.Skia/SKBitmapControl.cs | 2 +- src/Avalonia.Controls.Skia/SKBitmapImage.cs | 2 +- src/Avalonia.Controls.Skia/SKPathControl.cs | 2 +- src/Avalonia.Controls.Skia/SKPathImage.cs | 2 +- src/Avalonia.Controls.Skia/SKPictureControl.cs | 2 +- src/Avalonia.Controls.Skia/SKPictureImage.cs | 2 +- src/Avalonia.Svg.Skia/Svg.cs | 2 +- src/Avalonia.Svg/Svg.cs | 2 +- src/Avalonia.Svg/SvgImage.cs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls.Skia/SKBitmapControl.cs b/src/Avalonia.Controls.Skia/SKBitmapControl.cs index 418026cd..9eafd0d2 100644 --- a/src/Avalonia.Controls.Skia/SKBitmapControl.cs +++ b/src/Avalonia.Controls.Skia/SKBitmapControl.cs @@ -123,7 +123,7 @@ public override void Render(DrawingContext context) } using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom(new SKBitmapDrawOperation(new Rect(0, 0, bounds.Width, bounds.Height), bitmap)); } diff --git a/src/Avalonia.Controls.Skia/SKBitmapImage.cs b/src/Avalonia.Controls.Skia/SKBitmapImage.cs index 7bf1c0a9..b8caa04e 100644 --- a/src/Avalonia.Controls.Skia/SKBitmapImage.cs +++ b/src/Avalonia.Controls.Skia/SKBitmapImage.cs @@ -46,7 +46,7 @@ void IImage.Draw(DrawingContext context, Rect sourceRect, Rect destRect) var scaleMatrix = Matrix.CreateScale(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); var translateMatrix = Matrix.CreateTranslation(-sourceRect.X + destRect.X - bounds.Top, -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom(new SKBitmapDrawOperation(new Rect(0, 0, bounds.Width, bounds.Height), source)); } diff --git a/src/Avalonia.Controls.Skia/SKPathControl.cs b/src/Avalonia.Controls.Skia/SKPathControl.cs index 87f92190..6057a50c 100644 --- a/src/Avalonia.Controls.Skia/SKPathControl.cs +++ b/src/Avalonia.Controls.Skia/SKPathControl.cs @@ -140,7 +140,7 @@ public override void Render(DrawingContext context) } using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom( new SKPathDrawOperation( diff --git a/src/Avalonia.Controls.Skia/SKPathImage.cs b/src/Avalonia.Controls.Skia/SKPathImage.cs index 59847557..a0234dc8 100644 --- a/src/Avalonia.Controls.Skia/SKPathImage.cs +++ b/src/Avalonia.Controls.Skia/SKPathImage.cs @@ -66,7 +66,7 @@ void IImage.Draw(DrawingContext context, Rect sourceRect, Rect destRect) var scaleMatrix = Matrix.CreateScale(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); var translateMatrix = Matrix.CreateTranslation(-sourceRect.X + destRect.X - bounds.Top, -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom(new SKPathDrawOperation(new Rect(0, 0, bounds.Width, bounds.Height), source, paint)); } diff --git a/src/Avalonia.Controls.Skia/SKPictureControl.cs b/src/Avalonia.Controls.Skia/SKPictureControl.cs index 8a5977a4..8f42637d 100644 --- a/src/Avalonia.Controls.Skia/SKPictureControl.cs +++ b/src/Avalonia.Controls.Skia/SKPictureControl.cs @@ -123,7 +123,7 @@ public override void Render(DrawingContext context) } using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom( new SKPictureDrawOperation( diff --git a/src/Avalonia.Controls.Skia/SKPictureImage.cs b/src/Avalonia.Controls.Skia/SKPictureImage.cs index 001608dc..6c69b959 100644 --- a/src/Avalonia.Controls.Skia/SKPictureImage.cs +++ b/src/Avalonia.Controls.Skia/SKPictureImage.cs @@ -46,7 +46,7 @@ void IImage.Draw(DrawingContext context, Rect sourceRect, Rect destRect) var scaleMatrix = Matrix.CreateScale(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); var translateMatrix = Matrix.CreateTranslation(-sourceRect.X + destRect.X - bounds.Top, -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom(new SKPictureDrawOperation(new Rect(0, 0, bounds.Width, bounds.Height), source)); } diff --git a/src/Avalonia.Svg.Skia/Svg.cs b/src/Avalonia.Svg.Skia/Svg.cs index e0ce08e9..e61521a8 100644 --- a/src/Avalonia.Svg.Skia/Svg.cs +++ b/src/Avalonia.Svg.Skia/Svg.cs @@ -230,7 +230,7 @@ public override void Render(DrawingContext context) -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { context.Custom( new SvgSourceCustomDrawOperation( diff --git a/src/Avalonia.Svg/Svg.cs b/src/Avalonia.Svg/Svg.cs index 04e6ad28..693412a2 100644 --- a/src/Avalonia.Svg/Svg.cs +++ b/src/Avalonia.Svg/Svg.cs @@ -213,7 +213,7 @@ public override void Render(DrawingContext context) -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { if (_avaloniaPicture is { }) { diff --git a/src/Avalonia.Svg/SvgImage.cs b/src/Avalonia.Svg/SvgImage.cs index 473d2fa5..27e81caa 100644 --- a/src/Avalonia.Svg/SvgImage.cs +++ b/src/Avalonia.Svg/SvgImage.cs @@ -69,7 +69,7 @@ void IImage.Draw( -sourceRect.X + destRect.X - bounds.Top, -sourceRect.Y + destRect.Y - bounds.Left); using (context.PushClip(destRect)) - using (context.PushTransform(translateMatrix * scaleMatrix)) + using (context.PushTransform(scaleMatrix * translateMatrix)) { try {