When no margin detected, reserve a bit more space for comments

This commit is contained in:
sebastien committed 2026-10-13 21:23:48 +02:00
1 parent e7094d850e
commit 78a7b7679c
17 files changed
+357 -28

No files matched your search

@@ -25,6 +25,7 @@ from copienator import (
)
from copienator.annotation_actions import apply_checkbox_actions, apply_score_overrides
from copienator.annotation_data import AnnotationData, RefaireList, load_annotation_data
from copienator.annotation_layout import legacy_layout
from copienator.annotation_modifications import (
BASELINE,
baseline,
@@ -168,7 +169,6 @@ def _scan_annotation_directory(
if notes_image is None:
if required:
raise ValueError(f"Could not read annotations in {directory}")
return {}, {}
actions_by_student: dict[str, list[dict[str, Any]]] = defaultdict(list)
notes_by_student: dict[str, LabelNotes] = defaultdict(dict)
for action in actions:
@@ -181,12 +181,13 @@ def _scan_annotation_directory(
hmin = int(image_info.get("hmin", 0))
hmax = int(image_info.get("hmax", 0))
if student_id and label and hmax > hmin:
crop = notes_image.crop((0, hmin, notes_image.width, hmax))
if has_significant_notes(crop):
notes_by_student[student_id][label] = {
"img": crop,
"old_header_h": int(image_info.get("header_height", 0)),
}
crop = (notes_image.crop((0, hmin, notes_image.width, hmax))
if notes_image is not None else None)
notes_by_student[student_id][label] = {
"img": crop if has_significant_notes(crop) else None,
"old_header_h": int(image_info.get("header_height", 0)),
"layout": image_info.get('layout', legacy_layout()),
}
return dict(actions_by_student), dict(notes_by_student)
@@ -346,6 +347,8 @@ def apply_actions_and_regenerate_grouped(
content["coordinates"][0],
with_error=False,
with_empty=True,
source_pdf=pdf_path,
layout=label_notes.get(label, {}).get('layout', legacy_layout()),
)
if final_image is None:
incomplete = True