Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ class PyFT2Font final : public FT2Font
close();
}


void ft_glyph_warn(FT_ULong charcode, std::set<FT_String*> family_names)
{
std::set<FT_String*>::iterator it = family_names.begin();
std::stringstream ss;
ss<<*it;
ss << *it;
while(++it != family_names.end()){
ss<<", "<<*it;
}
Expand Down Expand Up @@ -463,19 +464,30 @@ read_from_file_callback(FT_Stream stream, unsigned long offset, unsigned char *b
return (unsigned long)n_read;
}

// FIX: Replace deprecated PyErr_Fetch/PyErr_Restore (deprecated in Python 3.12)
// with PyErr_GetRaisedException/PyErr_SetRaisedException where available,
// while keeping backward compatibility with older Python versions.
static void
close_file_callback(FT_Stream stream)
{
#if PY_VERSION_HEX >= 0x030c0000
PyObject *exc = PyErr_GetRaisedException();
#else
PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
#endif
PyFT2Font *self = (PyFT2Font *)stream->descriptor.pointer;
try {
self->py_file.attr("close")();
} catch (py::error_already_set &eas) {
eas.discard_as_unraisable(__func__);
}
self->py_file = py::object();
#if PY_VERSION_HEX >= 0x030c0000
PyErr_SetRaisedException(exc);
#else
PyErr_Restore(type, value, traceback);
#endif
}

const char *PyFT2Font_init__doc__ = R"""(
Expand Down
Loading