Caixa pixel-tight, accents visibles i zoom ×3 per defecte

This commit is contained in:
2026-04-26 17:37:32 +02:00
parent 805d9499ce
commit 7631f80d76
3 changed files with 104 additions and 34 deletions
+20 -4
View File
@@ -20,9 +20,10 @@ import font_gen
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
STATE_FILE = os.path.join(SCRIPT_DIR, ".font_gen_gui_state.json")
PREVIEW_MAX_W = 720
PREVIEW_MAX_H = 320
PREVIEW_MAX_W = 800
PREVIEW_MAX_H = 480
PREVIEW_DEBOUNCE_MS = 200
DEFAULT_ZOOM = 3 # zoom inicial cuando no hay estado guardado
AUTO_MAX_SCALE = 8 # techo del fit automático
MANUAL_MAX_SCALE = 16 # techo cuando el usuario pulsa +
@@ -31,6 +32,9 @@ class FontGenApp(tk.Tk):
def __init__(self) -> None:
super().__init__()
self.title("font-gen")
# Tamaño suficiente para mostrar el preview ×3 de fuentes pequeñas y
# medianas sin tener que estirar la ventana.
self.geometry("900x760")
self.minsize(640, 480)
self._preview_job: str | None = None
@@ -38,7 +42,7 @@ class FontGenApp(tk.Tk):
# en cuanto sale del scope local y el preview aparece en blanco.
self._preview_img_tk: ImageTk.PhotoImage | None = None
self._last_result: font_gen.FontBitmapResult | None = None
self._zoom: int | None = None # None = auto-fit; int = escala explícita
self._zoom: int | None = DEFAULT_ZOOM # None = auto-fit; int = escala explícita
self.ttf_var = tk.StringVar()
self.size_var = tk.IntVar(value=8)
@@ -51,6 +55,7 @@ class FontGenApp(tk.Tk):
self._build_ui()
self._load_state() # antes de los traces: el set() inicial no debe disparar preview
self._update_zoom_label()
for v in (self.ttf_var, self.size_var, self.columns_var, self.bw_var, self.bh_var):
v.trace_add("write", lambda *_: self._schedule_preview())
@@ -309,13 +314,24 @@ class FontGenApp(tk.Tk):
size = state.get("size")
if isinstance(size, int) and 4 <= size <= 256:
self.size_var.set(size)
# Zoom: None (auto), o int en [1, MANUAL_MAX_SCALE]
if "zoom" in state:
zoom = state["zoom"]
if zoom is None:
self._zoom = None
elif isinstance(zoom, int) and 1 <= zoom <= MANUAL_MAX_SCALE:
self._zoom = zoom
def _save_state(self) -> None:
try:
size = self.size_var.get()
except tk.TclError:
size = 8
state = {"ttf": self.ttf_var.get().strip(), "size": size}
state = {
"ttf": self.ttf_var.get().strip(),
"size": size,
"zoom": self._zoom,
}
try:
with open(STATE_FILE, "w", encoding="utf-8") as f:
json.dump(state, f, indent=2)