1
1
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2
2
#include < pybind11/pybind11.h>
3
3
#include < pybind11/numpy.h>
4
+ #include < pybind11/stl.h>
4
5
5
6
#include " ft2font.h"
6
7
#include " numpy/arrayobject.h"
@@ -171,7 +172,8 @@ const char *PyFT2Font_init__doc__ =
171
172
172
173
static PyFT2Font *
173
174
PyFT2Font_init (py::object filename, long hinting_factor = 8 ,
174
- 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 )
175
177
{
176
178
if (hinting_factor <= 0 ) {
177
179
throw py::value_error (" hinting_factor must be greater than 0" );
@@ -191,24 +193,13 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8,
191
193
open_args.stream = &self->stream ;
192
194
193
195
std::vector<FT2Font *> fallback_fonts;
194
- if (!fallback_list_or_none.is_none ()) {
195
- if (!py::isinstance<py::list>(fallback_list_or_none)) {
196
- throw py::type_error (" Fallback list must be a list" );
197
- }
198
- auto fallback_list = fallback_list_or_none.cast <py::list>();
199
-
200
- // go through fallbacks once to make sure the types are right
201
- for (auto item : fallback_list) {
202
- if (!py::isinstance<PyFT2Font>(item)) {
203
- throw py::type_error (" Fallback fonts must be FT2Font objects." );
204
- }
205
- }
206
- // go through a second time to add them to our lists
207
- 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 ()) {
208
199
self->fallbacks .append (item);
209
200
// Also (locally) cache the underlying FT2Font objects. As long as
210
201
// the Python objects are kept alive, these pointer are good.
211
- FT2Font *fback = py::cast<PyFT2Font *>( item) ->x ;
202
+ FT2Font *fback = item->x ;
212
203
fallback_fonts.push_back (fback);
213
204
}
214
205
}
0 commit comments