API to create FreeType face from in memory data

This commit is contained in:
Kovid Goyal
2017-11-10 14:30:54 +05:30
parent 774956053a
commit b0fffad0c2
2 changed files with 13 additions and 1 deletions

View File

@@ -23,5 +23,5 @@ bool render_glyphs_in_cells(PyObject *f, bool bold, bool italic, hb_glyph_info_t
void render_line(Line *line);
void sprite_tracker_set_limits(size_t max_texture_size, size_t max_array_len);
void sprite_tracker_set_layout(unsigned int cell_width, unsigned int cell_height);
typedef void (*free_extra_data_func)(void*);
PyObject* ft_face_from_data(const uint8_t* data, size_t sz, void *extra_data, free_extra_data_func fed, PyObject *path, int hinting, int hintstyle, float size_in_pts, float xdpi, float ydpi);

View File

@@ -32,6 +32,7 @@ typedef struct {
void *extra_data;
free_extra_data_func free_extra_data;
} Face;
PyTypeObject Face_Type;
static PyObject* FreeType_Exception = NULL;
@@ -126,6 +127,17 @@ init_ft_face(Face *self, PyObject *path, int hinting, int hintstyle, float size_
return true;
}
PyObject*
ft_face_from_data(const uint8_t* data, size_t sz, void *extra_data, free_extra_data_func fed, PyObject *path, int hinting, int hintstyle, float size_in_pts, float xdpi, float ydpi) {
Face *ans = (Face*)Face_Type.tp_alloc(&Face_Type, 0);
if (ans == NULL) return NULL;
int error = FT_New_Memory_Face(library, data, sz, 0, &ans->face);
if(error) { set_freetype_error("Failed to load memory face, with error:", error); Py_CLEAR(ans); return NULL; }
ans->extra_data = extra_data;
ans->free_extra_data = fed;
if (!init_ft_face(ans, path, hinting, hintstyle, size_in_pts, xdpi, ydpi)) Py_CLEAR(ans);
return (PyObject*)ans;
}
static PyObject*
new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {