Fix A4 preview box to actually render landscape
A plain swap of the printer's column/line counts didn't visually flip the box's orientation, since monospace glyphs are taller than wide: 64x54 characters still renders taller than wide at that char aspect. Compute the true visual aspect ratio of the rotated print instead, and scale the box to fill the terminal at that ratio. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>master
parent
deaf867091
commit
4be3e5a130
|
|
@ -195,9 +195,17 @@ def box_dims_for(term_rows, term_cols, cfg=None):
|
||||||
if cfg.printer_a4 and target_rows is not None:
|
if cfg.printer_a4 and target_rows is not None:
|
||||||
# The printed page is rotated 90 degrees before it reaches the
|
# The printed page is rotated 90 degrees before it reaches the
|
||||||
# printer (see prepare_print_frame), so the box shown on screen
|
# printer (see prepare_print_frame), so the box shown on screen
|
||||||
# should reflect that same landscape swap rather than the
|
# should have the same *visual* aspect ratio the final, rotated
|
||||||
# printer's raw portrait character grid.
|
# print will have - not just target_cols/target_rows swapped.
|
||||||
target_cols, target_rows = target_rows, target_cols
|
# 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)
|
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)
|
cols = max(min(target_cols + 2, max_cols), 10)
|
||||||
return rows, cols
|
return rows, cols
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue