@@ -207,6 +207,8 @@ P11X_DECLARE_ENUM(
207
207
* FT2Image
208
208
* */
209
209
210
+ using double_or_long = std::variant<double , long >;
211
+
210
212
const char *PyFT2Image__doc__ = R"""(
211
213
An image buffer for drawing glyphs.
212
214
)""" ;
@@ -227,9 +229,32 @@ const char *PyFT2Image_draw_rect_filled__doc__ = R"""(
227
229
The bounds of the rectangle from (x0, y0) to (x1, y1).
228
230
)""" ;
229
231
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
+
230
248
static 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)
232
252
{
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
+
233
258
self->draw_rect_filled (x0, y0, x1, y1);
234
259
}
235
260
@@ -1634,7 +1659,14 @@ PYBIND11_MODULE(ft2font, m)
1634
1659
1635
1660
py::class_<FT2Image>(m, " FT2Image" , py::is_final (), py::buffer_protocol (),
1636
1661
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__)
1638
1670
.def (" draw_rect_filled" , &PyFT2Image_draw_rect_filled,
1639
1671
" x0" _a, " y0" _a, " x1" _a, " y1" _a,
1640
1672
PyFT2Image_draw_rect_filled__doc__)
0 commit comments