Skip to content

Commit 96ec17b

Browse files
committed
updated for paint.net v4.0.21
1 parent d399725 commit 96ec17b

File tree

10 files changed

+78
-65
lines changed

10 files changed

+78
-65
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is a Paint.NET filetype plugin for loading SVG (Scalable Vector Graphics) a
55

66
The plugin is a tiny wrapper around the [SVG.NET Library](https://github.com/vvvv/SVG) which does the actual SVG reading.
77

8-
Tested on Paint.NET 4.0.13.
8+
Tested on Paint.NET 4.0.21.
99

1010
Please check the [Releases](https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET/releases) section for binary download.
1111

SVGType/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

SVGType.sln renamed to SvgFileType.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGType", "SVGType\SVGType.csproj", "{C32235C8-90B3-4C43-B589-B821C84839E9}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgFileTypePlugin", "SvgFileType\SvgFileTypePlugin.csproj", "{C32235C8-90B3-4C43-B589-B821C84839E9}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,4 +19,7 @@ Global
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1ACF9C3B-BF8E-4939-88D4-BA7E2CE114E5}
24+
EndGlobalSection
2225
EndGlobal

SVGType/Properties/AssemblyInfo.cs renamed to SvgFileType/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
8-
[assembly: AssemblyTitle("SVGType")]
8+
[assembly: AssemblyTitle("SvgFileType")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("SVGType")]
13-
[assembly: AssemblyCopyright("Copyright © 2017")]
12+
[assembly: AssemblyProduct("SvgFileType")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

SVGType/SvgType.cs renamed to SvgFileType/SvgFileType.cs

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
using System.Drawing;
66
using System.IO;
77
using System.IO.Compression;
8-
using System.Linq;
98
using System.Windows.Forms;
109

11-
namespace SVGType
10+
namespace SvgFileTypePlugin
1211
{
13-
public class SvgType : FileType
12+
public class SvgFileType : FileType
1413
{
15-
public SvgType()
14+
public SvgFileType()
1615
: base(
1716
"Scalable Vector Graphics",
1817
FileTypeFlags.SupportsLoading,
@@ -33,26 +32,11 @@ private static Form GetMainForm()
3332
}
3433
}
3534

36-
private static bool IsCompressed(Stream input)
37-
{
38-
if (input.Length < 3)
39-
return false;
40-
var headerBytes = new byte[3];
41-
input.Read(headerBytes, 0, 3);
42-
input.Position = 0;
43-
return headerBytes.SequenceEqual(new byte[] {0x1f, 0x8b, 0x8});
44-
}
45-
4635
protected override Document OnLoad(Stream input)
4736
{
48-
if (IsCompressed(input))
49-
input = new GZipStream(input, CompressionMode.Decompress);
50-
5137
SvgDocument doc;
52-
using (input)
53-
{
54-
doc = SvgDocument.Open<SvgDocument>(input);
55-
}
38+
using (var wrapper = new SvgStreamWrapper(input))
39+
doc = SvgDocument.Open<SvgDocument>(wrapper.SvgStream);
5640

5741
bool keepAspectRatio;
5842
int resolution;
@@ -62,21 +46,21 @@ protected override Document OnLoad(Stream input)
6246
var vph = 0;
6347
if (!doc.Width.IsNone && !doc.Width.IsEmpty &&
6448
doc.Width.Type != SvgUnitType.Percentage)
65-
vpw = (int) doc.Width.Value;
49+
vpw = (int)doc.Width.Value;
6650
if (!doc.Height.IsNone && !doc.Height.IsEmpty &&
6751
doc.Height.Type != SvgUnitType.Percentage)
68-
vph = (int) doc.Height.Value;
69-
var vbx = (int) doc.ViewBox.MinX;
70-
var vby = (int) doc.ViewBox.MinY;
71-
var vbw = (int) doc.ViewBox.Width;
72-
var vbh = (int) doc.ViewBox.Height;
52+
vph = (int)doc.Height.Value;
53+
var vbx = (int)doc.ViewBox.MinX;
54+
var vby = (int)doc.ViewBox.MinY;
55+
var vbw = (int)doc.ViewBox.Width;
56+
var vbh = (int)doc.ViewBox.Height;
7357
DialogResult dr = DialogResult.Cancel;
74-
using (var dialog = new UIDialog())
58+
using (var dialog = new UiDialog())
7559
{
7660
Form mainForm = GetMainForm();
7761
if (mainForm != null)
7862
{
79-
mainForm.Invoke((MethodInvoker) (() =>
63+
mainForm.Invoke((MethodInvoker)(() =>
8064
{
8165
dialog.SetSvgInfo(vpw, vph, vbx, vby, vbw, vbh);
8266
dr = dialog.ShowDialog(mainForm);
@@ -107,5 +91,38 @@ protected override Document OnLoad(Stream input)
10791
}
10892
return Document.FromImage(bmp);
10993
}
94+
95+
private sealed class SvgStreamWrapper : IDisposable
96+
{
97+
public Stream SvgStream { get; }
98+
99+
public SvgStreamWrapper(Stream input)
100+
{
101+
if (input.Length < 3)
102+
throw new InvalidDataException();
103+
var headerBytes = new byte[3];
104+
input.Read(headerBytes, 0, 3);
105+
input.Position = 0;
106+
if (headerBytes[0] == 0x1f && headerBytes[1] == 0x8b && headerBytes[2] == 0x8)
107+
SvgStream = new GZipStream(input, CompressionMode.Decompress, true);
108+
else
109+
SvgStream = input;
110+
}
111+
112+
#region IDisposable
113+
114+
private bool _disposed;
115+
116+
public void Dispose()
117+
{
118+
if (_disposed)
119+
return;
120+
if (SvgStream is GZipStream)
121+
SvgStream.Dispose();
122+
_disposed = true;
123+
}
124+
125+
#endregion
126+
}
110127
}
111128
}

SVGType/SvgTypeFactory.cs renamed to SvgFileType/SvgFileTypeFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using PaintDotNet;
22

3-
namespace SVGType
3+
namespace SvgFileTypePlugin
44
{
5-
public class SvgTypeFactory : IFileTypeFactory
5+
public class SvgFileTypeFactory : IFileTypeFactory
66
{
77
public FileType[] GetFileTypeInstances()
88
{
99
return new FileType[]
1010
{
11-
new SvgType()
11+
new SvgFileType()
1212
};
1313
}
1414
}

SVGType/SVGType.csproj renamed to SvgFileType/SvgFileTypePlugin.csproj

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<ProjectGuid>{C32235C8-90B3-4C43-B589-B821C84839E9}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>SVGType</RootNamespace>
11-
<AssemblyName>SVGType</AssemblyName>
12-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
10+
<RootNamespace>SvgFileTypePlugin</RootNamespace>
11+
<AssemblyName>SvgFileType</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
@@ -40,9 +40,9 @@
4040
<Reference Include="PaintDotNet.Data">
4141
<HintPath>C:\Program Files\paint.net\PaintDotNet.Data.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Svg, Version=2.2.1.39233, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Svg.2.3.0\lib\net35\Svg.dll</HintPath>
45-
<Private>True</Private>
43+
<Reference Include="Svg, Version=2.2.1.10396, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
44+
<SpecificVersion>False</SpecificVersion>
45+
<HintPath>..\..\..\Downloads\SVG-master\Source\bin\Release\Svg.dll</HintPath>
4646
</Reference>
4747
<Reference Include="System" />
4848
<Reference Include="System.Core" />
@@ -51,22 +51,19 @@
5151
<Reference Include="System.Xml" />
5252
</ItemGroup>
5353
<ItemGroup>
54-
<Compile Include="SvgType.cs" />
54+
<Compile Include="SvgFileType.cs" />
5555
<Compile Include="Properties\AssemblyInfo.cs" />
56-
<Compile Include="SvgTypeFactory.cs" />
57-
<Compile Include="UIDialog.cs">
56+
<Compile Include="SvgFileTypeFactory.cs" />
57+
<Compile Include="UiDialog.cs">
5858
<SubType>Form</SubType>
5959
</Compile>
60-
<Compile Include="UIDialog.Designer.cs">
61-
<DependentUpon>UIDialog.cs</DependentUpon>
60+
<Compile Include="UiDialog.Designer.cs">
61+
<DependentUpon>UiDialog.cs</DependentUpon>
6262
</Compile>
6363
</ItemGroup>
6464
<ItemGroup>
65-
<None Include="packages.config" />
66-
</ItemGroup>
67-
<ItemGroup>
68-
<EmbeddedResource Include="UIDialog.resx">
69-
<DependentUpon>UIDialog.cs</DependentUpon>
65+
<EmbeddedResource Include="UiDialog.resx">
66+
<DependentUpon>UiDialog.cs</DependentUpon>
7067
</EmbeddedResource>
7168
</ItemGroup>
7269
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

SVGType/UIDialog.Designer.cs renamed to SvgFileType/UIDialog.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SVGType/UIDialog.cs renamed to SvgFileType/UIDialog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
using System.Drawing;
33
using System.Windows.Forms;
44

5-
namespace SVGType
5+
namespace SvgFileTypePlugin
66
{
7-
public partial class UIDialog : Form
7+
public partial class UiDialog : Form
88
{
9-
public UIDialog()
9+
public UiDialog()
1010
{
1111
InitializeComponent();
1212
}
File renamed without changes.

0 commit comments

Comments
 (0)