Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: add leading typography width detection and enhance page footnote handling

myhloli4ee9d4adfe4e
diff --git a/mineru/model/flash/pdf/auxiliary_text.py b/mineru/model/flash/pdf/auxiliary_text.py
index 96a59949..b6d56734 100644
--- a/mineru/model/flash/pdf/auxiliary_text.py
+++ b/mineru/model/flash/pdf/auxiliary_text.py
@@ -556,7 +556,18 @@ def _footnote_lane_members(
# 同时限制绝对短线、相对长线和左缘偏移,排除图标、公式线及跨栏正文分隔线。
if rule_width < max(4.0 * median_height, 0.04 * local_page_width):
return set()
- if abs(rule_bbox[0] - lane.left) > max(2.0 * median_height, 0.04 * lane_width):
+ strict_left_tolerance = max(
+ 2.0 * median_height,
+ 0.04 * lane_width,
+ )
+ strict_left_alignment = (
+ abs(rule_bbox[0] - lane.left) <= strict_left_tolerance
+ )
+ relaxed_left_alignment = (
+ rule_bbox[0] < lane.left
+ and lane.left - rule_bbox[0] <= 2.25 * median_height
+ )
+ if not strict_left_alignment and not relaxed_left_alignment:
return set()
rule_center_y = _bbox_center_y(rule_bbox)
@@ -621,6 +632,24 @@ def _footnote_lane_members(
if _effective_text_row_gap(members[-1], current) > continuation_gap_limit:
break
members.append(current)
+ if relaxed_left_alignment and not strict_left_alignment:
+ first_bbox = members[0][1]
+ first_height = _line_effective_height(*members[0])
+ reference_height = max(
+ median_height,
+ page_median_height or 0.0,
+ )
+ horizontal_overlap = max(
+ 0.0,
+ min(rule_bbox[2], first_bbox[2])
+ - max(rule_bbox[0], first_bbox[0]),
+ )
+ if (
+ len(members) < 2
+ or first_height > 0.9 * reference_height
+ or horizontal_overlap / max(0.1, rule_width) < 0.8
+ ):
+ return set()
return {line.source_index for line, _bbox in members}
diff --git a/mineru/model/flash/pdf/line_merging.py b/mineru/model/flash/pdf/line_merging.py
index a4f7953f..c190d69a 100644
--- a/mineru/model/flash/pdf/line_merging.py
+++ b/mineru/model/flash/pdf/line_merging.py
@@ -369,6 +369,7 @@ def _merge_overlapping_inline_cluster(
dominant_font_weight=host.dominant_font_weight,
median_glyph_width=host.median_glyph_width,
leading_emphasis_width=ordered_members[0].leading_emphasis_width,
+ leading_typography_width=ordered_members[0].leading_typography_width,
split_from_row=any(line.split_from_row for line in ordered_members),
preserve_split_boundary=any(line.preserve_split_boundary for line in ordered_members),
semantic_type=host.semantic_type,
@@ -667,6 +668,7 @@ def _merge_same_baseline_group(
if any(member.median_glyph_width is not None for member in members)
else None,
leading_emphasis_width=members[0].leading_emphasis_width,
+ leading_typography_width=members[0].leading_typography_width,
split_from_row=any(member.split_from_row for member in members),
preserve_split_boundary=any(member.preserve_split_boundary for member in members),
semantic_type=members[0].semantic_type,
@@ -1117,6 +1119,7 @@ def _merge_dense_split_visual_row(
if any(member.median_glyph_width is not None for member in ordered_members)
else None,
leading_emphasis_width=ordered_members[0].leading_emphasis_width,
+ leading_typography_width=ordered_members[0].leading_typography_width,
split_from_row=False,
preserve_split_boundary=any(member.preserve_split_boundary for member in ordered_members),
semantic_type=ordered_members[0].semantic_type,
diff --git a/mineru/model/flash/pdf/models.py b/mineru/model/flash/pdf/models.py
index 0432a73e..f6f8e1b6 100644
--- a/mineru/model/flash/pdf/models.py
+++ b/mineru/model/flash/pdf/models.py
@@ -40,6 +40,7 @@ class _LineItem:
dominant_font_weight: float | None = None
median_glyph_width: float | None = None
leading_emphasis_width: float | None = None
+ leading_typography_width: float | None = None
split_from_row: bool = False
preserve_split_boundary: bool = False
semantic_type: str | None = None
diff --git a/mineru/model/flash/pdf/native_text.py b/mineru/model/flash/pdf/native_text.py
index 19c93d91..fcecbcf5 100644
--- a/mineru/model/flash/pdf/native_text.py
+++ b/mineru/model/flash/pdf/native_text.py
@@ -635,6 +635,51 @@ def _detect_leading_emphasis_width(
return max(0.1, prefix_bbox[2] - prefix_bbox[0])
+def _normalized_font_family(
+ signature: tuple[str, int] | None,
+) -> str | None:
+ """移除 PDF 子集前缀并归一化字体族,供行首排版切换判断使用。"""
+
+ if signature is None:
+ return None
+ name = re.sub(r"^[A-Z]{6}\+", "", signature[0])
+ return re.sub(r"[\s_-]+", "", name).casefold() or None
+
+
+def _detect_leading_typography_width(
+ glyphs: list[tuple[BBox, tuple[str, int] | None, float | None]],
+) -> float | None:
+ """提取与同行主体字体族不同的连续行首 run 几何宽度。"""
+
+ if len(glyphs) < 4:
+ return None
+ first_signature = glyphs[0][1]
+ first_family = _normalized_font_family(first_signature)
+ if first_signature is None or first_family is None:
+ return None
+ prefix = []
+ body = []
+ reached_body = False
+ for glyph in glyphs:
+ if not reached_body and glyph[1] == first_signature:
+ prefix.append(glyph)
+ continue
+ reached_body = True
+ body.append(glyph)
+ if len(prefix) < 2 or len(body) < 2:
+ return None
+ body_signatures = Counter(signature for _bbox, signature, _weight in body if signature is not None)
+ if not body_signatures:
+ return None
+ body_signature, body_count = body_signatures.most_common(1)[0]
+ if body_count < 2 or _normalized_font_family(body_signature) == first_family:
+ return None
+ prefix_bbox = _bbox_union_many(
+ [bbox for bbox, _signature, _weight in prefix],
+ )
+ return max(0.1, prefix_bbox[2] - prefix_bbox[0])
+
+
def _fill_native_typography(line: _LineItem, page_size: tuple[float, float]) -> None:
"""使用原始 bbox、PDF 字号和 dominant font 填充两套排版特征。"""
@@ -691,6 +736,9 @@ def _fill_native_typography(line: _LineItem, page_size: tuple[float, float]) ->
line.font_coverage = 0.0
line.dominant_font_weight = None
line.leading_emphasis_width = _detect_leading_emphasis_width(glyph_typography)
+ line.leading_typography_width = _detect_leading_typography_width(
+ glyph_typography,
+ )
def _is_detached_inline_script_candidate(
diff --git a/mineru/model/flash/pdf/pipeline.py b/mineru/model/flash/pdf/pipeline.py
index 0c4fdd8c..5dc40858 100644
--- a/mineru/model/flash/pdf/pipeline.py
+++ b/mineru/model/flash/pdf/pipeline.py
@@ -835,6 +835,11 @@ def _finalize_prepared_page(
prepared.drawing_lines,
page_footnote_groups=prepared.page_footnote_groups,
page_index=page_index,
+ visual_bboxes=[
+ block["bbox"]
+ for block in prepared.fixed_blocks
+ if block.get("type") == "image"
+ ],
)
text_blocks = _merge_multiline_title_blocks(text_blocks)
text_blocks = _merge_front_matter_column_blocks(
diff --git a/mineru/model/flash/pdf/tables.py b/mineru/model/flash/pdf/tables.py
index 33ff13ad..0455901f 100644
--- a/mineru/model/flash/pdf/tables.py
+++ b/mineru/model/flash/pdf/tables.py
@@ -51,7 +51,11 @@ from .geometry import (
_rotate_bbox_to_upright,
_transform_axis_lines,
)
-from .line_layout import _line_effective_height, _line_tight_output_bbox
+from .line_layout import (
+ _font_signatures_share_family,
+ _line_effective_height,
+ _line_tight_output_bbox,
+)
from .line_merging import _same_baseline_geometry
from .native_text import _normalize_native_run_text
@@ -2146,25 +2150,79 @@ def _materialize_table_annotations(
),
)
for annotation in annotations:
- block = _build_table_annotation_block(
+ annotation_blocks = _build_table_annotation_blocks(
source,
candidate,
annotation,
)
- if block is None:
+ if not annotation_blocks:
failed_annotations.append(annotation)
continue
- blocks.append(block)
+ blocks.extend(annotation_blocks)
externalized_line_indices.update(annotation.line_indices)
return blocks, externalized_line_indices, failed_annotations
-def _build_table_annotation_block(
+def _split_table_annotation_visual_groups(
+ line_geometry: list[tuple[_LineItem, BBox]],
+) -> list[list[tuple[_LineItem, BBox]]]:
+ """用短尾后的字体或字号重启拆分独立表格注释段。"""
+
+ if len(line_geometry) < 2:
+ return [line_geometry] if line_geometry else []
+ maximum_width = max(bbox[2] - bbox[0] for _line, bbox in line_geometry)
+ group_left = min(bbox[0] for _line, bbox in line_geometry)
+ groups = [[line_geometry[0]]]
+ for previous, current in zip(line_geometry, line_geometry[1:]):
+ previous_line, previous_bbox = previous
+ current_line, current_bbox = current
+ previous_width = previous_bbox[2] - previous_bbox[0]
+ current_width = current_bbox[2] - current_bbox[0]
+ pair_height = max(
+ _line_effective_height(*previous),
+ _line_effective_height(*current),
+ )
+ font_switch = (
+ previous_line.font_signature is not None
+ and current_line.font_signature is not None
+ and previous_line.font_coverage >= 0.6
+ and current_line.font_coverage >= 0.75
+ and not _font_signatures_share_family(
+ previous_line.font_signature,
+ current_line.font_signature,
+ )
+ )
+ scale_ratio = max(
+ previous_line.em_height or _line_effective_height(*previous),
+ current_line.em_height or _line_effective_height(*current),
+ ) / max(
+ 0.1,
+ min(
+ previous_line.em_height or _line_effective_height(*previous),
+ current_line.em_height or _line_effective_height(*current),
+ ),
+ )
+ vertical_gap = current_bbox[1] - (previous_bbox[1] + _line_effective_height(*previous))
+ should_split = (
+ previous_width <= 0.45 * maximum_width
+ and current_width >= 0.75 * maximum_width
+ and current_bbox[0] - group_left <= 3.0 * pair_height
+ and -0.25 * pair_height <= vertical_gap <= 0.75 * pair_height
+ and (font_switch or scale_ratio >= 1.25)
+ )
+ if should_split:
+ groups.append([current])
+ else:
+ groups[-1].append(current)
+ return groups
+
+
+def _build_table_annotation_blocks(
source: _PageSource,
candidate: _TableCandidate,
annotation: _TableAnnotation,
-) -> dict[str, Any] | None:
- """按父表格局部方向整理原生行,并生成保留排版元数据的独立注释块。"""
+) -> list[dict[str, Any]]:
+ """按视觉重启切分原生行,并生成保留排版元数据的独立注释块。"""
line_geometry = [
(
@@ -2180,43 +2238,59 @@ def _build_table_annotation_block(
]
# 原生来源顺序可抵抗旋转文字同一基线上的字形顶边抖动。
line_geometry.sort(key=lambda item: item[0].source_index)
- content = _merge_table_annotation_content(
- [line.text for line, _local_bbox in line_geometry],
- )
- if not line_geometry or not content:
- return None
- local_output_line_bboxes = []
- output_bbox_repaired = False
- for line, local_bbox in line_geometry:
- tight_candidate = _line_tight_output_bbox(line, source.page_size)
- if tight_candidate is None:
- local_output_line_bboxes.append(local_bbox)
- else:
- local_output_line_bboxes.append(
- _rotate_bbox_to_upright(
- tight_candidate,
- source.page_size,
- candidate.angle,
- )
+ blocks = []
+ for group in _split_table_annotation_visual_groups(line_geometry):
+ content = _merge_table_annotation_content(
+ [line.text for line, _local_bbox in group],
+ )
+ if not content:
+ continue
+ local_output_line_bboxes = []
+ output_bbox_repaired = False
+ for line, local_bbox in group:
+ tight_candidate = _line_tight_output_bbox(
+ line,
+ source.page_size,
)
- output_bbox_repaired = True
- return {
- "type": annotation.kind,
- "bbox": annotation.bbox,
- "angle": candidate.angle,
- "content": content,
- "_local_line_bboxes": [bbox for _line, bbox in line_geometry],
- "_local_output_line_bboxes": local_output_line_bboxes,
- "_output_bbox_repaired": output_bbox_repaired,
- "_line_heights": [_line_effective_height(line, bbox) for line, bbox in line_geometry],
- "_font_signatures": {
- line.font_signature
- for line, _bbox in line_geometry
- if line.font_signature is not None and line.font_coverage >= 0.5
- },
- # 已由表格检测器给出完整边界,禁止通用表注规则继续向下扩张。
- "_table_annotation_complete": True,
- }
+ if tight_candidate is None:
+ local_output_line_bboxes.append(local_bbox)
+ else:
+ local_output_line_bboxes.append(
+ _rotate_bbox_to_upright(
+ tight_candidate,
+ source.page_size,
+ candidate.angle,
+ )
+ )
+ output_bbox_repaired = True
+ blocks.append(
+ {
+ "type": annotation.kind,
+ "bbox": _bbox_union_many(
+ [
+ annotation.line_bboxes.get(
+ line.source_index,
+ line.bbox,
+ )
+ for line, _local_bbox in group
+ ]
+ ),
+ "angle": candidate.angle,
+ "content": content,
+ "_local_line_bboxes": [bbox for _line, bbox in group],
+ "_local_output_line_bboxes": local_output_line_bboxes,
+ "_output_bbox_repaired": output_bbox_repaired,
+ "_line_heights": [_line_effective_height(line, bbox) for line, bbox in group],
+ "_font_signatures": {
+ line.font_signature
+ for line, _bbox in group
+ if line.font_signature is not None and line.font_coverage >= 0.5
+ },
+ # 已由表格检测器给出完整边界,禁止通用表注规则继续向下扩张。
+ "_table_annotation_complete": True,
+ }
+ )
+ return blocks
def _merge_table_annotation_content(line_texts: list[str]) -> str:
diff --git a/mineru/model/flash/pdf/text_blocks.py b/mineru/model/flash/pdf/text_blocks.py
index 281b9aed..e32f00ea 100644
--- a/mineru/model/flash/pdf/text_blocks.py
+++ b/mineru/model/flash/pdf/text_blocks.py
@@ -536,9 +536,18 @@ def _split_unmarked_page_footnote_entries(
previous_width = previous[1][2] - previous[1][0]
previous_is_near_full = previous_width >= 0.8 * maximum_row_width
current_is_indented = current[1][0] - base_left > indent_threshold
+ same_left_compact_continuation = (
+ not first_line_is_indented
+ and previous_width >= 0.7 * maximum_row_width
+ and abs(current[1][0] - previous[1][0]) <= 0.5 * indent_threshold
+ and _title_fonts_compatible(previous[0], current[0])
+ and _effective_text_row_gap(previous, current) <= indent_threshold
+ )
# 满行后必然续接;其余行按首页观测到的首行/续行缩进模式决定边界。
- continues_previous = previous_is_near_full or (
- not current_is_indented if first_line_is_indented else current_is_indented
+ continues_previous = (
+ previous_is_near_full
+ or same_left_compact_continuation
+ or (not current_is_indented if first_line_is_indented else current_is_indented)
)
if continues_previous:
entries[-1].append(current[0])
@@ -760,6 +769,96 @@ def _isolated_indented_paragraph_break_sources(
return output
+def _centered_visual_reset_break_sources(
+ lane: _TextLane,
+ visual_bboxes: Sequence[BBox],
+ local_page_height: float,
+) -> set[int]:
+ """识别视觉主体下方短居中行到更宽居中行的独立注释重启。"""
+
+ if not visual_bboxes:
+ return set()
+ rows = sorted(
+ (item for item in lane.lines if item[0].semantic_type is None),
+ key=lambda item: (item[1][1], item[1][0], item[0].source_index),
+ )
+ output: set[int] = set()
+ for previous, current in zip(rows, rows[1:]):
+ previous_bbox = previous[1]
+ current_bbox = current[1]
+ previous_width = previous_bbox[2] - previous_bbox[0]
+ current_width = current_bbox[2] - current_bbox[0]
+ pair_height = max(
+ _line_effective_height(*previous),
+ _line_effective_height(*current),
+ )
+ if (
+ previous_width > 0.7 * current_width
+ or current_bbox[0] > previous_bbox[0] - 0.25 * pair_height
+ or current_bbox[2] < previous_bbox[2] + 0.25 * pair_height
+ or abs(_bbox_center_x(previous_bbox) - _bbox_center_x(current_bbox)) > 0.1 * current_width
+ ):
+ continue
+ vertical_gap = _effective_text_row_gap(previous, current)
+ if not -0.25 * pair_height <= vertical_gap <= 0.75 * pair_height:
+ continue
+ if any(
+ -0.25 * pair_height <= previous_bbox[1] - visual_bbox[3] <= max(2.0 * pair_height, 0.03 * local_page_height)
+ and _bbox_axis_overlap_ratio(current_bbox, visual_bbox, axis="x") >= 0.8
+ and abs(_bbox_center_x(current_bbox) - _bbox_center_x(visual_bbox))
+ <= 0.12 * max(current_width, visual_bbox[2] - visual_bbox[0])
+ for visual_bbox in visual_bboxes
+ ):
+ output.add(current[0].source_index)
+ return output
+
+
+def _leading_typography_reset_break_sources(
+ lane: _TextLane,
+ regular_gap: float,
+ gap_mad: float,
+) -> set[int]:
+ """识别短尾之后以独立行首字体 run 开启的宽行结构段。"""
+
+ rows = sorted(
+ (item for item in lane.lines if item[0].semantic_type is None),
+ key=lambda item: (item[1][1], item[1][0], item[0].source_index),
+ )
+ lane_width = max(0.1, lane.right - lane.left)
+ output: set[int] = set()
+ for previous, current in zip(rows, rows[1:]):
+ previous_width = previous[1][2] - previous[1][0]
+ current_width = current[1][2] - current[1][0]
+ pair_height = max(
+ _line_effective_height(*previous),
+ _line_effective_height(*current),
+ )
+ if (
+ current[0].leading_typography_width is None
+ or current[0].leading_typography_width > 0.2 * lane_width
+ or previous_width > 0.45 * lane_width
+ or current_width < 0.75 * lane_width
+ or abs(previous[1][0] - lane.left) > 0.75 * pair_height
+ or abs(current[1][0] - lane.left) > 0.75 * pair_height
+ or current[0].formula_candidate_only
+ or current[0].compact_formula_cluster
+ or current[0].inline_math_regions
+ ):
+ continue
+ vertical_gap = _effective_body_text_row_gap(previous, current)
+ if (
+ -0.25 * pair_height
+ <= vertical_gap
+ <= regular_gap
+ + max(
+ 0.75 * pair_height,
+ 3.0 * gap_mad,
+ )
+ ):
+ output.add(current[0].source_index)
+ return output
+
+
def _front_matter_keyword_break_sources(
lane: _TextLane,
local_page_height: float,
@@ -877,6 +976,7 @@ def _build_text_blocks(
*,
page_footnote_groups: Sequence[set[int]] | None = None,
page_index: int | None = None,
+ visual_bboxes: Sequence[BBox] | None = None,
) -> list[dict[str, Any]]:
"""先构建分组脚注,再按类型屏障、栏带和自然段边界聚合其余文本。"""
@@ -895,6 +995,7 @@ def _build_text_blocks(
median_height = statistics.median(effective_heights) if effective_heights else 1.0
local_page_width = page_size[1] if angle in {90, 270} else page_size[0]
local_page_height = page_size[0] if angle in {90, 270} else page_size[1]
+ local_visual_bboxes = [_rotate_bbox_to_upright(bbox, page_size, angle) for bbox in (visual_bboxes or [])]
lanes = _infer_text_lanes(line_geometry, local_page_width, median_height)
local_axis_lines = _transform_axis_lines(drawing_lines or [], page_size, angle)
split_row_counts: dict[int, int] = {}
@@ -921,7 +1022,21 @@ def _build_text_blocks(
structured_break_sources.update(
isolated_break_sources,
)
+ visual_reset_sources = _centered_visual_reset_break_sources(
+ lane,
+ local_visual_bboxes,
+ local_page_height,
+ )
+ typography_reset_sources = _leading_typography_reset_break_sources(
+ lane,
+ regular_gap,
+ gap_mad,
+ )
+ structured_break_sources.update(visual_reset_sources)
+ structured_break_sources.update(typography_reset_sources)
protected_break_sources: set[int] = set()
+ protected_break_sources.update(visual_reset_sources)
+ protected_break_sources.update(typography_reset_sources)
protected_break_sources.update(
_front_matter_keyword_break_sources(
lane,
@@ -2418,9 +2533,7 @@ def _merge_internal_text_block_group(
merged["_local_output_line_bboxes"] = [
bbox for index in ordered_indices for bbox in blocks[index].get("_local_output_line_bboxes", [])
]
- merged["_output_bbox_repaired"] = any(
- blocks[index].get("_output_bbox_repaired") is True for index in ordered_indices
- )
+ merged["_output_bbox_repaired"] = any(blocks[index].get("_output_bbox_repaired") is True for index in ordered_indices)
merged["_line_heights"] = [height for index in ordered_indices for height in blocks[index].get("_line_heights", [])]
merged["_font_signatures"] = set().union(
*[
@@ -2576,9 +2689,7 @@ def _merge_spatial_text_components(
merged["_local_output_line_bboxes"] = [
bbox for index in ordered_indices for bbox in blocks[index].get("_local_output_line_bboxes", [])
]
- merged["_output_bbox_repaired"] = any(
- blocks[index].get("_output_bbox_repaired") is True for index in ordered_indices
- )
+ merged["_output_bbox_repaired"] = any(blocks[index].get("_output_bbox_repaired") is True for index in ordered_indices)
merged["_line_heights"] = [height for index in ordered_indices for height in blocks[index].get("_line_heights", [])]
merged["_font_signatures"] = set().union(
*[
diff --git a/tests/fixtures/flash_layout_block_expectations.json b/tests/fixtures/flash_layout_block_expectations.json
index b384dcbf..f8844f71 100644
--- a/tests/fixtures/flash_layout_block_expectations.json
+++ b/tests/fixtures/flash_layout_block_expectations.json
@@ -5,17 +5,17 @@
"path": "demo/pdfs/中文论文.pdf",
"sha256": "7fe627f5c376d1fd32a231648a6d9f3cd95a071e0773bb4a00cb9d359ea20a9a",
"type_counts": {
- "caption": 18,
+ "caption": 22,
"doc_title": 2,
"equation": 6,
- "footnote": 1,
+ "footnote": 2,
"header": 24,
"image": 8,
"page_footnote": 4,
"page_number": 9,
"paragraph_title": 19,
"table": 3,
- "text": 106
+ "text": 107
},
"exact_typed_text": [
{"page_index": 0, "type": "header", "text": "2026年4月"},
@@ -37,6 +37,30 @@
{
"page_index": 0,
"fragments": ["2026年4月", "DOI:10.7522"]
+ },
+ {
+ "page_index": 2,
+ "fragments": ["注:异常值采用", "Note:Outlier detection"]
+ },
+ {
+ "page_index": 5,
+ "fragments": ["图4 Stacking模型真实值", "Fig. 4 Comparison"]
+ },
+ {
+ "page_index": 5,
+ "fragments": ["图5 Voting模型真实值", "Fig. 5 Comparison"]
+ },
+ {
+ "page_index": 6,
+ "fragments": ["图6 Stacking模型SHAP", "Fig. 6 SHAP"]
+ },
+ {
+ "page_index": 6,
+ "fragments": ["图7 Voting模型SHAP", "Fig. 7 SHAP"]
+ },
+ {
+ "page_index": 9,
+ "fragments": ["Abstract: Traditional", "Key words: silty sand"]
}
]
},
@@ -47,17 +71,21 @@
"caption": 5,
"doc_title": 2,
"equation": 14,
- "footer": 1,
"header": 50,
"image": 5,
- "page_footnote": 1,
+ "page_footnote": 2,
"page_number": 22,
"paragraph_title": 40,
"table": 2,
"text": 312
},
"exact_typed_text": [
- {"page_index": 2, "type": "caption", "text": "续表"}
+ {"page_index": 2, "type": "caption", "text": "续表"},
+ {
+ "page_index": 0,
+ "type": "page_footnote",
+ "text": "收稿日期:2023-07-19定稿日期:2023-10-30基金项目:新一代人工智能国家科技重大专项(2022ZD0116308)"
+ }
],
"same_block_groups": [
{
diff --git a/tests/fixtures/flash_layout_geometry_manifest.json b/tests/fixtures/flash_layout_geometry_manifest.json
index a191942a..218cf822 100644
--- a/tests/fixtures/flash_layout_geometry_manifest.json
+++ b/tests/fixtures/flash_layout_geometry_manifest.json
@@ -1995,8 +1995,8 @@
},
{
"page_index": 4,
- "fingerprint": "9628364973945ac7ffbceb9094aa09b9d25a0c88783b814637291bce20122ea6",
- "bbox_fingerprint": "2f52c50b71aa97c63efc144b8760ae9841b1b97b522f121dc366198d8e006300",
+ "fingerprint": "c31e76e61163cd637ddd7880b03ecd20d38af83a7f5e84f31887d26854a5608b",
+ "bbox_fingerprint": "5a25a03d678fc4ac4119bfbe957914ea8fc8d62b683d4a66b0c7d4bafe13ee64",
"approved": true,
"blocks": [
{
@@ -2030,32 +2030,22 @@
"text_sha256": "7552137a67fb2ac7a638e6692a4bc2726a4b97648ef4453cdb362ed56b9392f8"
},
{
- "id": "90b762039431c0a6448b",
+ "id": "0a8438790b171f49603a",
"type": "text",
- "text_sha256": "4cd94246420951d0d567809fa3c727cc1977dffae66a8cf958e021cffe9bf908"
+ "text_sha256": "8b5ee5f6e28b02aad8ea0fbfa0edacc03ea8045985d2d56c9806d9709a317ea7"
},
{
- "id": "167b2b9852af9de174d7",
- "type": "equation",
- "text_sha256": "dfe3ef59c8039d28b0d0ca5196fb00048187a471e5c28ec92fb5e0303253000b"
- },
- {
- "id": "0cbd1bfb78d0edc47805",
- "type": "text",
- "text_sha256": "562aec27358bc7b0b93bcbb0087f68e9cef37280537893343cffdb9df8ba68fd"
- },
- {
- "id": "16143b1cf3c631d9174e",
+ "id": "453cfa56214ad489830a",
"type": "paragraph_title",
"text_sha256": "12bf6117a0cf755f6032a86d5ce516263c3a2c6135d35589cb6025ea4d9b1c20"
},
{
- "id": "728db11892f5e9d4ce4b",
+ "id": "223733e5d1cf66934184",
"type": "text",
"text_sha256": "6042376df88b1af9dd545c6d43f1048db2ccfadf27c4bd2391e27fc1d37ed871"
},
{
- "id": "6e4b731e3d2d75b6103c",
+ "id": "114814c50d26fafc922b",
"type": "text",
"text_sha256": "9361fd7e69ebb026b08b0584d8dacbf1ba49110596c109a3d6e4c8ab57334766"
}
@@ -3328,8 +3318,8 @@
},
{
"page_index": 1,
- "fingerprint": "9d023ace95b1dd0a8c242e3e363274646f4a75ccc86b79d8a876fc4a3770c90c",
- "bbox_fingerprint": "295330f91bd5c1373a1c3bf745fc7779a95de2e0ce43eea62ea096f927504e48",
+ "fingerprint": "0312f0981bf8e43822179788fa84911f89bdedf2703cd23d33fd022952c63ddd",
+ "bbox_fingerprint": "7fea71c3ca97609e6bba7bc667793d22444e95c87392514af71a248704a5d84b",
"approved": true,
"blocks": [
{
@@ -3393,9 +3383,9 @@
"text_sha256": "4e0df7ac09bb1838dfe50dac0b1c0905c55dd6372fb155f5826d36a6fd988fed"
},
{
- "id": "2396ea28f28bdd357316",
- "type": "equation",
- "text_sha256": "86904351beea0f1915fa7f194c8bd083b110ac9be94f43865794d24117f5dd14"
+ "id": "1fd66179b489dbb9511e",
+ "type": "text",
+ "text_sha256": "0bd5632323c7a3b6a115b608c61da8de99ec31fcb4596fc82a91784414b02a7c"
},
{
"id": "6372be2369f6ac2f5ba1",
@@ -8907,8 +8897,8 @@
},
{
"page_index": 2,
- "fingerprint": "1ab89f6e4fc48c42e7c27a525b41e316876558ff63f35e9192b60031a0c1201d",
- "bbox_fingerprint": "796008e9b7be72556f746063bbbf9686d500484d72635093dc821c0e99689e39",
+ "fingerprint": "a4b2c328a7065534f1ef2d4f0ceed9b7be682d870f03a582126957ddf7a63094",
+ "bbox_fingerprint": "d10f00b989a0b594d00f762f93b5ac095ee10104b534dad5feccf96bf04bb212",
"approved": true,
"blocks": [
{
@@ -8972,92 +8962,97 @@
"text_sha256": "b0f268a89531609fcf106fb93337b5f44268c07ab6c1dcbfe20ff0c3e87f04f4"
},
{
- "id": "b42f13d3e63a3c9266e3",
+ "id": "72e0930c0d92b57fe9ad",
"type": "footnote",
- "text_sha256": "faf0bbe095ab6135447ad26c160228caaaf0462ee35f3b82ddf5a7c199e64686"
+ "text_sha256": "f5ad20288c56bdfdf77fa78e9d54f336f9e168364e96f007b333e56ace890966"
},
{
- "id": "18f3750ad18b4f273380",
+ "id": "2aa1677657dbd146c391",
+ "type": "footnote",
+ "text_sha256": "d1d29ac5e46a9e0851a19cf4a045bf70fd30e22116542bb5c2b7dafcf03d139e"
+ },
+ {
+ "id": "058fa920ce4da7c6389e",
"type": "text",
"text_sha256": "4bfd6519156e7f6eba601c953c1e2cb9fdbea07d65ad738cec0f4556ad8b93c2"
},
{
- "id": "9cf43c596c6d634870f8",
+ "id": "5101c090d8ef5c58e518",
"type": "paragraph_title",
"text_sha256": "e6efd046b3b0a3f9cfc0123d83385c7a693e01d92afeeaadd71c08ab268bc0d2"
},
{
- "id": "76721636a87f91971369",
+ "id": "8bc845b5aac6723e68c1",
"type": "paragraph_title",
"text_sha256": "7f82629df7e3cc4316e988c665ed1038522961d68b3524b5ded66c27f20facf3"
},
{
- "id": "a85f99d4329327bf24c4",
+ "id": "c1dfb6ecec98c19ac234",
"type": "text",
"text_sha256": "6c197f8be31b49d5b38a012f9c75f9aebca50d1077c1a5df151cb6634fb7975e"
},
{
- "id": "909445052d063e283e24",
+ "id": "bf6d82c93643970273f9",
"type": "text",
"text_sha256": "fe1095ea97d7e47fe6fb4008e80a15ebe060730aaf3da42f42bdbeb5b55a4372"
},
{
- "id": "5f43a37c643c93986a74",
+ "id": "8ac036f13daa30d47d40",
"type": "equation",
"text_sha256": "a492609a8b52523a0a675f6e901895a95ae95b31fbcd03218485b04441638f57"
},
{
- "id": "b1a14e4ae6771432c064",
+ "id": "d1f9b30590d345975b54",
"type": "text",
"text_sha256": "cd619a5003bbfedcb28e8eed368070c2c176f53aaa320e5c44ffb10f01299b0b"
},
{
- "id": "146e15f851fbe2a4febd",
+ "id": "4e9c5619cbfb653cf44f",
"type": "text",
"text_sha256": "888e43746a6f70c8de6445f1e479c2f604b4d9fcd3edc8ba7fa7e219e9a7a650"
},
{
- "id": "4968b1f0e6923aa0c25d",
+ "id": "0ba2609c7fc3484ddf42",
"type": "equation",
"text_sha256": "39d80b72544d98f3db20d9791b7c48eaae007e600031f86209d5587187a04304"
},
{
- "id": "db1ea6589bf84eac530b",
+ "id": "4fd39e7ed8ba63ca866a",
"type": "text",
"text_sha256": "5ded470bab88364ed2109fca0678e88e8e685d1c5c6e9410193c97d79d30401c"
},
{
- "id": "64b19fd3340bb3211994",
+ "id": "bd84cad610ecc719ed03",
"type": "text",
"text_sha256": "0ae4e1204eea3de50461b70abc68383cd8de56b82f24fdfd44f53808db6dad0c"
},
{
- "id": "a2dac363760d54eb2289",
+ "id": "be76fe7e574972176ee1",
"type": "equation",
"text_sha256": "6c5a396ab88a55cb19ab8def13e342251525c2dfc89946108272fa38fc5af9c9"
},
{
- "id": "d6a1c67fd4c8778735d4",
+ "id": "796a037e4b6951f0cf6f",
"type": "text",
"text_sha256": "93f8001cbd1da89c47b6d72695705d3d349d651ddf1222bc68110eb383eb5695"
},
{
- "id": "17b8cfc0c4ed9504e622",
+ "id": "2bc90d44ca54c86808dc",
"type": "text",
"text_sha256": "d92030986ffac72debd5c2bb5ff76bdd1803b2e96a0c5f365c3aaf2e5e6f1201"
},
{
- "id": "3ae78f01b96f80a96945",
+ "id": "343e82d343453c04f2ac",
"type": "equation",
"text_sha256": "1a3048989864e156bed72395cc4c15c128936d00de6596401b3b75f2fce36a7f"
},
{
- "id": "bd00a92e2ed1055cd980",
+ "id": "05cf4cdae9a16e70d860",
"type": "text",
"text_sha256": "aefe2ff3c3d9e81f7fd225abb68a846276f9422d5fbea894b869c9c89aa2f5e6"
},
{
- "id": "cda0edfc631ab98cdf9d",
+ "id": "029d02721f2d2672622b",
"type": "text",
"text_sha256": "b504448f8bd39a41419362924f64c7102b97b81c228a9e999c5fe25f3bcf1e73"
}
@@ -9321,8 +9316,8 @@
},
{
"page_index": 5,
- "fingerprint": "d07c1dcb9ae0c044f7dd049de88551f417af2fcf35035ef2124d13287968e019",
- "bbox_fingerprint": "8b618f8327ea3e6a8f0a3b4b2be0cc6a62551a629c065f31e034db594230c0f0",
+ "fingerprint": "c8fb1703e8772aa31113e35da97fdb7ecf2ac45e05a8f32175ca25b119ee949c",
+ "bbox_fingerprint": "89e08415a20da7f90349a3d9a40577597b6b218647749ba45478c7ef14994abe",
"approved": true,
"blocks": [
{
@@ -9361,32 +9356,42 @@
"text_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
{
- "id": "b1456c9ea49aef5ca1c1",
+ "id": "d08722dad1606e2b50fd",
"type": "caption",
- "text_sha256": "d64c9f909d46b2d2d9ea10df7088de325b010a881cf8107ae8564f45afffd09e"
+ "text_sha256": "159ff7ca509eda68f7ca5e6dd071a938e1b0b8aac079268742384bd678711923"
},
{
- "id": "eb8c17c8d93fbe63e6cd",
+ "id": "be8a744e81b976b256be",
+ "type": "caption",
+ "text_sha256": "035fe06ffa3843c359bc0bdbcd0033890ae4d1ba2f936a5305f7795ef8c99afe"
+ },
+ {
+ "id": "be553e76d9c31616bd8f",
"type": "image",
"text_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
{
- "id": "1050a970797e78b13ad8",
+ "id": "3bc4f06d90bc8bee7590",
+ "type": "caption",
+ "text_sha256": "1144e96c59f974068dbf92093246b748803fb2d4e7ad379909ad2ae4afa12231"
+ },
+ {
+ "id": "7021cae92d16da43a94e",
"type": "caption",
- "text_sha256": "622ea68230292be62a52caaa0d80eab73e6b7143c6317423ea290aef66e68005"
+ "text_sha256": "bd5a38c7cc574d1e58121589ef5fc92c935de67cdc4a4f22c1a105dde9253535"
},
{
- "id": "3a793438fcc54d20e680",
+ "id": "0a45494e75ba1aa302d1",
"type": "text",
"text_sha256": "fa3ee9e9c7e230d6d57b41f6b817aaf0935b39841322bb1eac295fca0b48f3b4"
},
{
- "id": "4b82bf55dc591cda0176",
+ "id": "07773dc69fee1156482b",
"type": "text",
"text_sha256": "1da0d82a6ce63c08d1f15a348b346efad731457eba544fd10e74bb621f81dbdb"
},
{
- "id": "1b5216ce42fbd2eb90b3",
+ "id": "8fc6da4dc321666e9075",
"type": "text",
"text_sha256": "15853773612fa94c052a5747207f0aaa0eff6aeab8272dee17a3b70768e6214e"
}
@@ -9394,8 +9399,8 @@
},
{
"page_index": 6,
- "fingerprint": "523f534c1e16bb522b2e4996aee468d184167b46391b5a08b0f2a741174771fb",
- "bbox_fingerprint": "8407f0d807e09d3d73944c151be9838a1c6389b100390ea44916337253cf2141",
+ "fingerprint": "80f5c0b1d5c1d4ee7ebe9c83ea0ce48596850c07c942d6be19cb9add993ff028",
+ "bbox_fingerprint": "6f07236d9115ebb5914e5dccff8d327cb507c03798c310a037197b842eabdcca",
"approved": true,
"blocks": [
{
@@ -9454,19 +9459,29 @@
"text_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
{
- "id": "4bacc5c6084b1ebd31b1",
+ "id": "b337b485803d0f9d7f14",
+ "type": "caption",
+ "text_sha256": "57a288d618c4d708e98540cb72a54be8c812fa8d1e2d187090e44fd64821c967"
+ },
+ {
+ "id": "6520b932bd07c3ebc85d",
"type": "caption",
- "text_sha256": "f8b8c1b95df702a998aa6a4e1bfb67a988be12f1c2fd7cacbaba3462864875fb"
+ "text_sha256": "cc4ad5f116908d1b0a072b4877631c71e5c2f7ba3fbdbb4e1192d5caae2b1d25"
},
{
- "id": "e682a42aec914d11e5dd",
+ "id": "7ba5d8ec4f5168dcabf9",
"type": "image",
"text_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
{
- "id": "fd6614ff8d1e653add1f",
+ "id": "80258a45b7ea7f492624",
+ "type": "caption",
+ "text_sha256": "004d9889cd3a0cc90d9220af8822dd0467c206c717348c500518d292ccd486ab"
+ },
+ {
+ "id": "d4d2c015eb7f098241e2",
"type": "caption",
- "text_sha256": "bf8563d42b4ff84efb8628cef208643b0b80f9e95bfb2688e3f39097b8e5bec8"
+ "text_sha256": "22fb4bd58e5d4ea4833c165213c3d3bca00a7e6fe8aaf4d85faef339559c030d"
}
]
},
@@ -9708,8 +9723,8 @@
},
{
"page_index": 9,
- "fingerprint": "c828fb1b1140ce885c6e6e3cedd978dad87757a854d3b82725912f4913132f90",
- "bbox_fingerprint": "7c357b5158e00256d27645253b6e5303efef3d111f1b09d2fc3d5b83b71a3f21",
+ "fingerprint": "4c26107a0ac41248dd6e3946fc775cf24933223ed8b890cbb6d855bb0fcccfa7",
+ "bbox_fingerprint": "ebe9d1954ff93a0f181ab629ff996ffcd2149ed76e990a0b6012786b8e4067a9",
"approved": true,
"blocks": [
{
@@ -9758,12 +9773,17 @@
"text_sha256": "df64a06243f290246f5db7be2c346b7ac1bdb2a60d79cefcda9a059c12ce1b10"
},
{
- "id": "932495559266acd62a7e",
+ "id": "4c2f1626cd26db0acb3a",
"type": "text",
- "text_sha256": "5774f1f1ab5c223f81c71d1f4aa2a8d8eddc74aff4d2cc978420a55abb09e813"
+ "text_sha256": "aa389723403ff06951e4bdc0f21198e7b39a2c62b34b4f39f7b876d212d8b488"
},
{
- "id": "2af969466ac7350b71bf",
+ "id": "b937c330a88a1caa3010",
+ "type": "text",
+ "text_sha256": "191e938b360a41c79920c3095dc2eebf0b2a93466e1ff2beb655caeb2c2862fc"
+ },
+ {
+ "id": "c8a6f5b9e4795587edac",
"type": "text",
"text_sha256": "5a12f3a1d1b1ed8914ecfebefbb3d148e5be82a37bddb43b88c2887d08c875fb"
}
@@ -9786,8 +9806,8 @@
"pages": [
{
"page_index": 0,
- "fingerprint": "254df1be62bbc381ca1544555aaf8df143fdd1c6d31ab26970c72d2b3be83732",
- "bbox_fingerprint": "a4627186bf8d5b235685136fb534a123a19d20476227d9413d176761440ab1a3",
+ "fingerprint": "8412b58c8c4fc008727a8e32ca4120ce6fcb60bdb1b59df3c2e3a7ef09402bea",
+ "bbox_fingerprint": "df2a97c3af2098d3f7d3198d4b205ccd35c45c61cb3b100e90ef079f20b6ab87",
"approved": true,
"blocks": [
{
@@ -9906,8 +9926,8 @@
"text_sha256": "c12d4d8eb6f87d6f8d116ae7a66adc187b5dcf83978b769dd5d7f3703ad71fc3"
},
{
- "id": "caadd964326cfc101eb0",
- "type": "footer",
+ "id": "254b2ff3cced9efb076d",
+ "type": "page_footnote",
"text_sha256": "d464e2f68d9911ceba3bd87ceb3abf4ebf06cf51f19868966e84f035580d80bf"
}
]
@@ -16032,8 +16052,8 @@
},
{
"page_index": 4,
- "fingerprint": "aeb346a70ea9baa5ad76b4f2fa59328bbcb96fd736b74486e4c13dbbed52c98a",
- "bbox_fingerprint": "b18335c7de00ca40048f898b45a9c9c6ef8039e243fcf5d1d945b9e9a97deae7",
+ "fingerprint": "0c61c6b4193888c26754fdfad68c3276f12859b3ee22a9ca46d3d64d137a9a70",
+ "bbox_fingerprint": "c554ad46319ad7e59e2ee4d5d5807cf3df1d47fed75ccae7f016cb5a22c34fa1",
"approved": true,
"blocks": [
{
@@ -16072,8 +16092,8 @@
"text_sha256": "0dace48adaa71a64bf461e33010ac3ed3dfd48e3fe828cb938e93b770032eb9c"
},
{
- "id": "2ba7503665159c06b7ab",
- "type": "text",
+ "id": "949e18b87d940e633356",
+ "type": "paragraph_title",
"text_sha256": "edc3efb149a25b9613ce36ac49d50fa08fbda9e7b7120a27b83d2c9a69b24a3f"
},
{
diff --git a/tests/unittest/_flash_pdf_test_utils.py b/tests/unittest/_flash_pdf_test_utils.py
index 69939cbd..76609b51 100644
--- a/tests/unittest/_flash_pdf_test_utils.py
+++ b/tests/unittest/_flash_pdf_test_utils.py
@@ -1,7 +1,6 @@
from __future__ import annotations
-
from mineru.model.flash.pdf import (
models,
)
@@ -22,6 +21,7 @@ def _text_line(
dominant_font_weight: float | None = None,
median_glyph_width: float | None = None,
leading_emphasis_width: float | None = None,
+ leading_typography_width: float | None = None,
preserve_split_boundary: bool = False,
semantic_type: str | None = None,
ink_bbox: tuple[float, float, float, float] | None = None,
@@ -42,6 +42,7 @@ def _text_line(
dominant_font_weight=dominant_font_weight,
median_glyph_width=median_glyph_width,
leading_emphasis_width=leading_emphasis_width,
+ leading_typography_width=leading_typography_width,
split_from_row=split_from_row,
preserve_split_boundary=preserve_split_boundary,
semantic_type=semantic_type,
diff --git a/tests/unittest/test_flash_pdf_auxiliary_text.py b/tests/unittest/test_flash_pdf_auxiliary_text.py
index 5faad6e3..aecbd8f8 100644
--- a/tests/unittest/test_flash_pdf_auxiliary_text.py
+++ b/tests/unittest/test_flash_pdf_auxiliary_text.py
@@ -385,6 +385,94 @@ def test_page_footnote_supports_independent_column_rules() -> None:
assert page.page_footnote_groups == [{6, 7}, {8, 9}]
+def test_page_footnote_accepts_slightly_left_shifted_rule_with_two_small_rows() -> None:
+ """验证轻微早于栏左缘的短横线可凭高覆盖和连续小字号行确认脚注。"""
+
+ body = [
+ _text_line(
+ f"body {index}",
+ (122.0, 180.0 + 90.0 * index, 622.0, 190.0 + 90.0 * index),
+ index,
+ effective_height=10.0,
+ )
+ for index in range(4)
+ ]
+ notes = [
+ _text_line(
+ "note one",
+ (122.0, 862.0, 550.0, 870.0),
+ 4,
+ effective_height=8.0,
+ ),
+ _text_line(
+ "note two",
+ (122.0, 874.0, 520.0, 882.0),
+ 5,
+ effective_height=8.0,
+ ),
+ ]
+ page = _prepared_text_page(
+ *body,
+ *notes,
+ page_size=(1000.0, 1000.0),
+ )
+ page.drawing_lines = [
+ models._AxisLine(
+ (100.0, 850.0, 300.0, 852.0),
+ 1.0,
+ "horizontal",
+ )
+ ]
+
+ auxiliary_text._classify_page_auxiliary_text(page)
+
+ assert all(line.semantic_type is None for line in body)
+ assert all(line.semantic_type == "page_footnote" for line in notes)
+ assert page.page_footnote_groups == [{4, 5}]
+
+
+def test_page_footnote_rejects_left_shifted_rule_with_single_or_body_size_row() -> None:
+ """验证轻微左偏横线缺少两行或字号收缩证据时不触发脚注。"""
+
+ for note_rows, note_height in ((1, 8.0), (2, 10.0)):
+ lines = [
+ *[
+ _text_line(
+ f"body {index}",
+ (122.0, 180.0 + 90.0 * index, 622.0, 190.0 + 90.0 * index),
+ index,
+ effective_height=10.0,
+ )
+ for index in range(4)
+ ],
+ *[
+ _text_line(
+ f"note {index}",
+ (122.0, 862.0 + 12.0 * index, 550.0, 862.0 + 12.0 * index + note_height),
+ 4 + index,
+ effective_height=note_height,
+ )
+ for index in range(note_rows)
+ ],
+ ]
+ page = _prepared_text_page(
+ *lines,
+ page_size=(1000.0, 1000.0),
+ )
+ page.drawing_lines = [
+ models._AxisLine(
+ (100.0, 850.0, 300.0, 852.0),
+ 1.0,
+ "horizontal",
+ )
+ ]
+
+ auxiliary_text._classify_page_auxiliary_text(page)
+
+ assert page.page_footnote_groups == []
+ assert all(line.semantic_type is None for line in lines)
+
+
def test_page_footnote_accepts_lower_half_column_width_rule_with_smaller_text() -> None:
"""验证页面下半部的栏宽横线可凭字号收缩识别单栏脚注。"""
@@ -570,6 +658,40 @@ def test_page_footnote_entries_split_first_line_indent_without_text() -> None:
]
+def test_page_footnote_entries_keep_same_left_compact_continuation() -> None:
+ """验证同左缘的次满首行与紧邻续行仍保留在同一脚注块。"""
+
+ lines = [
+ _text_line(
+ "first",
+ (70.0, 732.0, 220.0, 740.0),
+ 0,
+ effective_height=8.0,
+ median_glyph_width=4.0,
+ font_signature=("NoteFont", 0),
+ font_coverage=1.0,
+ ),
+ _text_line(
+ "continuation",
+ (70.0, 743.0, 270.0, 751.0),
+ 1,
+ effective_height=8.0,
+ median_glyph_width=4.0,
+ font_signature=("NoteFont", 0),
+ font_coverage=1.0,
+ ),
+ ]
+
+ entries = text_blocks._split_page_footnote_entries(
+ lines,
+ (595.0, 842.0),
+ )
+
+ assert [[line.source_index for line in entry] for entry in entries] == [
+ [0, 1],
+ ]
+
+
def test_page_footnote_entries_split_hanging_indent_and_tighten_boxes() -> None:
"""验证 Boosting 型续行缩进拆成四条脚注,且异常高字符框不再互相覆盖。"""
diff --git a/tests/unittest/test_flash_pdf_samples.py b/tests/unittest/test_flash_pdf_samples.py
index c8feb52d..a83372d8 100644
--- a/tests/unittest/test_flash_pdf_samples.py
+++ b/tests/unittest/test_flash_pdf_samples.py
@@ -322,7 +322,7 @@ def test_explicit_pdf_fixtures_keep_expected_txt_block_inventory() -> None:
{
"caption": 10,
"doc_title": 1,
- "equation": 7,
+ "equation": 6,
"footer": 1,
"footnote": 5,
"header": 12,
@@ -331,7 +331,7 @@ def test_explicit_pdf_fixtures_keep_expected_txt_block_inventory() -> None:
"page_number": 12,
"paragraph_title": 18,
"table": 5,
- "text": 85,
+ "text": 84,
}
),
),
@@ -358,12 +358,12 @@ def test_explicit_pdf_fixtures_keep_expected_txt_block_inventory() -> None:
"aside_text": 1,
"caption": 8,
"doc_title": 1,
- "equation": 8,
+ "equation": 7,
"image": 1,
"page_footnote": 6,
"paragraph_title": 21,
"table": 9,
- "text": 118,
+ "text": 119,
}
),
),
@@ -444,17 +444,17 @@ def test_explicit_pdf_fixtures_keep_expected_txt_block_inventory() -> None:
10,
Counter(
{
- "caption": 18,
+ "caption": 22,
"doc_title": 2,
"equation": 6,
- "footnote": 1,
+ "footnote": 2,
"header": 24,
"image": 8,
"page_footnote": 4,
"page_number": 9,
"paragraph_title": 19,
"table": 3,
- "text": 106,
+ "text": 107,
}
),
),
@@ -543,7 +543,7 @@ def test_demo1_keeps_five_real_tables_without_formula_false_positive() -> None:
model_list = _native_model_list("demo1.pdf")
- assert [len(page) for page in model_list] == [16, 9, 12, 18, 12, 13, 11, 10, 12, 7, 10, 26, 9]
+ assert [len(page) for page in model_list] == [16, 9, 12, 18, 10, 13, 11, 10, 12, 7, 10, 26, 9]
assert [sum(block["type"] == "table" for block in page) for page in model_list] == [
0,
0,
@@ -562,7 +562,7 @@ def test_demo1_keeps_five_real_tables_without_formula_false_positive() -> None:
assert sum(block["type"] == "doc_title" for page in model_list for block in page) == 1
assert sum(block["type"] == "header" for page in model_list for block in page) == 12
assert sum(block["type"] == "page_number" for page in model_list for block in page) == 12
- assert sum(block["type"] == "equation" for page in model_list for block in page) == 7
+ assert sum(block["type"] == "equation" for page in model_list for block in page) == 6
assert sum(block["type"] == "caption" for page in model_list for block in page) == 10
assert sum(block["type"] == "footnote" for page in model_list for block in page) == 5
middle_pages = model_json_to_pages(_model_json(model_list))
@@ -590,6 +590,15 @@ def test_demo1_keeps_five_real_tables_without_formula_false_positive() -> None:
assert _visible_content(page5_visual_blocks[2]) == (
"For *rainfall distribution, U, uniform; W, winter dominated; S, summer dominated. BFI, baseflow index."
)
+ inline_statistics = next(
+ block
+ for block in model_list[4]
+ if _visible_content(block).startswith("Due to the constraint")
+ )
+ assert inline_statistics["type"] == "text"
+ assert "The F-statistic was calculated as:" in _visible_content(
+ inline_statistics,
+ )
assert [[child["type"] for child in group["content"]] for group in _grouped_visual_blocks(model_list[5], "table")] == [
["table_caption", "table_body", "table_footnote"],
["table_caption", "table_body", "table_footnote"],
@@ -1011,8 +1020,8 @@ def test_demo3_auxiliary_text_types_match_real_page_geometry() -> None:
assert not [block for page in model_list for block in page if block["type"] == "footer"]
-def test_demo3_pages1_and2_fix_title_front_matter_and_embedding_formula() -> None:
- """验证首页标题稳定,第二页标题、公式和栏尾正文各自保持完整。"""
+def test_demo3_pages1_and2_fix_title_front_matter_and_embedding_list() -> None:
+ """验证首页标题稳定,第二页标题、嵌入列表和栏尾正文各自保持完整。"""
page1, page2 = _native_model_list("demo3.pdf")[:2]
title = next(block for block in page1 if _visible_content(block).startswith("TABLEFORMER:"))
@@ -1053,18 +1062,27 @@ def test_demo3_pages1_and2_fix_title_front_matter_and_embedding_formula() -> Non
assert tables_body["type"] == "text"
section_title = next(block for block in page2 if _visible_content(block).startswith("2 Preliminaries:"))
- equations = [block for block in page2 if block["type"] == "equation"]
+ embedding_list = next(
+ block
+ for block in page2
+ if _visible_content(block).startswith("token ids (W)")
+ )
assert section_title["type"] == "paragraph_title"
assert _visible_content(section_title) == "2 Preliminaries: TAPAS for Table Encoding"
- assert len(equations) == 1
- assert equations[0]["content"].splitlines() == [
- "token ids (W) = {wv1, wv2, · · · , wvn }",
- "positional ids (B) = {b1, b2, · · · , bn}",
- "segment ids (G) = {gseg1, gseg2, · · · , gsegn }",
- "column ids (C) = {ccol1, ccol2, · · · , ccoln}",
- "row ids (R) = {rrow1, rrow2, · · · , rrown }",
- "rank ids (Z) = {zrank1, zrank2, · · · , zrankn}",
- ]
+ assert embedding_list["type"] == "text"
+ assert not [block for block in page2 if block["type"] == "equation"]
+ embedding_text = _visible_content(embedding_list)
+ assert all(
+ label in embedding_text
+ for label in (
+ "token ids (W)",
+ "positional ids (B)",
+ "segment ids (G)",
+ "column ids (C)",
+ "row ids (R)",
+ "rank ids (Z)",
+ )
+ )
as_model_blocks = [
block
for block in page2
@@ -1872,7 +1890,7 @@ def test_frozen_soil_page3_formula3_remains_one_equation() -> None:
equations = [block for block in page if block["type"] == "equation"]
formula3 = [block for block in equations if r"\tag{3}" in str(block.get("content", ""))]
- assert len(page) == 30
+ assert len(page) == 31
assert len(equations) == 4
assert len(formula3) == 1
assert formula3[0]["bbox"] == [0.651, 0.717, 0.893, 0.746]
@@ -1902,7 +1920,7 @@ def test_frozen_soil_reference_tails_remain_single_text_blocks() -> None:
page = model_list[8]
captions = [block for page_blocks in model_list for block in page_blocks if block["type"] == "caption"]
- assert len(captions) == 18
+ assert len(captions) == 22
page2 = model_list[1]
image = next(block for block in page2 if block["type"] == "image")
chinese_caption = _blocks_containing(page2, "图1 冻土抗剪强度试验流程示意图")
@@ -1918,12 +1936,14 @@ def test_frozen_soil_reference_tails_remain_single_text_blocks() -> None:
"table_caption",
"table_body",
"table_footnote",
+ "table_footnote",
]
assert [tuple(round(value * 1000) for value in child["bbox"]) for child in page3_table_group["content"]] == [
(182, 688, 406, 700),
(114, 706, 474, 715),
(107, 721, 483, 838),
- (105, 837, 484, 926),
+ (105, 837, 484, 879),
+ (105, 884, 482, 926),
]
assert inline_text(page3_table_group["content"][0]["content"]).startswith("表1")
assert inline_text(page3_table_group["content"][1]["content"]).startswith("Table 1")
diff --git a/tests/unittest/test_flash_pdf_tables.py b/tests/unittest/test_flash_pdf_tables.py
index ace6c41f..2c820fad 100644
--- a/tests/unittest/test_flash_pdf_tables.py
+++ b/tests/unittest/test_flash_pdf_tables.py
@@ -1378,6 +1378,87 @@ def test_materialize_table_externalizes_multiline_annotations_once(
assert claimed == {0, 1, 2, 3, 4}
+def test_table_annotation_splits_short_tail_before_wide_font_family_reset() -> None:
+ """验证表下注短尾后的宽行字体族重启形成两个独立注释块。"""
+
+ lines = [
+ models._LineItem(
+ "first body",
+ (10.0, 70.0, 90.0, 80.0),
+ 0,
+ 0,
+ effective_height=10.0,
+ em_height=10.0,
+ font_signature=("FirstFont", 0),
+ font_coverage=1.0,
+ ),
+ models._LineItem(
+ "tail",
+ (10.0, 82.0, 30.0, 92.0),
+ 0,
+ 1,
+ effective_height=10.0,
+ em_height=10.0,
+ font_signature=("FirstFont", 0),
+ font_coverage=1.0,
+ ),
+ models._LineItem(
+ "second body",
+ (12.0, 94.0, 88.0, 104.0),
+ 0,
+ 2,
+ effective_height=10.0,
+ em_height=10.0,
+ font_signature=("SecondFont", 0),
+ font_coverage=1.0,
+ ),
+ ]
+ source = models._PageSource(
+ page_size=(120.0, 120.0),
+ lines=lines,
+ chars=[],
+ drawing_lines=[],
+ )
+ candidate = models._TableCandidate(
+ bbox=(5.0, 10.0, 110.0, 110.0),
+ local_bbox=(5.0, 10.0, 110.0, 110.0),
+ angle=0,
+ score=1.0,
+ core_bbox=(5.0, 10.0, 110.0, 60.0),
+ line_indices=set(),
+ )
+ annotation = models._TableAnnotation(
+ kind="footnote",
+ bbox=(10.0, 70.0, 90.0, 104.0),
+ line_indices={0, 1, 2},
+ line_bboxes={line.source_index: line.bbox for line in lines},
+ )
+
+ blocks = tables._build_table_annotation_blocks(
+ source,
+ candidate,
+ annotation,
+ )
+ lines[2].font_signature = ("FirstFont", 0)
+ control = tables._build_table_annotation_blocks(
+ source,
+ candidate,
+ annotation,
+ )
+
+ assert [block["content"] for block in blocks] == [
+ "first body tail",
+ "second body",
+ ]
+ assert [block["type"] for block in blocks] == [
+ "footnote",
+ "footnote",
+ ]
+ assert [block["content"] for block in control] == [
+ "first body tail second body",
+ ]
+
+
def test_invalid_table_annotation_falls_back_to_full_table_projection(
monkeypatch: pytest.MonkeyPatch,
) -> None:
diff --git a/tests/unittest/test_flash_pdf_text_blocks.py b/tests/unittest/test_flash_pdf_text_blocks.py
index 60c51150..1fa1c3e4 100644
--- a/tests/unittest/test_flash_pdf_text_blocks.py
+++ b/tests/unittest/test_flash_pdf_text_blocks.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+from dataclasses import replace
import pytest
@@ -2455,6 +2456,90 @@ def test_native_typography_caches_leading_emphasis_before_chars_are_cleared() ->
assert not line.chars
+def test_native_typography_caches_leading_font_family_run_without_weight_change() -> None:
+ """验证同字重的独立行首字体 run 仍缓存为视觉排版宽度。"""
+
+ chars = []
+ for index, char in enumerate("Lead"):
+ chars.append(
+ {
+ "char": char,
+ "bbox": (float(index * 5), 0.0, float(index * 5 + 5), 10.0),
+ "font": {"name": "LeadFont", "flags": 0, "weight": 400},
+ }
+ )
+ for index, char in enumerate("body", start=5):
+ chars.append(
+ {
+ "char": char,
+ "bbox": (float(index * 5), 0.0, float(index * 5 + 5), 10.0),
+ "font": {"name": "BodyFont", "flags": 0, "weight": 400},
+ }
+ )
+ line = models._LineItem(
+ text="Lead body",
+ bbox=(0.0, 0.0, 45.0, 10.0),
+ angle=0,
+ source_index=0,
+ chars=chars,
+ )
+
+ native_text._fill_native_typography(line, (100.0, 100.0))
+ pipeline._compact_prepared_lines([line], (100.0, 100.0))
+
+ assert line.leading_emphasis_width is None
+ assert line.leading_typography_width == 20.0
+ assert not line.chars
+
+
+def test_image_adjacent_centered_short_to_wide_rows_split_without_text_markers() -> None:
+ """验证图片下方短居中行到宽居中行按纯视觉关系形成独立块。"""
+
+ first = _text_line("alpha", (35.0, 62.0, 65.0, 72.0), 0)
+ second = _text_line("beta", (10.0, 74.0, 90.0, 84.0), 1)
+
+ blocks = text_blocks._build_text_blocks(
+ [first, second],
+ [],
+ (100.0, 100.0),
+ visual_bboxes=[(5.0, 10.0, 95.0, 60.0)],
+ )
+ control = text_blocks._build_text_blocks(
+ [first, second],
+ [],
+ (100.0, 100.0),
+ )
+
+ assert [block["content"] for block in blocks] == ["alpha", "beta"]
+ assert [block["content"] for block in control] == ["alpha beta"]
+
+
+def test_short_tail_and_leading_typography_run_split_structured_text() -> None:
+ """验证短尾之后的宽行仅在存在独立行首字体 run 时形成新块。"""
+
+ previous = _text_line("tail", (0.0, 0.0, 35.0, 10.0), 0)
+ opener = _text_line(
+ "opener body",
+ (0.0, 12.0, 90.0, 22.0),
+ 1,
+ leading_typography_width=12.0,
+ )
+
+ blocks = text_blocks._build_text_blocks(
+ [previous, opener],
+ [],
+ (100.0, 100.0),
+ )
+ control = text_blocks._build_text_blocks(
+ [previous, replace(opener, leading_typography_width=None)],
+ [],
+ (100.0, 100.0),
+ )
+
+ assert [block["content"] for block in blocks] == ["tail", "opener body"]
+ assert [block["content"] for block in control] == ["tail opener body"]
+
+
def test_native_typography_separates_loose_height_from_canonical_em() -> None:
"""验证异常 loose 字符高度不会覆盖 PDF 字号形成的 canonical 尺度。"""