PySFedit - An editor for PC Screen Fonts written in Python
#Coding#OsDevPySFedit is a graphical editor for PC Screen Fonts written in Python 3 using the GTK+ binding PyGObject. With PySFedit, one can create and edit PC Screen Font files and export them to multiple formats.
It is open source, the whole code is available on GitLab in the repository
kalehmann/PySFedit.
What is a PC Screen Font?
A PC Screen Font (abbreviated as PSF) is a bitmap font format mainly used by the Linux kernel for displaying text in the console.
There are two versions of PC Screen Fonts:
- the old type (PSF1)
- the new type (PSF2)
PSF1
The old type is fairly limited. A PSF1 font file contains either 256 or 512 glyphs. Each of these glyphs has a width of 8 pixels and all glyphs share the same height in pixels - which can be any value between 1 and 255 pixels.
Since each pixel occupies a single bit and the width of each glyph is constantly 8 pixels, the height of each glyph is equal to the size of its bitmap in bytes.
The glyph bitmaps may be followed by additional Unicode information describing the glyphs, otherwise every bitmap contains the character with the ASCII code equal to its position in the PSF file.
PSF2
The new type has some more features:
- support for possible future versions
- all glyphs have the same dimensions, but those can be selected freely
- variable number of glyphs
- optional Unicode table
How are the bitmaps stored?
The bitmaps are stored in binary form. In PSF1 every byte represents a line of the glyph. A one represents a set pixel and a zero represents an unset pixel.
For PSF2, a line may consist of more than one byte. If the width is not divisible by eight, the rest of the line is padded with zeros.
Here is an example for a PSF2 glyph with a width of 12 pixels and a height of 16 pixels representing an A:
| Offset | Line | Bytes | Pixels |
|--------|------|-------|--------------|
| 0x0000 | 00 | 00 00 | ............ |
| 0x0002 | 01 | 0F 00 | ....@@@@.... |
| 0x0004 | 02 | 1F 80 | ...@@@@@@... |
| 0x0006 | 03 | 39 C0 | ..@@@..@@@.. |
| 0x0008 | 04 | 30 C0 | ..@@....@@.. |
| 0x000A | 05 | 70 E0 | .@@@....@@@. |
| 0x000C | 06 | 60 60 | .@@......@@. |
| 0x000E | 07 | 60 60 | .@@......@@. |
| 0x0010 | 08 | 60 60 | .@@......@@. |
| 0x0012 | 09 | 7F E0 | .@@@@@@@@@@. |
| 0x0014 | 0A | 7F 60 | .@@@@@@@.@@. |
| 0x0016 | 0B | 60 60 | .@@......@@. |
| 0x0018 | 0C | 60 60 | .@@......@@. |
| 0x001A | 0D | 60 60 | .@@......@@. |
| 0x001C | 0E | 60 60 | .@@......@@. |
| 0x001E | 0F | 00 00 | ............ |How is the Unicode information stored?
If specified in the header, the glyph bitmaps are followed by a table of Unicode information, each describing the glyph bitmap at the corresponding position. The description consists of single Unicode values and sequences of Unicode values - for example a symbol with a combining accent.
Where to find further information about PC Screen Fonts?
There is very little information for this format available. Most of what you need can be found in the Linux source code, namely the psf header.
The homepage of the Eindhoven University of Technology contains also a revised version of this information.
There are some PC Screen Fonts preinstalled in most Linux distributions or at least included in the repositories.
| Distribution | Path | Package |
|---|---|---|
| Arch | /usr/share/kbd/consolefonts/ |
kbd |
| Fedora | /usr/lib/kbd/consolefonts/ |
kbd |
| Debian | /usr/share/consolefonts/ |
preinstalled |
| openSUSE | /usr/share/kbd/consolefonts/ |
preinstalled |
Those files are usually gzip compressed.
Applications for dealing with PSF files already exist. Do we really need a new one?
Yes… No… Maybe…
There are indeed other tools for dealing with PSF files, however I found none really convenient to use.
There is xmbdfed, a graphical font editor that supports several font formats including PSF. Still, it lacks the ability to deal with PSF fonts containing Unicode tables.
Moreover the psftools suite provides programs to convert PSF back and forth to text files - making it possible to edit fonts with a text editor.
Last but not least, the GitHub repository talamus/rw-psf contains two Perl scripts to convert PSF files back and forth to other formats.
What do we need PC Screen Fonts nowadays for?
Customizing the font of your console:
The PC Screen Font format is rather simple. It may be useful if you implement something to display glyphs from scratch, for example your own operating system ;)