Skip to content

Commit 489c282

Browse files
Merge pull request #9 from JeremyMeissner/1-import-svg-file
Some attributes compatibility for SVG files
2 parents f6bc7d6 + cd6bb0b commit 489c282

12 files changed

Lines changed: 814 additions & 1 deletion

File tree

FreeFrame.sln

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.1.32228.430
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeFrame", "FreeFrame\FreeFrame.csproj", "{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}"
77
EndProject
8-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7624DAC1-357B-4264-8501-F60942B4AD85}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeFrameTests", "FreeFrameTests\FreeFrameTests.csproj", "{C9665752-3F93-4FA8-8F2C-BF701D932E8A}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,6 +17,10 @@ Global
1717
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Debug|Any CPU.Build.0 = Debug|Any CPU
1818
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.ActiveCfg = Release|Any CPU
1919
{0B6F5913-5F9E-43E6-9C2B-6458771C0B64}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{C9665752-3F93-4FA8-8F2C-BF701D932E8A}.Release|Any CPU.Build.0 = Release|Any CPU
2024
EndGlobalSection
2125
GlobalSection(SolutionProperties) = preSolution
2226
HideSolutionNode = FALSE

FreeFrame/Components/Importer.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Xml;
7+
using FreeFrame.Components.Shapes;
8+
9+
namespace FreeFrame.Components
10+
{
11+
public static class Importer
12+
{
13+
static public void Import()
14+
{
15+
//TODO: find a solution for opening a crossplatform file dialog. Do I need a crossplatform dialog?
16+
//using (OpenFileDialog openFileDialog = new OpenFileDialog())
17+
//{
18+
//}
19+
}
20+
static public List<Shape> ImportFromStream(Stream pStream)
21+
{
22+
List<Shape> shapes = new List<Shape>();
23+
24+
using (XmlReader reader = XmlReader.Create(pStream))
25+
{
26+
while (reader.Read())
27+
{
28+
if (reader.HasAttributes)
29+
{
30+
//Console.WriteLine("Attributes of <" + reader.Name + ">");
31+
switch (reader.Name)
32+
{
33+
case "xml":
34+
case "svg":
35+
break; // Skip knowned elements
36+
case "polygon":
37+
shapes.Add(new SVGPolygon(reader));
38+
break;
39+
case "path":
40+
shapes.Add(new SVGPath(reader));
41+
break;
42+
case "rect":
43+
shapes.Add(new SVGRectangle(reader));
44+
break;
45+
case "circle":
46+
shapes.Add(new SVGCircle(reader));
47+
break;
48+
default:
49+
// TODO: show all the elemnt are not valid, be careful
50+
break;
51+
}
52+
}
53+
}
54+
}
55+
return (shapes);
56+
}
57+
static public List<Shape> ImportFromFile(string pFilename)
58+
{
59+
if (!File.Exists(pFilename))
60+
throw new ArgumentException($"'{pFilename}' file cannot be found.", nameof(pFilename)); // TODO: replace by a simple alert window
61+
62+
byte[] byteArray = Encoding.UTF8.GetBytes(File.ReadAllText(pFilename));
63+
64+
return ImportFromStream(new MemoryStream(byteArray));
65+
}
66+
static public List<Shape> ImportFromString(string pString)
67+
{
68+
byte[] byteArray = Encoding.UTF8.GetBytes(pString);
69+
70+
return ImportFromStream(new MemoryStream(byteArray));
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)