Skip to content

Commit 0fa1735

Browse files
committed
Added WithInkscapeEnabled to the ConfigurationFiles that can be used to enable Inkscape in the delegates.
1 parent 29e6386 commit 0fa1735

File tree

4 files changed

+109
-12
lines changed

4 files changed

+109
-12
lines changed

src/Magick.NET.Core/Configuration/IConfigurationFiles.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ public interface IConfigurationFiles
6969
/// Gets the type-ghostscript configuration.
7070
/// </summary>
7171
IConfigurationFile TypeGhostscript { get; }
72+
73+
/// <summary>
74+
/// Creates a new configuration with Inkscape enabled.
75+
/// </summary>
76+
/// <returns>A new configuration with Inkscape enabled.</returns>
77+
public IConfigurationFiles WithInkscapeEnabled();
7278
}

src/Magick.NET/Configuration/ConfigurationFile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public ConfigurationFile(string fileName)
1313
Data = LoadData();
1414
}
1515

16+
public ConfigurationFile(IConfigurationFile configurationFile)
17+
{
18+
FileName = configurationFile.FileName;
19+
Data = configurationFile.Data;
20+
}
21+
1622
public string FileName { get; }
1723

1824
public string Data { get; set; }

src/Magick.NET/Configuration/ConfigurationFiles.cs

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,45 @@ namespace ImageMagick.Configuration;
1010
/// </summary>
1111
public sealed class ConfigurationFiles : IConfigurationFiles
1212
{
13-
private ConfigurationFiles()
13+
private ConfigurationFiles(
14+
IConfigurationFile colors,
15+
IConfigurationFile configure,
16+
IConfigurationFile delegates,
17+
IConfigurationFile english,
18+
IConfigurationFile locale,
19+
IConfigurationFile log,
20+
IConfigurationFile policy,
21+
IConfigurationFile thresholds,
22+
IConfigurationFile type,
23+
IConfigurationFile typeGhostscript)
1424
{
15-
Colors = new ConfigurationFile("colors.xml");
16-
Configure = new ConfigurationFile("configure.xml");
17-
Delegates = new ConfigurationFile("delegates.xml");
18-
English = new ConfigurationFile("english.xml");
19-
Locale = new ConfigurationFile("locale.xml");
20-
Log = new ConfigurationFile("log.xml");
21-
Policy = new ConfigurationFile("policy.xml");
22-
Thresholds = new ConfigurationFile("thresholds.xml");
23-
Type = new ConfigurationFile("type.xml");
24-
TypeGhostscript = new ConfigurationFile("type-ghostscript.xml");
25+
Colors = colors;
26+
Configure = configure;
27+
Delegates = delegates;
28+
English = english;
29+
Locale = locale;
30+
Log = log;
31+
Policy = policy;
32+
Thresholds = thresholds;
33+
Type = type;
34+
TypeGhostscript = typeGhostscript;
2535
}
2636

2737
/// <summary>
2838
/// Gets the default configuration.
2939
/// </summary>
3040
public static IConfigurationFiles Default
31-
=> new ConfigurationFiles();
41+
=> new ConfigurationFiles(
42+
colors: new ConfigurationFile("colors.xml"),
43+
configure: new ConfigurationFile("configure.xml"),
44+
delegates: new ConfigurationFile("delegates.xml"),
45+
english: new ConfigurationFile("english.xml"),
46+
locale: new ConfigurationFile("locale.xml"),
47+
log: new ConfigurationFile("log.xml"),
48+
policy: new ConfigurationFile("policy.xml"),
49+
thresholds: new ConfigurationFile("thresholds.xml"),
50+
type: new ConfigurationFile("type.xml"),
51+
typeGhostscript: new ConfigurationFile("type-ghostscript.xml"));
3252

3353
/// <summary>
3454
/// Gets all the configuration files.
@@ -105,4 +125,26 @@ IConfigurationFiles IConfigurationFiles.Default
105125
/// Gets the type-ghostscript configuration.
106126
/// </summary>
107127
public IConfigurationFile TypeGhostscript { get; }
128+
129+
/// <summary>
130+
/// Creates a new configuration with Inkscape enabled.
131+
/// </summary>
132+
/// <returns>A new configuration with Inkscape enabled.</returns>
133+
public IConfigurationFiles WithInkscapeEnabled()
134+
{
135+
var delegates = new ConfigurationFile(Delegates);
136+
delegates.Data = delegates.Data.Replace(@"<!--<delegate decode=""svg:decode"" stealth=""True"" command=""&quot;inkscape&quot; &quot;%s&quot; - -export-filename=&quot;%s&quot; - -export-dpi=&quot;%s&quot; - -export-background=&quot;%s&quot; - -export-background-opacity=&quot;%s&quot; &gt; &quot;%s&quot; 2&gt;&amp;1""/>-->", @"<delegate decode=""svg:decode"" stealth=""True"" command=""&quot;inkscape&quot; &quot;%s&quot; --export-filename=&quot;%s&quot; --export-dpi=&quot;%s&quot; --export-background=&quot;%s&quot; --export-background-opacity=&quot;%s&quot; &gt; &quot;%s&quot; 2&gt;&amp;1""/>");
137+
138+
return new ConfigurationFiles(
139+
colors: new ConfigurationFile(Colors),
140+
configure: new ConfigurationFile(Configure),
141+
delegates: new ConfigurationFile(delegates),
142+
english: new ConfigurationFile(English),
143+
locale: new ConfigurationFile(Locale),
144+
log: new ConfigurationFile(Log),
145+
policy: new ConfigurationFile(Policy),
146+
thresholds: new ConfigurationFile(Thresholds),
147+
type: new ConfigurationFile(Type),
148+
typeGhostscript: new ConfigurationFile(TypeGhostscript));
149+
}
108150
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using ImageMagick.Configuration;
5+
using Xunit;
6+
7+
namespace Magick.NET.Tests;
8+
9+
public partial class ConfigurationFilesTests
10+
{
11+
public class TheWithInkscapeEnabledMethod
12+
{
13+
[Fact]
14+
public void ShouldReturnConfigurationWithInkScapeEnabled()
15+
{
16+
var defaultConfiguration = ConfigurationFiles.Default;
17+
defaultConfiguration.Colors.Data = "colors";
18+
defaultConfiguration.Configure.Data = "configure";
19+
defaultConfiguration.Delegates.Data = defaultConfiguration.Delegates.Data.Replace("\"browse\"", "\"foobar\"");
20+
defaultConfiguration.English.Data = "english";
21+
defaultConfiguration.Locale.Data = "locale";
22+
defaultConfiguration.Log.Data = "log";
23+
defaultConfiguration.Policy.Data = "policy";
24+
defaultConfiguration.Thresholds.Data = "thresholds";
25+
defaultConfiguration.Type.Data = "type";
26+
defaultConfiguration.TypeGhostscript.Data = "typeghostscript";
27+
28+
var configuration = defaultConfiguration.WithInkscapeEnabled();
29+
30+
Assert.Contains(" <delegate decode=\"svg:decode\" stealth=\"True\" command=\"&quot;inkscape&quot; &quot;%s&quot; --export-filename=&quot;%s&quot; --export-dpi=&quot;%s&quot; --export-background=&quot;%s&quot; --export-background-opacity=&quot;%s&quot; &gt; &quot;%s&quot; 2&gt;&amp;1\"/>", configuration.Delegates.Data);
31+
Assert.Contains("\"foobar\"", configuration.Delegates.Data);
32+
Assert.Equal("colors", configuration.Colors.Data);
33+
Assert.Equal("configure", configuration.Configure.Data);
34+
Assert.Equal("english", configuration.English.Data);
35+
Assert.Equal("locale", configuration.Locale.Data);
36+
Assert.Equal("log", configuration.Log.Data);
37+
Assert.Equal("policy", configuration.Policy.Data);
38+
Assert.Equal("thresholds", configuration.Thresholds.Data);
39+
Assert.Equal("type", configuration.Type.Data);
40+
Assert.Equal("typeghostscript", configuration.TypeGhostscript.Data);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)