Browse Source

It appears I am commiting a SVG library

flabbet 11 months ago
parent
commit
275f7bbd4b

+ 11 - 0
src/PixiEditor.SVG/Elements/SvgCircle.cs

@@ -0,0 +1,11 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgCircle : SvgPrimitive
+{
+    public SvgProperty<SvgNumericUnit> Cx { get; } = new("cx");
+    public SvgProperty<SvgNumericUnit> Cy { get; } = new("cy");
+
+    public SvgProperty<SvgNumericUnit> R { get; } = new("r");
+}

+ 13 - 0
src/PixiEditor.SVG/Elements/SvgEllipse.cs

@@ -0,0 +1,13 @@
+using PixiEditor.SVG.Features;
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgEllipse : SvgPrimitive 
+{
+    public SvgProperty<SvgNumericUnit> Cx { get; } = new("cx");
+    public SvgProperty<SvgNumericUnit> Cy { get; } = new("cy"); 
+    
+    public SvgProperty<SvgNumericUnit> Rx { get; } = new("rx"); 
+    public SvgProperty<SvgNumericUnit> Ry { get; } = new("ry"); 
+}

+ 13 - 0
src/PixiEditor.SVG/Elements/SvgG.cs

@@ -0,0 +1,13 @@
+using PixiEditor.SVG.Features;
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgG : SvgElement, ITransformable, IFillable, IStrokable
+{
+    public List<SvgElement> Children { get; } = new();
+    public SvgProperty<SvgTransform> Transform { get; } = new("transform");
+    public SvgProperty<SvgColorUnit> Fill { get; } = new("fill");
+    public SvgProperty<SvgColorUnit> Stroke { get; } = new("stroke");
+    public SvgProperty<SvgNumericUnit> StrokeWidth { get; } = new("stroke-width");
+}

+ 12 - 0
src/PixiEditor.SVG/Elements/SvgLine.cs

@@ -0,0 +1,12 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgLine : SvgPrimitive
+{
+    public SvgProperty<SvgNumericUnit> X1 { get; } = new("x1");
+    public SvgProperty<SvgNumericUnit> Y1 { get; } = new("y1");
+    
+    public SvgProperty<SvgNumericUnit> X2 { get; } = new("x2");
+    public SvgProperty<SvgNumericUnit> Y2 { get; } = new("y2");
+}

+ 8 - 0
src/PixiEditor.SVG/Elements/SvgPolyline.cs

@@ -0,0 +1,8 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgPolyline : SvgPrimitive
+{
+    public SvgArray<SvgNumericUnit> Points { get; } = new SvgArray<SvgNumericUnit>("points");
+}

+ 12 - 0
src/PixiEditor.SVG/Elements/SvgPrimitive.cs

@@ -0,0 +1,12 @@
+using PixiEditor.SVG.Features;
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgPrimitive : SvgElement, ITransformable, IFillable, IStrokable
+{
+    public SvgProperty<SvgTransform> Transform { get; } = new("transform");
+    public SvgProperty<SvgColorUnit> Fill { get; } = new("fill");
+    public SvgProperty<SvgColorUnit> Stroke { get; } = new("stroke");
+    public SvgProperty<SvgNumericUnit> StrokeWidth { get; } = new("stroke-width");
+}

+ 15 - 0
src/PixiEditor.SVG/Elements/SvgRectangle.cs

@@ -0,0 +1,15 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Elements;
+
+public class SvgRectangle : SvgPrimitive
+{
+    public SvgProperty<SvgNumericUnit> X { get; } = new("x");
+    public SvgProperty<SvgNumericUnit> Y { get; } = new("y");
+
+    public SvgProperty<SvgNumericUnit> Width { get; } = new("width"); 
+    public SvgProperty<SvgNumericUnit> Height { get; } = new("height"); 
+    
+    public SvgProperty<SvgNumericUnit> Rx { get; } = new("rx");
+    public SvgProperty<SvgNumericUnit> Ry { get; } = new("ry");
+}

+ 8 - 0
src/PixiEditor.SVG/Features/IFillable.cs

@@ -0,0 +1,8 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Features;
+
+public interface IFillable
+{
+    public SvgProperty<SvgColorUnit> Fill { get; }
+}

+ 9 - 0
src/PixiEditor.SVG/Features/IStrokable.cs

@@ -0,0 +1,9 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Features;
+
+public interface IStrokable
+{
+    public SvgProperty<SvgColorUnit> Stroke { get; }
+    public SvgProperty<SvgNumericUnit> StrokeWidth { get; }
+}

+ 8 - 0
src/PixiEditor.SVG/Features/ITransformable.cs

