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 i, 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         snprintf(buf, 
sizeof(buf), 
"%s/fonts/hersh.oc%d", 
G_gisbase(), i);
 
  137 static void read_fontmap(
const char *
name)
 
  143     memset(fontmap, 0, 
sizeof(fontmap));
 
  145     snprintf(buf, 
sizeof(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 --overwrite'",
 
  151                   buf, strerror(errno));
 
  155     while (fscanf(fp, 
"%s", buf) == 1) {
 
  158         if (sscanf(buf, 
"%d-%d", &a, &
b) == 2)
 
  160                 fontmap[num_chars++] = a++;
 
  161         else if (sscanf(buf, 
"%d", &a) == 1)
 
  162             fontmap[num_chars++] = a;
 
  168 static void load_font(
void)
 
  176     read_fontmap(current_font);
 
  183     if (strcmp(
name, current_font) == 0)
 
  187         sizeof(current_font)) {
 
  204     i = (int)achar - 040; 
 
  205     if (i <= 0 || i >= num_chars) {
 
  210     glyph = &glyphs[fontmap[i]];
 
  213     *
X = &xcoords[glyph->offset];
 
  214     *
Y = &ycoords[glyph->offset];
 
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
const char * G_gisbase(void)
Get full path name of the top level module directory.
size_t G_strlcpy(char *, const char *, size_t)
Safe string copy function.
Header file for msvc/fcntl.c.
int get_char_vects(unsigned char achar, int *n, unsigned char **X, unsigned char **Y)
int font_init(const char *name)