From 5564a723f5a57462fe9593ced75e2321aea113dd Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Wed, 10 Jun 2020 00:11:09 +0200 Subject: [PATCH] flip poster dimensions if necessary to create maximum size poster regardless of portrait or landscape mode --- plakativ.py | 21 ++++++++++++++++----- test.py | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plakativ.py b/plakativ.py index 633689c..8f0fd36 100755 --- a/plakativ.py +++ b/plakativ.py @@ -338,11 +338,22 @@ class Plakativ: if mode in ["size", "mult"]: if mode == "size": # fit the input page size into the selected postersize - poster_width = postersize[0] - poster_height = (poster_width * inpage_height) / inpage_width - if poster_height > postersize[1]: - poster_height = postersize[1] - poster_width = (poster_height * inpage_width) / inpage_height + width_portrait = postersize[0] + height_portrait = (width_portrait * inpage_height) / inpage_width + if height_portrait > postersize[1]: + height_portrait = postersize[1] + width_portrait = (height_portrait * inpage_width) / inpage_height + area_portrait = width_portrait * height_portrait + width_landscape = postersize[1] + height_landscape = (width_landscape * inpage_height) / inpage_width + if height_landscape > postersize[0]: + height_landscape = postersize[0] + width_landscape = (height_landscape * inpage_width) / inpage_height + area_landscape = width_landscape * height_landscape + if area_portrait > area_landscape: + poster_width, poster_height = width_portrait, height_portrait + else: + poster_width, poster_height = width_landscape, height_landscape elif mode == "mult": area = inpage_width * inpage_height * mult poster_width = math.sqrt(area * inpage_width / inpage_height) diff --git a/test.py b/test.py index 2ca85a7..1228276 100644 --- a/test.py +++ b/test.py @@ -55,7 +55,7 @@ _formats = { "dina4_landscape": (297, 210), "dina3_portrait": (297, 420), "dina3_landscape": (420, 297), - "dina1_portrait": (594, 841), + "dina2_portrait": (420, 594), } @@ -111,7 +111,7 @@ _formats = { ], ), ( - _formats["dina1_portrait"], + _formats["dina2_portrait"], _formats["dina4_landscape"], _formats["dina4_portrait"], "complex",