@@ -18,8 +18,6 @@ namespace mplcairo {
18
18
19
19
using namespace pybind11 ::literals;
20
20
21
- py::object GraphicsContextRenderer::mathtext_parser_{};
22
-
23
21
Region::Region (cairo_rectangle_int_t bbox, std::unique_ptr<uint8_t []> buf) :
24
22
bbox{bbox}, buf{std::move (buf)}
25
23
{}
@@ -1235,7 +1233,8 @@ void GraphicsContextRenderer::draw_text(
1235
1233
}
1236
1234
auto const & ac = additional_context ();
1237
1235
if (ismath) {
1238
- mathtext_parser_.attr (" parse" )(s, get_additional_state ().dpi , prop)
1236
+ py::module::import (" mplcairo" )
1237
+ .attr (" _mathtext_parse" )(s, get_additional_state ().dpi , prop)
1239
1238
.cast <MathtextBackend>()._draw (*this , x, y, angle);
1240
1239
} else {
1241
1240
// Need to set the current point (otherwise later texts will just follow,
@@ -1274,7 +1273,8 @@ GraphicsContextRenderer::get_text_width_height_descent(
1274
1273
if (ismath.cast <bool >()) {
1275
1274
// NOTE: Agg reports nonzero descents for seemingly zero-descent cases.
1276
1275
return
1277
- mathtext_parser_.attr (" parse" )(s, get_additional_state ().dpi , prop)
1276
+ py::module::import (" mplcairo" )
1277
+ .attr (" _mathtext_parse" )(s, get_additional_state ().dpi , prop)
1278
1278
.cast <MathtextBackend>().get_text_width_height_descent ();
1279
1279
} else {
1280
1280
cairo_save (cr_);
@@ -1514,9 +1514,11 @@ PYBIND11_MODULE(_mplcairo, m)
1514
1514
1515
1515
detail::PIXEL_MARKER =
1516
1516
py::module::import (" matplotlib.markers" ).attr (" MarkerStyle" )(" ," );
1517
- GraphicsContextRenderer::mathtext_parser_ =
1517
+ // Making the mathtext parser live in a Python module works around
1518
+ // FIXME[pybind11]'s failure to call the destructor (#1493).
1519
+ py::module::import (" mplcairo" ).attr (" _mathtext_parse" ) =
1518
1520
py::module::import (" matplotlib.mathtext" )
1519
- .attr (" MathTextParser" )(" mplcairo" );
1521
+ .attr (" MathTextParser" )(" mplcairo" ). attr ( " parse " ) ;
1520
1522
1521
1523
py::module::import (" atexit" ).attr (" register" )(
1522
1524
py::cpp_function{
@@ -1530,7 +1532,6 @@ PYBIND11_MODULE(_mplcairo, m)
1530
1532
// late in the shutdown sequence.)
1531
1533
detail::UNIT_CIRCLE = {};
1532
1534
detail::PIXEL_MARKER = {};
1533
- GraphicsContextRenderer::mathtext_parser_ = {};
1534
1535
}
1535
1536
}
1536
1537
);
0 commit comments