Skip to content

Commit 929e29a

Browse files
committed
code cleanup & bug fixes
1 parent 181178d commit 929e29a

26 files changed

+584
-410
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,5 @@ ModelManifest.xml
249249
/SvgFileTypePlugin.zip
250250
/setup.nsi
251251
/CreateZippedRelease.bat
252-
/header.bmp
252+
/header.bmp
253+
/SvgFileType/Properties
Binary file not shown.
-730 KB
Binary file not shown.

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
This is a Paint.NET filetype plugin for loading SVG (Scalable Vector Graphics) and its compressed variant SVGZ files.
77
SVG elements can be rendered as a flat image file or each on a separate layer.
88

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

11-
Tested on Paint.NET 4.2.16 & 4.3 Beta Build 7929.
11+
Tested on Paint.NET v4.2.16 & Paint.NET v4.3.2.
1212

1313
### Download links
1414

@@ -20,8 +20,8 @@ Here are the download links for latest release:
2020
<th>Manual Installation</th>
2121
</tr>
2222
<tr>
23-
<td><a href="https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET/releases/latest/download/SvgFileTypePlugin_setup.exe">SvgFileTypePlugin_setup.exe</a> (399 KiB)</td>
24-
<td><a href="https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET/releases/latest/download/SvgFileTypePlugin.zip">SvgFileTypePlugin.zip</a> (274 KiB)</td>
23+
<td><a href="https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET/releases/latest/download/SvgFileTypePlugin_setup.exe">SvgFileTypePlugin_setup.exe</a> (374 KiB)</td>
24+
<td><a href="https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET/releases/latest/download/SvgFileTypePlugin.zip">SvgFileTypePlugin.zip</a> (267 KiB)</td>
2525
</tr>
2626
</table>
2727

@@ -37,13 +37,12 @@ To manually install the plugin perform the following steps:
3737
* Download and extract `SvgFileTypePlugin.zip`
3838
* If you're using Paint.NET 4.3 or later:
3939
* If you're using Classic version of Paint.NET:
40-
* Create a new folder named `SvgFileTypePlugin` in the `<Paint.NET>\FileTypes` directory (default location is `C:\Program Files\paint.net\FileTypes`).
40+
* Copy _the `SvgFileTypePlugin` folder with its contents_ to the `<Paint.NET>\FileTypes` directory (default location is `C:\Program Files\paint.net\FileTypes`).
4141
* If you're using [Microsoft Store version of Paint.NET](https://www.microsoft.com/store/apps/9NBHCS1LX4R0):
42-
* Create a new folder named `SvgFileTypePlugin` in the `<Documents>\paint.net App Files\FileTypes` directory.
43-
* Put the extracted files in this newly created folder.
42+
* Copy _the `SvgFileTypePlugin` folder with its contents_ to the `<Documents>\paint.net App Files\FileTypes` directory.
4443
* If you're using Paint.NET 4.2:
4544
* If you're using Classic version of Paint.NET:
46-
* Put the extracted files in the `<Paint.NET>\FileTypes` directory (default location is `C:\Program Files\paint.net\FileTypes`).
45+
* Copy _the contents of `SvgFileTypePlugin` folder_ to the `<Paint.NET>\FileTypes` directory (default location is `C:\Program Files\paint.net\FileTypes`).
4746
* If you're using [Microsoft Store version of Paint.NET](https://www.microsoft.com/store/apps/9NBHCS1LX4R0):
48-
* Put the extracted files in the `<Documents>\paint.net App Files\FileTypes` directory.
47+
* Copy _the contents of `SvgFileTypePlugin` folder_ to the `<Documents>\paint.net App Files\FileTypes` directory.
4948
* Restart Paint.NET.

SvgFileType/SvgUnitExtensions.cs renamed to SvgFileType/Extensions/SvgUnitExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@
44

55
using Svg;
66
using System;
7+
using System.Drawing;
78

89
namespace SvgFileTypePlugin
910
{
1011
internal static class SvgUnitExtensions
1112
{
12-
public static int ToPixels(this SvgUnit unit, SvgElement owner)
13+
public static int ToDeviceValue(this SvgUnit unit, SvgElement owner)
1314
{
14-
if (owner == null) throw new ArgumentNullException(nameof(owner));
15+
if (owner == null)
16+
{
17+
throw new ArgumentNullException(nameof(owner));
18+
}
19+
1520
using (var renderer = SvgRenderer.FromNull())
1621
{
1722
return (int)Math.Round(unit.ToDeviceValue(renderer, UnitRenderingType.Other, owner));
1823
}
1924
}
25+
26+
//public static SizeF GetDeviceDimensions(this SvgDocument svg)
27+
//{
28+
// return new SizeF(svg.Width.ToDeviceValue(svg), svg.Height.ToDeviceValue(svg));
29+
//}
2030
}
2131
}

SvgFileType/FodyWeavers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
3-
<ILMerge IncludeAssemblies="Svg|Fizzler" NamespacePrefix="SvgFileTypePlugin$" FullImport="true" />
3+
<ILMerge IncludeAssemblies="Fizzler|Svg" NamespacePrefix="SvgFileTypePlugin$" FullImport="false" />
44
</Weavers>

