Skip to content

Commit 349f782

Browse files
author
Matteo Dell'Acqua
committed
Add validation to ^BY
1 parent 52fc140 commit 349f782

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/BinaryKits.Zpl.Viewer/CommandAnalyzers/BarCodeFieldDefaultZplCommandAnalyzer.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,46 @@ public override ZplElementBase Analyze(string zplCommand, VirtualPrinter virtual
1616

1717
if (zplDataParts.Length > 0 && int.TryParse(zplDataParts[0], out tmpint))
1818
{
19+
// TODO: add validation message: between 1 and 10
20+
if (tmpint < 1)
21+
{
22+
tmpint = 1;
23+
}
24+
else if (tmpint > 10)
25+
{
26+
tmpint = 10;
27+
}
28+
1929
virtualPrinter.SetBarcodeModuleWidth(tmpint);
2030
}
2131

2232
if (zplDataParts.Length > 1 && double.TryParse(zplDataParts[1], out tmpdbl))
2333
{
34+
// TODO: add validation message: between 2.0 and 3.0 in 0.1 increments
35+
if (tmpdbl < 2.0)
36+
{
37+
tmpdbl = 2.0;
38+
}
39+
else if (tmpdbl > 3.0)
40+
{
41+
tmpdbl = 3.0;
42+
}
43+
else
44+
{
45+
tmpdbl = System.Math.Round(tmpdbl, 1);
46+
}
47+
2448
virtualPrinter.SetBarcodeWideBarToNarrowBarWidthRatio(tmpdbl);
2549
}
2650

2751
if (zplDataParts.Length > 2 && int.TryParse(zplDataParts[2], out tmpint))
2852
{
53+
// TODO: add validation message: greater or equal than 1
54+
if (tmpint < 1)
55+
{
56+
tmpint = 1;
57+
}
58+
2959
virtualPrinter.SetBarcodeHeight(tmpint);
3060
}
3161

0 commit comments

Comments
 (0)