barnhill / barcodelib

C# Barcode Image Generation Library
Apache License 2.0
733 stars 238 forks source link

Codabar, encoding of '+' is wrong #165

Closed rob313663 closed 12 months ago

rob313663 commented 1 year ago

Hi!

Codabar_Code.Add('.', "1101101101");//"110101100101"); Codabar_Code.Add('+', "101100110011");//"101101100101");

From https://web.archive.org/web/20060512120028/http://www.barcodesymbols.com/codabar.htm: " + 0 0 1 0 1 0 1 15"

It shoulde be: "1011011011" in BarcodeLib notation (tested it with a barcode reader).

The comments after all the codewords in Codabar do not correspond to the value, so why are they there at all?

Anyway, BarcodeLib encoding has a design problem in the codewords encoding, same in Code 39 and Interleave 2 of 5, it encodes everything as bits, and not as wide and narrow, which for the Codabar means this can't be implemented:

"The original Pitney-Bowes specification actually varies the narrow:wide width ratio to make all characters the same width. That is, characters with 2 wide elements use a 3:1 ratio, while characters with 3 wide elements use a 2:1 ratio, so all characters are 10 narrow elements wide (plus the inter-character space makes 11). "Rationalized codabar" uses a fixed ratio and allows the character widths to vary."

Attached is an image where the wide to narrow ratio is 3:1 for codewords with two wide elements and 2:1 for codewords with three wide elements.

Here is my codeword table for Codabar:

private static void InitCodeWordPatterns() { // Encoding character as bBsS where b or B means bar and s or S means space. // Upper case means it is a wide element. Lower case is a narrow element. codewordPatterns = new Dictionary<char, CodabarCodeWord> { { '0', new CodabarCodeWord() { Pattern = "bsbsbSB", CodeWordValue = 0 }}, { '1', new CodabarCodeWord() { Pattern = "bsbsBSb", CodeWordValue = 1 }}, { '2', new CodabarCodeWord() { Pattern = "bsbSbsB", CodeWordValue = 2 }}, { '3', new CodabarCodeWord() { Pattern = "BSbsbsb", CodeWordValue = 3 }}, { '4', new CodabarCodeWord() { Pattern = "bsBsbSb", CodeWordValue = 4 }}, { '5', new CodabarCodeWord() { Pattern = "BsbsbSb", CodeWordValue = 5 }}, { '6', new CodabarCodeWord() { Pattern = "bSbsbsB", CodeWordValue = 6 }}, { '7', new CodabarCodeWord() { Pattern = "bSbsBsb", CodeWordValue = 7 }}, { '8', new CodabarCodeWord() { Pattern = "bSBsbsb", CodeWordValue = 8 }}, { '9', new CodabarCodeWord() { Pattern = "BsbSbsb", CodeWordValue = 9 }}, { '-', new CodabarCodeWord() { Pattern = "bsbSBsb", CodeWordValue = 10 }}, { '$', new CodabarCodeWord() { Pattern = "bsBSbsb", CodeWordValue = 11 }}, { ':', new CodabarCodeWord() { Pattern = "BsbsBsB", CodeWordValue = 12 }}, { '/', new CodabarCodeWord() { Pattern = "BsBsbsB", CodeWordValue = 13 }}, { '.', new CodabarCodeWord() { Pattern = "BsBsBsb", CodeWordValue = 14 }}, { '+', new CodabarCodeWord() { Pattern = "bsBsBsB", CodeWordValue = 15 }}, { 'A', new CodabarCodeWord() { Pattern = "bsBSbSb", CodeWordValue = 16 }}, { 'B', new CodabarCodeWord() { Pattern = "bSbSbsB", CodeWordValue = 17 }}, { 'C', new CodabarCodeWord() { Pattern = "bsbSbSB", CodeWordValue = 18 }}, { 'D', new CodabarCodeWord() { Pattern = "bsbSBSb", CodeWordValue = 19 }}, };

Codabar.codeWordToChar = Codabar.InitCodeWordToChar();

}

codabar

rob313663 commented 1 year ago

The image shows the x2 or x3 width of wide elements depending on how many wide elements there are in the code word.

barnhill commented 12 months ago

Good find on the + symbol being encoded incorrectly ... Ive merged a change to fix that encoding and will push a new version out soon.

barnhill commented 12 months ago

Fixed by https://github.com/barnhill/barcodelib/commit/8b3c739077971026e543ec3e2646ce21713c6c54

barnhill commented 12 months ago

Published 3.0.1 to nuget should be out soon as its approved by MS