@@ -430,6 +430,9 @@ const char *PyFT2Font_init__doc__ = R"""(
430
430
hinting_factor : int, optional
431
431
Must be positive. Used to scale the hinting in the x-direction.
432
432
433
+ face_index : int, optional
434
+ The index of the face in the font file to load.
435
+
433
436
_fallback_list : list of FT2Font, optional
434
437
A list of FT2Font objects used to find missing glyphs.
435
438
@@ -444,7 +447,7 @@ const char *PyFT2Font_init__doc__ = R"""(
444
447
)""" ;
445
448
446
449
static 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 ,
448
451
std::optional<std::vector<PyFT2Font *>> fallback_list = std::nullopt ,
449
452
std::optional<int > kerning_factor = std::nullopt ,
450
453
bool warn_if_used = false )
@@ -460,6 +463,10 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
460
463
kerning_factor = 0 ;
461
464
}
462
465
466
+ if (face_index < 0 || face_index > 0xffff ) {
467
+ throw std::range_error (" face_index must be between 0 and 65535, inclusive" );
468
+ }
469
+
463
470
std::vector<FT2Font *> fallback_fonts;
464
471
if (fallback_list) {
465
472
// go through fallbacks to add them to our lists
@@ -509,7 +516,7 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
509
516
self->stream .close = nullptr ;
510
517
}
511
518
512
- self->open (open_args);
519
+ self->open (face_index, open_args);
513
520
514
521
return self;
515
522
}
@@ -1546,7 +1553,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1546
1553
auto cls = py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
1547
1554
PyFT2Font__doc__)
1548
1555
.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 ,
1550
1557
" _fallback_list" _a=py::none (), " _kerning_factor" _a=py::none (),
1551
1558
" _warn_if_used" _a=false ,
1552
1559
PyFT2Font_init__doc__)
@@ -1622,8 +1629,12 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1622
1629
}, " PostScript name of the font." )
1623
1630
.def_property_readonly (
1624
1631
" num_faces" , [](PyFT2Font *self) {
1625
- return self->get_face ()->num_faces ;
1632
+ return self->get_face ()->num_faces & 0xffff ;
1626
1633
}, " 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." )
1627
1638
.def_property_readonly (
1628
1639
" family_name" , [](PyFT2Font *self) {
1629
1640
if (const char *name = self->get_face ()->family_name ) {
0 commit comments