使用高于 32 像素的 TTY 字体

使用高于 32 像素的 TTY 字体

我有一台 HiDPI 笔记本电脑,32 像素有点太小,无法舒适地阅读。我无法找到更大的字体,所以我决定创建自己的字体。

这对于任何高度小于或等于 32px 的字体都适用,但任何更大的字体都会被 setfont 拒绝:

> file FC-32.psf
FC-32.psf: Linux/i386 PC Screen Font v2 data, 256 characters, Unicode directory, 32x16
> file FC-33.psf 
FC-33.psf: Linux/i386 PC Screen Font v2 data, 256 characters, Unicode directory, 33x16
> # -----------
> setfont ./FC-32.psf
> # 32 is fine
> setfont ./FC-33.psf
Bad character height 33
> # (It also reject reasonable numbers like 48 and 64)

这是我的字体有问题吗?难道我做错了什么?这是 Linux 控制台中的硬限制吗?我找不到任何有关限制的提及,也找不到任何更大字体的示例。


使用的测试文件和脚本

FC-32.psf.gz - 32x16,有效

FC-33.psf.gz - 33x16,被拒绝

下面给出了我生成字体的脚本。它将某些.otf字体转换为.psf.gz可配置的高度。数学是反复试验,并且可能特定于 FiraCode。

我还可以根据要求提供测试文件。

#!/bin/zsh
# Based on this: https://unix.stackexchange.com/questions/161890/how-can-i-make-a-psf-font-for-the-console-from-a-otf-one

H=32 # <- FONT HEIGHT
PTS=12
(( W=H*5/10 ))
(( WIDTH = W*10 ))
(( DPI=H*60/PTS ))
COUNT=256
OUT=FC

otf2bdf -r $DPI -p $PTS -c C ./FiraCode-Regular.otf \
  | sed -e "s/AVERAGE_WIDTH.*/AVERAGE_WIDTH $WIDTH/" \
  > "$OUT.bdf"

bdf2psf --fb "$OUT.bdf" \
  /usr/share/bdf2psf/standard.equivalents \
  /usr/share/bdf2psf/ascii.set+/usr/share/bdf2psf/useful.set \
  $COUNT "$OUT.psf"

gzip "$OUT.psf" -f

答案1

我不确定任何面向用户的文档中是否明确记录了该限制,但它已融入内核中。这描述fbcon_set_font说:

/*
 *  User asked to set font; we are guaranteed that
 *  a) width and height are in range 1..32
 *  b) charcount does not exceed 512
 *  but lets not assume that, since someone might someday want to use larger
 *  fonts. And charcount of 512 is small for unicode support.
 *
 *  However, user space gives the font in 32 rows , regardless of
 *  actual font height. So a new API is needed if support for larger fonts
 *  is ever implemented.
 */

fbcon_get_font以 32 行步长处理字符:

    if (font->width <= 8) {
        j = vc->vc_font.height;
        for (i = 0; i < font->charcount; i++) {
            memcpy(data, fontdata, j);
            memset(data + j, 0, 32 - j);
            data += 32;
            fontdata += j;
        }

(对宽度超过 8 像素的字体进行类似的处理)。

相关内容