Software, technology, sysadmin war stories, and more. Feed
Tuesday, March 13, 2012

Treating bar codes as just another font

After I had been doing my thing as a sysadmin for that school district for a little while, people started figuring out that they could bring strange problems and requests to me. They had this sense that even if I didn't have something which would solve the problem, I could probably find it or make it. They were right.

Each school had a member of faculty who was their tech connection to the people like me at the district level. We got to know them pretty well. One of those people eventually left that role and became a librarian at another school. One day, she sent me an interesting request. Her library was starting to do inventory with some new system, and she needed something which would help with their bar codes. That's when I heard about it.

At first, it started simply. The librarians would have a sequence and needed to generate a code 39 check digit. They pointed me at a page which explained how it all worked, so I wrote a small tool which would calculate that check digit given arbitrary input. I put a small web interface as the frontend to this and turned them loose on it. They liked this, and soon requested the ability to generate check digits for a range, so I added that, too.

After a few months, it expanded again. Now, they wanted to have the actual bar codes on the result page. This request came with more URLs detailing their specs and one of them even had a TrueType font file! That's all I needed to know.

A couple of minutes later, I had glued libgd and freetype2 together along with my usual CGI backend stuff to make it generate arbitrary bar codes based on the query string. Then I just put some IMG SRCs in the output from my first program and it was ready for a test. At first, they didn't report success. It was a little fiddly since I was trying to make something which would scan properly for them, and they were in another state.

Finally, I had an idea: the CueCat. This was an odd little PS/2 keyboard wedge type device which had been given away by Wired and Radio Shack and a few other places towards the end of the '90s. I still had mine, and figured maybe it could help. I wound up wasting a lot of paper and toner before finding out that it wouldn't parse code39 bar codes beyond 11 characters, including the check digit.

After a whole lot of screwing around with a GNU barcode utility, I finally got it to generate something that my CueCat would read. With that as a reference, I turned back to my own program to figure out how to make it behave. Ultimately, I had to do a lot of font size adjustments to get the width right and then had to triple the height to make it work.

But how do you triple the height when you can't grow the font size without also spreading out the "characters"? I came up with an evil hack of a solution: just generate the output string three times and carefully align them so that they overlap vertically. It looked like this...


... but they were rendered as bar codes, naturally.

This yielded pretty good results. I heard back from the librarians and they said it was just a bit too wide for their scanner. Apparently it didn't use the "swipe" method like my CueCat and was a "hold it in place" thing. This forced me to adjust the size downward just a bit while testing to make sure it wouldn't mess up scans.

After a lot of back-and-forth, it was finally done, and they loved it. I had just been running it on my old workstation machine for internal purposes, but they wanted to share it with others outside our school district. I eventually just created a new host name in DNS and set up a virtual host in Apache which did nothing but serve up fresh bar codes.

These were good times. Real people had a real problem and I was able to solve it and make them happy. I miss that part of the job.