id_barcode – a barcode maker for Adobe InDesign
id_barcode is multiple things. It’s an example of writing structured, modular code for an InDesign plugin. It’s a demonstration of test-driven development for producing InDesign plugins. It also makes barcodes.
InDesign barcode maker
First off, this is a barcode maker for InDesign. It’s fairly simple – just put in your ISBN, and choose the font for the ISBN and for the numbers under the bars.
Here it is:
and this is what the barcode looks like:
Writing modular InDesign plugins
I split id_barcode across four files:
- barcode_library.js (the actual barcode logic)
- barcode_test.js (test code for testing barcode_library.js)
- dropdown.js (a dropdown menu widget)
- barcode_main.js (the GUI and code for rendering the barcode)
Really barcode_main.js should be split up into two files, one for the GUI and one for rendering the barcode.
Each part of the code does one thing. barcode_library doesn’t know anything about InDesign, all it does is produce a data structure giving the relative bar widths. The GUI code doesn’t contain any logic, it just lets the user enter the relevant details. Then the rendering code takes the barcode from the GUI, uses the library to get the bar widths, and draws the barcode with these widths and the fonts selected by the user.
#import lines. This was pretty straightforward.
So far this plugin is very basic. You can’t customise anything apart from the fonts, so if you standardly use a different barcode design you’d need to do manual work to each barcode. The error handling’s a bit rubbish as well. If I make it more customisable, I think it would be worth test-driving the layout changes. The most important thing is to write a test that ensures the bars are all the correct width. I’d then have to start delving further into InDesign’s object model, which is a bit of a mess. We’ll see.
If anybody’s interested in contributing you can fork me on github!