diff --git a/src/Canvas.cc b/src/Canvas.cc index bd39d4329..9270031f2 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -706,9 +706,9 @@ NAN_METHOD(Canvas::StreamJPEGSync) { char * str_value(Local val, const char *fallback, bool can_be_number) { if (val->IsString() || (can_be_number && val->IsNumber())) { - return g_strdup(*Nan::Utf8String(val)); + return strdup(*Nan::Utf8String(val)); } else if (fallback) { - return g_strdup(fallback); + return strdup(fallback); } else { return NULL; } @@ -765,9 +765,9 @@ NAN_METHOD(Canvas::RegisterFont) { Nan::ThrowError(GENERIC_FACE_ERROR); } - g_free(family); - g_free(weight); - g_free(style); + free(family); + free(weight); + free(style); } NAN_METHOD(Canvas::DeregisterAllFonts) { diff --git a/src/register_font.cc b/src/register_font.cc index 1b8632dd2..927a66b4b 100644 --- a/src/register_font.cc +++ b/src/register_font.cc @@ -94,35 +94,12 @@ to_utf8(FT_Byte* buf, FT_UInt len, FT_UShort pid, FT_UShort eid) { * system, fall back to the other */ -typedef struct _NameDef { - const char *buf; - int rank; // the higher the more desirable -} NameDef; - -gint -_name_def_compare(gconstpointer a, gconstpointer b) { - return ((NameDef*)a)->rank > ((NameDef*)b)->rank ? -1 : 1; -} - -// Some versions of GTK+ do not have this, particualrly the one we -// currently link to in node-canvas's wiki -void -_free_g_list_item(gpointer data, gpointer user_data) { - NameDef *d = (NameDef *)data; - free((void *)(d->buf)); -} - -void -_g_list_free_full(GList *list) { - g_list_foreach(list, _free_g_list_item, NULL); - g_list_free(list); -} - char * get_family_name(FT_Face face) { FT_SfntName name; - GList *list = NULL; - char *utf8name = NULL; + + int best_rank = -1; + char* best_buf = NULL; for (unsigned i = 0; i < FT_Get_Sfnt_Name_Count(face); ++i) { FT_Get_Sfnt_Name(face, i, &name); @@ -131,20 +108,19 @@ get_family_name(FT_Face face) { char *buf = to_utf8(name.string, name.string_len, name.platform_id, name.encoding_id); if (buf) { - NameDef *d = (NameDef*)malloc(sizeof(NameDef)); - d->buf = (const char*)buf; - d->rank = GET_NAME_RANK(name); - - list = g_list_insert_sorted(list, (gpointer)d, _name_def_compare); + int rank = GET_NAME_RANK(name); + if (rank > best_rank) { + best_rank = rank; + if (best_buf) free(best_buf); + best_buf = buf; + } else { + free(buf); + } } } } - GList *best_def = g_list_first(list); - if (best_def) utf8name = (char*) strdup(((NameDef*)best_def->data)->buf); - if (list) _g_list_free_full(list); - - return utf8name; + return best_buf; } PangoWeight