From 55b029e87ac1bd34df9f72b70007836cd993b352 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Mon, 25 Sep 2017 04:23:59 -0700 Subject: [PATCH] Version 0.1 of raqm, shipping in Fedora, has a differently sized raqm_glyph_t struct --- _imagingft.c | 88 +++++++++++++++++++++++++++++++++-------------- libImaging/raqm.h | 13 +++++++ 2 files changed, 75 insertions(+), 26 deletions(-) diff --git a/_imagingft.c b/_imagingft.c index 5c0505be9..84ead77c2 100644 --- a/_imagingft.c +++ b/_imagingft.c @@ -80,25 +80,28 @@ static PyTypeObject Font_Type; typedef raqm_t* (*t_raqm_create)(void); typedef int (*t_raqm_set_text)(raqm_t *rq, - const uint32_t *text, - size_t len); + const uint32_t *text, + size_t len); typedef bool (*t_raqm_set_text_utf8) (raqm_t *rq, - const char *text, - size_t len); + const char *text, + size_t len); typedef bool (*t_raqm_set_par_direction) (raqm_t *rq, - raqm_direction_t dir); + raqm_direction_t dir); typedef bool (*t_raqm_add_font_feature) (raqm_t *rq, - const char *feature, - int len); + const char *feature, + int len); typedef bool (*t_raqm_set_freetype_face) (raqm_t *rq, - FT_Face face); + FT_Face face); typedef bool (*t_raqm_layout) (raqm_t *rq); typedef raqm_glyph_t* (*t_raqm_get_glyphs) (raqm_t *rq, - size_t *length); + size_t *length); +typedef raqm_glyph_t_01* (*t_raqm_get_glyphs_01) (raqm_t *rq, + size_t *length); typedef void (*t_raqm_destroy) (raqm_t *rq); typedef struct { void* raqm; + int version; t_raqm_create create; t_raqm_set_text set_text; t_raqm_set_text_utf8 set_text_utf8; @@ -107,6 +110,7 @@ typedef struct { t_raqm_set_freetype_face set_freetype_face; t_raqm_layout layout; t_raqm_get_glyphs get_glyphs; + t_raqm_get_glyphs_01 get_glyphs_01; t_raqm_destroy destroy; } p_raqm_func; @@ -159,8 +163,14 @@ setraqm(void) p_raqm.add_font_feature = (t_raqm_add_font_feature)dlsym(p_raqm.raqm, "raqm_add_font_feature"); p_raqm.set_freetype_face = (t_raqm_set_freetype_face)dlsym(p_raqm.raqm, "raqm_set_freetype_face"); p_raqm.layout = (t_raqm_layout)dlsym(p_raqm.raqm, "raqm_layout"); - p_raqm.get_glyphs = (t_raqm_get_glyphs)dlsym(p_raqm.raqm, "raqm_get_glyphs"); p_raqm.destroy = (t_raqm_destroy)dlsym(p_raqm.raqm, "raqm_destroy"); + if(dlsym(p_raqm.raqm, "raqm_index_to_position")) { + p_raqm.get_glyphs = (t_raqm_get_glyphs)dlsym(p_raqm.raqm, "raqm_get_glyphs"); + p_raqm.version = 2; + } else { + p_raqm.version = 1; + p_raqm.get_glyphs_01 = (t_raqm_get_glyphs_01)dlsym(p_raqm.raqm, "raqm_get_glyphs"); + } if (dlerror() || !(p_raqm.create && p_raqm.set_text && @@ -169,7 +179,7 @@ setraqm(void) p_raqm.add_font_feature && p_raqm.set_freetype_face && p_raqm.layout && - p_raqm.get_glyphs && + (p_raqm.get_glyphs || p_raqm.get_glyphs_01) && p_raqm.destroy)) { dlclose(p_raqm.raqm); p_raqm.raqm = NULL; @@ -183,8 +193,14 @@ setraqm(void) p_raqm.add_font_feature = (t_raqm_add_font_feature)GetProcAddress(p_raqm.raqm, "raqm_add_font_feature"); p_raqm.set_freetype_face = (t_raqm_set_freetype_face)GetProcAddress(p_raqm.raqm, "raqm_set_freetype_face"); p_raqm.layout = (t_raqm_layout)GetProcAddress(p_raqm.raqm, "raqm_layout"); - p_raqm.get_glyphs = (t_raqm_get_glyphs)GetProcAddress(p_raqm.raqm, "raqm_get_glyphs"); p_raqm.destroy = (t_raqm_destroy)GetProcAddress(p_raqm.raqm, "raqm_destroy"); + if(dlsym(p_raqm.raqm, "raqm_index_to_position")) { + p_raqm.get_glyphs = (t_raqm_get_glyphs)GetProcAddress(p_raqm.raqm, "raqm_get_glyphs"); + p_raqm.version = 2; + } else { + p_raqm.version = 1; + p_raqm.get_glyphs_01 = (t_raqm_get_glyphs_01)GetProcAddress(p_raqm.raqm, "raqm_get_glyphs"); + } if (!(p_raqm.create && p_raqm.set_text && p_raqm.set_text_utf8 && @@ -192,7 +208,7 @@ setraqm(void) p_raqm.add_font_feature && p_raqm.set_freetype_face && p_raqm.layout && - p_raqm.get_glyphs && + (p_raqm.get_glyphs || p_raqm.get_glyphs_01) && p_raqm.destroy)) { FreeLibrary(p_raqm.raqm); p_raqm.raqm = NULL; @@ -322,7 +338,8 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, int i = 0; raqm_t *rq; size_t count = 0; - raqm_glyph_t *glyphs; + raqm_glyph_t *glyphs = NULL; + raqm_glyph_t_01 *glyphs_01 = NULL; raqm_direction_t direction; rq = (*p_raqm.create)(); @@ -434,11 +451,20 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, goto failed; } - glyphs = (*p_raqm.get_glyphs)(rq, &count); - if (glyphs == NULL) { - PyErr_SetString(PyExc_ValueError, "raqm_get_glyphs() failed."); - count = 0; - goto failed; + if (p_raqm.version == 1){ + glyphs_01 = (*p_raqm.get_glyphs_01)(rq, &count); + if (glyphs_01 == NULL) { + PyErr_SetString(PyExc_ValueError, "raqm_get_glyphs() failed."); + count = 0; + goto failed; + } + } else { /* version == 2 */ + glyphs = (*p_raqm.get_glyphs)(rq, &count); + if (glyphs == NULL) { + PyErr_SetString(PyExc_ValueError, "raqm_get_glyphs() failed."); + count = 0; + goto failed; + } } (*glyph_info) = PyMem_New(GlyphInfo, count); @@ -448,12 +474,22 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, goto failed; } - for (i = 0; i < count; i++) { - (*glyph_info)[i].index = glyphs[i].index; - (*glyph_info)[i].x_offset = glyphs[i].x_offset; - (*glyph_info)[i].x_advance = glyphs[i].x_advance; - (*glyph_info)[i].y_offset = glyphs[i].y_offset; - (*glyph_info)[i].cluster = glyphs[i].cluster; + if (p_raqm.version == 1){ + for (i = 0; i < count; i++) { + (*glyph_info)[i].index = glyphs_01[i].index; + (*glyph_info)[i].x_offset = glyphs_01[i].x_offset; + (*glyph_info)[i].x_advance = glyphs_01[i].x_advance; + (*glyph_info)[i].y_offset = glyphs_01[i].y_offset; + (*glyph_info)[i].cluster = glyphs_01[i].cluster; + } + } else { + for (i = 0; i < count; i++) { + (*glyph_info)[i].index = glyphs[i].index; + (*glyph_info)[i].x_offset = glyphs[i].x_offset; + (*glyph_info)[i].x_advance = glyphs[i].x_advance; + (*glyph_info)[i].y_offset = glyphs[i].y_offset; + (*glyph_info)[i].cluster = glyphs[i].cluster; + } } failed: @@ -958,7 +994,7 @@ setup_module(PyObject* m) { PyDict_SetItemString(d, "freetype2_version", v); - setraqm(); + setraqm(); v = PyBool_FromLong(!!p_raqm.raqm); PyDict_SetItemString(d, "HAVE_RAQM", v); diff --git a/libImaging/raqm.h b/libImaging/raqm.h index d33f080bf..eae1f43b7 100644 --- a/libImaging/raqm.h +++ b/libImaging/raqm.h @@ -94,6 +94,19 @@ typedef struct raqm_glyph_t { FT_Face ftface; } raqm_glyph_t; +/** + * version 0.1 of the raqm_glyph_t structure + */ +typedef struct raqm_glyph_t_01 { + unsigned int index; + int x_advance; + int y_advance; + int x_offset; + int y_offset; + uint32_t cluster; +} raqm_glyph_t_01; + + raqm_t * raqm_create (void);