From 90f3347c2950fb5e01233f61d2e5d93326470cd7 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:00:50 -0400 Subject: [PATCH 01/32] Target .NET Standard 2.0, .NET Standard 2.1 and .NET 6.0 --- Directory.Build.props | 2 +- QRCoder.Xaml/QRCoder.Xaml.csproj | 6 +- QRCoder/ASCIIQRCode.cs | 2 - QRCoder/ArtQRCode.cs | 8 - QRCoder/Attributes/NotNullWhenAttribute.cs | 2 +- .../Attributes/StackTraceHiddenAttribute.cs | 21 ++ .../SupportedOSPlatformAttribute.cs | 39 ++++ QRCoder/Base64QRCode.cs | 19 -- QRCoder/Extensions/BitArrayExtensions.cs | 24 ++ QRCoder/Extensions/StreamExtensions.cs | 20 +- QRCoder/Extensions/StringExtensions.cs | 57 +---- QRCoder/Extensions/StringValueAttribute.cs | 55 ----- QRCoder/PayloadGenerator.cs | 4 - QRCoder/PayloadGenerator/OneTimePassword.cs | 10 +- .../PayloadGenerator/RussiaPaymentOrder.cs | 34 --- QRCoder/PdfByteQRCode.cs | 207 ++++++++---------- QRCoder/PngByteQRCode.cs | 12 - QRCoder/PostscriptQRCode.cs | 2 - QRCoder/QRCode.cs | 7 - QRCoder/QRCodeData.cs | 4 - QRCoder/QRCodeGenerator.cs | 51 +---- .../QRCodeGenerator/AlphanumericEncoder.cs | 4 - QRCoder/QRCodeGenerator/ByteDataSegment.cs | 6 +- QRCoder/QRCodeGenerator/CodewordBlock.cs | 4 - QRCoder/QRCodeGenerator/GaloisField.cs | 8 - QRCoder/QRCodeGenerator/NumericDataSegment.cs | 4 +- QRCoder/QRCodeGenerator/Polynom.cs | 53 ----- QRCoder/QRCoder.csproj | 22 +- QRCoder/SvgQRCode.cs | 18 +- QRCoderConsole/Program.cs | 4 +- QRCoderConsole/QRCoderConsole.csproj | 11 +- QRCoderDemo/QRCoderDemo.csproj | 4 +- QRCoderTests/QRCoderTests.csproj | 11 +- 33 files changed, 239 insertions(+), 496 deletions(-) create mode 100644 QRCoder/Attributes/StackTraceHiddenAttribute.cs create mode 100644 QRCoder/Attributes/SupportedOSPlatformAttribute.cs delete mode 100644 QRCoder/Extensions/StringValueAttribute.cs diff --git a/Directory.Build.props b/Directory.Build.props index cca9d899..a3d0495c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -39,7 +39,7 @@ true True true - $(NoWarn);IDE0005;CA1510 + $(NoWarn);IDE0005;CA1510;CA1708 True 8-recommended diff --git a/QRCoder.Xaml/QRCoder.Xaml.csproj b/QRCoder.Xaml/QRCoder.Xaml.csproj index e023aff2..467b48b4 100644 --- a/QRCoder.Xaml/QRCoder.Xaml.csproj +++ b/QRCoder.Xaml/QRCoder.Xaml.csproj @@ -2,8 +2,8 @@ - net35;net40;net5.0-windows;net6.0-windows - true + net462;net6.0-windows + true true @@ -16,7 +16,7 @@ f9ec6466-b807-40ae-bc05-db9f88967c0c - + diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index 6ba02124..9bffc6ce 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -56,7 +56,6 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString var sideLength = (QrCodeData.ModuleMatrix.Count - quietZonesModifier) * verticalNumberOfRepeats; var qrCode = new string[sideLength]; var lineCapacity = (QrCodeData.ModuleMatrix.Count - quietZonesModifier) * repeatPerModule * darkColorString.Length; -#if HAS_SPAN if (darkColorString.Length == whiteSpaceString.Length && lineCapacity < 510) { Span row = stackalloc char[512].Slice(0, lineCapacity); @@ -78,7 +77,6 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString } return qrCode; } -#endif var lineBuilder = new StringBuilder(lineCapacity); for (var y = 0; y < sideLength; y++) { diff --git a/QRCoder/ArtQRCode.cs b/QRCoder/ArtQRCode.cs index 7ace0d9b..383d3742 100644 --- a/QRCoder/ArtQRCode.cs +++ b/QRCoder/ArtQRCode.cs @@ -1,5 +1,3 @@ -#if SYSTEM_DRAWING - using System.Drawing; using System.Drawing.Drawing2D; using static QRCoder.ArtQRCode; @@ -11,9 +9,7 @@ namespace QRCoder; /// /// Represents an art-style QR code generator that provides functionality to render QR codes with dots as modules. /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public class ArtQRCode : AbstractQRCode, IDisposable { /// @@ -266,9 +262,7 @@ public enum BackgroundImageStyle /// /// Provides static methods for creating art-style QR codes. /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public static class ArtQRCodeHelper { /// @@ -302,5 +296,3 @@ public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color dark return qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, backgroundColor, backgroundImage, pixelSizeFactor, drawQuietZones, quietZoneRenderingStyle, backgroundImageStyle, finderPatternImage); } } - -#endif diff --git a/QRCoder/Attributes/NotNullWhenAttribute.cs b/QRCoder/Attributes/NotNullWhenAttribute.cs index 258826ac..56769228 100644 --- a/QRCoder/Attributes/NotNullWhenAttribute.cs +++ b/QRCoder/Attributes/NotNullWhenAttribute.cs @@ -1,4 +1,4 @@ -#if !NETCOREAPP && !NETSTANDARD2_1 +#if NETSTANDARD2_0 namespace System.Diagnostics.CodeAnalysis; /// diff --git a/QRCoder/Attributes/StackTraceHiddenAttribute.cs b/QRCoder/Attributes/StackTraceHiddenAttribute.cs new file mode 100644 index 00000000..f30a8fb1 --- /dev/null +++ b/QRCoder/Attributes/StackTraceHiddenAttribute.cs @@ -0,0 +1,21 @@ +#if !NET6_0_OR_GREATER + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics; + +/// +/// Types and Methods attributed with StackTraceHidden will be omitted from the stack trace text shown in StackTrace.ToString() +/// and Exception.StackTrace +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)] +public sealed class StackTraceHiddenAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public StackTraceHiddenAttribute() { } +} + +#endif diff --git a/QRCoder/Attributes/SupportedOSPlatformAttribute.cs b/QRCoder/Attributes/SupportedOSPlatformAttribute.cs new file mode 100644 index 00000000..40a8483b --- /dev/null +++ b/QRCoder/Attributes/SupportedOSPlatformAttribute.cs @@ -0,0 +1,39 @@ +#if !NET6_0_OR_GREATER +#pragma warning disable IDE0060 // Remove unused parameter + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Runtime.Versioning; + +/// +/// Records the operating system (and minimum version) that supports an API. Multiple attributes can be +/// applied to indicate support on multiple operating systems. +/// +/// +/// Callers can apply a +/// or use guards to prevent calls to APIs on unsupported operating systems. +/// +/// A given platform should only be specified once. +/// +[AttributeUsage( + AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Interface | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +internal sealed class SupportedOSPlatformAttribute : Attribute +{ + public SupportedOSPlatformAttribute(string platformName) + { + } +} + +#endif diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 166cc49f..3f713fd3 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -1,4 +1,3 @@ -#if !NETSTANDARD1_3 using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; @@ -88,7 +87,6 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, return Convert.ToBase64String(pngData, Base64FormattingOptions.None); } -#if SYSTEM_DRAWING #pragma warning disable CA1416 // Validate platform compatibility var qr = new QRCode(QrCodeData); var base64 = string.Empty; @@ -98,12 +96,8 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, } return base64; #pragma warning restore CA1416 // Validate platform compatibility -#else - throw new PlatformNotSupportedException("Only the PNG image type is supported on this platform."); -#endif } -#if SYSTEM_DRAWING /// /// Returns a base64-encoded string that contains the resulting QR code as an image with an embedded icon. /// @@ -116,9 +110,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, /// Indicates if quiet zones around the QR code should be drawn. /// The type of image to generate (PNG, JPEG, GIF). /// Returns the QR code graphic as a base64-encoded string. -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Bitmap icon, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true, ImageType imgType = ImageType.Png) { var qr = new QRCode(QrCodeData); @@ -129,18 +121,14 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, } return base64; } -#endif -#if SYSTEM_DRAWING /// /// Converts a bitmap to a base64-encoded string. /// /// The bitmap to convert. /// The type of image (PNG, JPEG, GIF). /// Returns the base64-encoded string representation of the bitmap. -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif private static string BitmapToBase64(Bitmap bmp, ImageType imgType) { var iFormat = imgType switch @@ -154,7 +142,6 @@ private static string BitmapToBase64(Bitmap bmp, ImageType imgType) bmp.Save(memoryStream, iFormat); return Convert.ToBase64String(memoryStream.ToArray(), Base64FormattingOptions.None); } -#endif /// /// Specifies the type of image to generate. @@ -164,16 +151,12 @@ public enum ImageType /// /// Graphics Interchange Format (GIF) image format, a bitmap image format with limited color support /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif Gif, /// /// Joint Photographic Experts Group (JPEG) image format, a lossy compressed image format /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif Jpeg, /// /// Portable Network Graphics (PNG) image format, a lossless raster graphics format @@ -211,5 +194,3 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar return qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex, drawQuietZones, imgType); } } - -#endif diff --git a/QRCoder/Extensions/BitArrayExtensions.cs b/QRCoder/Extensions/BitArrayExtensions.cs index 1baf039e..28906797 100644 --- a/QRCoder/Extensions/BitArrayExtensions.cs +++ b/QRCoder/Extensions/BitArrayExtensions.cs @@ -22,4 +22,28 @@ public static int CopyTo(this BitArray source, BitArray destination, int sourceO } return destinationOffset + count; } + + public static void ShiftTowardsBit0(this BitArray fStrEcc, int num) + { +#if !NETSTANDARD2_0 + fStrEcc.RightShift(num); // Shift towards bit 0 +#else + for (var i = 0; i < fStrEcc.Length - num; i++) + fStrEcc[i] = fStrEcc[i + num]; + for (var i = fStrEcc.Length - num; i < fStrEcc.Length; i++) + fStrEcc[i] = false; +#endif + } + + public static void ShiftAwayFromBit0(this BitArray fStrEcc, int num) + { +#if !NETSTANDARD2_0 + fStrEcc.LeftShift(num); // Shift away from bit 0 +#else + for (var i = fStrEcc.Length - 1; i >= num; i--) + fStrEcc[i] = fStrEcc[i - num]; + for (var i = 0; i < num; i++) + fStrEcc[i] = false; +#endif + } } diff --git a/QRCoder/Extensions/StreamExtensions.cs b/QRCoder/Extensions/StreamExtensions.cs index c260d327..56c972fc 100644 --- a/QRCoder/Extensions/StreamExtensions.cs +++ b/QRCoder/Extensions/StreamExtensions.cs @@ -1,19 +1,17 @@ -#if NET35 +#if NETSTANDARD2_0 + +using System; +using System.Collections.Generic; +using System.Text; + namespace QRCoder; internal static class StreamExtensions { - /// - /// Copies a stream to another stream. - /// - public static void CopyTo(this System.IO.Stream input, System.IO.Stream output) + public static void Write(this Stream stream, ReadOnlySpan bytes) { - byte[] buffer = new byte[16 * 1024]; - int bytesRead; - while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) - { - output.Write(buffer, 0, bytesRead); - } + stream.Write(bytes.ToArray(), 0, bytes.Length); } } + #endif diff --git a/QRCoder/Extensions/StringExtensions.cs b/QRCoder/Extensions/StringExtensions.cs index 6ad02de9..8d43b525 100644 --- a/QRCoder/Extensions/StringExtensions.cs +++ b/QRCoder/Extensions/StringExtensions.cs @@ -1,46 +1,10 @@ using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace QRCoder; internal static class StringExtensions { - /// - /// Indicates whether the specified string is null, empty, or consists only of white-space characters. - /// - /// - /// if the is null, empty, or white space; otherwise, . - /// - public static bool IsNullOrWhiteSpace( - [NotNullWhen(false)] - this string? value) - { -#if NET35 - if (value == null) - return true; - - for (int i = 0; i < value.Length; i++) - { - if (!char.IsWhiteSpace(value[i])) - return false; - } - - return true; -#else - return string.IsNullOrWhiteSpace(value); -#endif - } - -#if !NETCOREAPP2_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER - /// - /// Determines whether the beginning of this string instance matches the specified character. - /// - /// The string to check. - /// The character to compare. - /// true if value starts with c; otherwise, false. - internal static bool StartsWith(this string value, char c) - => value.Length > 0 && value[0] == c; -#endif - /// /// Converts a hex color string to a byte array. /// @@ -53,7 +17,7 @@ internal static byte[] HexColorToByteArray(this string colorString) offset = 1; byte[] byteColor = new byte[(colorString.Length - offset) / 2]; for (int i = 0; i < byteColor.Length; i++) -#if HAS_SPAN +#if !NETSTANDARD2_0 byteColor[i] = byte.Parse(colorString.AsSpan(i * 2 + offset, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); #else byteColor[i] = byte.Parse(colorString.Substring(i * 2 + offset, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); @@ -61,12 +25,6 @@ internal static byte[] HexColorToByteArray(this string colorString) return byteColor; } -#if NETSTANDARD1_3 - /// - internal static string ToString(this char c, CultureInfo _) - => c.ToString(); -#endif - /// /// Appends an integer value to the StringBuilder using invariant culture formatting. /// @@ -77,7 +35,7 @@ internal static void AppendInvariant(this StringBuilder sb, int num) #if NET6_0_OR_GREATER sb.Append(CultureInfo.InvariantCulture, $"{num}"); #else -#if HAS_SPAN +#if !NETSTANDARD2_0 Span buffer = stackalloc char[16]; if (num.TryFormat(buffer, out int charsWritten, default, CultureInfo.InvariantCulture)) { @@ -99,7 +57,7 @@ internal static void AppendInvariant(this StringBuilder sb, float num) #if NET6_0_OR_GREATER sb.Append(CultureInfo.InvariantCulture, $"{num:G7}"); #else -#if HAS_SPAN +#if !NETSTANDARD2_0 Span buffer = stackalloc char[16]; if (num.TryFormat(buffer, out int charsWritten, "G7", CultureInfo.InvariantCulture)) { @@ -110,4 +68,11 @@ internal static void AppendInvariant(this StringBuilder sb, float num) sb.Append(num.ToString("G7", CultureInfo.InvariantCulture)); #endif } + +#if NETSTANDARD2_0 + public static bool StartsWith(this string target, char value) + { + return target.Length > 0 && target[0] == value; + } +#endif } diff --git a/QRCoder/Extensions/StringValueAttribute.cs b/QRCoder/Extensions/StringValueAttribute.cs deleted file mode 100644 index ca93b888..00000000 --- a/QRCoder/Extensions/StringValueAttribute.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Reflection; - -namespace QRCoder.Extensions; - -/// -/// Used to represent a string value for a value in an enum -/// -[Obsolete("This attribute will be removed in a future version of QRCoder.")] -[AttributeUsage(AttributeTargets.Field)] -public class StringValueAttribute : Attribute -{ - - #region Properties - - /// - /// Holds the alue in an enum - /// - public string StringValue { get; protected set; } - - #endregion - - /// - /// Init a StringValue Attribute - /// - /// - public StringValueAttribute(string value) - { - StringValue = value; - } -} - -/// -/// Enumeration extension methods. -/// -[Obsolete("This class will be removed in a future version of QRCoder.")] -public static class CustomExtensions -{ - /// - /// Will get the string value for a given enum's value - /// -#if NET6_0_OR_GREATER - [RequiresUnreferencedCode("This method uses reflection to examine the provided enum value.")] -#endif - public static string? GetStringValue(this Enum value) - { -#if NETSTANDARD1_3 - var fieldInfo = value.GetType().GetRuntimeField(value.ToString()); -#else - var fieldInfo = value.GetType().GetField(value.ToString())!; -#endif - var attr = fieldInfo.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[]; - return attr!.Length > 0 ? attr[0].StringValue : null; - } -} diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 1bb15d81..064b61d5 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -1,7 +1,3 @@ -#if NETSTANDARD1_3 -using System.Reflection; -#endif - namespace QRCoder; /// diff --git a/QRCoder/PayloadGenerator/OneTimePassword.cs b/QRCoder/PayloadGenerator/OneTimePassword.cs index e81eeb87..f91ee602 100644 --- a/QRCoder/PayloadGenerator/OneTimePassword.cs +++ b/QRCoder/PayloadGenerator/OneTimePassword.cs @@ -174,7 +174,7 @@ private string TimeToString() /// StringBuilder to append the common fields. private void ProcessCommonFields(StringBuilder sb) { - if (Secret.IsNullOrWhiteSpace()) + if (string.IsNullOrWhiteSpace(Secret)) { throw new InvalidOperationException("Secret must be a filled out base32 encoded string"); } @@ -183,18 +183,18 @@ private void ProcessCommonFields(StringBuilder sb) string? escapedLabel = null; string? label = null; - if (!Issuer.IsNullOrWhiteSpace()) + if (!string.IsNullOrWhiteSpace(Issuer)) { - if (Issuer.Contains(':')) + if (Issuer!.Contains(':')) { throw new InvalidOperationException("Issuer must not have a ':'"); } escapedIssuer = Uri.EscapeDataString(Issuer); } - if (!Label.IsNullOrWhiteSpace()) + if (!string.IsNullOrWhiteSpace(Label)) { - if (Label.Contains(':')) + if (Label!.Contains(':')) { throw new InvalidOperationException("Label must not have a ':'"); } diff --git a/QRCoder/PayloadGenerator/RussiaPaymentOrder.cs b/QRCoder/PayloadGenerator/RussiaPaymentOrder.cs index adc6d159..3bd6cfc5 100644 --- a/QRCoder/PayloadGenerator/RussiaPaymentOrder.cs +++ b/QRCoder/PayloadGenerator/RussiaPaymentOrder.cs @@ -1,7 +1,3 @@ -#if NETSTANDARD1_3 -using System.Reflection; -#endif - namespace QRCoder; public static partial class PayloadGenerator @@ -65,9 +61,6 @@ public override string ToString() var cp = _characterSet.ToString().Replace("_", "-"); var bytes = ToBytes(); -#if !NETFRAMEWORK - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); -#endif return Encoding.GetEncoding(cp).GetString(bytes, 0, bytes.Length); } @@ -81,9 +74,6 @@ public byte[] ToBytes() { //Setup byte encoder //Encode return string as byte[] with correct CharacterSet -#if !NETFRAMEWORK - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); -#endif var cp = _characterSet.ToString().Replace("_", "-"); //Calculate the seperator @@ -140,17 +130,6 @@ private string DetermineSeparator() /// A List of strings private List GetOptionalFieldsAsList() { -#if NETSTANDARD1_3 - return typeof(OptionalFields).GetRuntimeProperties() - .Where(field => field.GetValue(_oFields) != null) - .Select(field => - { - var objValue = field.GetValue(_oFields, null); - var value = field.PropertyType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) : objValue.ToString(); - return $"{field.Name}={value}"; - }) - .ToList(); -#else return typeof(OptionalFields).GetProperties() .Where(field => field.GetValue(_oFields, null) != null) .Select(field => @@ -160,7 +139,6 @@ private List GetOptionalFieldsAsList() return $"{field.Name}={value}"; }) .ToList(); -#endif } @@ -170,17 +148,6 @@ private List GetOptionalFieldsAsList() /// A List of strings private List GetMandatoryFieldsAsList() { -#if NETSTANDARD1_3 - return typeof(MandatoryFields).GetRuntimeFields() - .Where(field => field.GetValue(_mFields) != null) - .Select(field => - { - var objValue = field.GetValue(_mFields); - var value = field.FieldType.Equals(typeof(DateTime?)) ? ((DateTime)objValue).ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) : objValue.ToString(); - return $"{field.Name}={value}"; - }) - .ToList(); -#else return typeof(MandatoryFields).GetFields() .Where(field => field.GetValue(_mFields) != null) .Select(field => @@ -190,7 +157,6 @@ private List GetMandatoryFieldsAsList() return $"{field.Name}={value}"; }) .ToList(); -#endif } /// diff --git a/QRCoder/PdfByteQRCode.cs b/QRCoder/PdfByteQRCode.cs index dd80fc84..130ceb97 100644 --- a/QRCoder/PdfByteQRCode.cs +++ b/QRCoder/PdfByteQRCode.cs @@ -55,120 +55,105 @@ public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string li //Create PDF document using var stream = new MemoryStream(); -#if NETFRAMEWORK - var writer = new StreamWriter(stream, System.Text.Encoding.ASCII); -#elif NET6_0_OR_GREATER - var writer = new StreamWriter(stream, System.Text.Encoding.ASCII, leaveOpen: true); -#else - var writer = new StreamWriter(stream, System.Text.Encoding.ASCII, 1024, true); -#endif - try + using var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true); + var xrefs = new List(); + + // PDF header - declares PDF version 1.5 + writer.Write("%PDF-1.5\r\n"); + writer.Flush(); + + // Binary comment - ensures PDF is treated as binary file (prevents text mode corruption) + stream.Write(_pdfBinaryComment, 0, _pdfBinaryComment.Length); + writer.WriteLine(); + + writer.Flush(); + xrefs.Add(stream.Position); + + // Object 1: Catalog - root of PDF document structure + writer.Write( + ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) + "<<\r\n" + // Begin dictionary + "/Type /Catalog\r\n" + // Declares this as the document catalog + "/Pages 2 0 R\r\n" + // References the Pages object (object 2) + ">>\r\n" + // End dictionary + "endobj\r\n" // End object + ); + + writer.Flush(); + xrefs.Add(stream.Position); + + // Object 2: Pages - defines page tree structure + writer.Write( + ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) + "<<\r\n" + // Begin dictionary + "/Count 1\r\n" + // Number of pages in document + "/Kids [ <<\r\n" + // Array of page objects - begin inline page dictionary + "/Type /Page\r\n" + // Declares this as a page + "/Parent 2 0 R\r\n" + // References parent Pages object + "/MediaBox [0 0 " + pdfMediaSize + " " + pdfMediaSize + "]\r\n" + // Page dimensions [x1 y1 x2 y2] + "/Resources << /ProcSet [ /PDF ] >>\r\n" + // Required resources: PDF operations only (no images) + "/Contents 3 0 R\r\n" + // References content stream (object 3) + ">> ]\r\n" + // End inline page dictionary and Kids array + ">>\r\n" + // End dictionary + "endobj\r\n" // End object + ); + + // Content stream - PDF drawing instructions + var scale = ToStr(imgSize * 72 / (float)dpi / moduleCount); // Scale factor to convert module units to PDF points + var pathCommands = CreatePathFromModules(); // Create path from dark modules + var content = "q\r\n" + // 'q' = Save graphics state + scale + " 0 0 -" + scale + " 0 " + pdfMediaSize + " cm\r\n" + // 'cm' = Transformation matrix: scale X, scale & flip Y, translate to top + lightColorPdf + " rg\r\n" + // 'rg' = Set RGB fill color for background + "0 0 " + ToStr(moduleCount) + " " + ToStr(moduleCount) + " re\r\n" + // 're' = Rectangle covering entire QR code + "f\r\n" + // 'f' = Fill background + darkColorPdf + " rg\r\n" + // 'rg' = Set RGB fill color for dark modules + pathCommands + // Add all dark module rectangles to path + "f*\r\n" + // 'f*' = Fill with even-odd rule + "Q"; // 'Q' = Restore graphics state + + writer.Flush(); + xrefs.Add(stream.Position); + + // Object 3: Content stream - contains the drawing instructions + writer.Write( + ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) + "<< /Length " + ToStr(content.Length) + " >>\r\n" + // Dictionary with stream length in bytes + "stream\r\n" + // Begin stream data + content + "endstream\r\n" + // Stream content followed by end stream marker + "endobj\r\n" // End object + ); + + writer.Flush(); + var startxref = checked((int)stream.Position); + + // Cross-reference table - maps object numbers to byte offsets + writer.Write( + "xref\r\n" + // Cross-reference table keyword + "0 " + ToStr(xrefs.Count + 1) + "\r\n" + // First object number (0) and count of entries + "0000000000 65535 f\r\n" // Entry 0: always free, generation 65535, 'f' = free + ); + + // Write byte offset for each object + foreach (var refValue in xrefs) { - var xrefs = new List(); - - // PDF header - declares PDF version 1.5 - writer.Write("%PDF-1.5\r\n"); - writer.Flush(); - - // Binary comment - ensures PDF is treated as binary file (prevents text mode corruption) - stream.Write(_pdfBinaryComment, 0, _pdfBinaryComment.Length); - writer.WriteLine(); - - writer.Flush(); - xrefs.Add(stream.Position); - - // Object 1: Catalog - root of PDF document structure - writer.Write( - ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) - "<<\r\n" + // Begin dictionary - "/Type /Catalog\r\n" + // Declares this as the document catalog - "/Pages 2 0 R\r\n" + // References the Pages object (object 2) - ">>\r\n" + // End dictionary - "endobj\r\n" // End object - ); - - writer.Flush(); - xrefs.Add(stream.Position); - - // Object 2: Pages - defines page tree structure - writer.Write( - ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) - "<<\r\n" + // Begin dictionary - "/Count 1\r\n" + // Number of pages in document - "/Kids [ <<\r\n" + // Array of page objects - begin inline page dictionary - "/Type /Page\r\n" + // Declares this as a page - "/Parent 2 0 R\r\n" + // References parent Pages object - "/MediaBox [0 0 " + pdfMediaSize + " " + pdfMediaSize + "]\r\n" + // Page dimensions [x1 y1 x2 y2] - "/Resources << /ProcSet [ /PDF ] >>\r\n" + // Required resources: PDF operations only (no images) - "/Contents 3 0 R\r\n" + // References content stream (object 3) - ">> ]\r\n" + // End inline page dictionary and Kids array - ">>\r\n" + // End dictionary - "endobj\r\n" // End object - ); - - // Content stream - PDF drawing instructions - var scale = ToStr(imgSize * 72 / (float)dpi / moduleCount); // Scale factor to convert module units to PDF points - var pathCommands = CreatePathFromModules(); // Create path from dark modules - var content = "q\r\n" + // 'q' = Save graphics state - scale + " 0 0 -" + scale + " 0 " + pdfMediaSize + " cm\r\n" + // 'cm' = Transformation matrix: scale X, scale & flip Y, translate to top - lightColorPdf + " rg\r\n" + // 'rg' = Set RGB fill color for background - "0 0 " + ToStr(moduleCount) + " " + ToStr(moduleCount) + " re\r\n" + // 're' = Rectangle covering entire QR code - "f\r\n" + // 'f' = Fill background - darkColorPdf + " rg\r\n" + // 'rg' = Set RGB fill color for dark modules - pathCommands + // Add all dark module rectangles to path - "f*\r\n" + // 'f*' = Fill with even-odd rule - "Q"; // 'Q' = Restore graphics state - - writer.Flush(); - xrefs.Add(stream.Position); - - // Object 3: Content stream - contains the drawing instructions - writer.Write( - ToStr(xrefs.Count) + " 0 obj\r\n" + // Object number and generation number (0) - "<< /Length " + ToStr(content.Length) + " >>\r\n" + // Dictionary with stream length in bytes - "stream\r\n" + // Begin stream data - content + "endstream\r\n" + // Stream content followed by end stream marker - "endobj\r\n" // End object - ); - - writer.Flush(); - var startxref = checked((int)stream.Position); - - // Cross-reference table - maps object numbers to byte offsets - writer.Write( - "xref\r\n" + // Cross-reference table keyword - "0 " + ToStr(xrefs.Count + 1) + "\r\n" + // First object number (0) and count of entries - "0000000000 65535 f\r\n" // Entry 0: always free, generation 65535, 'f' = free - ); - - // Write byte offset for each object - foreach (var refValue in xrefs) - { - // Write each entry as a 10-digit zero-padded byte offset, 5-digit zero-padded generation number (0), and 'n' = in use - writer.Write(checked((int)refValue).ToString("0000000000", CultureInfo.InvariantCulture) + " 00000 n\r\n"); - } - - // Trailer - provides location of catalog and xref table - writer.Write( - "trailer\r\n" + // Trailer keyword - "<<\r\n" + // Begin trailer dictionary - "/Size " + ToStr(xrefs.Count + 1) + "\r\n" + // Total number of entries in xref table - "/Root 1 0 R\r\n" + // Reference to catalog object - ">>\r\n" + // End trailer dictionary - "startxref\r\n" + // Start of xref keyword - ToStr(startxref) + "\r\n" + // Byte offset of xref table - "%%EOF" // End of file marker - ); - - writer.Flush(); - } - finally - { -#if !NETFRAMEWORK - writer.Dispose(); -#endif + // Write each entry as a 10-digit zero-padded byte offset, 5-digit zero-padded generation number (0), and 'n' = in use + writer.Write(checked((int)refValue).ToString("0000000000", CultureInfo.InvariantCulture) + " 00000 n\r\n"); } + // Trailer - provides location of catalog and xref table + writer.Write( + "trailer\r\n" + // Trailer keyword + "<<\r\n" + // Begin trailer dictionary + "/Size " + ToStr(xrefs.Count + 1) + "\r\n" + // Total number of entries in xref table + "/Root 1 0 R\r\n" + // Reference to catalog object + ">>\r\n" + // End trailer dictionary + "startxref\r\n" + // Start of xref keyword + ToStr(startxref) + "\r\n" + // Byte offset of xref table + "%%EOF" // End of file marker + ); + + writer.Flush(); + return stream.ToArray(); } diff --git a/QRCoder/PngByteQRCode.cs b/QRCoder/PngByteQRCode.cs index 3b118cd9..7f113e69 100644 --- a/QRCoder/PngByteQRCode.cs +++ b/QRCoder/PngByteQRCode.cs @@ -1,6 +1,4 @@ -#if HAS_SPAN using System.Buffers; -#endif using System.IO.Compression; using static QRCoder.QRCodeGenerator; @@ -39,14 +37,11 @@ public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) png.WriteHeader(size, size, 1, PngBuilder.ColorType.Greyscale); var scanLines = DrawScanlines(pixelsPerModule, drawQuietZones); png.WriteScanlines(scanLines); -#if HAS_SPAN ArrayPool.Shared.Return(scanLines.Array!); -#endif png.WriteEnd(); return png.GetBytes(); } -#if !NETSTANDARD1_3 /// /// Creates a 2-color PNG of the QR code, using 1-bit indexed color. Colors may contain transparency. /// @@ -57,7 +52,6 @@ public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) /// Returns the QR code graphic as a PNG byte array. public byte[] GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) => GetGraphic(pixelsPerModule, new byte[] { darkColor.R, darkColor.G, darkColor.B, darkColor.A }, new byte[] { lightColor.R, lightColor.G, lightColor.B, lightColor.A }, drawQuietZones); -#endif /// /// Creates a 2-color PNG of the QR code, using 1-bit indexed color. Accepts 3-byte RGB colors for normal images and 4-byte RGBA-colors for transparent images. @@ -75,9 +69,7 @@ public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgba, byte[] light png.WritePalette(darkColorRgba, lightColorRgba); var scanLines = DrawScanlines(pixelsPerModule, drawQuietZones); png.WriteScanlines(scanLines); -#if HAS_SPAN ArrayPool.Shared.Return(scanLines.Array!); -#endif png.WriteEnd(); return png.GetBytes(); } @@ -95,12 +87,8 @@ private ArraySegment DrawScanlines(int pixelsPerModule, bool drawQuietZone var quietZoneOffset = (drawQuietZones ? 0 : 4); var bytesPerScanline = (matrixSize * pixelsPerModule + 7) / 8 + 1; // A monochrome scanline is one byte for filter type then one bit per pixel. var scanLinesLength = bytesPerScanline * matrixSize * pixelsPerModule; -#if HAS_SPAN var scanlines = ArrayPool.Shared.Rent(scanLinesLength); Array.Clear(scanlines, 0, scanLinesLength); -#else - var scanlines = new byte[scanLinesLength]; -#endif for (var y = 0; y < matrixSize; y++) { diff --git a/QRCoder/PostscriptQRCode.cs b/QRCoder/PostscriptQRCode.cs index 99f86065..75d3a580 100644 --- a/QRCoder/PostscriptQRCode.cs +++ b/QRCoder/PostscriptQRCode.cs @@ -1,4 +1,3 @@ -#if !NETSTANDARD1_3 using System.Drawing; using System.Text; using static QRCoder.QRCodeGenerator; @@ -237,4 +236,3 @@ public static string GetQRCode(string plainText, int pointsPerModule, string dar return qrCode.GetGraphic(pointsPerModule, darkColorHex, lightColorHex, drawQuietZones, epsFormat); } } -#endif diff --git a/QRCoder/QRCode.cs b/QRCoder/QRCode.cs index e5b121f8..d9f26099 100644 --- a/QRCoder/QRCode.cs +++ b/QRCoder/QRCode.cs @@ -1,4 +1,3 @@ -#if SYSTEM_DRAWING using System.Drawing; using System.Drawing.Drawing2D; using static QRCoder.QRCodeGenerator; @@ -8,9 +7,7 @@ namespace QRCoder; /// /// Represents a QR code generator that outputs QR codes as bitmap images. /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public class QRCode : AbstractQRCode, IDisposable { /// @@ -193,9 +190,7 @@ internal static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cor /// /// Provides static methods for creating bitmap QR codes. /// -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public static class QRCodeHelper { /// @@ -223,5 +218,3 @@ public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color dark return qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, icon, iconSizePercent, iconBorderWidth, drawQuietZones); } } - -#endif diff --git a/QRCoder/QRCodeData.cs b/QRCoder/QRCodeData.cs index 37ee29a5..5f6410a0 100644 --- a/QRCoder/QRCodeData.cs +++ b/QRCoder/QRCodeData.cs @@ -148,11 +148,7 @@ public byte[] GetRawData(Compression compressMode) try { //Add header - signature ("QRR") -#if HAS_SPAN targetStream.Write([0x51, 0x52, 0x52, 0x00]); -#else - targetStream.Write(new byte[] { 0x51, 0x52, 0x52, 0x00 }, 0, 4); -#endif //Add header - rowsize targetStream.WriteByte((byte)ModuleMatrix.Count); diff --git a/QRCoder/QRCodeGenerator.cs b/QRCoder/QRCodeGenerator.cs index a0c02dc7..7ee7a62f 100644 --- a/QRCoder/QRCodeGenerator.cs +++ b/QRCoder/QRCodeGenerator.cs @@ -1,6 +1,4 @@ -#if HAS_SPAN using System.Buffers; -#endif using System; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -512,11 +510,11 @@ private static void GetFormatString(BitArray fStrEcc, int version, ECCLevel leve } // Align bits with the start of the array. - ShiftTowardsBit0(fStrEcc, index); + fStrEcc.ShiftTowardsBit0(index); // Prefix the error correction bits with the ECC level and version number. fStrEcc.Length = 10 + 5; - ShiftAwayFromBit0(fStrEcc, (10 - count) + 5); + fStrEcc.ShiftAwayFromBit0((10 - count) + 5); if (version < 0) WriteMicroEccLevelAndVersion(); else @@ -591,9 +589,7 @@ void WriteMicroEccLevelAndVersion() } } -#if !NETFRAMEWORK || NET45_OR_GREATER [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif private static void TrimLeadingZeros(BitArray fStrEcc, ref int index, ref int count) { while (count > 0 && !fStrEcc[index]) @@ -603,30 +599,6 @@ private static void TrimLeadingZeros(BitArray fStrEcc, ref int index, ref int co } } - private static void ShiftTowardsBit0(BitArray fStrEcc, int num) - { -#if HAS_SPAN - fStrEcc.RightShift(num); // Shift towards bit 0 -#else - for (var i = 0; i < fStrEcc.Length - num; i++) - fStrEcc[i] = fStrEcc[i + num]; - for (var i = fStrEcc.Length - num; i < fStrEcc.Length; i++) - fStrEcc[i] = false; -#endif - } - - private static void ShiftAwayFromBit0(BitArray fStrEcc, int num) - { -#if HAS_SPAN - fStrEcc.LeftShift(num); // Shift away from bit 0 -#else - for (var i = fStrEcc.Length - 1; i >= num; i--) - fStrEcc[i] = fStrEcc[i - num]; - for (var i = 0; i < num; i++) - fStrEcc[i] = false; -#endif - } - private static readonly BitArray _getVersionGenerator = new BitArray(new bool[] { true, true, true, true, true, false, false, true, false, false, true, false, true }); /// @@ -655,11 +627,11 @@ private static void GetVersionString(BitArray vStr, int version) TrimLeadingZeros(vStr, ref index, ref count); // Trim leading zeros after each XOR operation to maintain the proper sequence. } - ShiftTowardsBit0(vStr, index); // Align the bit array so the data starts at index 0. + vStr.ShiftTowardsBit0(index); // Align the bit array so the data starts at index 0. // Prefix the error correction encoding with 6 bits containing the version number vStr.Length = 12 + 6; - ShiftAwayFromBit0(vStr, (12 - count) + 6); + vStr.ShiftAwayFromBit0((12 - count) + 6); DecToBin(version, 6, vStr, 0); } @@ -716,13 +688,8 @@ private static ArraySegment CalculateECCWords(BitArray bitArray, int offse generatorPolynom.Dispose(); // Convert the resulting polynomial into a byte array representing the ECC codewords. -#if HAS_SPAN var array = ArrayPool.Shared.Rent(leadTermSource.Count); var ret = new ArraySegment(array, 0, leadTermSource.Count); -#else - var ret = new ArraySegment(new byte[leadTermSource.Count]); - var array = ret.Array!; -#endif for (var i = 0; i < leadTermSource.Count; i++) array[i] = (byte)leadTermSource[i].Coefficient; @@ -1018,11 +985,7 @@ private static BitArray PlainTextToBinary(string plainText, EncodingMode encMode /// The number of leading zeros to prepend to the resulting BitArray. /// A BitArray representing the bits of the input byteArray, with optional leading zeros. private static BitArray ToBitArray( -#if HAS_SPAN ReadOnlySpan byteArray, // byte[] has an implicit cast to ReadOnlySpan -#else - byte[] byteArray, -#endif int prefixZeros = 0) { // Calculate the total number of bits in the resulting BitArray including the prefix zeros. @@ -1039,11 +1002,7 @@ private static BitArray ToBitArray( /// The target BitArray to write to. /// The starting offset in the BitArray where bits will be written. private static void CopyToBitArray( -#if HAS_SPAN ReadOnlySpan byteArray, // byte[] has an implicit cast to ReadOnlySpan -#else - byte[] byteArray, -#endif BitArray bitArray, int offset) { @@ -1235,7 +1194,7 @@ static int[] GetNotUniqueExponents(Polynom list) var dic = new Dictionary(list.Count); foreach (var row in list) { -#if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER +#if !NETSTANDARD2_0 if (!dic.TryAdd(row.Exponent, false)) #else if (!dic.ContainsKey(row.Exponent)) diff --git a/QRCoder/QRCodeGenerator/AlphanumericEncoder.cs b/QRCoder/QRCodeGenerator/AlphanumericEncoder.cs index ea66319c..e5591ae2 100644 --- a/QRCoder/QRCodeGenerator/AlphanumericEncoder.cs +++ b/QRCoder/QRCodeGenerator/AlphanumericEncoder.cs @@ -7,13 +7,9 @@ public partial class QRCodeGenerator /// internal static class AlphanumericEncoder { -#if HAS_SPAN // With C# 7.3 and later, this byte array is inlined into the assembly's read-only data section, improving performance and reducing memory usage. // See: https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-core-3-0/ internal static ReadOnlySpan _map => -#else - internal static readonly byte[] _map = -#endif [ // 0..31 255, 255, 255, 255, 255, 255, 255, 255, diff --git a/QRCoder/QRCodeGenerator/ByteDataSegment.cs b/QRCoder/QRCodeGenerator/ByteDataSegment.cs index 05ad74d4..7fea2b51 100644 --- a/QRCoder/QRCodeGenerator/ByteDataSegment.cs +++ b/QRCoder/QRCodeGenerator/ByteDataSegment.cs @@ -1,6 +1,4 @@ -#if HAS_SPAN using System.Buffers; -#endif namespace QRCoder; @@ -215,7 +213,7 @@ private static int PlainTextToBinaryByte(string plainText, EciMode eciMode, bool { var targetEncoding = GetTargetEncoding(plainText, eciMode, utf8BOM, forceUtf8, out var includeUtf8BOM); -#if HAS_SPAN +#if !NETSTANDARD2_0 // We can use stackalloc for small arrays to prevent heap allocations const int MAX_STACK_SIZE_IN_BYTES = 512; @@ -242,7 +240,7 @@ private static int PlainTextToBinaryByte(string plainText, EciMode eciMode, bool CopyToBitArray(codeBytes, bitArray, offset); offset += (int)((uint)codeBytes.Length * 8); -#if HAS_SPAN +#if !NETSTANDARD2_0 if (bufferFromPool != null) ArrayPool.Shared.Return(bufferFromPool); #endif diff --git a/QRCoder/QRCodeGenerator/CodewordBlock.cs b/QRCoder/QRCodeGenerator/CodewordBlock.cs index 58e3f43c..524a94d7 100644 --- a/QRCoder/QRCodeGenerator/CodewordBlock.cs +++ b/QRCoder/QRCodeGenerator/CodewordBlock.cs @@ -1,6 +1,4 @@ -#if HAS_SPAN using System.Buffers; -#endif namespace QRCoder; @@ -47,12 +45,10 @@ public static List GetList(int capacity) public static void ReturnList(List list) { -#if HAS_SPAN foreach (var item in list) { ArrayPool.Shared.Return(item.ECCWords.Array!); } -#endif list.Clear(); Interlocked.CompareExchange(ref _codewordBlocks, list, null); } diff --git a/QRCoder/QRCodeGenerator/GaloisField.cs b/QRCoder/QRCodeGenerator/GaloisField.cs index 46c8f262..09af0a97 100644 --- a/QRCoder/QRCodeGenerator/GaloisField.cs +++ b/QRCoder/QRCodeGenerator/GaloisField.cs @@ -15,18 +15,10 @@ public partial class QRCodeGenerator /// internal static class GaloisField { -#if HAS_SPAN internal static ReadOnlySpan _galoisFieldByExponentAlpha => -#else - internal static readonly byte[] _galoisFieldByExponentAlpha = -#endif [1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1]; -#if HAS_SPAN internal static ReadOnlySpan _galoisFieldByIntegerValue => -#else - internal static readonly byte[] _galoisFieldByIntegerValue = -#endif [0, 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75, 4, 100, 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113, 5, 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69, 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 166, 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 34, 136, 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 131, 56, 70, 64, 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 84, 250, 133, 186, 61, 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 229, 172, 115, 243, 167, 87, 7, 112, 192, 247, 140, 128, 99, 13, 103, 74, 222, 237, 49, 197, 254, 24, 227, 165, 153, 119, 38, 184, 180, 124, 17, 68, 146, 217, 35, 32, 137, 46, 55, 63, 209, 91, 149, 188, 207, 205, 144, 135, 151, 178, 220, 252, 190, 97, 242, 86, 211, 171, 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162, 31, 45, 67, 216, 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246, 108, 161, 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90, 203, 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215, 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175]; /// diff --git a/QRCoder/QRCodeGenerator/NumericDataSegment.cs b/QRCoder/QRCodeGenerator/NumericDataSegment.cs index 3337af62..34a061ce 100644 --- a/QRCoder/QRCodeGenerator/NumericDataSegment.cs +++ b/QRCoder/QRCodeGenerator/NumericDataSegment.cs @@ -122,7 +122,7 @@ private static int PlainTextToBinaryNumeric(string plainText, int offset, int le for (int i = offset; i < endIndex - 2; i += 3) { // Parse the next three characters as a decimal integer. -#if HAS_SPAN +#if !NETSTANDARD2_0 var dec = int.Parse(plainText.AsSpan(i, 3), NumberStyles.None, CultureInfo.InvariantCulture); #else var dec = int.Parse(plainText.Substring(i, 3), NumberStyles.None, CultureInfo.InvariantCulture); @@ -136,7 +136,7 @@ private static int PlainTextToBinaryNumeric(string plainText, int offset, int le // Handle any remaining digits if the total number is not a multiple of three. if (length > 0) // Two remaining digits are encoded in 7 bits; one remaining digit is encoded in 4 bits. { -#if HAS_SPAN +#if !NETSTANDARD2_0 var dec = int.Parse(plainText.AsSpan(offset, length), NumberStyles.None, CultureInfo.InvariantCulture); #else var dec = int.Parse(plainText.Substring(offset, length), NumberStyles.None, CultureInfo.InvariantCulture); diff --git a/QRCoder/QRCodeGenerator/Polynom.cs b/QRCoder/QRCodeGenerator/Polynom.cs index 90237945..1f94c53c 100644 --- a/QRCoder/QRCodeGenerator/Polynom.cs +++ b/QRCoder/QRCodeGenerator/Polynom.cs @@ -63,9 +63,7 @@ public PolynomItem this[int index] } } -#if NET6_0_OR_GREATER [StackTraceHidden] -#endif private static void ThrowIndexArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException("index"); @@ -188,13 +186,10 @@ private void AssertCapacity(int min) //_polyItems = newArray; } -#if NET6_0_OR_GREATER [StackTraceHidden] -#endif void ThrowNotSupportedException() => throw new NotSupportedException("The polynomial capacity is fixed and cannot be increased."); } -#if HAS_SPAN /// /// Rents memory for the polynomial terms from the shared memory pool. /// @@ -206,54 +201,6 @@ private static PolynomItem[] RentArray(int count) /// private static void ReturnArray(PolynomItem[] array) => System.Buffers.ArrayPool.Shared.Return(array); -#else - // Implement a poor-man's array pool for .NET Framework - [ThreadStatic] - private static List? _arrayPool; - - /// - /// Rents memory for the polynomial terms from a shared memory pool. - /// - private static PolynomItem[] RentArray(int count) - { - if (count <= 0) - ThrowArgumentOutOfRangeException(); - - // Search for a suitable array in the thread-local pool, if it has been initialized - if (_arrayPool != null) - { - for (int i = 0; i < _arrayPool.Count; i++) - { - var array = _arrayPool[i]; - if (array.Length >= count) - { - _arrayPool.RemoveAt(i); - return array; - } - } - } - - // No suitable buffer found; create a new one - return new PolynomItem[count]; - - void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException(nameof(count), "The count must be a positive number."); - } - - /// - /// Returns memory allocated for the polynomial terms back to a shared memory pool. - /// - private static void ReturnArray(PolynomItem[] array) - { - if (array == null) - return; - - // Initialize the thread-local pool if it's not already done - _arrayPool ??= new List(8); - - // Add the buffer back to the pool - _arrayPool.Add(array); - } -#endif /// /// Returns an enumerator that iterates through the polynomial terms. diff --git a/QRCoder/QRCoder.csproj b/QRCoder/QRCoder.csproj index 270286d8..2f6ab10b 100644 --- a/QRCoder/QRCoder.csproj +++ b/QRCoder/QRCoder.csproj @@ -2,7 +2,7 @@ - net35;net40;netstandard1.3;netstandard2.0;netstandard2.1;net5.0;net6.0 + netstandard2.0;netstandard2.1;net6.0 true true @@ -24,22 +24,10 @@ - - - - - - - - - - - - - - - - + + + + diff --git a/QRCoder/SvgQRCode.cs b/QRCoder/SvgQRCode.cs index 0078dc9d..b4ebe7b9 100644 --- a/QRCoder/SvgQRCode.cs +++ b/QRCoder/SvgQRCode.cs @@ -1,6 +1,4 @@ -#if !NETSTANDARD1_3 using System.Drawing; -using QRCoder.Extensions; using static QRCoder.QRCodeGenerator; using static QRCoder.SvgQRCode; @@ -330,7 +328,7 @@ private static int GetTransparency(string colorHex) if (colorHex.Length == 9) { // Extract alpha channel (last 2 characters) -#if HAS_SPAN +#if !NETSTANDARD2_0 if (int.TryParse(colorHex.AsSpan(7, 2), NumberStyles.HexNumber, null, out int alpha)) #else if (int.TryParse(colorHex.Substring(7, 2), NumberStyles.HexNumber, null, out int alpha)) @@ -343,7 +341,7 @@ private static int GetTransparency(string colorHex) else if (colorHex.Length == 5) { // Extract alpha channel (last character) and multiply by 17 to convert 4-bit to 8-bit -#if HAS_SPAN +#if !NETSTANDARD2_0 if (int.TryParse(colorHex.AsSpan(4, 1), NumberStyles.HexNumber, null, out int alpha)) #else if (int.TryParse(colorHex.Substring(4, 1), NumberStyles.HexNumber, null, out int alpha)) @@ -435,16 +433,13 @@ public class SvgLogo private readonly object _logoRaw; private readonly bool _isEmbedded; -#if SYSTEM_DRAWING /// /// Create a logo object to be used in SvgQRCode renderer /// /// Logo to be rendered as Bitmap/rasterized graphic /// Degree of percentage coverage of the QR code by the logo /// If true, the background behind the logo will be cleaned -#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { _iconSizePercent = iconSizePercent; @@ -459,7 +454,6 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac _logoRaw = iconRasterized; _isEmbedded = false; } -#endif /// /// Create a logo object to be used in SvgQRCode renderer @@ -535,17 +529,11 @@ public enum MediaType : int /// /// Portable Network Graphics (PNG) image format /// -#pragma warning disable CS0618 // Type or member is obsolete - [StringValue("image/png")] -#pragma warning restore CS0618 // Type or member is obsolete PNG = 0, /// /// Scalable Vector Graphics (SVG) image format /// -#pragma warning disable CS0618 // Type or member is obsolete - [StringValue("image/svg+xml")] -#pragma warning restore CS0618 // Type or member is obsolete SVG = 1 } @@ -588,5 +576,3 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar return qrCode.GetGraphic(pixelsPerModule, darkColorHex, lightColorHex, drawQuietZones, sizingMode, logo); } } - -#endif diff --git a/QRCoderConsole/Program.cs b/QRCoderConsole/Program.cs index ed7cccf2..29c517ef 100644 --- a/QRCoderConsole/Program.cs +++ b/QRCoderConsole/Program.cs @@ -7,7 +7,7 @@ namespace QRCoderConsole; -#if NET6_0 && WINDOWS +#if NET6_0 [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif internal sealed class MainClass @@ -227,7 +227,7 @@ public static class OptionSetter public static QRCodeGenerator.ECCLevel GetECCLevel(string value) => Enum.TryParse(value, true, out QRCodeGenerator.ECCLevel level) ? level : QRCodeGenerator.ECCLevel.Default; -#if NET6_0 && WINDOWS +#if NET6_0 [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif public static ImageFormat GetImageFormat(string value) => value.ToLowerInvariant() switch diff --git a/QRCoderConsole/QRCoderConsole.csproj b/QRCoderConsole/QRCoderConsole.csproj index 71ae8d89..ad079e55 100644 --- a/QRCoderConsole/QRCoderConsole.csproj +++ b/QRCoderConsole/QRCoderConsole.csproj @@ -1,9 +1,9 @@ - net45;net5.0;net5.0-windows;net6.0-windows + net462;net6.0;net6.0-windows - true + true Exe @@ -13,21 +13,18 @@ - + - - - - + diff --git a/QRCoderDemo/QRCoderDemo.csproj b/QRCoderDemo/QRCoderDemo.csproj index 503e7923..22bf8299 100644 --- a/QRCoderDemo/QRCoderDemo.csproj +++ b/QRCoderDemo/QRCoderDemo.csproj @@ -1,8 +1,8 @@  - net462;net5.0-windows - true + net462;net6.0-windows + true Exe true en-us diff --git a/QRCoderTests/QRCoderTests.csproj b/QRCoderTests/QRCoderTests.csproj index 00537872..94dc9b29 100644 --- a/QRCoderTests/QRCoderTests.csproj +++ b/QRCoderTests/QRCoderTests.csproj @@ -1,10 +1,10 @@  - net462;netcoreapp2.1;netcoreapp3.1;net5.0-windows;net6.0-windows - true - true - $(DefineConstants);TEST_XAML + net462;netcoreapp2.1;netcoreapp3.1;net6.0-windows + true + true + $(DefineConstants);TEST_XAML true 2.1.30 $(NoWarn);CA1707;CA1416;CA1850 @@ -19,7 +19,6 @@ - buildTransitive @@ -45,7 +44,7 @@ - + From cee10c3e01f01c05c11c9bc1b0b2d2ee4d5c3eb7 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:09:39 -0400 Subject: [PATCH 02/32] Remove master branch restriction from PR workflow --- .github/workflows/wf-build-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/wf-build-test.yml b/.github/workflows/wf-build-test.yml index 5a81bf4a..e1eee625 100644 --- a/.github/workflows/wf-build-test.yml +++ b/.github/workflows/wf-build-test.yml @@ -2,8 +2,6 @@ name: Build, test (Pull Request) on: pull_request: - branches: - - master concurrency: group: pr-${{ github.event.pull_request.number }} From 733f3c10b48354f642ea7e3f1723f594c18fce3e Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:10:18 -0400 Subject: [PATCH 03/32] Add develop branch to CI workflow triggers --- .github/workflows/wf-build-release-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/wf-build-release-ci.yml b/.github/workflows/wf-build-release-ci.yml index 82d3f292..31928894 100644 --- a/.github/workflows/wf-build-release-ci.yml +++ b/.github/workflows/wf-build-release-ci.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - develop concurrency: group: ${{ github.workflow }}-${{ github.ref }} From d20feafcf4f77949b76b969bb48c509cb497465b Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:10:36 -0400 Subject: [PATCH 04/32] Update workflow to remove master branch restriction Removed branch specification for pull request trigger. --- .github/workflows/wf-verify-formatting.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/wf-verify-formatting.yml b/.github/workflows/wf-verify-formatting.yml index 3dbb788e..63461c27 100644 --- a/.github/workflows/wf-verify-formatting.yml +++ b/.github/workflows/wf-verify-formatting.yml @@ -1,9 +1,6 @@ name: Format (Pull Request) on: pull_request: - branches: - - master - workflow_dispatch: jobs: format: From 429f8e8d463b4605f9326608bb07835516728c69 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:11:01 -0400 Subject: [PATCH 05/32] Update VersionPrefix to 2.0.0-preview --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index a3d0495c..bcb6efb5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,7 +11,7 @@ - 1.6.1-preview + 2.0.0-preview 12 enable false From d5b1a92a76a9119ce5eefc89f94b2afcc07d96b3 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:49:16 -0400 Subject: [PATCH 06/32] Don't test .NET Core 2.1 --- QRCoderTests/QRCoderTests.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/QRCoderTests/QRCoderTests.csproj b/QRCoderTests/QRCoderTests.csproj index 94dc9b29..55c46197 100644 --- a/QRCoderTests/QRCoderTests.csproj +++ b/QRCoderTests/QRCoderTests.csproj @@ -1,12 +1,11 @@  - net462;netcoreapp2.1;netcoreapp3.1;net6.0-windows + net462;netcoreapp3.1;net6.0-windows true true $(DefineConstants);TEST_XAML true - 2.1.30 $(NoWarn);CA1707;CA1416;CA1850 ..\QRCoder\QRCoderStrongName.snk From 07894bb24de10bf729cca8ed16a0ca4c3fc05d9d Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:50:19 -0400 Subject: [PATCH 07/32] Remove .NET Core 2.1 and .NET 5.0 from CI workflows --- .github/workflows/wf-build-release-ci.yml | 2 -- .github/workflows/wf-build-test.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/wf-build-release-ci.yml b/.github/workflows/wf-build-release-ci.yml index 31928894..e7ec9f21 100644 --- a/.github/workflows/wf-build-release-ci.yml +++ b/.github/workflows/wf-build-release-ci.yml @@ -23,9 +23,7 @@ jobs: uses: actions/setup-dotnet@v5 with: dotnet-version: | - 2.1.x 3.1.x - 5.0.x 6.0.x 8.0.x diff --git a/.github/workflows/wf-build-test.yml b/.github/workflows/wf-build-test.yml index e1eee625..f079ec6f 100644 --- a/.github/workflows/wf-build-test.yml +++ b/.github/workflows/wf-build-test.yml @@ -16,9 +16,7 @@ jobs: matrix: dotnet-framework: - { name: ".NET Framework 4.6.2", framework: "net462", coverage: false, no-build: true, sdk: "" } - - { name: ".NET Core 2.1", framework: "netcoreapp2.1", coverage: true, no-build: false, sdk: "2.1.x" } - { name: ".NET Core 3.1", framework: "netcoreapp3.1", coverage: true, no-build: true, sdk: "3.1.x" } - - { name: ".NET 5.0 Windows", framework: "net5.0-windows", coverage: true, no-build: true, sdk: "5.0.x" } - { name: ".NET 6.0 Windows", framework: "net6.0-windows", coverage: true, no-build: true, sdk: "6.0.x" } steps: From 232723bf0a1e187850e207423ad324ab62c42cf9 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 12:59:17 -0400 Subject: [PATCH 08/32] Add QRCoder library classes and methods for QR code generation and payload handling - Implemented abstract class AbstractQRCode and derived classes: ArtQRCode, AsciiQRCode, Base64QRCode, BitmapByteQRCode, PdfByteQRCode, PngByteQRCode, PostscriptQRCode, SvgQRCode, and QRCode. - Added helper classes for each QR code type to facilitate QR code generation. - Introduced PayloadGenerator with various payload types including BezahlCode, BitcoinAddress, CalendarEvent, ContactData, Geolocation, Girocode, and more. - Defined enums for various configurations and options within the QR code generation process. - Included exception handling classes for managing errors related to data size and specific payload types. - Established a comprehensive structure for QR code data management with QRCodeData and QRCodeGenerator classes. --- QRCoderApiTests/net60/QRCoder.approved.txt | 18 - .../netstandard13/QRCoder.approved.txt | 888 ------------------ .../QRCoder.approved.txt | 17 - .../RussiaPaymentOrderTests.cs | 6 + README.md | 2 - 5 files changed, 6 insertions(+), 925 deletions(-) delete mode 100644 QRCoderApiTests/netstandard13/QRCoder.approved.txt rename QRCoderApiTests/{net35+net40+net50+netstandard20+netstandard21 => netstandard20+netstandard21}/QRCoder.approved.txt (98%) diff --git a/QRCoderApiTests/net60/QRCoder.approved.txt b/QRCoderApiTests/net60/QRCoder.approved.txt index c0599c3a..89fbe918 100644 --- a/QRCoderApiTests/net60/QRCoder.approved.txt +++ b/QRCoderApiTests/net60/QRCoder.approved.txt @@ -985,9 +985,7 @@ namespace QRCoder public bool IsEmbedded() { } public enum MediaType { - [QRCoder.Extensions.StringValue("image/png")] PNG = 0, - [QRCoder.Extensions.StringValue("image/svg+xml")] SVG = 1, } } @@ -1005,19 +1003,3 @@ namespace QRCoder.Exceptions public DataTooLongException(string eccLevel, string encodingMode, int version, int maxSizeByte) { } } } -namespace QRCoder.Extensions -{ - [System.Obsolete("This class will be removed in a future version of QRCoder.")] - public static class CustomExtensions - { - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This method uses reflection to examine the provided enum value.")] - public static string? GetStringValue(this System.Enum value) { } - } - [System.AttributeUsage(System.AttributeTargets.Field)] - [System.Obsolete("This attribute will be removed in a future version of QRCoder.")] - public class StringValueAttribute : System.Attribute - { - public StringValueAttribute(string value) { } - public string StringValue { get; set; } - } -} diff --git a/QRCoderApiTests/netstandard13/QRCoder.approved.txt b/QRCoderApiTests/netstandard13/QRCoder.approved.txt deleted file mode 100644 index f127e9ef..00000000 --- a/QRCoderApiTests/netstandard13/QRCoder.approved.txt +++ /dev/null @@ -1,888 +0,0 @@ -namespace QRCoder -{ - public abstract class AbstractQRCode - { - protected AbstractQRCode() { } - protected AbstractQRCode(QRCoder.QRCodeData data) { } - protected QRCoder.QRCodeData QrCodeData { get; set; } - public void Dispose() { } - public virtual void SetQRCodeData(QRCoder.QRCodeData data) { } - } - public class AsciiQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public AsciiQRCode() { } - public AsciiQRCode(QRCoder.QRCodeData data) { } - public string GetGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true, string endOfLine = " -") { } - public string GetGraphicSmall(bool drawQuietZones = true, bool invert = false, string endOfLine = " -") { } - public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true) { } - } - public static class AsciiQRCodeHelper - { - public static string GetQRCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, string endOfLine = " -", bool drawQuietZones = true, bool invert = true) { } - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorString, string whiteSpaceString, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, string endOfLine = " -", bool drawQuietZones = true) { } - } - public class BitmapByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public BitmapByteQRCode() { } - public BitmapByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule) { } - public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightColorRgb) { } - public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex) { } - } - public static class BitmapByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - } - public static class PayloadGenerator - { - public static bool ChecksumMod10(string digits) { } - public class BezahlCode : QRCoder.PayloadGenerator.Payload - { - public BezahlCode(QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, string name, string account = "", string bnc = "", string iban = "", string bic = "", string reason = "") { } - public BezahlCode(QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, string name, string account, string bnc, decimal amount, string periodicTimeunit = "", int periodicTimeunitRotation = 0, System.DateTime? periodicFirstExecutionDate = default, System.DateTime? periodicLastExecutionDate = default, string reason = "", int postingKey = 0, QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, System.DateTime? executionDate = default) { } - public BezahlCode( - QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, - string name, - string iban, - string bic, - decimal amount, - string periodicTimeunit = "", - int periodicTimeunitRotation = 0, - System.DateTime? periodicFirstExecutionDate = default, - System.DateTime? periodicLastExecutionDate = default, - string creditorId = "", - string mandateId = "", - System.DateTime? dateOfSignature = default, - string reason = "", - string sepaReference = "", - QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, - System.DateTime? executionDate = default) { } - public BezahlCode( - QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, - string name, - string account, - string bnc, - string iban, - string bic, - decimal amount, - string periodicTimeunit = "", - int periodicTimeunitRotation = 0, - System.DateTime? periodicFirstExecutionDate = default, - System.DateTime? periodicLastExecutionDate = default, - string creditorId = "", - string mandateId = "", - System.DateTime? dateOfSignature = default, - string reason = "", - int postingKey = 0, - string sepaReference = "", - QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, - System.DateTime? executionDate = default, - int internalMode = 0) { } - public override string ToString() { } - public enum AuthorityType - { - [System.Obsolete("Use singlepaymentsepa instead for SEPA-compliant payments")] - singlepayment = 0, - singlepaymentsepa = 1, - [System.Obsolete("Use singledirectdebitsepa instead for SEPA-compliant payments")] - singledirectdebit = 2, - singledirectdebitsepa = 3, - [System.Obsolete("Use periodicsinglepaymentsepa instead for SEPA-compliant payments")] - periodicsinglepayment = 4, - periodicsinglepaymentsepa = 5, - contact = 6, - contact_v2 = 7, - } - public class BezahlCodeException : System.Exception - { - public BezahlCodeException() { } - public BezahlCodeException(string message) { } - public BezahlCodeException(string message, System.Exception inner) { } - } - public enum Currency - { - AED = 784, - AFN = 971, - ALL = 8, - AMD = 51, - ANG = 532, - AOA = 973, - ARS = 32, - AUD = 36, - AWG = 533, - AZN = 944, - BAM = 977, - BBD = 52, - BDT = 50, - BGN = 975, - BHD = 48, - BIF = 108, - BMD = 60, - BND = 96, - BOB = 68, - BOV = 984, - BRL = 986, - BSD = 44, - BTN = 64, - BWP = 72, - BYR = 974, - BZD = 84, - CAD = 124, - CDF = 976, - CHE = 947, - CHF = 756, - CHW = 948, - CLF = 990, - CLP = 152, - CNY = 156, - COP = 170, - COU = 970, - CRC = 188, - CUC = 931, - CUP = 192, - CVE = 132, - CZK = 203, - DJF = 262, - DKK = 208, - DOP = 214, - DZD = 12, - EGP = 818, - ERN = 232, - ETB = 230, - EUR = 978, - FJD = 242, - FKP = 238, - GBP = 826, - GEL = 981, - GHS = 936, - GIP = 292, - GMD = 270, - GNF = 324, - GTQ = 320, - GYD = 328, - HKD = 344, - HNL = 340, - HRK = 191, - HTG = 332, - HUF = 348, - IDR = 360, - ILS = 376, - INR = 356, - IQD = 368, - IRR = 364, - ISK = 352, - JMD = 388, - JOD = 400, - JPY = 392, - KES = 404, - KGS = 417, - KHR = 116, - KMF = 174, - KPW = 408, - KRW = 410, - KWD = 414, - KYD = 136, - KZT = 398, - LAK = 418, - LBP = 422, - LKR = 144, - LRD = 430, - LSL = 426, - LYD = 434, - MAD = 504, - MDL = 498, - MGA = 969, - MKD = 807, - MMK = 104, - MNT = 496, - MOP = 446, - MRO = 478, - MUR = 480, - MVR = 462, - MWK = 454, - MXN = 484, - MXV = 979, - MYR = 458, - MZN = 943, - NAD = 516, - NGN = 566, - NIO = 558, - NOK = 578, - NPR = 524, - NZD = 554, - OMR = 512, - PAB = 590, - PEN = 604, - PGK = 598, - PHP = 608, - PKR = 586, - PLN = 985, - PYG = 600, - QAR = 634, - RON = 946, - RSD = 941, - RUB = 643, - RWF = 646, - SAR = 682, - SBD = 90, - SCR = 690, - SDG = 938, - SEK = 752, - SGD = 702, - SHP = 654, - SLL = 694, - SOS = 706, - SRD = 968, - SSP = 728, - STD = 678, - SVC = 222, - SYP = 760, - SZL = 748, - THB = 764, - TJS = 972, - TMT = 934, - TND = 788, - TOP = 776, - TRY = 949, - TTD = 780, - TWD = 901, - TZS = 834, - UAH = 980, - UGX = 800, - USD = 840, - USN = 997, - UYI = 940, - UYU = 858, - UZS = 860, - VEF = 937, - VND = 704, - VUV = 548, - WST = 882, - XAF = 950, - XAG = 961, - XAU = 959, - XBA = 955, - XBB = 956, - XBC = 957, - XBD = 958, - XCD = 951, - XDR = 960, - XOF = 952, - XPD = 964, - XPF = 953, - XPT = 962, - XSU = 994, - XTS = 963, - XUA = 965, - XXX = 999, - YER = 886, - ZAR = 710, - ZMW = 967, - ZWL = 932, - } - } - public class BitcoinAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public BitcoinAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class BitcoinCashAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public BitcoinCashAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class BitcoinLikeCryptoCurrencyAddress : QRCoder.PayloadGenerator.Payload - { - public BitcoinLikeCryptoCurrencyAddress(QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress.BitcoinLikeCryptoCurrencyType currencyType, string address, double? amount, string? label = null, string? message = null) { } - public override string ToString() { } - public enum BitcoinLikeCryptoCurrencyType - { - Bitcoin = 0, - BitcoinCash = 1, - Litecoin = 2, - } - } - public class Bookmark : QRCoder.PayloadGenerator.Payload - { - public Bookmark(string url, string title) { } - public override string ToString() { } - } - public class CalendarEvent : QRCoder.PayloadGenerator.Payload - { - public CalendarEvent(string subject, string? description, string? location, System.DateTime start, System.DateTime end, bool allDayEvent, QRCoder.PayloadGenerator.CalendarEvent.EventEncoding encoding = 1) { } - public CalendarEvent(string subject, string? description, string? location, System.DateTimeOffset start, System.DateTimeOffset end, bool allDayEvent, QRCoder.PayloadGenerator.CalendarEvent.EventEncoding encoding = 1) { } - public override string ToString() { } - public enum EventEncoding - { - iCalComplete = 0, - Universal = 1, - } - } - public class ContactData : QRCoder.PayloadGenerator.Payload - { - public ContactData( - QRCoder.PayloadGenerator.ContactData.ContactOutputType outputType, - string firstname, - string lastname, - string? nickname = null, - string? phone = null, - string? mobilePhone = null, - string? workPhone = null, - string? email = null, - System.DateTime? birthday = default, - string? website = null, - string? street = null, - string? houseNumber = null, - string? city = null, - string? zipCode = null, - string? country = null, - string? note = null, - string? stateRegion = null, - QRCoder.PayloadGenerator.ContactData.AddressOrder addressOrder = 0, - string? org = null, - string? orgTitle = null) { } - public ContactData( - QRCoder.PayloadGenerator.ContactData.ContactOutputType outputType, - string firstname, - string lastname, - string? nickname, - string? phone, - string? mobilePhone, - string? workPhone, - string? email, - System.DateTime? birthday, - string? website, - string? street, - string? houseNumber, - string? city, - string? zipCode, - string? country, - string? note, - string? stateRegion, - QRCoder.PayloadGenerator.ContactData.AddressOrder addressOrder, - string? org, - string? orgTitle, - QRCoder.PayloadGenerator.ContactData.AddressType addressType) { } - public override string ToString() { } - public enum AddressOrder - { - Default = 0, - Reversed = 1, - } - public enum AddressType - { - Home = 0, - Work = 1, - HomePreferred = 2, - WorkPreferred = 3, - } - public enum ContactOutputType - { - MeCard = 0, - VCard21 = 1, - VCard3 = 2, - VCard4 = 3, - } - } - public class Geolocation : QRCoder.PayloadGenerator.Payload - { - public Geolocation(string latitude, string longitude, QRCoder.PayloadGenerator.Geolocation.GeolocationEncoding encoding = 0) { } - public override string ToString() { } - public enum GeolocationEncoding - { - GEO = 0, - GoogleMaps = 1, - } - } - public class Girocode : QRCoder.PayloadGenerator.Payload - { - public Girocode(string iban, string? bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override string ToString() { } - public enum GirocodeEncoding - { - UTF_8 = 0, - ISO_8859_1 = 1, - ISO_8859_2 = 2, - ISO_8859_4 = 3, - ISO_8859_5 = 4, - ISO_8859_7 = 5, - ISO_8859_10 = 6, - ISO_8859_15 = 7, - } - public class GirocodeException : System.Exception - { - public GirocodeException() { } - public GirocodeException(string message) { } - public GirocodeException(string message, System.Exception inner) { } - } - public enum GirocodeVersion - { - Version1 = 0, - Version2 = 1, - } - public enum TypeOfRemittance - { - Structured = 0, - Unstructured = 1, - } - } - public class LitecoinAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public LitecoinAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class MMS : QRCoder.PayloadGenerator.Payload - { - public MMS(string number, QRCoder.PayloadGenerator.MMS.MMSEncoding encoding = 0) { } - public MMS(string number, string subject, QRCoder.PayloadGenerator.MMS.MMSEncoding encoding = 0) { } - public override string ToString() { } - public enum MMSEncoding - { - MMS = 0, - MMSTO = 1, - } - } - public class Mail : QRCoder.PayloadGenerator.Payload - { - public Mail(string? mailReceiver = null, string? subject = null, string? message = null, QRCoder.PayloadGenerator.Mail.MailEncoding encoding = 0) { } - public override string ToString() { } - public enum MailEncoding - { - MAILTO = 0, - MATMSG = 1, - SMTP = 2, - } - } - public class MoneroTransaction : QRCoder.PayloadGenerator.Payload - { - public MoneroTransaction(string address, float? txAmount = default, string? txPaymentId = null, string? recipientName = null, string? txDescription = null) { } - public override string ToString() { } - public class MoneroTransactionException : System.Exception - { - public MoneroTransactionException() { } - public MoneroTransactionException(string message) { } - public MoneroTransactionException(string message, System.Exception inner) { } - } - } - public class OneTimePassword : QRCoder.PayloadGenerator.Payload - { - public OneTimePassword() { } - [System.Obsolete("This property is obsolete, use AuthAlgorithm instead", false)] - public QRCoder.PayloadGenerator.OneTimePassword.OoneTimePasswordAuthAlgorithm Algorithm { get; set; } - public QRCoder.PayloadGenerator.OneTimePassword.OneTimePasswordAuthAlgorithm AuthAlgorithm { get; set; } - public int? Counter { get; set; } - public int Digits { get; set; } - public string? Issuer { get; set; } - public string? Label { get; set; } - public int? Period { get; set; } - public string Secret { get; set; } - public QRCoder.PayloadGenerator.OneTimePassword.OneTimePasswordAuthType Type { get; set; } - public override string ToString() { } - public enum OneTimePasswordAuthAlgorithm - { - SHA1 = 0, - SHA256 = 1, - SHA512 = 2, - } - public enum OneTimePasswordAuthType - { - TOTP = 0, - HOTP = 1, - } - [System.Obsolete("This enum is obsolete, use OneTimePasswordAuthAlgorithm instead", false)] - public enum OoneTimePasswordAuthAlgorithm - { - SHA1 = 0, - SHA256 = 1, - SHA512 = 2, - } - } - public abstract class Payload - { - protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public virtual int Version { get; } - public abstract override string ToString() { } - } - public class PhoneNumber : QRCoder.PayloadGenerator.Payload - { - public PhoneNumber(string number) { } - public override string ToString() { } - } - public class RussiaPaymentOrder : QRCoder.PayloadGenerator.Payload - { - public RussiaPaymentOrder(string name, string personalAcc, string bankName, string BIC, string correspAcc, QRCoder.PayloadGenerator.RussiaPaymentOrder.OptionalFields? optionalFields = null, QRCoder.PayloadGenerator.RussiaPaymentOrder.CharacterSets characterSet = 2) { } - public byte[] ToBytes() { } - public override string ToString() { } - public enum CharacterSets - { - windows_1251 = 1, - utf_8 = 2, - koi8_r = 3, - } - public class OptionalFields - { - public OptionalFields() { } - public string? AddAmount { get; set; } - public System.DateTime? BirthDate { get; set; } - public string? CBC { get; set; } - public string? Category { get; set; } - public string? ChildFio { get; set; } - public string? ClassNum { get; set; } - public string? Contract { get; set; } - public string? CounterId { get; set; } - public string? CounterVal { get; set; } - public System.DateTime? DocDate { get; set; } - public string? DocIdx { get; set; } - public string? DocNo { get; set; } - public string? DrawerStatus { get; set; } - public string? ExecId { get; set; } - public string? FirstName { get; set; } - public string? Flat { get; set; } - public string? InstNum { get; set; } - public string? KPP { get; set; } - public string? LastName { get; set; } - public string? MiddleName { get; set; } - public string? OKTMO { get; set; } - public string? PayeeINN { get; set; } - public string? PayerAddress { get; set; } - public string? PayerINN { get; set; } - public string? PayerIdNum { get; set; } - public string? PayerIdType { get; set; } - public string? PaymPeriod { get; set; } - public string? PaymTerm { get; set; } - public string? PaytReason { get; set; } - public string? PensAcc { get; set; } - public string? PersAcc { get; set; } - public string? PersonalAccount { get; set; } - public string? Phone { get; set; } - public string? Purpose { get; set; } - public System.DateTime? QuittDate { get; set; } - public string? QuittId { get; set; } - public string? RegType { get; set; } - public string? RuleId { get; set; } - public string? ServiceName { get; set; } - public string? SpecFio { get; set; } - public string? Sum { get; set; } - public string? TaxPaytKind { get; set; } - public string? TaxPeriod { get; set; } - public QRCoder.PayloadGenerator.RussiaPaymentOrder.TechCode? TechCode { get; set; } - public string? UIN { get; set; } - } - public class RussiaPaymentOrderException : System.Exception - { - public RussiaPaymentOrderException(string message) { } - } - public enum TechCode - { - Мобильная_связь_стационарный_телефон = 1, - Коммунальные_услуги_ЖКХAFN = 2, - ГИБДД_налоги_пошлины_бюджетные_платежи = 3, - Охранные_услуги = 4, - Услуги_оказываемые_УФМС = 5, - ПФР = 6, - Погашение_кредитов = 7, - Образовательные_учреждения = 8, - Интернет_и_ТВ = 9, - Электронные_деньги = 10, - Отдых_и_путешествия = 11, - Инвестиции_и_страхование = 12, - Спорт_и_здоровье = 13, - Благотворительные_и_общественные_организации = 14, - Прочие_услуги = 15, - } - } - public class SMS : QRCoder.PayloadGenerator.Payload - { - public SMS(string number, QRCoder.PayloadGenerator.SMS.SMSEncoding encoding = 0) { } - public SMS(string number, string subject, QRCoder.PayloadGenerator.SMS.SMSEncoding encoding = 0) { } - public override string ToString() { } - public enum SMSEncoding - { - SMS = 0, - SMSTO = 1, - SMS_iOS = 2, - } - } - public class ShadowSocksConfig : QRCoder.PayloadGenerator.Payload - { - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, string? tag = null) { } - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, System.Collections.Generic.Dictionary? parameters, string? tag = null) { } - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, string plugin, string? pluginOption, string? tag = null) { } - public override string ToString() { } - public enum Method - { - Chacha20IetfPoly1305 = 0, - Aes128Gcm = 1, - Aes192Gcm = 2, - Aes256Gcm = 3, - XChacha20IetfPoly1305 = 4, - Aes128Cfb = 5, - Aes192Cfb = 6, - Aes256Cfb = 7, - Aes128Ctr = 8, - Aes192Ctr = 9, - Aes256Ctr = 10, - Camellia128Cfb = 11, - Camellia192Cfb = 12, - Camellia256Cfb = 13, - Chacha20Ietf = 14, - Aes256Cb = 15, - Aes128Ofb = 16, - Aes192Ofb = 17, - Aes256Ofb = 18, - Aes128Cfb1 = 19, - Aes192Cfb1 = 20, - Aes256Cfb1 = 21, - Aes128Cfb8 = 22, - Aes192Cfb8 = 23, - Aes256Cfb8 = 24, - Chacha20 = 25, - BfCfb = 26, - Rc4Md5 = 27, - Salsa20 = 28, - DesCfb = 29, - IdeaCfb = 30, - Rc2Cfb = 31, - Cast5Cfb = 32, - Salsa20Ctr = 33, - Rc4 = 34, - SeedCfb = 35, - Table = 36, - } - public class ShadowSocksConfigException : System.Exception - { - public ShadowSocksConfigException() { } - public ShadowSocksConfigException(string message) { } - public ShadowSocksConfigException(string message, System.Exception inner) { } - } - } - public class SkypeCall : QRCoder.PayloadGenerator.Payload - { - public SkypeCall(string skypeUsername) { } - public override string ToString() { } - } - public class SlovenianUpnQr : QRCoder.PayloadGenerator.Payload - { - public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } - public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public override int Version { get; } - public override string ToString() { } - } - public class SwissQrCode : QRCoder.PayloadGenerator.Payload - { - public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation? additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact? debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact? ultimateCreditor = null, string? alternativeProcedure1 = null, string? alternativeProcedure2 = null) { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public override string ToString() { } - public class AdditionalInformation - { - public AdditionalInformation(string? unstructuredMessage = null, string? billInformation = null) { } - public string? BillInformation { get; } - public string Trailer { get; } - public string? UnstructureMessage { get; } - public class SwissQrCodeAdditionalInformationException : System.Exception - { - public SwissQrCodeAdditionalInformationException() { } - public SwissQrCodeAdditionalInformationException(string message) { } - public SwissQrCodeAdditionalInformationException(string message, System.Exception inner) { } - } - } - public class Contact - { - [System.Obsolete("This constructor is deprecated. Use WithCombinedAddress instead.")] - public Contact(string name, string country, string addressLine1, string addressLine2) { } - [System.Obsolete("This constructor is deprecated. Use WithStructuredAddress instead.")] - public Contact(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null) { } - public override string ToString() { } - public static QRCoder.PayloadGenerator.SwissQrCode.Contact WithCombinedAddress(string name, string country, string addressLine1, string addressLine2) { } - public static QRCoder.PayloadGenerator.SwissQrCode.Contact WithStructuredAddress(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null) { } - public enum AddressType - { - StructuredAddress = 0, - CombinedAddress = 1, - } - public class SwissQrCodeContactException : System.Exception - { - public SwissQrCodeContactException() { } - public SwissQrCodeContactException(string message) { } - public SwissQrCodeContactException(string message, System.Exception inner) { } - } - } - public enum Currency - { - CHF = 756, - EUR = 978, - } - public class Iban - { - public Iban(string iban, QRCoder.PayloadGenerator.SwissQrCode.Iban.IbanType ibanType) { } - public bool IsQrIban { get; } - public override string ToString() { } - public enum IbanType - { - Iban = 0, - QrIban = 1, - } - public class SwissQrCodeIbanException : System.Exception - { - public SwissQrCodeIbanException() { } - public SwissQrCodeIbanException(string message) { } - public SwissQrCodeIbanException(string message, System.Exception inner) { } - } - } - public class Reference - { - public Reference(QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceType referenceType, string? reference = null, QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceTextType? referenceTextType = default) { } - public QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceType RefType { get; } - public string? ReferenceText { get; } - public enum ReferenceTextType - { - QrReference = 0, - CreditorReferenceIso11649 = 1, - } - public enum ReferenceType - { - QRR = 0, - SCOR = 1, - NON = 2, - } - public class SwissQrCodeReferenceException : System.Exception - { - public SwissQrCodeReferenceException() { } - public SwissQrCodeReferenceException(string message) { } - public SwissQrCodeReferenceException(string message, System.Exception inner) { } - } - } - public class SwissQrCodeException : System.Exception - { - public SwissQrCodeException() { } - public SwissQrCodeException(string message) { } - public SwissQrCodeException(string message, System.Exception inner) { } - } - } - public class Url : QRCoder.PayloadGenerator.Payload - { - public Url(string url) { } - public override string ToString() { } - } - public class WhatsAppMessage : QRCoder.PayloadGenerator.Payload - { - public WhatsAppMessage(string message) { } - public WhatsAppMessage(string number, string message) { } - public override string ToString() { } - } - public class WiFi : QRCoder.PayloadGenerator.Payload - { - public WiFi(string ssid, string password, QRCoder.PayloadGenerator.WiFi.Authentication authenticationMode, bool isHiddenSSID = false, bool escapeHexStrings = true) { } - public override string ToString() { } - public enum Authentication - { - WEP = 0, - WPA = 1, - nopass = 2, - WPA2 = 3, - } - } - } - public class PdfByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public PdfByteQRCode() { } - public PdfByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule) { } - public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, int dpi = 150, long jpgQuality = 85) { } - } - public static class PdfByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - } - public sealed class PngByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public PngByteQRCode() { } - public PngByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) { } - public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, bool drawQuietZones = true) { } - } - public static class PngByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size, bool drawQuietZones = true) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true) { } - } - public class QRCodeData : System.IDisposable - { - public QRCodeData(int version) { } - public QRCodeData(byte[] rawData, QRCoder.QRCodeData.Compression compressMode) { } - public QRCodeData(int version, bool addPadding) { } - public QRCodeData(string pathToRawData, QRCoder.QRCodeData.Compression compressMode) { } - public System.Collections.Generic.List ModuleMatrix { get; set; } - public int Version { get; } - public virtual void Dispose() { } - public byte[] GetRawData(QRCoder.QRCodeData.Compression compressMode) { } - public void SaveRawData(string filePath, QRCoder.QRCodeData.Compression compressMode) { } - public enum Compression - { - Uncompressed = 0, - Deflate = 1, - GZip = 2, - } - } - public class QRCodeGenerator : System.IDisposable - { - public QRCodeGenerator() { } - public QRCoder.QRCodeData CreateQrCode(QRCoder.PayloadGenerator.Payload payload) { } - public QRCoder.QRCodeData CreateQrCode(QRCoder.PayloadGenerator.Payload payload, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public QRCoder.QRCodeData CreateQrCode(byte[] binaryData, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public QRCoder.QRCodeData CreateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - public virtual void Dispose() { } - public static QRCoder.QRCodeData GenerateMicroQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel = -1, int requestedVersion = 0) { } - public static QRCoder.QRCodeData GenerateQrCode(QRCoder.PayloadGenerator.Payload payload) { } - public static QRCoder.QRCodeData GenerateQrCode(QRCoder.PayloadGenerator.Payload payload, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public static QRCoder.QRCodeData GenerateQrCode(byte[] binaryData, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - public enum ECCLevel - { - Default = -1, - L = 0, - M = 1, - Q = 2, - H = 3, - } - public enum EciMode - { - Default = 0, - Iso8859_1 = 3, - Iso8859_2 = 4, - Utf8 = 26, - } - } -} -namespace QRCoder.Exceptions -{ - public class DataTooLongException : System.Exception - { - public DataTooLongException(string eccLevel, string encodingMode, int maxSizeByte) { } - public DataTooLongException(string eccLevel, string encodingMode, int version, int maxSizeByte) { } - } -} -namespace QRCoder.Extensions -{ - [System.Obsolete("This class will be removed in a future version of QRCoder.")] - public static class CustomExtensions - { - public static string? GetStringValue(this System.Enum value) { } - } - [System.AttributeUsage(System.AttributeTargets.Field)] - [System.Obsolete("This attribute will be removed in a future version of QRCoder.")] - public class StringValueAttribute : System.Attribute - { - public StringValueAttribute(string value) { } - public string StringValue { get; set; } - } -} diff --git a/QRCoderApiTests/net35+net40+net50+netstandard20+netstandard21/QRCoder.approved.txt b/QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt similarity index 98% rename from QRCoderApiTests/net35+net40+net50+netstandard20+netstandard21/QRCoder.approved.txt rename to QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt index fa119ea8..ebe18a41 100644 --- a/QRCoderApiTests/net35+net40+net50+netstandard20+netstandard21/QRCoder.approved.txt +++ b/QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt @@ -977,9 +977,7 @@ namespace QRCoder public bool IsEmbedded() { } public enum MediaType { - [QRCoder.Extensions.StringValue("image/png")] PNG = 0, - [QRCoder.Extensions.StringValue("image/svg+xml")] SVG = 1, } } @@ -997,18 +995,3 @@ namespace QRCoder.Exceptions public DataTooLongException(string eccLevel, string encodingMode, int version, int maxSizeByte) { } } } -namespace QRCoder.Extensions -{ - [System.Obsolete("This class will be removed in a future version of QRCoder.")] - public static class CustomExtensions - { - public static string? GetStringValue(this System.Enum value) { } - } - [System.AttributeUsage(System.AttributeTargets.Field)] - [System.Obsolete("This attribute will be removed in a future version of QRCoder.")] - public class StringValueAttribute : System.Attribute - { - public StringValueAttribute(string value) { } - public string StringValue { get; set; } - } -} diff --git a/QRCoderTests/PayloadGeneratorTests/RussiaPaymentOrderTests.cs b/QRCoderTests/PayloadGeneratorTests/RussiaPaymentOrderTests.cs index 5856a91d..68901699 100644 --- a/QRCoderTests/PayloadGeneratorTests/RussiaPaymentOrderTests.cs +++ b/QRCoderTests/PayloadGeneratorTests/RussiaPaymentOrderTests.cs @@ -20,6 +20,9 @@ public void russiapayment_generator_can_generate_payload_mandatory_fields() [Fact] public void russiapayment_generator_can_generate_payload_encoding_win1251() { +#if !NETFRAMEWORK + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); +#endif var account = "40702810138250123017"; var bic = "044525225"; var bankName = "ОАО \"БАНК\""; @@ -32,6 +35,9 @@ public void russiapayment_generator_can_generate_payload_encoding_win1251() [Fact] public void russiapayment_generator_can_generate_payload_encoding_koi8() { +#if !NETFRAMEWORK + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); +#endif var account = "40702810138250123017"; var bic = "044525225"; var bankName = "ОАО \"БАНК\""; diff --git a/README.md b/README.md index 7dec93b5..8311b128 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,6 @@ using System.Text; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); ``` -Note that the `RussiaPaymentOrder` payload generator already includes this registration internally, so no additional setup is required when using that class. - ## 🚀 CI Builds The NuGet feed contains only **major/stable** releases. If you want the latest functions and features, you can use the CI builds [via Github packages](https://github.com/Shane32/qrcoder/packages). From 8eced06cd5e95b7ee2b05d768475a124d2f4f94f Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 13:03:41 -0400 Subject: [PATCH 09/32] Update --- QRCoderTests/ArtQRCodeRendererTests.cs | 3 --- QRCoderTests/Base64QRCodeRendererTests.cs | 2 -- .../PayloadGeneratorTests/BitcoinCashAddressTests.cs | 9 --------- .../PayloadGeneratorTests/LitecoinAddressTests.cs | 9 --------- QRCoderTests/QRCodeRendererTests.cs | 3 --- QRCoderTests/QRGeneratorTests.cs | 2 -- QRCoderTests/SvgQRCodeRendererTests.cs | 2 -- QRCoderTests/TransposeVerificationTests.cs | 4 ---- 8 files changed, 34 deletions(-) diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index 96c1c845..5339b1a8 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -1,5 +1,3 @@ -#if SYSTEM_DRAWING - namespace QRCoderTests; public class ArtQRCodeRendererTests @@ -73,4 +71,3 @@ public void can_render_artqrcode_from_helper() bmp.ShouldMatchApproved(); } } -#endif diff --git a/QRCoderTests/Base64QRCodeRendererTests.cs b/QRCoderTests/Base64QRCodeRendererTests.cs index e65552d0..36ef5e2e 100644 --- a/QRCoderTests/Base64QRCodeRendererTests.cs +++ b/QRCoderTests/Base64QRCodeRendererTests.cs @@ -42,7 +42,6 @@ public void can_render_base64_qrcode_transparent() base64QRCode.ShouldBe(Convert.ToBase64String(pngCodeGfx)); } -#if SYSTEM_DRAWING [Fact] public void can_render_base64_qrcode_jpeg() { @@ -50,5 +49,4 @@ public void can_render_base64_qrcode_jpeg() var data = Convert.FromBase64String(base64QRCode); data.ShouldMatchApprovedImage(asMonochrome: true); // remove JPEG compression artifacts by converting to monochrome } -#endif } diff --git a/QRCoderTests/PayloadGeneratorTests/BitcoinCashAddressTests.cs b/QRCoderTests/PayloadGeneratorTests/BitcoinCashAddressTests.cs index 46b3b2dc..71f77e15 100644 --- a/QRCoderTests/PayloadGeneratorTests/BitcoinCashAddressTests.cs +++ b/QRCoderTests/PayloadGeneratorTests/BitcoinCashAddressTests.cs @@ -63,13 +63,8 @@ public void bitcoincash_address_generator_should_round_to_satoshi() [Fact] public void bitcoincash_address_generator_disregards_current_culture() { -#if NETCOREAPP1_1 - var currentCulture = CultureInfo.DefaultThreadCurrentCulture; - CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE"); -#else var currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); -#endif var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; var amount = .123; @@ -81,10 +76,6 @@ public void bitcoincash_address_generator_disregards_current_culture() .ToString() .ShouldBe("bitcoincash:qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890?amount=.123"); -#if NETCOREAPP1_1 - CultureInfo.DefaultThreadCurrentCulture = currentCulture; -#else Thread.CurrentThread.CurrentCulture = currentCulture; -#endif } } diff --git a/QRCoderTests/PayloadGeneratorTests/LitecoinAddressTests.cs b/QRCoderTests/PayloadGeneratorTests/LitecoinAddressTests.cs index c31ad491..046e9988 100644 --- a/QRCoderTests/PayloadGeneratorTests/LitecoinAddressTests.cs +++ b/QRCoderTests/PayloadGeneratorTests/LitecoinAddressTests.cs @@ -63,13 +63,8 @@ public void litecoin_address_generator_should_round_to_satoshi() [Fact] public void litecoin_address_generator_disregards_current_culture() { -#if NETCOREAPP1_1 - var currentCulture = CultureInfo.DefaultThreadCurrentCulture; - CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE"); -#else var currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); -#endif var address = "LY1t7iLnwtPCb1DPZP38FA835XzFqXBq54"; var amount = .123; @@ -81,10 +76,6 @@ public void litecoin_address_generator_disregards_current_culture() .ToString() .ShouldBe("litecoin:LY1t7iLnwtPCb1DPZP38FA835XzFqXBq54?amount=.123"); -#if NETCOREAPP1_1 - CultureInfo.DefaultThreadCurrentCulture = currentCulture; -#else Thread.CurrentThread.CurrentCulture = currentCulture; -#endif } } diff --git a/QRCoderTests/QRCodeRendererTests.cs b/QRCoderTests/QRCodeRendererTests.cs index 98db5fb2..617e15dc 100644 --- a/QRCoderTests/QRCodeRendererTests.cs +++ b/QRCoderTests/QRCodeRendererTests.cs @@ -1,5 +1,3 @@ -#if SYSTEM_DRAWING - namespace QRCoderTests; public class QRCodeRendererTests @@ -111,4 +109,3 @@ public void can_render_qrcode_from_helper() bmp.ShouldMatchApproved(); } } -#endif diff --git a/QRCoderTests/QRGeneratorTests.cs b/QRCoderTests/QRGeneratorTests.cs index 3d771395..2c2970da 100644 --- a/QRCoderTests/QRGeneratorTests.cs +++ b/QRCoderTests/QRGeneratorTests.cs @@ -28,7 +28,6 @@ public void validate_antilogtable() checkString2.ShouldBe("0,0,:1,0,:2,1,:3,25,:4,2,:5,50,:6,26,:7,198,:8,3,:9,223,:10,51,:11,238,:12,27,:13,104,:14,199,:15,75,:16,4,:17,100,:18,224,:19,14,:20,52,:21,141,:22,239,:23,129,:24,28,:25,193,:26,105,:27,248,:28,200,:29,8,:30,76,:31,113,:32,5,:33,138,:34,101,:35,47,:36,225,:37,36,:38,15,:39,33,:40,53,:41,147,:42,142,:43,218,:44,240,:45,18,:46,130,:47,69,:48,29,:49,181,:50,194,:51,125,:52,106,:53,39,:54,249,:55,185,:56,201,:57,154,:58,9,:59,120,:60,77,:61,228,:62,114,:63,166,:64,6,:65,191,:66,139,:67,98,:68,102,:69,221,:70,48,:71,253,:72,226,:73,152,:74,37,:75,179,:76,16,:77,145,:78,34,:79,136,:80,54,:81,208,:82,148,:83,206,:84,143,:85,150,:86,219,:87,189,:88,241,:89,210,:90,19,:91,92,:92,131,:93,56,:94,70,:95,64,:96,30,:97,66,:98,182,:99,163,:100,195,:101,72,:102,126,:103,110,:104,107,:105,58,:106,40,:107,84,:108,250,:109,133,:110,186,:111,61,:112,202,:113,94,:114,155,:115,159,:116,10,:117,21,:118,121,:119,43,:120,78,:121,212,:122,229,:123,172,:124,115,:125,243,:126,167,:127,87,:128,7,:129,112,:130,192,:131,247,:132,140,:133,128,:134,99,:135,13,:136,103,:137,74,:138,222,:139,237,:140,49,:141,197,:142,254,:143,24,:144,227,:145,165,:146,153,:147,119,:148,38,:149,184,:150,180,:151,124,:152,17,:153,68,:154,146,:155,217,:156,35,:157,32,:158,137,:159,46,:160,55,:161,63,:162,209,:163,91,:164,149,:165,188,:166,207,:167,205,:168,144,:169,135,:170,151,:171,178,:172,220,:173,252,:174,190,:175,97,:176,242,:177,86,:178,211,:179,171,:180,20,:181,42,:182,93,:183,158,:184,132,:185,60,:186,57,:187,83,:188,71,:189,109,:190,65,:191,162,:192,31,:193,45,:194,67,:195,216,:196,183,:197,123,:198,164,:199,118,:200,196,:201,23,:202,73,:203,236,:204,127,:205,12,:206,111,:207,246,:208,108,:209,161,:210,59,:211,82,:212,41,:213,157,:214,85,:215,170,:216,251,:217,96,:218,134,:219,177,:220,187,:221,204,:222,62,:223,90,:224,203,:225,89,:226,95,:227,176,:228,156,:229,169,:230,160,:231,81,:232,11,:233,245,:234,22,:235,235,:236,122,:237,117,:238,44,:239,215,:240,79,:241,174,:242,213,:243,233,:244,230,:245,231,:246,173,:247,232,:248,116,:249,214,:250,244,:251,234,:252,168,:253,80,:254,88,:255,175,:"); } -#if !NETFRAMEWORK // [Theory] is not supported in xunit < 2.0.0 [Theory] [InlineData("54321", ECCLevel.Default, "ZfnO93tpy9jjaACKXue2VsACXxY", 11)] //verified [InlineData("00000000", ECCLevel.M, "lEBc3nKaK0UpMfenT5FTX02Zgfg", 13)] //verified @@ -368,7 +367,6 @@ public void can_encode_various_strings_various_ecc(int inputChars, ECCLevel eccL var hashString = Convert.ToBase64String(hash); hashString.ShouldBe(expectedHash); } -#endif [Fact] public void validate_alphanumencdict() diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index 0aab3d83..cb8567ea 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -72,7 +72,6 @@ public void can_render_svg_qrcode_without_quietzones_hex() svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); } -#if SYSTEM_DRAWING [Fact] public void can_render_svg_qrcode_with_png_logo_bitmap() { @@ -156,7 +155,6 @@ public void can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones() svg = svg.Replace(base64Data, "=====BASE64DATA====="); svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); } -#endif [Fact] public void can_render_svg_qrcode_with_png_logo_bytearray() diff --git a/QRCoderTests/TransposeVerificationTests.cs b/QRCoderTests/TransposeVerificationTests.cs index fd8e0d4f..6a053d17 100644 --- a/QRCoderTests/TransposeVerificationTests.cs +++ b/QRCoderTests/TransposeVerificationTests.cs @@ -19,7 +19,6 @@ public TransposeVerificationTests() _sharedQrCodeData = gen.CreateQrCode("ABCD", QRCodeGenerator.ECCLevel.L); } -#if SYSTEM_DRAWING [Theory] [InlineData("QRCode")] [InlineData("BitmapByteQRCode")] @@ -89,7 +88,6 @@ public void artqrcode_renderer() using var bitmap = qrCode.GetGraphic(10, Color.Black, Color.White, Color.White, null, 1, true, ArtQRCode.QuietZoneStyle.Flat, ArtQRCode.BackgroundImageStyle.Fill, null); bitmap.ShouldMatchApproved(); } -#endif [Theory] [InlineData("FullSize")] @@ -146,7 +144,6 @@ public void black_module_position() } } -#if SYSTEM_DRAWING [Fact] public void black_module_reference() { @@ -167,5 +164,4 @@ public void black_module_reference() using var bitmap = qrCode.GetGraphic(10); bitmap.ShouldMatchApproved(); } -#endif } From 3f8a9f7e96df8cc4f818ae8c185f8c5caec897c2 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 13:07:53 -0400 Subject: [PATCH 10/32] Fix usings --- QRCoder/QRCodeGenerator.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/QRCoder/QRCodeGenerator.cs b/QRCoder/QRCodeGenerator.cs index 7ee7a62f..7585af3e 100644 --- a/QRCoder/QRCodeGenerator.cs +++ b/QRCoder/QRCodeGenerator.cs @@ -1,8 +1,6 @@ using System.Buffers; -using System; using System.Diagnostics; using System.Runtime.CompilerServices; -using System.Text; namespace QRCoder; From 38ef897baff7fdc70f1ddca42b1922512cc1175a Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 18:46:10 -0400 Subject: [PATCH 11/32] update --- Directory.Build.targets | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 8457e280..157e82b6 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,11 +1,5 @@ - - - $(DefineConstants);SYSTEM_DRAWING - $(DefineConstants);HAS_SPAN - - true From d6b1ca5c427dcd94c764f4d80c12a517e579fcd5 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 18:47:22 -0400 Subject: [PATCH 12/32] update --- Directory.Build.targets | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 157e82b6..c5927367 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -16,9 +16,4 @@ true - - - - - From 3b3ceb2ec69f6e3b17a8286fbd40e2e9b36c2584 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 20:13:07 -0400 Subject: [PATCH 13/32] Split project to QRCoder.SystemDrawing --- .../ArtQRCode.cs | 0 {QRCoder => QRCoder.SystemDrawing}/QRCode.cs | 0 .../QRCoder.SystemDrawing.csproj | 26 + .../SupportedOSPlatformAttribute.cs | 0 QRCoder.sln | 18 + QRCoder/Base64QRCode.cs | 132 ++- QRCoder/Extensions/ColorTranslator.cs | 213 ++++ QRCoder/QRCoder.csproj | 2 - QRCoder/SvgQRCode.cs | 22 - QRCoderApiTests/ApiApprovalTests.cs | 1 + .../QRCoder.approved.txt | 69 +- QRCoderApiTests/QRCoderApiTests.csproj | 2 +- .../net60/QRCoder.SystemDrawing.approved.txt | 58 + QRCoderApiTests/net60/QRCoder.approved.txt | 1005 ----------------- .../QRCoder.SystemDrawing.approved.txt | 54 + QRCoderBenchmarks/QRCoderBenchmarks.csproj | 2 +- QRCoderConsole/QRCoderConsole.csproj | 2 +- QRCoderDemo/QRCoderDemo.csproj | 7 +- ...can_render_base64_qrcode_jpeg.approved.gif | Bin 1395 -> 0 bytes QRCoderTests/Base64QRCodeRendererTests.cs | 13 +- QRCoderTests/QRCoderTests.csproj | 2 +- ...g_qrcode_with_png_logo_bitmap.approved.svg | 5 - ..._png_logo_bitmap.embeddedLogo.approved.gif | Bin 1410 -> 0 bytes ...ogo_bitmap_without_background.approved.svg | 5 - ...thout_background.embeddedLogo.approved.gif | Bin 1410 -> 0 bytes ...ogo_bitmap_without_quietzones.approved.svg | 5 - ...thout_quietzones.embeddedLogo.approved.gif | Bin 1410 -> 0 bytes QRCoderTests/SvgQRCodeRendererTests.cs | 84 -- 28 files changed, 461 insertions(+), 1266 deletions(-) rename {QRCoder => QRCoder.SystemDrawing}/ArtQRCode.cs (100%) rename {QRCoder => QRCoder.SystemDrawing}/QRCode.cs (100%) create mode 100644 QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj rename {QRCoder/Attributes => QRCoder.SystemDrawing}/SupportedOSPlatformAttribute.cs (100%) create mode 100644 QRCoder/Extensions/ColorTranslator.cs rename QRCoderApiTests/{netstandard20+netstandard21 => }/QRCoder.approved.txt (92%) create mode 100644 QRCoderApiTests/net60/QRCoder.SystemDrawing.approved.txt delete mode 100644 QRCoderApiTests/net60/QRCoder.approved.txt create mode 100644 QRCoderApiTests/netstandard20+netstandard21/QRCoder.SystemDrawing.approved.txt delete mode 100644 QRCoderTests/Base64QRCodeRendererTests.can_render_base64_qrcode_jpeg.approved.gif delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.approved.svg delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.embeddedLogo.approved.gif delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.approved.svg delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.embeddedLogo.approved.gif delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.approved.svg delete mode 100644 QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.embeddedLogo.approved.gif diff --git a/QRCoder/ArtQRCode.cs b/QRCoder.SystemDrawing/ArtQRCode.cs similarity index 100% rename from QRCoder/ArtQRCode.cs rename to QRCoder.SystemDrawing/ArtQRCode.cs diff --git a/QRCoder/QRCode.cs b/QRCoder.SystemDrawing/QRCode.cs similarity index 100% rename from QRCoder/QRCode.cs rename to QRCoder.SystemDrawing/QRCode.cs diff --git a/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj b/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj new file mode 100644 index 00000000..4bb5d916 --- /dev/null +++ b/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj @@ -0,0 +1,26 @@ + + + + + netstandard2.0;netstandard2.1;net6.0 + true + true + + + c# csharp qr qrcoder qrcode qr-generator qr-code-generator + QRCoder is a simple library, written in C#.NET, which enables you to create QR codes. + + + QRCoderStrongName.snk + + + + + + + + + + + + diff --git a/QRCoder/Attributes/SupportedOSPlatformAttribute.cs b/QRCoder.SystemDrawing/SupportedOSPlatformAttribute.cs similarity index 100% rename from QRCoder/Attributes/SupportedOSPlatformAttribute.cs rename to QRCoder.SystemDrawing/SupportedOSPlatformAttribute.cs diff --git a/QRCoder.sln b/QRCoder.sln index b27c2e14..0ee669f1 100644 --- a/QRCoder.sln +++ b/QRCoder.sln @@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderSamples", "QRCoderSamples\QRCoderSamples.csproj", "{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoder.SystemDrawing", "QRCoder.SystemDrawing\QRCoder.SystemDrawing.csproj", "{FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -201,6 +203,22 @@ Global {61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x64.Build.0 = Release|Any CPU {61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x86.ActiveCfg = Release|Any CPU {61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x86.Build.0 = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|ARM.ActiveCfg = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|ARM.Build.0 = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|x64.ActiveCfg = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|x64.Build.0 = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|x86.ActiveCfg = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Debug|x86.Build.0 = Debug|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|Any CPU.Build.0 = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|ARM.ActiveCfg = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|ARM.Build.0 = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|x64.ActiveCfg = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|x64.Build.0 = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|x86.ActiveCfg = Release|Any CPU + {FEE6DC1D-BE5A-4498-A70D-35C516AD13F3}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 3f713fd3..b7e39019 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -1,5 +1,4 @@ using System.Drawing; -using System.Drawing.Imaging; using System.Runtime.InteropServices; using static QRCoder.Base64QRCode; using static QRCoder.QRCodeGenerator; @@ -35,6 +34,17 @@ public Base64QRCode(QRCodeData data) : base(data) public string GetGraphic(int pixelsPerModule) => GetGraphic(pixelsPerModule, Color.Black, Color.White, true); + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules in HTML hex format. + /// The color of the light modules in HTML hex format. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) + => GetGraphic(pixelsPerModule, ColorTranslator.FromHtml(darkColorHtmlHex), ColorTranslator.FromHtml(lightColorHtmlHex), drawQuietZones); + /// /// Returns a base64-encoded string that contains the resulting QR code as an image. /// @@ -44,119 +54,80 @@ public string GetGraphic(int pixelsPerModule) /// Indicates if quiet zones around the QR code should be drawn. /// The type of image to generate (PNG, JPEG, GIF). /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true, ImageType imgType = ImageType.Png) + [Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload without the imgType parameter.")] + public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones, ImageType imgType) => GetGraphic(pixelsPerModule, ColorTranslator.FromHtml(darkColorHtmlHex), ColorTranslator.FromHtml(lightColorHtmlHex), drawQuietZones, imgType); /// - /// Returns a base64-encoded string that contains the resulting QR code as an image. + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. /// /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. /// The color of the dark modules. /// The color of the light modules. /// Indicates if quiet zones around the QR code should be drawn. - /// The type of image to generate (PNG, JPEG, GIF). /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true, ImageType imgType = ImageType.Png) + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) { - if (imgType == ImageType.Png) - { - var pngCoder = new PngByteQRCode(QrCodeData); + var pngCoder = new PngByteQRCode(QrCodeData); - byte[] pngData; - if (darkColor == Color.Black && lightColor == Color.White) + byte[] pngData; + if (darkColor == Color.Black && lightColor == Color.White) + { + pngData = pngCoder.GetGraphic(pixelsPerModule, drawQuietZones); + } + else + { + byte[] darkColorBytes; + byte[] lightColorBytes; + if (darkColor.A != 255 || lightColor.A != 255) { - pngData = pngCoder.GetGraphic(pixelsPerModule, drawQuietZones); + darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B, darkColor.A }; + lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B, lightColor.A }; } else { - byte[] darkColorBytes; - byte[] lightColorBytes; - if (darkColor.A != 255 || lightColor.A != 255) - { - darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B, darkColor.A }; - lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B, lightColor.A }; - } - else - { - darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B }; - lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B }; - } - pngData = pngCoder.GetGraphic(pixelsPerModule, darkColorBytes, lightColorBytes, drawQuietZones); + darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B }; + lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B }; } - - return Convert.ToBase64String(pngData, Base64FormattingOptions.None); + pngData = pngCoder.GetGraphic(pixelsPerModule, darkColorBytes, lightColorBytes, drawQuietZones); } -#pragma warning disable CA1416 // Validate platform compatibility - var qr = new QRCode(QrCodeData); - var base64 = string.Empty; - using (var bmp = qr.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones)) - { - base64 = BitmapToBase64(bmp, imgType); - } - return base64; -#pragma warning restore CA1416 // Validate platform compatibility + return Convert.ToBase64String(pngData, Base64FormattingOptions.None); } /// - /// Returns a base64-encoded string that contains the resulting QR code as an image with an embedded icon. + /// Returns a base64-encoded string that contains the resulting QR code as an image. /// /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. /// The color of the dark modules. /// The color of the light modules. - /// The icon to embed in the center of the QR code. - /// The size of the icon as a percentage of the QR code. - /// The width of the border around the icon. /// Indicates if quiet zones around the QR code should be drawn. /// The type of image to generate (PNG, JPEG, GIF). /// Returns the QR code graphic as a base64-encoded string. - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Bitmap icon, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true, ImageType imgType = ImageType.Png) + [Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload without the imgType parameter.")] + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones, ImageType imgType) { - var qr = new QRCode(QrCodeData); - var base64 = string.Empty; - using (var bmp = qr.GetGraphic(pixelsPerModule, darkColor, lightColor, icon, iconSizePercent, iconBorderWidth, drawQuietZones)) + if (imgType != ImageType.Png) { - base64 = BitmapToBase64(bmp, imgType); + throw new NotSupportedException($"Only PNG format is supported. {imgType} format is no longer supported."); } - return base64; - } - /// - /// Converts a bitmap to a base64-encoded string. - /// - /// The bitmap to convert. - /// The type of image (PNG, JPEG, GIF). - /// Returns the base64-encoded string representation of the bitmap. - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - private static string BitmapToBase64(Bitmap bmp, ImageType imgType) - { - var iFormat = imgType switch - { - ImageType.Png => ImageFormat.Png, - ImageType.Jpeg => ImageFormat.Jpeg, - ImageType.Gif => ImageFormat.Gif, - _ => ImageFormat.Png, - }; - using var memoryStream = new MemoryStream(); - bmp.Save(memoryStream, iFormat); - return Convert.ToBase64String(memoryStream.ToArray(), Base64FormattingOptions.None); + return GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); } /// /// Specifies the type of image to generate. /// + [Obsolete("ImageType enum is obsolete. Only PNG format is supported.")] public enum ImageType { /// /// Graphics Interchange Format (GIF) image format, a bitmap image format with limited color support /// - [System.Runtime.Versioning.SupportedOSPlatform("windows")] Gif, /// /// Joint Photographic Experts Group (JPEG) image format, a lossy compressed image format /// - [System.Runtime.Versioning.SupportedOSPlatform("windows")] Jpeg, /// /// Portable Network Graphics (PNG) image format, a lossless raster graphics format @@ -171,6 +142,28 @@ public enum ImageType /// public static class Base64QRCodeHelper { + /// + /// Creates a base64-encoded QR code with a single function call. + /// + /// The text or payload to be encoded inside the QR code. + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules in HTML hex format. + /// The color of the light modules in HTML hex format. + /// The level of error correction data. + /// Specifies whether the generator should be forced to work in UTF-8 mode. + /// Specifies whether the byte-order-mark should be used. + /// Specifies which ECI mode should be used. + /// Sets the fixed QR code target version. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true) + { + using var qrGenerator = new QRCodeGenerator(); + using var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion); + using var qrCode = new Base64QRCode(qrCodeData); + return qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex, drawQuietZones); + } + /// /// Creates a base64-encoded QR code with a single function call. /// @@ -186,7 +179,8 @@ public static class Base64QRCodeHelper /// Indicates if quiet zones around the QR code should be drawn. /// The type of image to generate (PNG, JPEG, GIF). /// Returns the QR code graphic as a base64-encoded string. - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, ImageType imgType = ImageType.Png) + [Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload without the imgType parameter.")] + public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8, bool utf8BOM, EciMode eciMode, int requestedVersion, bool drawQuietZones, ImageType imgType) { using var qrGenerator = new QRCodeGenerator(); using var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion); diff --git a/QRCoder/Extensions/ColorTranslator.cs b/QRCoder/Extensions/ColorTranslator.cs new file mode 100644 index 00000000..ac7d624a --- /dev/null +++ b/QRCoder/Extensions/ColorTranslator.cs @@ -0,0 +1,213 @@ +#if !NETCOREAPP3_1_OR_GREATER + +using System; +using System.Collections.Generic; +using System.Text; + +namespace QRCoder; + +internal static class ColorTranslator +{ + /// + /// Dictionary of known HTML color names mapped to their RGB values. + /// + private static readonly Dictionary _knownColors = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "AliceBlue", System.Drawing.Color.FromArgb(255, 240, 248, 255) }, + { "AntiqueWhite", System.Drawing.Color.FromArgb(255, 250, 235, 215) }, + { "Aqua", System.Drawing.Color.FromArgb(255, 0, 255, 255) }, + { "Aquamarine", System.Drawing.Color.FromArgb(255, 127, 255, 212) }, + { "Azure", System.Drawing.Color.FromArgb(255, 240, 255, 255) }, + { "Beige", System.Drawing.Color.FromArgb(255, 245, 245, 220) }, + { "Bisque", System.Drawing.Color.FromArgb(255, 255, 228, 196) }, + { "Black", System.Drawing.Color.FromArgb(255, 0, 0, 0) }, + { "BlanchedAlmond", System.Drawing.Color.FromArgb(255, 255, 235, 205) }, + { "Blue", System.Drawing.Color.FromArgb(255, 0, 0, 255) }, + { "BlueViolet", System.Drawing.Color.FromArgb(255, 138, 43, 226) }, + { "Brown", System.Drawing.Color.FromArgb(255, 165, 42, 42) }, + { "BurlyWood", System.Drawing.Color.FromArgb(255, 222, 184, 135) }, + { "CadetBlue", System.Drawing.Color.FromArgb(255, 95, 158, 160) }, + { "Chartreuse", System.Drawing.Color.FromArgb(255, 127, 255, 0) }, + { "Chocolate", System.Drawing.Color.FromArgb(255, 210, 105, 30) }, + { "Coral", System.Drawing.Color.FromArgb(255, 255, 127, 80) }, + { "CornflowerBlue", System.Drawing.Color.FromArgb(255, 100, 149, 237) }, + { "Cornsilk", System.Drawing.Color.FromArgb(255, 255, 248, 220) }, + { "Crimson", System.Drawing.Color.FromArgb(255, 220, 20, 60) }, + { "Cyan", System.Drawing.Color.FromArgb(255, 0, 255, 255) }, + { "DarkBlue", System.Drawing.Color.FromArgb(255, 0, 0, 139) }, + { "DarkCyan", System.Drawing.Color.FromArgb(255, 0, 139, 139) }, + { "DarkGoldenrod", System.Drawing.Color.FromArgb(255, 184, 134, 11) }, + { "DarkGray", System.Drawing.Color.FromArgb(255, 169, 169, 169) }, + { "DarkGreen", System.Drawing.Color.FromArgb(255, 0, 100, 0) }, + { "DarkKhaki", System.Drawing.Color.FromArgb(255, 189, 183, 107) }, + { "DarkMagenta", System.Drawing.Color.FromArgb(255, 139, 0, 139) }, + { "DarkOliveGreen", System.Drawing.Color.FromArgb(255, 85, 107, 47) }, + { "DarkOrange", System.Drawing.Color.FromArgb(255, 255, 140, 0) }, + { "DarkOrchid", System.Drawing.Color.FromArgb(255, 153, 50, 204) }, + { "DarkRed", System.Drawing.Color.FromArgb(255, 139, 0, 0) }, + { "DarkSalmon", System.Drawing.Color.FromArgb(255, 233, 150, 122) }, + { "DarkSeaGreen", System.Drawing.Color.FromArgb(255, 143, 188, 143) }, + { "DarkSlateBlue", System.Drawing.Color.FromArgb(255, 72, 61, 139) }, + { "DarkSlateGray", System.Drawing.Color.FromArgb(255, 47, 79, 79) }, + { "DarkTurquoise", System.Drawing.Color.FromArgb(255, 0, 206, 209) }, + { "DarkViolet", System.Drawing.Color.FromArgb(255, 148, 0, 211) }, + { "DeepPink", System.Drawing.Color.FromArgb(255, 255, 20, 147) }, + { "DeepSkyBlue", System.Drawing.Color.FromArgb(255, 0, 191, 255) }, + { "DimGray", System.Drawing.Color.FromArgb(255, 105, 105, 105) }, + { "DodgerBlue", System.Drawing.Color.FromArgb(255, 30, 144, 255) }, + { "Firebrick", System.Drawing.Color.FromArgb(255, 178, 34, 34) }, + { "FloralWhite", System.Drawing.Color.FromArgb(255, 255, 250, 240) }, + { "ForestGreen", System.Drawing.Color.FromArgb(255, 34, 139, 34) }, + { "Fuchsia", System.Drawing.Color.FromArgb(255, 255, 0, 255) }, + { "Gainsboro", System.Drawing.Color.FromArgb(255, 220, 220, 220) }, + { "GhostWhite", System.Drawing.Color.FromArgb(255, 248, 248, 255) }, + { "Gold", System.Drawing.Color.FromArgb(255, 255, 215, 0) }, + { "Goldenrod", System.Drawing.Color.FromArgb(255, 218, 165, 32) }, + { "Gray", System.Drawing.Color.FromArgb(255, 128, 128, 128) }, + { "Green", System.Drawing.Color.FromArgb(255, 0, 128, 0) }, + { "GreenYellow", System.Drawing.Color.FromArgb(255, 173, 255, 47) }, + { "Honeydew", System.Drawing.Color.FromArgb(255, 240, 255, 240) }, + { "HotPink", System.Drawing.Color.FromArgb(255, 255, 105, 180) }, + { "IndianRed", System.Drawing.Color.FromArgb(255, 205, 92, 92) }, + { "Indigo", System.Drawing.Color.FromArgb(255, 75, 0, 130) }, + { "Ivory", System.Drawing.Color.FromArgb(255, 255, 255, 240) }, + { "Khaki", System.Drawing.Color.FromArgb(255, 240, 230, 140) }, + { "Lavender", System.Drawing.Color.FromArgb(255, 230, 230, 250) }, + { "LavenderBlush", System.Drawing.Color.FromArgb(255, 255, 240, 245) }, + { "LawnGreen", System.Drawing.Color.FromArgb(255, 124, 252, 0) }, + { "LemonChiffon", System.Drawing.Color.FromArgb(255, 255, 250, 205) }, + { "LightBlue", System.Drawing.Color.FromArgb(255, 173, 216, 230) }, + { "LightCoral", System.Drawing.Color.FromArgb(255, 240, 128, 128) }, + { "LightCyan", System.Drawing.Color.FromArgb(255, 224, 255, 255) }, + { "LightGoldenrodYellow", System.Drawing.Color.FromArgb(255, 250, 250, 210) }, + { "LightGray", System.Drawing.Color.FromArgb(255, 211, 211, 211) }, + { "LightGreen", System.Drawing.Color.FromArgb(255, 144, 238, 144) }, + { "LightPink", System.Drawing.Color.FromArgb(255, 255, 182, 193) }, + { "LightSalmon", System.Drawing.Color.FromArgb(255, 255, 160, 122) }, + { "LightSeaGreen", System.Drawing.Color.FromArgb(255, 32, 178, 170) }, + { "LightSkyBlue", System.Drawing.Color.FromArgb(255, 135, 206, 250) }, + { "LightSlateGray", System.Drawing.Color.FromArgb(255, 119, 136, 153) }, + { "LightSteelBlue", System.Drawing.Color.FromArgb(255, 176, 196, 222) }, + { "LightYellow", System.Drawing.Color.FromArgb(255, 255, 255, 224) }, + { "Lime", System.Drawing.Color.FromArgb(255, 0, 255, 0) }, + { "LimeGreen", System.Drawing.Color.FromArgb(255, 50, 205, 50) }, + { "Linen", System.Drawing.Color.FromArgb(255, 250, 240, 230) }, + { "Magenta", System.Drawing.Color.FromArgb(255, 255, 0, 255) }, + { "Maroon", System.Drawing.Color.FromArgb(255, 128, 0, 0) }, + { "MediumAquamarine", System.Drawing.Color.FromArgb(255, 102, 205, 170) }, + { "MediumBlue", System.Drawing.Color.FromArgb(255, 0, 0, 205) }, + { "MediumOrchid", System.Drawing.Color.FromArgb(255, 186, 85, 211) }, + { "MediumPurple", System.Drawing.Color.FromArgb(255, 147, 112, 219) }, + { "MediumSeaGreen", System.Drawing.Color.FromArgb(255, 60, 179, 113) }, + { "MediumSlateBlue", System.Drawing.Color.FromArgb(255, 123, 104, 238) }, + { "MediumSpringGreen", System.Drawing.Color.FromArgb(255, 0, 250, 154) }, + { "MediumTurquoise", System.Drawing.Color.FromArgb(255, 72, 209, 204) }, + { "MediumVioletRed", System.Drawing.Color.FromArgb(255, 199, 21, 133) }, + { "MidnightBlue", System.Drawing.Color.FromArgb(255, 25, 25, 112) }, + { "MintCream", System.Drawing.Color.FromArgb(255, 245, 255, 250) }, + { "MistyRose", System.Drawing.Color.FromArgb(255, 255, 228, 225) }, + { "Moccasin", System.Drawing.Color.FromArgb(255, 255, 228, 181) }, + { "NavajoWhite", System.Drawing.Color.FromArgb(255, 255, 222, 173) }, + { "Navy", System.Drawing.Color.FromArgb(255, 0, 0, 128) }, + { "OldLace", System.Drawing.Color.FromArgb(255, 253, 245, 230) }, + { "Olive", System.Drawing.Color.FromArgb(255, 128, 128, 0) }, + { "OliveDrab", System.Drawing.Color.FromArgb(255, 107, 142, 35) }, + { "Orange", System.Drawing.Color.FromArgb(255, 255, 165, 0) }, + { "OrangeRed", System.Drawing.Color.FromArgb(255, 255, 69, 0) }, + { "Orchid", System.Drawing.Color.FromArgb(255, 218, 112, 214) }, + { "PaleGoldenrod", System.Drawing.Color.FromArgb(255, 238, 232, 170) }, + { "PaleGreen", System.Drawing.Color.FromArgb(255, 152, 251, 152) }, + { "PaleTurquoise", System.Drawing.Color.FromArgb(255, 175, 238, 238) }, + { "PaleVioletRed", System.Drawing.Color.FromArgb(255, 219, 112, 147) }, + { "PapayaWhip", System.Drawing.Color.FromArgb(255, 255, 239, 213) }, + { "PeachPuff", System.Drawing.Color.FromArgb(255, 255, 218, 185) }, + { "Peru", System.Drawing.Color.FromArgb(255, 205, 133, 63) }, + { "Pink", System.Drawing.Color.FromArgb(255, 255, 192, 203) }, + { "Plum", System.Drawing.Color.FromArgb(255, 221, 160, 221) }, + { "PowderBlue", System.Drawing.Color.FromArgb(255, 176, 224, 230) }, + { "Purple", System.Drawing.Color.FromArgb(255, 128, 0, 128) }, + { "Red", System.Drawing.Color.FromArgb(255, 255, 0, 0) }, + { "RosyBrown", System.Drawing.Color.FromArgb(255, 188, 143, 143) }, + { "RoyalBlue", System.Drawing.Color.FromArgb(255, 65, 105, 225) }, + { "SaddleBrown", System.Drawing.Color.FromArgb(255, 139, 69, 19) }, + { "Salmon", System.Drawing.Color.FromArgb(255, 250, 128, 114) }, + { "SandyBrown", System.Drawing.Color.FromArgb(255, 244, 164, 96) }, + { "SeaGreen", System.Drawing.Color.FromArgb(255, 46, 139, 87) }, + { "SeaShell", System.Drawing.Color.FromArgb(255, 255, 245, 238) }, + { "Sienna", System.Drawing.Color.FromArgb(255, 160, 82, 45) }, + { "Silver", System.Drawing.Color.FromArgb(255, 192, 192, 192) }, + { "SkyBlue", System.Drawing.Color.FromArgb(255, 135, 206, 235) }, + { "SlateBlue", System.Drawing.Color.FromArgb(255, 106, 90, 205) }, + { "SlateGray", System.Drawing.Color.FromArgb(255, 112, 128, 144) }, + { "Snow", System.Drawing.Color.FromArgb(255, 255, 250, 250) }, + { "SpringGreen", System.Drawing.Color.FromArgb(255, 0, 255, 127) }, + { "SteelBlue", System.Drawing.Color.FromArgb(255, 70, 130, 180) }, + { "Tan", System.Drawing.Color.FromArgb(255, 210, 180, 140) }, + { "Teal", System.Drawing.Color.FromArgb(255, 0, 128, 128) }, + { "Thistle", System.Drawing.Color.FromArgb(255, 216, 191, 216) }, + { "Tomato", System.Drawing.Color.FromArgb(255, 255, 99, 71) }, + { "Transparent", System.Drawing.Color.FromArgb(0, 255, 255, 255) }, + { "Turquoise", System.Drawing.Color.FromArgb(255, 64, 224, 208) }, + { "Violet", System.Drawing.Color.FromArgb(255, 238, 130, 238) }, + { "Wheat", System.Drawing.Color.FromArgb(255, 245, 222, 179) }, + { "White", System.Drawing.Color.FromArgb(255, 255, 255, 255) }, + { "WhiteSmoke", System.Drawing.Color.FromArgb(255, 245, 245, 245) }, + { "Yellow", System.Drawing.Color.FromArgb(255, 255, 255, 0) }, + { "YellowGreen", System.Drawing.Color.FromArgb(255, 154, 205, 50) } + }; + + /// + /// Translates an HTML color representation to a System.Drawing.Color structure. + /// Supports hex format (#RRGGBB or #AARRGGBB) and named colors (case-insensitive). + /// + /// The string representation of the HTML color to translate. + /// The System.Drawing.Color structure that represents the translated HTML color. + /// Thrown when htmlColor is not a valid HTML color string. + public static System.Drawing.Color FromHtml(string htmlColor) + { + if (string.IsNullOrWhiteSpace(htmlColor)) + throw new ArgumentException("HTML color string cannot be null or empty.", nameof(htmlColor)); + + htmlColor = htmlColor.Trim(); + + // Check if it's a named color first + if (_knownColors.TryGetValue(htmlColor, out var namedColor)) + return namedColor; + + // Remove leading '#' if present + if (htmlColor.StartsWith('#')) + htmlColor = htmlColor.Substring(1); + + // Validate hex string + if (htmlColor.Length != 6 && htmlColor.Length != 8) + throw new ArgumentException($"Invalid HTML color format: #{htmlColor}. Expected format: #RRGGBB, #AARRGGBB, or a named color.", nameof(htmlColor)); + + // Parse hex values + try + { + if (htmlColor.Length == 6) + { + // #RRGGBB format + int r = Convert.ToInt32(htmlColor.Substring(0, 2), 16); + int g = Convert.ToInt32(htmlColor.Substring(2, 2), 16); + int b = Convert.ToInt32(htmlColor.Substring(4, 2), 16); + return System.Drawing.Color.FromArgb(255, r, g, b); + } + else + { + // #AARRGGBB format + int a = Convert.ToInt32(htmlColor.Substring(0, 2), 16); + int r = Convert.ToInt32(htmlColor.Substring(2, 2), 16); + int g = Convert.ToInt32(htmlColor.Substring(4, 2), 16); + int b = Convert.ToInt32(htmlColor.Substring(6, 2), 16); + return System.Drawing.Color.FromArgb(a, r, g, b); + } + } + catch (FormatException) + { + throw new ArgumentException($"Invalid HTML color format: #{htmlColor}. Contains non-hexadecimal characters.", nameof(htmlColor)); + } + } +} + +#endif diff --git a/QRCoder/QRCoder.csproj b/QRCoder/QRCoder.csproj index 2f6ab10b..4ec4e009 100644 --- a/QRCoder/QRCoder.csproj +++ b/QRCoder/QRCoder.csproj @@ -25,8 +25,6 @@ - - diff --git a/QRCoder/SvgQRCode.cs b/QRCoder/SvgQRCode.cs index b4ebe7b9..fbe35901 100644 --- a/QRCoder/SvgQRCode.cs +++ b/QRCoder/SvgQRCode.cs @@ -433,28 +433,6 @@ public class SvgLogo private readonly object _logoRaw; private readonly bool _isEmbedded; - /// - /// Create a logo object to be used in SvgQRCode renderer - /// - /// Logo to be rendered as Bitmap/rasterized graphic - /// Degree of percentage coverage of the QR code by the logo - /// If true, the background behind the logo will be cleaned - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) - { - _iconSizePercent = iconSizePercent; - using (var ms = new System.IO.MemoryStream()) - { - using var bitmap = new Bitmap(iconRasterized); - bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); - _logoData = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length, Base64FormattingOptions.None); - } - _mediaType = MediaType.PNG; - _fillLogoBackground = fillLogoBackground; - _logoRaw = iconRasterized; - _isEmbedded = false; - } - /// /// Create a logo object to be used in SvgQRCode renderer /// diff --git a/QRCoderApiTests/ApiApprovalTests.cs b/QRCoderApiTests/ApiApprovalTests.cs index 77f3a5e9..78bac86e 100644 --- a/QRCoderApiTests/ApiApprovalTests.cs +++ b/QRCoderApiTests/ApiApprovalTests.cs @@ -44,6 +44,7 @@ public class ApiApprovalTests { [Theory] [InlineData(typeof(QRCoder.QRCodeData))] + [InlineData(typeof(QRCoder.QRCode))] [InlineData(typeof(QRCoder.Xaml.XamlQRCode))] public void PublicApi(Type type) { diff --git a/QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt b/QRCoderApiTests/QRCoder.approved.txt similarity index 92% rename from QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt rename to QRCoderApiTests/QRCoder.approved.txt index ebe18a41..02865d47 100644 --- a/QRCoderApiTests/netstandard20+netstandard21/QRCoder.approved.txt +++ b/QRCoderApiTests/QRCoder.approved.txt @@ -8,44 +8,6 @@ namespace QRCoder public void Dispose() { } public virtual void SetQRCodeData(QRCoder.QRCodeData data) { } } - public class ArtQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public ArtQRCode() { } - public ArtQRCode(QRCoder.QRCodeData data) { } - public System.Drawing.Bitmap GetGraphic(System.Drawing.Bitmap? backgroundImage = null) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Color backgroundColor, System.Drawing.Bitmap? backgroundImage = null, double pixelSizeFactor = 1, bool drawQuietZones = true, QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 0, QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, System.Drawing.Bitmap? finderPatternImage = null) { } - public enum BackgroundImageStyle - { - Fill = 0, - DataAreaOnly = 1, - } - public enum QuietZoneStyle - { - Dotted = 0, - Flat = 1, - } - } - public static class ArtQRCodeHelper - { - public static System.Drawing.Bitmap GetQRCode( - string plainText, - int pixelsPerModule, - System.Drawing.Color darkColor, - System.Drawing.Color lightColor, - System.Drawing.Color backgroundColor, - QRCoder.QRCodeGenerator.ECCLevel eccLevel, - bool forceUtf8 = false, - bool utf8BOM = false, - QRCoder.QRCodeGenerator.EciMode eciMode = 0, - int requestedVersion = -1, - System.Drawing.Bitmap? backgroundImage = null, - double pixelSizeFactor = 1, - bool drawQuietZones = true, - QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 1, - QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, - System.Drawing.Bitmap? finderPatternImage = null) { } - } public class AsciiQRCode : QRCoder.AbstractQRCode, System.IDisposable { public AsciiQRCode() { } @@ -68,9 +30,15 @@ namespace QRCoder public Base64QRCode() { } public Base64QRCode(QRCoder.QRCodeData data) { } public string GetGraphic(int pixelsPerModule) { } - public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap icon, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } + public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } + public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) { } + [System.Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload" + + " without the imgType parameter.")] + public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones, QRCoder.Base64QRCode.ImageType imgType) { } + [System.Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload" + + " without the imgType parameter.")] + public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones, QRCoder.Base64QRCode.ImageType imgType) { } + [System.Obsolete("ImageType enum is obsolete. Only PNG format is supported.")] public enum ImageType { Gif = 0, @@ -80,7 +48,10 @@ namespace QRCoder } public static class Base64QRCodeHelper { - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } + public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true) { } + [System.Obsolete("The imgType parameter is obsolete. Only PNG format is supported. Use the overload" + + " without the imgType parameter.")] + public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8, bool utf8BOM, QRCoder.QRCodeGenerator.EciMode eciMode, int requestedVersion, bool drawQuietZones, QRCoder.Base64QRCode.ImageType imgType) { } } public class BitmapByteQRCode : QRCoder.AbstractQRCode, System.IDisposable { @@ -888,15 +859,6 @@ namespace QRCoder { public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false) { } } - public class QRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public QRCode() { } - public QRCode(QRCoder.QRCodeData data) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true, System.Drawing.Color? iconBackgroundColor = default) { } - } public class QRCodeData : System.IDisposable { public QRCodeData(int version) { } @@ -944,10 +906,6 @@ namespace QRCoder Utf8 = 26, } } - public static class QRCodeHelper - { - public static System.Drawing.Bitmap GetQRCode(string plainText, int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true) { } - } public class SvgQRCode : QRCoder.AbstractQRCode, System.IDisposable { public SvgQRCode() { } @@ -967,7 +925,6 @@ namespace QRCoder public class SvgLogo { public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { } - public SvgLogo(System.Drawing.Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { } public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBackground = true, bool iconEmbedded = true) { } public bool FillLogoBackground() { } public string GetDataUri() { } diff --git a/QRCoderApiTests/QRCoderApiTests.csproj b/QRCoderApiTests/QRCoderApiTests.csproj index cab6421c..c3527001 100644 --- a/QRCoderApiTests/QRCoderApiTests.csproj +++ b/QRCoderApiTests/QRCoderApiTests.csproj @@ -6,8 +6,8 @@ + - diff --git a/QRCoderApiTests/net60/QRCoder.SystemDrawing.approved.txt b/QRCoderApiTests/net60/QRCoder.SystemDrawing.approved.txt new file mode 100644 index 00000000..2bd70386 --- /dev/null +++ b/QRCoderApiTests/net60/QRCoder.SystemDrawing.approved.txt @@ -0,0 +1,58 @@ +namespace QRCoder +{ + [System.Runtime.Versioning.SupportedOSPlatform("windows")] + public class ArtQRCode : QRCoder.AbstractQRCode, System.IDisposable + { + public ArtQRCode() { } + public ArtQRCode(QRCoder.QRCodeData data) { } + public System.Drawing.Bitmap GetGraphic(System.Drawing.Bitmap? backgroundImage = null) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Color backgroundColor, System.Drawing.Bitmap? backgroundImage = null, double pixelSizeFactor = 1, bool drawQuietZones = true, QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 0, QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, System.Drawing.Bitmap? finderPatternImage = null) { } + public enum BackgroundImageStyle + { + Fill = 0, + DataAreaOnly = 1, + } + public enum QuietZoneStyle + { + Dotted = 0, + Flat = 1, + } + } + [System.Runtime.Versioning.SupportedOSPlatform("windows")] + public static class ArtQRCodeHelper + { + public static System.Drawing.Bitmap GetQRCode( + string plainText, + int pixelsPerModule, + System.Drawing.Color darkColor, + System.Drawing.Color lightColor, + System.Drawing.Color backgroundColor, + QRCoder.QRCodeGenerator.ECCLevel eccLevel, + bool forceUtf8 = false, + bool utf8BOM = false, + QRCoder.QRCodeGenerator.EciMode eciMode = 0, + int requestedVersion = -1, + System.Drawing.Bitmap? backgroundImage = null, + double pixelSizeFactor = 1, + bool drawQuietZones = true, + QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 1, + QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, + System.Drawing.Bitmap? finderPatternImage = null) { } + } + [System.Runtime.Versioning.SupportedOSPlatform("windows")] + public class QRCode : QRCoder.AbstractQRCode, System.IDisposable + { + public QRCode() { } + public QRCode(QRCoder.QRCodeData data) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true, System.Drawing.Color? iconBackgroundColor = default) { } + } + [System.Runtime.Versioning.SupportedOSPlatform("windows")] + public static class QRCodeHelper + { + public static System.Drawing.Bitmap GetQRCode(string plainText, int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true) { } + } +} diff --git a/QRCoderApiTests/net60/QRCoder.approved.txt b/QRCoderApiTests/net60/QRCoder.approved.txt deleted file mode 100644 index 89fbe918..00000000 --- a/QRCoderApiTests/net60/QRCoder.approved.txt +++ /dev/null @@ -1,1005 +0,0 @@ -namespace QRCoder -{ - public abstract class AbstractQRCode - { - protected AbstractQRCode() { } - protected AbstractQRCode(QRCoder.QRCodeData data) { } - protected QRCoder.QRCodeData QrCodeData { get; set; } - public void Dispose() { } - public virtual void SetQRCodeData(QRCoder.QRCodeData data) { } - } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public class ArtQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public ArtQRCode() { } - public ArtQRCode(QRCoder.QRCodeData data) { } - public System.Drawing.Bitmap GetGraphic(System.Drawing.Bitmap? backgroundImage = null) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Color backgroundColor, System.Drawing.Bitmap? backgroundImage = null, double pixelSizeFactor = 1, bool drawQuietZones = true, QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 0, QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, System.Drawing.Bitmap? finderPatternImage = null) { } - public enum BackgroundImageStyle - { - Fill = 0, - DataAreaOnly = 1, - } - public enum QuietZoneStyle - { - Dotted = 0, - Flat = 1, - } - } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public static class ArtQRCodeHelper - { - public static System.Drawing.Bitmap GetQRCode( - string plainText, - int pixelsPerModule, - System.Drawing.Color darkColor, - System.Drawing.Color lightColor, - System.Drawing.Color backgroundColor, - QRCoder.QRCodeGenerator.ECCLevel eccLevel, - bool forceUtf8 = false, - bool utf8BOM = false, - QRCoder.QRCodeGenerator.EciMode eciMode = 0, - int requestedVersion = -1, - System.Drawing.Bitmap? backgroundImage = null, - double pixelSizeFactor = 1, - bool drawQuietZones = true, - QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 1, - QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, - System.Drawing.Bitmap? finderPatternImage = null) { } - } - public class AsciiQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public AsciiQRCode() { } - public AsciiQRCode(QRCoder.QRCodeData data) { } - public string GetGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true, string endOfLine = " -") { } - public string GetGraphicSmall(bool drawQuietZones = true, bool invert = false, string endOfLine = " -") { } - public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true) { } - } - public static class AsciiQRCodeHelper - { - public static string GetQRCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, string endOfLine = " -", bool drawQuietZones = true, bool invert = true) { } - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorString, string whiteSpaceString, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, string endOfLine = " -", bool drawQuietZones = true) { } - } - public class Base64QRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public Base64QRCode() { } - public Base64QRCode(QRCoder.QRCodeData data) { } - public string GetGraphic(int pixelsPerModule) { } - public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap icon, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - public enum ImageType - { - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - Gif = 0, - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - Jpeg = 1, - Png = 2, - } - } - public static class Base64QRCodeHelper - { - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true, QRCoder.Base64QRCode.ImageType imgType = 2) { } - } - public class BitmapByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public BitmapByteQRCode() { } - public BitmapByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule) { } - public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightColorRgb) { } - public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex) { } - } - public static class BitmapByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - } - public static class PayloadGenerator - { - public static bool ChecksumMod10(string digits) { } - public class BezahlCode : QRCoder.PayloadGenerator.Payload - { - public BezahlCode(QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, string name, string account = "", string bnc = "", string iban = "", string bic = "", string reason = "") { } - public BezahlCode(QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, string name, string account, string bnc, decimal amount, string periodicTimeunit = "", int periodicTimeunitRotation = 0, System.DateTime? periodicFirstExecutionDate = default, System.DateTime? periodicLastExecutionDate = default, string reason = "", int postingKey = 0, QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, System.DateTime? executionDate = default) { } - public BezahlCode( - QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, - string name, - string iban, - string bic, - decimal amount, - string periodicTimeunit = "", - int periodicTimeunitRotation = 0, - System.DateTime? periodicFirstExecutionDate = default, - System.DateTime? periodicLastExecutionDate = default, - string creditorId = "", - string mandateId = "", - System.DateTime? dateOfSignature = default, - string reason = "", - string sepaReference = "", - QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, - System.DateTime? executionDate = default) { } - public BezahlCode( - QRCoder.PayloadGenerator.BezahlCode.AuthorityType authority, - string name, - string account, - string bnc, - string iban, - string bic, - decimal amount, - string periodicTimeunit = "", - int periodicTimeunitRotation = 0, - System.DateTime? periodicFirstExecutionDate = default, - System.DateTime? periodicLastExecutionDate = default, - string creditorId = "", - string mandateId = "", - System.DateTime? dateOfSignature = default, - string reason = "", - int postingKey = 0, - string sepaReference = "", - QRCoder.PayloadGenerator.BezahlCode.Currency currency = 978, - System.DateTime? executionDate = default, - int internalMode = 0) { } - public override string ToString() { } - public enum AuthorityType - { - [System.Obsolete("Use singlepaymentsepa instead for SEPA-compliant payments")] - singlepayment = 0, - singlepaymentsepa = 1, - [System.Obsolete("Use singledirectdebitsepa instead for SEPA-compliant payments")] - singledirectdebit = 2, - singledirectdebitsepa = 3, - [System.Obsolete("Use periodicsinglepaymentsepa instead for SEPA-compliant payments")] - periodicsinglepayment = 4, - periodicsinglepaymentsepa = 5, - contact = 6, - contact_v2 = 7, - } - public class BezahlCodeException : System.Exception - { - public BezahlCodeException() { } - public BezahlCodeException(string message) { } - public BezahlCodeException(string message, System.Exception inner) { } - } - public enum Currency - { - AED = 784, - AFN = 971, - ALL = 8, - AMD = 51, - ANG = 532, - AOA = 973, - ARS = 32, - AUD = 36, - AWG = 533, - AZN = 944, - BAM = 977, - BBD = 52, - BDT = 50, - BGN = 975, - BHD = 48, - BIF = 108, - BMD = 60, - BND = 96, - BOB = 68, - BOV = 984, - BRL = 986, - BSD = 44, - BTN = 64, - BWP = 72, - BYR = 974, - BZD = 84, - CAD = 124, - CDF = 976, - CHE = 947, - CHF = 756, - CHW = 948, - CLF = 990, - CLP = 152, - CNY = 156, - COP = 170, - COU = 970, - CRC = 188, - CUC = 931, - CUP = 192, - CVE = 132, - CZK = 203, - DJF = 262, - DKK = 208, - DOP = 214, - DZD = 12, - EGP = 818, - ERN = 232, - ETB = 230, - EUR = 978, - FJD = 242, - FKP = 238, - GBP = 826, - GEL = 981, - GHS = 936, - GIP = 292, - GMD = 270, - GNF = 324, - GTQ = 320, - GYD = 328, - HKD = 344, - HNL = 340, - HRK = 191, - HTG = 332, - HUF = 348, - IDR = 360, - ILS = 376, - INR = 356, - IQD = 368, - IRR = 364, - ISK = 352, - JMD = 388, - JOD = 400, - JPY = 392, - KES = 404, - KGS = 417, - KHR = 116, - KMF = 174, - KPW = 408, - KRW = 410, - KWD = 414, - KYD = 136, - KZT = 398, - LAK = 418, - LBP = 422, - LKR = 144, - LRD = 430, - LSL = 426, - LYD = 434, - MAD = 504, - MDL = 498, - MGA = 969, - MKD = 807, - MMK = 104, - MNT = 496, - MOP = 446, - MRO = 478, - MUR = 480, - MVR = 462, - MWK = 454, - MXN = 484, - MXV = 979, - MYR = 458, - MZN = 943, - NAD = 516, - NGN = 566, - NIO = 558, - NOK = 578, - NPR = 524, - NZD = 554, - OMR = 512, - PAB = 590, - PEN = 604, - PGK = 598, - PHP = 608, - PKR = 586, - PLN = 985, - PYG = 600, - QAR = 634, - RON = 946, - RSD = 941, - RUB = 643, - RWF = 646, - SAR = 682, - SBD = 90, - SCR = 690, - SDG = 938, - SEK = 752, - SGD = 702, - SHP = 654, - SLL = 694, - SOS = 706, - SRD = 968, - SSP = 728, - STD = 678, - SVC = 222, - SYP = 760, - SZL = 748, - THB = 764, - TJS = 972, - TMT = 934, - TND = 788, - TOP = 776, - TRY = 949, - TTD = 780, - TWD = 901, - TZS = 834, - UAH = 980, - UGX = 800, - USD = 840, - USN = 997, - UYI = 940, - UYU = 858, - UZS = 860, - VEF = 937, - VND = 704, - VUV = 548, - WST = 882, - XAF = 950, - XAG = 961, - XAU = 959, - XBA = 955, - XBB = 956, - XBC = 957, - XBD = 958, - XCD = 951, - XDR = 960, - XOF = 952, - XPD = 964, - XPF = 953, - XPT = 962, - XSU = 994, - XTS = 963, - XUA = 965, - XXX = 999, - YER = 886, - ZAR = 710, - ZMW = 967, - ZWL = 932, - } - } - public class BitcoinAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public BitcoinAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class BitcoinCashAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public BitcoinCashAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class BitcoinLikeCryptoCurrencyAddress : QRCoder.PayloadGenerator.Payload - { - public BitcoinLikeCryptoCurrencyAddress(QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress.BitcoinLikeCryptoCurrencyType currencyType, string address, double? amount, string? label = null, string? message = null) { } - public override string ToString() { } - public enum BitcoinLikeCryptoCurrencyType - { - Bitcoin = 0, - BitcoinCash = 1, - Litecoin = 2, - } - } - public class Bookmark : QRCoder.PayloadGenerator.Payload - { - public Bookmark(string url, string title) { } - public override string ToString() { } - } - public class CalendarEvent : QRCoder.PayloadGenerator.Payload - { - public CalendarEvent(string subject, string? description, string? location, System.DateTime start, System.DateTime end, bool allDayEvent, QRCoder.PayloadGenerator.CalendarEvent.EventEncoding encoding = 1) { } - public CalendarEvent(string subject, string? description, string? location, System.DateTimeOffset start, System.DateTimeOffset end, bool allDayEvent, QRCoder.PayloadGenerator.CalendarEvent.EventEncoding encoding = 1) { } - public override string ToString() { } - public enum EventEncoding - { - iCalComplete = 0, - Universal = 1, - } - } - public class ContactData : QRCoder.PayloadGenerator.Payload - { - public ContactData( - QRCoder.PayloadGenerator.ContactData.ContactOutputType outputType, - string firstname, - string lastname, - string? nickname = null, - string? phone = null, - string? mobilePhone = null, - string? workPhone = null, - string? email = null, - System.DateTime? birthday = default, - string? website = null, - string? street = null, - string? houseNumber = null, - string? city = null, - string? zipCode = null, - string? country = null, - string? note = null, - string? stateRegion = null, - QRCoder.PayloadGenerator.ContactData.AddressOrder addressOrder = 0, - string? org = null, - string? orgTitle = null) { } - public ContactData( - QRCoder.PayloadGenerator.ContactData.ContactOutputType outputType, - string firstname, - string lastname, - string? nickname, - string? phone, - string? mobilePhone, - string? workPhone, - string? email, - System.DateTime? birthday, - string? website, - string? street, - string? houseNumber, - string? city, - string? zipCode, - string? country, - string? note, - string? stateRegion, - QRCoder.PayloadGenerator.ContactData.AddressOrder addressOrder, - string? org, - string? orgTitle, - QRCoder.PayloadGenerator.ContactData.AddressType addressType) { } - public override string ToString() { } - public enum AddressOrder - { - Default = 0, - Reversed = 1, - } - public enum AddressType - { - Home = 0, - Work = 1, - HomePreferred = 2, - WorkPreferred = 3, - } - public enum ContactOutputType - { - MeCard = 0, - VCard21 = 1, - VCard3 = 2, - VCard4 = 3, - } - } - public class Geolocation : QRCoder.PayloadGenerator.Payload - { - public Geolocation(string latitude, string longitude, QRCoder.PayloadGenerator.Geolocation.GeolocationEncoding encoding = 0) { } - public override string ToString() { } - public enum GeolocationEncoding - { - GEO = 0, - GoogleMaps = 1, - } - } - public class Girocode : QRCoder.PayloadGenerator.Payload - { - public Girocode(string iban, string? bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override string ToString() { } - public enum GirocodeEncoding - { - UTF_8 = 0, - ISO_8859_1 = 1, - ISO_8859_2 = 2, - ISO_8859_4 = 3, - ISO_8859_5 = 4, - ISO_8859_7 = 5, - ISO_8859_10 = 6, - ISO_8859_15 = 7, - } - public class GirocodeException : System.Exception - { - public GirocodeException() { } - public GirocodeException(string message) { } - public GirocodeException(string message, System.Exception inner) { } - } - public enum GirocodeVersion - { - Version1 = 0, - Version2 = 1, - } - public enum TypeOfRemittance - { - Structured = 0, - Unstructured = 1, - } - } - public class LitecoinAddress : QRCoder.PayloadGenerator.BitcoinLikeCryptoCurrencyAddress - { - public LitecoinAddress(string address, double? amount, string? label = null, string? message = null) { } - } - public class MMS : QRCoder.PayloadGenerator.Payload - { - public MMS(string number, QRCoder.PayloadGenerator.MMS.MMSEncoding encoding = 0) { } - public MMS(string number, string subject, QRCoder.PayloadGenerator.MMS.MMSEncoding encoding = 0) { } - public override string ToString() { } - public enum MMSEncoding - { - MMS = 0, - MMSTO = 1, - } - } - public class Mail : QRCoder.PayloadGenerator.Payload - { - public Mail(string? mailReceiver = null, string? subject = null, string? message = null, QRCoder.PayloadGenerator.Mail.MailEncoding encoding = 0) { } - public override string ToString() { } - public enum MailEncoding - { - MAILTO = 0, - MATMSG = 1, - SMTP = 2, - } - } - public class MoneroTransaction : QRCoder.PayloadGenerator.Payload - { - public MoneroTransaction(string address, float? txAmount = default, string? txPaymentId = null, string? recipientName = null, string? txDescription = null) { } - public override string ToString() { } - public class MoneroTransactionException : System.Exception - { - public MoneroTransactionException() { } - public MoneroTransactionException(string message) { } - public MoneroTransactionException(string message, System.Exception inner) { } - } - } - public class OneTimePassword : QRCoder.PayloadGenerator.Payload - { - public OneTimePassword() { } - [System.Obsolete("This property is obsolete, use AuthAlgorithm instead", false)] - public QRCoder.PayloadGenerator.OneTimePassword.OoneTimePasswordAuthAlgorithm Algorithm { get; set; } - public QRCoder.PayloadGenerator.OneTimePassword.OneTimePasswordAuthAlgorithm AuthAlgorithm { get; set; } - public int? Counter { get; set; } - public int Digits { get; set; } - public string? Issuer { get; set; } - public string? Label { get; set; } - public int? Period { get; set; } - public string Secret { get; set; } - public QRCoder.PayloadGenerator.OneTimePassword.OneTimePasswordAuthType Type { get; set; } - public override string ToString() { } - public enum OneTimePasswordAuthAlgorithm - { - SHA1 = 0, - SHA256 = 1, - SHA512 = 2, - } - public enum OneTimePasswordAuthType - { - TOTP = 0, - HOTP = 1, - } - [System.Obsolete("This enum is obsolete, use OneTimePasswordAuthAlgorithm instead", false)] - public enum OoneTimePasswordAuthAlgorithm - { - SHA1 = 0, - SHA256 = 1, - SHA512 = 2, - } - } - public abstract class Payload - { - protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public virtual int Version { get; } - public abstract override string ToString() { } - } - public class PhoneNumber : QRCoder.PayloadGenerator.Payload - { - public PhoneNumber(string number) { } - public override string ToString() { } - } - public class RussiaPaymentOrder : QRCoder.PayloadGenerator.Payload - { - public RussiaPaymentOrder(string name, string personalAcc, string bankName, string BIC, string correspAcc, QRCoder.PayloadGenerator.RussiaPaymentOrder.OptionalFields? optionalFields = null, QRCoder.PayloadGenerator.RussiaPaymentOrder.CharacterSets characterSet = 2) { } - public byte[] ToBytes() { } - public override string ToString() { } - public enum CharacterSets - { - windows_1251 = 1, - utf_8 = 2, - koi8_r = 3, - } - public class OptionalFields - { - public OptionalFields() { } - public string? AddAmount { get; set; } - public System.DateTime? BirthDate { get; set; } - public string? CBC { get; set; } - public string? Category { get; set; } - public string? ChildFio { get; set; } - public string? ClassNum { get; set; } - public string? Contract { get; set; } - public string? CounterId { get; set; } - public string? CounterVal { get; set; } - public System.DateTime? DocDate { get; set; } - public string? DocIdx { get; set; } - public string? DocNo { get; set; } - public string? DrawerStatus { get; set; } - public string? ExecId { get; set; } - public string? FirstName { get; set; } - public string? Flat { get; set; } - public string? InstNum { get; set; } - public string? KPP { get; set; } - public string? LastName { get; set; } - public string? MiddleName { get; set; } - public string? OKTMO { get; set; } - public string? PayeeINN { get; set; } - public string? PayerAddress { get; set; } - public string? PayerINN { get; set; } - public string? PayerIdNum { get; set; } - public string? PayerIdType { get; set; } - public string? PaymPeriod { get; set; } - public string? PaymTerm { get; set; } - public string? PaytReason { get; set; } - public string? PensAcc { get; set; } - public string? PersAcc { get; set; } - public string? PersonalAccount { get; set; } - public string? Phone { get; set; } - public string? Purpose { get; set; } - public System.DateTime? QuittDate { get; set; } - public string? QuittId { get; set; } - public string? RegType { get; set; } - public string? RuleId { get; set; } - public string? ServiceName { get; set; } - public string? SpecFio { get; set; } - public string? Sum { get; set; } - public string? TaxPaytKind { get; set; } - public string? TaxPeriod { get; set; } - public QRCoder.PayloadGenerator.RussiaPaymentOrder.TechCode? TechCode { get; set; } - public string? UIN { get; set; } - } - public class RussiaPaymentOrderException : System.Exception - { - public RussiaPaymentOrderException(string message) { } - } - public enum TechCode - { - Мобильная_связь_стационарный_телефон = 1, - Коммунальные_услуги_ЖКХAFN = 2, - ГИБДД_налоги_пошлины_бюджетные_платежи = 3, - Охранные_услуги = 4, - Услуги_оказываемые_УФМС = 5, - ПФР = 6, - Погашение_кредитов = 7, - Образовательные_учреждения = 8, - Интернет_и_ТВ = 9, - Электронные_деньги = 10, - Отдых_и_путешествия = 11, - Инвестиции_и_страхование = 12, - Спорт_и_здоровье = 13, - Благотворительные_и_общественные_организации = 14, - Прочие_услуги = 15, - } - } - public class SMS : QRCoder.PayloadGenerator.Payload - { - public SMS(string number, QRCoder.PayloadGenerator.SMS.SMSEncoding encoding = 0) { } - public SMS(string number, string subject, QRCoder.PayloadGenerator.SMS.SMSEncoding encoding = 0) { } - public override string ToString() { } - public enum SMSEncoding - { - SMS = 0, - SMSTO = 1, - SMS_iOS = 2, - } - } - public class ShadowSocksConfig : QRCoder.PayloadGenerator.Payload - { - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, string? tag = null) { } - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, System.Collections.Generic.Dictionary? parameters, string? tag = null) { } - public ShadowSocksConfig(string hostname, int port, string password, QRCoder.PayloadGenerator.ShadowSocksConfig.Method method, string plugin, string? pluginOption, string? tag = null) { } - public override string ToString() { } - public enum Method - { - Chacha20IetfPoly1305 = 0, - Aes128Gcm = 1, - Aes192Gcm = 2, - Aes256Gcm = 3, - XChacha20IetfPoly1305 = 4, - Aes128Cfb = 5, - Aes192Cfb = 6, - Aes256Cfb = 7, - Aes128Ctr = 8, - Aes192Ctr = 9, - Aes256Ctr = 10, - Camellia128Cfb = 11, - Camellia192Cfb = 12, - Camellia256Cfb = 13, - Chacha20Ietf = 14, - Aes256Cb = 15, - Aes128Ofb = 16, - Aes192Ofb = 17, - Aes256Ofb = 18, - Aes128Cfb1 = 19, - Aes192Cfb1 = 20, - Aes256Cfb1 = 21, - Aes128Cfb8 = 22, - Aes192Cfb8 = 23, - Aes256Cfb8 = 24, - Chacha20 = 25, - BfCfb = 26, - Rc4Md5 = 27, - Salsa20 = 28, - DesCfb = 29, - IdeaCfb = 30, - Rc2Cfb = 31, - Cast5Cfb = 32, - Salsa20Ctr = 33, - Rc4 = 34, - SeedCfb = 35, - Table = 36, - } - public class ShadowSocksConfigException : System.Exception - { - public ShadowSocksConfigException() { } - public ShadowSocksConfigException(string message) { } - public ShadowSocksConfigException(string message, System.Exception inner) { } - } - } - public class SkypeCall : QRCoder.PayloadGenerator.Payload - { - public SkypeCall(string skypeUsername) { } - public override string ToString() { } - } - public class SlovenianUpnQr : QRCoder.PayloadGenerator.Payload - { - public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } - public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public override int Version { get; } - public override string ToString() { } - } - public class SwissQrCode : QRCoder.PayloadGenerator.Payload - { - public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation? additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact? debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact? ultimateCreditor = null, string? alternativeProcedure1 = null, string? alternativeProcedure2 = null) { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } - public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } - public override string ToString() { } - public class AdditionalInformation - { - public AdditionalInformation(string? unstructuredMessage = null, string? billInformation = null) { } - public string? BillInformation { get; } - public string Trailer { get; } - public string? UnstructureMessage { get; } - public class SwissQrCodeAdditionalInformationException : System.Exception - { - public SwissQrCodeAdditionalInformationException() { } - public SwissQrCodeAdditionalInformationException(string message) { } - public SwissQrCodeAdditionalInformationException(string message, System.Exception inner) { } - } - } - public class Contact - { - [System.Obsolete("This constructor is deprecated. Use WithCombinedAddress instead.")] - public Contact(string name, string country, string addressLine1, string addressLine2) { } - [System.Obsolete("This constructor is deprecated. Use WithStructuredAddress instead.")] - public Contact(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null) { } - public override string ToString() { } - public static QRCoder.PayloadGenerator.SwissQrCode.Contact WithCombinedAddress(string name, string country, string addressLine1, string addressLine2) { } - public static QRCoder.PayloadGenerator.SwissQrCode.Contact WithStructuredAddress(string name, string zipCode, string city, string country, string? street = null, string? houseNumber = null) { } - public enum AddressType - { - StructuredAddress = 0, - CombinedAddress = 1, - } - public class SwissQrCodeContactException : System.Exception - { - public SwissQrCodeContactException() { } - public SwissQrCodeContactException(string message) { } - public SwissQrCodeContactException(string message, System.Exception inner) { } - } - } - public enum Currency - { - CHF = 756, - EUR = 978, - } - public class Iban - { - public Iban(string iban, QRCoder.PayloadGenerator.SwissQrCode.Iban.IbanType ibanType) { } - public bool IsQrIban { get; } - public override string ToString() { } - public enum IbanType - { - Iban = 0, - QrIban = 1, - } - public class SwissQrCodeIbanException : System.Exception - { - public SwissQrCodeIbanException() { } - public SwissQrCodeIbanException(string message) { } - public SwissQrCodeIbanException(string message, System.Exception inner) { } - } - } - public class Reference - { - public Reference(QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceType referenceType, string? reference = null, QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceTextType? referenceTextType = default) { } - public QRCoder.PayloadGenerator.SwissQrCode.Reference.ReferenceType RefType { get; } - public string? ReferenceText { get; } - public enum ReferenceTextType - { - QrReference = 0, - CreditorReferenceIso11649 = 1, - } - public enum ReferenceType - { - QRR = 0, - SCOR = 1, - NON = 2, - } - public class SwissQrCodeReferenceException : System.Exception - { - public SwissQrCodeReferenceException() { } - public SwissQrCodeReferenceException(string message) { } - public SwissQrCodeReferenceException(string message, System.Exception inner) { } - } - } - public class SwissQrCodeException : System.Exception - { - public SwissQrCodeException() { } - public SwissQrCodeException(string message) { } - public SwissQrCodeException(string message, System.Exception inner) { } - } - } - public class Url : QRCoder.PayloadGenerator.Payload - { - public Url(string url) { } - public override string ToString() { } - } - public class WhatsAppMessage : QRCoder.PayloadGenerator.Payload - { - public WhatsAppMessage(string message) { } - public WhatsAppMessage(string number, string message) { } - public override string ToString() { } - } - public class WiFi : QRCoder.PayloadGenerator.Payload - { - public WiFi(string ssid, string password, QRCoder.PayloadGenerator.WiFi.Authentication authenticationMode, bool isHiddenSSID = false, bool escapeHexStrings = true) { } - public override string ToString() { } - public enum Authentication - { - WEP = 0, - WPA = 1, - nopass = 2, - WPA2 = 3, - } - } - } - public class PdfByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public PdfByteQRCode() { } - public PdfByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule) { } - public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, int dpi = 150, long jpgQuality = 85) { } - } - public static class PdfByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - } - public sealed class PngByteQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public PngByteQRCode() { } - public PngByteQRCode(QRCoder.QRCodeData data) { } - public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) { } - public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, bool drawQuietZones = true) { } - public byte[] GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } - } - public static class PngByteQRCodeHelper - { - public static byte[] GetQRCode(string txt, QRCoder.QRCodeGenerator.ECCLevel eccLevel, int size, bool drawQuietZones = true) { } - public static byte[] GetQRCode(string plainText, int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true) { } - } - public class PostscriptQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public PostscriptQRCode() { } - public PostscriptQRCode(QRCoder.QRCodeData data) { } - public string GetGraphic(int pointsPerModule, bool epsFormat = false) { } - public string GetGraphic(System.Drawing.Size viewBox, bool drawQuietZones = true, bool epsFormat = false) { } - public string GetGraphic(System.Drawing.Size viewBox, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, bool epsFormat = false) { } - public string GetGraphic(System.Drawing.Size viewBox, string darkColorHex, string lightColorHex, bool drawQuietZones = true, bool epsFormat = false) { } - public string GetGraphic(int pointsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, bool epsFormat = false) { } - public string GetGraphic(int pointsPerModule, string darkColorHex, string lightColorHex, bool drawQuietZones = true, bool epsFormat = false) { } - } - public static class PostscriptQRCodeHelper - { - public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false) { } - } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public class QRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public QRCode() { } - public QRCode(QRCoder.QRCodeData data) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) { } - public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true, System.Drawing.Color? iconBackgroundColor = default) { } - } - public class QRCodeData : System.IDisposable - { - public QRCodeData(int version) { } - public QRCodeData(byte[] rawData, QRCoder.QRCodeData.Compression compressMode) { } - public QRCodeData(int version, bool addPadding) { } - public QRCodeData(string pathToRawData, QRCoder.QRCodeData.Compression compressMode) { } - public System.Collections.Generic.List ModuleMatrix { get; set; } - public int Version { get; } - public virtual void Dispose() { } - public byte[] GetRawData(QRCoder.QRCodeData.Compression compressMode) { } - public void SaveRawData(string filePath, QRCoder.QRCodeData.Compression compressMode) { } - public enum Compression - { - Uncompressed = 0, - Deflate = 1, - GZip = 2, - } - } - public class QRCodeGenerator : System.IDisposable - { - public QRCodeGenerator() { } - public QRCoder.QRCodeData CreateQrCode(QRCoder.PayloadGenerator.Payload payload) { } - public QRCoder.QRCodeData CreateQrCode(QRCoder.PayloadGenerator.Payload payload, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public QRCoder.QRCodeData CreateQrCode(byte[] binaryData, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public QRCoder.QRCodeData CreateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - public virtual void Dispose() { } - public static QRCoder.QRCodeData GenerateMicroQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel = -1, int requestedVersion = 0) { } - public static QRCoder.QRCodeData GenerateQrCode(QRCoder.PayloadGenerator.Payload payload) { } - public static QRCoder.QRCodeData GenerateQrCode(QRCoder.PayloadGenerator.Payload payload, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public static QRCoder.QRCodeData GenerateQrCode(byte[] binaryData, QRCoder.QRCodeGenerator.ECCLevel eccLevel) { } - public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } - public enum ECCLevel - { - Default = -1, - L = 0, - M = 1, - Q = 2, - H = 3, - } - public enum EciMode - { - Default = 0, - Iso8859_1 = 3, - Iso8859_2 = 4, - Utf8 = 26, - } - } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public static class QRCodeHelper - { - public static System.Drawing.Bitmap GetQRCode(string plainText, int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true) { } - } - public class SvgQRCode : QRCoder.AbstractQRCode, System.IDisposable - { - public SvgQRCode() { } - public SvgQRCode(QRCoder.QRCodeData data) { } - public string GetGraphic() { } - public string GetGraphic(int pixelsPerModule) { } - public string GetGraphic(System.Drawing.Size viewBox, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - public string GetGraphic(System.Drawing.Size viewBox, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - public string GetGraphic(System.Drawing.Size viewBox, string darkColorHex, string lightColorHex, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - public string GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - public string GetGraphic(int pixelsPerModule, string darkColorHex, string lightColorHex, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - public enum SizingMode - { - WidthHeightAttribute = 0, - ViewBoxAttribute = 1, - } - public class SvgLogo - { - public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { } - [System.Runtime.Versioning.SupportedOSPlatform("windows")] - public SvgLogo(System.Drawing.Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { } - public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBackground = true, bool iconEmbedded = true) { } - public bool FillLogoBackground() { } - public string GetDataUri() { } - public int GetIconSizePercent() { } - public QRCoder.SvgQRCode.SvgLogo.MediaType GetMediaType() { } - public object GetRawLogo() { } - public bool IsEmbedded() { } - public enum MediaType - { - PNG = 0, - SVG = 1, - } - } - } - public static class SvgQRCodeHelper - { - public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, bool drawQuietZones = true, QRCoder.SvgQRCode.SizingMode sizingMode = 0, QRCoder.SvgQRCode.SvgLogo? logo = null) { } - } -} -namespace QRCoder.Exceptions -{ - public class DataTooLongException : System.Exception - { - public DataTooLongException(string eccLevel, string encodingMode, int maxSizeByte) { } - public DataTooLongException(string eccLevel, string encodingMode, int version, int maxSizeByte) { } - } -} diff --git a/QRCoderApiTests/netstandard20+netstandard21/QRCoder.SystemDrawing.approved.txt b/QRCoderApiTests/netstandard20+netstandard21/QRCoder.SystemDrawing.approved.txt new file mode 100644 index 00000000..70ee5f33 --- /dev/null +++ b/QRCoderApiTests/netstandard20+netstandard21/QRCoder.SystemDrawing.approved.txt @@ -0,0 +1,54 @@ +namespace QRCoder +{ + public class ArtQRCode : QRCoder.AbstractQRCode, System.IDisposable + { + public ArtQRCode() { } + public ArtQRCode(QRCoder.QRCodeData data) { } + public System.Drawing.Bitmap GetGraphic(System.Drawing.Bitmap? backgroundImage = null) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Color backgroundColor, System.Drawing.Bitmap? backgroundImage = null, double pixelSizeFactor = 1, bool drawQuietZones = true, QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 0, QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, System.Drawing.Bitmap? finderPatternImage = null) { } + public enum BackgroundImageStyle + { + Fill = 0, + DataAreaOnly = 1, + } + public enum QuietZoneStyle + { + Dotted = 0, + Flat = 1, + } + } + public static class ArtQRCodeHelper + { + public static System.Drawing.Bitmap GetQRCode( + string plainText, + int pixelsPerModule, + System.Drawing.Color darkColor, + System.Drawing.Color lightColor, + System.Drawing.Color backgroundColor, + QRCoder.QRCodeGenerator.ECCLevel eccLevel, + bool forceUtf8 = false, + bool utf8BOM = false, + QRCoder.QRCodeGenerator.EciMode eciMode = 0, + int requestedVersion = -1, + System.Drawing.Bitmap? backgroundImage = null, + double pixelSizeFactor = 1, + bool drawQuietZones = true, + QRCoder.ArtQRCode.QuietZoneStyle quietZoneRenderingStyle = 1, + QRCoder.ArtQRCode.BackgroundImageStyle backgroundImageStyle = 1, + System.Drawing.Bitmap? finderPatternImage = null) { } + } + public class QRCode : QRCoder.AbstractQRCode, System.IDisposable + { + public QRCode() { } + public QRCode(QRCoder.QRCodeData data) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true) { } + public System.Drawing.Bitmap GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true, System.Drawing.Color? iconBackgroundColor = default) { } + } + public static class QRCodeHelper + { + public static System.Drawing.Bitmap GetQRCode(string plainText, int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1, System.Drawing.Bitmap? icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true) { } + } +} diff --git a/QRCoderBenchmarks/QRCoderBenchmarks.csproj b/QRCoderBenchmarks/QRCoderBenchmarks.csproj index a3f98c55..314b5e1e 100644 --- a/QRCoderBenchmarks/QRCoderBenchmarks.csproj +++ b/QRCoderBenchmarks/QRCoderBenchmarks.csproj @@ -13,7 +13,7 @@ - + diff --git a/QRCoderConsole/QRCoderConsole.csproj b/QRCoderConsole/QRCoderConsole.csproj index ad079e55..cab34dcb 100644 --- a/QRCoderConsole/QRCoderConsole.csproj +++ b/QRCoderConsole/QRCoderConsole.csproj @@ -28,6 +28,6 @@ - + \ No newline at end of file diff --git a/QRCoderDemo/QRCoderDemo.csproj b/QRCoderDemo/QRCoderDemo.csproj index 22bf8299..f2bfcfd3 100644 --- a/QRCoderDemo/QRCoderDemo.csproj +++ b/QRCoderDemo/QRCoderDemo.csproj @@ -15,12 +15,9 @@ - + - - {aa6be23a-7813-4d2a-835e-b673631ae9f1} - QRCoder - + \ No newline at end of file diff --git a/QRCoderTests/Base64QRCodeRendererTests.can_render_base64_qrcode_jpeg.approved.gif b/QRCoderTests/Base64QRCodeRendererTests.can_render_base64_qrcode_jpeg.approved.gif deleted file mode 100644 index ea6ee4617ec964db2ed52da614f099a1e6f19b05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1395 zcmV-(1&sPfNk%w1VWj}20Du4h00030|NkNW6iY{WAX869R3Jx5Mj%CQV{c?-asVs< z0001`0Hpu`0{@JUsmtvTqnxzbi?iOm`wxcVNS5Y_rs~SJ?hD8AOxN~}=lag~{tpZa zhs2`sh)gP%%%<}RjY_9fD&UIEYPVc&Li^2zu@f+&i%xf0>UMj4g#+Ye@!5^{uJU~Q z!TjfE00==C(1*x|$VYca<`^eoxX8FiiPsqTs2LeCdFiIOsbMIW*HL-Y5$#LtMYtmcz%UQV*{BSHgN;^Cl%iBzm4842`Id`4rpp9F-ODx*y9D1$0 z*1+xSO%86k{#Kriwmsi14$D4%fAX1+e{YRJI$`hBWJ=KwUOQp~6*Qz*u;DagvjXbF z#;{(-ME~(N>RE`e;fCA-;!vY6v2t}Ov!+^yWqYOsI+0Y@ zvNy&0L`QdSTC-2lj)iLXmDj6qquDZS?`mMg0s&KV%8D^T$W+@VPKhBdGq4tpRaN(u zvNXvaG-JlQx6abXiu;OI{W`2F#}qk}P^xfkU6xpJN6qQ`uGHPb^#*Sp`M7Z1w3+)2 z9!~k{;?tc=w>{!IaqEPeXO&(Bb!g<_fov~7ev5h@4hm}#?`-LCwqUV>Dlw; zkNbGY(D$Eg2nsk9Q}vzIhh1-3MqPshdIup*Y}NM}cY^6hnlgVSl^2I0 zCbl04gRSUYfty+Q0*iYMHX(MIQRsq z>SmC74hrdvq|wM*43Bo1Dvz*fTB@TUa;oC3LxLI|t3~N5DX;DfS>|XYHd*MflK&Pv ztBy$u`|GiEmIf@8X75CKyz+Z3_nEQBA(w2c!-`gX$-s5aytAJ$tGX`~zDg`` zfY3&9G{T-`x?a;HcN;L%F(-}nxJw&-HPT*hcrwn}q0Dgz=Q-Oe%`KcADYGc5{V8u~ zE9-LH{z6SR+zj8{FK`{>i_Df|id^*H><%urn3U#Ow!C61JnqxTE>3vk`TtrDww&Ce z8ZP6HAMQBdXxd9|)?@2DFXRZT9C7A$*F36`of8V$=b>|svFo|BeyHvy+gz*fU-MqN z)_cPqe7kSMsd|R6DsNNp&MMAt*leTzG3CHdUj6p-8Z4;L(Q|*g^_61p^ULG!>YDf2 zd)Rg6;ImKh`tLg(&GliY?>z3ZD-FQ^iEnuAd!F3#hd_PpZ+8XsA9tE}Kn2pOaApJA z_YzpS`@M>R^}C$=Hn=eDx$Sl&L>|$4N3v`A4Rj{t(bNz(LJu0wejqfS2rbpU8MbhO zD8yi}U_iFiU1oXHqF(v5!@mGdrg-w(T&~EL#1Jk~a`fw-%QQnpCOR7McUQ#W>Z;bn z*2QOxWGtf@&xpn}s&S2MY@-|B2*)_eagKDXqaE*v$2{tBk9_Q-AO8r*K#HIM06Q!B B)u#Xe diff --git a/QRCoderTests/Base64QRCodeRendererTests.cs b/QRCoderTests/Base64QRCodeRendererTests.cs index 36ef5e2e..4005f201 100644 --- a/QRCoderTests/Base64QRCodeRendererTests.cs +++ b/QRCoderTests/Base64QRCodeRendererTests.cs @@ -43,10 +43,15 @@ public void can_render_base64_qrcode_transparent() } [Fact] - public void can_render_base64_qrcode_jpeg() + public void can_render_base64_qrcode_jpeg_throws_exception() { - var base64QRCode = new Base64QRCode(_data).GetGraphic(5, Color.Black, Color.White, true, Base64QRCode.ImageType.Jpeg); - var data = Convert.FromBase64String(base64QRCode); - data.ShouldMatchApprovedImage(asMonochrome: true); // remove JPEG compression artifacts by converting to monochrome + var ex = Should.Throw(() => + { +#pragma warning disable CS0618 // Type or member is obsolete + var base64QRCode = new Base64QRCode(_data).GetGraphic(5, Color.Black, Color.White, true, Base64QRCode.ImageType.Jpeg); +#pragma warning restore CS0618 // Type or member is obsolete + }); + ex.Message.ShouldContain("Only PNG format is supported"); + ex.Message.ShouldContain("Jpeg"); } } diff --git a/QRCoderTests/QRCoderTests.csproj b/QRCoderTests/QRCoderTests.csproj index 55c46197..666210f9 100644 --- a/QRCoderTests/QRCoderTests.csproj +++ b/QRCoderTests/QRCoderTests.csproj @@ -40,7 +40,7 @@ - + diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.approved.svg b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.approved.svg deleted file mode 100644 index c0aa04cb..00000000 --- a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.approved.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.embeddedLogo.approved.gif b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap.embeddedLogo.approved.gif deleted file mode 100644 index 7b265b04d160f5eeaa3042f5c22c42a592460d66..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1410 zcmV-|1%3KQNk%w1VPpVg0Q4IGgEKGnuB-du-|%~P%uq}C!odFZ^zx63?Pp@IL_q6Y zR{6}z|NsA%J2&*Cpz(%*_qet0acuqT>bXcn+E!2c*46WwmcmR&pFTQ^H#7U;-~a#s z000000000000000A^sFgM|mJqPexQAM@dE?MQ&qnWMy&yA^8LW000{REC2ui0Av7U z000I5;3ke_X`X1Ru59bRa4gSs%>vj&P)e^*gb4;*^IQow0eQ-RrKDdnB*F@RZw3eGgld={3g zT&8rzE-SlN=&}WRn+;$Ktz@4RRS+k(t1NHhi=7=ftD6?3A1x>BK&z{P0l~Y=S~hzC zn?YU0&K3|tp&FWl1NR(QcxJ)ER0awLGtlssiG!&IcAL;ys9WfA)v zGt=8TwgX0WgK6dB=v4Wr=yf(R(* z6Be}@5S|?+0AR}%qTTnA6&c>w2N5H9bs-ax-Nzk?14?#BTq3A5Vh@x7WIzEYMgV~U z5NxEP9k^_u(2Gkb2cQBG6mX9K6&NsML{f3oM@S-217wjEQ~<$*d_C~MiT*%PWdIw( zG0O%(rs2RaVJ@OynP9}|OmmW~$)*z;2}xK11==(MBLi^R#{+{ckYY0uq$NRscaR_@ z9L5>2l^_2pQ$Pd=JaA?&2T&TRq<)O~V;>z2pg{p?rg6YC0u=Czm(bvM2b3GQXa{fz zAW%V2aDc|2T6gp)q8|_-RRFGNH2969cFtx8iyK&2$OF-dMeG+2m6Ou{rp^@h28eqW zqR|osX!}KN*BIacPtcV5#e0RQxmIQ7MMyN(72yM#a>uMZJ8iUqdcw1&;2XqbT0 zpZzQmfd&hx+n04tbqEboXedPjb&whW=K;4$AOMz*H8m(<5$I@*xL}Oet+)P0R#n0# zjf_>jV7zGi`awc6{<>X4#5GG-2}5*PhvM1 zH})AH-+qI#!ohqRaJSb5Xb>K`-XI=^#b;|WcoPm)u%WSSSq?_$LY{2y!vGR=-2=T^ zEzvg^ur5{lj3o^afVobvew6Ep_W*;ej1+l~(jfbwJ2v9Jjzy0mv3dM8$@eY;H$Xmr zGVfT36T_mdSPxC~SByDM_14w5y5BZnY>W5joNtB7G5~*y-sTbP1M@U+Z%PDj_wWDz zZ}Za+rZA^CZJ~gAVg&*d#fAmmOAih#7$Wo+LGkH9eh$Q6Ak-H@_*sI2FS4K|MnJs+ zYHx%nz+fvhh{6+mDi*P8AqyBc3e3q626WQ|;BGjBqcI|DJd{Eb`T&I>A_50GfCUhQ Qz%3&>@rh83Vh8{LJI?uVhyVZp diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.approved.svg b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.approved.svg deleted file mode 100644 index f87e9449..00000000 --- a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.approved.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.embeddedLogo.approved.gif b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_background.embeddedLogo.approved.gif deleted file mode 100644 index 7b265b04d160f5eeaa3042f5c22c42a592460d66..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1410 zcmV-|1%3KQNk%w1VPpVg0Q4IGgEKGnuB-du-|%~P%uq}C!odFZ^zx63?Pp@IL_q6Y zR{6}z|NsA%J2&*Cpz(%*_qet0acuqT>bXcn+E!2c*46WwmcmR&pFTQ^H#7U;-~a#s z000000000000000A^sFgM|mJqPexQAM@dE?MQ&qnWMy&yA^8LW000{REC2ui0Av7U z000I5;3ke_X`X1Ru59bRa4gSs%>vj&P)e^*gb4;*^IQow0eQ-RrKDdnB*F@RZw3eGgld={3g zT&8rzE-SlN=&}WRn+;$Ktz@4RRS+k(t1NHhi=7=ftD6?3A1x>BK&z{P0l~Y=S~hzC zn?YU0&K3|tp&FWl1NR(QcxJ)ER0awLGtlssiG!&IcAL;ys9WfA)v zGt=8TwgX0WgK6dB=v4Wr=yf(R(* z6Be}@5S|?+0AR}%qTTnA6&c>w2N5H9bs-ax-Nzk?14?#BTq3A5Vh@x7WIzEYMgV~U z5NxEP9k^_u(2Gkb2cQBG6mX9K6&NsML{f3oM@S-217wjEQ~<$*d_C~MiT*%PWdIw( zG0O%(rs2RaVJ@OynP9}|OmmW~$)*z;2}xK11==(MBLi^R#{+{ckYY0uq$NRscaR_@ z9L5>2l^_2pQ$Pd=JaA?&2T&TRq<)O~V;>z2pg{p?rg6YC0u=Czm(bvM2b3GQXa{fz zAW%V2aDc|2T6gp)q8|_-RRFGNH2969cFtx8iyK&2$OF-dMeG+2m6Ou{rp^@h28eqW zqR|osX!}KN*BIacPtcV5#e0RQxmIQ7MMyN(72yM#a>uMZJ8iUqdcw1&;2XqbT0 zpZzQmfd&hx+n04tbqEboXedPjb&whW=K;4$AOMz*H8m(<5$I@*xL}Oet+)P0R#n0# zjf_>jV7zGi`awc6{<>X4#5GG-2}5*PhvM1 zH})AH-+qI#!ohqRaJSb5Xb>K`-XI=^#b;|WcoPm)u%WSSSq?_$LY{2y!vGR=-2=T^ zEzvg^ur5{lj3o^afVobvew6Ep_W*;ej1+l~(jfbwJ2v9Jjzy0mv3dM8$@eY;H$Xmr zGVfT36T_mdSPxC~SByDM_14w5y5BZnY>W5joNtB7G5~*y-sTbP1M@U+Z%PDj_wWDz zZ}Za+rZA^CZJ~gAVg&*d#fAmmOAih#7$Wo+LGkH9eh$Q6Ak-H@_*sI2FS4K|MnJs+ zYHx%nz+fvhh{6+mDi*P8AqyBc3e3q626WQ|;BGjBqcI|DJd{Eb`T&I>A_50GfCUhQ Qz%3&>@rh83Vh8{LJI?uVhyVZp diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.approved.svg b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.approved.svg deleted file mode 100644 index 0c5196f7..00000000 --- a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.approved.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.embeddedLogo.approved.gif b/QRCoderTests/SvgQRCodeRendererTests.can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones.embeddedLogo.approved.gif deleted file mode 100644 index 7b265b04d160f5eeaa3042f5c22c42a592460d66..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1410 zcmV-|1%3KQNk%w1VPpVg0Q4IGgEKGnuB-du-|%~P%uq}C!odFZ^zx63?Pp@IL_q6Y zR{6}z|NsA%J2&*Cpz(%*_qet0acuqT>bXcn+E!2c*46WwmcmR&pFTQ^H#7U;-~a#s z000000000000000A^sFgM|mJqPexQAM@dE?MQ&qnWMy&yA^8LW000{REC2ui0Av7U z000I5;3ke_X`X1Ru59bRa4gSs%>vj&P)e^*gb4;*^IQow0eQ-RrKDdnB*F@RZw3eGgld={3g zT&8rzE-SlN=&}WRn+;$Ktz@4RRS+k(t1NHhi=7=ftD6?3A1x>BK&z{P0l~Y=S~hzC zn?YU0&K3|tp&FWl1NR(QcxJ)ER0awLGtlssiG!&IcAL;ys9WfA)v zGt=8TwgX0WgK6dB=v4Wr=yf(R(* z6Be}@5S|?+0AR}%qTTnA6&c>w2N5H9bs-ax-Nzk?14?#BTq3A5Vh@x7WIzEYMgV~U z5NxEP9k^_u(2Gkb2cQBG6mX9K6&NsML{f3oM@S-217wjEQ~<$*d_C~MiT*%PWdIw( zG0O%(rs2RaVJ@OynP9}|OmmW~$)*z;2}xK11==(MBLi^R#{+{ckYY0uq$NRscaR_@ z9L5>2l^_2pQ$Pd=JaA?&2T&TRq<)O~V;>z2pg{p?rg6YC0u=Czm(bvM2b3GQXa{fz zAW%V2aDc|2T6gp)q8|_-RRFGNH2969cFtx8iyK&2$OF-dMeG+2m6Ou{rp^@h28eqW zqR|osX!}KN*BIacPtcV5#e0RQxmIQ7MMyN(72yM#a>uMZJ8iUqdcw1&;2XqbT0 zpZzQmfd&hx+n04tbqEboXedPjb&whW=K;4$AOMz*H8m(<5$I@*xL}Oet+)P0R#n0# zjf_>jV7zGi`awc6{<>X4#5GG-2}5*PhvM1 zH})AH-+qI#!ohqRaJSb5Xb>K`-XI=^#b;|WcoPm)u%WSSSq?_$LY{2y!vGR=-2=T^ zEzvg^ur5{lj3o^afVobvew6Ep_W*;ej1+l~(jfbwJ2v9Jjzy0mv3dM8$@eY;H$Xmr zGVfT36T_mdSPxC~SByDM_14w5y5BZnY>W5joNtB7G5~*y-sTbP1M@U+Z%PDj_wWDz zZ}Za+rZA^CZJ~gAVg&*d#fAmmOAih#7$Wo+LGkH9eh$Q6Ak-H@_*sI2FS4K|MnJs+ zYHx%nz+fvhh{6+mDi*P8AqyBc3e3q626WQ|;BGjBqcI|DJd{Eb`T&I>A_50GfCUhQ Qz%3&>@rh83Vh8{LJI?uVhyVZp diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index cb8567ea..9e1b8f95 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -72,90 +72,6 @@ public void can_render_svg_qrcode_without_quietzones_hex() svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); } - [Fact] - public void can_render_svg_qrcode_with_png_logo_bitmap() - { - //Create QR code - var gen = new QRCodeGenerator(); - var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H); - - //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 - var logoBitmap = HelperFunctions.GetIconBitmap(); - var logoObj = new SvgQRCode.SvgLogo(iconRasterized: logoBitmap, 15); - logoObj.GetMediaType().ShouldBe(SvgQRCode.SvgLogo.MediaType.PNG); - - var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj); - - // remove PNG encoded bitmap from SVG and verify it separately (to avoid diffs due to different encoding settings of System.Drawing) - var regex = new Regex( - @"]*\bxlink:href\s*=\s*[""']data:[^;""']+;base64,([A-Za-z0-9+/=]+)[""']", - RegexOptions.IgnoreCase); - var match = regex.Match(svg); - if (!match.Success || match.Groups.Count < 2) - throw new InvalidOperationException("Could not find embedded image data in SVG output."); - var base64Data = match.Groups[1].Value; - var imageData = Convert.FromBase64String(base64Data); - imageData.ShouldMatchApprovedImage(discriminator: "embeddedLogo"); - svg = svg.Replace(base64Data, "=====BASE64DATA====="); - svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); - } - - [Fact] - public void can_render_svg_qrcode_with_png_logo_bitmap_without_background() - { - //Create QR code - var gen = new QRCodeGenerator(); - var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H); - - //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 - var logoBitmap = HelperFunctions.GetIconBitmap(); - var logoObj = new SvgQRCode.SvgLogo(iconRasterized: logoBitmap, 15, false); - logoObj.GetMediaType().ShouldBe(SvgQRCode.SvgLogo.MediaType.PNG); - - var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj); - - // remove PNG encoded bitmap from SVG and verify it separately (to avoid diffs due to different encoding settings of System.Drawing) - var regex = new Regex( - @"]*\bxlink:href\s*=\s*[""']data:[^;""']+;base64,([A-Za-z0-9+/=]+)[""']", - RegexOptions.IgnoreCase); - var match = regex.Match(svg); - if (!match.Success || match.Groups.Count < 2) - throw new InvalidOperationException("Could not find embedded image data in SVG output."); - var base64Data = match.Groups[1].Value; - var imageData = Convert.FromBase64String(base64Data); - imageData.ShouldMatchApprovedImage(discriminator: "embeddedLogo"); - svg = svg.Replace(base64Data, "=====BASE64DATA====="); - svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); - } - - [Fact] - public void can_render_svg_qrcode_with_png_logo_bitmap_without_quietzones() - { - //Create QR code - var gen = new QRCodeGenerator(); - var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H); - - //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 - var logoBitmap = HelperFunctions.GetIconBitmap(); - var logoObj = new SvgQRCode.SvgLogo(iconRasterized: logoBitmap, 15); - logoObj.GetMediaType().ShouldBe(SvgQRCode.SvgLogo.MediaType.PNG); - - var svg = new SvgQRCode(data).GetGraphic(10, Color.Black, Color.White, drawQuietZones: false, logo: logoObj); - - // remove PNG encoded bitmap from SVG and verify it separately (to avoid diffs due to different encoding settings of System.Drawing) - var regex = new Regex( - @"]*\bxlink:href\s*=\s*[""']data:[^;""']+;base64,([A-Za-z0-9+/=]+)[""']", - RegexOptions.IgnoreCase); - var match = regex.Match(svg); - if (!match.Success || match.Groups.Count < 2) - throw new InvalidOperationException("Could not find embedded image data in SVG output."); - var base64Data = match.Groups[1].Value; - var imageData = Convert.FromBase64String(base64Data); - imageData.ShouldMatchApprovedImage(discriminator: "embeddedLogo"); - svg = svg.Replace(base64Data, "=====BASE64DATA====="); - svg.ShouldMatchApproved(x => x.NoDiff().WithFileExtension("svg")); - } - [Fact] public void can_render_svg_qrcode_with_png_logo_bytearray() { From 3dab0820475a9fd24a6e92decd8cd2dd75552e83 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 21:41:11 -0400 Subject: [PATCH 14/32] update --- QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj b/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj index 4bb5d916..0e24d459 100644 --- a/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj +++ b/QRCoder.SystemDrawing/QRCoder.SystemDrawing.csproj @@ -11,7 +11,7 @@ QRCoder is a simple library, written in C#.NET, which enables you to create QR codes. - QRCoderStrongName.snk + ../QRCoder/QRCoderStrongName.snk From 2db52d0fd70fd3b81278724751c9728cf9185850 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 21:58:54 -0400 Subject: [PATCH 15/32] Add additional color names with alternative spellings to ColorTranslator --- QRCoder/Extensions/ColorTranslator.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/QRCoder/Extensions/ColorTranslator.cs b/QRCoder/Extensions/ColorTranslator.cs index ac7d624a..daeaceb7 100644 --- a/QRCoder/Extensions/ColorTranslator.cs +++ b/QRCoder/Extensions/ColorTranslator.cs @@ -38,6 +38,7 @@ internal static class ColorTranslator { "DarkCyan", System.Drawing.Color.FromArgb(255, 0, 139, 139) }, { "DarkGoldenrod", System.Drawing.Color.FromArgb(255, 184, 134, 11) }, { "DarkGray", System.Drawing.Color.FromArgb(255, 169, 169, 169) }, + { "DarkGrey", System.Drawing.Color.FromArgb(255, 169, 169, 169) }, { "DarkGreen", System.Drawing.Color.FromArgb(255, 0, 100, 0) }, { "DarkKhaki", System.Drawing.Color.FromArgb(255, 189, 183, 107) }, { "DarkMagenta", System.Drawing.Color.FromArgb(255, 139, 0, 139) }, @@ -49,11 +50,13 @@ internal static class ColorTranslator { "DarkSeaGreen", System.Drawing.Color.FromArgb(255, 143, 188, 143) }, { "DarkSlateBlue", System.Drawing.Color.FromArgb(255, 72, 61, 139) }, { "DarkSlateGray", System.Drawing.Color.FromArgb(255, 47, 79, 79) }, + { "DarkSlateGrey", System.Drawing.Color.FromArgb(255, 47, 79, 79) }, { "DarkTurquoise", System.Drawing.Color.FromArgb(255, 0, 206, 209) }, { "DarkViolet", System.Drawing.Color.FromArgb(255, 148, 0, 211) }, { "DeepPink", System.Drawing.Color.FromArgb(255, 255, 20, 147) }, { "DeepSkyBlue", System.Drawing.Color.FromArgb(255, 0, 191, 255) }, { "DimGray", System.Drawing.Color.FromArgb(255, 105, 105, 105) }, + { "DimGrey", System.Drawing.Color.FromArgb(255, 105, 105, 105) }, { "DodgerBlue", System.Drawing.Color.FromArgb(255, 30, 144, 255) }, { "Firebrick", System.Drawing.Color.FromArgb(255, 178, 34, 34) }, { "FloralWhite", System.Drawing.Color.FromArgb(255, 255, 250, 240) }, @@ -64,6 +67,7 @@ internal static class ColorTranslator { "Gold", System.Drawing.Color.FromArgb(255, 255, 215, 0) }, { "Goldenrod", System.Drawing.Color.FromArgb(255, 218, 165, 32) }, { "Gray", System.Drawing.Color.FromArgb(255, 128, 128, 128) }, + { "Grey", System.Drawing.Color.FromArgb(255, 128, 128, 128) }, { "Green", System.Drawing.Color.FromArgb(255, 0, 128, 0) }, { "GreenYellow", System.Drawing.Color.FromArgb(255, 173, 255, 47) }, { "Honeydew", System.Drawing.Color.FromArgb(255, 240, 255, 240) }, @@ -81,12 +85,14 @@ internal static class ColorTranslator { "LightCyan", System.Drawing.Color.FromArgb(255, 224, 255, 255) }, { "LightGoldenrodYellow", System.Drawing.Color.FromArgb(255, 250, 250, 210) }, { "LightGray", System.Drawing.Color.FromArgb(255, 211, 211, 211) }, + { "LightGrey", System.Drawing.Color.FromArgb(255, 211, 211, 211) }, { "LightGreen", System.Drawing.Color.FromArgb(255, 144, 238, 144) }, { "LightPink", System.Drawing.Color.FromArgb(255, 255, 182, 193) }, { "LightSalmon", System.Drawing.Color.FromArgb(255, 255, 160, 122) }, { "LightSeaGreen", System.Drawing.Color.FromArgb(255, 32, 178, 170) }, { "LightSkyBlue", System.Drawing.Color.FromArgb(255, 135, 206, 250) }, { "LightSlateGray", System.Drawing.Color.FromArgb(255, 119, 136, 153) }, + { "LightSlateGrey", System.Drawing.Color.FromArgb(255, 119, 136, 153) }, { "LightSteelBlue", System.Drawing.Color.FromArgb(255, 176, 196, 222) }, { "LightYellow", System.Drawing.Color.FromArgb(255, 255, 255, 224) }, { "Lime", System.Drawing.Color.FromArgb(255, 0, 255, 0) }, @@ -126,6 +132,7 @@ internal static class ColorTranslator { "Plum", System.Drawing.Color.FromArgb(255, 221, 160, 221) }, { "PowderBlue", System.Drawing.Color.FromArgb(255, 176, 224, 230) }, { "Purple", System.Drawing.Color.FromArgb(255, 128, 0, 128) }, + { "RebeccaPurple", System.Drawing.Color.FromArgb(255, 102, 51, 153) }, { "Red", System.Drawing.Color.FromArgb(255, 255, 0, 0) }, { "RosyBrown", System.Drawing.Color.FromArgb(255, 188, 143, 143) }, { "RoyalBlue", System.Drawing.Color.FromArgb(255, 65, 105, 225) }, @@ -139,6 +146,7 @@ internal static class ColorTranslator { "SkyBlue", System.Drawing.Color.FromArgb(255, 135, 206, 235) }, { "SlateBlue", System.Drawing.Color.FromArgb(255, 106, 90, 205) }, { "SlateGray", System.Drawing.Color.FromArgb(255, 112, 128, 144) }, + { "SlateGrey", System.Drawing.Color.FromArgb(255, 112, 128, 144) }, { "Snow", System.Drawing.Color.FromArgb(255, 255, 250, 250) }, { "SpringGreen", System.Drawing.Color.FromArgb(255, 0, 255, 127) }, { "SteelBlue", System.Drawing.Color.FromArgb(255, 70, 130, 180) }, From 7070bcc8fbc478ccafe0bbcf33cbbe7fc475f51f Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:01:55 -0400 Subject: [PATCH 16/32] Add documentation for known HTML color names in ColorTranslator --- QRCoder/Extensions/ColorTranslator.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QRCoder/Extensions/ColorTranslator.cs b/QRCoder/Extensions/ColorTranslator.cs index daeaceb7..54d59389 100644 --- a/QRCoder/Extensions/ColorTranslator.cs +++ b/QRCoder/Extensions/ColorTranslator.cs @@ -10,6 +10,8 @@ internal static class ColorTranslator { /// /// Dictionary of known HTML color names mapped to their RGB values. + /// This list matches the CSS named colors as documented at: + /// https://developer.mozilla.org/en-US/docs/Web/CSS/named-color /// private static readonly Dictionary _knownColors = new Dictionary(StringComparer.OrdinalIgnoreCase) { From 1f7fcb499f2009a8f44778a9a077d34c10c2054d Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:23:41 -0400 Subject: [PATCH 17/32] Refactor GetGraphic method to simplify color handling logic --- QRCoder/Base64QRCode.cs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index b7e39019..87942245 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -69,29 +69,7 @@ public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string li public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) { var pngCoder = new PngByteQRCode(QrCodeData); - - byte[] pngData; - if (darkColor == Color.Black && lightColor == Color.White) - { - pngData = pngCoder.GetGraphic(pixelsPerModule, drawQuietZones); - } - else - { - byte[] darkColorBytes; - byte[] lightColorBytes; - if (darkColor.A != 255 || lightColor.A != 255) - { - darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B, darkColor.A }; - lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B, lightColor.A }; - } - else - { - darkColorBytes = new byte[] { darkColor.R, darkColor.G, darkColor.B }; - lightColorBytes = new byte[] { lightColor.R, lightColor.G, lightColor.B }; - } - pngData = pngCoder.GetGraphic(pixelsPerModule, darkColorBytes, lightColorBytes, drawQuietZones); - } - + var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); return Convert.ToBase64String(pngData, Base64FormattingOptions.None); } From 40d3e4fdd652a1ea491e3155fd4ff104f0e1b95f Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:28:22 -0400 Subject: [PATCH 18/32] Refactor GetGraphic method overloads to improve color handling and maintain consistency --- QRCoder/Base64QRCode.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 87942245..7c2d33fd 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -58,21 +58,6 @@ public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string li public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones, ImageType imgType) => GetGraphic(pixelsPerModule, ColorTranslator.FromHtml(darkColorHtmlHex), ColorTranslator.FromHtml(lightColorHtmlHex), drawQuietZones, imgType); - /// - /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. - /// - /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. - /// The color of the dark modules. - /// The color of the light modules. - /// Indicates if quiet zones around the QR code should be drawn. - /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) - { - var pngCoder = new PngByteQRCode(QrCodeData); - var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); - return Convert.ToBase64String(pngData, Base64FormattingOptions.None); - } - /// /// Returns a base64-encoded string that contains the resulting QR code as an image. /// @@ -93,6 +78,21 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, return GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); } + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules. + /// The color of the light modules. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) + { + var pngCoder = new PngByteQRCode(QrCodeData); + var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); + return Convert.ToBase64String(pngData, Base64FormattingOptions.None); + } + /// /// Specifies the type of image to generate. /// From 2336548cb0d9c26d26bf39f7ef8c02708241a081 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:29:35 -0400 Subject: [PATCH 19/32] Refactor GetGraphic method to enhance functionality and remove redundancy --- QRCoder/Base64QRCode.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 7c2d33fd..a7ae3d55 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -34,6 +34,21 @@ public Base64QRCode(QRCodeData data) : base(data) public string GetGraphic(int pixelsPerModule) => GetGraphic(pixelsPerModule, Color.Black, Color.White, true); + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules. + /// The color of the light modules. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) + { + var pngCoder = new PngByteQRCode(QrCodeData); + var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); + return Convert.ToBase64String(pngData, Base64FormattingOptions.None); + } + /// /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. /// @@ -78,21 +93,6 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, return GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); } - /// - /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. - /// - /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. - /// The color of the dark modules. - /// The color of the light modules. - /// Indicates if quiet zones around the QR code should be drawn. - /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) - { - var pngCoder = new PngByteQRCode(QrCodeData); - var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); - return Convert.ToBase64String(pngData, Base64FormattingOptions.None); - } - /// /// Specifies the type of image to generate. /// From 6f82b7cbdaf0d27305d06fb9bd1ccef1b31a4d36 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:30:42 -0400 Subject: [PATCH 20/32] Refactor GetGraphic method to improve clarity and maintain consistency in overloads --- QRCoder/Base64QRCode.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index a7ae3d55..0b63e3e4 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -26,14 +26,6 @@ public Base64QRCode(QRCodeData data) : base(data) { } - /// - /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. - /// - /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. - /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule) - => GetGraphic(pixelsPerModule, Color.Black, Color.White, true); - /// /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. /// @@ -49,6 +41,14 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, return Convert.ToBase64String(pngData, Base64FormattingOptions.None); } + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule) + => GetGraphic(pixelsPerModule, Color.Black, Color.White, true); + /// /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. /// From 593c44c272a35950061a09d2c53ccdac55bbe7bb Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:31:20 -0400 Subject: [PATCH 21/32] Refactor GetGraphic method to restore and enhance overload with color parameters for improved flexibility --- QRCoder/Base64QRCode.cs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 0b63e3e4..dcf113aa 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -26,21 +26,6 @@ public Base64QRCode(QRCodeData data) : base(data) { } - /// - /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. - /// - /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. - /// The color of the dark modules. - /// The color of the light modules. - /// Indicates if quiet zones around the QR code should be drawn. - /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) - { - var pngCoder = new PngByteQRCode(QrCodeData); - var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); - return Convert.ToBase64String(pngData, Base64FormattingOptions.None); - } - /// /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. /// @@ -113,6 +98,20 @@ public enum ImageType Png } + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules. + /// The color of the light modules. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) + { + var pngCoder = new PngByteQRCode(QrCodeData); + var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); + return Convert.ToBase64String(pngData, Base64FormattingOptions.None); + } } /// From 62f6ddd236d4cc557232d5badd3e9d464db31599 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:33:57 -0400 Subject: [PATCH 22/32] Refactor GetGraphic method to add overload for enhanced color customization and maintain consistency --- QRCoder/Base64QRCode.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index dcf113aa..79eb6cf3 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -78,6 +78,21 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, return GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); } + /// + /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. + /// + /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. + /// The color of the dark modules. + /// The color of the light modules. + /// Indicates if quiet zones around the QR code should be drawn. + /// Returns the QR code graphic as a base64-encoded string. + public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) + { + var pngCoder = new PngByteQRCode(QrCodeData); + var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); + return Convert.ToBase64String(pngData, Base64FormattingOptions.None); + } + /// /// Specifies the type of image to generate. /// @@ -97,21 +112,6 @@ public enum ImageType /// Png } - - /// - /// Returns a base64-encoded string that contains the resulting QR code as a PNG image. - /// - /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. - /// The color of the dark modules. - /// The color of the light modules. - /// Indicates if quiet zones around the QR code should be drawn. - /// Returns the QR code graphic as a base64-encoded string. - public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) - { - var pngCoder = new PngByteQRCode(QrCodeData); - var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); - return Convert.ToBase64String(pngData, Base64FormattingOptions.None); - } } /// From ec94c43d676730b42e202fd5c66e04ff160c89b0 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 22:57:00 -0400 Subject: [PATCH 23/32] Update --- QRCoder/PngByteQRCode.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/QRCoder/PngByteQRCode.cs b/QRCoder/PngByteQRCode.cs index 7f113e69..0645750c 100644 --- a/QRCoder/PngByteQRCode.cs +++ b/QRCoder/PngByteQRCode.cs @@ -51,7 +51,9 @@ public byte[] GetGraphic(int pixelsPerModule, bool drawQuietZones = true) /// Indicates if quiet zones around the QR code should be drawn. /// Returns the QR code graphic as a PNG byte array. public byte[] GetGraphic(int pixelsPerModule, System.Drawing.Color darkColor, System.Drawing.Color lightColor, bool drawQuietZones = true) - => GetGraphic(pixelsPerModule, new byte[] { darkColor.R, darkColor.G, darkColor.B, darkColor.A }, new byte[] { lightColor.R, lightColor.G, lightColor.B, lightColor.A }, drawQuietZones); + => darkColor == System.Drawing.Color.Black && lightColor == System.Drawing.Color.White + ? GetGraphic(pixelsPerModule, drawQuietZones) + : GetGraphic(pixelsPerModule, [darkColor.R, darkColor.G, darkColor.B, darkColor.A], [lightColor.R, lightColor.G, lightColor.B, lightColor.A], drawQuietZones); /// /// Creates a 2-color PNG of the QR code, using 1-bit indexed color. Accepts 3-byte RGB colors for normal images and 4-byte RGBA-colors for transparent images. From 252d8dd9a74e6924ea1f3371b801dc0840b212cf Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 23:18:03 -0400 Subject: [PATCH 24/32] Update cross-platform support information in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8311b128..3e20e029 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ QRCoder is a simple C# library originally created by [Raffael Herrmann](https:// - 🎨 **Multiple output formats** - PNG, SVG, PDF, ASCII, Bitmap, PostScript, and more - 📱 **23+ payload generators** - WiFi, vCard, URLs, payments, and many more - 🔧 **Highly configurable** - Error correction levels, custom colors, logos, and styling -- 🌐 **Cross-platform** - Supports .NET 5+, .NET Framework 3.5+, .NET Core 1.0+, and .NET Standard 1.3+ +- 🌐 **Cross-platform** - Supports .NET Standard 2.0+ and any compatible frameworks - 📦 **Micro QR codes** - Smaller QR codes for space-constrained applications ## 📦 Installation From 68880f5750548a9ee4dd960d39e851a8fab232ea Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 23:40:22 -0400 Subject: [PATCH 25/32] Add migration guide for QRCoder v2 with new features and breaking changes --- docs/migrations/migration2.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/migrations/migration2.md diff --git a/docs/migrations/migration2.md b/docs/migrations/migration2.md new file mode 100644 index 00000000..0612a9a5 --- /dev/null +++ b/docs/migrations/migration2.md @@ -0,0 +1,17 @@ +# Migration Guide: QRCoder v2 + +This guide helps you migrate from QRCoder v1.x to v2.x. + +## New Features + +_Coming soon - this section will be populated as new features are added to v2._ + +## Breaking Changes + +### Minimum framework version is now .NET Standard 2.0 + +Upgrade your project to one of the following frameworks if required: + +- .NET Framework 4.6.2 or higher +- .NET Core 2.0 or higher +- .NET 5 or higher From 564826a778d144caf626a7471bb7bf6645182e9c Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 18 Oct 2025 23:44:00 -0400 Subject: [PATCH 26/32] Add migration guide for QRCoder v2 and update README.md --- README.md | 1 + docs/migrations/migration2.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/migrations/migration2.md diff --git a/README.md b/README.md index 3e20e029..e40b560e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ QRCoder is a simple C# library originally created by [Raffael Herrmann](https:// - 📚 [Documentation & Wiki](https://github.com/Shane32/QRCoder/wiki) - 📋 [Release notes / Changelog](https://github.com/Shane32/QRCoder/releases) - 🚀 [Upcoming features](https://github.com/Shane32/QRCoder/milestones) +- 🔄 [Migration guide for v2](https://github.com/Shane32/QRCoder/blob/master/docs/migrations/migration2.md) ## ✨ Features diff --git a/docs/migrations/migration2.md b/docs/migrations/migration2.md new file mode 100644 index 00000000..0612a9a5 --- /dev/null +++ b/docs/migrations/migration2.md @@ -0,0 +1,17 @@ +# Migration Guide: QRCoder v2 + +This guide helps you migrate from QRCoder v1.x to v2.x. + +## New Features + +_Coming soon - this section will be populated as new features are added to v2._ + +## Breaking Changes + +### Minimum framework version is now .NET Standard 2.0 + +Upgrade your project to one of the following frameworks if required: + +- .NET Framework 4.6.2 or higher +- .NET Core 2.0 or higher +- .NET 5 or higher From 695ab8bae5864f5d227b1b9152ee80a8953a2e65 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sun, 19 Oct 2025 00:04:55 -0400 Subject: [PATCH 27/32] Update project references and enhance migration documentation for QRCoder v2 --- QRCoderSamples/MigrationSamples.cs | 54 ++++++++++++++++++++++++++++ QRCoderSamples/QRCoderSamples.csproj | 2 +- README.md | 7 ++-- docs/migrations/migration2.md | 52 ++++++++++++++++++++++++++- 4 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 QRCoderSamples/MigrationSamples.cs diff --git a/QRCoderSamples/MigrationSamples.cs b/QRCoderSamples/MigrationSamples.cs new file mode 100644 index 00000000..4c38d2c6 --- /dev/null +++ b/QRCoderSamples/MigrationSamples.cs @@ -0,0 +1,54 @@ +using QRCoder; +using System.Drawing.Imaging; + +namespace QRCoderSamples; + +public static class MigrationSamples +{ + /// + /// Example showing how to convert a QR code to base64 with a custom image format (e.g., JPEG). + /// This is useful when migrating from Base64QRCode which previously supported multiple image formats. + /// + public static string ConvertQRCodeToBase64Jpeg() + { + // Generate QR code data + using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q); + + // Use QRCode renderer to get a bitmap + using var qrCode = new QRCode(qrCodeData); + using var bitmap = qrCode.GetGraphic(20); + + // Convert bitmap to JPEG byte array + using var ms = new MemoryStream(); + bitmap.Save(ms, ImageFormat.Jpeg); + byte[] jpegBytes = ms.ToArray(); + + // Convert to base64 + string base64String = Convert.ToBase64String(jpegBytes); + + return base64String; + } + + /// + /// Example showing how to convert a Bitmap to PNG byte array for use with SvgQRCode logos. + /// SvgQRCode logos now require PNG-encoded byte arrays or SVG strings instead of Bitmap instances. + /// + public static string ConvertBitmapToSvgQRCodeWithLogo() + { + // Convert a Bitmap to PNG byte array + using var bitmap = new System.Drawing.Bitmap("logo.jpg"); + using var ms = new MemoryStream(); + bitmap.Save(ms, ImageFormat.Png); + byte[] pngBytes = ms.ToArray(); + + // Create SvgLogo with PNG byte array + var logo = new SvgQRCode.SvgLogo(pngBytes, iconSizePercent: 15); + + // Generate QR code with logo + using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q); + using var qrCode = new SvgQRCode(qrCodeData); + string svg = qrCode.GetGraphic(20, "#000000", "#ffffff", true, SvgQRCode.SizingMode.WidthHeightAttribute, logo); + + return svg; + } +} diff --git a/QRCoderSamples/QRCoderSamples.csproj b/QRCoderSamples/QRCoderSamples.csproj index f1c88569..4a7d296a 100644 --- a/QRCoderSamples/QRCoderSamples.csproj +++ b/QRCoderSamples/QRCoderSamples.csproj @@ -6,7 +6,7 @@ - + diff --git a/README.md b/README.md index e40b560e..08122b84 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ QRCoder provides multiple renderers for different output formats and use cases. |----------|---------------|----------|---------------| | [**PngByteQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#25-pngbyteqrcode-renderer-in-detail) | PNG byte array | — | `new PngByteQRCode(data).GetGraphic(20)` | | [**SvgQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#26-svgqrcode-renderer-in-detail) | SVG string | — | `new SvgQRCode(data).GetGraphic(20)` | -| [**QRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#21-qrcode-renderer-in-detail) | System.Drawing.Bitmap | Windows¹ | `new QRCode(data).GetGraphic(20)` | -| [**ArtQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#211-artqrcode-renderer-in-detail) | Artistic bitmap with custom images | Windows¹ | `new ArtQRCode(data).GetGraphic(20)` | +| [**QRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#21-qrcode-renderer-in-detail) | System.Drawing.Bitmap | SystemDrawing¹ | `new QRCode(data).GetGraphic(20)` | +| [**ArtQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#211-artqrcode-renderer-in-detail) | Artistic bitmap with custom images | SystemDrawing¹ | `new ArtQRCode(data).GetGraphic(20)` | | [**AsciiQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#22-asciiqrcode-renderer-in-detail) | ASCII art string | — | `new AsciiQRCode(data).GetGraphic(1)` or `new AsciiQRCode(data).GetGraphicSmall()` | | [**Base64QRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#23-base64qrcode-renderer-in-detail) | Base64 encoded image | — | `new Base64QRCode(data).GetGraphic(20)` | | [**BitmapByteQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#24-bitmapbyteqrcode-renderer-in-detail) | BMP byte array | — | `new BitmapByteQRCode(data).GetGraphic(20)` | @@ -121,7 +121,8 @@ QRCoder provides multiple renderers for different output formats and use cases. | [**UnityQRCode**](https://github.com/Shane32/QRCoder/wiki/Advanced-usage---QR-Code-renderers#27-unityqrcode-renderer-in-detail) | Unity Texture2D | Unity³ | `new UnityQRCode(data).GetGraphic(20)` | **Notes:** -- ¹ Requires Windows or System.Drawing.Common package (uses GDI+) + +- ¹ Requires the [QRCoder.SystemDrawing](https://www.nuget.org/packages/QRCoder.SystemDrawing) package (Windows or System.Drawing.Common, uses GDI+) - ² Requires the [QRCoder.Xaml](https://www.nuget.org/packages/QRCoder.Xaml) package - ³ Requires the [QRCoder.Unity](https://www.nuget.org/packages/QRCoder.Unity) package diff --git a/docs/migrations/migration2.md b/docs/migrations/migration2.md index 0612a9a5..29e06570 100644 --- a/docs/migrations/migration2.md +++ b/docs/migrations/migration2.md @@ -8,10 +8,60 @@ _Coming soon - this section will be populated as new features are added to v2._ ## Breaking Changes -### Minimum framework version is now .NET Standard 2.0 +### 1. Minimum framework version is now .NET Standard 2.0 Upgrade your project to one of the following frameworks if required: - .NET Framework 4.6.2 or higher - .NET Core 2.0 or higher - .NET 5 or higher + +### 2. QRCode and ArtQRCode moved to separate package + +The QRCode and ArtQRCode renderers have been moved to the [QRCoder.SystemDrawing](https://www.nuget.org/packages/QRCoder.SystemDrawing) NuGet package. + +### 3. Base64QRCode only supports PNG format + +Base64QRCode now only supports PNG format. To use other image formats, use a different renderer and convert to base64: + +```csharp +using QRCoder; + +// Generate QR code data +using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q); + +// Use QRCode renderer to get a bitmap +using var qrCode = new QRCode(qrCodeData); +using var bitmap = qrCode.GetGraphic(20); + +// Convert bitmap to JPEG byte array +using var ms = new MemoryStream(); +bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); +byte[] jpegBytes = ms.ToArray(); + +// Convert to base64 +string base64String = Convert.ToBase64String(jpegBytes); +``` + +### 4. SvgQRCode logos must be PNG byte arrays or SVG strings + +SvgQRCode logos now require PNG-encoded byte arrays or SVG strings instead of Bitmap instances. Use the SvgLogo constructor with either a byte array for PNG images or a string for SVG content. + +```csharp +using QRCoder; +using System.Drawing.Imaging; + +// Convert a Bitmap to PNG byte array +using var bitmap = new Bitmap("logo.jpg"); +using var ms = new MemoryStream(); +bitmap.Save(ms, ImageFormat.Png); +byte[] pngBytes = ms.ToArray(); + +// Create SvgLogo with PNG byte array +var logo = new SvgQRCode.SvgLogo(pngBytes, iconSizePercent: 15); + +// Generate QR code with logo +using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q); +using var qrCode = new SvgQRCode(qrCodeData); +string svg = qrCode.GetGraphic(20, "#000000", "#ffffff", true, SvgQRCode.SizingMode.WidthHeightAttribute, logo); +``` From 18c2f7778bc6d30350d6f1fcacd0676bcd22cd08 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sun, 19 Oct 2025 00:08:49 -0400 Subject: [PATCH 28/32] fix usings --- QRCoderSamples/MigrationSamples.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoderSamples/MigrationSamples.cs b/QRCoderSamples/MigrationSamples.cs index 4c38d2c6..c3996ab5 100644 --- a/QRCoderSamples/MigrationSamples.cs +++ b/QRCoderSamples/MigrationSamples.cs @@ -1,5 +1,5 @@ -using QRCoder; using System.Drawing.Imaging; +using QRCoder; namespace QRCoderSamples; From 5cf388d36e9dcc67b75bb68bd85a6f85b5481590 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sun, 19 Oct 2025 00:10:04 -0400 Subject: [PATCH 29/32] update --- QRCoder/Base64QRCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 79eb6cf3..205f9419 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -88,7 +88,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, /// Returns the QR code graphic as a base64-encoded string. public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true) { - var pngCoder = new PngByteQRCode(QrCodeData); + using var pngCoder = new PngByteQRCode(QrCodeData); var pngData = pngCoder.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones); return Convert.ToBase64String(pngData, Base64FormattingOptions.None); } From f6d19cd942dbae3444f1ea25ef41b1e18fb4d7ce Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 25 Oct 2025 18:38:55 -0400 Subject: [PATCH 30/32] Update QRCoder/Base64QRCode.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Günther Foidl --- QRCoder/Base64QRCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder/Base64QRCode.cs b/QRCoder/Base64QRCode.cs index 205f9419..4757311e 100644 --- a/QRCoder/Base64QRCode.cs +++ b/QRCoder/Base64QRCode.cs @@ -120,7 +120,7 @@ public enum ImageType public static class Base64QRCodeHelper { /// - /// Creates a base64-encoded QR code with a single function call. + /// Creates a base64-encoded QR code as a one-shot operation. /// /// The text or payload to be encoded inside the QR code. /// The number of pixels each dark/light module of the QR code will occupy in the final QR code image. From d8b1b589483e58dd31d1dbfdedf55a5c9f668e89 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 25 Oct 2025 19:40:35 -0400 Subject: [PATCH 31/32] Use ReadOnlySpan --- QRCoder/PdfByteQRCode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoder/PdfByteQRCode.cs b/QRCoder/PdfByteQRCode.cs index 130ceb97..25a2c87b 100644 --- a/QRCoder/PdfByteQRCode.cs +++ b/QRCoder/PdfByteQRCode.cs @@ -9,7 +9,7 @@ namespace QRCoder; /// public class PdfByteQRCode : AbstractQRCode, IDisposable { - private readonly byte[] _pdfBinaryComment = new byte[] { 0x25, 0xe2, 0xe3, 0xcf, 0xd3 }; + private static ReadOnlySpan _pdfBinaryComment => [0x25, 0xe2, 0xe3, 0xcf, 0xd3]; /// /// Initializes a new instance of the class. @@ -63,7 +63,7 @@ public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string li writer.Flush(); // Binary comment - ensures PDF is treated as binary file (prevents text mode corruption) - stream.Write(_pdfBinaryComment, 0, _pdfBinaryComment.Length); + stream.Write(_pdfBinaryComment); writer.WriteLine(); writer.Flush(); From e1cbf15b33a05529d72115317b9a43cc8567fdc2 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sat, 25 Oct 2025 19:48:53 -0400 Subject: [PATCH 32/32] Add newlines --- QRCoderConsole/QRCoderConsole.csproj | 2 +- QRCoderDemo/QRCoderDemo.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoderConsole/QRCoderConsole.csproj b/QRCoderConsole/QRCoderConsole.csproj index cab34dcb..19f1ca0e 100644 --- a/QRCoderConsole/QRCoderConsole.csproj +++ b/QRCoderConsole/QRCoderConsole.csproj @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/QRCoderDemo/QRCoderDemo.csproj b/QRCoderDemo/QRCoderDemo.csproj index f2bfcfd3..13ba6368 100644 --- a/QRCoderDemo/QRCoderDemo.csproj +++ b/QRCoderDemo/QRCoderDemo.csproj @@ -20,4 +20,4 @@ - \ No newline at end of file +