From: Christian Heller Date: Sun, 24 Sep 2023 18:21:53 +0000 (+0200) Subject: Bookmaker: Refactor cut drawing code. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/test.html?a=commitdiff_plain;h=be11e7df61a4d5f75b89fd655f57ccbeb2a539b7;p=misc Bookmaker: Refactor cut drawing code. --- diff --git a/bookmaker.py b/bookmaker.py index 20d9c4d..0018779 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -138,6 +138,15 @@ def parse_page_range(range_string, pages): end_page = int(end) return start_page, end_page +def draw_cut(canvas, x_spine_limit, direction, half_height): + outer_start_x = x_spine_limit - 0.5 * CUT_WIDTH * direction + inner_start_x = x_spine_limit + 0.5 * CUT_WIDTH * direction + middle_point_y = half_height + MIDDLE_POINT_DEPTH * direction + end_point_y = half_height + CUT_DEPTH * direction + canvas.line(inner_start_x, half_height, x_spine_limit, end_point_y) + canvas.line(x_spine_limit, end_point_y, x_spine_limit, middle_point_y) + canvas.line(x_spine_limit, middle_point_y, outer_start_x, half_height) + def parse_args(): parser = argparse.ArgumentParser(description=__doc__, epilog=help_epilogue, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("-i", "--input_file", action="append", required=True, help="input PDF file") @@ -434,22 +443,8 @@ def main(): c.line(x_right_spine_limit, A4_HEIGHT, x_right_spine_limit, 0) if front_page: c.setLineWidth(0.2) - # cut upper left - 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 - middle_point_up_left_y = half_height + MIDDLE_POINT_DEPTH - end_point_up_left_y = half_height + CUT_DEPTH - c.line(start_up_left_right_x, half_height, x_left_spine_limit, end_point_up_left_y) - c.line(x_left_spine_limit, end_point_up_left_y, x_left_spine_limit, middle_point_up_left_y) - c.line(x_left_spine_limit, middle_point_up_left_y, start_up_left_left_x, half_height) - # cut lower right - start_down_right_left_x = x_right_spine_limit - 0.5 * CUT_WIDTH - start_down_right_right_x = x_right_spine_limit + 0.5 * CUT_WIDTH - middle_point_down_right_y = half_height - MIDDLE_POINT_DEPTH - end_point_down_right_y = half_height - CUT_DEPTH - c.line(start_down_right_left_x, half_height, x_right_spine_limit, end_point_down_right_y) - c.line(x_right_spine_limit, end_point_down_right_y, x_right_spine_limit, middle_point_down_right_y) - c.line(x_right_spine_limit, middle_point_down_right_y, start_down_right_right_x, half_height) + draw_cut(c, x_left_spine_limit, (1), half_height) + draw_cut(c, x_right_spine_limit, (-1), half_height) if args.analyze or front_page: c.save() new_pdf = pypdf.PdfReader(packet)