2
* from lib/driver/parse_ftcap.c
3
* These functions are copied from the diplay driver lib,
4
* so that we don't need to have an active display driver open,
11
#include <grass/gis.h>
12
#include <grass/glocale.h>
13
#include <grass/freetypecap.h>
16
static int font_exists(const char *name);
18
static int font_exists(const char *name)
22
fp = fopen(name, "r");
30
void free_freetypecap(struct GFONT_CAP *ftcap)
35
G_free(ftcap->longname);
37
G_free(ftcap->encoding);
43
struct GFONT_CAP *find_font_from_freetypecap(const char *font)
45
char *capfile, file[GPATH_MAX];
49
struct GFONT_CAP *font_cap = NULL;
52
if ((capfile = getenv("GRASS_FONT_CAP"))) {
53
if ((fp = fopen(capfile, "r")) == NULL)
55
("%s: Unable to read font definition file; use the default"),
59
sprintf(file, "%s/etc/fontcap", G_gisbase());
60
if ((fp = fopen(file, "r")) == NULL)
61
G_warning(_("%s: No font definition file"), file);
65
while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
66
char name[GNAME_MAX], longname[GNAME_MAX],
67
path[GPATH_MAX], encoding[128];
75
if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
76
name, longname, &type, path, &index, encoding)
79
if (strcmp(name, font) != 0 && strcmp(longname, font) != 0)
81
if (!font_exists(path))
84
font_cap = (struct GFONT_CAP *)G_malloc(sizeof(struct GFONT_CAP));
86
font_cap[fonts_count].name = G_store(name);
87
font_cap[fonts_count].longname = G_store(longname);
88
font_cap[fonts_count].type = type;
89
font_cap[fonts_count].path = G_store(path);
90
font_cap[fonts_count].index = index;
91
font_cap[fonts_count].encoding = G_store(encoding);