This commit is contained in:
Wiesław Šoltés 2021-07-29 05:34:56 +00:00 коммит произвёл GitHub
Родитель 92a0c34717
Коммит d45d376659
7 изменённых файлов: 86 добавлений и 21 удалений

Просмотреть файл

@ -1,7 +1,10 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgToXaml", "SvgToXaml\SvgToXaml.csproj", "{F6C225E1-F217-4146-8FC5-536B93B2ED93}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgToXaml", "SvgToXaml\SvgToXaml.csproj", "{F6C225E1-F217-4146-8FC5-536B93B2ED93}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgToXamlConverter", "SvgToXamlConverter\SvgToXamlConverter.csproj", "{06BE0887-524B-4119-814D-42AE1DCA4C91}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -12,5 +15,9 @@ Global
{F6C225E1-F217-4146-8FC5-536B93B2ED93}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6C225E1-F217-4146-8FC5-536B93B2ED93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6C225E1-F217-4146-8FC5-536B93B2ED93}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6C225E1-F217-4146-8FC5-536B93B2ED93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6C225E1-F217-4146-8FC5-536B93B2ED93}.Release|Any CPU.Build.0 = Release|Any CPU {F6C225E1-F217-4146-8FC5-536B93B2ED93}.Release|Any CPU.Build.0 = Release|Any CPU
{06BE0887-524B-4119-814D-42AE1DCA4C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06BE0887-524B-4119-814D-42AE1DCA4C91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06BE0887-524B-4119-814D-42AE1DCA4C91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06BE0887-524B-4119-814D-42AE1DCA4C91}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

Просмотреть файл

@ -1,18 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.999-cibuild0015120-beta" /> <PackageReference Include="Avalonia" Version="0.10.999-cibuild0015120-beta" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0015120-beta" /> <PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0015120-beta" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0015120-beta" /> <PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0015120-beta" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.999-cibuild0015120-beta" /> <PackageReference Include="Avalonia.ReactiveUI" Version="0.10.999-cibuild0015120-beta" />
<PackageReference Include="Avalonia.Controls.Skia" Version="0.10.6.2" /> <PackageReference Include="Avalonia.Controls.Skia" Version="0.10.6.2" />
<PackageReference Include="Svg.Skia" Version="0.5.6.2" /> <PackageReference Include="Svg.Skia" Version="0.5.6.2" />
</ItemGroup> <PackageReference Include="SkiaSharp" Version="2.88.0-preview.61" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.61" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\SvgToXamlConverter\SvgConverter.cs">
<Link>SvgConverter.cs</Link>
</Compile>
</ItemGroup>
</Project> </Project>

Просмотреть файл

@ -1,7 +1,6 @@
using System; using System;
using System.Windows.Input; using System.Windows.Input;
using ReactiveUI; using ReactiveUI;
using SkiaSharp;
using Svg.Skia; using Svg.Skia;
namespace SvgToXaml.ViewModels namespace SvgToXaml.ViewModels
@ -11,7 +10,7 @@ namespace SvgToXaml.ViewModels
private string _name; private string _name;
private string _path; private string _path;
private SKSvg? _svg; private SKSvg? _svg;
private SKPicture? _picture; private SkiaSharp.SKPicture? _picture;
public string Name public string Name
{ {
@ -31,7 +30,7 @@ namespace SvgToXaml.ViewModels
private set => this.RaiseAndSetIfChanged(ref _svg, value); private set => this.RaiseAndSetIfChanged(ref _svg, value);
} }
public SKPicture? Picture public SkiaSharp.SKPicture? Picture
{ {
get => _picture; get => _picture;
private set => this.RaiseAndSetIfChanged(ref _picture, value); private set => this.RaiseAndSetIfChanged(ref _picture, value);

Просмотреть файл

@ -10,6 +10,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using ReactiveUI;
using Svg.Skia; using Svg.Skia;
using SvgToXamlConverter;
namespace SvgToXaml.ViewModels namespace SvgToXaml.ViewModels
{ {

Просмотреть файл

@ -0,0 +1,39 @@
using System;
using System.IO;
using Svg.Skia;
namespace SvgToXamlConverter
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 1 || args.Length == 2)
{
try
{
var inputPath = args[0];
var svg = new SKSvg();
var picture = svg.Load(inputPath);
var xaml = SvgConverter.ToXaml(svg.Model);
if (args.Length == 1)
{
Console.WriteLine(xaml);
}
if (args.Length == 2)
{
var outputPath = args[1];
File.WriteAllText(outputPath, xaml);
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
Console.WriteLine($"{ex.StackTrace}");
}
}
}
}
}

Просмотреть файл

@ -4,11 +4,11 @@ using System.Linq;
using System.Text; using System.Text;
using ShimSkiaSharp; using ShimSkiaSharp;
namespace SvgToXaml namespace SvgToXamlConverter
{ {
public static class SvgConverter public static class SvgConverter
{ {
public static char[] NewLine = { '\r', '\n' }; public static string NewLine = "\r\n";
public static string ToString(double value) public static string ToString(double value)
{ {

Просмотреть файл

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Svg.Skia" Version="0.5.6.2" />
<PackageReference Include="SkiaSharp" Version="2.88.0-preview.61" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.61" />
</ItemGroup>
</Project>