@@ -498,6 +498,16 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
498498 return self;
499499}
500500
501+ static py::str
502+ PyFT2Font_fname (PyFT2Font *self)
503+ {
504+ if (self->stream .close ) { // Called passed a filename to the constructor.
505+ return self->py_file .attr (" name" );
506+ } else {
507+ return py::cast<py::str>(self->py_file );
508+ }
509+ }
510+
501511const char *PyFT2Font_clear__doc__ =
502512 " Clear all the glyphs, reset for a new call to `.set_text`." ;
503513
@@ -1431,6 +1441,32 @@ PyFT2Font_get_image(PyFT2Font *self)
14311441 return py::array_t <unsigned char >(dims, im.get_buffer ());
14321442}
14331443
1444+ const char *PyFT2Font__get_type1_encoding_vector__doc__ = R"""(
1445+ Return a list mapping CharString indices of a Type 1 font to FreeType glyph indices.
1446+
1447+ Returns
1448+ -------
1449+ list[int]
1450+ )""" ;
1451+
1452+ static std::array<FT_UInt, 256 >
1453+ PyFT2Font__get_type1_encoding_vector (PyFT2Font *self)
1454+ {
1455+ auto face = self->x ->get_face ();
1456+ auto indices = std::array<FT_UInt, 256 >{};
1457+ for (auto i = 0u ; i < indices.size (); ++i) {
1458+ auto len = FT_Get_PS_Font_Value (face, PS_DICT_ENCODING_ENTRY, i, nullptr , 0 );
1459+ if (len == -1 ) {
1460+ // Explicitly ignore missing entries (mapped to glyph 0 = .notdef).
1461+ continue ;
1462+ }
1463+ auto buf = std::make_unique<char []>(len);
1464+ FT_Get_PS_Font_Value (face, PS_DICT_ENCODING_ENTRY, i, buf.get (), len);
1465+ indices[i] = FT_Get_Name_Index (face, buf.get ());
1466+ }
1467+ return indices;
1468+ }
1469+
14341470static const char *
14351471PyFT2Font_postscript_name (PyFT2Font *self)
14361472{
@@ -1569,16 +1605,6 @@ PyFT2Font_underline_thickness(PyFT2Font *self)
15691605 return self->x ->get_face ()->underline_thickness ;
15701606}
15711607
1572- static py::str
1573- PyFT2Font_fname (PyFT2Font *self)
1574- {
1575- if (self->stream .close ) { // Called passed a filename to the constructor.
1576- return self->py_file .attr (" name" );
1577- } else {
1578- return py::cast<py::str>(self->py_file );
1579- }
1580- }
1581-
15821608static py::object
15831609ft2font__getattr__ (std::string name) {
15841610 auto api = py::module_::import (" matplotlib._api" );
@@ -1761,6 +1787,8 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
17611787 PyFT2Font_get_sfnt_table__doc__)
17621788 .def (" get_path" , &PyFT2Font_get_path, PyFT2Font_get_path__doc__)
17631789 .def (" get_image" , &PyFT2Font_get_image, PyFT2Font_get_image__doc__)
1790+ .def (" _get_type1_encoding_vector" , &PyFT2Font__get_type1_encoding_vector,
1791+ PyFT2Font__get_type1_encoding_vector__doc__)
17641792
17651793 .def_property_readonly (" postscript_name" , &PyFT2Font_postscript_name,
17661794 " PostScript name of the font." )
0 commit comments