This commit is contained in:
2026-07-22 15:28:35 -04:00
parent 755fa0632c
commit dd42e8fc58
5 changed files with 91 additions and 18 deletions

View File

@ -12,6 +12,7 @@ quadrant that lands in the cell's top-left corner tells us whether the
applied transpose is CCW (correct) or CW (the bug we fixed).
"""
import re
import sys
import tempfile
from pathlib import Path
@ -129,6 +130,18 @@ def check_layout_combos():
sheet = opened.convert("RGB")
assert sheet.size == (page_w, page_h)
# PDF twin: page must be exactly the sheet's pixel size at
# 300 DPI, in points (1/72in) - that is what the printer sees.
pdf = out.with_suffix(".pdf")
assert pdf.exists(), "PDF twin not written"
m = re.search(rb"/MediaBox\s*\[\s*0[ ,]+0[ ,]+([\d.]+)[ ,]+([\d.]+)\s*\]",
pdf.read_bytes())
assert m, "PDF MediaBox missing"
pw, ph = float(m.group(1)), float(m.group(2))
want_w, want_h = page_w * 72 / 300, page_h * 72 / 300
assert abs(pw - want_w) < 1 and abs(ph - want_h) < 1, (
f"PDF page {pw}x{ph}pt != ~{want_w}x{want_h}pt")
for i, r in enumerate(layout["photo_rects"]):
got = sheet.getpixel(rect_center(r))
exp = colors[i]
@ -231,12 +244,53 @@ def check_falling_photos_rotation_halved():
print(f" ROT=±{fp.ROT_MAX} SPIN=±{fp.SPIN_MAX} OK")
def check_print_sheet_prefers_pdf():
print("== print_sheet job selection ==")
calls = []
class FakeResult:
returncode = 0
stdout = "ok"
stderr = ""
def fake_run(*a, **k):
calls.append(list(a[0]))
return FakeResult()
orig = cs.subprocess.run
cs.subprocess.run = fake_run
try:
with tempfile.TemporaryDirectory() as d:
jpg = Path(d) / "s.jpg"
Image.new("RGB", (3300, 2550), (10, 20, 30)).save(jpg, dpi=(300, 300))
# No PDF yet: prints the JPEG, with explicit orientation.
ok, _ = cs.print_sheet(jpg, "SomePrinter")
assert ok
argv = calls.pop()
assert argv[-1].endswith("s.jpg"), argv
assert "landscape" in argv, argv
assert "-d" in argv and "SomePrinter" in argv, argv
# PDF twin exists: it wins, and no orientation flag is needed.
jpg.with_suffix(".pdf").write_bytes(b"%PDF-1.4 fake")
ok, _ = cs.print_sheet(jpg, "SomePrinter")
assert ok
argv = calls.pop()
assert argv[-1].endswith("s.pdf"), argv
assert "landscape" not in argv and "portrait" not in argv, argv
finally:
cs.subprocess.run = orig
print(" JPEG fallback gets orientation; PDF twin preferred OK")
def main():
check_layout_combos()
check_rotation_mode_expectations()
check_rotation_direction()
check_default_config_shape()
check_falling_photos_rotation_halved()
check_print_sheet_prefers_pdf()
print("\nAll tests passed.")