@@ -430,6 +430,9 @@ const char *PyFT2Font_init__doc__ = R"""(
430430 hinting_factor : int, optional
431431 Must be positive. Used to scale the hinting in the x-direction.
432432
433+ face_index : int, optional
434+ The index of the face in the font file to load.
435+
433436 _fallback_list : list of FT2Font, optional
434437 A list of FT2Font objects used to find missing glyphs.
435438
@@ -444,7 +447,7 @@ const char *PyFT2Font_init__doc__ = R"""(
444447)""" ;
445448
446449static PyFT2Font *
447- PyFT2Font_init (py::object filename, long hinting_factor = 8 ,
450+ PyFT2Font_init (py::object filename, long hinting_factor = 8 , FT_Long face_index = 0 ,
448451 std::optional<std::vector<PyFT2Font *>> fallback_list = std::nullopt ,
449452 std::optional<int > kerning_factor = std::nullopt ,
450453 bool warn_if_used = false )
@@ -460,6 +463,10 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
460463 kerning_factor = 0 ;
461464 }
462465
466+ if (face_index < 0 || face_index > 0xffff ) {
467+ throw std::range_error (" face_index must be between 0 and 65535, inclusive" );
468+ }
469+
463470 std::vector<FT2Font *> fallback_fonts;
464471 if (fallback_list) {
465472 // go through fallbacks to add them to our lists
@@ -509,7 +516,7 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
509516 self->stream .close = nullptr ;
510517 }
511518
512- self->open (open_args);
519+ self->open (face_index, open_args);
513520
514521 return self;
515522}
@@ -1546,7 +1553,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
15461553 auto cls = py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
15471554 PyFT2Font__doc__)
15481555 .def (py::init (&PyFT2Font_init),
1549- " filename" _a, " hinting_factor" _a=8 , py::kw_only (),
1556+ " filename" _a, " hinting_factor" _a=8 , py::kw_only (), " face_index " _a= 0 ,
15501557 " _fallback_list" _a=py::none (), " _kerning_factor" _a=py::none (),
15511558 " _warn_if_used" _a=false ,
15521559 PyFT2Font_init__doc__)
@@ -1622,8 +1629,12 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
16221629 }, " PostScript name of the font." )
16231630 .def_property_readonly (
16241631 " num_faces" , [](PyFT2Font *self) {
1625- return self->get_face ()->num_faces ;
1632+ return self->get_face ()->num_faces & 0xffff ;
16261633 }, " Number of faces in file." )
1634+ .def_property_readonly (
1635+ " face_index" , [](PyFT2Font *self) {
1636+ return self->get_face ()->face_index ;
1637+ }, " The index of the font in the file." )
16271638 .def_property_readonly (
16281639 " family_name" , [](PyFT2Font *self) {
16291640 if (const char *name = self->get_face ()->family_name ) {
0 commit comments