@@ -172,7 +172,8 @@ const char *PyFT2Font_init__doc__ =
172172
173173static PyFT2Font *
174174PyFT2Font_init (py::object filename, long hinting_factor = 8 ,
175- py::object fallback_list_or_none = py::none(), int kerning_factor = 0)
175+ std::optional<std::vector<PyFT2Font *>> fallback_list = std::nullopt ,
176+ int kerning_factor = 0 )
176177{
177178 if (hinting_factor <= 0 ) {
178179 throw py::value_error (" hinting_factor must be greater than 0" );
@@ -192,24 +193,13 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
192193 open_args.stream = &self->stream ;
193194
194195 std::vector<FT2Font *> fallback_fonts;
195- if (!fallback_list_or_none.is_none ()) {
196- if (!py::isinstance<py::list>(fallback_list_or_none)) {
197- throw py::type_error (" Fallback list must be a list" );
198- }
199- auto fallback_list = fallback_list_or_none.cast <py::list>();
200-
201- // go through fallbacks once to make sure the types are right
202- for (auto item : fallback_list) {
203- if (!py::isinstance<PyFT2Font>(item)) {
204- throw py::type_error (" Fallback fonts must be FT2Font objects." );
205- }
206- }
207- // go through a second time to add them to our lists
208- for (auto item : fallback_list) {
196+ if (fallback_list) {
197+ // go through fallbacks to add them to our lists
198+ for (auto item : *fallback_list) {
209199 self->fallbacks .append (item);
210200 // Also (locally) cache the underlying FT2Font objects. As long as
211201 // the Python objects are kept alive, these pointer are good.
212- FT2Font *fback = py::cast<PyFT2Font *>( item) ->x ;
202+ FT2Font *fback = item->x ;
213203 fallback_fonts.push_back (fback);
214204 }
215205 }
0 commit comments