Refine rendering and packing logic
This commit is contained in:
+20
-2
@@ -18,6 +18,7 @@ from .settings import (
|
||||
RENDER_DIR,
|
||||
ROOT,
|
||||
TEMP_DIR,
|
||||
TEXT_SUPERSAMPLING,
|
||||
BuildConfig,
|
||||
mm_to_px,
|
||||
)
|
||||
@@ -45,8 +46,8 @@ def build_printable(config: BuildConfig) -> Path | None:
|
||||
|
||||
cols, rows = grid_capacity(config)
|
||||
print(f"Card grid: {cols} columns x {rows} rows on {config.paper_name.upper()} ({cols * rows} images/page)")
|
||||
next_page, deferred_character_items = render_card_pages(card_items, config, 1)
|
||||
next_page = render_board_pages(board_items, config, next_page, deferred_character_items)
|
||||
next_page, deferred_character_items, remaining_board_items = render_card_pages(card_items, config, 1, board_items)
|
||||
next_page = render_board_pages(remaining_board_items, config, next_page, deferred_character_items)
|
||||
pdf = write_pdf(config)
|
||||
if pdf:
|
||||
print(f"Wrote {pdf.relative_to(ROOT)}")
|
||||
@@ -123,6 +124,16 @@ def prompt_positive_int(label: str, default: int) -> int:
|
||||
return parsed
|
||||
|
||||
|
||||
def positive_int_arg(value: str) -> int:
|
||||
try:
|
||||
parsed = int(value)
|
||||
except ValueError as error:
|
||||
raise argparse.ArgumentTypeError("must be a positive integer") from error
|
||||
if parsed <= 0:
|
||||
raise argparse.ArgumentTypeError("must be a positive integer")
|
||||
return parsed
|
||||
|
||||
|
||||
def prompt_nonnegative_float(label: str, default: float) -> float:
|
||||
value = input(f"{label} [{default:g}]: ").strip()
|
||||
if not value:
|
||||
@@ -263,6 +274,7 @@ def default_config() -> BuildConfig:
|
||||
clean_edge_mm=0.35,
|
||||
output_pdf_name="",
|
||||
delete_temp=True,
|
||||
text_supersampling=TEXT_SUPERSAMPLING,
|
||||
render_only=False,
|
||||
)
|
||||
|
||||
@@ -328,6 +340,7 @@ def interactive_config(args: argparse.Namespace) -> BuildConfig:
|
||||
clean_edge_mm=default.clean_edge_mm,
|
||||
output_pdf_name=output_pdf_name,
|
||||
delete_temp=None,
|
||||
text_supersampling=args.text_supersampling or default.text_supersampling,
|
||||
render_only=default.render_only,
|
||||
)
|
||||
|
||||
@@ -352,6 +365,7 @@ def parse_args(argv=None) -> argparse.Namespace:
|
||||
parser.add_argument("--render-only", action="store_true", help="Render source card/board PNGs and skip page/PDF creation.")
|
||||
parser.add_argument("--output", help="Output PDF filename under print/. Adds .pdf if missing.")
|
||||
parser.add_argument("--rent-raised", type=int, help="Number of Rent raised encounter cards to print.")
|
||||
parser.add_argument("--text-supersampling", type=positive_int_arg, metavar="N", help="Render text at N times final resolution before downscaling.")
|
||||
parser.add_argument("--keep-temp", action="store_true", help="Keep temporary rendered PNGs under print/temp/.")
|
||||
parser.add_argument(
|
||||
"--starter-colors",
|
||||
@@ -411,6 +425,7 @@ def apply_overrides(config: BuildConfig, args: argparse.Namespace) -> BuildConfi
|
||||
clean_edge_mm=config.clean_edge_mm,
|
||||
output_pdf_name=args.output if args.output is not None else config.output_pdf_name,
|
||||
delete_temp=delete_temp,
|
||||
text_supersampling=args.text_supersampling or config.text_supersampling,
|
||||
render_only=args.render_only or config.render_only,
|
||||
)
|
||||
|
||||
@@ -435,6 +450,7 @@ def with_board_size(config: BuildConfig, board_mode: str, board_custom_mm: tuple
|
||||
clean_edge_mm=config.clean_edge_mm,
|
||||
output_pdf_name=config.output_pdf_name,
|
||||
delete_temp=config.delete_temp,
|
||||
text_supersampling=config.text_supersampling,
|
||||
render_only=config.render_only,
|
||||
)
|
||||
|
||||
@@ -475,6 +491,7 @@ def main(argv=None) -> None:
|
||||
clean_edge_mm=config.clean_edge_mm,
|
||||
output_pdf_name=config.output_pdf_name,
|
||||
delete_temp=config.delete_temp,
|
||||
text_supersampling=config.text_supersampling,
|
||||
render_only=config.render_only,
|
||||
)
|
||||
config = apply_overrides(config, args)
|
||||
@@ -495,6 +512,7 @@ def main(argv=None) -> None:
|
||||
bleed: {config.bleed_mm} mm ({mm_to_px(config.bleed_mm, config.dpi)} px at {config.dpi} DPI)
|
||||
crop black borders: {'yes' if config.crop_black_borders else 'no'}
|
||||
gamma: {'off' if not config.gamma_enabled else f'{config.gamma} with black point {config.black_point}'}
|
||||
text supersampling: {config.text_supersampling}
|
||||
output: {'rendered PNGs only' if config.render_only else 'rendered PNGs, page PNGs, and PDF'}
|
||||
pdf name: {(config.output_pdf_name.strip() or 'blockminers_printable.pdf') if not config.render_only else '<not written>'}
|
||||
temp files: {'kept for render-only output' if config.render_only else 'ask after build' if config.delete_temp is None else 'deleted after build' if config.delete_temp else 'kept under print/temp'}
|
||||
|
||||
Reference in New Issue
Block a user