Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Oct 10, 2022
1 parent 09495e9 commit 4962392
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build/Avalonia.Controls.Skia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Controls.Skia" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Controls.Skia" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Desktop.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Diagnostics.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Markup.Xaml.Loader.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Skia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Skia" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Skia" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.ThemeManager.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.ThemeManager" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.ThemeManager" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Themes.Fluent.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Web.Blazor.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Web.Blazor" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Web.Blazor" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.Xaml.Behaviors.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Avalonia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview1" />
<PackageReference Include="Avalonia" Version="11.0.0-preview2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Base.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>11.0.0</VersionPrefix>
<VersionSuffix>preview1</VersionSuffix>
<VersionSuffix>preview2</VersionSuffix>
<Authors>Wiesław Šoltés</Authors>
<Company>Wiesław Šoltés</Company>
<Copyright>Copyright © Wiesław Šoltés 2022</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion build/SkiaSharp.Linux.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.108" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/SkiaSharp.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.108" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/Svg.Skia.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Svg.Skia" Version="0.6.0-preview1" />
<PackageReference Include="Svg.Skia" Version="0.6.0-preview2" />
</ItemGroup>
</Project>
13 changes: 10 additions & 3 deletions src/SvgToXaml.Base/ViewModels/SvgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ namespace SvgToXaml.ViewModels;

