metafloor / bwip-js

Barcode Writer in Pure JavaScript
Other
2.12k stars 305 forks source link

Embedded linux run bwip-js with duktape or mujs? #19

Closed linhuikui closed 7 years ago

linhuikui commented 9 years ago

Hi: I need run bwip-js in embedded linux without browser and without node.js (too big). Is it possible to run bwip-js with duktape or mujs, the bwip-js and mujs are javascript interpreters?

metafloor commented 9 years ago

bwip-js does not currently rely on any ecmascript 6 features (that may change in future versions) so it should be able to run in duktape or mujs. I do not use those platforms, so I have no way to develop interfaces for them.

There are two pieces of functionality the embedding will need: TypedArrays and zlib. You need binary buffers for the emscripten compiled freetype.js and for rendering images efficiently; and zlib for the PNG compression. duktape appears to have the binary buffers but not zlib. You can use NUL-compression in the PNG (but image sizes may be too large), or port zlib to duktape.

One unknown is how the freetype module will behave. The emscripten compiler adds boilerplate code for running in node.js, typical browsers, and a "generic" javascript environment. I am not sure how that code will react in duktape.

If you want to try porting bwip-js to either duktape or mujs, I can hopefully answer any questions you may have during the development.

linhuikui commented 9 years ago

my purpose is the binary string, do not the .png files. I just want get the string after encodered, and print by my printer. my javascript and html are poor, and my english is poor.(^ ^). It is thanks a lot, if you give some advices for how to get the binary string after encodered and the string interpretation. Thanks.

metafloor commented 9 years ago

Below is a link to the node.js test driver I use for comparing BWIPP (using ghostscript) to bwip-js. It disables the rendering by adding the option dontdraw. When a renderer is not called, a dictionary object is left on the postscript stack that contains the encoding information.

(This does not work with any bar code type that has the word composite in its name or description. Composite symbols ignore the dontdraw option.)

node-test.txt (Remove the .txt extension - github does not allow attaching extension-less files...)

See the very bottom of the file where there is a series of console.log() output. You extract the dictionary object from the stack using var dict = bw.pop().

Which bar code types are you using? Linear? 2D (like qrcode or datamatrix)?
The bar code type matters at it determines how to extract the encoding data from BWIPP.

If working with linear bar codes, the dictionary object will contain the encoding in the sbs (spaces and bars) property, along with bar height information in the bbs (baseline offset) and bhs (bar height) properties.

If working with 2D bar codes, the dictionary object will contain the pixs value, which is the dots encoding, along with with the dot dimensions in the pixx and pixy properties and overall symbol size in the width and height properties.

You will need to experiment with these values to truly understand how they work.

terryburton commented 9 years ago

"(This does not work with any bar code type that has the word composite in its name or description. Composite symbols ignore the dontdraw option.)"

Bug raised: https://github.com/bwipp/postscriptbarcode/issues/54

linhuikui commented 9 years ago

Thanks. you know, node.js is much bigger for embedded linux. so, I was try hard to run bwip-js with duktape or mujs, and does not need the .png files, but the string after encoded and the rows and colums of the binary string. if it is meaning the font are does not needed? It seems duktape and mujs can't load much js files.

metafloor commented 9 years ago

The node-test driver was given as an example of how to work with bwip-js where you do not render to images. The dontdraw option plus ensuring that includetext is not an option will keep the freetype font logic from coming into play. That will save lots of JavaScript bandwidth.

You will need to adapt the code to work with duktape. I am not familiar with duktape's limits or abilities so how may bar code generators you can load simultaneously will have to be determined empirically.

metafloor commented 8 years ago

Please download the new version 1.0 release. Code size has been dramatically decreased and asynchronous loading has been eliminated (both with the BWIPP cross-compiled code and with freetype). This should make bwipjs more usable in limited javascript environments. I still support IE10, so the code does not take advantage of any new-fangled language features.

metafloor commented 7 years ago

I am closing this as the issue is inactive.