Enforce configurable height and pixel limits for tablet documents

This commit is contained in:
sebastien committed 2026-10-26 15:09:05 +01:00
1 parent 8918d64452
commit a38c1ff4b3
10 files changed
+187 -57

No files matched your search

+16 -5
View File
@@ -26,7 +26,7 @@ from copienator import (
workspace_from_target,
)
from copienator.annotation_data import load_annotation_data
from copienator.annotation_documents import MAX_HEIGHT_PX, copy_documents
from copienator.annotation_documents import MAX_HEIGHT_PX, MAX_PIXELS, copy_documents, document_fits
from copienator.commands import annotating
from copienator.commands.import_annotations import clear_import_directory
from copienator.filesystem import staged_directory
@@ -212,18 +212,23 @@ def _render_student(
batches = []
start = 0
height = 0
width = 0
for index, image in enumerate(label_images):
if image.height > MAX_HEIGHT_PX:
if not document_fits(image.width, image.height, MAX_HEIGHT_PX, MAX_PIXELS):
raise CliError(
f"Copie{student_id} ({bnote_entries[index]['label']}) is "
f"{image.height} px high; a single answer cannot be split and "
f"the maximum document height is {MAX_HEIGHT_PX} px."
f"{image.width} × {image.height} px ({image.width * image.height} pixels); "
f"a single answer cannot be split. Document limits are "
f"{MAX_HEIGHT_PX} px high and {MAX_PIXELS} pixels."
)
if height + image.height > MAX_HEIGHT_PX:
if not document_fits(max(width, image.width), height + image.height,
MAX_HEIGHT_PX, MAX_PIXELS):
batches.append((start, index))
start = index
height = 0
width = 0
height += image.height
width = max(width, image.width)
batches.append((start, len(label_images)))
with staged_directory(output_dir) as staging:
@@ -251,6 +256,12 @@ def _save_document(
) -> None:
max_width = max(image.width for image in label_images)
total_height = sum(image.height for image in label_images)
if not document_fits(max_width, total_height, MAX_HEIGHT_PX, MAX_PIXELS):
raise CliError(
f"Document would be {max_width} × {total_height} px "
f"({max_width * total_height} pixels); document limits are "
f"{MAX_HEIGHT_PX} px high and {MAX_PIXELS} pixels."
)
concatenated = Image.new("RGB", (max_width, total_height), "white")
checkbox_map: list[dict[str, Any]] = []
current_y = 0