notebookvb

This commit is contained in:
Vladimir Buzalka
2026-05-09 08:25:18 +02:00
parent c083e8e79a
commit 5bfd4176e4
30 changed files with 228 additions and 3105 deletions
@@ -62,6 +62,7 @@ def draw_kakuro(c: Canvas, x0: float, y0: float, cell: float,
num_font = max(cell * 0.5, 6)
if title:
c.setFillColor(colors.black)
c.setFont("ArialBold", 12)
c.drawString(x0, y0 + 5, title)
@@ -114,6 +115,43 @@ def draw_kakuro(c: Canvas, x0: float, y0: float, cell: float,
c.line(x0 + i * cell, y0, x0 + i * cell, y0 - h * cell)
def generate_pdf(puzzles: list[dict], output_path: Path):
"""puzzles: difficulty, puzzle_str, puzzle_date"""
BOARD_CM = 11
SOL_CM = 6
GAP = 1.5 * cm
page_w, page_h = A4
prepped = []
for p in puzzles:
grid = parse_grid(p["puzzle_str"])
h, w = len(grid), len(grid[0])
cell = BOARD_CM * cm / max(h, w)
prepped.append((p, h, w, cell))
c = Canvas(str(output_path), pagesize=A4)
for i in range(0, len(prepped), 2):
for j, (p, h, w, cell) in enumerate(prepped[i:i + 2]):
x0 = (page_w - w * cell) / 2
y0 = page_h - 2 * cm - j * (BOARD_CM * cm + 3 * cm)
draw_kakuro(c, x0, y0, cell, p["puzzle_str"],
f"Kakuro {p['difficulty'].capitalize()}{p['puzzle_date']}")
c.showPage()
c.setFont("ArialBold", 14)
c.drawCentredString(page_w / 2, page_h - 2 * cm, "Řešení")
y_cursor = page_h - 3.5 * cm
for p, h, w, _ in prepped:
sol_cell = SOL_CM * cm / max(h, w)
x0 = (page_w - w * sol_cell) / 2
draw_kakuro(c, x0, y_cursor, sol_cell, p["puzzle_str"],
p["difficulty"].capitalize(), show_solution=True)
y_cursor -= h * sol_cell + GAP
c.showPage()
c.save()
def main():
conn = connect_mysql(database="puzzle")
cur = conn.cursor()