diff --git a/photobooth.py b/photobooth.py index b31f899..7c9e6d9 100755 --- a/photobooth.py +++ b/photobooth.py @@ -195,9 +195,17 @@ def box_dims_for(term_rows, term_cols, cfg=None): if cfg.printer_a4 and target_rows is not None: # The printed page is rotated 90 degrees before it reaches the # printer (see prepare_print_frame), so the box shown on screen - # should reflect that same landscape swap rather than the - # printer's raw portrait character grid. - target_cols, target_rows = target_rows, target_cols + # should have the same *visual* aspect ratio the final, rotated + # print will have - not just target_cols/target_rows swapped. + # Monospace glyphs are taller than wide (_CHAR_ASPECT), so a plain + # swap of the character counts still renders taller than wide; + # scale the box to fill the terminal at the correct ratio instead. + landscape_ratio = 1 / (visual_aspect(target_cols, target_rows) * _CHAR_ASPECT) + avail_cols, avail_rows = max_cols - 2, max_rows - 2 + if avail_cols / avail_rows > landscape_ratio: + target_rows, target_cols = avail_rows, round(avail_rows * landscape_ratio) + else: + target_cols, target_rows = avail_cols, round(avail_cols / landscape_ratio) rows = max_rows if target_rows is None else max(min(target_rows + 2, max_rows), 3) cols = max(min(target_cols + 2, max_cols), 10) return rows, cols