From d45d376659b97e92c8d036565e3e69ad4558b146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Thu, 29 Jul 2021 05:34:56 +0000 Subject: [PATCH] Add console app --- SvgToXaml.sln | 7 ++++ SvgToXaml/SvgToXaml.csproj | 39 +++++++++++-------- SvgToXaml/ViewModels/FileItemViewModel.cs | 5 +-- SvgToXaml/ViewModels/MainWindowViewModel.cs | 1 + SvgToXamlConverter/Program.cs | 39 +++++++++++++++++++ .../SvgConverter.cs | 4 +- SvgToXamlConverter/SvgToXamlConverter.csproj | 12 ++++++ 7 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 SvgToXamlConverter/Program.cs rename {SvgToXaml => SvgToXamlConverter}/SvgConverter.cs (99%) create mode 100644 SvgToXamlConverter/SvgToXamlConverter.csproj diff --git a/SvgToXaml.sln b/SvgToXaml.sln index 48189b6..35fe6e5 100644 --- a/SvgToXaml.sln +++ b/SvgToXaml.sln @@ -1,7 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 +# Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgToXaml", "SvgToXaml\SvgToXaml.csproj", "{F6C225E1-F217-4146-8FC5-536B93B2ED93}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgToXamlConverter", "SvgToXamlConverter\SvgToXamlConverter.csproj", "{06BE0887-524B-4119-814D-42AE1DCA4C91}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.Release|Any CPU.ActiveCfg = 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 EndGlobal diff --git a/SvgToXaml/SvgToXaml.csproj b/SvgToXaml/SvgToXaml.csproj index c853e20..91b9a6b 100644 --- a/SvgToXaml/SvgToXaml.csproj +++ b/SvgToXaml/SvgToXaml.csproj @@ -1,18 +1,25 @@  - - WinExe - net5.0 - enable - - - - - - - - - - - - + + WinExe + net5.0 + enable + + + + + + + + + + + + + + + + + SvgConverter.cs + + diff --git a/SvgToXaml/ViewModels/FileItemViewModel.cs b/SvgToXaml/ViewModels/FileItemViewModel.cs index 7c37f3f..073678a 100644 --- a/SvgToXaml/ViewModels/FileItemViewModel.cs +++ b/SvgToXaml/ViewModels/FileItemViewModel.cs @@ -1,7 +1,6 @@ using System; using System.Windows.Input; using ReactiveUI; -using SkiaSharp; using Svg.Skia; namespace SvgToXaml.ViewModels @@ -11,7 +10,7 @@ namespace SvgToXaml.ViewModels private string _name; private string _path; private SKSvg? _svg; - private SKPicture? _picture; + private SkiaSharp.SKPicture? _picture; public string Name { @@ -31,7 +30,7 @@ namespace SvgToXaml.ViewModels private set => this.RaiseAndSetIfChanged(ref _svg, value); } - public SKPicture? Picture + public SkiaSharp.SKPicture? Picture { get => _picture; private set => this.RaiseAndSetIfChanged(ref _picture, value); diff --git a/SvgToXaml/ViewModels/MainWindowViewModel.cs b/SvgToXaml/ViewModels/MainWindowViewModel.cs index fd9480c..4f31532 100644 --- a/SvgToXaml/ViewModels/MainWindowViewModel.cs +++ b/SvgToXaml/ViewModels/MainWindowViewModel.cs @@ -10,6 +10,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Threading; using ReactiveUI; using Svg.Skia; +using SvgToXamlConverter; namespace SvgToXaml.ViewModels { diff --git a/SvgToXamlConverter/Program.cs b/SvgToXamlConverter/Program.cs new file mode 100644 index 0000000..b386ab2 --- /dev/null +++ b/SvgToXamlConverter/Program.cs @@ -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}"); + } + } + } + } +} diff --git a/SvgToXaml/SvgConverter.cs b/SvgToXamlConverter/SvgConverter.cs similarity index 99% rename from SvgToXaml/SvgConverter.cs rename to SvgToXamlConverter/SvgConverter.cs index ee6d069..69852c3 100644 --- a/SvgToXaml/SvgConverter.cs +++ b/SvgToXamlConverter/SvgConverter.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Text; using ShimSkiaSharp; -namespace SvgToXaml +namespace SvgToXamlConverter { public static class SvgConverter { - public static char[] NewLine = { '\r', '\n' }; + public static string NewLine = "\r\n"; public static string ToString(double value) { diff --git a/SvgToXamlConverter/SvgToXamlConverter.csproj b/SvgToXamlConverter/SvgToXamlConverter.csproj new file mode 100644 index 0000000..1f571b2 --- /dev/null +++ b/SvgToXamlConverter/SvgToXamlConverter.csproj @@ -0,0 +1,12 @@ + + + Exe + net5.0 + enable + + + + + + +