@@ -350,7 +350,7 @@ GraphicsContextRenderer::GraphicsContextRenderer(
350350{}
351351
352352cairo_t * GraphicsContextRenderer::cr_from_fileformat_args (
353- StreamSurfaceType type, std::optional< py::object> file,
353+ StreamSurfaceType type, py::object file,
354354 double width, double height, double dpi)
355355{
356356 auto surface_create_for_stream =
@@ -384,22 +384,17 @@ cairo_t* GraphicsContextRenderer::cr_from_fileformat_args(
384384 " cairo was built without {.name} support" _format (type)
385385 .cast <std::string>()};
386386 }
387- auto const & cb = file
388- ? cairo_write_func_t {
389- [](void * closure, unsigned char const * data, unsigned int length)
387+ auto const & cb =
388+ [](void * closure, unsigned char const * data, unsigned int length)
390389 -> cairo_status_t {
391- auto const & write =
392- py::reinterpret_borrow<py::object>(static_cast <PyObject*>(closure));
393- auto const & written =
394- write (py::memoryview::from_memory (data, length)).cast <unsigned int >();
395- return // NOTE: This does not appear to affect the context status.
396- written == length ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR;
397- }}
398- : nullptr ;
399- py::object write =
400- // TODO: Why does py::none() not work here?
401- file ? file->attr (" write" ) : py::reinterpret_borrow<py::object>(Py_None);
402-
390+ auto const & write =
391+ py::reinterpret_borrow<py::object>(static_cast <PyObject*>(closure));
392+ auto const & written =
393+ write (py::memoryview::from_memory (data, length)).cast <unsigned int >();
394+ return // NOTE: This does not appear to affect the context status.
395+ written == length ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR;
396+ };
397+ auto const & write = file.attr (" write" );
403398 auto const & surface =
404399 surface_create_for_stream (cb, write.ptr (), width, height);
405400 cairo_surface_set_fallback_resolution (surface, dpi, dpi);
@@ -416,7 +411,7 @@ cairo_t* GraphicsContextRenderer::cr_from_fileformat_args(
416411}
417412
418413GraphicsContextRenderer::GraphicsContextRenderer (
419- StreamSurfaceType type, std::optional< py::object> file,
414+ StreamSurfaceType type, py::object file,
420415 double width, double height, double dpi) :
421416 GraphicsContextRenderer{
422417 cr_from_fileformat_args (type, file, width, height, dpi), width, height,
@@ -2137,8 +2132,7 @@ Only intended for debugging purposes.
21372132 .def (py::init<double , double , double >())
21382133 .def (py::init<
21392134 py::object, double , double , double , std::tuple<double , double >>())
2140- .def (py::init<
2141- StreamSurfaceType, std::optional<py::object>, double , double , double >())
2135+ .def (py::init<StreamSurfaceType, py::object, double , double , double >())
21422136 .def (
21432137 py::pickle (
21442138 [](GraphicsContextRenderer const & gcr) -> py::tuple {
0 commit comments