13 unsigned int offset:20;
14 unsigned int count:12;
17 static struct glyph *glyphs;
18 static int glyphs_alloc;
20 static unsigned char *xcoords, *ycoords;
21 static int coords_offset;
22 static int coords_alloc;
24 static int fontmap[1024];
27 static char current_font[16];
28 static int font_loaded;
30 static struct glyph *glyph_slot(
int idx)
32 if (glyphs_alloc <= idx) {
33 int new_alloc = idx + ((glyphs_alloc > 0) ? 1000 : 4000);
35 glyphs =
G_realloc(glyphs, new_alloc *
sizeof(
struct glyph));
36 memset(&glyphs[glyphs_alloc], 0,
37 (new_alloc - glyphs_alloc) *
sizeof(
struct glyph));
38 glyphs_alloc = new_alloc;
44 static int coord_slots(
int count)
48 if (coords_alloc < coords_offset + count) {
50 coords_offset + count + ((coords_alloc > 0) ? 10000 : 60000);
51 xcoords =
G_realloc(xcoords, coords_alloc);
52 ycoords =
G_realloc(ycoords, coords_alloc);
56 coords_offset +=
count;
61 static void read_hersh(
const char *filename)
63 FILE *fp = fopen(filename,
"r");
72 unsigned int idx,
count;
75 switch (c = fgetc(fp)) {
86 if (fread(buf, 1, 5, fp) != 5)
92 if (fread(buf, 1, 3, fp) != 3)
98 glyph = glyph_slot(idx);
99 coords = coord_slots(count);
101 glyph->offset = coords;
102 glyph->count =
count;
104 for (i = 0; i <
count; i++) {
105 if ((i + 4) % 36 == 0) {
107 if (fgetc(fp) ==
'\r')
111 xcoords[coords + i] = fgetc(fp);
112 ycoords[coords + i] = fgetc(fp);
115 if (fgetc(fp) ==
'\r')
122 static void load_glyphs(
void)
129 for (i = 1; i <= 4; i++) {
132 sprintf(buf,
"%s/fonts/hersh.oc%d",
G_gisbase(), i);
137 static void read_fontmap(
const char *
name)
143 memset(fontmap, 0,
sizeof(fontmap));
145 sprintf(buf,
"%s/fonts/%s.hmp",
G_gisbase(), name);
147 fp = fopen(buf,
"r");
149 G_warning(
"Unable to open font map '%s': %s. " 150 "Try running 'g.mkfontcap -o'", 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)
185 strcpy(current_font, name);
192 int *n,
unsigned char **
X,
unsigned char **
Y)
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];
int font_init(const char *name)
int get_char_vects(unsigned char achar, int *n, unsigned char **X, unsigned char **Y)
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_warning(const char *,...) __attribute__((format(printf