Understanding Code128 character sets and Limitations of Code128 Fontware

There are three character sets defined in code 128 - A, B and C. The primary reason for this arrangement is that code 128 has only 106 unique patterns in total, which is not enough to encode all 127 ASCII characters and 4 special function characters (FNC1 ~ FNC4). Furthermore, most data encoded are numbers, which can be more efficiently using a numeric-only set.

Under this arrangement, three sets encode different regions data with overlapping. Code128C only encodes numbers and FNC1 character. When it encodes numbers, two adjacent digits are combined into one code128 pattern (character). Set A includes capital letters, control characters and digits. Set B includes all printable characters. Needless to say, there are a large overlapping between set A and set B. In addition to data characters, each set uses patterns to switch from one to another. For example, START-A character starts set A. SHIFT character switches between set A and set B. More information can be found athttp://www.morovia.com/education/symbology/code128.asp

However with this arrangement, the encoding process (from data to patterns) becomes more complicated, especially when using a barcode font. There are two approaches in converting data into patterns:

  1. Force using the same character set through the data. This approach is easy to implement, and in many occasions it actually produces the shortest barcode. For example, when the data is numeric and has an even length (because set C encodes two adjacent digits into one pattern), set C is the best choice obviously. When the data is all letters, code B is sufficient.

  2. Try to find the best (shortest) result possible. Look ahead a few characters and if another character set produce a better result, switch it.

Morovia uses the second approach in its non-font products, such as Monterey Barcode Creator and Barcode ActiveX. On its font product (Code128 Fonts), Morovia allows users to select the way they'd like. That is why we provide a number of functions: Code128A, Code128B, Code128C and Code128Ex.

Function Code128Ex implements the second approach - it aggressively searches for the best result, and it generally produces the best one. The implement is quite complicated and as a result, only binary interface (DLL/COM) is provided. If you look at the VBA function Code128Ex, you will find that it simply calls the COM interface.

The first approach generally fits the use of barcode font better. It is easy to understand. This approach is used by many software (based on barcode fonts) and barcode printers (also based on fonts). It is also easy to troubleshoot by looking at its human readable text when formatted with a barcode font with human readable. To take this approach, just call one of three encoding functions and format the result with appropriate font.

The primary disadvantage is that you lose the space efficiency when the data contain a lot of digits. The images below illustrate the problem - the same data represented in a set-A-only, a set-B-only and a mixed-set barcode. Because most of the data are digits, the length of the barcode resulted from mixed encoding is about half of the other two.

Understanding Limitations of Code128 Fonts

Morovia Code128 Fonts assign every unique Code128 pattern to a character. Users can access the pattern by entering the corresponding character. To create a Code128 barcode, you call one of the encoding functions and format the result with one of the fonts.

Although there are 20 fonts in the package, the same character produces the same barcode pattern among all fonts. The only difference is the human readable text portion. Therefore, you can remove human readable by changing the font to a non-human-readable one. The name of a non-human-readable font does not contain trailing 'A'.

Although you can use a human readable font to produce a barcode with human readable, there are certain limitations you should aware. First, if a barcode is encoded with mixed sets (such as the result from Code128Ex), it is impossible to keep the human readable text in synchronization with original data when the whole barcode is formatted with one font. In other words, the human readable produced by a human-readable font is only meaningful when the barcode character set is the same as the one that the font is designed for. This behavior does not impact the barcode itself due to its design. That is why we have a strange human readable in the third barcode (mixed encode). In this case, you probably want to format the result with a non-human-readable font, and to place a text box under the barcode to make up the human readable text.

When you use one of the single set functions, you may find that extra characters appear at the end of human readable text. As a matter of fact, all three barcodes have extra characters in the human readable text. Sometime you may not see them, but most of times the extra characters are there. The reason is actually quite simple - code128 requires a check character at the end of the barcode. Because we are using a font, if that checksum character happens to be a printable characters (remember not all characters encoded are printable), extra character(s) will show up. In the cases of set A and B, it is one extra. In the case of set C, it is two digits. Due to the limit on the available characters that a font can use, it is impossible to solve the issue in the font design. If you are creating the barcode on a word processor, you can get around by formatting this check character with a non-human-readable counterpart.

The good thing is that those human readable text issues can be simply solved by reformatting the string with its non-human-readable counterpart. You can always add human readable text by placing a text box below the barcode and fill it with correct information.