Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions
agl.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  agl_name

Defines

#define AGL_DEFAULT_LISTFILE   "glyphlist.txt"
#define AGL_PREDEF_LISTFILE   "pdfglyphlist.txt"
#define AGL_EXTRA_LISTFILE   "texglyphlist.txt"
#define AGL_MAX_UNICODES   16

Typedefs

typedef struct agl_name

Functions

char * agl_chop_suffix (const char *glyphname, char **suffix)
long agl_sput_UTF16BE (const char *name, unsigned char **dstpp, unsigned char *limptr, int *num_fails)
int agl_get_unicodes (const char *glyphstr, long *unicodes, int max_uncodes)
int agl_name_is_unicode (const char *glyphname)
long agl_name_convert_unicode (const char *glyphname)
const char * agl_suffix_to_otltag (const char *suffix)
agl_nameagl_lookup_list (const char *glyphname)
int agl_load_listfile (const char *filename, int format)
void agl_set_verbose (void)
void agl_init_map (void)
void agl_close_map (void)

Class Documentation

struct agl_name

Definition at line 33 of file agl.h.

Collaboration diagram for agl_name:
Class Members
struct agl_name * alternate
int is_predef
int n_components
char * name
char * suffix
long unicodes

Define Documentation

#define AGL_DEFAULT_LISTFILE   "glyphlist.txt"

Definition at line 28 of file agl.h.

#define AGL_EXTRA_LISTFILE   "texglyphlist.txt"

Definition at line 30 of file agl.h.

#define AGL_MAX_UNICODES   16

Definition at line 32 of file agl.h.

#define AGL_PREDEF_LISTFILE   "pdfglyphlist.txt"

Definition at line 29 of file agl.h.


Typedef Documentation

typedef struct agl_name

Definition at line 41 of file agl.h.


Function Documentation

char* agl_chop_suffix ( const char *  glyphname,
char **  suffix 
)

Definition at line 96 of file agl.c.

{
  char  *name, *p;
  int    len;

  ASSERT(glyphname && suffix);

  p = strchr(glyphname, '.');
  if (p) {
    len = strlen(glyphname) - strlen(p);
    if (len < 1) {
      name = NULL;
      *suffix = NEW(strlen(glyphname), char);
      strcpy(*suffix, glyphname+1);
    } else {
      p++;
      name = NEW(len + 1, char);
      strncpy(name, glyphname, len);
      name[len] = '\0';
      if (p[0] == '\0') {
       *suffix = NULL;
      } else {
       *suffix = NEW(strlen(p) + 1, char);
       strcpy(*suffix, p);
      }
    }
  } else {
    name = NEW(strlen(glyphname) + 1, char);
    strcpy(name, glyphname);
    *suffix = NULL;
  }

  return name;
}

Here is the caller graph for this function:

void agl_close_map ( void  )

Definition at line 387 of file agl.c.

