GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Font.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 
4 #include <grass/gis.h>
5 #include "driver.h"
6 #include "driverlib.h"
7 
8 static int font_type = GFONT_STROKE;
9 
10 static void stroke_set(const char *filename)
11 {
12  if (font_init(filename) == 0)
13  font_type = GFONT_STROKE;
14 }
15 
16 static void freetype_set(const char *filename, int index)
17 {
18  if (font_init_freetype(filename, index) == 0)
19  font_type = GFONT_FREETYPE;
20 }
21 
22 void COM_Font_get(const char *name)
23 {
24  if (G_is_absolute_path(name)) {
25  if (!font_exists(name))
26  return;
27 
28  freetype_set(name, 0);
29  }
30  else {
31  int i;
32 
33  /* check if freetype font is available in freetypecap */
34  for (i = 0; ftcap[i].name; i++)
35  if (strcmp(name, ftcap[i].name) == 0) {
36  switch (ftcap[i].type) {
37  case GFONT_FREETYPE:
38  freetype_set(ftcap[i].path, ftcap[i].index);
39  font_init_charset(ftcap[i].encoding);
40  break;
41  case GFONT_STROKE:
42  stroke_set(ftcap[i].name);
43  break;
44  }
45  return;
46  }
47 
48  stroke_set("romans");
49  }
50 }
51 
52 void COM_Font_init_charset(const char *charset)
53 {
54  font_init_charset(charset);
55 }
56 
58 {
59  return font_type == GFONT_FREETYPE;
60 }
61 
62 static void font_list(char ***list, int *count, int verbose)
63 {
64  char **fonts;
65  int num_fonts;
66  int i;
67 
68  for (i = 0; ftcap[i].name; i++) ;
69 
70  num_fonts = i;
71 
72  fonts = G_malloc(num_fonts * sizeof(const char *));
73 
74  for (i = 0; i < num_fonts; i++) {
75  struct GFONT_CAP *p = &ftcap[i];
76 
77  if (verbose) {
78  char buf[GPATH_MAX];
79 
80  sprintf(buf, "%s|%s|%d|%s|%d|%s|",
81  p->name, p->longname, p->type,
82  p->path, p->index, p->encoding);
83 
84  fonts[i] = G_store(buf);
85  }
86  else
87  fonts[i] = G_store(p->name);
88  }
89 
90  *list = fonts;
91  *count = num_fonts;
92 }
93 
94 void COM_Font_list(char ***list, int *count)
95 {
96  font_list(list, count, 0);
97 }
98 
99 void COM_Font_info(char ***list, int *count)
100 {
101  font_list(list, count, 1);
102 }
103 
104 void free_font_list(char **fonts, int count)
105 {
106  int i;
107 
108  for (i = 0; i < count; i++)
109  G_free(fonts[i]);
110  G_free(fonts);
111 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
string name
Definition: render.py:1314
int font_init(const char *)
Definition: font2.c:180
int count
struct GFONT_CAP * ftcap
Definition: driver/init.c:28
void COM_Font_init_charset(const char *)
Definition: Font.c:52
int font_init_freetype(const char *, int)
Definition: font_freetype.c:10
void COM_Font_list(char ***, int *)
Definition: Font.c:94
void free_font_list(char **fonts, int num_fonts)
Definition: Font.c:104
void COM_Font_info(char ***, int *)
Definition: Font.c:99
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int G_is_absolute_path(const char *path)
Checks if a specified path looks like an absolute path on the host system.
Definition: paths.c:52
int font_is_freetype(void)
Definition: Font.c:57
int font_exists(const char *name)
Definition: parse_ftcap.c:9
void COM_Font_get(const char *)
Definition: Font.c:22
int font_init_charset(const char *)
Definition: font_freetype.c:21