@@ -426,6 +426,9 @@ const char *PyFT2Font_init__doc__ = R"""(
426
426
hinting_factor : int, optional
427
427
Must be positive. Used to scale the hinting in the x-direction.
428
428
429
+ face_index : int, optional
430
+ The index of the face in the font file to load.
431
+
429
432
_fallback_list : list of FT2Font, optional
430
433
A list of FT2Font objects used to find missing glyphs.
431
434
@@ -440,7 +443,7 @@ const char *PyFT2Font_init__doc__ = R"""(
440
443
)""" ;
441
444
442
445
static PyFT2Font *
443
- PyFT2Font_init (py::object filename, long hinting_factor = 8 ,
446
+ PyFT2Font_init (py::object filename, long hinting_factor = 8 , FT_Long face_index = 0 ,
444
447
std::optional<std::vector<PyFT2Font *>> fallback_list = std::nullopt ,
445
448
std::optional<int > kerning_factor = std::nullopt ,
446
449
bool warn_if_used = false )
@@ -456,6 +459,10 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
456
459
kerning_factor = 0 ;
457
460
}
458
461
462
+ if (face_index < 0 || face_index >= 1 <<16 ) {
463
+ throw std::range_error (" face_index must be between 0 and 65535, inclusive" );
464
+ }
465
+
459
466
PyFT2Font *self = new PyFT2Font ();
460
467
self->x = nullptr ;
461
468
memset (&self->stream , 0 , sizeof (FT_StreamRec));
@@ -502,8 +509,8 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
502
509
self->stream .close = nullptr ;
503
510
}
504
511
505
- self->x = new FT2Font (open_args, hinting_factor, fallback_fonts, ft_glyph_warn ,
506
- warn_if_used);
512
+ self->x = new FT2Font (face_index, open_args, hinting_factor, fallback_fonts,
513
+ ft_glyph_warn, warn_if_used);
507
514
508
515
self->x ->set_kerning_factor (*kerning_factor);
509
516
@@ -1609,7 +1616,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1609
1616
auto cls = py::class_<PyFT2Font>(m, " FT2Font" , py::is_final (), py::buffer_protocol (),
1610
1617
PyFT2Font__doc__)
1611
1618
.def (py::init (&PyFT2Font_init),
1612
- " filename" _a, " hinting_factor" _a=8 , py::kw_only (),
1619
+ " filename" _a, " hinting_factor" _a=8 , py::kw_only (), " face_index " _a= 0 ,
1613
1620
" _fallback_list" _a=py::none (), " _kerning_factor" _a=py::none (),
1614
1621
" _warn_if_used" _a=false ,
1615
1622
PyFT2Font_init__doc__)
@@ -1682,8 +1689,12 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1682
1689
}, " PostScript name of the font." )
1683
1690
.def_property_readonly (
1684
1691
" num_faces" , [](PyFT2Font *self) {
1685
- return self->x ->get_face ()->num_faces ;
1692
+ return self->x ->get_face ()->num_faces & 0xffff ;
1686
1693
}, " Number of faces in file." )
1694
+ .def_property_readonly (
1695
+ " face_index" , [](PyFT2Font *self) {
1696
+ return self->x ->get_face ()->face_index ;
1697
+ }, " The index of the font in the file." )
1687
1698
.def_property_readonly (
1688
1699
" family_name" , [](PyFT2Font *self) {
1689
1700
if (const char *name = self->x ->get_face ()->family_name ) {
0 commit comments