From: Christian Heller Date: Sat, 23 Sep 2023 23:39:58 +0000 (+0200) Subject: Use cm as unit for all input values. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=62a5f685da1cbfc256b712d6c0b1222cf19ec1ea;p=misc Use cm as unit for all input values. --- diff --git a/bookmaker.py b/bookmaker.py index 72ffbfa..2211b84 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -4,18 +4,22 @@ import argparse import io from reportlab.lib.pagesizes import A4 a4_width, a4_height = A4 +points_per_cm = 10 * 72 / 25.4 +cut_depth = 1.95 * points_per_cm +cut_width = 1.05 * points_per_cm +middle_point_depth = 0.4 * points_per_cm parser = argparse.ArgumentParser(description="build print-ready book PDF") parser.add_argument("-i", "--input_file", action="append", required=True, help="input PDF file") parser.add_argument("-o", "--output_file", required=True, help="output PDF file") parser.add_argument("-p", "--page_range", action="append", help="page range, e.g., '3-end'") -parser.add_argument("-c", "--crop_range", action="append", help="crops left, bottom, right, top – e.g., '10,10,10,10'; prefix with ':'-delimited page range to limit effect") -parser.add_argument("-n", "--nup4", action='store_true', help="puts 4 input pages onto 1 output page") -parser.add_argument("-a", "--analyze", action="store_true", help="print lines identifying spine, page borders") +parser.add_argument("-c", "--crop_range", action="append", help="cm crops left, bottom, right, top – e.g., '10,10,10,10'; prefix with ':'-delimited page range to limit effect") parser.add_argument("-t", "--symmetry", action="store_true", help="alternate horizontal crops between odd and even pages") parser.add_argument("-r", "--rotate", dest="rotate", type=int, action="append", help="rotate page of number by 90° (usable multiple times on same page!)") -parser.add_argument("-m", "--margin", type=float, default=4.3, help="print margin in mm (default 4.3)") -parser.add_argument("-s", "--spine", type=float, default=10, help="on --nup4, mm width of margin hidden in spine (default 10)") +parser.add_argument("-n", "--nup4", action='store_true', help="puts 4 input pages onto 1 output page") +parser.add_argument("-a", "--analyze", action="store_true", help="in --nup4, print lines identifying spine, page borders") +parser.add_argument("-m", "--margin", type=float, default=0.43, help="print margin for --nup4 in cm (default 0.43)") +parser.add_argument("-s", "--spine", type=float, default=1, help="on --nup4, cm width of margin hidden in spine (default 1)") args = parser.parse_args() @@ -76,7 +80,7 @@ if args.crop_range: page_range = None crops = initial_split[0] start_page, end_page = parse_page_range(page_range, pages_to_add) - crop_left, crop_bottom, crop_right, crop_top = [float(x) for x in crops.split(',')] + crop_left, crop_bottom, crop_right, crop_top = [float(x) * points_per_cm for x in crops.split(',')] cropped_width = a4_width - crop_left - crop_right cropped_height = a4_height - crop_bottom - crop_top zoom = 1 @@ -112,10 +116,9 @@ if not args.nup4: odd_page = not odd_page else: - points_per_mm = 2.83465 n_pages_per_axis = 2 - spine_limit = args.spine * points_per_mm - printable_margin = args.margin * points_per_mm + spine_limit = args.spine * points_per_cm + printable_margin = args.margin * points_per_cm printable_scale = (a4_width - 2*printable_margin)/a4_width half_width = a4_width / n_pages_per_axis half_height = a4_height / n_pages_per_axis @@ -239,9 +242,6 @@ else: c.line(x_right_spine_limit, a4_height, x_right_spine_limit, 0) if front_page: c.setLineWidth(0.2) - cut_depth = 19.5 * points_per_mm - cut_width = 10.5 * points_per_mm - middle_point_depth = 4 * points_per_mm start_up_left_left_x = x_left_spine_limit - 0.5 * cut_width start_up_left_right_x = x_left_spine_limit + 0.5 * cut_width