Skip to content

Commit 7e95812

Browse files
author
Alex Tessmer
committed
Added support for CODE93FullASCII
Add support for encoding the full ASCII table in CODE93, using two symbol encodings per character for the extended set. CODE93 no longer automatically converts the input data to upper case, use CODE93FullASCII if lower case inputs are needed. The symbol for the stop/end sequence is changed to '\xff', as '*' is a valid input character in CODE93FullASCII.
1 parent 7c2863a commit 7e95812

8 files changed

Lines changed: 118 additions & 17 deletions

File tree

automation/barcode-building.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"name": "code93",
39-
"names": "CODE93",
39+
"names": ["CODE93", "CODE93FullASCII"],
4040
"barcodeFile": "./CODE93"
4141
}
4242
]

src/barcodes/CODE93/CODE93.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import Barcode from "../Barcode.js";
66

77
class CODE93 extends Barcode {
88
constructor(data, options){
9-
data = data.toUpperCase();
10-
119
super(data, options);
1210
}
1311

@@ -16,7 +14,17 @@ class CODE93 extends Barcode {
1614
}
1715

1816
encode(){
19-
const symbols = this.data.split('');
17+
const symbols = this.data
18+
.split('')
19+
.flatMap(c => {
20+
const encoding = CODE93.getEncoding(c);
21+
if (typeof(encoding) === 'string') {
22+
// Single-symbol character
23+
return c;
24+
}
25+
// Multi-symbol character
26+
return encoding;
27+
});
2028
const encoded = symbols
2129
.map(s => CODE93.getEncoding(s))
2230
.join('');
@@ -29,13 +37,13 @@ class CODE93 extends Barcode {
2937
text: this.text,
3038
data:
3139
// Add the start bits
32-
CODE93.getEncoding('*') +
40+
CODE93.getEncoding('\xff') +
3341
// Add the encoded bits
3442
encoded +
3543
// Add the checksum
3644
CODE93.getEncoding(csumC) + CODE93.getEncoding(csumK) +
3745
// Add the stop bits
38-
CODE93.getEncoding('*') +
46+
CODE93.getEncoding('\xff') +
3947
// Add the termination bit
4048
'1'
4149
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Encoding documentation
2+
// https://en.wikipedia.org/wiki/Code_93#Full_ASCII_Code_93
3+
4+
import CODE93 from './CODE93.js';
5+
6+
class CODE93FullASCII extends CODE93 {
7+
constructor(data, options) {
8+
super(data, options);
9+
}
10+
11+
valid() {
12+
return /^[\x00-\x7f]+$/.test(this.data);
13+
}
14+
}
15+
16+
export default CODE93FullASCII;

src/barcodes/CODE93/constants.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,30 @@ export const SYMBOLS = [
1414
// Only used for csum and multi-symbols character encodings
1515
'($)', '(%)', '(/)', '(+)',
1616
// Start/Stop
17-
'*'
17+
'\xff',
18+
// Multi-sequence characters (Full ASCII Code 93)
19+
'\x00', '\x01', '\x02', '\x03',
20+
'\x04', '\x04', '\x06', '\x07',
21+
'\x08', '\x09', '\x0a', '\x0b',
22+
'\x0c', '\x0d', '\x0e', '\x0f',
23+
'\x10', '\x11', '\x12', '\x13',
24+
'\x14', '\x14', '\x16', '\x17',
25+
'\x18', '\x19', '\x1a', '\x1b',
26+
'\x1c', '\x1d', '\x1e', '\x1f',
27+
'!', '"', '#', '&',
28+
'\'', '(', ')', '*',
29+
',', ':', ';', '<',
30+
'=', '>', '?', '@',
31+
'[', '\\', ']', '^',
32+
'_', '`', 'a', 'b',
33+
'c', 'd', 'e', 'f',
34+
'g', 'h', 'i', 'j',
35+
'k', 'l', 'm', 'n',
36+
'o', 'p', 'q', 'r',
37+
's', 't', 'u', 'v',
38+
'w', 'x', 'y', 'z',
39+
'{', '|', '}', '~',
40+
'\x7f',
1841
];
1942

2043
// Order matches SYMBOLS array
@@ -30,5 +53,27 @@ export const BINARIES = [
3053
'101101100', '101100110', '100110110', '100111010',
3154
'100101110', '111010100', '111010010', '111001010',
3255
'101101110', '101110110', '110101110', '100100110',
33-
'111011010', '111010110', '100110010', '101011110'
56+
'111011010', '111010110', '100110010', '101011110',
57+
['(%)', 'U'], ['($)', 'A'], ['($)', 'B'], ['($)', 'C'],
58+
['($)', 'D'], ['($)', 'E'], ['($)', 'F'], ['($)', 'G'],
59+
['($)', 'H'], ['($)', 'I'], ['($)', 'J'], ['($)', 'K'],
60+
['($)', 'L'], ['($)', 'M'], ['($)', 'N'], ['($)', 'O'],
61+
['($)', 'P'], ['($)', 'Q'], ['($)', 'R'], ['($)', 'S'],
62+
['($)', 'T'], ['($)', 'U'], ['($)', 'V'], ['($)', 'W'],
63+
['($)', 'X'], ['($)', 'Y'], ['($)', 'Z'], ['(%)', 'A'],
64+
['(%)', 'B'], ['(%)', 'C'], ['(%)', 'D'], ['(%)', 'E'],
65+
['(/)', 'A'], ['(/)', 'B'], ['(/)', 'C'], ['(/)', 'F'],
66+
['(/)', 'G'], ['(/)', 'H'], ['(/)', 'I'], ['(/)', 'J'],
67+
['(/)', 'L'], ['(/)', 'Z'], ['(%)', 'F'], ['(%)', 'G'],
68+
['(%)', 'H'], ['(%)', 'I'], ['(%)', 'J'], ['(%)', 'V'],
69+
['(%)', 'K'], ['(%)', 'L'], ['(%)', 'M'], ['(%)', 'N'],
70+
['(%)', 'O'], ['(%)', 'W'], ['(+)', 'A'], ['(+)', 'B'],
71+
['(+)', 'C'], ['(+)', 'D'], ['(+)', 'E'], ['(+)', 'F'],
72+
['(+)', 'G'], ['(+)', 'H'], ['(+)', 'I'], ['(+)', 'J'],
73+
['(+)', 'K'], ['(+)', 'L'], ['(+)', 'M'], ['(+)', 'N'],
74+
['(+)', 'O'], ['(+)', 'P'], ['(+)', 'Q'], ['(+)', 'R'],
75+
['(+)', 'S'], ['(+)', 'T'], ['(+)', 'U'], ['(+)', 'V'],
76+
['(+)', 'W'], ['(+)', 'X'], ['(+)', 'Y'], ['(+)', 'Z'],
77+
['(%)', 'P'], ['(%)', 'Q'], ['(%)', 'R'], ['(%)', 'S'],
78+
['(%)', 'T'],
3479
];

src/barcodes/CODE93/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import CODE93 from './CODE93.js';
2+
import CODE93FullASCII from './CODE93FullASCII.js';
23

3-
export {CODE93};
4+
export {CODE93, CODE93FullASCII};

src/barcodes/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ITF, ITF14} from './ITF/';
55
import {MSI, MSI10, MSI11, MSI1010, MSI1110} from './MSI/';
66
import {pharmacode} from './pharmacode/';
77
import {codabar} from './codabar';
8-
import {CODE93} from './CODE93/';
8+
import {CODE93, CODE93FullASCII} from './CODE93/';
99
import {GenericBarcode} from './GenericBarcode/';
1010

1111
export default {
@@ -17,6 +17,6 @@ export default {
1717
MSI, MSI10, MSI11, MSI1010, MSI1110,
1818
pharmacode,
1919
codabar,
20-
CODE93,
20+
CODE93, CODE93FullASCII,
2121
GenericBarcode
2222
};

test/browser/tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function createTests(newTest){
2424
newTest("A1234567890A", {format: "codabar", width: 1});
2525
newTest("C1234567890D", {format: "codabar", width: 1});
2626
newTest("ABCDEFG", {format: "CODE93", width: 1});
27+
newTest("ABCDefg!", {format: "CODE93FullASCII", width: 1});
2728
newTest("12345674", {format: "GenericBarcode", width: 1});
2829
newTest("Such customize!", {
2930
width: 1,

test/node/CODE93.test.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,52 @@ var Canvas = require("canvas");
66
describe('CODE93', function() {
77
it('should be able to include the encoder(s)', function () {
88
CODE93 = JsBarcode.getModule("CODE93");
9+
CODE93FullASCII = JsBarcode.getModule("CODE93FullASCII");
910
});
1011

1112
it('should be able to encode normal text', function () {
13+
const encoded = "1010111101101010001101001001010010001010001001100101101110101001010111101";
14+
1215
var enc = new CODE93("AB12", {});
13-
assert.equal("1010111101101010001101001001010010001010001001100101101110101001010111101"
14-
, enc.encode().data);
16+
assert.equal(encoded, enc.encode().data);
17+
18+
var enc = new CODE93FullASCII("AB12", {});
19+
assert.equal(encoded, enc.encode().data);
20+
});
21+
22+
it('should be able to encode full ASCII', function () {
23+
// Lowercase characters
24+
var enc = new CODE93FullASCII("ABab12", {});
25+
assert.equal("1010111101101010001101001001001100101101010001001100101101001001010010001010001001001100101011101101010111101",
26+
enc.encode().data);
27+
28+
// Special characters
29+
var enc = new CODE93FullASCII("AB!*12", {});
30+
assert.equal("1010111101101010001101001001110101101101010001110101101001101001010010001010001001100101001101011001010111101",
31+
enc.encode().data);
32+
33+
// Non-printable ASCII characters
34+
var enc = new CODE93FullASCII("AB\x07\x09", {});
35+
assert.equal("1010111101101010001101001001001001101011010001001001101011000101011010001011011001010111101",
36+
enc.encode().data);
1537
});
1638

1739
it('should warn with invalid text', function () {
40+
// Lowercase characters
41+
var enc = new CODE93("ABab12", {});
42+
assert.equal(false, enc.valid());
43+
44+
// Special characters
1845
var enc = new CODE93("AB!12", {});
1946
assert.equal(false, enc.valid());
20-
});
2147

22-
it('should make lowercase to uppercase', function () {
23-
var enc = new CODE93("abc123ABC", {});
24-
assert.equal("ABC123ABC", enc.encode().text);
48+
// Non-printable ASCII
49+
var enc = new CODE93("AB\x07 ", {});
50+
assert.equal(false, enc.valid());
51+
52+
// Non-ASCII
53+
var enc = new CODE93FullASCII("ABð", {});
54+
assert.equal(false, enc.valid());
2555
});
2656

2757
it('should calculate correct checksums with special character checksum values', function () {

0 commit comments

Comments
 (0)