Printing with human sized characters

First off this has nothing to do with CUPS. On the R01 its an obscene burden I’d rather do without and for some reason the CUPS print is abnormally huge. Most of my printing will be done from the shell or programs I write myself. Using the DevTerm’s “printer” service is perfect for this… almost. So if you’re looking for CUPS related stuff you’ll have to look elsewhere.

For me, the problem with the printer service is readabilty. The print size was WAY smaller than any thermal/receipt printer I’ve ever seen. And I’ve seen many! Looking through the printer software’s README.md and following what was there was problematic. One gotcha is that because BASH is written in C and \x0 | \0 have special meaning (end of string) in C its likely that that byte and anything after it never get sent. I haven’t done specific testing to (dis)prove this. The README.md also didn’t mesh well with my brain. So here is what I found perusing the source…

The source is setup to use a few internal fonts OR one external TTF font. The largest internal font, which is the default, is 8 pixels wide. According to remarks in the source and the datasheet a pixel is 1/8th mm. That means that the largest font uses 1mm wide chars, which may be fine for nats, ants and the optically gifted, but not for mere humans. And the font size only goes down from there.

A typical receipt printer prints at about 12cpi, which equates to about a 2mm wide char (2x the size). They might go a bit smaller but nothing less than 1.5mm. So how do we get human size print? Since there aren’t any viable built-in fonts I moved on to the external font option. It turns out that the service comes pre-configured to use an external font. They refer to this in the README.md as the UNICODE mode. This is because the TTF font supports more than the base ASCII set, which is all the internal fonts support.

It turns out that the printer driver supports 5 fonts. Either the 5 built in unusable fonts or the external font at 5 different sizes. Further testing showed that sizes 2-4 (numbers start at 0) are usable. For me size 3 is good. This leaves me with one fine print size, a regular size, and a big print size.

So! How do we get these printing? In BASH we can initialize the printer like so:

$ echo -en '\e!\x1\x1d!\x3' > /tmp/DEVTERM_PRINTER_IN

FYI: the ‘!’ (exclamation mark) is hex code \x21, which is seen in their README.md I just prefer characters I can see.

After sending that sequence any text sent to the /tmp/DEVTERM_PRINTER_IN pipe will be printed in human size fonts! AND as a bonus you get non-ASCII language support too! If the font reverts for some reason just resend the sequence.

Explanation: The first 3 bytes starting with the ‘\e’ (Escape, \x1b, 27) selects the external TTF font (UNICODE mode) the final sequence starting with \x1d selects font (size) 3 (\x3). You can replace the \x3 with any value in the range of \x0 to \x4.

Last notes on fonts: The external font used by the printer driver is set in the /usr/local/etc/devterm-printer file. There is an environment variable defined there named TTF you could point this to a different font. You would then have to restart the printer service to make it official and then re-send the sequence shown above since the service will revert to the default built-in font upon restart.

JIC you haven’t seen the README.md it can be seen on GitHub.

5 Likes