Move SheetLayout, make InputCardImage to resize
This commit is contained in:
parent
902482abb0
commit
89e20fd61e
4 changed files with 123 additions and 108 deletions
|
|
@ -0,0 +1,82 @@
|
|||
from typing import Tuple
|
||||
|
||||
from base_proxy import CARD_W_INCHES, CARD_H_INCHES, LEAVE_BLEED_INCHES
|
||||
|
||||
|
||||
class SheetLayout:
|
||||
def __init__(self, dpi: int, w_inches: float, h_inches: float):
|
||||
self.dpi = dpi
|
||||
|
||||
self.card_w_inches = CARD_W_INCHES
|
||||
self.card_h_inches = CARD_H_INCHES
|
||||
self.card_w = self.in_to_px(self.card_w_inches)
|
||||
self.card_h = self.in_to_px(self.card_h_inches)
|
||||
|
||||
self.w_inches = w_inches
|
||||
self.h_inches = h_inches
|
||||
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 = 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
|
||||
|
||||
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
|
||||
|
||||
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 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
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def letter_portrait_3x3_sheet_layout() -> SheetLayout:
|
||||
return SheetLayout(1200, 8.5, 11)
|
||||
|
||||
|
||||
def letter_landscape_2x4_sheet_layout() -> SheetLayout:
|
||||
return SheetLayout(1200, 11, 8.5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue