2
\file lib/driver/parse_ftcap.c
4
\brief Display Driver - fontcaps
6
(C) 2006-2011 by the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Glynn Clements <glynn gclements.plus.com> (original contributor)
12
\author Huidae Cho <grass4u gmail.com>
4
19
#include <grass/gis.h>
5
20
#include <grass/glocale.h>
6
#include <grass/freetypecap.h>
21
#include <grass/fontcap.h>
7
22
#include "driverlib.h"
25
\brief Check if font exists
9
27
int font_exists(const char *name)
13
fp = fopen(name, "r");
29
return access(name, R_OK) >= 0;
33
\brief Parse fontcap entry
35
\param e pointer to GFONT_CAP struct
41
int parse_fontcap_entry(struct GFONT_CAP *e, const char *str)
43
char name[GNAME_MAX], longname[GNAME_MAX], path[GPATH_MAX], encoding[128];
46
if (sscanf(str, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
47
name, longname, &type, path, &index, encoding) == 6) {
48
if (!font_exists(path))
51
/* GFONT_DRIVER type fonts do not have path. */
52
else if (sscanf(str, "%[^|]|%[^|]|%d||%d|%[^|]|",
53
name, longname, &type, &index, encoding) == 5)
58
e->name = G_store(name);
59
e->longname = G_store(longname);
61
e->path = G_store(path);
63
e->encoding = G_store(encoding);
21
struct GFONT_CAP *parse_freetypecap(void)
71
\return pointer to GFONT_CAP structure
73
struct GFONT_CAP *parse_fontcap(void)
23
75
char *capfile, file[GPATH_MAX];
24
76
char buf[GPATH_MAX];
42
94
while (fgets(buf, sizeof(buf), fp) && !feof(fp)) {
43
char name[GNAME_MAX], longname[GNAME_MAX],
44
path[GPATH_MAX], encoding[128];
48
98
p = strchr(buf, '#');
52
if (sscanf(buf, "%[^|]|%[^|]|%d|%[^|]|%d|%[^|]|",
53
name, longname, &type, path, &index, encoding)
57
if (!font_exists(path))
60
fonts = (struct GFONT_CAP *)G_realloc(fonts,
63
sizeof(struct GFONT_CAP));
65
fonts[fonts_count].name = G_store(name);
66
fonts[fonts_count].longname = G_store(longname);
67
fonts[fonts_count].type = type;
68
fonts[fonts_count].path = G_store(path);
69
fonts[fonts_count].index = index;
70
fonts[fonts_count].encoding = G_store(encoding);
102
if (!parse_fontcap_entry(&cap, buf))
105
fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
106
fonts[fonts_count++] = cap;
77
fonts = (struct GFONT_CAP *)G_realloc(fonts, (fonts_count + 1) *
78
sizeof(struct GFONT_CAP));
112
fonts = G_realloc(fonts, (fonts_count + 1) * sizeof(struct GFONT_CAP));
79
113
fonts[fonts_count].name = NULL;
80
114
fonts[fonts_count].path = NULL;
85
void free_freetypecap(struct GFONT_CAP *ftcap)
120
\brief Free allocated GFONT_CAP structure
122
\param ftcap pointer to GFONT_CAP to be freed
124
void free_fontcap(struct GFONT_CAP *ftcap)