@@ -172,7 +172,8 @@ const char *PyFT2Font_init__doc__ =
172
172
173
173
static PyFT2Font *
174
174
PyFT2Font_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 )
176
177
{
177
178
if (hinting_factor <= 0 ) {
178
179
throw py::value_error (" hinting_factor must be greater than 0" );
@@ -192,24 +193,13 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
192
193
open_args.stream = &self->stream ;
193
194
194
195
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.value ()) {
209
199
self->fallbacks .append (item);
210
200
// Also (locally) cache the underlying FT2Font objects. As long as
211
201
// the Python objects are kept alive, these pointer are good.
212
- FT2Font *fback = py::cast<PyFT2Font *>( item) ->x ;
202
+ FT2Font *fback = item->x ;
213
203
fallback_fonts.push_back (fback);
214
204
}
215
205
}
0 commit comments