taloria/art/tools/font_probe.py
torsten 9d7ff3138f art: 8x10-Pixelsatz — eigener Satz mit Umlauten und ß
Die Schriftgröße ist entschieden (Roadmap §0.0): 8x10 statt 5x7. Dazu ein
eigener Pixelsatz in tools/font8.py, kein Lizenzfont: 93 Glyphen,
gemischt, inkl. Ä/Ö/Ü/ä/ö/ü/ß, % und Gedankenstrichen. Zelle 8x10,
Vorschub 8, Zeile 12; Kapitalhöhe 7, x-Höhe 5, Unterlängen 8-9.

Probe (tools/font_probe.py, 0 $): Zeichensatz, Fließtext und eine
400x70-Dialogbox bei 8x10 sowie derselbe Satz im alten 5x7. Ergebnis: In
der 292-px-Box passen 35 statt 47 Zeichen pro Zeile (-26 %); für
dieselbe Textmenge wächst die Box auf ~390 px.

Die UI-Elemente sind weiterhin auf 5x7 gezeichnet; der Neusatz und der
Engine-Export (FontFile/BMFont) bleiben offen und stehen so in Roadmap
0.2, Projektbeschreibung §6/§8.1 und im UI-README. Feinschliff offen bei
M/W/%/&/*.
2026-11-14 23:28:20 +01:00

88 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Probe für den 8x10-Satz: Zeichensatz, Fließtext und Dialogbox.
python3 art/tools/font_probe.py [ZIELORDNER] # Default art/prep/font8
Schreibt `_probe_1280x720.png` (2x), `_probe_640x360.png` (1x) und
`_alphabet_4x.png` (Glyphen zum Prüfen). Kein Modell, kein pixelize.
"""
from __future__ import annotations
import sys
from pathlib import Path
from PIL import Image, ImageDraw
ART = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ART / "tools"))
import font8 # noqa: E402
import ui # noqa: E402
W, H = 640, 360
ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
abc = "abcdefghijklmnopqrstuvwxyz"
DIG = "0123456789"
PUN = ".,:;!?'\"-+=/()[]%&<>*"
UML = "ÄÖÜäöüß"
TEXT = ("Der Ghul greift an. Valyria zahlt in Ferrum, nicht in Gold. "
"Ärger mit der Nordmark? Prüfe die Zölle in Garana — "
"fünf Prozent für Waren aus Lichtenwalde.")
def main() -> int:
out = Path(sys.argv[1]) if len(sys.argv) > 1 else ART / "prep" / "font8"
out.mkdir(parents=True, exist_ok=True)
im = Image.new("RGBA", (W, H), ui.alpha(ui.INK))
d = ImageDraw.Draw(im)
y = 8
for line in (ABC, abc, DIG + " " + PUN, UML):
font8.draw_text(d, 8, y, line, ui.CREAM)
y += font8.LINE
y += 6
draw = lambda yy, txt, col: font8.draw_text(d, 8, yy, txt, col) # noqa: E731
for line in font8.wrap(TEXT, W - 16):
draw(y, line, ui.CREAM_D)
y += font8.LINE
# Dialogbox bei 8x10: 400 px breit, drei Zeilen
y += 8
box = (8, y, 8 + 400, y + 70)
ui.panel(d, box)
d.rectangle((9, y + 1, 9 + 399 - 1, y + 1), fill=ui.alpha(ui.PANEL_HI))
font8.draw_text(d, 14, y + 8, "ALDRIC VON FALKENRUH", ui.GOLD)
for i, line in enumerate(("Der Zoll ist bezahlt. Was",
"wollt Ihr in Garana?",)):
font8.draw_text(d, 14, y + 22 + i * font8.LINE, line, ui.CREAM)
# Vergleich: derselbe Satz im alten 5x7
ui.draw_text(d, 8, y + 88, "5X7 ZUM VERGLEICH:", ui.OCHRE)
ui.draw_text(d, 8, y + 98, TEXT[:60], ui.CREAM_D)
im.save(out / "_probe_640x360.png")
im.resize((W * 2, H * 2), Image.NEAREST).save(out / "_probe_1280x720.png")
# Alphabet zum Prüfen der Glyphen, 4x
lines = (ABC, abc, DIG + " " + PUN, UML,
"Der Ghul griff 7 Zölle — 12,5 %!")
sheet = Image.new("RGBA",
(max(font8.text_width(t) for t in lines) + 32,
6 * font8.LINE + 24),
ui.alpha(ui.INK))
sd = ImageDraw.Draw(sheet)
yy = 8
for line in lines:
font8.draw_text(sd, 16, yy, line, ui.CREAM)
yy += font8.LINE
sheet.resize((sheet.width * 4, sheet.height * 4), Image.NEAREST).save(
out / "_alphabet_4x.png")
print(f"{out}/_probe_640x360.png, _probe_1280x720.png, _alphabet_4x.png")
return 0
if __name__ == "__main__":
sys.exit(main())