@@ -968,7 +968,7 @@ const char *PyFT2Font_draw_glyph_to_bitmap__doc__ = R"""(
968
968
969
969
Parameters
970
970
----------
971
- image : FT2Image
971
+ image : 2d array of uint8
972
972
The image buffer on which to draw the glyph.
973
973
x, y : int
974
974
The pixel location at which to draw the glyph.
@@ -983,14 +983,16 @@ const char *PyFT2Font_draw_glyph_to_bitmap__doc__ = R"""(
983
983
)""" ;
984
984
985
985
static void
986
- PyFT2Font_draw_glyph_to_bitmap (PyFT2Font *self, FT2Image &image,
986
+ PyFT2Font_draw_glyph_to_bitmap (PyFT2Font *self, py::buffer &image,
987
987
double_or_<int > vxd, double_or_<int > vyd,
988
988
PyGlyph *glyph, bool antialiased = true )
989
989
{
990
990
auto xd = _double_to_<int >(" x" , vxd);
991
991
auto yd = _double_to_<int >(" y" , vyd);
992
992
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);
994
996
}
995
997
996
998
const char *PyFT2Font_get_glyph_name__doc__ = R"""(
@@ -1440,12 +1442,7 @@ const char *PyFT2Font_get_image__doc__ = R"""(
1440
1442
static py::array
1441
1443
PyFT2Font_get_image (PyFT2Font *self)
1442
1444
{
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 ();
1449
1446
}
1450
1447
1451
1448
const char *PyFT2Font__get_type1_encoding_vector__doc__ = R"""(
@@ -1565,6 +1562,10 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1565
1562
PyFT2Image__doc__)
1566
1563
.def (py::init (
1567
1564
[](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" );
1568
1569
return new FT2Image (
1569
1570
_double_to_<long >(" width" , width),
1570
1571
_double_to_<long >(" height" , height)
@@ -1604,8 +1605,8 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1604
1605
.def_property_readonly (" bbox" , &PyGlyph_get_bbox,
1605
1606
" The control box of the glyph." );
1606
1607
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__)
1609
1610
.def (py::init (&PyFT2Font_init),
1610
1611
" filename" _a, " hinting_factor" _a=8 , py::kw_only (),
1611
1612
" _fallback_list" _a=py::none (), " _kerning_factor" _a=0 ,
@@ -1639,10 +1640,20 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1639
1640
.def (" get_descent" , &PyFT2Font_get_descent, PyFT2Font_get_descent__doc__)
1640
1641
.def (" draw_glyphs_to_bitmap" , &PyFT2Font_draw_glyphs_to_bitmap,
1641
1642
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
1646
1657
.def (" get_glyph_name" , &PyFT2Font_get_glyph_name, " index" _a,
1647
1658
PyFT2Font_get_glyph_name__doc__)
1648
1659
.def (" get_charmap" , &PyFT2Font_get_charmap, PyFT2Font_get_charmap__doc__)
@@ -1760,10 +1771,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1760
1771
" The original filename for this object." )
1761
1772
1762
1773
.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 ();
1767
1775
});
1768
1776
1769
1777
m.attr (" __freetype_version__" ) = version_string;
0 commit comments