miscs
This commit is contained in:
1 parent
0d8970061e
commit
c30aac0572
14 files changed
+343
-48
No files matched your search
@@ -15,7 +15,8 @@ BODY_TOP = .30
|
||||
BODY_BOTTOM = .82
|
||||
DISCARD_LEFT_FRACTION = .10
|
||||
STANDARD_MARGIN_MM = 40
|
||||
MIN_MARGIN_MM = STANDARD_MARGIN_MM / 2
|
||||
MARGIN_CLEARANCE_MM = 20
|
||||
MIN_MARGIN_MM = MARGIN_CLEARANCE_MM
|
||||
|
||||
|
||||
def trimmed_left_edge(starts: list[float]) -> float | None:
|
||||
@@ -89,7 +90,7 @@ def format_groups(images: list[Image.Image], reference_width: float) -> list[lis
|
||||
|
||||
|
||||
def analyse_margins(images: list[Image.Image], render_dpi: int, reference_width: float) -> dict:
|
||||
"""Pool occupied bands per format, trim outliers, and crop at half the edge."""
|
||||
"""Pool occupied bands and use the larger half-margin or 20 mm-clearance cut."""
|
||||
starts = [0] * len(images)
|
||||
groups = []
|
||||
page_estimates = {}
|
||||
@@ -113,7 +114,8 @@ def analyse_margins(images: list[Image.Image], render_dpi: int, reference_width:
|
||||
left_mm = 0.0
|
||||
if len(values) >= min(2, len(indices)):
|
||||
status = 'near-edge' if edge < MIN_MARGIN_MM else 'margin'
|
||||
left_mm = 0.0 if edge < MIN_MARGIN_MM else edge / 2
|
||||
left_mm = (0.0 if edge < MIN_MARGIN_MM else
|
||||
max(edge / 2, edge - MARGIN_CLEARANCE_MM))
|
||||
# Secondary subpages can start in the middle of an answer. Preserve
|
||||
# their left edge even when the only visible writing is indented.
|
||||
if images[indices[0]].width < .8 * reference_width:
|
||||
@@ -152,8 +154,9 @@ def analyse_margins(images: list[Image.Image], render_dpi: int, reference_width:
|
||||
'status': 'unknown' if edge is None else
|
||||
('low' if edge < MIN_MARGIN_MM else 'normal')})
|
||||
|
||||
return {'version': 6, 'pages': pages, 'starts_px': starts, 'groups': groups,
|
||||
return {'version': 8, 'pages': pages, 'starts_px': starts, 'groups': groups,
|
||||
'no_margin_from_page': no_margin_from_page,
|
||||
'discard_left_fraction': DISCARD_LEFT_FRACTION, 'cut_fraction_of_margin': .5,
|
||||
'discard_left_fraction': DISCARD_LEFT_FRACTION, 'margin_clearance_mm': MARGIN_CLEARANCE_MM,
|
||||
'cut_fraction_of_margin': .5, 'cut_rule': 'maximum',
|
||||
'standard_margin_mm': STANDARD_MARGIN_MM, 'minimum_margin_mm': MIN_MARGIN_MM,
|
||||
'body_height_fraction': [BODY_TOP, BODY_BOTTOM]}
|
||||
Reference in new issue
Block a user