public class SvgViewModel : ViewModelBase
{
private static readonly IAssetLoader s_assetLoader = new SkiaAssetLoader();
private static readonly SkiaModel s_model;
private static readonly IAssetLoader s_assetLoader;

public SKDrawable? Drawable { get; private set; }

public SKPicture? Model { get; private set; }

public SkiaSharp.SKPicture? Picture { get; private set; }

static SvgViewModel()
{
s_model = new SkiaModel(new SKSvgSettings());
s_assetLoader = new SkiaAssetLoader(new SkiaModel(new SKSvgSettings()));
}

private void Reset()
{
Model = null;
Expand All @@ -37,7 +44,7 @@ public void Dispose()
{
Model = SvgExtensions.ToModel(svgDocument, s_assetLoader, out var drawable, out _, ignoreAttributes);
Drawable = drawable;
Picture = Model?.ToSKPicture();
Picture = s_model.ToSKPicture(Model);
return Picture;
}
return null;
Expand All @@ -51,7 +58,7 @@ public void Dispose()
{
Model = SvgExtensions.ToModel(svgDocument, s_assetLoader, out var drawable, out _, ignoreAttributes);
Drawable = drawable;
Picture = Model?.ToSKPicture();
Picture = s_model.ToSKPicture(Model);
return Picture;
}
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/SvgToXamlConverter/Model/Drawing/DrawingGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
{
case ShimSkiaSharp.ClipPathCanvasCommand(var clipPath, _, _):
{
var path = Svg.Skia.SkiaModelExtensions.ToSKPath(clipPath);
var path = Factory.s_model.ToSKPath(clipPath);
if (path is null)
{
break;
Expand All @@ -111,7 +111,7 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
}
case ShimSkiaSharp.ClipRectCanvasCommand(var skRect, _, _):
{
var rect = Svg.Skia.SkiaModelExtensions.ToSKRect(skRect);
var rect = Factory.s_model.ToSKRect(skRect);
var path = new SkiaSharp.SKPath();
path.AddRect(rect);

Expand All @@ -129,7 +129,7 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
}
case ShimSkiaSharp.SetMatrixCanvasCommand(var skMatrix):
{
var matrix = Svg.Skia.SkiaModelExtensions.ToSKMatrix(skMatrix);
var matrix = Factory.s_model.ToSKMatrix(skMatrix);
if (matrix.IsIdentity)
{
break;
Expand Down Expand Up @@ -291,7 +291,7 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
}
case ShimSkiaSharp.DrawPathCanvasCommand(var skPath, var skPaint):
{
var path = Svg.Skia.SkiaModelExtensions.ToSKPath(skPath);
var path = Factory.s_model.ToSKPath(skPath);
if (path.IsEmpty)
{
break;
Expand All @@ -306,7 +306,7 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
}
case ShimSkiaSharp.DrawTextCanvasCommand(var text, var x, var y, var skPaint):
{
var paint = Svg.Skia.SkiaModelExtensions.ToSKPaint(skPaint);
var paint = Factory.s_model.ToSKPaint(skPaint);
var path = paint.GetTextPath(text, x, y);
if (path.IsEmpty)
{
Expand Down Expand Up @@ -350,4 +350,4 @@ private void Initialize(ShimSkiaSharp.SKPicture? picture, ResourceDictionary? re
}
}
}
}
}
22 changes: 12 additions & 10 deletions src/SvgToXamlConverter/Model/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace SvgToXamlConverter.Model;

internal static class Factory
{
internal static Svg.Skia.SkiaModel s_model = new Svg.Skia.SkiaModel(new Svg.Skia.SKSvgSettings());

public static Brush CreateBrush(ShimSkiaSharp.ColorShader colorShader, SkiaSharp.SKRect skBounds, string? key = null)
{
var brush = new SolidColorBrush
Expand All @@ -27,9 +29,9 @@ public static LinearGradientBrush CreateBrush(ShimSkiaSharp.LinearGradientShader
Bounds = skBounds,
LocalMatrix = linearGradientShader.LocalMatrix is null
? null
: Svg.Skia.SkiaModelExtensions.ToSKMatrix(linearGradientShader.LocalMatrix.Value),
Start = Svg.Skia.SkiaModelExtensions.ToSKPoint(linearGradientShader.Start),
End = Svg.Skia.SkiaModelExtensions.ToSKPoint(linearGradientShader.End),
: s_model.ToSKMatrix(linearGradientShader.LocalMatrix.Value),
Start = s_model.ToSKPoint(linearGradientShader.Start),
End = s_model.ToSKPoint(linearGradientShader.End),
Mode = linearGradientShader.Mode
};

Expand All @@ -54,8 +56,8 @@ public static Brush CreateBrush(ShimSkiaSharp.RadialGradientShader radialGradien
Bounds = skBounds,
LocalMatrix = radialGradientShader.LocalMatrix is null
? null
: Svg.Skia.SkiaModelExtensions.ToSKMatrix(radialGradientShader.LocalMatrix.Value),
Center = Svg.Skia.SkiaModelExtensions.ToSKPoint(radialGradientShader.Center),
: s_model.ToSKMatrix(radialGradientShader.LocalMatrix.Value),
Center = s_model.ToSKPoint(radialGradientShader.Center),
Radius = radialGradientShader.Radius,
Mode = radialGradientShader.Mode
};
Expand All @@ -81,9 +83,9 @@ public static Brush CreateBrush(ShimSkiaSharp.TwoPointConicalGradientShader twoP
Bounds = skBounds,
LocalMatrix = twoPointConicalGradientShader.LocalMatrix is null
? null
: Svg.Skia.SkiaModelExtensions.ToSKMatrix(twoPointConicalGradientShader.LocalMatrix.Value),
Start = Svg.Skia.SkiaModelExtensions.ToSKPoint(twoPointConicalGradientShader.Start),
End = Svg.Skia.SkiaModelExtensions.ToSKPoint(twoPointConicalGradientShader.End),
: s_model.ToSKMatrix(twoPointConicalGradientShader.LocalMatrix.Value),
Start = s_model.ToSKPoint(twoPointConicalGradientShader.Start),
End = s_model.ToSKPoint(twoPointConicalGradientShader.End),
StartRadius = twoPointConicalGradientShader.StartRadius,
EndRadius = twoPointConicalGradientShader.EndRadius,
Mode = twoPointConicalGradientShader.Mode
Expand All @@ -108,7 +110,7 @@ public static Brush CreateBrush(ShimSkiaSharp.TwoPointConicalGradientShader twoP
{
Key = key,
Bounds = skBounds,
LocalMatrix = Svg.Skia.SkiaModelExtensions.ToSKMatrix(pictureShader.LocalMatrix),
LocalMatrix = s_model.ToSKMatrix(pictureShader.LocalMatrix),
Picture = new Image(new DrawingImage(new DrawingGroup(pictureShader.Src))),
CullRect = pictureShader.Src?.CullRect ?? ShimSkiaSharp.SKRect.Empty,
Tile = pictureShader.Tile,
Expand Down Expand Up @@ -154,4 +156,4 @@ public static Brush CreateBrush(ShimSkiaSharp.TwoPointConicalGradientShader twoP

return pen;
}
}
}

0 comments on commit 4962392

Please sign in to comment.