From f44b1a4a14e61e4ecc266d72d06fe3b97997350c Mon Sep 17 00:00:00 2001 From: dperry Date: Tue, 22 Feb 2011 05:29:43 +0000 Subject: [PATCH] Code to support selection of pango PS fonts from equivalent installed fonts. --- plugin/pango/gvgetfontlist.h | 125 ++++++++ plugin/pango/gvgetfontlist_pango.c | 464 +++++++++++++++++++++++++++++ 2 files changed, 589 insertions(+) create mode 100644 plugin/pango/gvgetfontlist.h create mode 100644 plugin/pango/gvgetfontlist_pango.c diff --git a/plugin/pango/gvgetfontlist.h b/plugin/pango/gvgetfontlist.h new file mode 100644 index 000000000..acded54cb --- /dev/null +++ b/plugin/pango/gvgetfontlist.h @@ -0,0 +1,125 @@ + +#define GV_FONT_LIST PS_AVANTGARDE,PS_BOOKMAN,PS_COURIER,PS_HELVETICA, PS_NEWCENTURYSCHLBK,PS_PALATINO,PS_SYMBOL,PS_TIMES,PS_CHANCERY,PS_DINGBATS +#define GV_FONT_LIST_SIZE 10 +#define MAX_FACE_SIZE 12 +#define MAX_GV_PS_FONTS 35 +#define FONT_FACE_NUM 11 + +#define PS_AVANTGARDE "AvantGarde" +#define PS_BOOKMAN "Bookman" +#define PS_COURIER "Courier" +#define PS_HELVETICA SAN_5 +#define PS_NEWCENTURYSCHLBK "NewCenturySchlbk" +#define PS_PALATINO "Palatino" +#define PS_SYMBOL "Symbol" +#define PS_TIMES SER_3 +#define PS_CHANCERY "ZapfChancery" +#define PS_DINGBATS "ZapfDingbats" + +#define FNT_BOLD 1 +#define FNT_BOOK 1<<2 +#define FNT_CONDENSED 1<<3 +#define FNT_DEMI 1<<4 +#define FNT_EXTRALIGHT 1<<5 +#define FNT_ITALIC 1<<6 +#define FNT_LIGHT 1<<7 +#define FNT_MEDIUM 1<<8 +#define FNT_OBLIQUE 1<<9 +#define FNT_REGULAR 1<<10 +#define FNT_ROMAN 1<<10 + +#define FNT_BOLD_ST "BOLD" +#define FNT_BOOK_ST "BOOK" +#define FNT_CONDENSED_ST "CONDENSED" +#define FNT_DEMI_ST "DEMI" +#define FNT_EXTRALIGHT_ST "EXTRALIGHT" +#define FNT_ITALIC_ST "ITALIC" +#define FNT_LIGHT_ST "LIGHT" +#define FNT_MEDIUM_ST "MEDIUM" +#define FNT_OBLIQUE_ST "OBLIQUE" +#define FNT_REGULAR_ST "REGULAR" +#define FNT_ROMAN_ST "ROMAN" + +#define SAN_0 "sans" +#define SAN_1 "URW Gothic L" +#define SAN_2 "Charcoal" +#define SAN_3 "Nimbus Sans L" +#define SAN_4 "Verdana" +#define SAN_5 "Helvetica" +#define SAN_6 "Bitstream Vera Sans" +#define SAN_7 "DejaVu Sans" +#define SAN_8 "Liberation Sans" +#define SAN_9 "Luxi Sans" +#define SAN_10 "FreeSans" +#define SAN_11 "Arial" + +#define SER_0 "serif" +#define SER_1 "URW Bookman L" +#define SER_2 "Times New Roman" +#define SER_3 "Times" +#define SER_4 "Nimbus Roman No9 L" +#define SER_5 "Bitstream Vera Serif" +#define SER_6 "DejaVu Serif" +#define SER_7 "Liberation Serif" +#define SER_8 "Luxi Serif" +#define SER_9 "FreeSerif" +#define SER_10 "Century Schoolbook L" +#define SER_11 "Charcoal" +#define SER_12 "Georgia" +#define SER_13 "URW Palladio L" +#define SER_14 "Norasi" +#define SER_15 "Rekha" +#define SER_16 "URW Chancery L" + +#define MON_0 "monospace" +#define MON_1 "Nimbus Mono L" +#define MON_2 "Inconsolata" +#define MON_3 "Courier New" +#define MON_4 "Bitstream Vera Sans Mono" +#define MON_5 "DejaVu Sans Mono" +#define MON_6 "Liberation Mono" +#define MON_7 "Luxi Mono" +#define MON_8 "FreeMono" + +#define SYM_0 "fantasy" +#define SYM_1 "Impact" +#define SYM_2 "Copperplate Gothic Std" +#define SYM_3 "Cooper Std" +#define SYM_4 "Bauhaus Std" + +#define DING_0 "fantasy" +#define DING_1 "Dingbats" +#define DING_2 "Impact" +#define DING_3 "Copperplate Gothic Std" +#define DING_4 "Cooper Std" +#define DING_5 "Bauhaus Std" + +#define MAX_FONTNAME 100 +#define MAX_FONTSZ 512 + + + +typedef struct { + char* generic_name; + char* fontname; + char** equiv; + int eq_sz; +} fontdef_t; + +typedef struct { + char * gv_ps_fontname; + char * fontname; + int faces; +} availfont_t; + +typedef struct { + char gv_ps_fontname[MAX_FONTNAME]; + char gv_font[MAX_FONTSZ]; +}gv_font_map; + +void get_font_mapping(PangoFontMap *pfm, gv_font_map *gfm); + + + + + diff --git a/plugin/pango/gvgetfontlist_pango.c b/plugin/pango/gvgetfontlist_pango.c new file mode 100644 index 000000000..c076a6e1b --- /dev/null +++ b/plugin/pango/gvgetfontlist_pango.c @@ -0,0 +1,464 @@ +#define HAVE_PANGOCAIRO +#include +#include + +#include "gvplugin_textlayout.h" +#ifdef HAVE_PANGOCAIRO +#include +#include "gvgetfontlist.h" +#endif + +#define N_NEW(n,t) (t*)malloc((n)*sizeof(t)) + +static PostscriptAlias postscript_alias[] = { +#include "ps_font_equiv.h" +}; + +/* Frees memory used by the Graphviz PS font definitions */ +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]); + 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 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); + } + + } + + /* 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; + } + } +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); +} + +/* 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'; + 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); +} -- 2.40.0