@@ -350,7 +350,7 @@ GraphicsContextRenderer::GraphicsContextRenderer(
350
350
{}
351
351
352
352
cairo_t * GraphicsContextRenderer::cr_from_fileformat_args (
353
- StreamSurfaceType type, std::optional< py::object> file,
353
+ StreamSurfaceType type, py::object file,
354
354
double width, double height, double dpi)
355
355
{
356
356
auto surface_create_for_stream =
@@ -384,22 +384,17 @@ cairo_t* GraphicsContextRenderer::cr_from_fileformat_args(
384
384
" cairo was built without {.name} support" _format (type)
385
385
.cast <std::string>()};
386
386
}
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)
390
389
-> 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" );
403
398
auto const & surface =
404
399
surface_create_for_stream (cb, write .ptr (), width, height);
405
400
cairo_surface_set_fallback_resolution (surface, dpi, dpi);
@@ -416,7 +411,7 @@ cairo_t* GraphicsContextRenderer::cr_from_fileformat_args(
416
411
}
417
412
418
413
GraphicsContextRenderer::GraphicsContextRenderer (
419
- StreamSurfaceType type, std::optional< py::object> file,
414
+ StreamSurfaceType type, py::object file,
420
415
double width, double height, double dpi) :
421
416
GraphicsContextRenderer{
422
417
cr_from_fileformat_args (type, file, width, height, dpi), width, height,
@@ -2137,8 +2132,7 @@ Only intended for debugging purposes.
2137
2132
.def (py::init<double , double , double >())
2138
2133
.def (py::init<
2139
2134
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 >())
2142
2136
.def (
2143
2137
py::pickle (
2144
2138
[](GraphicsContextRenderer const & gcr) -> py::tuple {
0 commit comments