Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix: connect ArcTo playback paths
myhloli5e6b57bfcb60
diff --git a/mineru/model/flash/office/metafile/parser.py b/mineru/model/flash/office/metafile/parser.pyindex 33fb7d4e..0cb0e309 100644--- a/mineru/model/flash/office/metafile/parser.py+++ b/mineru/model/flash/office/metafile/parser.py@@ -397,10 +397,12 @@ class _Playback:self.emit_path(builder.build(), stroke=True, fill=False)self.state.current_position = remaining[-1]- def angle_arc(self, path: GraphicsPath, *, start: Point, end: Point) -> None:- """绘制 current-to-start 连线和 AngleArc,并把 current position 更新到终点。"""+ def connected_arc(self, path: GraphicsPath) -> None:+ """绘制 current-to-projected-start 连线和圆弧,并更新到 projected endpoint。"""+ if not path.segments:+ returnmapped_path = transform_path(path, self.logical_matrix())- mapped_start = self.map_point(start)+ mapped_start = mapped_path.segments[0].points[0]tail = GraphicsPath(mapped_path.segments[1:])if self.path_active:self._ensure_active_path_current()@@ -412,7 +414,7 @@ class _Playback:builder.line_to(mapped_start)builder.extend(tail)self.emit_path(builder.build(), stroke=True, fill=False)- self.state.current_position = end+ self.state.current_position = path.segments[-1].points[-1]def begin_path(self) -> None:"""开始新的 GDI path bracket 并清除旧路径。"""@@ -1386,9 +1388,10 @@ def _handle_emf_record(record_type: int, record: BoundedReader, playback: _Playbend = float(record.i32(32)), float(record.i32(36))close_mode = "chord" if record_type == 46 else "pie" if record_type == 47 else "open"path = arc_path(rect, start, end, direction=playback.state.arc_direction, close_mode=close_mode)- playback.emit_logical_path(path, stroke=True, fill=close_mode != "open")if record_type == 55:- playback.state.current_position = end+ playback.connected_arc(path)+ else:+ playback.emit_logical_path(path, stroke=True, fill=close_mode != "open")returnif record_type == 41:center = float(record.i32(8)), float(record.i32(12))@@ -1407,15 +1410,13 @@ def _handle_emf_record(record_type: int, record: BoundedReader, playback: _Playbcenter[1] - radius * sin(radians(end_angle)),)direction = 1 if sweep_angle >= 0 else 2- playback.angle_arc(+ playback.connected_arc(arc_path(Rect(center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius),start,end,direction=direction,),- start=start,- end=end,)returndiff --git a/tests/unittest/_metafile_test_utils.py b/tests/unittest/_metafile_test_utils.pyindex 491dbd17..835b1beb 100644--- a/tests/unittest/_metafile_test_utils.py+++ b/tests/unittest/_metafile_test_utils.py@@ -106,6 +106,15 @@ def emf_angle_arc(center_x: int, center_y: int, radius: int, start_angle: float,return emf_record(41, struct.pack("<iiIff", center_x, center_y, radius, start_angle, sweep_angle))+def emf_arc_to(+ rect: tuple[int, int, int, int],+ start: tuple[int, int],+ end: tuple[int, int],+) -> bytes:+ """构造 EMR_ARCTO,start/end 可位于椭圆边界之外。"""+ return emf_record(55, struct.pack("<8i", *rect, *start, *end))++def emf_begin_path() -> bytes:"""构造 EMR_BEGINPATH。"""return emf_record(59)@@ -319,6 +328,7 @@ __all__ = ["build_emf","build_placeable_wmf","emf_angle_arc",+ "emf_arc_to","emf_create_brush","emf_create_pen","emf_begin_path",diff --git a/tests/unittest/test_flash_office_metafile.py b/tests/unittest/test_flash_office_metafile.pyindex 0f9b0b55..bc37b349 100644--- a/tests/unittest/test_flash_office_metafile.py+++ b/tests/unittest/test_flash_office_metafile.py@@ -58,6 +58,7 @@ from _metafile_test_utils import (build_emf,build_placeable_wmf,emf_angle_arc,+ emf_arc_to,emf_begin_path,emf_close_figure,emf_create_brush,@@ -412,6 +413,23 @@ def test_emf_anglearc_uses_sweep_direction_and_updates_current_position(assert commands[1].path.segments[0].points[0] == pytest.approx((0.0, expected_end_y))+def test_emf_arcto_connects_current_position_to_projected_arc_endpoints() -> None:+ """验证 ArcTo 连接 current 与椭圆投影起点,并将 current 更新到投影终点。"""+ data = build_emf(+ [+ emf_move_to(10, 10),+ emf_arc_to((0, 0, 100, 100), (150, 50), (50, -100)),+ emf_line_to(80, 80),+ ]+ )+ commands = [command for command in metafile_parser.parse_metafile(data).commands if isinstance(command, DrawPathCommand)]++ assert commands[0].path.segments[0].points == ((10.0, 10.0),)+ assert commands[0].path.segments[1].points[0] == pytest.approx((100.0, 50.0))+ assert commands[0].path.segments[-1].points[0] == pytest.approx((50.0, 0.0))+ assert commands[1].path.segments[0].points[0] == pytest.approx((50.0, 0.0))++def test_emf_stroke_and_fill_closes_every_open_figure() -> None:"""验证 StrokeAndFillPath 在描边前显式闭合全部开放 figure。"""data = build_emf(