|
|
@@ -45,7 +45,7 @@ class BookletArranger(Extension):
|
|
|
rown = QHBoxLayout()
|
|
|
rown.addWidget(stats)
|
|
|
layout.addLayout(rown)
|
|
|
-
|
|
|
+
|
|
|
# Options row. Bleed, cropmarks, outer-page offset.
|
|
|
self.bleedInput = QLineEdit('24')
|
|
|
self.cropmarksCheck = QCheckBox('Cropmarks')
|
|
|
@@ -163,27 +163,38 @@ class BookletArranger(Extension):
|
|
|
|
|
|
# Actually arranges the pages into a booklet!
|
|
|
def arrangePage(self, page):
|
|
|
+ max_sheets = self.page_count / 4
|
|
|
page_name = page.name()
|
|
|
match = re.search('[0-9]+', page_name)
|
|
|
page_number = int(match[0])
|
|
|
|
|
|
# Is the page in the higher or lower half? e.g. p1-16 or p17-32?
|
|
|
+ # Calculation differs based on this.
|
|
|
high = page_number > (self.page_count / 2)
|
|
|
|
|
|
+ # Work out which paper sheet/side a page should be on.
|
|
|
+ # e.g. for 32 pages: p32 p1/p2 p31 will be on sheet 1 sides A/B.
|
|
|
+ #
|
|
|
+ # Side number 1 = sheet 1 side A (front).
|
|
|
+ # Side number 2 = sheet 1 side B (back).
|
|
|
+ # Side number 3 = sheet 2 side A (front).
|
|
|
+ # ...
|
|
|
+ #
|
|
|
if high:
|
|
|
side_number = self.page_count - page_number + 1
|
|
|
else:
|
|
|
side_number = page_number
|
|
|
- odd_side = side_number % 2 # Detect odd paper sides, as sides have different page arrangements.
|
|
|
+ current_sheet = ceil(side_number / 2)
|
|
|
+
|
|
|
+ # Work out if a page should be on the left or right side of the sheet.
|
|
|
+ front_side = side_number % 2 # Odds sheet/sides (1, 3, 5...) are front.
|
|
|
right = True
|
|
|
- if (high and odd_side) or (not high and not odd_side):
|
|
|
+ if (high and front_side) or (not high and not front_side):
|
|
|
right = False
|
|
|
- max_sheets = self.page_count / 4
|
|
|
- current_sheet = ceil(side_number / 2)
|
|
|
|
|
|
- # Add page to correct group/paper sheet side.
|
|
|
+ # Add page to correct group (which represent paper sheets/sides).
|
|
|
side_name = "p" + str(current_sheet)
|
|
|
- side_name += "f" if odd_side else "b"
|
|
|
+ side_name += "a" if front_side else "b"
|
|
|
sidegroup = self.doc.nodeByName(side_name)
|
|
|
if not sidegroup:
|
|
|
sidegroup = self.doc.createGroupLayer(side_name)
|
|
|
@@ -213,7 +224,7 @@ class BookletArranger(Extension):
|
|
|
x_diff = x_diff - (bds.right() + 1 - bds.left()) - offset
|
|
|
page.move(page_pos.x() + x_diff, page_pos.y() + y_diff)
|
|
|
|
|
|
- # Keep new bounds for crop marks.
|
|
|
+ # Keep pre-bleed bounds for crop marks.
|
|
|
bds = page.bounds()
|
|
|
|
|
|
# Bleed by stated amount on outward sides, bleed to middle on inward sides.
|
|
|
@@ -228,24 +239,31 @@ class BookletArranger(Extension):
|
|
|
self.bleedPage(page, bleed_amounts)
|
|
|
|
|
|
# Add crop marks. Which crop marks are created depends on which side the page is on.
|
|
|
- black_pixel = b'\x00\x00\x00\xff'
|
|
|
- crop_mark_width = 2
|
|
|
- crop_mark_height = 48
|
|
|
- crop_mark = QByteArray(black_pixel * crop_mark_width * crop_mark_height)
|
|
|
- ## Vertical cropmarks
|
|
|
- x = bds.right() if right else bds.left() - 1
|
|
|
- y = bds.top() - crop_mark_height - bleed_amount
|
|
|
- page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
- y = bds.bottom() + 1 + bleed_amount
|
|
|
- page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
- ## Horizontal cropmarks
|
|
|
- crop_mark_width = 48
|
|
|
- crop_mark_height = 2
|
|
|
- x = bds.right() + 1 + bleed_amount if right else bds.left() - bleed_amount - crop_mark_width
|
|
|
- y = bds.top() - 1
|
|
|
- page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
- y = bds.bottom()
|
|
|
- page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
+ if self.cropmarksCheck.isChecked():
|
|
|
+ black_pixel = b'\x00\x00\x00\xff'
|
|
|
+ crop_mark_width = 2
|
|
|
+ crop_mark_height = 48
|
|
|
+ crop_mark = QByteArray(black_pixel * crop_mark_width * crop_mark_height)
|
|
|
+ ## Vertical cropmarks
|
|
|
+ x = bds.right() if right else bds.left() - 1
|
|
|
+ ytop = bds.top() - crop_mark_height - bleed_amount
|
|
|
+ page.setPixelData(crop_mark, x, ytop, crop_mark_width, crop_mark_height)
|
|
|
+ ybot = bds.bottom() + 1 + bleed_amount
|
|
|
+ page.setPixelData(crop_mark, x, ybot, crop_mark_width, crop_mark_height)
|
|
|
+ if page_number == 1:
|
|
|
+ # Specially mark centre on first page (always p1a right side)
|
|
|
+ x = bds.left() - 1 - offset
|
|
|
+ page.setPixelData(crop_mark, x, ytop, crop_mark_width, crop_mark_height)
|
|
|
+ page.setPixelData(crop_mark, x, ybot, crop_mark_width, crop_mark_height)
|
|
|
+
|
|
|
+ ## Horizontal cropmarks
|
|
|
+ crop_mark_width = 48
|
|
|
+ crop_mark_height = 2
|
|
|
+ x = bds.right() + 1 + bleed_amount if right else bds.left() - bleed_amount - crop_mark_width
|
|
|
+ y = bds.top() - 1
|
|
|
+ page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
+ y = bds.bottom()
|
|
|
+ page.setPixelData(crop_mark, x, y, crop_mark_width, crop_mark_height)
|
|
|
|
|
|
def bleedPage(self, page, amounts):
|
|
|
|