Only external bleed
This commit is contained in:
parent
89e20fd61e
commit
088181085e
3 changed files with 165 additions and 73 deletions
159
sheet_layout.py
159
sheet_layout.py
|
|
@ -1,10 +1,18 @@
|
|||
from typing import Tuple
|
||||
import dataclasses
|
||||
import math
|
||||
from typing import List, Tuple
|
||||
|
||||
from base_proxy import CARD_W_INCHES, CARD_H_INCHES, LEAVE_BLEED_INCHES
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class CardImageTransfer:
|
||||
topleft_dest: Tuple[int, int]
|
||||
bleeds: List[int]
|
||||
|
||||
|
||||
class SheetLayout:
|
||||
def __init__(self, dpi: int, w_inches: float, h_inches: float):
|
||||
def __init__(self, dpi: int, w_inches: float, h_inches: float, internal_bleed: bool):
|
||||
self.dpi = dpi
|
||||
|
||||
self.card_w_inches = CARD_W_INCHES
|
||||
|
|
@ -17,66 +25,129 @@ class SheetLayout:
|
|||
self.w = self.in_to_px(self.w_inches)
|
||||
self.h = self.in_to_px(self.h_inches)
|
||||
self.leave_bleed = self.in_to_px(LEAVE_BLEED_INCHES)
|
||||
self.cropped_image_dest_w = self.card_w + self.leave_bleed * 2
|
||||
self.cropped_image_dest_h = self.card_h + self.leave_bleed * 2
|
||||
|
||||
self.spacing_inches = 0.05
|
||||
self.spacing_inches = 0.05 if internal_bleed else 0
|
||||
self.spacing = self.in_to_px(self.spacing_inches)
|
||||
|
||||
self.min_padding_inches = 0.12
|
||||
self.min_padding = self.in_to_px(self.min_padding_inches)
|
||||
|
||||
self.cards_per_row = ((self.w - self.min_padding * 2 + self.spacing)
|
||||
// (self.cropped_image_dest_w + self.spacing))
|
||||
self.cards_per_column = ((self.h - self.min_padding * 2 + self.spacing)
|
||||
// (self.cropped_image_dest_h + self.spacing))
|
||||
self.cards_per_sheet = self.cards_per_row * self.cards_per_column
|
||||
paste_area_left_xs = []
|
||||
paste_area_right_xs = []
|
||||
card_area_left_xs = []
|
||||
card_area_right_xs = []
|
||||
cur_x = 0
|
||||
x_index = 0
|
||||
|
||||
self.total_w_content = self.cropped_image_dest_w * self.cards_per_row + self.spacing * (self.cards_per_row - 1)
|
||||
self.total_h_content = self.cropped_image_dest_h * self.cards_per_column + self.spacing * (self.cards_per_column - 1)
|
||||
self.blank_space_w = (self.w - self.total_w_content) // 2
|
||||
self.blank_space_h = (self.h - self.total_h_content) // 2
|
||||
while True:
|
||||
paste_area_left = cur_x
|
||||
if x_index == 0 or internal_bleed:
|
||||
# Left side bleed
|
||||
card_area_left = cur_x + self.leave_bleed
|
||||
else:
|
||||
card_area_left = cur_x
|
||||
card_area_right = card_area_left + self.card_w
|
||||
if internal_bleed:
|
||||
# Right side bleed (added to last card of row in break block)
|
||||
paste_area_right = card_area_right + self.leave_bleed
|
||||
else:
|
||||
paste_area_right = card_area_right
|
||||
|
||||
if paste_area_right >= self.w - 2 * self.min_padding - (self.leave_bleed if not internal_bleed else 0):
|
||||
if not internal_bleed:
|
||||
# Right side bleed of previous card
|
||||
paste_area_right_xs[-1] += self.leave_bleed
|
||||
|
||||
self.cards_per_row = x_index
|
||||
self.total_w_content = paste_area_right_xs[-1]
|
||||
|
||||
# Center content horizontally
|
||||
self.blank_space_w = (self.w - self.total_w_content) // 2
|
||||
self.paste_area_left_xs = [x + self.blank_space_w for x in paste_area_left_xs]
|
||||
self.paste_area_right_xs = [x + self.blank_space_w for x in paste_area_right_xs]
|
||||
self.card_area_left_xs = [x + self.blank_space_w for x in card_area_left_xs]
|
||||
self.card_area_right_xs = [x + self.blank_space_w for x in card_area_right_xs]
|
||||
break
|
||||
|
||||
paste_area_left_xs.append(paste_area_left)
|
||||
paste_area_right_xs.append(paste_area_right)
|
||||
card_area_left_xs.append(card_area_left)
|
||||
card_area_right_xs.append(card_area_right)
|
||||
cur_x = paste_area_right + self.spacing
|
||||
x_index += 1
|
||||
|
||||
paste_area_top_ys = []
|
||||
paste_area_bottom_ys = []
|
||||
card_area_top_ys = []
|
||||
card_area_bottom_ys = []
|
||||
cur_y = 0
|
||||
y_index = 0
|
||||
|
||||
while True:
|
||||
paste_area_top = cur_y
|
||||
if y_index == 0 or internal_bleed:
|
||||
# Top bleed
|
||||
card_area_top = cur_y + self.leave_bleed
|
||||
else:
|
||||
card_area_top = cur_y
|
||||
card_area_bottom = card_area_top + self.card_h
|
||||
if internal_bleed:
|
||||
# Bottom bleed (added to last card of column in break block)
|
||||
paste_area_bottom = card_area_bottom + self.leave_bleed
|
||||
else:
|
||||
paste_area_bottom = card_area_bottom
|
||||
|
||||
if paste_area_bottom >= self.h - 2 * self.min_padding - (self.leave_bleed if not internal_bleed else 0):
|
||||
if not internal_bleed:
|
||||
# Bottom bleed of previous card
|
||||
paste_area_bottom_ys[-1] += self.leave_bleed
|
||||
|
||||
self.cards_per_column = y_index
|
||||
self.total_h_content = paste_area_bottom_ys[-1]
|
||||
|
||||
# Center content vertically
|
||||
self.blank_space_h = (self.h - self.total_h_content) // 2
|
||||
self.paste_area_top_ys = [y + self.blank_space_h for y in paste_area_top_ys]
|
||||
self.paste_area_bottom_ys = [y + self.blank_space_h for y in paste_area_bottom_ys]
|
||||
self.card_area_top_ys = [y + self.blank_space_h for y in card_area_top_ys]
|
||||
self.card_area_bottom_ys = [y + self.blank_space_h for y in card_area_bottom_ys]
|
||||
break
|
||||
|
||||
paste_area_top_ys.append(paste_area_top)
|
||||
paste_area_bottom_ys.append(paste_area_bottom)
|
||||
card_area_top_ys.append(card_area_top)
|
||||
card_area_bottom_ys.append(card_area_bottom)
|
||||
cur_y = paste_area_bottom + self.spacing
|
||||
y_index += 1
|
||||
|
||||
self.cards_per_sheet = self.cards_per_row * self.cards_per_column
|
||||
|
||||
print(self.__dict__)
|
||||
|
||||
def in_to_px(self, inches: float) -> float:
|
||||
return round(inches * self.dpi)
|
||||
|
||||
def top_of_row(self, y_index: int, with_bleed: bool) -> int:
|
||||
assert 0 <= y_index < self.cards_per_column
|
||||
top = self.blank_space_h + (self.cropped_image_dest_h + self.spacing) * y_index
|
||||
if not with_bleed:
|
||||
top += self.leave_bleed
|
||||
return top
|
||||
def create_card_image_transfer(self, y_index: int, x_index: int) -> CardImageTransfer:
|
||||
top_row = y_index == 0
|
||||
bottom_row = y_index == self.cards_per_column - 1
|
||||
left_col = x_index == 0
|
||||
right_col = x_index == self.cards_per_row - 1
|
||||
|
||||
def bottom_of_row(self, y_index: int, with_bleed: bool) -> int:
|
||||
if with_bleed:
|
||||
return self.top_of_row(y_index, True) + self.cropped_image_dest_h
|
||||
else:
|
||||
return self.top_of_row(y_index, False) + self.card_h
|
||||
paste_x = self.paste_area_left_xs[x_index]
|
||||
paste_y = self.paste_area_top_ys[y_index]
|
||||
|
||||
def left_of_column(self, x_index: int, with_bleed: bool) -> int:
|
||||
assert 0 <= x_index < self.cards_per_row
|
||||
left = self.blank_space_w + (self.cropped_image_dest_w + self.spacing) * x_index
|
||||
if not with_bleed:
|
||||
left += self.leave_bleed
|
||||
return left
|
||||
|
||||
def right_of_column(self, x_index: int, with_bleed: bool) -> int:
|
||||
if with_bleed:
|
||||
return self.left_of_column(x_index, True) + self.cropped_image_dest_w
|
||||
else:
|
||||
return self.left_of_column(x_index, False) + self.card_w
|
||||
|
||||
def topleft_of_card_with_bleed(self, y_index: int, x_index: int) -> Tuple[int, int]:
|
||||
x = self.left_of_column(x_index, with_bleed=True)
|
||||
y = self.top_of_row(y_index, with_bleed=True)
|
||||
return (x, y)
|
||||
bleeds = [
|
||||
self.leave_bleed if top_row else 0,
|
||||
self.leave_bleed if bottom_row else 0,
|
||||
self.leave_bleed if left_col else 0,
|
||||
self.leave_bleed if right_col else 0]
|
||||
return CardImageTransfer((paste_x, paste_y), bleeds)
|
||||
|
||||
|
||||
def letter_portrait_3x3_sheet_layout() -> SheetLayout:
|
||||
return SheetLayout(1200, 8.5, 11)
|
||||
return SheetLayout(1200, 8.5, 11, False)
|
||||
|
||||
|
||||
def letter_landscape_2x4_sheet_layout() -> SheetLayout:
|
||||
return SheetLayout(1200, 11, 8.5)
|
||||
return SheetLayout(1200, 11, 8.5, False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue