diff --git a/paperforge/worker/ocr_document.py b/paperforge/worker/ocr_document.py index 0beacfe9..d421e13f 100644 --- a/paperforge/worker/ocr_document.py +++ b/paperforge/worker/ocr_document.py @@ -1591,7 +1591,7 @@ def infer_zones( _zone_page_width = _page_width_for_zone_block( ref_heading_block if ref_heading_block else (blocks[0] if blocks else {}), blocks, - anchors, + (anchors or {}).get("body_family_anchor"), ) body_blocks = [ @@ -1609,10 +1609,7 @@ def infer_zones( ) and ( (body_end_page is None or int(block.get("page", 0) or 0) <= body_end_page) - or ( - _is_above_same_page_reference_heading(block, refs_start_page, ref_heading_top if ref_heading_block else None) - and _is_in_same_reference_column(block, ref_heading_block, _zone_page_width) - ) + or _is_above_same_page_reference_heading(block, refs_start_page, ref_heading_top if ref_heading_block else None) ) and not _is_reference_item_candidate(block) and not _is_reference_heading_candidate(block) diff --git a/tests/test_ocr_document.py b/tests/test_ocr_document.py index 2b24d386..ce4be114 100644 --- a/tests/test_ocr_document.py +++ b/tests/test_ocr_document.py @@ -5601,3 +5601,17 @@ def test_same_page_tail_column_aware() -> None: # Left-column body below ref heading but in different column -> NOT in tail zone assert "p3_b1" not in region_bus["tail_nonref_hold_zone"]["block_ids"], \ "Left-column body should not be in tail_nonref_hold_zone despite being below ref heading" + + +def test_is_in_same_reference_column_cross_column() -> None: + from paperforge.worker.ocr_document import _is_in_same_reference_column + pw = 1200.0 + ref_heading = {"bbox": [700, 100, 1100, 140], "page_width": pw} + left_block = {"bbox": [100, 200, 500, 250], "page_width": pw} + right_block = {"bbox": [700, 200, 1100, 250], "page_width": pw} + assert _is_in_same_reference_column(left_block, ref_heading, pw) is False, "Left-column block should not be in same column as right-column ref heading" + assert _is_in_same_reference_column(right_block, ref_heading, pw) is True, "Right-column block should be in same column as right-column ref heading" + single_ref = {"bbox": [50, 100, 1150, 140], "page_width": pw} + single_block = {"bbox": [50, 200, 1150, 250], "page_width": pw} + assert _is_in_same_reference_column(single_block, single_ref, pw) is True, "Full-width blocks on single-column page should return True" + assert _is_in_same_reference_column(left_block, None, pw) is True, "None ref heading should return True (conservative)"