@@ -0,0 +1,8 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG.Features;
+
+public interface ITransformable
+{
+    public SvgProperty<SvgTransform> Transform { get; }
+}

+ 13 - 0
src/PixiEditor.SVG/PixiEditor.SVG.csproj

@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <TargetFramework>net8.0</TargetFramework>
+        <ImplicitUsings>enable</ImplicitUsings>
+        <Nullable>enable</Nullable>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <ProjectReference Include="..\PixiEditor.Numerics\PixiEditor.Numerics.csproj" />
+    </ItemGroup>
+
+</Project>

+ 3 - 0
src/PixiEditor.SVG/README.md

@@ -0,0 +1,3 @@
+# Introduction 
+
+PixiEditor SVG is a .NET library that is used to read and write SVG files.

+ 10 - 0
src/PixiEditor.SVG/SvgDocument.cs

@@ -0,0 +1,10 @@
+using PixiEditor.Numerics;
+
+namespace PixiEditor.SVG;
+
+public class SvgDocument
+{
+   public string RootNamespace { get; set; } = "http://www.w3.org/2000/svg";
+   public string Version { get; set; } = "1.1";
+   public RectD ViewBox { get; set; }
+}

+ 6 - 0
src/PixiEditor.SVG/SvgElement.cs

@@ -0,0 +1,6 @@
+namespace PixiEditor.SVG;
+
+public class SvgElement
+{
+    
+}

+ 27 - 0
src/PixiEditor.SVG/SvgProperty.cs

@@ -0,0 +1,27 @@
+using PixiEditor.SVG.Units;
+
+namespace PixiEditor.SVG;
+
+public abstract class SvgProperty
+{
+    protected SvgProperty(string svgName)
+    {
+        SvgName = svgName;
+    }
+
+    public string SvgName { get; set; }
+    public ISvgUnit Value { get; set; }
+}
+
+public class SvgProperty<T> : SvgProperty where T : ISvgUnit
+{
+    public new T Value
+    {
+        get => (T)base.Value;
+        set => base.Value = value;
+    }
+
+    public SvgProperty(string svgName) : base(svgName)
+    {
+    }
+}

+ 11 - 0
src/PixiEditor.SVG/Units/SvgArray.cs

@@ -0,0 +1,11 @@
+namespace PixiEditor.SVG.Units;
+
+public class SvgArray<T> : SvgProperty where T : ISvgUnit
+{
+    public T[] Units { get; set; }
+
+    public SvgArray(string svgName, params T[] units) : base(svgName)
+    {
+        Units = units;
+    }
+}

+ 36 - 0
src/PixiEditor.SVG/Units/SvgColorUnit.cs

@@ -0,0 +1,36 @@
+namespace PixiEditor.SVG.Units;
+
+public struct SvgColorUnit : ISvgUnit
+{
+    public string Value { get; set; }
+
+    public SvgColorUnit(string value)
+    {
+        Value = value;
+    }
+
+    public static SvgColorUnit FromHex(string value)
+    {
+        return new SvgColorUnit(value);
+    }
+
+    public static SvgColorUnit FromRgb(int r, int g, int b)
+    {
+        return new SvgColorUnit($"rgb({r},{g},{b})");
+    }
+
+    public static SvgColorUnit FromRgba(int r, int g, int b, double a)
+    {
+        return new SvgColorUnit($"rgba({r},{g},{b},{a})");
+    }
+
+    public static SvgColorUnit FromHsl(int h, int s, int l)
+    {
+        return new SvgColorUnit($"hsl({h},{s}%,{l}%)");
+    }
+
+    public static SvgColorUnit FromHsla(int h, int s, int l, double a)
+    {
+        return new SvgColorUnit($"hsla({h},{s}%,{l}%,{a})");
+    }
+}

+ 32 - 0
src/PixiEditor.SVG/Units/SvgNumericUnit.cs

@@ -0,0 +1,32 @@
+namespace PixiEditor.SVG.Units;
+
+public struct SvgNumericUnit(double value, string postFix) : ISvgUnit
+{
+    public string PostFix { get; } = postFix;
+    public double Value { get; set; } = value;
+
+    public static SvgNumericUnit FromPixels(double value)
+    {
+        return new SvgNumericUnit(value, "px");
+    }
+    
+    public static SvgNumericUnit FromInches(double value)
+    {
+        return new SvgNumericUnit(value, "in");
+    }
+    
+    public static SvgNumericUnit FromCentimeters(double value)
+    {
+        return new SvgNumericUnit(value, "cm");
+    }
+    
+    public static SvgNumericUnit FromMillimeters(double value)
+    {
+        return new SvgNumericUnit(value, "mm");
+    }
+    
+    public static SvgNumericUnit FromPercent(double value)
+    {
+        return new SvgNumericUnit(value, "%");
+    }
+}

+ 11 - 0
src/PixiEditor.SVG/Units/SvgStringUnit.cs

@@ -0,0 +1,11 @@
+namespace PixiEditor.SVG.Units;
+
+public struct SvgStringUnit : ISvgUnit
+{
+    public SvgStringUnit(string value)
+    {
+        Value = value;
+    }
+
+    public string Value { get; set; }
+}

+ 12 - 0
src/PixiEditor.SVG/Units/SvgTransform.cs

@@ -0,0 +1,12 @@
+using System.Numerics;
+
+namespace PixiEditor.SVG.Units;
+
+public struct SvgTransform : ISvgUnit
+{
+    public SvgTransform()
+    {
+    }
+
+    public Matrix3x2 MatrixValue { get; set; } = Matrix3x2.Identity;
+}

+ 6 - 0
src/PixiEditor.SVG/Units/SvgUnit.cs

@@ -0,0 +1,6 @@
+namespace PixiEditor.SVG.Units;
+
+public interface ISvgUnit
+{
+    
+}

+ 31 - 0
src/PixiEditor.sln

@@ -114,6 +114,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libs", "Libs", "{E8A74431-F
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiParser", "PixiParser\src\PixiParser\PixiParser.csproj", "{0D3DE5D1-D984-407D-B2A6-7945F011B636}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.SVG", "PixiEditor.SVG\PixiEditor.SVG.csproj", "{786E1F87-4A10-493E-88BD-3F2461DBFCA0}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|x64 = Debug|x64
@@ -845,6 +847,34 @@ Global
 		{41B40602-2E8C-4B76-9BDB-B9FDE686ACCE}.Debug|x64.Build.0 = Debug|Any CPU
 		{41B40602-2E8C-4B76-9BDB-B9FDE686ACCE}.Debug|ARM64.ActiveCfg = Debug|Any CPU
 		{41B40602-2E8C-4B76-9BDB-B9FDE686ACCE}.Debug|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Debug|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Debug|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Debug|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevRelease|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevRelease|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevRelease|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevRelease|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevSteam|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevSteam|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevSteam|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.DevSteam|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX Debug|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX Debug|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX Debug|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX Debug|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.MSIX|ARM64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Release|x64.ActiveCfg = Release|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Release|x64.Build.0 = Release|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Release|ARM64.ActiveCfg = Release|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Release|ARM64.Build.0 = Release|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Steam|x64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Steam|x64.Build.0 = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Steam|ARM64.ActiveCfg = Debug|Any CPU
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0}.Steam|ARM64.Build.0 = Debug|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -896,6 +926,7 @@ Global
 		{1CCCA0DF-C0D4-4482-B15D-BB9702726C04} = {E8A74431-F76F-43B1-BC66-CA05E249E6F4}
 		{47BC7BC5-C070-49F4-8C8C-542DEDFC78B5} = {E8A74431-F76F-43B1-BC66-CA05E249E6F4}
 		{0D3DE5D1-D984-407D-B2A6-7945F011B636} = {E8A74431-F76F-43B1-BC66-CA05E249E6F4}
+		{786E1F87-4A10-493E-88BD-3F2461DBFCA0} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {D04B4AB0-CA33-42FD-A909-79966F9255C5}

+ 14 - 0
src/PixiEditor/Models/Files/VectorFileType.cs

@@ -0,0 +1,14 @@
+using PixiEditor.Models.IO;
+using PixiEditor.ViewModels.Document;
+
+namespace PixiEditor.Models.Files;
+
+internal abstract class VectorFileType : IoFileType
+{
+    public override FileTypeDialogDataSet.SetKind SetKind { get; } = FileTypeDialogDataSet.SetKind.Vector;
+
+    public override Task<SaveResult> TrySave(string pathWithExtension, DocumentViewModel document, ExportConfig config, ExportJob? job)
+    {
+        throw new NotImplementedException(); 
+    }
+}

+ 2 - 1
src/PixiEditor/Models/IO/FileTypeDialogDataSet.cs

@@ -16,7 +16,8 @@ internal class FileTypeDialogDataSet
         Pixi = 1 << 0,
         Image = 1 << 1,
         Video = 1 << 2,
-        Any = ~0
+        Vector = 1 << 3,
+        Any = ~0,
     }
     IEnumerable<IoFileType> fileTypes;
     string displayName;