Cropping investigation

This commit is contained in:
sebastien committed 2026-10-11 10:12:59 +02:00
1 parent 48602c24f1
commit bd1964ffcd
10 files changed
+814 -24

No files matched your search

+14 -2
View File
@@ -20,7 +20,7 @@ class CropExerciseBottomsTests(unittest.TestCase):
page = document.new_page(width=600, height=height)
page.insert_text((80, text_y), "student answer", fontsize=16)
if footer:
page.insert_text((20, height - 3), "Ex 2", fontsize=10)
page.insert_text((20, height - 15), "9/9", fontsize=10)
document.save(path)
return path
@@ -33,7 +33,7 @@ class CropExerciseBottomsTests(unittest.TestCase):
self.assertEqual(records[0]["status"], "skipped-short")
self.assertFalse(destination.exists())
def test_footer_fragment_is_ignored_for_a_large_bottom_crop(self):
def test_isolated_page_number_allows_a_large_bottom_crop(self):
source = self.make_pdf("large.pdf", 400, 100)
destination = self.root / "out" / source.name
records = process_exercise_pdf(
@@ -45,6 +45,18 @@ class CropExerciseBottomsTests(unittest.TestCase):
self.assertLess(result[0].rect.height, 250)
self.assertAlmostEqual(result[0].rect.width, 600)
def test_content_in_former_ignored_bottom_strip_is_retained(self):
source = self.make_pdf("bottom-content.pdf", 400, 100, footer=False)
with pymupdf.open(source) as doc:
doc[0].insert_text((20, 399), "Ex 2", fontsize=10)
doc.save(self.root / "bottom-label.pdf")
records = process_exercise_pdf(
self.root / "bottom-label.pdf", self.root / "retained.pdf",
self.review, 800, dpi=150
)
self.assertEqual(records[0]["status"], "unchanged-small-crop")
self.assertFalse((self.root / "retained.pdf").exists())
def test_crop_smaller_than_four_lines_is_not_written(self):
source = self.make_pdf("small.pdf", 400, 330, footer=False)
destination = self.root / "out" / source.name