(
page,
caption_anchor: dict,
extra_rects: list[tuple[float, float, float, float]],
page_rect,
)
| 916 | |
| 917 | |
| 918 | def _finalize_table_bbox( |
| 919 | page, |
| 920 | caption_anchor: dict, |
| 921 | extra_rects: list[tuple[float, float, float, float]], |
| 922 | page_rect, |
| 923 | ) -> tuple[float, float, float, float] | None: |
| 924 | if not extra_rects: |
| 925 | return None |
| 926 | caption_x0, caption_y0, caption_x1, caption_y1 = caption_anchor["bbox"] |
| 927 | accepted: list[tuple[float, float, float, float]] = list(extra_rects) + [ |
| 928 | (caption_x0, caption_y0, caption_x1, caption_y1) |
| 929 | ] |
| 930 | |
| 931 | y0 = min(b[1] for b in accepted) |
| 932 | y1 = max(b[3] for b in accepted) |
| 933 | initial_x0 = min(b[0] for b in accepted) |
| 934 | initial_x1 = max(b[2] for b in accepted) |
| 935 | for r in _collect_drawing_rects(page): |
| 936 | ry_mid = (r[1] + r[3]) / 2.0 |
| 937 | if y0 - 4.0 <= ry_mid <= y1 + 4.0 and r[2] >= initial_x0 - 12.0 and r[0] <= initial_x1 + 12.0: |
| 938 | accepted.append(r) |
| 939 | for r in _collect_xref_rects(page): |
| 940 | ry_mid = (r[1] + r[3]) / 2.0 |
| 941 | if y0 - 4.0 <= ry_mid <= y1 + 4.0 and r[2] >= initial_x0 - 12.0 and r[0] <= initial_x1 + 12.0: |
| 942 | accepted.append(r) |
| 943 | |
| 944 | x0 = min(b[0] for b in accepted) |
| 945 | y0 = min(b[1] for b in accepted) |
| 946 | x1 = max(b[2] for b in accepted) |
| 947 | y1 = max(b[3] for b in accepted) |
| 948 | |
| 949 | bbox = _clip_to_page((x0, y0, x1, y1), page_rect, padding=6.0) |
| 950 | width = bbox[2] - bbox[0] |
| 951 | height = bbox[3] - bbox[1] |
| 952 | if width < MIN_FIGURE_WIDTH_PT or height < MIN_FIGURE_HEIGHT_PT: |
| 953 | return None |
| 954 | return bbox |
| 955 | |
| 956 | |
| 957 | def _estimate_table_bbox( |
no test coverage detected