Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shorten PyFT2Font_get_charmap. #16393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2020
Merged
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
36 changes: 8 additions & 28 deletions src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,44 +975,24 @@ const char *PyFT2Font_get_charmap__doc__ =
static PyObject *PyFT2Font_get_charmap(PyFT2Font *self, PyObject *args, PyObject *kwds)
{
PyObject *charmap;

charmap = PyDict_New();
if (charmap == NULL) {
if (!(charmap = PyDict_New())) {
return NULL;
}

FT_UInt index;
FT_ULong code = FT_Get_First_Char(self->x->get_face(), &index);
while (index != 0) {
PyObject *key;
PyObject *val;

key = PyLong_FromLong(code);
if (key == NULL) {
Py_DECREF(charmap);
return NULL;
}

val = PyLong_FromLong(index);
if (val == NULL) {
Py_DECREF(key);
Py_DECREF(charmap);
return NULL;
}

if (PyDict_SetItem(charmap, key, val)) {
Py_DECREF(key);
Py_DECREF(val);
PyObject *key = NULL, *val = NULL;
bool error = (!(key = PyLong_FromLong(code))
|| !(val = PyLong_FromLong(index))
|| (PyDict_SetItem(charmap, key, val) == -1));
Py_XDECREF(key);
Py_XDECREF(val);
if (error) {
Py_DECREF(charmap);
return NULL;
}

Py_DECREF(key);
Py_DECREF(val);

code = FT_Get_Next_Char(self->x->get_face(), code, &index);
}

return charmap;
}

Expand Down