- for crops in args.crops:
- initial_split = crops.split(':')
- if len(initial_split) > 1:
- page_range = initial_split[0]
- crops = initial_split[1]
- else:
- page_range = None
- crops = initial_split[0]
- start_page, end_page = parse_page_range(page_range, pages_to_add)
- crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm = [float(x) for x in crops.split(',')]
- crop_left = crop_left_cm * points_per_cm
- crop_bottom = crop_bottom_cm * points_per_cm
- crop_right = crop_right_cm * points_per_cm
- crop_top = crop_top_cm * points_per_cm
- if args.symmetry:
- print("-c, -t: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm (but alternating left and right crop between even and odd pages)" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm))
- else:
- print("-c: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm))
- cropped_width = a4_width - crop_left - crop_right
- cropped_height = a4_height - crop_bottom - crop_top
- zoom = 1
- zoom_horizontal = a4_width / (a4_width - crop_left - crop_right)
- zoom_vertical = a4_height / (a4_height - crop_bottom - crop_top)
- if (zoom_horizontal > 1 and zoom_vertical < 1) or (zoom_horizontal < 1 and zoom_vertical > 1):
- print("Error: opposing zooms.")
- exit(1)
- elif zoom_horizontal + zoom_vertical > 2:
- zoom = min(zoom_horizontal, zoom_vertical)
- else:
- zoom = max(zoom_horizontal, zoom_vertical)
- for page_num in range(start_page, end_page):
- if args.symmetry and page_num % 2:
- crops_at_page[page_num] = (crop_right, crop_bottom, crop_left, crop_top)
- else:
- crops_at_page[page_num] = (crop_left, crop_bottom, crop_right, crop_top)
- zoom_at_page[page_num] = zoom
+ for crops in args.crops:
+ initial_split = crops.split(':')
+ if len(initial_split) > 1:
+ page_range = initial_split[0]
+ crops = initial_split[1]
+ else:
+ page_range = None
+ crops = initial_split[0]
+ start_page, end_page = parse_page_range(page_range, pages_to_add)
+ crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm = [float(x) for x in crops.split(',')]
+ crop_left = crop_left_cm * points_per_cm
+ crop_bottom = crop_bottom_cm * points_per_cm
+ crop_right = crop_right_cm * points_per_cm
+ crop_top = crop_top_cm * points_per_cm
+ if args.symmetry:
+ print("-c, -t: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm (but alternating left and right crop between even and odd pages)" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm))
+ else:
+ print("-c: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm))
+ cropped_width = a4_width - crop_left - crop_right
+ cropped_height = a4_height - crop_bottom - crop_top
+ zoom = 1
+ zoom_horizontal = a4_width / (a4_width - crop_left - crop_right)
+ zoom_vertical = a4_height / (a4_height - crop_bottom - crop_top)
+ if (zoom_horizontal > 1 and zoom_vertical < 1) or (zoom_horizontal < 1 and zoom_vertical > 1):
+ raise ValueError("crops would create opposing zoom directions")
+ elif zoom_horizontal + zoom_vertical > 2:
+ zoom = min(zoom_horizontal, zoom_vertical)
+ else:
+ zoom = max(zoom_horizontal, zoom_vertical)
+ for page_num in range(start_page, end_page):
+ if args.symmetry and page_num % 2:
+ crops_at_page[page_num] = (crop_right, crop_bottom, crop_left, crop_top)
+ else:
+ crops_at_page[page_num] = (crop_left, crop_bottom, crop_right, crop_top)
+ zoom_at_page[page_num] = zoom