Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SVG exporting under .NET 6 on Linux #490

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0_OR_GREATER
using QRCoder.Extensions;
using System;
using System.Collections;
Expand All @@ -11,9 +11,6 @@

namespace QRCoder
{
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class SvgQRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -270,13 +267,16 @@ public class SvgLogo
private object _logoRaw;
private bool _isEmbedded;


#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
/// <summary>
/// Create a logo object to be used in SvgQRCode renderer
/// </summary>
/// <param name="iconRasterized">Logo to be rendered as Bitmap/rasterized graphic</param>
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
{
_iconSizePercent = iconSizePercent;
Expand All @@ -293,6 +293,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac
_logoRaw = iconRasterized;
_isEmbedded = false;
}
#endif

/// <summary>
/// Create a logo object to be used in SvgQRCode renderer
Expand Down Expand Up @@ -379,9 +380,6 @@ public enum MediaType : int
}
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class SvgQRCodeHelper
{
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
Expand Down
4 changes: 3 additions & 1 deletion QRCoderTests/SvgQRCodeRendererTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETCOREAPP1_1 && !NET6_0
#if !NETCOREAPP1_1
using System;
using Xunit;
using QRCoder;
Expand Down Expand Up @@ -103,6 +103,7 @@ public void can_render_svg_qrcode_without_quietzones_hex()
result.ShouldBe("4ab0417cc6127e347ca1b2322c49ed7d");
}

#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
[Fact]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if !NET6_0 would exclude both .NET 6 on Linux and .NET 6 on Windows. So the ifdef has been fixed to properly run on all applicable test targets

[Category("QRRenderer/SvgQRCode")]
public void can_render_svg_qrcode_with_png_logo()
Expand All @@ -121,6 +122,7 @@ public void can_render_svg_qrcode_with_png_logo()
var result = HelperFunctions.StringToHash(svg);
result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31");
}
#endif

[Fact]
[Category("QRRenderer/SvgQRCode")]
Expand Down
Loading