{
  ht_clear_table(&aglmap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int agl_get_unicodes ( const char *  glyphstr,
long *  unicodes,
int  max_uncodes 
)

Definition at line 735 of file agl.c.

{
  int   count = 0;
  char *p, *endptr;

  p      = (char *) glyphstr;
  endptr = strchr(p, '.');
  if (!endptr)
    endptr = p + strlen(p);

  while (p < endptr) {
    char     *name, *delim;
    long      sub_len;
    int       i;
    agl_name *agln0, *agln1 = NULL;

    delim = strchr(p, '_');
    if (delim == p) {
      /*
       * Glyph names starting with a underscore or two subsequent
       * underscore in glyph name not allowed?
       */
      WARN("Invalid glyph name component in \"%s\".", glyphstr);
      return -1; /* Cannot continue */
    } else if (!delim || delim > endptr) {
      delim = endptr;
    }
    sub_len = (long) (delim - p);

    name = NEW(sub_len+1, char);
    memcpy(name, p, sub_len);
    name[sub_len] = '\0';

    if (agl_name_is_unicode(name)) {
      p  = name;
      if (p[1] != 'n') { /* uXXXXXXXX */
       if (count >= max_unicodes) {
         RELEASE(name);
         return -1;
       }
       p++;
       unicodes[count++] = xtol(p, strlen(p));
      } else {
       p += 3;
       while (*p != '\0') {
         if (count >= max_unicodes) {
           RELEASE(name);
           return -1;
         }
         unicodes[count++] = xtol(p, 4);
         p += 4;
       }
      }
    } else {
      agln1 = agl_lookup_list(name);
      if (!agln1 || (agln1->n_components == 1 &&
                   IS_PUA(agln1->unicodes[0]))) {
       agln0 = agl_normalized_name(name);
       if (agln0) {
         if (verbose > 1 && agln0->suffix) {
           WARN("agl: fix %s --> %s.%s",
               name, agln0->name, agln0->suffix);
         }
         agln1 = agl_lookup_list(agln0->name);
         agl_release_name(agln0);
       }
      }
      if (agln1) {
       if (count + agln1->n_components > max_unicodes) {
         RELEASE(name);
         return -1;
       }
       for (i = 0; i < agln1->n_components; i++) {
         unicodes[count++] = agln1->unicodes[i];
       }
      } else {
       if (verbose > 1)
         WARN("No Unicode mapping for glyph name \"%s\" found.", name);
       RELEASE(name);
       return -1;
      }
    }
    RELEASE(name);
    p = delim + 1;
  }

  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void agl_init_map ( void  )

Definition at line 374 of file agl.c.

{
  ht_init_table(&aglmap, hval_free);
  agl_load_listfile(AGL_EXTRA_LISTFILE, 0);
  if (agl_load_listfile(AGL_PREDEF_LISTFILE, 1) < 0) {
    WARN("Failed to load AGL file \"%s\"...", AGL_PREDEF_LISTFILE);
  }
  if (agl_load_listfile(AGL_DEFAULT_LISTFILE, 0) < 0) {
    WARN("Failed to load AGL file \"%s\"...", AGL_DEFAULT_LISTFILE);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int agl_load_listfile ( const char *  filename,
int  format 
)

Definition at line 395 of file agl.c.

{
  int   count = 0;
  char *p, *endptr, *nextptr;
  char  wbuf[WBUF_SIZE];
  FILE *fp;

  if (!filename)
    return  -1;

  fp = DPXFOPEN(filename, DPX_RES_TYPE_AGL);
  if (!fp) {
    return -1;
  }

  if (verbose)
    MESG("<AGL:%s", filename);

  while ((p = mfgets(wbuf, WBUF_SIZE, fp)) != NULL) {
    agl_name *agln, *duplicate;
    char     *name;
    int       n_unicodes, i;
    long      unicodes[AGL_MAX_UNICODES];

    endptr = p + strlen(p);
    skip_white(&p, endptr);

    /* Need table version check. */
    if (!p || p[0] == '#' || p >= endptr)
      continue;
    nextptr = strchr(p, ';');
    if (!nextptr || nextptr == p)
      continue;

    name = parse_ident(&p, nextptr);

    skip_white(&p, endptr);
    if (!name || p[0] != ';') {
      WARN("Invalid AGL entry: %s", wbuf);
      if (name)
        RELEASE(name);
      continue;
    }

    p++;
    skip_white(&p, endptr);

    n_unicodes = 0;
    while (p < endptr &&
           ((p[0]  >= '0' && p[0] <= '9') ||
            (p[0]  >= 'A' && p[0] <= 'F'))
          ) {

      if (n_unicodes >= AGL_MAX_UNICODES) {
        WARN("Too many Unicode values");
        break;
      }
      unicodes[n_unicodes++] = strtol(p, &nextptr, 16);

      p = nextptr;
      skip_white(&p, endptr);
    }

    if (n_unicodes == 0) {
      WARN("AGL entry ignored (no mapping): %s", wbuf);
      RELEASE(name);
      continue;
    }

    agln = agl_normalized_name(name);
    agln->is_predef = is_predef;
    agln->n_components = n_unicodes;
    for (i = 0; i < n_unicodes; i++) {
      agln->unicodes[i] = unicodes[i];
    }

    duplicate = ht_lookup_table(&aglmap, name, strlen(name));
    if (!duplicate)
      ht_append_table(&aglmap, name, strlen(name), agln);
    else {
      while (duplicate->alternate)
        duplicate = duplicate->alternate;
      duplicate->alternate = agln;
    }

    if (verbose > 3) {
      if (agln->suffix)
        MESG("agl: %s [%s.%s] -->", name, agln->name, agln->suffix);
      else
        MESG("agl: %s [%s] -->", name, agln->name);
      for (i = 0; i < agln->n_components; i++) {
        if (agln->unicodes[i] > 0xffff) {
          MESG(" U+%06X", agln->unicodes[i]);
        } else {
          MESG(" U+%04X", agln->unicodes[i]);
        }
      }
      MESG("\n");
    }

    RELEASE(name);
    count++;
  }
  DPXFCLOSE(fp);

  if (verbose)
    MESG(">");

  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

agl_name* agl_lookup_list ( const char *  glyphname)

Definition at line 507 of file agl.c.

{
  agl_name *agln;

  if (!glyphname)
    return NULL;

  agln = ht_lookup_table(&aglmap, glyphname, strlen(glyphname));

  return agln;
}

Here is the call graph for this function:

Here is the caller graph for this function:

long agl_name_convert_unicode ( const char *  glyphname)

Definition at line 558 of file agl.c.

{
  long  ucv = -1;
  char *p;

  if (!agl_name_is_unicode(glyphname))
    return -1;

  if (strlen(glyphname) > 7 && *(glyphname+7) != '.') {
    WARN("Mapping to multiple Unicode characters not supported.");
    return -1;
  }

  if (glyphname[1] == 'n')
    p = (char *) (glyphname + 3);
  else
    p = (char *) (glyphname + 1);
  ucv = 0;
  while (*p != '\0' && *p != '.') {
    if (!isdigit(*p) && (*p < 'A' || *p > 'F')) {
      WARN("Invalid char %c in Unicode glyph name %s.", *p, glyphname);
      return -1;
    }
    ucv <<= 4;
    ucv += isdigit(*p) ? *p - '0' : *p - 'A' + 10;
    p++;
  }

  if (!UC_is_valid(ucv)) {
    if (ucv < 0x10000) {
      WARN("Invalid Unicode code value U+%04X.", ucv);
    } else {
      WARN("Invalid Unicode code value U+%06X.", ucv);
    }
    ucv = -1;
  }

  return ucv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int agl_name_is_unicode ( const char *  glyphname)

Definition at line 520 of file agl.c.

{
  char c, *suffix;
  int  i, len;

  if (!glyphname)
    return 0;

  suffix = strchr(glyphname, '.');
  len    = (int) (suffix ? suffix - glyphname : (int)strlen(glyphname));
  /*
   * uni02ac is invalid glyph name and mapped to th empty string.
   */
  if (len >= 7 && (len - 3) % 4 == 0 &&
      !strncmp(glyphname, "uni", 3)) {
    c = glyphname[3];
    /*
     * Check if the 4th character is uppercase hexadecimal digit.
     * "union" should not be treated as Unicode glyph name.
     */
    if (isdigit(c) || (c >= 'A' && c <= 'F'))
      return 1;
    else
      return 0;
  } else if (len <= 7 && len >= 5 &&
            glyphname[0] == 'u') {
    for (i = 1; i < len - 1; i++) {
      c = glyphname[i];
      if (!isdigit(c) && (c < 'A' || c > 'F'))
       return 0;
    }
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void agl_set_verbose ( void  )

Definition at line 58 of file agl.c.

{
  verbose++;
}

Here is the caller graph for this function:

long agl_sput_UTF16BE ( const char *  name,
unsigned char **  dstpp,
unsigned char *  limptr,
int *  num_fails 
)

Definition at line 652 of file agl.c.

{
  long  len   = 0;
  int   count = 0;
  char *p, *endptr;

  ASSERT(glyphstr && dstpp);

  p      = (char *) glyphstr;
  endptr = strchr(p, '.');
  if (!endptr)
    endptr = p + strlen(p);

  while (p < endptr) {
    char     *name, *delim;
    long      sub_len;
    int       i;
    agl_name *agln0, *agln1 = NULL;

    delim = strchr(p, '_');
    if (delim == p) {
      /*
       * Glyph names starting with a underscore or two subsequent
       * underscore in glyph name not allowed?
       */
      WARN("Invalid glyph name component in \"%s\".", glyphstr);
      count++;
      if (fail_count)
       *fail_count = count;
      return len; /* Cannot continue */
    } else if (!delim || delim > endptr) {
      delim = endptr;
    }
    sub_len = (long) (delim - p);

    name = NEW(sub_len+1, char);
    memcpy(name, p, sub_len);
    name[sub_len] = '\0';

    if (agl_name_is_unicode(name)) {
      sub_len = put_unicode_glyph(name, dstpp, limptr);
      if (sub_len > 0)
       len += sub_len;
      else {
       count++;
      }
    } else {
      agln1 = agl_lookup_list(name);
      if (!agln1 || (agln1->n_components == 1 &&
                   IS_PUA(agln1->unicodes[0]))) {
       agln0 = agl_normalized_name(name);
       if (agln0) {
         if (verbose > 1 && agln0->suffix) {
           WARN("agl: fix %s --> %s.%s",
               name, agln0->name, agln0->suffix);
         }
         agln1 = agl_lookup_list(agln0->name);
         agl_release_name(agln0);
       }
      }
      if (agln1) {
       for (i = 0; i < agln1->n_components; i++) {
         len += UC_sput_UTF16BE (agln1->unicodes[i], dstpp, limptr);
       }
      } else {
       if (verbose) {
         WARN("No Unicode mapping for glyph name \"%s\" found.", name);
       }
       count++;
      }
    }
    RELEASE(name);
    p = delim + 1;
  }

  if (fail_count)
    *fail_count = count;
  return len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* agl_suffix_to_otltag ( const char *  suffix)

Definition at line 268 of file agl.c.

{
  int i, j;
  
  for (i = 0; var_list[i].key; i++) {
    for (j = 0; var_list[i].suffixes[j]; j++) {
      if (!strcmp(suffix, var_list[i].suffixes[j]))
        return var_list[i].otl_tag; 
    }
    if (!strcmp(suffix, var_list[i].key))
      return var_list[i].otl_tag;
    if (var_list[i].otl_tag &&
       !strcmp(suffix, var_list[i].otl_tag))
      return var_list[i].otl_tag;
  }
  
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function: