diff --git a/CHANGELOG.md b/CHANGELOG.md index b23c185c6..07160e6dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ The release run heads these entries with the version and opens a fresh ## Unreleased +- Python `Frame.line()` returns a bound `DrawingLine` with its endpoints instead + of raising a conversion error. + - Spreadsheet rendering bounds columns as well as rows by the cell budget and avoids rescanning blank spans for every empty cell. diff --git a/python/src/bind_document.cpp b/python/src/bind_document.cpp index 5c956dfaa..09dce5e1a 100644 --- a/python/src/bind_document.cpp +++ b/python/src/bind_document.cpp @@ -311,6 +311,13 @@ void odr_python::bind_document(py::module_ &m) { .def_readwrite("width", &odr::DrawingPath::width) .def_readwrite("height", &odr::DrawingPath::height); + py::class_(m, "DrawingLine") + .def(py::init<>()) + .def_readwrite("x1", &odr::DrawingLine::x1) + .def_readwrite("y1", &odr::DrawingLine::y1) + .def_readwrite("x2", &odr::DrawingLine::x2) + .def_readwrite("y2", &odr::DrawingLine::y2); + py::class_(m, "DrawingTransform") .def(py::init<>()) .def_readwrite("a", &odr::DrawingTransform::a) diff --git a/python/tests/test_document.py b/python/tests/test_document.py index 5e28ad9b9..78eccbe20 100644 --- a/python/tests/test_document.py +++ b/python/tests/test_document.py @@ -457,3 +457,26 @@ def test_recalculate_computes_the_stale_formulas(tmp_path): assert result.changed()[0].column == 1 assert repr(result.changed()[0]) == "SheetPosition(0!B1)" assert document.recalculate().changed() == [] + + +def test_frame_line_exposes_its_endpoints(): + source = b""" + + + + + """ + document = pyodr.open(pyodr.File.from_memory(source)).as_document_file().document() + frames = list(document.root_element().first_child()) + line = frames[0].as_frame().line() + assert [str(line.x1), str(line.y1), str(line.x2), str(line.y2)] == [ + "1cm", + "2cm", + "3cm", + "4cm", + ] + assert frames[1].as_frame().line() is None