Quadrícula a la previsualització a partir de ×2

This commit is contained in:
2026-04-26 17:43:15 +02:00
parent 7631f80d76
commit 82f6f75e9e
+19
View File
@@ -11,6 +11,7 @@ from __future__ import annotations
import json
import os
import tkinter as tk
from math import ceil
from tkinter import filedialog, messagebox, ttk
from PIL import Image, ImageTk
@@ -26,6 +27,8 @@ 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 +
GRID_MIN_SCALE = 2 # zoom mínimo para mostrar la cuadrícula
GRID_COLOR = "#dd2222"
class FontGenApp(tk.Tk):
@@ -225,6 +228,22 @@ class FontGenApp(tk.Tk):
self.preview_canvas.create_image(0, 0, anchor="nw", image=self._preview_img_tk)
self.preview_canvas.configure(scrollregion=(0, 0, preview.width, preview.height))
# Cuadrícula a partir de un cierto zoom: a 1x los píxeles del glifo
# y los de la línea son del mismo grosor y se confunden.
if scale >= GRID_MIN_SCALE:
cols = result.columns
rows_n = ceil(len(result.chars) / cols)
cell_w = result.box_width * scale
cell_h = result.box_height * scale
grid_w = cols * cell_w
grid_h = rows_n * cell_h
for c in range(cols + 1):
x = c * cell_w
self.preview_canvas.create_line(x, 0, x, grid_h, fill=GRID_COLOR, width=1)
for r in range(rows_n + 1):
y = r * cell_h
self.preview_canvas.create_line(0, y, grid_w, y, fill=GRID_COLOR, width=1)
info = (f"{len(result.chars)} chars · "
f"caja {result.box_width}×{result.box_height} px · "
f"bitmap {base_w}×{base_h} px (×{scale})")