GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <string.h> 00003 00004 #include <grass/gis.h> 00005 #include "driver.h" 00006 #include "driverlib.h" 00007 00008 static int font_type = GFONT_STROKE; 00009 00010 static void stroke_set(const char *filename) 00011 { 00012 if (font_init(filename) == 0) 00013 font_type = GFONT_STROKE; 00014 } 00015 00016 static void freetype_set(const char *filename, int index) 00017 { 00018 if (font_init_freetype(filename, index) == 0) 00019 font_type = GFONT_FREETYPE; 00020 } 00021 00022 void COM_Font_get(const char *name) 00023 { 00024 if (G_is_absolute_path(name)) { 00025 if (!font_exists(name)) 00026 return; 00027 00028 freetype_set(name, 0); 00029 } 00030 else { 00031 int i; 00032 00033 /* check if freetype font is available in freetypecap */ 00034 for (i = 0; ftcap[i].name; i++) 00035 if (strcmp(name, ftcap[i].name) == 0) { 00036 switch (ftcap[i].type) { 00037 case GFONT_FREETYPE: 00038 freetype_set(ftcap[i].path, ftcap[i].index); 00039 font_init_charset(ftcap[i].encoding); 00040 break; 00041 case GFONT_STROKE: 00042 stroke_set(ftcap[i].name); 00043 break; 00044 } 00045 return; 00046 } 00047 00048 stroke_set("romans"); 00049 } 00050 } 00051 00052 void COM_Font_init_charset(const char *charset) 00053 { 00054 font_init_charset(charset); 00055 } 00056 00057 int font_is_freetype(void) 00058 { 00059 return font_type == GFONT_FREETYPE; 00060 } 00061 00062 static void font_list(char ***list, int *count, int verbose) 00063 { 00064 char **fonts; 00065 int num_fonts; 00066 int i; 00067 00068 for (i = 0; ftcap[i].name; i++) ; 00069 00070 num_fonts = i; 00071 00072 fonts = G_malloc(num_fonts * sizeof(const char *)); 00073 00074 for (i = 0; i < num_fonts; i++) { 00075 struct GFONT_CAP *p = &ftcap[i]; 00076 00077 if (verbose) { 00078 char buf[GPATH_MAX]; 00079 00080 sprintf(buf, "%s|%s|%d|%s|%d|%s|", 00081 p->name, p->longname, p->type, 00082 p->path, p->index, p->encoding); 00083 00084 fonts[i] = G_store(buf); 00085 } 00086 else 00087 fonts[i] = G_store(p->name); 00088 } 00089 00090 *list = fonts; 00091 *count = num_fonts; 00092 } 00093 00094 void COM_Font_list(char ***list, int *count) 00095 { 00096 font_list(list, count, 0); 00097 } 00098 00099 void COM_Font_info(char ***list, int *count) 00100 { 00101 font_list(list, count, 1); 00102 } 00103 00104 void free_font_list(char **fonts, int count) 00105 { 00106 int i; 00107 00108 for (i = 0; i < count; i++) 00109 G_free(fonts[i]); 00110 G_free(fonts); 00111 }