Skip to content

Commit

Permalink
Fix in PostScript emulation for new DataMatrix code.
Browse files Browse the repository at this point in the history
  • Loading branch information
metafloor committed Sep 22, 2015
1 parent fb03fa3 commit 5ffb440
Show file tree
Hide file tree
Showing 101 changed files with 6,754 additions and 10,463 deletions.
30 changes: 7 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ All linear and two-dimensional barcodes in common use (and many uncommon
ones) are available. An exhaustive list of supported barcode types can be found at
the end of this document.

## Note to DataMatrix Bar Code Users

If you are using bwip-js version 14.0.0 or 14.0.1, please upgrade immediately.
There was a PostScript emulation bug that was exercised by new code added to
BWIPP version 2015-08-10. bwip-js version 14.0.2 fixes the issue.

## Status

* Current bwip-js version is 0.14.1 (21-Sep-2015)
* Current bwip-js version is 0.14.2 (22-Sep-2015)
* Current BWIPP version is 2015-08-10
* Node.js compatibility >= v0.10 (reported to work with v0.8 but not tested).
* npm dependencies: none
Expand Down Expand Up @@ -320,25 +326,3 @@ BWIPP cross-compiled code was not straightforward.

• AusPost 4 State Customer Code • Aztec Code • Aztec Runes • BC412 • Channel Code • Codabar • Codablock F • Code 11 • Code 128 • Code 16K • Code 25 • Code 39 • Code 39 Extended • Code 49 • Code 93 • Code 93 Extended • Code One • Compact Aztec Code • Compact PDF417 • COOP 2 of 5 • Custom 1D symbology • Custom 4 state symbology • Data Matrix • Datalogic 2 of 5 • Deutsche Post Identcode • Deutsche Post Leitcode • EAN-13 • EAN-13 Composite • EAN-2 (2 digit addon) • EAN-5 (5 digit addon) • EAN-8 • EAN-8 Composite • Flattermarken • GS1 Composite 2D Component • GS1 Data Matrix • GS1 DataBar Expanded • GS1 DataBar Expanded Composite • GS1 DataBar Expanded Stacked • GS1 DataBar Expanded Stacked Composite • GS1 DataBar Limited • GS1 DataBar Limited Composite • GS1 DataBar Omnidirectional • GS1 DataBar Omnidirectional Composite • GS1 DataBar Stacked • GS1 DataBar Stacked Composite • GS1 DataBar Stacked Omnidirectional • GS1 DataBar Stacked Omnidirectional Composite • GS1 DataBar Truncated • GS1 DataBar Truncated Composite • GS1 QR Code • GS1-128 • GS1-128 Composite • GS1-14 • HIBC Codablock F • HIBC Code 128 • HIBC Code 39 • HIBC Data Matrix • HIBC MicroPDF417 • HIBC PDF417 • HIBC QR Code • IATA 2 of 5 • Industrial 2 of 5 • Interleaved 2 of 5 (ITF) • ISBN • ISMN • ISSN • Italian Pharmacode • ITF-14 • Japan Post 4 State Customer Code • Matrix 2 of 5 • MaxiCode • Micro QR Code • MicroPDF417 • Miscellaneous symbols • MSI Modified Plessey • PDF417 • Pharmaceutical Binary Code • Pharmazentralnummer (PZN) • Plessey UK • PosiCode • QR Code • Royal Dutch TPG Post KIX • Royal Mail 4 State Customer Code • SSCC-18 • Telepen • Telepen Numeric • Two-track Pharmacode • UPC-A • UPC-A Composite • UPC-E • UPC-E Composite • USPS Intelligent Mail • USPS PLANET • USPS POSTNET •


## Emulator Notes

bwip-js does not provide a general purpose PostScript emulation layer. The emulation
supports only the PostScript operators used by BWIPP and is implemented
as a cross-compiler that converts the non-graphics code to equivalent JavaScript,
and the graphics operations to calls into a simple bitmap interface.

The emulation uses, as much as possible, native JavaScript data types:
* Boolean values true and false
* Null value
* Numeric values (integer and float)
* Objects (PostScript dictionary object)
* Function objects

You will note that two of the more common JavaScript data types, strings and arrays,
are not on the list. PostScript implements live-view semantics with strings and
arrays, similar to JavaScript's Typed Arrays and Views. For that matter, PostScript
strings can be implemented using Uint8Arrays but PostScript arrays have no similar
JavaScript equivalent. We must wait for ECMAScript6's computed property name getters
and setters to land in the primary browsers before arrays can be handled cleanly.

30 changes: 26 additions & 4 deletions bwip.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var BWIPJS = function() {

// dict-stack lookup
this.dstk.get = function(id) {
if (typeof id == 'number')
id = '\uffff' + id;
for (var i = this.length-1; i >= 0; i--) {
if (this[i][id] !== undefined) {
return this[i][id];
Expand Down Expand Up @@ -86,6 +88,24 @@ BWIPJS.decrefs = function(module) {
}
}

BWIPJS.get = function(obj, id) {
if (obj instanceof BWIPJS.psarray || obj instanceof BWIPJS.psstring)
return obj.value[obj.offset+parseFloat(id)];
if (typeof id === 'number')
return obj['\uffff' + id];
// Explicit toString() to convert psstrings
return obj[id.toString()];
}
BWIPJS.set = function(obj, id, val) {
if (obj instanceof BWIPJS.psarray || obj instanceof BWIPJS.psstring)
obj.value[obj.offset+parseFloat(id)] = val;
else if (typeof id === 'number')
obj['\uffff' + id] = val;
else
// Explicit toString() to convert psstrings
obj[id.toString()] = val;
}

// FreeType interface
BWIPJS.ft_monochrome = Module.cwrap("monochrome", 'number', ['number']);
BWIPJS.ft_lookup = Module.cwrap("find_font", 'number', ['string']);
Expand All @@ -109,7 +129,6 @@ BWIPJS.logapi = function(fn, args) {
};
//BWIPJS.load = function(s) {}; // force a run-time error


BWIPJS.psarray = function(v) {
if (!(this instanceof BWIPJS.psarray))
return new BWIPJS.psarray(v);
Expand Down Expand Up @@ -229,7 +248,6 @@ BWIPJS.psstring.prototype.valueOf = function() {
s += String.fromCharCode(this.value[i]);
return s;
}

BWIPJS.psstring.prototype.get = function(n) {
return this.value[this.offset+parseFloat(n)];
}
Expand Down Expand Up @@ -312,8 +330,12 @@ BWIPJS.pstostring = function(v) {
}
if (typeof(v) == 'object') {
var s = '';
for (var i in v)
s += ' /' + i + ' ' + BWIPJS.pstostring(v[i]);
for (var i in v) {
if (i.charCodeAt(0) == 0xffff)
s += ' ' + i.substr(1) + ' ' + BWIPJS.pstostring(v[i]);
else
s += ' (' + i + ') ' + BWIPJS.pstostring(v[i]);
}
return '<<' + s + ' >>';
}
// Watch for the usual floating-point nonsense
Expand Down
Loading

0 comments on commit 5ffb440

Please sign in to comment.