A4 = (A4_WIDTH, A4_HEIGHT)
# constants specifically for --nup4
-A4_HALF_WIDTH = A4_WIDTH / 2
-A4_HALF_HEIGHT = A4_HEIGHT / 2
CUT_DEPTH = 1.95 * POINTS_PER_CM
CUT_WIDTH = 1.05 * POINTS_PER_CM
MIDDLE_POINT_DEPTH = 0.4 * POINTS_PER_CM
self.shrink_for_margin = (A4_WIDTH - 2 * self.margin)/A4_WIDTH
# NB: We define spine size un-shrunk, but .shrink_for_spine is used
# with values shrunk for the margin, which we undo here.
- spine_part_of_page = ((INNER_SPINE_MARGIN_PER_PAGE / A4_HALF_WIDTH)
+ spine_part_of_page = ((INNER_SPINE_MARGIN_PER_PAGE / A4_WIDTH/2)
/ self.shrink_for_margin)
self.shrink_for_spine = 1 - spine_part_of_page
def rotate_pages(
- args_rotate_page: list[int],
+ args_rotate_page: Optional[list[int]],
pages: list[Page]
) -> None:
'For pages page numbered in args_rotate_page, rotate by 90°.'
page.translate(ty=(1 - nup4_geometry.shrink_for_spine) * A4_HEIGHT)
if nup4_i in {0, 1}:
y_section = A4_HEIGHT
- page.set_box(bottom=A4_HALF_HEIGHT, top=A4_HEIGHT)
+ page.set_box(bottom=A4_HEIGHT/2, top=A4_HEIGHT)
else: # nup4_in in {2, 3}
y_section = 0
- page.set_box(bottom=0, top=A4_HALF_HEIGHT)
+ page.set_box(bottom=0, top=A4_HEIGHT/2)
x_section: float
if nup4_i in {0, 2}:
x_section = 0
- page.set_box(left=0, right=A4_HALF_WIDTH)
+ page.set_box(left=0, right=A4_WIDTH/2)
else: # nup4_in in {1, 3}
page.translate(tx=(1 - nup4_geometry.shrink_for_spine) * A4_WIDTH)
x_section = A4_WIDTH
- page.set_box(left=A4_HALF_WIDTH, right=A4_WIDTH)
+ page.set_box(left=A4_WIDTH/2, right=A4_WIDTH)
page.translate(tx=x_section, ty=y_section)
page.scale(QUARTER_SCALE_FACTOR)
c = Canvas(packet, pagesize=A4)
c.setLineWidth(0.1)
c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT)
- c.line(0, A4_HALF_HEIGHT, A4_WIDTH, A4_HALF_HEIGHT)
+ c.line(0, A4_HEIGHT/2, A4_WIDTH, A4_HEIGHT/2)
c.line(0, 0, A4_WIDTH, 0)
c.line(0, A4_HEIGHT, 0, 0)
- c.line(A4_HALF_WIDTH, A4_HEIGHT, A4_HALF_WIDTH, 0)
+ c.line(A4_WIDTH/2, A4_HEIGHT, A4_WIDTH/2, 0)
c.line(A4_WIDTH, A4_HEIGHT, A4_WIDTH, 0)
c.save()
new_pdf = PdfReader(packet)
new_page.translate(tx=printable_offset_x, ty=printable_offset_y)
if not (args_analyze or is_front_page):
return
- x_left_spine_limit = A4_HALF_WIDTH * nup4_geometry.shrink_for_spine
+ x_left_spine_limit = A4_WIDTH/2 * nup4_geometry.shrink_for_spine
x_right_spine_limit = A4_WIDTH - x_left_spine_limit
packet = BytesIO()
c = Canvas(packet, pagesize=A4)
directed_half_width = 0.5 * CUT_WIDTH * direction
outer_start_x = x_spine_limit - directed_half_width
inner_start_x = x_spine_limit + directed_half_width
- middle_point_y = A4_HALF_HEIGHT + MIDDLE_POINT_DEPTH * direction
- end_point_y = A4_HALF_HEIGHT + CUT_DEPTH * direction
- canvas.line(inner_start_x, A4_HALF_HEIGHT, x_spine_limit, end_point_y)
+ middle_point_y = A4_HEIGHT/2 + MIDDLE_POINT_DEPTH * direction
+ end_point_y = A4_HEIGHT/2 + CUT_DEPTH * direction
+ canvas.line(inner_start_x, A4_HEIGHT/2, 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, A4_HALF_HEIGHT)
+ canvas.line(x_spine_limit, middle_point_y, outer_start_x, A4_HEIGHT/2)
def main(