Intel's Ronler Acres Plant

Silicon Forest

Saturday, April 22, 2017

Fun with Fonts

Lowercase Letter A with a couple of obscure measurements.
I've been working intermittently on my gears program. I want to replace that static initialization with a GUI (Graphical User Interface) that would allow modifications on the fly. One of the first things you need is the ability to write text on the screen. I found and tried a sample program and amazingly it worked. However, the text on the screen was kind of skinny and feeble looking, so I'm going to need a different font, and OMG, what a Pandora's box I have opened.

Back in the good old days before these nasty little PC's took over, any time you needed to talk to a computer you used a terminal. A terminal had a CRT screen that would display (typically) 25 lines with 80 characters each. A serial data cable connected your terminal to the computer, or if you were on another planet, to a modem.

When you pressed a key on the keyboard, the terminal sent the ASCII code for that character to the computer, and when the computer had something to say to you, it sent the ASCII codes to the terminal. Formatting was limited to deciding when to end a line of text. When a line ended, the action moved to the next line. If the screen was full, the line at the top of the screen scrolled off the top and was never seen again.

This worked fine until some people (like SGI) decided they wanted to draw pictures. Then the PC and Windows came along and now things get a little more complicated. When you sent a character code to a terminal, the terminal was hard wired to display that character. There was only one font and only one character set, so on one hand you were restricted with what you could do, on the other you were free from having to learn a whole bunch of obscure bullshit.

Now with modern computers with hi-resolution displays, when you want to write a character to the screen, the computer has to look up picture for that character from the font you have chosen (or had chosen for you) and copy it into display memory in the correct location, which depends on a whole bunch of typesetting and window management rules.

Okay, I don't like the default font, which font should I use? Well, for starters, how many fonts are there? Only about a zillion. I suspect there might be a thousand on the machine I am using. Now some of them are the same font, just rendered in different sizes and / or with special features like bold or italic, and some of them are foreign languages or sets of funny characters, like dingbats or Russian.

Still, there are a bunch of fonts. There has to be a better way to get a handle on them that just listing them using xlsfonts. My first thought was to take the list and edit it into something I could import into a spreadsheet. That might have helped, but it would have been a lot of work, and I would still have a thousand entries. Then I got to thinking I could write a program (using xlsfonts.c as a model) that could identify fonts with common attributes, like typeface, or size, or even just whether they are fixed pitch or proportional fonts.

So I'm poking around in xlsfonts.c and I find a bit of code that determines whether it is a fixed or proportional pitch font, except there is third kind of font called a 'character cell' font, which confuses the heck out of me. I do some digging around and find this:
The type of spacing (S): p (“proportional”) for variable-width fonts, m for monospaced
fonts, c for character-cell fonts. The difference between a monospaced font and a
character-cell font is signi´Čücant. In monospaced fonts, the offset between the glyph’s
point of origin and that of the following glyph remains unchanged; the glyph it-
self may lie partly or entirely outside the abstract box whose width corresponds to
this offset. In character-cell Fonts, there is one additional property: the pixels of the
glyph, which are entirely contained within this abstract box. A character cell font is
monospaced a fortiori: the converse may not be true. Nonetheless, most monospaeed
fonts (such as Courier or Computer Modem Typewriter) can be regarded as character-
oell fonts, since they simulate the output of the typewriter, which was a source of
inspiration for the character-cell fonts. - Fonts & Encodings by Yannis Haralambous
So, if I am reading this correctly, both monospaced and character-cell fonts allocate a fixed block of space on the screen. Characters from character-cell fonts will appear entirely within this block. However, characters from monospaced may appear anywhere in the universe, well, anywhere on the plane of your display screen. Of course, any character whose location will place it outside of the screen will not appear. Computers are not very smart, but they generally can tell if it can display something or not.

I haven't come across any examples of characters that exist outside the box, they may be used to place accent marks. But that is just a suspicion. They might be used by the NSA to send encrypted messages to their agents or for some other nefarious purpose. I will let you know if I find any.



No comments: