When we last left the barcode software we had a set of images that represented every character in the Code 128 symbology. There was a Microsoft ExcelWebApp (really a downloadable spreadsheet) that you could use to type in a string to generate your own barcodes. There was also a very in-depth discussion about how you can roll your own barcodes using this same technique.
If you have a little HTML experience, this set of images is all that you need to put a barcode on a website or embed one into an e-mail. The drawback of this method is that it is a little cumbersome and not very highly interactive. If you want several dozen barcodes, the “brute force” technique, as I call it, is not very efficient.
That is why, during my original postings, I hinted that the real ‘Wow!’ factor is in utilizing JavaScript to take a lot of the drugework out. This technique is what I am ready to share now. The barcodes have been streamlined and now provide the ability to represent any one of dozens of different symbologies including Code 128, Code 39, Interleaved 2 of 5, UPC and even 2D symbologies like QR Code and PDF417.
The 2D symbologies had me stumped for a little while because of a much more elaborate error-correction scheme utilizing Reed-Solomon codes. I will have more on that later, but suffice it to say 2D barcodes rely on a buffer of error-correction bytes. These bytes not only inform the scanner if a barcode has been damaged, but help the barcode reader piece together the correct data in the barcode so it doesn’t necessarily have to report an unreadable symbol.
In order to produce the JavaScript driven version of the barcodes, I had to make a couple of changes:
- The symbols themselves had to go.
- Separate the symbology-specific logic from the rendering.
The Symbol Agnostic “Metafont”
In order to most efficiently use JavaScript to produce barcodes, the specific barcode symbology (Code 128, UPC, Datamatrix, etc.) needs to be “built” at run-time. Otherwise you find yourself spending weeks in drawing packages rendering little bit-wise versions of each character set.
What you can do with JavaScript, instead, is give the software the means of producing bars and spaces with a limited set of PNG files and drive the data that is specific to the methodology out to the barcode generator. In other words, once JavaScript knows how to produce the bars and lines and spacing, you can feed it flags or ‘1’s and ‘0’s to explain the symbol specific messages. As I mentioned in an earlier post, barcodes are a computer’s Morse code. As such, the JavaScript barcode rendering engine is like the telegraph machine and wiring. The operator software is separate and it alone knows the details of each symbology.
The big disadvantage of the new method is the fact that we will not be seeing the alternate and title text associated with each barcode character. Since the Javascript that generates the bars is no longer speaking any particular barcode dialect, it doesn’t really know what it is rendering.
Separated For Their Own Good
Separating the “operator” from the “equipment” allows the operator to specialize in the idiosyncrasies of the symbology. All symbology-specific code can be held in an external JavaScript file, so it only loads if the application requires it. That means another visit to the server, but a much smaller initial package and simpler symbologies like Interleaved 2of5 and Code 39 do not have to bear the overhead of QR Code or PDF417.
Separation also allows the “equipment” to be super lean and lightning fast. Rendering a barcode becomes its “hedgehog” and that JavaScript function can forget about every other thing.
Conceptual Introduction
Before I divulge the complete package, I want to walk through the creation of the new software. I also want to have an understanding, up front, that this software has been contrived by yours truly. Therefore, in its published form, it will contain the following text:
The MIT License (MIT) Copyright (c) 2013, Notionovus, LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You are approved to use the software as you see fit, but if you use the software in its entirety in a republished work, it is expected that credit will be given and the copyright notice will not be removed.
In the next installment of this series, we will dive into the mechanics of the barcode generation code. Until next time, thank you for tuning in.