home
·
contact
·
privacy
projects
/
bookmaker
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3dab9fc
)
Minor code simplifications.
master
author
Plom Heller
<plom@plomlompom.com>
Thu, 9 Apr 2026 16:39:33 +0000
(18:39 +0200)
committer
Plom Heller
<plom@plomlompom.com>
Thu, 9 Apr 2026 16:39:33 +0000
(18:39 +0200)
bookmaker.py
patch
|
blob
|
history
diff --git
a/bookmaker.py
b/bookmaker.py
index 9da85aab88b6ef066d8cb07aa042ceaa7c19fafa..fce2175da32dafe8c0c4763b8fbc4f9f03a81ca0 100755
(executable)
--- a/
bookmaker.py
+++ b/
bookmaker.py
@@
-46,8
+46,6
@@
A4_HEIGHT = 29.7 * POINTS_PER_CM
A4 = (A4_WIDTH, A4_HEIGHT)
# constants specifically for --nup4
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
CUT_DEPTH = 1.95 * POINTS_PER_CM
CUT_WIDTH = 1.05 * POINTS_PER_CM
MIDDLE_POINT_DEPTH = 0.4 * POINTS_PER_CM
@@
-204,7
+202,7
@@
class Nup4Geometry:
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.
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
/ self.shrink_for_margin)
self.shrink_for_spine = 1 - spine_part_of_page
@@
-452,7
+450,7
@@
def validate_ranges(
def rotate_pages(
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°.'
pages: list[Page]
) -> None:
'For pages page numbered in args_rotate_page, rotate by 90°.'
@@
-631,18
+629,18
@@
def nup4_outer_page_transform(
page.translate(ty=(1 - nup4_geometry.shrink_for_spine) * A4_HEIGHT)
if nup4_i in {0, 1}:
y_section = A4_HEIGHT
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_H
ALF_HEIGHT
, top=A4_HEIGHT)
+ page.set_box(bottom=A4_H
EIGHT/2
, top=A4_HEIGHT)
else: # nup4_in in {2, 3}
y_section = 0
else: # nup4_in in {2, 3}
y_section = 0
- page.set_box(bottom=0, top=A4_H
ALF_HEIGHT
)
+ page.set_box(bottom=0, top=A4_H
EIGHT/2
)
x_section: float
if nup4_i in {0, 2}:
x_section = 0
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
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)
page.translate(tx=x_section, ty=y_section)
page.scale(QUARTER_SCALE_FACTOR)
@@
-660,10
+658,10
@@
def ornate_nup4(
c = Canvas(packet, pagesize=A4)
c.setLineWidth(0.1)
c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT)
c = Canvas(packet, pagesize=A4)
c.setLineWidth(0.1)
c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT)
- c.line(0, A4_H
ALF_HEIGHT, A4_WIDTH, A4_HALF_HEIGHT
)
+ c.line(0, A4_H
EIGHT/2, A4_WIDTH, A4_HEIGHT/2
)
c.line(0, 0, A4_WIDTH, 0)
c.line(0, A4_HEIGHT, 0, 0)
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)
c.line(A4_WIDTH, A4_HEIGHT, A4_WIDTH, 0)
c.save()
new_pdf = PdfReader(packet)
@@
-674,7
+672,7
@@
def ornate_nup4(
new_page.translate(tx=printable_offset_x, ty=printable_offset_y)
if not (args_analyze or is_front_page):
return
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)
x_right_spine_limit = A4_WIDTH - x_left_spine_limit
packet = BytesIO()
c = Canvas(packet, pagesize=A4)
@@
-701,11
+699,11
@@
def draw_cut(
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
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_H
ALF_HEIGHT
+ MIDDLE_POINT_DEPTH * direction
- end_point_y = A4_H
ALF_HEIGHT
+ CUT_DEPTH * direction
- canvas.line(inner_start_x, A4_H
ALF_HEIGHT
, x_spine_limit, end_point_y)
+ middle_point_y = A4_H
EIGHT/2
+ MIDDLE_POINT_DEPTH * direction
+ end_point_y = A4_H
EIGHT/2
+ CUT_DEPTH * direction
+ canvas.line(inner_start_x, A4_H
EIGHT/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, end_point_y, x_spine_limit, middle_point_y)
- canvas.line(x_spine_limit, middle_point_y, outer_start_x, A4_H
ALF_HEIGHT
)
+ canvas.line(x_spine_limit, middle_point_y, outer_start_x, A4_H
EIGHT/2
)
def main(
def main(