SvgFileType/Import/ButtonHelper.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Osman Tunçelli. All rights reserved.
2+
// Use of this source code is governed by a LGPL license that can be
3+
// found in the COPYING file.
4+
5+
using System.Drawing;
6+
7+
namespace SvgFileTypePlugin.Import
8+
{
9+
internal static class ButtonHelper
10+
{
11+
public static void DrawText(Graphics g, Rectangle rectangle, Font font, string text, bool enabled, Color color)
12+
{
13+
//Create string format
14+
using (var sf = new StringFormat())
15+
{
16+
sf.Alignment = StringAlignment.Near;
17+
sf.LineAlignment = StringAlignment.Near;
18+
19+
if (enabled)
20+
{
21+
using (var solidBrush = new SolidBrush(color))
22+
{
23+
g.DrawString(text, font, solidBrush, rectangle, sf);
24+
}
25+
}
26+
else
27+
{
28+
g.DrawString(text, font, SystemBrushes.GrayText, rectangle, sf);
29+
}
30+
}
31+
}
32+
}
33+
}

SvgFileType/Import/MyCheckBox.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2021 Osman Tunçelli. All rights reserved.
2+
// Use of this source code is governed by a LGPL license that can be
3+
// found in the COPYING file.
4+
5+
using System.Drawing;
6+
using System.Windows.Forms;
7+
using System.Windows.Forms.VisualStyles;
8+
9+
namespace SvgFileTypePlugin.Import
10+
{
11+
internal sealed class MyCheckBox : CheckBox
12+
{
13+
public MyCheckBox()
14+
{
15+
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
16+
SetStyle(ControlStyles.UserPaint, true);
17+
}
18+
19+
protected override void OnPaint(PaintEventArgs e)
20+
{
21+
using (SolidBrush b = new SolidBrush(BackColor))
22+
{
23+
e.Graphics.FillRectangle(b, ClientRectangle);
24+
}
25+
26+
//Draw the checkbox
27+
CheckBoxState state;
28+
switch(CheckState)
29+
{
30+
case CheckState.Checked when Enabled:
31+
state = CheckBoxState.CheckedNormal;
32+
break;
33+
case CheckState.Checked when !Enabled:
34+
state = CheckBoxState.CheckedDisabled;
35+
break;
36+
case CheckState.Unchecked when Enabled:
37+
state = CheckBoxState.UncheckedNormal;
38+
break;
39+
case CheckState.Unchecked when !Enabled:
40+
state = CheckBoxState.UncheckedDisabled;
41+
break;
42+
case CheckState.Indeterminate when Enabled:
43+
state = CheckBoxState.MixedNormal;
44+
break;
45+
default:
46+
case CheckState.Indeterminate when !Enabled:
47+
state = CheckBoxState.MixedDisabled;
48+
break;
49+
}
50+
51+
Size glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);
52+
Point glyphLocation = new Point(0, (Bounds.Height - glyphSize.Height) / 2);
53+
CheckBoxRenderer.DrawCheckBox(e.Graphics, glyphLocation, state);
54+
int left = glyphSize.Width + 2;
55+
Rectangle textArea = new Rectangle(left, 1, Bounds.Width - left, Bounds.Height);
56+
ButtonHelper.DrawText(e.Graphics, textArea, Font, Text, Enabled, ForeColor);
57+
}
58+
}
59+
}

SvgFileType/Import/MyRadioButton.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2021 Osman Tunçelli. All rights reserved.
2+
// Use of this source code is governed by a LGPL license that can be
3+
// found in the COPYING file.
4+
5+
using System.Drawing;
6+
using System.Windows.Forms;
7+
using System.Windows.Forms.VisualStyles;
8+
9+
namespace SvgFileTypePlugin.Import
10+
{
11+
internal sealed class MyRadioButton : RadioButton
12+
{
13+
public MyRadioButton()
14+
{
15+
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
16+
SetStyle(ControlStyles.UserPaint, true);
17+
}
18+
19+
protected override void OnPaint(PaintEventArgs e)
20+
{
21+
using (SolidBrush b = new SolidBrush(BackColor))
22+
{
23+
e.Graphics.FillRectangle(b, ClientRectangle);
24+
}
25+
26+
//Draw the checkbox
27+
28+
RadioButtonState state;
29+
30+
if (Checked)
31+
{
32+
state = Enabled ? RadioButtonState.CheckedNormal : RadioButtonState.CheckedDisabled;
33+
}
34+
else
35+
{
36+
state = Enabled ? RadioButtonState.UncheckedNormal : RadioButtonState.UncheckedDisabled;
37+
}
38+
39+
Size glyphSize = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);
40+
Point glyphLocation = new Point(0, (Bounds.Height - glyphSize.Height) / 2);
41+
RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state);
42+
int left = glyphSize.Width + 2;
43+
Rectangle textArea = new Rectangle(left, 1, Bounds.Width - left, Bounds.Height);
44+
ButtonHelper.DrawText(e.Graphics, textArea, Font, Text, Enabled, ForeColor);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)