From: erg Date: Thu, 24 Feb 2011 20:40:27 +0000 (+0000) Subject: Fix problem when no matching available font is found. We then provide and test X-Git-Tag: LAST_LIBGRAPH~32^2~998 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d9b75ef6565934bae7c0837264dbe2240844fb7;p=graphviz Fix problem when no matching available font is found. We then provide and test for an empty string "". --- diff --git a/plugin/pango/gvgetfontlist_pango.c b/plugin/pango/gvgetfontlist_pango.c index c076a6e1b..f9bc94d44 100644 --- a/plugin/pango/gvgetfontlist_pango.c +++ b/plugin/pango/gvgetfontlist_pango.c @@ -1,3 +1,4 @@ +/* vim:set shiftwidth=4 ts=8: */ #define HAVE_PANGOCAIRO #include #include @@ -15,176 +16,191 @@ static PostscriptAlias postscript_alias[] = { }; /* Frees memory used by the Graphviz PS font definitions */ -void gv_flist_free_ps(fontdef_t **gv_ps_fontdefs_p){ -int i,j; +void gv_flist_free_ps(fontdef_t ** gv_ps_fontdefs_p) +{ + int i, j; -for(i=0;igeneric_name = generic; - gv_ps_fontdefs->equiv = N_NEW(arraysz,char*); - for(j=0;jequiv[j] = strdup(font_equiv[j]); +void load_fontdefs(fontdef_t * gv_ps_fontdefs, char *generic, + const int arraysz, const char **font_equiv) +{ + int j; + gv_ps_fontdefs->generic_name = generic; + gv_ps_fontdefs->equiv = N_NEW(arraysz, char *); + for (j = 0; j < arraysz; j++) { + gv_ps_fontdefs->equiv[j] = strdup(font_equiv[j]); gv_ps_fontdefs->eq_sz = arraysz; - } + } } /* Converts string to upper case */ -void upperCase(char *src ) { - for (; *src != '\0'; ++src ) { - if ( *src>='a' && *src <= 'z' ) { - *src = *src - 32; - } - } +void upperCase(char *src) +{ + for (; *src != '\0'; ++src) { + if (*src >= 'a' && *src <= 'z') { + *src = *src - 32; + } + } } -void get_faces(PangoFontFamily *family, int *availfaces){ - PangoFontFace** faces; - PangoFontFace* face; - int i,j,n_faces; - const char* name; - const char *facetypes[] = {FNT_BOLD_ST,FNT_BOOK_ST,FNT_CONDENSED_ST,FNT_DEMI_ST, - FNT_EXTRALIGHT_ST,FNT_ITALIC_ST,FNT_LIGHT_ST, - FNT_MEDIUM_ST,FNT_OBLIQUE_ST,FNT_REGULAR_ST,FNT_ROMAN_ST}; - - const int facevalue[] = {FNT_BOLD,FNT_BOOK,FNT_CONDENSED,FNT_DEMI,FNT_EXTRALIGHT,FNT_ITALIC, - FNT_LIGHT,FNT_MEDIUM,FNT_OBLIQUE,FNT_REGULAR,FNT_ROMAN}; - char *ucName; - *availfaces = 0; - /* Get the faces (Bold, Italic, etc.) for the current font family */ - pango_font_family_list_faces (family, &faces, &n_faces); - for (i = 0; i < n_faces; i++) { - face = faces[i]; - name = pango_font_face_get_face_name (face); - - /* name is const char, so it needs to be copied for upper case conversion */ - ucName = strdup(name); - upperCase(ucName); - /* if the family face type is one of the known types, logically OR the known type value - to the available faces integer */ - for(j=0;jfontname = gv_ps_fontnames[i]; //Graphviz PS font, ie. "AvantGarde" - gv_ps_fontdefs_p[i] = gv_ps_fontdefs; - - /* Load the font definition struct with generic and font equivalences */ - if(strcmp(gv_ps_fontnames[i],PS_AVANTGARDE)==0) { - load_fontdefs(gv_ps_fontdefs, SAN_0, PS_ADVANT_E_SZ,PS_ADVANT_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_BOOKMAN)==0) { - load_fontdefs(gv_ps_fontdefs, SER_0, PS_BOOKMAN_E_SZ,PS_BOOKMAN_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_COURIER)==0) { - load_fontdefs(gv_ps_fontdefs, MON_0, PS_COURIER_E_SZ,PS_COURIER_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_HELVETICA)==0) { - load_fontdefs(gv_ps_fontdefs, SAN_0, PS_HELVETICA_E_SZ,PS_HELVETICA_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_NEWCENTURYSCHLBK)==0) { - load_fontdefs(gv_ps_fontdefs, SER_0, PS_NEWCENT_E_SZ,PS_NEWCENT_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_PALATINO)==0) { - load_fontdefs(gv_ps_fontdefs, SER_0, PS_PALATINO_E_SZ,PS_PALATINO_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_TIMES)==0) { - load_fontdefs(gv_ps_fontdefs, SER_0, PS_TIMES_E_SZ,PS_TIMES_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_SYMBOL)==0) { - load_fontdefs(gv_ps_fontdefs, SYM_0, PS_SYMBOL_E_SZ,PS_SYMBOL_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_CHANCERY)==0) { - load_fontdefs(gv_ps_fontdefs, SER_0, PS_CHANCERY_E_SZ,PS_CHANCERY_E); - } - else if (strcmp(gv_ps_fontnames[i],PS_DINGBATS)==0) { - load_fontdefs(gv_ps_fontdefs, DING_0, PS_DINGBATS_E_SZ,PS_DINGBATS_E); - } - + const char *PS_ADVANT_E[] = + { SAN_1, SAN_2, SAN_3, SAN_4, SAN_5, SAN_6, SAN_7, SAN_8, SAN_9, +SAN_10 }; + const int PS_ADVANT_E_SZ = sizeof(PS_ADVANT_E) / sizeof(char *); + + const char *PS_BOOKMAN_E[] = + { SER_1, SER_2, SER_3, SER_4, SER_5, SER_6, SER_7, SER_8, SER_9 }; + const int PS_BOOKMAN_E_SZ = sizeof(PS_BOOKMAN_E) / sizeof(char *); + + const char *PS_COURIER_E[] = + { MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8 }; + const int PS_COURIER_E_SZ = sizeof(PS_COURIER_E) / sizeof(char *); + + const char *PS_HELVETICA_E[] = + { SAN_3, SAN_11, SAN_4, SAN_6, SAN_7, SAN_8, SAN_9, SAN_10 }; + const int PS_HELVETICA_E_SZ = sizeof(PS_HELVETICA_E) / sizeof(char *); + + const char *PS_NEWCENT_E[] = { SER_10, SER_2, SER_3, SER_4, SER_12, + SER_5, SER_6, SER_7, SER_8, SER_9 + }; + const int PS_NEWCENT_E_SZ = sizeof(PS_NEWCENT_E) / sizeof(char *); + + const char *PS_PALATINO_E[] = + { SER_13, SER_2, SER_3, SER_4, SER_14, SER_15, + SER_5, SER_6, SER_7, SER_8, SER_9 + }; + const int PS_PALATINO_E_SZ = sizeof(PS_PALATINO_E) / sizeof(char *); + + const char *PS_TIMES_E[] = + { SER_4, SER_2, SER_11, SER_5, SER_6, SER_7, SER_8, SER_9 }; + const int PS_TIMES_E_SZ = sizeof(PS_TIMES_E) / sizeof(char *); + + const char *PS_SYMBOL_E[] = { SYM_1, SYM_2, SYM_3, SYM_4 }; + const int PS_SYMBOL_E_SZ = sizeof(PS_SYMBOL_E) / sizeof(char *); + + const char *PS_CHANCERY_E[] = + { SER_16, SER_11, SER_2, SER_3, SER_4, SER_5, + SER_6, SER_7, SER_8, SER_9 + }; + const int PS_CHANCERY_E_SZ = sizeof(PS_CHANCERY_E) / sizeof(char *); + + const char *PS_DINGBATS_E[] = { DING_1, SYM_1, SYM_2, SYM_3, SYM_4 }; + const int PS_DINGBATS_E_SZ = sizeof(PS_DINGBATS_E) / sizeof(char *); + + PangoFontFamily **families; + PangoFontFamily *family; + fontdef_t **gv_ps_fontdefs_p, *gv_ps_fontdefs, gv_ps_fontdef; + int n_families; + int i, j, k, array_sz, availfaces; + availfont_t **gv_af_p, *gv_afs; + const char *name; + char *gv_ps_fontname, *family_name; + char *gv_ps_fontnames[] = { GV_FONT_LIST }; /* array of recognized Graphviz PS font names */ + + gv_ps_fontdefs_p = N_NEW(GV_FONT_LIST_SIZE, fontdef_t *); + for (i = 0; i < GV_FONT_LIST_SIZE; i++) { + gv_ps_fontdefs = N_NEW(1, fontdef_t); + gv_ps_fontdefs->fontname = gv_ps_fontnames[i]; //Graphviz PS font, ie. "AvantGarde" + gv_ps_fontdefs_p[i] = gv_ps_fontdefs; + + /* Load the font definition struct with generic and font equivalences */ + if (strcmp(gv_ps_fontnames[i], PS_AVANTGARDE) == 0) { + load_fontdefs(gv_ps_fontdefs, SAN_0, PS_ADVANT_E_SZ, + PS_ADVANT_E); + } else if (strcmp(gv_ps_fontnames[i], PS_BOOKMAN) == 0) { + load_fontdefs(gv_ps_fontdefs, SER_0, PS_BOOKMAN_E_SZ, + PS_BOOKMAN_E); + } else if (strcmp(gv_ps_fontnames[i], PS_COURIER) == 0) { + load_fontdefs(gv_ps_fontdefs, MON_0, PS_COURIER_E_SZ, + PS_COURIER_E); + } else if (strcmp(gv_ps_fontnames[i], PS_HELVETICA) == 0) { + load_fontdefs(gv_ps_fontdefs, SAN_0, PS_HELVETICA_E_SZ, + PS_HELVETICA_E); + } else if (strcmp(gv_ps_fontnames[i], PS_NEWCENTURYSCHLBK) == 0) { + load_fontdefs(gv_ps_fontdefs, SER_0, PS_NEWCENT_E_SZ, + PS_NEWCENT_E); + } else if (strcmp(gv_ps_fontnames[i], PS_PALATINO) == 0) { + load_fontdefs(gv_ps_fontdefs, SER_0, PS_PALATINO_E_SZ, + PS_PALATINO_E); + } else if (strcmp(gv_ps_fontnames[i], PS_TIMES) == 0) { + load_fontdefs(gv_ps_fontdefs, SER_0, PS_TIMES_E_SZ, + PS_TIMES_E); + } else if (strcmp(gv_ps_fontnames[i], PS_SYMBOL) == 0) { + load_fontdefs(gv_ps_fontdefs, SYM_0, PS_SYMBOL_E_SZ, + PS_SYMBOL_E); + } else if (strcmp(gv_ps_fontnames[i], PS_CHANCERY) == 0) { + load_fontdefs(gv_ps_fontdefs, SER_0, PS_CHANCERY_E_SZ, + PS_CHANCERY_E); + } else if (strcmp(gv_ps_fontnames[i], PS_DINGBATS) == 0) { + load_fontdefs(gv_ps_fontdefs, DING_0, PS_DINGBATS_E_SZ, + PS_DINGBATS_E); } - /* Get a list of font families installed on the system */ - pango_font_map_list_families (fontmap, &families, &n_families); - - /* Setup a pointer to available font structs */ - gv_af_p = N_NEW(GV_FONT_LIST_SIZE,availfont_t*); - - for(j=0;jfontname = NULL; - gv_afs->gv_ps_fontname = gv_ps_fontname; - gv_afs->faces = 0; - } - else{ - gv_afs->fontname = family_name; - gv_afs->gv_ps_fontname = gv_ps_fontname; - gv_afs->faces = availfaces; + if (!(family_name == '\0')) + break; + } + } + /* if a match is not found on the equivalent font family names, search + for a match on the generic family name assigned to the Graphviz PS font */ + if (family_name == '\0') { + for (i = 0; i < n_families; i++) { + family = families[i]; + name = pango_font_family_get_name(family); + if (strcasecmp(gv_ps_fontdef.generic_name, name) == 0) { + family_name = strdup(name); + get_faces(family, &availfaces); + break; } + } } -g_free(families); -//display_available_fonts(gv_ps_fontdefs_p,gv_af_p); + /* if not match is found on the generic name, set the available font + name to NULL */ + if (family_name == '\0') { + gv_afs->fontname = NULL; + gv_afs->gv_ps_fontname = gv_ps_fontname; + gv_afs->faces = 0; + } else { + gv_afs->fontname = family_name; + gv_afs->gv_ps_fontname = gv_ps_fontname; + gv_afs->faces = availfaces; + } + } + g_free(families); +// display_available_fonts(gv_ps_fontdefs_p, gv_af_p); /* Free the Graphviz PS font definitions */ -gv_flist_free_ps(gv_ps_fontdefs_p); -return(gv_af_p); + gv_flist_free_ps(gv_ps_fontdefs_p); + return (gv_af_p); } /* Returns the font corresponding to a Graphviz PS font. AvantGarde-Book may return URW Gothic L, book */ -char* gv_get_font(char *buf, availfont_t **gv_af_p, PostscriptAlias *ps_alias){ -char ps_param[MAX_FACE_SIZE]; -char *avail_faces; -int i; - -buf[0]='\0'; -for(i=0;ixfig_code].gv_ps_fontname,ps_alias->name); - buf[0]='\0'; + strcpy(gv_fmap[ps_alias->xfig_code].gv_ps_fontname, + ps_alias->name); + buf[0] = '\0'; gv_get_font(buf, gv_af_p, ps_alias); - strcpy(gv_fmap[ps_alias->xfig_code].gv_font,buf); -} -gv_flist_free_af(gv_af_p); + strcpy(gv_fmap[ps_alias->xfig_code].gv_font, buf); + } + gv_flist_free_af(gv_af_p); } diff --git a/plugin/pango/gvtextlayout_pango.c b/plugin/pango/gvtextlayout_pango.c index 618029df1..d3267895f 100644 --- a/plugin/pango/gvtextlayout_pango.c +++ b/plugin/pango/gvtextlayout_pango.c @@ -104,7 +104,7 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath) if (para->postscript_alias) { psfnt = fnt = gv_fmap[para->postscript_alias->xfig_code].gv_font; - if(psfnt == NULL) + if(!psfnt || (*psfnt == '\0')) psfnt = fnt = pango_psfontResolve (para->postscript_alias); } else