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
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
"""8x10-Pixelsatz für Taloria — gemischt, inkl. Umlauten und ß.
|
|
|
|
|
|
|
|
|
|
|
|
Jedes Zeichen ist eine Zelle 8x10: sechs Spalten Glyphe, links/rechts je
|
|
|
|
|
|
1 px Rand, Vorschub 8, Zeile 12. Die Glyphen liegen als zehn Zeilen à sechs
|
|
|
|
|
|
Zeichen im Dict; `#` ist ein Pixel, `.` leer.
|
|
|
|
|
|
|
|
|
|
|
|
draw_text(d, x, y, "Der Ghul greift an.", CREAM)
|
|
|
|
|
|
text_width("Der Ghul greift an.") # in Pixeln
|
|
|
|
|
|
|
|
|
|
|
|
Unterstützt A-Z, a-z, 0-9, deutsche Umlaute und ß, Satzzeichen und die
|
|
|
|
|
|
üblichen Rechen-/Klammerzeichen. Unbekannte Zeichen werden als `?` gezeichnet.
|
|
|
|
|
|
"""
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
from PIL import ImageDraw
|
|
|
|
|
|
|
|
|
|
|
|
ADVANCE = 8
|
|
|
|
|
|
LINE = 12
|
|
|
|
|
|
ROWS = 10
|
|
|
|
|
|
COLS = 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _g(*rows: str) -> str:
|
|
|
|
|
|
assert len(rows) == ROWS, f"{len(rows)} Zeilen statt {ROWS}"
|
|
|
|
|
|
for r in rows:
|
|
|
|
|
|
assert len(r) == COLS, f"Zeile {r!r} hat {len(r)} statt {COLS} Zeichen"
|
|
|
|
|
|
return "/".join(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLYPHS: dict[str, str] = {
|
|
|
|
|
|
" ": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
"......", "......", "......", "......", "......"),
|
|
|
|
|
|
# --- Grossbuchstaben (Zeilen 1-7) -----------------------------------
|
|
|
|
|
|
"A": _g("......", "..##..", ".#..#.", "#....#", "#....#",
|
|
|
|
|
|
"######", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"B": _g("......", "#####.", "#....#", "#....#", "#####.",
|
|
|
|
|
|
"#....#", "#....#", "#####.", "......", "......"),
|
|
|
|
|
|
"C": _g("......", ".####.", "#....#", "#.....", "#.....",
|
|
|
|
|
|
"#.....", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"D": _g("......", "####..", "#...#.", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#...#.", "####..", "......", "......"),
|
|
|
|
|
|
"E": _g("......", "######", "#.....", "#.....", "#####.",
|
|
|
|
|
|
"#.....", "#.....", "######", "......", "......"),
|
|
|
|
|
|
"F": _g("......", "######", "#.....", "#.....", "#####.",
|
|
|
|
|
|
"#.....", "#.....", "#.....", "......", "......"),
|
|
|
|
|
|
"G": _g("......", ".####.", "#....#", "#.....", "#..###",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"H": _g("......", "#....#", "#....#", "#....#", "######",
|
|
|
|
|
|
"#....#", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"I": _g("......", "######", "..##..", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "######", "......", "......"),
|
|
|
|
|
|
"J": _g("......", "...###", "....##", ".....#", ".....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"K": _g("......", "#....#", "#...#.", "#..#..", "###...",
|
|
|
|
|
|
"#..#..", "#...#.", "#....#", "......", "......"),
|
|
|
|
|
|
"L": _g("......", "#.....", "#.....", "#.....", "#.....",
|
|
|
|
|
|
"#.....", "#.....", "######", "......", "......"),
|
|
|
|
|
|
"M": _g("......", "#....#", "##..##", "#.##.#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"N": _g("......", "#....#", "##...#", "#.#..#", "#..#.#",
|
|
|
|
|
|
"#...##", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"O": _g("......", ".####.", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"P": _g("......", "#####.", "#....#", "#....#", "#####.",
|
|
|
|
|
|
"#.....", "#.....", "#.....", "......", "......"),
|
|
|
|
|
|
"Q": _g("......", ".####.", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#...#.", ".####.", ".....#", "......"),
|
|
|
|
|
|
"R": _g("......", "#####.", "#....#", "#....#", "#####.",
|
|
|
|
|
|
"#..#..", "#...#.", "#....#", "......", "......"),
|
|
|
|
|
|
"S": _g("......", ".####.", "#....#", "#.....", ".####.",
|
|
|
|
|
|
".....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"T": _g("......", "######", "..##..", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "..##..", "......", "......"),
|
|
|
|
|
|
"U": _g("......", "#....#", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"V": _g("......", "#....#", "#....#", "#....#", "#....#",
|
|
|
|
|
|
".#..#.", ".#..#.", "..##..", "......", "......"),
|
|
|
|
|
|
"W": _g("......", "#....#", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#.##.#", "##..##", "#....#", "......", "......"),
|
|
|
|
|
|
"X": _g("......", "#....#", "#....#", ".#..#.", "..##..",
|
|
|
|
|
|
".#..#.", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"Y": _g("......", "#....#", "#....#", ".#..#.", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "..##..", "......", "......"),
|
|
|
|
|
|
"Z": _g("......", "######", ".....#", "....#.", "..##..",
|
|
|
|
|
|
".#....", "#.....", "######", "......", "......"),
|
|
|
|
|
|
# --- Kleinbuchstaben (x-Hoehe 3-7, Oberlaenge ab 1) -----------------
|
|
|
|
|
|
"a": _g("......", "......", "......", ".####.", ".....#",
|
|
|
|
|
|
".####.", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"b": _g("......", "#.....", "#.....", "####..", "#....#",
|
|
|
|
|
|
"#....#", "#....#", "####..", "......", "......"),
|
|
|
|
|
|
"c": _g("......", "......", "......", ".####.", "#.....",
|
|
|
|
|
|
"#.....", "#.....", ".####.", "......", "......"),
|
|
|
|
|
|
"d": _g("......", ".....#", ".....#", ".####.", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"e": _g("......", "......", "......", ".####.", "#....#",
|
|
|
|
|
|
"######", "#.....", ".####.", "......", "......"),
|
|
|
|
|
|
"f": _g("......", "..###.", ".#...#", ".#....", "####..",
|
|
|
|
|
|
".#....", ".#....", ".#....", "......", "......"),
|
|
|
|
|
|
"g": _g("......", "......", "......", ".####.", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", ".....#", ".####."),
|
|
|
|
|
|
"h": _g("......", "#.....", "#.....", "####..", "#....#",
|
|
|
|
|
|
"#....#", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"i": _g("......", "..##..", "......", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "..##..", "......", "......"),
|
|
|
|
|
|
"j": _g("......", "...##.", "......", "...##.", "...##.",
|
|
|
|
|
|
"...##.", "...##.", "#..##.", ".##...", "......"),
|
|
|
|
|
|
"k": _g("......", "#.....", "#.....", "#..#..", "#.#...",
|
|
|
|
|
|
"##....", "#.#...", "#..#..", "......", "......"),
|
|
|
|
|
|
"l": _g("......", "..##..", "..##..", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "..###.", "......", "......"),
|
|
|
|
|
|
"m": _g("......", "......", "......", "##.##.", "#.#.#.",
|
|
|
|
|
|
"#.#.#.", "#.#.#.", "#.#.#.", "......", "......"),
|
|
|
|
|
|
"n": _g("......", "......", "......", "####..", "#....#",
|
|
|
|
|
|
"#....#", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"o": _g("......", "......", "......", ".####.", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"p": _g("......", "......", "......", "####..", "#....#",
|
|
|
|
|
|
"#....#", "#....#", "####..", "#.....", "#....."),
|
|
|
|
|
|
"q": _g("......", "......", "......", ".####.", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", ".....#", ".....#"),
|
|
|
|
|
|
"r": _g("......", "......", "......", "#.###.", "##....",
|
|
|
|
|
|
"#.....", "#.....", "#.....", "......", "......"),
|
|
|
|
|
|
"s": _g("......", "......", "......", ".####.", "#.....",
|
|
|
|
|
|
".####.", ".....#", ".####.", "......", "......"),
|
|
|
|
|
|
"t": _g("......", ".#....", ".#....", "####..", ".#....",
|
|
|
|
|
|
".#....", ".#....", "..###.", "......", "......"),
|
|
|
|
|
|
"u": _g("......", "......", "......", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"v": _g("......", "......", "......", "#....#", "#....#",
|
|
|
|
|
|
".#..#.", ".#..#.", "..##..", "......", "......"),
|
|
|
|
|
|
"w": _g("......", "......", "......", "#....#", "#....#",
|
|
|
|
|
|
"#.##.#", "##..##", "#....#", "......", "......"),
|
|
|
|
|
|
"x": _g("......", "......", "......", "#....#", ".#..#.",
|
|
|
|
|
|
"..##..", ".#..#.", "#....#", "......", "......"),
|
|
|
|
|
|
"y": _g("......", "......", "......", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", ".....#", ".####."),
|
|
|
|
|
|
"z": _g("......", "......", "......", "######", "....#.",
|
|
|
|
|
|
"..##..", ".#....", "######", "......", "......"),
|
|
|
|
|
|
# --- Ziffern -------------------------------------------------------
|
|
|
|
|
|
"0": _g("......", ".####.", "#....#", "#...##", "#..#.#",
|
|
|
|
|
|
"##...#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"1": _g("......", "..##..", ".###..", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "..##..", "######", "......", "......"),
|
|
|
|
|
|
"2": _g("......", ".####.", "#....#", ".....#", "...##.",
|
|
|
|
|
|
"..##..", ".#....", "######", "......", "......"),
|
|
|
|
|
|
"3": _g("......", ".####.", "#....#", ".....#", "..###.",
|
|
|
|
|
|
".....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"4": _g("......", "...##.", "..###.", ".#..#.", "#...#.",
|
|
|
|
|
|
"######", "....#.", "....#.", "......", "......"),
|
|
|
|
|
|
"5": _g("......", "######", "#.....", "#####.", ".....#",
|
|
|
|
|
|
".....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"6": _g("......", "..###.", ".#....", "#.....", "#####.",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"7": _g("......", "######", ".....#", "....#.", "...#..",
|
|
|
|
|
|
"..#...", "..#...", "..#...", "......", "......"),
|
|
|
|
|
|
"8": _g("......", ".####.", "#....#", "#....#", ".####.",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"9": _g("......", ".####.", "#....#", "#....#", ".#####",
|
|
|
|
|
|
".....#", "....#.", ".###..", "......", "......"),
|
|
|
|
|
|
# --- Satzzeichen ---------------------------------------------------
|
|
|
|
|
|
".": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
"......", "......", "..##..", "......", "......"),
|
|
|
|
|
|
",": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
"......", "......", "..##..", ".##...", "......"),
|
|
|
|
|
|
":": _g("......", "......", "......", "..##..", "......",
|
|
|
|
|
|
"......", "......", "..##..", "......", "......"),
|
|
|
|
|
|
";": _g("......", "......", "......", "..##..", "......",
|
|
|
|
|
|
"......", "......", "..##..", ".##...", "......"),
|
|
|
|
|
|
"!": _g("......", "..##..", "..##..", "..##..", "..##..",
|
|
|
|
|
|
"..##..", "......", "..##..", "......", "......"),
|
|
|
|
|
|
"?": _g("......", ".###..", "#...#.", "....#.", "...#..",
|
|
|
|
|
|
"..#...", "......", "..#...", "......", "......"),
|
|
|
|
|
|
"'": _g("......", "..##..", "..#...", "......", "......",
|
|
|
|
|
|
"......", "......", "......", "......", "......"),
|
|
|
|
|
|
"\"": _g("......", ".#..#.", ".#..#.", "......", "......",
|
|
|
|
|
|
"......", "......", "......", "......", "......"),
|
|
|
|
|
|
"-": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
".####.", "......", "......", "......", "......"),
|
|
|
|
|
|
"+": _g("......", "......", "......", "..#...", ".####.",
|
|
|
|
|
|
"..#...", "......", "......", "......", "......"),
|
|
|
|
|
|
"=": _g("......", "......", "......", ".####.", "......",
|
|
|
|
|
|
".####.", "......", "......", "......", "......"),
|
|
|
|
|
|
"/": _g("......", "....#.", "....#.", "...#..", "..#...",
|
|
|
|
|
|
"..#...", ".#....", ".#....", "......", "......"),
|
|
|
|
|
|
"(": _g("......", "...#..", "..#...", "..#...", "..#...",
|
|
|
|
|
|
"..#...", "..#...", "...#..", "......", "......"),
|
|
|
|
|
|
")": _g("......", "..#...", "...#..", "...#..", "...#..",
|
|
|
|
|
|
"...#..", "...#..", "..#...", "......", "......"),
|
|
|
|
|
|
"[": _g("......", "..###.", "..#...", "..#...", "..#...",
|
|
|
|
|
|
"..#...", "..#...", "..###.", "......", "......"),
|
|
|
|
|
|
"]": _g("......", ".###..", "...#..", "...#..", "...#..",
|
|
|
|
|
|
"...#..", "...#..", ".###..", "......", "......"),
|
|
|
|
|
|
"%": _g("......", "#...#.", "#..#..", "...#..", "..#...",
|
|
|
|
|
|
".#....", ".#...#", ".....#", "......", "......"),
|
|
|
|
|
|
"&": _g("......", ".##...", "#..#..", "#.#...", ".#....",
|
|
|
|
|
|
"#.#.#.", "#..#..", ".##.#.", "......", "......"),
|
|
|
|
|
|
"<": _g("......", "......", "...#..", "..#...", ".#....",
|
|
|
|
|
|
"..#...", "...#..", "......", "......", "......"),
|
|
|
|
|
|
">": _g("......", "......", ".#....", "..#...", "...#..",
|
|
|
|
|
|
"..#...", ".#....", "......", "......", "......"),
|
|
|
|
|
|
"*": _g("......", "......", ".#.#..", "..##..", ".#.#..",
|
|
|
|
|
|
"......", "......", "......", "......", "......"),
|
|
|
|
|
|
"—": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
"######", "......", "......", "......", "......"),
|
|
|
|
|
|
"–": _g("......", "......", "......", "......", "......",
|
|
|
|
|
|
".####.", "......", "......", "......", "......"),
|
|
|
|
|
|
# --- Umlaute und scharfes S ----------------------------------------
|
|
|
|
|
|
"Ä": _g(".#..#.", "..##..", ".#..#.", "#....#", "#....#",
|
|
|
|
|
|
"######", "#....#", "#....#", "......", "......"),
|
|
|
|
|
|
"Ö": _g(".#..#.", ".####.", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"Ü": _g(".#..#.", "#....#", "#....#", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"ä": _g("......", ".#..#.", "......", ".####.", ".....#",
|
|
|
|
|
|
".####.", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"ö": _g("......", ".#..#.", "......", ".####.", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
|
|
|
|
|
"ü": _g("......", ".#..#.", "......", "#....#", "#....#",
|
|
|
|
|
|
"#....#", "#....#", ".####.", "......", "......"),
|
art: Phase 0 abgeschlossen — Pictures neu, 9-Slice, BMFont, Referenzblatt
Pictures/: die vier Vollbilder waren mit --size 320x180 gerechnet. Bei Kacheln
und Sprites war der Nachlauf eine Halbierung, hier nicht — die 320er Basis
steckte im Bild. Aus den Rohbildern neu gerechnet (640x360, 2x), sichtbar
feiner; damit liegt jede Kategorie in 2x.
9-Slice: ui.py bekommt elem_panel_slice() und liefert
final/UI/ui_panel_9slice_12px.png (Rand 2 px bei 1x, 4 px in der 2x-Datei).
tools/ui_slice.py setzt Panels aus den neun Teilen zusammen und vergleicht sie
mit panel(): 4x4 bis 400x56 pixelgleich, Belegblatt in prep/ui-slice/.
Font: tools/font_export.py schreibt final/Font/ (Atlas + BMFont, 1x und 2x,
93 Zeichen, Vorschub 8, Zeile 12, Basis 8). Geprüft ohne Godot: alle Zeichen
werden nur aus der .fnt gesetzt und mit font8.draw_text bytegleich verglichen.
Dabei zwei Fehler gefunden und behoben: der Atlas brauchte den 1-px-Vorlauf von
draw_text (sonst sitzt Text 1 px zu weit links), und das ß war als § gesetzt
(jetzt mit durchgehendem Stamm).
Referenzblatt: tools/referenz.py baut final/_referenz.png (1280 px, 2x) mit je
2-6 freigegebenen Assets pro Kategorie, Schriftprobe und Palettenhinweis.
Doku: Roadmap auf "Phase 0 abgeschlossen" (offen nur noch Weltpalette,
Kontrastregel, Listen-Zustände, NSC-Porträts), ui.md §2/§3/§7, UI-README,
WORKFLOW §4.7, art/README auf acht Kategorien.
2026-11-15 00:06:01 +01:00
|
|
|
|
# ß: langer Stamm links, oben und unten je ein Bogen. Ohne den Stamm
|
|
|
|
|
|
# liest die Form bei 6 px als § (vorher so gesetzt, am 15.11. korrigiert).
|
|
|
|
|
|
"ß": _g("......", ".#.##.", ".##..#", ".#...#", ".#.##.",
|
|
|
|
|
|
".#...#", ".#...#", ".####.", "......", "......"),
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FALLBACK = GLYPHS["?"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _rows(ch: str) -> list[str]:
|
|
|
|
|
|
return GLYPHS.get(ch, FALLBACK).split("/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def text_width(text: str) -> int:
|
|
|
|
|
|
return len(text) * ADVANCE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_text(d: ImageDraw.ImageDraw, x: int, y: int, text: str,
|
|
|
|
|
|
color, scale: int = 1) -> int:
|
|
|
|
|
|
"""Zeichnet Text; gibt die x-Position danach zurück."""
|
|
|
|
|
|
for ch in text:
|
|
|
|
|
|
rows = _rows(ch)
|
|
|
|
|
|
for ry, row in enumerate(rows):
|
|
|
|
|
|
for rx, c in enumerate(row):
|
|
|
|
|
|
if c == "#":
|
|
|
|
|
|
px, py = x + rx + 1, y + ry
|
|
|
|
|
|
if scale == 1:
|
|
|
|
|
|
d.point((px, py), fill=color)
|
|
|
|
|
|
else:
|
|
|
|
|
|
d.rectangle((px * scale, py * scale,
|
|
|
|
|
|
(px + 1) * scale - 1, (py + 1) * scale - 1),
|
|
|
|
|
|
fill=color)
|
|
|
|
|
|
x += ADVANCE * scale
|
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wrap(text: str, max_px: int) -> list[str]:
|
|
|
|
|
|
words, lines, cur = text.split(), [], ""
|
|
|
|
|
|
for w in words:
|
|
|
|
|
|
cand = w if not cur else f"{cur} {w}"
|
|
|
|
|
|
if text_width(cand) <= max_px:
|
|
|
|
|
|
cur = cand
|
|
|
|
|
|
else:
|
|
|
|
|
|
if cur:
|
|
|
|
|
|
lines.append(cur)
|
|
|
|
|
|
cur = w
|
|
|
|
|
|
if cur:
|
|
|
|
|
|
lines.append(cur)
|
|
|
|
|
|
return lines
|