@@ -426,6 +426,9 @@ const char *PyFT2Font_init__doc__ = R"""(
426426 hinting_factor : int, optional
427427 Must be positive. Used to scale the hinting in the x-direction.
428428
429+ face_index : int, optional
430+ The index of the face in the font file to load.
431+
429432 _fallback_list : list of FT2Font, optional
430433 A list of FT2Font objects used to find missing glyphs.
431434
@@ -446,14 +449,18 @@ const char *PyFT2Font_init__doc__ = R"""(
446449)""" ;
447450
448451static PyFT2Font *
449- PyFT2Font_init (py::object filename, long hinting_factor = 8 ,
452+ PyFT2Font_init (py::object filename, long hinting_factor = 8 , FT_Long face_index = 0 ,
450453 std::optional<std::vector<PyFT2Font *>> fallback_list = std::nullopt ,
451454 int kerning_factor = 0 , bool warn_if_used = false )
452455{
453456 if (hinting_factor <= 0 ) {
454457 throw py::value_error (" hinting_factor must be greater than 0" );
455458 }
456459
460+ if (face_index < 0 || face_index >= 1 <<16 ) {
461+ throw std::range_error (" face_index must be between 0 and 65535, inclusive" );
462+ }
463+
457464 PyFT2Font *self = new PyFT2Font ();
458465 self->x = nullptr ;
459466 memset (&self->stream , 0 , sizeof (FT_StreamRec));
@@ -497,8 +504,8 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
497504 self->stream .close = nullptr ;
498505 }
499506
500- self->x = new FT2Font (open_args, hinting_factor, fallback_fonts, ft_glyph_warn ,
501- warn_if_used);
507+ self->x = new FT2Font (face_index, open_args, hinting_factor, fallback_fonts,
508+ ft_glyph_warn, warn_if_used);
502509
503510 self->x ->set_kerning_factor (kerning_factor);
504511
@@ -1604,7 +1611,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
16041611 auto cls = py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
16051612 PyFT2Font__doc__)
16061613 .def (py::init (&PyFT2Font_init),
1607- " filename" _a, " hinting_factor" _a=8 , py::kw_only (),
1614+ " filename" _a, " hinting_factor" _a=8 , py::kw_only (), " face_index " _a= 0 ,
16081615 " _fallback_list" _a=py::none (), " _kerning_factor" _a=0 ,
16091616 " _warn_if_used" _a=false ,
16101617 PyFT2Font_init__doc__)
@@ -1677,8 +1684,12 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
16771684 }, " PostScript name of the font." )
16781685 .def_property_readonly (
16791686 " num_faces" , [](PyFT2Font *self) {
1680- return self->x ->get_face ()->num_faces ;
1687+ return self->x ->get_face ()->num_faces & 0xffff ;
16811688 }, " Number of faces in file." )
1689+ .def_property_readonly (
1690+ " face_index" , [](PyFT2Font *self) {
1691+ return self->x ->get_face ()->face_index ;
1692+ }, " The index of the font in the file." )
16821693 .def_property_readonly (
16831694 " family_name" , [](PyFT2Font *self) {
16841695 if (const char *name = self->x ->get_face ()->family_name ) {
0 commit comments