PySFedit - An editor for PC Screen Fonts written in Python#Coding#OsDev
PySFedit is a graphical editor for PC Screen Fonts written in Python3 using the Gtk+-binding pygobject.
With PySFedit you can create and edit PC Screen Font files and export them to many formats.
It is open source, the whole code is available on GitLab in the repository kalehmann/PySFedit.
What is a PC Screen Font?
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)
The old type is fairly limited. In contains either 256 or 512 glyphs. The width of the bitmaps is constant 8 pixels. All bitmaps have the same height, but the value can bee selected freely.
Since a pixel is a bit and the width is constant, the height is equal to the size of every 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.
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 binary. In psf1 every byte represents a line of the glyph. A one represents a set pixel, a zero a empty one.
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 a example for a psf2 glyph with a width of 12 pixels and a height of 16 pixels representing an A:
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 its 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 only 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 refurbished version of those information.
There are some PC Screen Fonts preinstalled at most Linux distributions or at least included in the repos.
Those files are usually gzip compressed.
Applications for dealing with psf files already exists. 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 which support for several font formats including psf, still it lacks the ability to deal with psf fonts with unicode tables.
Moreover the psftools provide 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 pearl 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 ;)