From 0d4984f21616cba9034b1831043d69f57ae1ed06 Mon Sep 17 00:00:00 2001 From: Anselmo Schaefler Date: Fri, 4 Feb 2022 10:18:21 -0400 Subject: [PATCH 1/7] Added GetGraphicSmall to ASCIIQRCode. Credits for qrcode-terminal. --- QRCoder/ASCIIQRCode.cs | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index bffe7cd0..ed753af8 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -62,6 +62,51 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString } return qrCode.ToArray(); } + + /// + /// Returns a strings that contains the resulting QR code as ASCII chars. + /// + /// + public string GetGraphicSmall() + { + string endOfLine = "\n"; + bool BLACK = true, WHITE = false; + + var platte = new + { + WHITE_ALL = "\u2588", + WHITE_BLACK = "\u2580", + BLACK_WHITE = "\u2584", + BLACK_ALL = " ", + }; + + var moduleData = QrCodeData.ModuleMatrix; + var lineBuilder = new StringBuilder(); + for (var row = 0; row < moduleData.Count; row += 2) + { + for (var col = 0; col < moduleData.Count; col++) + { + try + { + if (moduleData[col][row] == WHITE && moduleData[col][row + 1] == WHITE) + lineBuilder.Append(platte.WHITE_ALL); + else if (moduleData[col][row] == WHITE && moduleData[col][row + 1] == BLACK) + lineBuilder.Append(platte.WHITE_BLACK); + else if (moduleData[col][row] == BLACK && moduleData[col][row + 1] == WHITE) + lineBuilder.Append(platte.BLACK_WHITE); + else + lineBuilder.Append(platte.BLACK_ALL); + } + catch (Exception) + { + lineBuilder.Append(platte.WHITE_BLACK); + } + + } + lineBuilder.Append(endOfLine); + } + return lineBuilder.ToString(); + } } From e91953e886eabd64d0168714d8af793a41758289 Mon Sep 17 00:00:00 2001 From: Anselmo Schaefler Date: Fri, 4 Feb 2022 10:18:21 -0400 Subject: [PATCH 2/7] Added GetGraphicSmall to ASCIIQRCode. Credits for qrcode-terminal. --- QRCoder/ASCIIQRCode.cs | 55 ++++++++++++++++++++++++ QRCoderTests/AsciiQRCodeRendererTests.cs | 14 ++++++ 2 files changed, 69 insertions(+) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index bffe7cd0..8649da7b 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -62,6 +62,61 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString } return qrCode.ToArray(); } + + /// + /// Returns a strings that contains the resulting QR code as ASCII chars. + /// + /// + public string GetGraphicSmall(bool drawQuietZones = true) + { + string endOfLine = "\n"; + bool BLACK = true, WHITE = false; + + var platte = new + { + WHITE_ALL = "\u2588", + WHITE_BLACK = "\u2580", + BLACK_WHITE = "\u2584", + BLACK_ALL = " ", + }; + + var moduleData = QrCodeData.ModuleMatrix; + var lineBuilder = new StringBuilder(); + + var quietZonesModifier = (drawQuietZones ? 4 : 8); + var quietZonesOffset = (int)(quietZonesModifier * 0.5); + var sideLength = (QrCodeData.ModuleMatrix.Count - quietZonesModifier); + + for (var row = 0; row < sideLength; row = row + 2) + { + for (var col = 0; col < moduleData.Count - quietZonesModifier; col++) + { + try + { + var current = moduleData[col + quietZonesOffset][row + quietZonesOffset]; + var next = moduleData[col + quietZonesOffset][(row + 1) + quietZonesOffset]; + if (current == WHITE && next == WHITE) + lineBuilder.Append(platte.WHITE_ALL); + else if (current == WHITE && next == BLACK) + lineBuilder.Append(platte.WHITE_BLACK); + else if (current == BLACK && next == WHITE) + lineBuilder.Append(platte.BLACK_WHITE); + else + lineBuilder.Append(platte.BLACK_ALL); + } + catch (Exception) + { + if (drawQuietZones) + lineBuilder.Append(platte.WHITE_BLACK); + else + lineBuilder.Append(platte.BLACK_ALL); + } + + } + lineBuilder.Append(endOfLine); + } + return lineBuilder.ToString(); + } } diff --git a/QRCoderTests/AsciiQRCodeRendererTests.cs b/QRCoderTests/AsciiQRCodeRendererTests.cs index 7ac2656b..04c91182 100644 --- a/QRCoderTests/AsciiQRCodeRendererTests.cs +++ b/QRCoderTests/AsciiQRCodeRendererTests.cs @@ -24,6 +24,20 @@ public void can_render_ascii_qrcode() asciiCode.ShouldBe(targetCode); } + [Fact] + [Category("QRRenderer/AsciiQRCode")] + public void can_render_small_ascii_qrcode() + { + var targetCode = "█████████████████████████\n██ ▄▄▄▄▄ █▀▄█ ▀█ ▄▄▄▄▄ ██\n██ █ █ █▄█ █▄█ █ █ ██\n██ █▄▄▄█ █▄▀▀▀▀█ █▄▄▄█ ██\n██▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄██\n██ ▄▄ █▄ ██▀ ▄▄▄▀ ▀ ▄▀██\n██▀█▄█ █▄ ▄ ▀▄▀ █▄█▄▄███\n███▄▄▄▄█▄▄▄████▀▀ █▄█▄██\n██ ▄▄▄▄▄ █▄▄█▄▄▀ ▀ ▄█▄▄██\n██ █ █ █ ▀ █▄▀█ ██▄█▄██\n██ █▄▄▄█ █ ▀▄▀ █▄█▄ █ ▄██\n██▄▄▄▄▄▄▄█▄▄▄█████▄█▄▄▄██\n█████████████████████████\n"; + + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); + var asciiCode = new AsciiQRCode(data).GetGraphicSmall(); + + asciiCode.ShouldBe(targetCode); + } + [Fact] [Category("QRRenderer/AsciiQRCode")] public void can_render_ascii_qrcode_without_quietzones() From 3a994a6a12fc77410ced2016c7b7493c20f679d0 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Mon, 22 Apr 2024 23:29:44 +0200 Subject: [PATCH 3/7] Updated doc strings, added newline parameter and test cases --- QRCoder/ASCIIQRCode.cs | 39 +++++++++++--------- QRCoderTests/AsciiQRCodeRendererTests.cs | 46 ++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index 8649da7b..9ac4b468 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -16,15 +16,18 @@ public AsciiQRCode(QRCodeData data) : base(data) { } /// - /// Returns a strings that contains the resulting QR code as ASCII chars. + /// Returns a strings that contains the resulting QR code as textual representation. /// /// Number of repeated darkColorString/whiteSpaceString per module. /// String for use as dark color modules. In case of string make sure whiteSpaceString has the same length. /// String for use as white modules (whitespace). In case of string make sure darkColorString has the same length. + /// Bool that defines if quiet zones around the QR code shall be drawn /// End of line separator. (Default: \n) /// public string GetGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true, string endOfLine = "\n") { + if (repeatPerModule < 1) + throw new Exception("The repeatPerModule-parameter must be 1 or greater."); return string.Join(endOfLine, GetLineByLineGraphic(repeatPerModule, darkColorString, whiteSpaceString, drawQuietZones)); } @@ -64,15 +67,17 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString } /// - /// Returns a strings that contains the resulting QR code as ASCII chars. + /// Returns a strings that contains the resulting QR code as minified textual representation. /// + /// Bool that defines if quiet zones around the QR code shall be drawn + /// If set to true, dark and light colors will be inverted + /// End of line separator. (Default: \n) /// - public string GetGraphicSmall(bool drawQuietZones = true) + public string GetGraphic(bool drawQuietZones = true, bool invert = false, string endOfLine = "\n") { - string endOfLine = "\n"; bool BLACK = true, WHITE = false; - var platte = new + var palette = new { WHITE_ALL = "\u2588", WHITE_BLACK = "\u2580", @@ -83,39 +88,39 @@ public string GetGraphicSmall(bool drawQuietZones = true) var moduleData = QrCodeData.ModuleMatrix; var lineBuilder = new StringBuilder(); - var quietZonesModifier = (drawQuietZones ? 4 : 8); + var quietZonesModifier = (drawQuietZones ? 0 : 8); var quietZonesOffset = (int)(quietZonesModifier * 0.5); var sideLength = (QrCodeData.ModuleMatrix.Count - quietZonesModifier); - for (var row = 0; row < sideLength; row = row + 2) + for (var row = 0; row < sideLength; row += 2) { - for (var col = 0; col < moduleData.Count - quietZonesModifier; col++) + for (var col = 0; col < sideLength; col++) { try { - var current = moduleData[col + quietZonesOffset][row + quietZonesOffset]; - var next = moduleData[col + quietZonesOffset][(row + 1) + quietZonesOffset]; + var current = moduleData[col + quietZonesOffset][row + quietZonesOffset] ^ invert; + var next = moduleData[col + quietZonesOffset][(row + 1) + quietZonesOffset] ^ invert; if (current == WHITE && next == WHITE) - lineBuilder.Append(platte.WHITE_ALL); + lineBuilder.Append(palette.WHITE_ALL); else if (current == WHITE && next == BLACK) - lineBuilder.Append(platte.WHITE_BLACK); + lineBuilder.Append(palette.WHITE_BLACK); else if (current == BLACK && next == WHITE) - lineBuilder.Append(platte.BLACK_WHITE); + lineBuilder.Append(palette.BLACK_WHITE); else - lineBuilder.Append(platte.BLACK_ALL); + lineBuilder.Append(palette.BLACK_ALL); } catch (Exception) { if (drawQuietZones) - lineBuilder.Append(platte.WHITE_BLACK); + lineBuilder.Append(palette.WHITE_BLACK); else - lineBuilder.Append(platte.BLACK_ALL); + lineBuilder.Append(palette.BLACK_ALL); } } lineBuilder.Append(endOfLine); } - return lineBuilder.ToString(); + return lineBuilder.ToString().Trim(endOfLine.ToCharArray()); } } diff --git a/QRCoderTests/AsciiQRCodeRendererTests.cs b/QRCoderTests/AsciiQRCodeRendererTests.cs index 04c91182..da3daa49 100644 --- a/QRCoderTests/AsciiQRCodeRendererTests.cs +++ b/QRCoderTests/AsciiQRCodeRendererTests.cs @@ -28,12 +28,54 @@ public void can_render_ascii_qrcode() [Category("QRRenderer/AsciiQRCode")] public void can_render_small_ascii_qrcode() { - var targetCode = "█████████████████████████\n██ ▄▄▄▄▄ █▀▄█ ▀█ ▄▄▄▄▄ ██\n██ █ █ █▄█ █▄█ █ █ ██\n██ █▄▄▄█ █▄▀▀▀▀█ █▄▄▄█ ██\n██▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄██\n██ ▄▄ █▄ ██▀ ▄▄▄▀ ▀ ▄▀██\n██▀█▄█ █▄ ▄ ▀▄▀ █▄█▄▄███\n███▄▄▄▄█▄▄▄████▀▀ █▄█▄██\n██ ▄▄▄▄▄ █▄▄█▄▄▀ ▀ ▄█▄▄██\n██ █ █ █ ▀ █▄▀█ ██▄█▄██\n██ █▄▄▄█ █ ▀▄▀ █▄█▄ █ ▄██\n██▄▄▄▄▄▄▄█▄▄▄█████▄█▄▄▄██\n█████████████████████████\n"; + var targetCode = "█████████████████████████████\n█████████████████████████████\n████ ▄▄▄▄▄ █▀▄█ ▀█ ▄▄▄▄▄ ████\n████ █ █ █▄█ █▄█ █ █ ████\n████ █▄▄▄█ █▄▀▀▀▀█ █▄▄▄█ ████\n████▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄████\n████ ▄▄ █▄ ██▀ ▄▄▄▀ ▀ ▄▀████\n████▀█▄█ █▄ ▄ ▀▄▀ █▄█▄▄█████\n█████▄▄▄▄█▄▄▄████▀▀ █▄█▄████\n████ ▄▄▄▄▄ █▄▄█▄▄▀ ▀ ▄█▄▄████\n████ █ █ █ ▀ █▄▀█ ██▄█▄████\n████ █▄▄▄█ █ ▀▄▀ █▄█▄ █ ▄████\n████▄▄▄▄▄▄▄█▄▄▄█████▄█▄▄▄████\n█████████████████████████████\n▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"; //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); - var asciiCode = new AsciiQRCode(data).GetGraphicSmall(); + var asciiCode = new AsciiQRCode(data).GetGraphic(); + + asciiCode.ShouldBe(targetCode); + } + + [Fact] + [Category("QRRenderer/AsciiQRCode")] + public void can_render_small_ascii_qrcode_without_quietzones() + { + var targetCode = " ▄▄▄▄▄ █▀▄█ ▀█ ▄▄▄▄▄ \n █ █ █▄█ █▄█ █ █ \n █▄▄▄█ █▄▀▀▀▀█ █▄▄▄█ \n▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄\n ▄▄ █▄ ██▀ ▄▄▄▀ ▀ ▄▀\n▀█▄█ █▄ ▄ ▀▄▀ █▄█▄▄█\n█▄▄▄▄█▄▄▄████▀▀ █▄█▄\n ▄▄▄▄▄ █▄▄█▄▄▀ ▀ ▄█▄▄\n █ █ █ ▀ █▄▀█ ██▄█▄\n █▄▄▄█ █ ▀▄▀ █▄█▄ █ ▄\n▄▄▄▄▄▄▄█▄▄▄█████▄█▄▄▄"; + + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); + var asciiCode = new AsciiQRCode(data).GetGraphic(drawQuietZones: false); + + asciiCode.ShouldBe(targetCode); + } + + [Fact] + [Category("QRRenderer/AsciiQRCode")] + public void can_render_small_ascii_qrcode_inverted() + { + var targetCode = " \n \n █▀▀▀▀▀█ ▄▀ █▄ █▀▀▀▀▀█ \n █ ███ █ ▀ █ ▀ █ ███ █ \n █ ▀▀▀ █ ▀▄▄▄▄ █ ▀▀▀ █ \n ▀▀▀▀▀▀▀ █ █▄▀ ▀▀▀▀▀▀▀ \n ██▀▀█ ▀█ ▄█▀▀▀▄█▄█▀▄ \n ▄ ▀ █ ▀██▀█▄▀▄█ ▀ ▀▀ \n ▀▀▀▀ ▀▀▀ ▄▄██ ▀ ▀ \n █▀▀▀▀▀█ ▀▀ ▀▀▄█▄█▀ ▀▀ \n █ ███ █ █▄█ ▀▄ █ ▀ ▀ \n █ ▀▀▀ █ █▄▀▄█ ▀ ▀█ █▀ \n ▀▀▀▀▀▀▀ ▀▀▀ ▀ ▀▀▀ \n \n "; + + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); + var asciiCode = new AsciiQRCode(data).GetGraphic(invert: true); + + asciiCode.ShouldBe(targetCode); + } + + [Fact] + [Category("QRRenderer/AsciiQRCode")] + public void can_render_small_ascii_qrcode_with_custom_eol() + { + var targetCode = "█████████████████████████████\r\n█████████████████████████████\r\n████ ▄▄▄▄▄ █▀▄█ ▀█ ▄▄▄▄▄ ████\r\n████ █ █ █▄█ █▄█ █ █ ████\r\n████ █▄▄▄█ █▄▀▀▀▀█ █▄▄▄█ ████\r\n████▄▄▄▄▄▄▄█ █ ▀▄█▄▄▄▄▄▄▄████\r\n████ ▄▄ █▄ ██▀ ▄▄▄▀ ▀ ▄▀████\r\n████▀█▄█ █▄ ▄ ▀▄▀ █▄█▄▄█████\r\n█████▄▄▄▄█▄▄▄████▀▀ █▄█▄████\r\n████ ▄▄▄▄▄ █▄▄█▄▄▀ ▀ ▄█▄▄████\r\n████ █ █ █ ▀ █▄▀█ ██▄█▄████\r\n████ █▄▄▄█ █ ▀▄▀ █▄█▄ █ ▄████\r\n████▄▄▄▄▄▄▄█▄▄▄█████▄█▄▄▄████\r\n█████████████████████████████\r\n▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"; + + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); + var asciiCode = new AsciiQRCode(data).GetGraphic(endOfLine: "\r\n"); asciiCode.ShouldBe(targetCode); } From af881096d4900a5a7d0567c2e768cbba926fd9e4 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Mon, 22 Apr 2024 23:42:45 +0200 Subject: [PATCH 4/7] Removed try-catch and replaced by robust implementation in ArtQrCode small renderer --- QRCoder/ASCIIQRCode.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index 9ac4b468..dd7b8b95 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -99,7 +99,14 @@ public string GetGraphic(bool drawQuietZones = true, bool invert = false, string try { var current = moduleData[col + quietZonesOffset][row + quietZonesOffset] ^ invert; - var next = moduleData[col + quietZonesOffset][(row + 1) + quietZonesOffset] ^ invert; + var nextRowId = row + quietZonesOffset + 1; + + // Set next to whitespace "color" + var next = false ^ invert; + // Fill next with value, if in data range + if (nextRowId < QrCodeData.ModuleMatrix.Count) + next = moduleData[col + quietZonesOffset][nextRowId] ^ invert; + if (current == WHITE && next == WHITE) lineBuilder.Append(palette.WHITE_ALL); else if (current == WHITE && next == BLACK) @@ -109,14 +116,6 @@ public string GetGraphic(bool drawQuietZones = true, bool invert = false, string else lineBuilder.Append(palette.BLACK_ALL); } - catch (Exception) - { - if (drawQuietZones) - lineBuilder.Append(palette.WHITE_BLACK); - else - lineBuilder.Append(palette.BLACK_ALL); - } - } lineBuilder.Append(endOfLine); } From 9967c6d28b89d7af36b9487e8183ff8c92dff76c Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Tue, 23 Apr 2024 00:12:06 +0200 Subject: [PATCH 5/7] Fixed last line rendering in small AsciiQrCode renderer --- QRCoder/ASCIIQRCode.cs | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index dd7b8b95..bf78188a 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -86,40 +86,39 @@ public string GetGraphic(bool drawQuietZones = true, bool invert = false, string }; var moduleData = QrCodeData.ModuleMatrix; - var lineBuilder = new StringBuilder(); + var sbSize = (moduleData.Count + endOfLine.Length) * (int)Math.Ceiling(moduleData.Count / 2.0) - 1; + var lineBuilder = new StringBuilder(sbSize); var quietZonesModifier = (drawQuietZones ? 0 : 8); var quietZonesOffset = (int)(quietZonesModifier * 0.5); - var sideLength = (QrCodeData.ModuleMatrix.Count - quietZonesModifier); + var sideLength = (moduleData.Count - quietZonesModifier); for (var row = 0; row < sideLength; row += 2) { for (var col = 0; col < sideLength; col++) { - try - { - var current = moduleData[col + quietZonesOffset][row + quietZonesOffset] ^ invert; - var nextRowId = row + quietZonesOffset + 1; + var current = moduleData[col + quietZonesOffset][row + quietZonesOffset] ^ invert; + var nextRowId = row + quietZonesOffset + 1; - // Set next to whitespace "color" - var next = false ^ invert; - // Fill next with value, if in data range - if (nextRowId < QrCodeData.ModuleMatrix.Count) - next = moduleData[col + quietZonesOffset][nextRowId] ^ invert; + // Set next to whitespace "color" + var next = BLACK; + // Fill next with value, if in data range + if (nextRowId < QrCodeData.ModuleMatrix.Count) + next = moduleData[col + quietZonesOffset][nextRowId] ^ invert; - if (current == WHITE && next == WHITE) - lineBuilder.Append(palette.WHITE_ALL); - else if (current == WHITE && next == BLACK) - lineBuilder.Append(palette.WHITE_BLACK); - else if (current == BLACK && next == WHITE) - lineBuilder.Append(palette.BLACK_WHITE); - else - lineBuilder.Append(palette.BLACK_ALL); - } + if (current == WHITE && next == WHITE) + lineBuilder.Append(palette.WHITE_ALL); + else if (current == WHITE && next == BLACK) + lineBuilder.Append(palette.WHITE_BLACK); + else if (current == BLACK && next == WHITE) + lineBuilder.Append(palette.BLACK_WHITE); + else + lineBuilder.Append(palette.BLACK_ALL); } - lineBuilder.Append(endOfLine); + if (row + 2 < sideLength) + lineBuilder.Append(endOfLine); } - return lineBuilder.ToString().Trim(endOfLine.ToCharArray()); + return lineBuilder.ToString(); } } @@ -133,5 +132,13 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar using (var qrCode = new AsciiQRCode(qrCodeData)) return qrCode.GetGraphic(pixelsPerModule, darkColorString, whiteSpaceString, drawQuietZones, endOfLine); } + + public static string GetQRCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n", bool drawQuietZones = true, bool invert = true) + { + using (var qrGenerator = new QRCodeGenerator()) + using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) + using (var qrCode = new AsciiQRCode(qrCodeData)) + return qrCode.GetGraphic(drawQuietZones, invert, endOfLine); + } } } \ No newline at end of file From fb8be9e256beba2f8773744a72e8197f8d2a6f49 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Tue, 23 Apr 2024 00:30:20 +0200 Subject: [PATCH 6/7] Updated docstrings in ASCIIQrCode --- QRCoder/ASCIIQRCode.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index bf78188a..67e9f5b8 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -30,7 +30,7 @@ public string GetGraphic(int repeatPerModule, string darkColorString = "██", throw new Exception("The repeatPerModule-parameter must be 1 or greater."); return string.Join(endOfLine, GetLineByLineGraphic(repeatPerModule, darkColorString, whiteSpaceString, drawQuietZones)); } - + /// /// Returns an array of strings that contains each line of the resulting QR code as ASCII chars. @@ -38,6 +38,7 @@ public string GetGraphic(int repeatPerModule, string darkColorString = "██", /// Number of repeated darkColorString/whiteSpaceString per module. /// String for use as dark color modules. In case of string make sure whiteSpaceString has the same length. /// String for use as white modules (whitespace). In case of string make sure darkColorString has the same length. + /// Bool that defines if quiet zones around the QR code shall be drawn /// public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString = "██", string whiteSpaceString = " ", bool drawQuietZones = true) { From 80fd2886f35339ed843170fb55e7c863a6f0b355 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Tue, 23 Apr 2024 00:32:09 +0200 Subject: [PATCH 7/7] Rolled back to GetGraphicSmall naming --- QRCoder/ASCIIQRCode.cs | 4 ++-- QRCoderTests/AsciiQRCodeRendererTests.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index 67e9f5b8..6f07c447 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -74,7 +74,7 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString /// If set to true, dark and light colors will be inverted /// End of line separator. (Default: \n) /// - public string GetGraphic(bool drawQuietZones = true, bool invert = false, string endOfLine = "\n") + public string GetGraphicSmall(bool drawQuietZones = true, bool invert = false, string endOfLine = "\n") { bool BLACK = true, WHITE = false; @@ -139,7 +139,7 @@ public static string GetQRCode(string plainText, ECCLevel eccLevel, bool forceUt using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new AsciiQRCode(qrCodeData)) - return qrCode.GetGraphic(drawQuietZones, invert, endOfLine); + return qrCode.GetGraphicSmall(drawQuietZones, invert, endOfLine); } } } \ No newline at end of file diff --git a/QRCoderTests/AsciiQRCodeRendererTests.cs b/QRCoderTests/AsciiQRCodeRendererTests.cs index da3daa49..75152911 100644 --- a/QRCoderTests/AsciiQRCodeRendererTests.cs +++ b/QRCoderTests/AsciiQRCodeRendererTests.cs @@ -33,7 +33,7 @@ public void can_render_small_ascii_qrcode() //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); - var asciiCode = new AsciiQRCode(data).GetGraphic(); + var asciiCode = new AsciiQRCode(data).GetGraphicSmall(); asciiCode.ShouldBe(targetCode); } @@ -47,7 +47,7 @@ public void can_render_small_ascii_qrcode_without_quietzones() //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); - var asciiCode = new AsciiQRCode(data).GetGraphic(drawQuietZones: false); + var asciiCode = new AsciiQRCode(data).GetGraphicSmall(drawQuietZones: false); asciiCode.ShouldBe(targetCode); } @@ -61,7 +61,7 @@ public void can_render_small_ascii_qrcode_inverted() //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); - var asciiCode = new AsciiQRCode(data).GetGraphic(invert: true); + var asciiCode = new AsciiQRCode(data).GetGraphicSmall(invert: true); asciiCode.ShouldBe(targetCode); } @@ -75,7 +75,7 @@ public void can_render_small_ascii_qrcode_with_custom_eol() //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); - var asciiCode = new AsciiQRCode(data).GetGraphic(endOfLine: "\r\n"); + var asciiCode = new AsciiQRCode(data).GetGraphicSmall(endOfLine: "\r\n"); asciiCode.ShouldBe(targetCode); }