@@ -207,6 +207,8 @@ P11X_DECLARE_ENUM(
207207 * FT2Image
208208 * */
209209
210+ using double_or_long = std::variant<double , long >;
211+
210212const char *PyFT2Image__doc__ = R"""(
211213 An image buffer for drawing glyphs.
212214)""" ;
@@ -227,9 +229,32 @@ const char *PyFT2Image_draw_rect_filled__doc__ = R"""(
227229 The bounds of the rectangle from (x0, y0) to (x1, y1).
228230)""" ;
229231
232+ static long
233+ _double_to_long (const char *name, double_or_long &var)
234+ {
235+ if (auto value = std::get_if<double >(&var)) {
236+ auto api = py::module_::import (" matplotlib._api" );
237+ auto warn = api.attr (" warn_deprecated" );
238+ warn (" since" _a=" 3.10" , " name" _a=name, " obj_type" _a=" parameter as float" ,
239+ " alternative" _a=" int({})" _s.format (name));
240+ return static_cast <long >(*value);
241+ } else if (auto value = std::get_if<long >(&var)) {
242+ return *value;
243+ } else {
244+ throw std::runtime_error (" Should not happen" );
245+ }
246+ }
247+
230248static void
231- PyFT2Image_draw_rect_filled (FT2Image *self, double x0, double y0, double x1, double y1)
249+ PyFT2Image_draw_rect_filled (FT2Image *self,
250+ double_or_long vx0, double_or_long vy0,
251+ double_or_long vx1, double_or_long vy1)
232252{
253+ auto x0 = _double_to_long (" x0" , vx0);
254+ auto y0 = _double_to_long (" y0" , vy0);
255+ auto x1 = _double_to_long (" x1" , vx1);
256+ auto y1 = _double_to_long (" y1" , vy1);
257+
233258 self->draw_rect_filled (x0, y0, x1, y1);
234259}
235260
@@ -1634,7 +1659,14 @@ PYBIND11_MODULE(ft2font, m)
16341659
16351660 py::class_<FT2Image>(m, " FT2Image" , py::is_final (), py::buffer_protocol (),
16361661 PyFT2Image__doc__)
1637- .def (py::init<double , double >(), " width" _a, " height" _a, PyFT2Image_init__doc__)
1662+ .def (py::init (
1663+ [](double_or_long width, double_or_long height) {
1664+ return new FT2Image (
1665+ _double_to_long (" width" , width),
1666+ _double_to_long (" height" , height)
1667+ );
1668+ }),
1669+ " width" _a, " height" _a, PyFT2Image_init__doc__)
16381670 .def (" draw_rect_filled" , &PyFT2Image_draw_rect_filled,
16391671 " x0" _a, " y0" _a, " x1" _a, " y1" _a,
16401672 PyFT2Image_draw_rect_filled__doc__)
0 commit comments