Ensure descriptor is always set for coretext font objects
This commit is contained in:
parent
75e1b30fc1
commit
aa1b94aed0
@ -176,18 +176,11 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
float point_sz, dpi;
|
float point_sz, dpi;
|
||||||
if (!PyArg_ParseTuple(args, "Off", &descriptor, &point_sz, &dpi)) return NULL;
|
if (!PyArg_ParseTuple(args, "Off", &descriptor, &point_sz, &dpi)) return NULL;
|
||||||
self = (Face *)type->tp_alloc(type, 0);
|
self = (Face *)type->tp_alloc(type, 0);
|
||||||
if (self) {
|
if (!self) return NULL;
|
||||||
CTFontDescriptorRef desc = font_descriptor_from_python(descriptor);
|
CTFontDescriptorRef desc = font_descriptor_from_python(descriptor);
|
||||||
if (desc) {
|
if (!desc) { Py_CLEAR(self); if(!PyErr_Occurred()) PyErr_NoMemory(); return NULL; }
|
||||||
self->descriptor = desc;
|
self->descriptor = desc;
|
||||||
if (apply_size(self, point_sz, dpi)) {
|
if (!apply_size(self, point_sz, dpi) || !init_font_names(self)) Py_CLEAR(self);
|
||||||
if (!init_font_names(self)) Py_CLEAR(self);
|
|
||||||
} else Py_CLEAR(self);
|
|
||||||
} else {
|
|
||||||
Py_CLEAR(self);
|
|
||||||
if (!PyErr_Occurred()) PyErr_NoMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (PyObject*)self;
|
return (PyObject*)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,18 +226,17 @@ face_for_text(Face *self, PyObject *args) {
|
|||||||
CFRange range = CFRangeMake(0, CFStringGetLength(str));
|
CFRange range = CFRangeMake(0, CFStringGetLength(str));
|
||||||
CFStringGetCharacters(str, range, chars);
|
CFStringGetCharacters(str, range, chars);
|
||||||
CTFontRef font = CTFontCreateForString(self->font, str, range);
|
CTFontRef font = CTFontCreateForString(self->font, str, range);
|
||||||
if (font == self->font) return (PyObject*)self;
|
|
||||||
if (font == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to find fallback font"); goto end; }
|
if (font == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to find fallback font"); goto end; }
|
||||||
ans = (Face *)Face_Type.tp_alloc(&Face_Type, 0);
|
ans = (Face *)Face_Type.tp_alloc(&Face_Type, 0);
|
||||||
if (ans == NULL) { PyErr_NoMemory(); goto end; }
|
if (ans == NULL) { CFRelease(font); PyErr_NoMemory(); goto end; }
|
||||||
ans->font = font;
|
ans->font = font;
|
||||||
|
ans->descriptor = self->descriptor; CFRetain(ans->descriptor);
|
||||||
if (!init_font(ans) || !init_font_names(ans)) { Py_CLEAR(ans); goto end; }
|
if (!init_font(ans) || !init_font_names(ans)) { Py_CLEAR(ans); goto end; }
|
||||||
ans->point_sz = self->point_sz;
|
ans->point_sz = self->point_sz;
|
||||||
ans->dpi = self->dpi;
|
ans->dpi = self->dpi;
|
||||||
end:
|
end:
|
||||||
CFRelease(str);
|
CFRelease(str);
|
||||||
if (ans) return (PyObject*)ans;
|
return (PyObject*)ans;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user