Skip to content

Commit c287050

Browse files
committed
Update PostscriptQRCode so it runs on Linux
1 parent d634b72 commit c287050

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

QRCoder/PostscriptQRCode.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
1+
#if !NETSTANDARD1_3
22
using System;
33
using System.Drawing;
44
using static QRCoder.QRCodeGenerator;
55

66
namespace QRCoder
77
{
88

9-
#if NET6_0_WINDOWS
10-
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
11-
#endif
129
public class PostscriptQRCode : AbstractQRCode, IDisposable
1310
{
1411
/// <summary>
@@ -143,9 +140,6 @@ sc sc scale
143140
";
144141
}
145142

146-
#if NET6_0_WINDOWS
147-
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
148-
#endif
149143
public static class PostscriptQRCodeHelper
150144
{
151145
public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false)
@@ -157,5 +151,4 @@ public static string GetQRCode(string plainText, int pointsPerModule, string dar
157151
}
158152
}
159153
}
160-
161154
#endif
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#if !NETCOREAPP1_1
2+
using QRCoder;
3+
using QRCoderTests.Helpers;
4+
using QRCoderTests.Helpers.XUnitExtenstions;
5+
using Shouldly;
6+
using System;
7+
using System.Drawing;
8+
using System.IO;
9+
using System.Text.RegularExpressions;
10+
using Xunit;
11+
12+
namespace QRCoderTests
13+
{
14+
public class PostscriptQRCodeRendererTests
15+
{
16+
[Fact]
17+
[Category("QRRenderer/PostscriptQRCode")]
18+
public void can_render_postscript_qrcode_simple()
19+
{
20+
//Create QR code
21+
var gen = new QRCodeGenerator();
22+
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
23+
var svg = new PostscriptQRCode(data).GetGraphic(5);
24+
25+
var result = HelperFunctions.StringToHash(RemoveCreationDate(svg));
26+
result.ShouldBe("06b90d1e64bf022a248453e5f91101a0");
27+
}
28+
29+
[Fact]
30+
[Category("QRRenderer/PostscriptQRCode")]
31+
public void can_render_postscript_qrcode_eps()
32+
{
33+
//Create QR code
34+
var gen = new QRCodeGenerator();
35+
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
36+
var svg = new PostscriptQRCode(data).GetGraphic(5, true);
37+
38+
var result = HelperFunctions.StringToHash(RemoveCreationDate(svg));
39+
result.ShouldBe("50f6152cdb0b685595d80e7888712d3b");
40+
}
41+
42+
[Fact]
43+
[Category("QRRenderer/PostscriptQRCode")]
44+
public void can_render_postscript_qrcode_size()
45+
{
46+
//Create QR code
47+
var gen = new QRCodeGenerator();
48+
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
49+
var svg = new PostscriptQRCode(data).GetGraphic(new Size(33, 33));
50+
51+
var result = HelperFunctions.StringToHash(RemoveCreationDate(svg));
52+
result.ShouldBe("49c7faaafef312eb4b6ea1fec195e63d");
53+
}
54+
55+
[Fact]
56+
[Category("QRRenderer/PostscriptQRCode")]
57+
public void can_render_postscript_qrcode_size_no_quiet_zones()
58+
{
59+
//Create QR code
60+
var gen = new QRCodeGenerator();
61+
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
62+
var svg = new PostscriptQRCode(data).GetGraphic(new Size(50, 50), false);
63+
64+
var result = HelperFunctions.StringToHash(RemoveCreationDate(svg));
65+
result.ShouldBe("9bfa0468e125d9815a39902133a10762");
66+
}
67+
68+
[Fact]
69+
[Category("QRRenderer/PostscriptQRCode")]
70+
public void can_render_postscript_qrcode_colors()
71+
{
72+
//Create QR code
73+
var gen = new QRCodeGenerator();
74+
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
75+
var svg = new PostscriptQRCode(data).GetGraphic(5, Color.Red, Color.Blue);
76+
77+
var result = HelperFunctions.StringToHash(RemoveCreationDate(svg));
78+
result.ShouldBe("2e001d7f67a446eb1b5df32ff5321808");
79+
}
80+
81+
private static string RemoveCreationDate(string text)
82+
{
83+
// Regex pattern to match lines that start with %%CreationDate: followed by any characters until the end of the line
84+
string pattern = @"%%CreationDate:.*\r?\n?";
85+
86+
// Use Regex.Replace to remove matching lines
87+
return Regex.Replace(text, pattern, string.Empty, RegexOptions.Multiline);
88+
}
89+
}
90+
}
91+
#endif

0 commit comments

Comments
 (0)