Version 0.1 of raqm, shipping in Fedora, has a differently sized raqm_glyph_t struct

This commit is contained in:
Eric Soroos 2017-09-25 04:23:59 -07:00 committed by Eric Soroos
parent 1852368089
commit 55b029e87a
2 changed files with 75 additions and 26 deletions

View File

@ -95,10 +95,13 @@ typedef bool (*t_raqm_set_freetype_face) (raqm_t *rq,
typedef bool (*t_raqm_layout) (raqm_t *rq);
typedef raqm_glyph_t* (*t_raqm_get_glyphs) (raqm_t *rq,
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,12 +451,21 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
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);
if ((*glyph_info) == NULL) {
@ -448,6 +474,15 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
goto failed;
}
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;
@ -455,6 +490,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir,
(*glyph_info)[i].y_offset = glyphs[i].y_offset;
(*glyph_info)[i].cluster = glyphs[i].cluster;
}
}
failed:
(*p_raqm.destroy)(rq);

View File

@ -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);