user2918461
user2918461

Reputation:

Where are characters stored for display?

Open a terminal. Type some stuff. Some characters appear on the screen. Where are the characters you see stored on disk? In what format are they stored?

I'm dreaming of a silly little project to teach my students about unicode and text encodings. I want to show that \x24 doesn't mean "$" - it's just printed that way because that's the way the computer is told to represent those bytes when you tell it that they are encoded utf8.

I don't want to handle this within my application with a map or anything, I want to know where in the depths of my ubuntu installation can I find a file that instructs the os/application/whatever to render the character 00100100 as $.

Does anyone know? I wonder if the solution is simple or really hairy.

Upvotes: 1

Views: 378

Answers (2)

that other guy
that other guy

Reputation: 123620

Different terminals use different font rendering mechanisms, and get their font data from different places in different formats.

VGA consoles will by default use a font stored in the VGA BIOS. New fonts can be loaded and written to VRAM from /usr/share/consolefonts or /usr/lib/kbd/consolefonts or similar with setfont. On disk they're stored in an ancient DOS .psf format. Characters are not rendered by the OS, but by the VGA adapter itself.

FB consoles use bitmap fonts compiled into the kernel. They're declared in C files in the kernel tree like lib/fonts/font_8x16.c like this (squint a bit to see that the 1s form a dollar sign):

/* 36 0x24 '$' */
0x18, /* 00011000 */
0x18, /* 00011000 */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0xc2, /* 11000010 */
0xc0, /* 11000000 */
0x7c, /* 01111100 */
0x06, /* 00000110 */
0x06, /* 00000110 */
0x86, /* 10000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0x18, /* 00011000 */
0x18, /* 00011000 */
0x00, /* 00000000 */
0x00, /* 00000000 */

Characters are rendered by the FBcon driver in drivers/video/console/newport_con.c putc.

Older X11 terminals like xterm will use X11 core fonts, stored as PCF bitmap fonts or (later) PostScript fonts, these days usually found in /usr/share/fonts/X11. Characters are rendered by the X11 server.

Modern X11 terminals like gnome-terminal and konsole will use XFT fonts, stored in TrueType or OpenType format in /usr/share/fonts. They're rendered by the X11 client through the FreeType library.


For a low level OS class, changing the VGA font might be a good trick. For a high level IT class, you could edit a TrueType font to show different things and switch between the fonts in a text processor.

PS: WingDings already demonstrates this by e.g. drawing J as a smiley face:

Outlook screenshot showing that J turns into a smiley when the font is changed to Wingdings

Upvotes: 1

user2918461
user2918461

Reputation:

Thanks to Kirill, I found that they were in my font directories. I went to the following locations

/usr/share/fonts /usr/local/share/fonts

The fonts seem to be in some binary format. vi font.ttf just shows a bunch of garbage. Next I

rm -rf *

Now all of my programs are mad at me and throw up these error messages, but I can't understand what they're complaining about.

I did this in virtual box, no one faint.

enter image description here

Upvotes: 2

Related Questions