Type

Unicode Code 2 PDF


“Now witness the firepower of this fully armed and operational battlestation enscript replacement”.

Back in the day, when OSU had licenses for Adobe TranScript to drive all the laser printers on campus, I was pretty much the only person who really understood how it worked. So much so that after I left for California, the Physics department’s sysadmin gave me an account on his servers to help him get a new version to work.

Somewhere along the line, Adobe stopped actively supporting PostScript (having given up the rights in order to make it a public standard), and TranScript went away, taking with it the extremely useful enscript text-to-PostScript utility.

Which was reimplemented a-bit-too-faithfully by GNU folks, and then crufted up with useless garbage. Mind you, full compatibility already made it pretty crufty, because the original Knew Way Too Much about how Unix PostScript printer management worked in the late Eighties and early Nineties. What GNU-enscript hasn’t done is keep up with the times: the last release was 12 years ago.

No features. No fixes. No Unicode. No OpenType fonts. No PDF output.

That last bit was particularly grating for me, because a few releases back, Apple abandoned PostScript rendering completely, so the only convenient way to print decades of documents is by shoving them through GhostScript’s ps2pdf, which works, if you’re comfortable with their history of not taking security seriously (grumblegrumble getoffamylawn).

[yes, the free Acrobat Reader still exists, and handles PostScript, but it’s slow to launch and crufted up with Adobe’s attempts at revenue extraction; I have the full Acrobat Pro from the Adobe CC suite, and it’s even slower and cruftier]

I just wanted Unicode text, set in any available fixed-width font, neatly paginated with page numbering and headers/footers, written directly to a PDF file. There are a number of open-source tools that advertise some of these capabilities, but all the ones I’ve tried suck to some degree. Writing my own has been an idea gathering dust in my note-taking apps for several years, but after completing my rewrite of longpass in Python, I decided to finally take a stab at it.

First up, the name: I’ve kept track of all the text-to-pdf tools I came across, brainstormed to find something better, then googled to see which ones had unfortunate connotations. TL/DR: I’m not happy with it, but uc2p is at least short, inoffensive, and fairly unique, so that’s been the working name of the project.

Second, the code. Porting the box and paper modules from PDF::Cairo gave me flexible layout and styling, and after abandoning ReportLab’s Platypus subsystem in favor of the lower-level PDFgen, I was quickly able to knock together some prototypes over the past few days.

The code (~1,200 lines, including libraries) needs a cleanup pass and a real config file for styles, but here’s a sample page of output in the classic -2rGL66 style (two-up, rotated, gaudy headers, 66 lines/page).

By the way, at least with later versions of Adobe’s enscript and with the GNU clone, that -L 66 doesn’t actually do anything useful; -l auto-resizes the font to put exactly 66 lines on each page or column, but it’s incompatible with any page headers or footers. It was kind of an accident that -2rGL66 ever worked as expected; IIRC, it got broken by a margin change in the template in Adobe’s version, and that was faithfully copied by GNU.

What -L N actually does is ensure that no more than N lines will appear on a page. So you could leave the bottom half of the page blank by setting -L 30, for no good reason. My new script, on the other hand, always fits exactly N lines into the space.

Anyway, I’m abandoning drop-in compatibility, so I’m currently going through the various options, giving sensible single-letter abbreviations to the most common ones and moving the rest to a catchall -O opt1=val -O opt2 .... Which will match the structure of the config file where I define layout styles.

Just for fun, a few people out there still have extremely stale web sites, so it’s possible to see what options the Adobe version had in 1992. I love that multi-column printing was under -v, and that there were two completely different one-character options for “send email after job prints” (-w and -m).

And of course everything related to “job burst pages”, something that I haven’t seen in so long that I forgot it was a thing.

Unrelated,

“Dear Amazon, why are you so forcefully recommending a book on talking to small children about sex? I’m pretty sure I’ve never bought anything that would make that relevant for me, or I’d have already gotten a knock on the door from federal agents…”

Iosevka Termanal


So, yeah, I rolled my own. The primary change from the prebuilt SS02 version was that I made it standard-width and a bit lighter. And reversed the slash on the zero, just because I could. I included the build plan and the necessary diffs in the Zip file, and only built Regular and Bold with their matching italics.

Completely unrelated, Amazon recommended a new manga series to me: To Save The World, Can You Wake Up The Morning After With A Demi-Human?. In which Our Hero’s mission is to knock up as many monster girls as possible in the hope that one of them will give birth to The Chosen One who will defeat The Demon Lord.

Except that he’d really rather just hold hands with the cute elf girl in his homeroom class. And he passes out whenever the girls get him excited. And then they do him anyway while he’s out. And the more often they all get a fill-up, the more potent his secret sauce becomes, so they’re all willing to share. Even the Legal Loli dwarf girl who can’t quite wrap herself around it yet.

Not an isekai, apparently, just a perfectly ordinary Japan with a wide variety of horny monster girls and a recurring Demon Lord infestation.

9/2 update

I decided to make the bold a bit bolder, to better differentiate it at various sizes. Zip file updated.

More fun with programming fonts


After working with SomeType Mono for a little while, I decided to quantify my font ratings.

I started by dusting off my old fontforge svg2ttf script, since I knew its Python API exposed everything I needed. Then I discovered that I can’t get that API to work any more. Somewhere between the Python 2->3 updates and Homebrew’s descent into madness, it done broke.

I know how to extract metrics and outlines using Font::FreeType and Cairo in Perl, and most of what I need is already exposed in my PDF::Cairo module, but I’d have had to do some mucking about with internals to get it all, and it would have added a messy dependency should I decide to share the script.

So I switched to Adobe Font Toolkit, which cleanly installs into a Python virtualenv without any issues. Its tx utility can both extract metadata and calculate precise bounding boxes for every glyph, which allows me to measure many of my concerns:

FONT OfficeCodePro-Regular.otf
x-height 69.012% of ascender height
relative width 100.000%
vertical centering offset from '=':
! greater -3.79%
! less -3.79%
! parenleft -7.04%
! parenright -7.04%
! bracketleft -7.04%
! bracketright -7.04%
! braceleft -7.04%
! braceright -7.04%
! bar -10.83%
width compared to '=':
! asciitilde +4.19%

This tells me that Office Code Pro has a standard typewriter width (Courier, Prestige Elite, etc), a decent x-height, equal widths for -=+, a slightly-wide ~, common vertical centering for =-+~*&#%/\ and digits, a very small vertical offset for <>, a bigger one for ()[]{}, and an annoyingly large one for |. Since I’m not analyzing the glyph outlines yet, I can’t tell that it has a five-lobed asterisk and a slashed zero.

For comparison, here’s the latest release of Iosevka Fixed SS02 Regular:

FONT iosevka-fixed-ss02-regular.ttf
x-height 69.829% of ascender height
relative width 83.333%
vertical centering offset from '=':
! asciitilde -2.11%
! ampersand +3.62%
! percent +3.62%
! zero +3.62%
! X +3.62%
width compared to '=':
! asciitilde +19.47%

Similar x-height, much narrower, &% aligned with caps/numerals, and twiddle a hair low and extra-wide.

The last time I looked at Iosevka, all the “SSnn” variants were built with the same family name, so you couldn’t tell which of the sixteen variations you’d downloaded except by the file name. They’ve cleaned things up quite a bit, and now it’s fully scriptable so you can roll your own variation and Have It Your Way. The downside is that the repo is over 5 gigabytes. The other downside is that it uses npm.

Other fonts I’ve tried recently? IBM Plex Mono (painfully short hyphen, dotted zero, goofy #), Cascadia Mono (the dotted zero and goofy alphabet clobber its otherwise perfect score, although I’d use Light rather than Regular), Go Mono (five-lobed goofy asterisk, serifs, and inconsistent punctuation weight), JetBrains Mono NL (dotted zero, five-lobed asterisk, small-but-consistent vertical offsets for ()[]{}/\|~*), and Code Saver (short hyphen, high /\, low |).

Oh, and the name of my script? Termanal. If I ever roll my own custom font, obviously I’ll call it Termanal Regular. 😁

Update

Just found the current much-expanded version of the Inconsolata family. Slashed zero, ligatures off by default, five-lobed asterisk, annoyingly short hyphen, slightly-low [], annoyingly low |, eight weights, and nine widths (166%, 125%, 100%, 92%, 83%, 75%, 67%, 58%, and 42% for when you need all the columns).

Sometype Mono


I’m trying out a programming font, the free Sometype Mono. It avoids almost everything I hate about coding fonts, and beats out the previous champ Office Code Pro by not having an italic $ or five-lobed *. Set width is a bit narrower, but not as condensed as the same designer’s non-free Code Saver ($25 for 3 weights and matching italics, if you like squeezing a few extra columns into your windows). Specifically, an 80-column window of Office Code Pro will fit 83 of Sometype Mono, 86 of Code Saver, or 88 of my former standard Anonymous Pro.

I can get Code Saver through my Adobe CC subscription, but I’m going to start with the free one, since I’m setting up a new work laptop this weekend, and it won’t have an Adobe license.

Update

The Programming Fonts web site, which I hadn’t visited for a few years, includes Sometype Mono in its live previews, as well as an increasing number of cleanups of existing fonts to fix many of my complaints. The least-unreadable preview setting at the bottom is the base16-light color scheme and the None syntax coloring.

My new favorite programming font


I have a hate/tolerate relationship with so-called “programmer’s fonts”. Let me count the ways they suck, in no particular order:

  1. Not fixed-width. Blech.
  2. Too-narrow set width (ranging between condensed and crushed).
  3. Inconsistent weight/color between alpha, numeric, and punctuation. The creator of Fira Code actually managed to make \ and / different weights!
  4. Twee punctuation.
  5. Failure to adequately distinguish 0O, l1, etc.
  6. Dotted zero instead of slashed (so that 00 is staring at you; Hack takes this one step further, for an Eye-Of-Sauron effect).
  7. Inconsistent centerline for special chars (^>~*+=-})]|\/#$%&@).
  8. Special-char centerline inconsistent with digits.
  9. - not same length as + and = (surprisingly common!).
  10. Five-lobed asterisk, even worse when it’s upside-down.
  11. Poor rendering either on or off high-DPI displays.
  12. Special Dishonorable Mention to Monofur for having lower-case digits, seemingly-random centerlines, twee punctuation, and a generally obnoxious character design.

For a long time, I’ve been using Anonymous Pro, hand-edited to fix its centerline problem, but the new winner is Office Code Pro, which suffers only from a slightly-twee %, a slightly-italic $, a five-lobed *, and an ever-so-slight centerline offset for braces, parens, and the v-bar (most easily seen in the -{| combo).

It is hands-down the cleanest, most usable fixed-width font I’ve ever found, fixing almost every problem with its parent, Adobe’s free Source Code Pro. Pity the repo just has the compiled fonts rather than the source diffs, because I’d love to fork it and fix those last few niggling flaws.

Installing fonts from the DynaFont collection


Let’s say that you have purchased a shovelware disc of Japanese fonts, such as this one from DynaComWare (discontinued, but it turns up occasionally; I bought mine at a going-out-of-business sale).

[Note that when I describe this particular disc as “shovelware”, I’m really referring to the collection of 3,000+ renamed ripoffs of Western fonts (from font pirate Bay Animation) that are thrown in; for Japanese, Chinese, and Korean fonts, DynaComWare is a legitimate foundry.]

The ripoffs (as well as the Korean, Chinese, special-effects, and kana fonts) are just stored on-disc with no protection, but the good stuff is hiding in files with the .t4_ and .t9_ extensions. The only supported way to install them is by running the included Windows program (which might not display correctly on non-Japanese versions of Windows, and of course doesn’t work at all on a Mac), but it turns out that they’re just encrypted ZIP files with a simple 8-digit numeric password, six digits of which can be inferred from the timestamp.

One thing to note is that the disc contains two sets of kanji fonts, in directories labeled JIS90 and JIS2004. The difference between the two is a subtle appearance change in a small number of characters, neatly described in this Adobe PDF file. A small number of fonts are available only in the JIS90 flavor, mostly pseudo-bitmap fonts of little real value; most people won’t notice the difference, and if you do, well, you’ve got both.

I highly recommend the disc, by the way.

Anonymous Pro (still) FTW!


Adobe has released an Open Source coding font, appropriately named Source Code Pro. I tried it out, and while it’s mostly nice, a side-by-side comparison of the fixed-width fonts on my machine reconfirmed that the also-free Anonymous Pro still beats them all.

Of course, if you don’t write Perl, you might not need expressions like “$K[$i%@K]” to look good, but I still can’t be comfortable with any font where “00” looks like it’s staring at you…

And my test sample, if you’re interested, consisted of Andale Mono, Anonymous Pro, Consolas, Courier, Inconsolata, Monaco, Osaka, and Lucida Sans Typewriter.

Custom font mappings in World Tools Pro


World Tools Pro enables most of the hidden Japanese typography functionality in InDesign, but as I discovered the moment I tried to really use it, they left out the ability to add custom ranges to composite fonts. The fix is to create the composite font as usual, then open the Adobe ExtendScript Toolkit, paste in the following snippet of code, edit as needed, and run it:

app.compositeFonts.item(1).compositeFontEntries.add({
    name:"Macron",
    customCharacters:"āĀēĒīĪōŌūŪ",
    appliedFont:"Minion Pro",
    fontStyle:"Regular",
    relativeSize:100,
    baselineShift:0,
    verticalScale:100,
    horizontalScale:100,
    scaleOption:false
  });

Set the value of item() based on font’s position in the pulldown list; the meaning of the rest should be obvious.

“Need a clue, take a clue,
 got a clue, leave a clue”