From c9cf7f6484d6b439e16fded2c10bc18c8fa49649 Mon Sep 17 00:00:00 2001 From: The_miro Date: Tue, 14 Jul 2026 09:41:13 +0200 Subject: [PATCH] fix: correct A4 landscape sizing math to avoid page overflow a4_landscape_chars() was sizing the capture/preview to the *final* landscape look (assuming the physical page gets fed sideways), but txt2printr.sh actually rotates the ascii art 90 degrees in software on a normally-fed page. Combining both produced ~107 printed lines, overflowing the printer's page-length capacity onto a second sheet. Since the software rotation is cancelled out by the reader turning the finished page 90 degrees, the capture buffer's own dimensions equal the final visual result, but its width becomes the printed line count post-rotation - so it must be capped by the page's line capacity along the long edge, with height derived from the target landscape aspect ratio (corrected for non-square character cells) instead of just filling the available character budget. Co-Authored-By: Claude Sonnet 5 --- photobooth.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/photobooth.py b/photobooth.py index 6f70db2..723ad0c 100755 --- a/photobooth.py +++ b/photobooth.py @@ -180,11 +180,26 @@ _PRINT_MARGIN_IN = 0.5 def a4_landscape_chars(cpi, lpi): - """(cols, rows) of an A4 sheet printed sideways, at the given pitch.""" + """(cols, rows) to capture/preview for an A4 landscape printout. + + txt2printr.sh prints on a normally-fed (portrait) page and rotates the + ascii art 90 degrees in software; the reader turns the finished sheet + 90 degrees to view it. That second turn cancels the software rotation, + so this buffer's own dimensions equal the final visual result - but its + width becomes the printed *line count* after rotation, which must fit + within one page's line capacity along the long (feed) edge. Height is + then derived from the target landscape aspect ratio, corrected for + non-square character cells (cells are cpi/lpi times taller than wide), + so the final printout keeps true A4 proportions instead of just filling + however many character cells happen to fit. + """ long_in = _A4_LONG_MM / _MM_PER_IN short_in = _A4_SHORT_MM / _MM_PER_IN - cols = max(1, round((long_in - 2 * _PRINT_MARGIN_IN) * cpi)) - rows = max(1, round((short_in - 2 * _PRINT_MARGIN_IN) * lpi)) + max_lines = max(1, round((long_in - 2 * _PRINT_MARGIN_IN) * lpi)) + max_chars = max(1, round((short_in - 2 * _PRINT_MARGIN_IN) * cpi)) + aspect = (long_in / short_in) * (cpi / lpi) + cols = max_lines + rows = max(1, min(max_chars, round(cols / aspect))) return cols, rows