Manual - Code 128
Introduction
Code 128 allows you to encode all the ASCII characters from 0 to 127. Different encoding tables allow you to encode data more efficiently. When a character is not available in the table, a "change table" character is written. You can select the table when you start your code, it is a good choice to choose a table which contains the first characters you want to write.
If you don't specify a specific table, the table is automatically chosen.
Here is a list of the supported table characters:
- Table A : ASCII 0-95 (capital letters, numbers, special characters)
- Table B : ASCII 32-127 (capital letters, lower case, numbers, special characters)
- Table C : Group numbers by 2 from 00 to 99
Code 128 also contains 4 special characters that can't be written directly. These are the characters FNC1, FNC2, FNC3, and FNC4. You can write them by activating the tilde character (~) with the tilde={} method.
You can pass normal text to the method text={} in order to let this method analyze your text and choose the best encoding method. You can also still force the encoding method; below are the possibilities you can pass to the text={} method:
- auto encoding : automatic encoding method
[Code128.CODE128_A, 'TEXT']
: Table A[Code128.CODE128_B, 'text']
: Table B[Code128.CODE128_C, '012345']
: Table C[[Code128.CODE128_C, '012345'], 'auto encoding']
: multiple encoding method
This class inherits the BakeryBarcode1D class.
Extended ASCII character support
In order to support extended ASCII characters such as ü (u-umlaut/diaeresis) or ß (eszett), you have to precede the character by an FNC4 then subtract the unicode point of the character by 128.
The FNC4 code acts as a toggle for only a single character. If you plan to encode more than 1 subsequent character, you can use two consecutive FNC4 characters to latch into the extended values. You can repeat the double FNC4 characters to revert back to non-extended values.
For instance, to encode Grüße, you would do the following:
const text = 'Gr~F4' + String.fromCharCode('ü'.charCodeAt(0) - 128) + '~F4'
+ String.fromCharCode('ß'.charCodeAt(0) - 128) + 'e';
or
const text = 'Gr~F4~F4' + String.fromCharCode('ü'.charCodeAt(0) - 128)
+ String.fromCharCode('ß'.charCodeAt(0) - 128) + '~F4e';
Example
Methods
BakeryCode128's Methods
-
start={
start } — Specifies by which table the barcode should start -
tilde={
tilde } — Modifies the use of the tilde character ~
BakeryBarcode1D's Methods
-
thickness={
thickness } — Specifies the thickness of the barcode -
label={
label } — Sets the label -
font={
font } — Sets the text font for the label -
displayChecksum={
display } — Specifies the checksum to be added to the label
BakeryBarcode's Methods
-
text={
text } — Analyzes atext message to draw afterwards -
scale={
scale } — Sets the scale of the barcode -
foregroundColor={
color } — Sets the color of the bars -
backgroundColor={
color } — Sets the color of the spaces -
offsetX={
value } — Sets the X offset -
offsetY={
value } — Sets the Y offset
Code Example
import { BakeryColor, BakeryFont } from '@barcode-bakery/barcode-react';
import { BakeryCode128 } from '@barcode-bakery/barcode-react/1d';
export default function Home() {
const font = new BakeryFont('Arial', 18);
const colorBlack = new BakeryColor(0, 0, 0);
const colorWhite = new BakeryColor(255, 255, 255);
return <BakeryCode128
scale={2}
thickness={30}
foregroundColor={colorBlack}
backgroundColor={colorWhite}
font={font}
text='a123'
>;
}
Method explanations
-
start={
start } — Specifies by which table the barcode should startDescriptionThe argument can be A, B, C or null. This selects the table the barcode will start.
The default value is null.
This means the table will be automatically chosen when you provide the text.
The tables contain different characters which can be encoded in the barcode.
Check the introduction of this document to obtain more information. -
tilde={
tilde } — Modifies the use of the tilde character ~DescriptionBy settingtrue in this argument, the tilde characters (ASCII 126 ~) will be processed as special characters. These are the special characters you can write.
- ~~ : Writes a simple tilde
- ~Fx : Writes a FNCx character, with x varying between 1 and 4
The default value is true.
-
thickness={
thickness } — Specifies the thickness of the barcodeDescriptionThe thickness of the barcode in pixels. This is the vertical size. -
label={
label } — Sets the labelDescriptionThe text label will be written below or above the barcode depending on the barcode. You can write the special valueBakeryBarcode1D.Label if you would like your text to be chosen automatically. It will be the value passed to thetext={} method. -
font={
font } — Sets the text font for the labelDescriptionThe value of the argument must be an instance of theBakeryFontFile class. -
displayChecksum={
display } — Specifies the checksum to be added to the labelDescriptionSettingtrue will append the checksum to the default label.
The default value is true.
-
text={
text } — Analyzes atext message to draw afterwardsDescriptionThe data you pass to thetext argument must be supported by the type of barcode you use.
Check each barcode's introduction section to obtain more information on how to use this method within each symbology. -
scale={
scale } — Sets the scale of the barcodeDescriptionThe barcode will bex times bigger. Then a pixel will bex byx for its size. -
foregroundColor={
color } — Sets the color of the barsDescriptionSets the color of the bars of the barcode. By default, the color is black. This argument can be aBakeryColor class or any other argument thatBakeryColor can accept in its constructor. -
backgroundColor={
color } — Sets the color of the spacesDescriptionSets the color of the spaces of the barcode. By default, the color is white. This argument can be aBakeryColor class or any other argument thatBakeryColor can accept in its constructor. -
offsetX={
value } — Sets the X offsetDescriptionSpecifies the X offset of the barcode in pixels multiplied by the scale. -
offsetY={
value } — Sets the Y offsetDescriptionSpecifies the Y offset of the barcode in pixels multiplied by the scale.