12 unsigned int offset : 20;
13 unsigned int count : 12;
16 static struct glyph *glyphs;
17 static int glyphs_alloc;
19 static unsigned char *xcoords, *ycoords;
20 static int coords_offset;
21 static int coords_alloc;
23 static int fontmap[1024];
26 static char current_font[16];
27 static int font_loaded;
29 static struct glyph *glyph_slot(
int idx)
31 if (glyphs_alloc <= idx) {
32 int new_alloc = idx + ((glyphs_alloc > 0) ? 1000 : 4000);
34 glyphs =
G_realloc(glyphs, new_alloc *
sizeof(
struct glyph));
35 memset(&glyphs[glyphs_alloc], 0,
36 (new_alloc - glyphs_alloc) *
sizeof(
struct glyph));
37 glyphs_alloc = new_alloc;
43 static int coord_slots(
int count)
47 if (coords_alloc < coords_offset +
count) {
49 coords_offset +
count + ((coords_alloc > 0) ? 10000 : 60000);
50 xcoords =
G_realloc(xcoords, coords_alloc);
51 ycoords =
G_realloc(ycoords, coords_alloc);
55 coords_offset +=
count;
60 static void read_hersh(
const char *filename)
62 FILE *fp = fopen(filename,
"r");
71 unsigned int i, idx,
count;
74 switch (c = fgetc(fp)) {
85 if (fread(buf, 1, 5, fp) != 5)
91 if (fread(buf, 1, 3, fp) != 3)
97 glyph = glyph_slot(idx);
98 coords = coord_slots(
count);
100 glyph->offset = coords;
101 glyph->count =
count;
103 for (i = 0; i <
count; i++) {
104 if ((i + 4) % 36 == 0) {
106 if (fgetc(fp) ==
'\r')
110 xcoords[coords + i] = fgetc(fp);
111 ycoords[coords + i] = fgetc(fp);
114 if (fgetc(fp) ==
'\r')
121 static void load_glyphs(
void)
128 for (i = 1; i <= 4; i++) {
131 sprintf(buf,
"%s/fonts/hersh.oc%d",
G_gisbase(), i);
136 static void read_fontmap(
const char *
name)
142 memset(fontmap, 0,
sizeof(fontmap));
146 fp = fopen(buf,
"r");
148 G_warning(
"Unable to open font map '%s': %s. "
149 "Try running 'g.mkfontcap --overwrite'",
150 buf, strerror(errno));
154 while (fscanf(fp,
"%s", buf) == 1) {
157 if (sscanf(buf,
"%d-%d", &a, &
b) == 2)
159 fontmap[num_chars++] = a++;
160 else if (sscanf(buf,
"%d", &a) == 1)
161 fontmap[num_chars++] = a;
167 static void load_font(
void)
175 read_fontmap(current_font);
182 if (strcmp(
name, current_font) == 0)
200 i = (int)achar - 040;
201 if (i <= 0 || i >= num_chars) {
206 glyph = &glyphs[fontmap[i]];
209 *
X = &xcoords[glyph->offset];
210 *
Y = &ycoords[glyph->offset];
void G_warning(const char *,...) __attribute__((format(printf
const char * G_gisbase(void)
Get full path name of the top level module directory.
int get_char_vects(unsigned char achar, int *n, unsigned char **X, unsigned char **Y)
int font_init(const char *name)