modest improvement to cropping (safer)

This commit is contained in:
2026-09-15 15:13:41 +02:00
parent 9b22a8a137
commit 5b8215e7f5
6 changed files with 56 additions and 9 deletions
+11 -1
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import argparse
import math
import shutil
import tempfile
from collections import defaultdict
@@ -23,6 +24,7 @@ from copienator import (
from copienator.filesystem import staged_directory
SQUARE = 1000 // 38
ANSWER_TOP_PADDING_POINTS = 4 * 72 / 25.4
Coordinate = tuple[str, int, int, int, int, int]
ParsedCoordinate = tuple[str, str, int, int, int, int, int]
@@ -171,7 +173,15 @@ def _render_split_outputs(
for page_number in range(start_page, end_page + 1):
page = document[page_number]
y0 = (y_start / 1000) * page.rect.height if page_number == start_page else 0
y0 = (
math.floor(max(
0,
(y_start / 1000) * page.rect.height
- ANSWER_TOP_PADDING_POINTS,
))
if page_number == start_page
else 0
)
y1 = (end_y / 1000) * page.rect.height if page_number == end_page else page.rect.height
clip = pymupdf.Rect(
fraction_x0 * page.rect.width, y0,