diff --git a/kitty/fonts.h b/kitty/fonts.h index fd78c7e51..6a92aa761 100644 --- a/kitty/fonts.h +++ b/kitty/fonts.h @@ -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); diff --git a/kitty/freetype.c b/kitty/freetype.c index 968f88b11..0261be443 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -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) {