トップ 最新

かってきままな日々

2026-03-26 (Th) [長年日記]

_ Limine フォント作成

フォント文字の最大サイズは 32x64 らしいので、 これ以上大きな文字は使えない。

Noto Sans Mono CJK JP を Limine 用 bin に変換してみた。

import sys
from PIL import Image, ImageFont, ImageDraw

def convert_ttc_to_limine(ttc_path, out_path, font_index, width, height):
    try:
        # indexを指定して特定のフォント(JP)を読み込む
        # サイズ(height)はピクセル単位で指定
        font = ImageFont.truetype(ttc_path, height, index=font_index)
        print(f"Using font: {font.getname()}") # 読み込んだフォント名を表示して確認
    except IOError:
        print("Font file not found or index out of range.")
        return

    with open(out_path, 'wb') as f:
        # Limineの基本フォントは通常ASCII範囲(0-127)か256文字
        for i in range(256):
            # 1bit(モノクロ)モードでキャンバス作成
            img = Image.new('1', (width, height), 0)
            draw = ImageDraw.Draw(img)
            
            # 文字を描画(中央寄せなどの調整が必要な場合はここで行う)
            # Noto Sans Monoなので基本的にはそのまま描画でOK
            draw.text((0, 0), chr(i), font=font, fill=1)
            
            # Limineのビットマップ形式(行ごとのバイトデータ)として書き込み
            f.write(img.tobytes())

if __name__ == "__main__":
    TTC_PATH = "/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"
    OUT_PATH = "noto_mono_jp.bin"
    # index=2 が JP であることが多いですが、実行後の表示で確認してください
    convert_ttc_to_limine(TTC_PATH, OUT_PATH, font_index=2, width=32, height=64)
    print(f"Successfully generated {OUT_PATH}")

実行すると noto_mono_jp.bin ができる。

/efi/ に置いて、limine.conf に以下を追加。

term_font: boot():/noto_mono_jp.bin
term_font_size: 32x64

reboot。

まぁまぁ綺麗だな。