Skip to content

Commit af88109

Browse files
committed
Removed try-catch and replaced by robust implementation in ArtQrCode small renderer
1 parent 3a994a6 commit af88109

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

QRCoder/ASCIIQRCode.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ public string GetGraphic(bool drawQuietZones = true, bool invert = false, string
9999
try
100100
{
101101
var current = moduleData[col + quietZonesOffset][row + quietZonesOffset] ^ invert;
102-
var next = moduleData[col + quietZonesOffset][(row + 1) + quietZonesOffset] ^ invert;
102+
var nextRowId = row + quietZonesOffset + 1;
103+
104+
// Set next to whitespace "color"
105+
var next = false ^ invert;
106+
// Fill next with value, if in data range
107+
if (nextRowId < QrCodeData.ModuleMatrix.Count)
108+
next = moduleData[col + quietZonesOffset][nextRowId] ^ invert;
109+
103110
if (current == WHITE && next == WHITE)
104111
lineBuilder.Append(palette.WHITE_ALL);
105112
else if (current == WHITE && next == BLACK)
@@ -109,14 +116,6 @@ public string GetGraphic(bool drawQuietZones = true, bool invert = false, string
109116
else
110117
lineBuilder.Append(palette.BLACK_ALL);
111118
}
112-
catch (Exception)
113-
{
114-
if (drawQuietZones)
115-
lineBuilder.Append(palette.WHITE_BLACK);
116-
else
117-
lineBuilder.Append(palette.BLACK_ALL);
118-
}
119-
120119
}
121120
lineBuilder.Append(endOfLine);
122121
}

0 commit comments

Comments
 (0)