diff --git a/python/commands/board/view.py b/python/commands/board/view.py index 8156ecf..bc9d78f 100644 --- a/python/commands/board/view.py +++ b/python/commands/board/view.py @@ -198,6 +198,14 @@ class BoardViewCommands: output_svg, "--mode-single", "--black-and-white", + # Render the board, not the drawing sheet. kicad-cli's + # default (page-size-mode 0) plots only the area inside the + # sheet, so board geometry past the page edge is left out. + # Mode 2 sizes the output to the board's bounding box; + # --exclude-drawing-sheet drops the title block. + "--exclude-drawing-sheet", + "--page-size-mode", + "2", ] if layers: cmd += ["--layers", ",".join(layers)] diff --git a/tests/test_get_board_2d_view_save_to_file.py b/tests/test_get_board_2d_view_save_to_file.py index 5e3f7a5..17940c0 100644 --- a/tests/test_get_board_2d_view_save_to_file.py +++ b/tests/test_get_board_2d_view_save_to_file.py @@ -79,6 +79,19 @@ def test_inline_png_returns_base64_image_data(tmp_path): assert "filePath" not in result +@pytest.mark.unit +def test_export_frames_to_board_area(tmp_path): + """The export drops the drawing sheet and crops to the board area, so a small + board isn't rendered on a mostly-empty A4 page (kicad-cli's default).""" + cmd, root, board_path = _make_view_cmd(tmp_path) + w1, w2, w3 = _patch_kicad_cli(root) + with w1, w2 as run, w3, patch("commands.board.view._svg_to_png", return_value=_FAKE_PNG): + cmd.get_board_2d_view({"pcbPath": str(board_path), "format": "png"}) + argv = run.call_args[0][0] + assert "--exclude-drawing-sheet" in argv + assert argv[argv.index("--page-size-mode") + 1] == "2" + + @pytest.mark.unit def test_inline_svg_returns_base64_image_data(tmp_path): """responseMode='inline' with format='svg' returns base64-encoded SVG in imageData."""