@@ -968,7 +968,7 @@ const char *PyFT2Font_draw_glyph_to_bitmap__doc__ = R"""(
968968
969969 Parameters
970970 ----------
971- image : FT2Image
971+ image : 2d array of uint8
972972 The image buffer on which to draw the glyph.
973973 x, y : int
974974 The pixel location at which to draw the glyph.
@@ -983,14 +983,16 @@ const char *PyFT2Font_draw_glyph_to_bitmap__doc__ = R"""(
983983)""" ;
984984
985985static void
986- PyFT2Font_draw_glyph_to_bitmap (PyFT2Font *self, FT2Image &image,
986+ PyFT2Font_draw_glyph_to_bitmap (PyFT2Font *self, py::buffer &image,
987987 double_or_<int > vxd, double_or_<int > vyd,
988988 PyGlyph *glyph, bool antialiased = true )
989989{
990990 auto xd = _double_to_<int >(" x" , vxd);
991991 auto yd = _double_to_<int >(" y" , vyd);
992992
993- self->x ->draw_glyph_to_bitmap (image, xd, yd, glyph->glyphInd , antialiased);
993+ self->x ->draw_glyph_to_bitmap (
994+ py::array_t <uint8_t , py::array::c_style>{image},
995+ xd, yd, glyph->glyphInd , antialiased);
994996}
995997
996998const char *PyFT2Font_get_glyph_name__doc__ = R"""(
@@ -1440,12 +1442,7 @@ const char *PyFT2Font_get_image__doc__ = R"""(
14401442static py::array
14411443PyFT2Font_get_image (PyFT2Font *self)
14421444{
1443- FT2Image &im = self->x ->get_image ();
1444- py::ssize_t dims[] = {
1445- static_cast <py::ssize_t >(im.get_height ()),
1446- static_cast <py::ssize_t >(im.get_width ())
1447- };
1448- return py::array_t <unsigned char >(dims, im.get_buffer ());
1445+ return self->x ->get_image ();
14491446}
14501447
14511448const char *PyFT2Font__get_type1_encoding_vector__doc__ = R"""(
@@ -1565,6 +1562,10 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
15651562 PyFT2Image__doc__)
15661563 .def (py::init (
15671564 [](double_or_<long > width, double_or_<long > height) {
1565+ auto warn =
1566+ py::module_::import (" matplotlib._api" ).attr (" warn_deprecated" );
1567+ warn (" since" _a=" 3.11" , " name" _a=" FT2Image" , " obj_type" _a=" class" ,
1568+ " alternative" _a=" a 2D uint8 ndarray" );
15681569 return new FT2Image (
15691570 _double_to_<long >(" width" , width),
15701571 _double_to_<long >(" height" , height)
@@ -1604,8 +1605,8 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
16041605 .def_property_readonly (" bbox" , &PyGlyph_get_bbox,
16051606 " The control box of the glyph." );
16061607
1607- py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
1608- PyFT2Font__doc__)
1608+ auto cls = py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
1609+ PyFT2Font__doc__)
16091610 .def (py::init (&PyFT2Font_init),
16101611 " filename" _a, " hinting_factor" _a=8 , py::kw_only (),
16111612 " _fallback_list" _a=py::none (), " _kerning_factor" _a=0 ,
@@ -1639,10 +1640,20 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
16391640 .def (" get_descent" , &PyFT2Font_get_descent, PyFT2Font_get_descent__doc__)
16401641 .def (" draw_glyphs_to_bitmap" , &PyFT2Font_draw_glyphs_to_bitmap,
16411642 py::kw_only (), " antialiased" _a=true ,
1642- PyFT2Font_draw_glyphs_to_bitmap__doc__)
1643- .def (" draw_glyph_to_bitmap" , &PyFT2Font_draw_glyph_to_bitmap,
1644- " image" _a, " x" _a, " y" _a, " glyph" _a, py::kw_only (), " antialiased" _a=true ,
1645- PyFT2Font_draw_glyph_to_bitmap__doc__)
1643+ PyFT2Font_draw_glyphs_to_bitmap__doc__);
1644+ // The generated docstring uses an unqualified "Buffer" as type hint,
1645+ // which causes an error in sphinx. This is fixed as of pybind11
1646+ // master (since #5566) which now uses "collections.abc.Buffer";
1647+ // restore the signature once that version is released.
1648+ {
1649+ py::options options{};
1650+ options.disable_function_signatures ();
1651+ cls
1652+ .def (" draw_glyph_to_bitmap" , &PyFT2Font_draw_glyph_to_bitmap,
1653+ " image" _a, " x" _a, " y" _a, " glyph" _a, py::kw_only (), " antialiased" _a=true ,
1654+ PyFT2Font_draw_glyph_to_bitmap__doc__);
1655+ }
1656+ cls
16461657 .def (" get_glyph_name" , &PyFT2Font_get_glyph_name, " index" _a,
16471658 PyFT2Font_get_glyph_name__doc__)
16481659 .def (" get_charmap" , &PyFT2Font_get_charmap, PyFT2Font_get_charmap__doc__)
@@ -1760,10 +1771,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
17601771 " The original filename for this object." )
17611772
17621773 .def_buffer ([](PyFT2Font &self) -> py::buffer_info {
1763- FT2Image &im = self.x ->get_image ();
1764- std::vector<py::size_t > shape { im.get_height (), im.get_width () };
1765- std::vector<py::size_t > strides { im.get_width (), 1 };
1766- return py::buffer_info (im.get_buffer (), shape, strides);
1774+ return self.x ->get_image ().request ();
17671775 });
17681776
17691777 m.attr (" __freetype_version__" ) = version_string;
0 commit comments