Back to index

tetex-bin  3.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CharCodeToUnicode Class Reference

#include <CharCodeToUnicode.h>

Collaboration diagram for CharCodeToUnicode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void mergeCMap (GString *buf, int nBits)
 ~CharCodeToUnicode ()
void incRefCnt ()
void decRefCnt ()
GBool match (GString *tagA)
void setMapping (CharCode c, Unicode *u, int len)
int mapToUnicode (CharCode c, Unicode *u, int size)

Static Public Member Functions

static CharCodeToUnicodeparseCIDToUnicode (GString *fileName, GString *collection)
static CharCodeToUnicodeparseUnicodeToUnicode (GString *fileName)
static CharCodeToUnicodemake8BitToUnicode (Unicode *toUnicode)
static CharCodeToUnicodeparseCMap (GString *buf, int nBits)

Private Member Functions

void parseCMap1 (int(*getCharFunc)(void *), void *data, int nBits)
void addMapping (CharCode code, char *uStr, int n, int offset)
 CharCodeToUnicode (GString *tagA)
 CharCodeToUnicode (GString *tagA, Unicode *mapA, CharCode mapLenA, GBool copyMap, CharCodeToUnicodeString *sMapA, int sMapLenA, int sMapSizeA)

Private Attributes

GStringtag
Unicodemap
CharCode mapLen
CharCodeToUnicodeStringsMap
int sMapLen
int sMapSize
int refCnt

Detailed Description

Definition at line 30 of file CharCodeToUnicode.h.


Constructor & Destructor Documentation

Definition at line 393 of file CharCodeToUnicode.cc.

                                      {
  if (tag) {
    delete tag;
  }
  gfree(map);
  if (sMap) {
    gfree(sMap);
  }
#if MULTITHREADED
  gDestroyMutex(&mutex);
#endif
}

Here is the call graph for this function:

Definition at line 355 of file CharCodeToUnicode.cc.

                                                  {
  CharCode i;

  tag = tagA;
  mapLen = 256;
  map = (Unicode *)gmalloc(mapLen * sizeof(Unicode));
  for (i = 0; i < mapLen; ++i) {
    map[i] = 0;
  }
  sMap = NULL;
  sMapLen = sMapSize = 0;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

CharCodeToUnicode::CharCodeToUnicode ( GString tagA,
Unicode mapA,
CharCode  mapLenA,
GBool  copyMap,
CharCodeToUnicodeString sMapA,
int  sMapLenA,
int  sMapSizeA 
) [private]

Definition at line 372 of file CharCodeToUnicode.cc.

                                                              {
  tag = tagA;
  mapLen = mapLenA;
  if (copyMap) {
    map = (Unicode *)gmalloc(mapLen * sizeof(Unicode));
    memcpy(map, mapA, mapLen * sizeof(Unicode));
  } else {
    map = mapA;
  }
  sMap = sMapA;
  sMapLen = sMapLenA;
  sMapSize = sMapSizeA;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Here is the call graph for this function:


Member Function Documentation

void CharCodeToUnicode::addMapping ( CharCode  code,
char *  uStr,
int  n,
int  offset 
) [private]

Definition at line 313 of file CharCodeToUnicode.cc.

                                           {
  CharCode oldLen, i;
  Unicode u;
  char uHex[5];
  int j;

  if (code >= mapLen) {
    oldLen = mapLen;
    mapLen = (code + 256) & ~255;
    map = (Unicode *)grealloc(map, mapLen * sizeof(Unicode));
    for (i = oldLen; i < mapLen; ++i) {
      map[i] = 0;
    }
  }
  if (n <= 4) {
    if (sscanf(uStr, "%x", &u) != 1) {
      error(-1, "Illegal entry in ToUnicode CMap");
      return;
    }
    map[code] = u + offset;
  } else {
    if (sMapLen >= sMapSize) {
      sMapSize = sMapSize + 16;
      sMap = (CharCodeToUnicodeString *)
              grealloc(sMap, sMapSize * sizeof(CharCodeToUnicodeString));
    }
    map[code] = 0;
    sMap[sMapLen].c = code;
    sMap[sMapLen].len = n / 4;
    for (j = 0; j < sMap[sMapLen].len && j < maxUnicodeString; ++j) {
      strncpy(uHex, uStr + j*4, 4);
      uHex[4] = '\0';
      if (sscanf(uHex, "%x", &sMap[sMapLen].u[j]) != 1) {
       error(-1, "Illegal entry in ToUnicode CMap");
      }
    }
    sMap[sMapLen].u[sMap[sMapLen].len - 1] += offset;
    ++sMapLen;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 416 of file CharCodeToUnicode.cc.

                                  {
  GBool done;

#if MULTITHREADED
  gLockMutex(&mutex);
#endif
  done = --refCnt == 0;
#if MULTITHREADED
  gUnlockMutex(&mutex);
#endif
  if (done) {
    delete this;
  }
}

Here is the caller graph for this function:

Definition at line 406 of file CharCodeToUnicode.cc.

                                  {
#if MULTITHREADED
  gLockMutex(&mutex);
#endif
  ++refCnt;
#if MULTITHREADED
  gUnlockMutex(&mutex);
#endif
}

Here is the caller graph for this function:

Definition at line 186 of file CharCodeToUnicode.cc.

                                                                          {
  return new CharCodeToUnicode(NULL, toUnicode, 256, gTrue, NULL, 0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 456 of file CharCodeToUnicode.cc.

                                                                    {
  int i, j;

  if (c >= mapLen) {
    return 0;
  }
  if (map[c]) {
    u[0] = map[c];
    return 1;
  }
  for (i = 0; i < sMapLen; ++i) {
    if (sMap[i].c == c) {
      for (j = 0; j < sMap[i].len && j < size; ++j) {
       u[j] = sMap[i].u[j];
      }
      return j;
    }
  }
  return 0;
}

Here is the caller graph for this function:

Definition at line 431 of file CharCodeToUnicode.cc.

                                            {
  return tag && !tag->cmp(tagA);
}

Here is the call graph for this function:

void CharCodeToUnicode::mergeCMap ( GString buf,
int  nBits 
)

Definition at line 200 of file CharCodeToUnicode.cc.

                                                         {
  char *p;

  p = buf->getCString();
  parseCMap1(&getCharFromString, &p, nBits);
}

Here is the call graph for this function:

Here is the caller graph for this function:

CharCodeToUnicode * CharCodeToUnicode::parseCIDToUnicode ( GString fileName,
GString collection 
) [static]

Definition at line 57 of file CharCodeToUnicode.cc.

                                                                      {
  FILE *f;
  Unicode *mapA;
  CharCode size, mapLenA;
  char buf[64];
  Unicode u;
  CharCodeToUnicode *ctu;

  if (!(f = fopen(fileName->getCString(), "r"))) {
    error(-1, "Couldn't open cidToUnicode file '%s'",
         fileName->getCString());
    return NULL;
  }

  size = 32768;
  mapA = (Unicode *)gmalloc(size * sizeof(Unicode));
  mapLenA = 0;

  while (getLine(buf, sizeof(buf), f)) {
    if (mapLenA == size) {
      size *= 2;
      mapA = (Unicode *)grealloc(mapA, size * sizeof(Unicode));
    }
    if (sscanf(buf, "%x", &u) == 1) {
      mapA[mapLenA] = u;
    } else {
      error(-1, "Bad line (%d) in cidToUnicode file '%s'",
           (int)(mapLenA + 1), fileName->getCString());
      mapA[mapLenA] = 0;
    }
    ++mapLenA;
  }
  fclose(f);

  ctu = new CharCodeToUnicode(collection->copy(), mapA, mapLenA, gTrue,
                           NULL, 0, 0);
  gfree(mapA);
  return ctu;
}

Here is the call graph for this function:

Here is the caller graph for this function:

CharCodeToUnicode * CharCodeToUnicode::parseCMap ( GString buf,
int  nBits 
) [static]

Definition at line 190 of file CharCodeToUnicode.cc.

                                                                       {
  CharCodeToUnicode *ctu;
  char *p;

  ctu = new CharCodeToUnicode(NULL);
  p = buf->getCString();
  ctu->parseCMap1(&getCharFromString, &p, nBits);
  return ctu;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CharCodeToUnicode::parseCMap1 ( int(*)(void *)  getCharFunc,
void data,
int  nBits 
) [private]

Definition at line 207 of file CharCodeToUnicode.cc.

                                          {
  PSTokenizer *pst;
  char tok1[256], tok2[256], tok3[256];
  int nDigits, n1, n2, n3;
  CharCode i;
  CharCode code1, code2;
  GString *name;
  FILE *f;

  nDigits = nBits / 4;
  pst = new PSTokenizer(getCharFunc, data);
  pst->getToken(tok1, sizeof(tok1), &n1);
  while (pst->getToken(tok2, sizeof(tok2), &n2)) {
    if (!strcmp(tok2, "usecmap")) {
      if (tok1[0] == '/') {
       name = new GString(tok1 + 1);
       if ((f = globalParams->findToUnicodeFile(name))) {
         parseCMap1(&getCharFromFile, f, nBits);
         fclose(f);
       } else {
         error(-1, "Couldn't find ToUnicode CMap file for '%s'",
              name->getCString());
       }
       delete name;
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else if (!strcmp(tok2, "beginbfchar")) {
      while (pst->getToken(tok1, sizeof(tok1), &n1)) {
       if (!strcmp(tok1, "endbfchar")) {
         break;
       }
       if (!pst->getToken(tok2, sizeof(tok2), &n2) ||
           !strcmp(tok2, "endbfchar")) {
         error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
         break;
       }
       if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
             tok2[0] == '<' && tok2[n2 - 1] == '>')) {
         error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
         continue;
       }
       tok1[n1 - 1] = tok2[n2 - 1] = '\0';
       if (sscanf(tok1 + 1, "%x", &code1) != 1) {
         error(-1, "Illegal entry in bfchar block in ToUnicode CMap");
         continue;
       }
       addMapping(code1, tok2 + 1, n2 - 1, 0);
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else if (!strcmp(tok2, "beginbfrange")) {
      while (pst->getToken(tok1, sizeof(tok1), &n1)) {
       if (!strcmp(tok1, "endbfrange")) {
         break;
       }
       if (!pst->getToken(tok2, sizeof(tok2), &n2) ||
           !strcmp(tok2, "endbfrange") ||
           !pst->getToken(tok3, sizeof(tok3), &n3) ||
           !strcmp(tok3, "endbfrange")) {
         error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
         break;
       }
       if (!(n1 == 2 + nDigits && tok1[0] == '<' && tok1[n1 - 1] == '>' &&
             n2 == 2 + nDigits && tok2[0] == '<' && tok2[n2 - 1] == '>')) {
         error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
         continue;
       }
       tok1[n1 - 1] = tok2[n2 - 1] = '\0';
       if (sscanf(tok1 + 1, "%x", &code1) != 1 ||
           sscanf(tok2 + 1, "%x", &code2) != 1) {
         error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
         continue;
       }
       if (!strcmp(tok3, "[")) {
         i = 0;
         while (pst->getToken(tok1, sizeof(tok1), &n1) &&
               code1 + i <= code2) {
           if (!strcmp(tok1, "]")) {
             break;
           }
           if (tok1[0] == '<' && tok1[n1 - 1] == '>') {
             tok1[n1 - 1] = '\0';
             addMapping(code1 + i, tok1 + 1, n1 - 2, 0);
           } else {
             error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
           }
           ++i;
         }
       } else if (tok3[0] == '<' && tok3[n3 - 1] == '>') {
         tok3[n3 - 1] = '\0';
         for (i = 0; code1 <= code2; ++code1, ++i) {
           addMapping(code1, tok3 + 1, n3 - 2, i);
         }

       } else {
         error(-1, "Illegal entry in bfrange block in ToUnicode CMap");
       }
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else {
      strcpy(tok1, tok2);
    }
  }
  delete pst;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file CharCodeToUnicode.cc.

                                                                 {
  FILE *f;
  Unicode *mapA;
  CharCodeToUnicodeString *sMapA;
  CharCode size, oldSize, len, sMapSizeA, sMapLenA;
  char buf[256];
  char *tok;
  Unicode u0;
  Unicode uBuf[maxUnicodeString];
  CharCodeToUnicode *ctu;
  int line, n, i;

  if (!(f = fopen(fileName->getCString(), "r"))) {
    error(-1, "Couldn't open unicodeToUnicode file '%s'",
         fileName->getCString());
    return NULL;
  }

  size = 4096;
  mapA = (Unicode *)gmalloc(size * sizeof(Unicode));
  memset(mapA, 0, size * sizeof(Unicode));
  len = 0;
  sMapA = NULL;
  sMapSizeA = sMapLenA = 0;

  line = 0;
  while (getLine(buf, sizeof(buf), f)) {
    ++line;
    if (!(tok = strtok(buf, " \t\r\n")) ||
       sscanf(tok, "%x", &u0) != 1) {
      error(-1, "Bad line (%d) in unicodeToUnicode file '%s'",
           line, fileName->getCString());
      continue;
    }
    n = 0;
    while (n < maxUnicodeString) {
      if (!(tok = strtok(NULL, " \t\r\n"))) {
       break;
      }
      if (sscanf(tok, "%x", &uBuf[n]) != 1) {
       error(-1, "Bad line (%d) in unicodeToUnicode file '%s'",
             line, fileName->getCString());
       break;
      }
      ++n;
    }
    if (n < 1) {
      error(-1, "Bad line (%d) in unicodeToUnicode file '%s'",
           line, fileName->getCString());
      continue;
    }
    if (u0 >= size) {
      oldSize = size;
      while (u0 >= size) {
       size *= 2;
      }
      mapA = (Unicode *)grealloc(mapA, size * sizeof(Unicode));
      memset(mapA + oldSize, 0, (size - oldSize) * sizeof(Unicode));
    }
    if (n == 1) {
      mapA[u0] = uBuf[0];
    } else {
      mapA[u0] = 0;
      if (sMapLenA == sMapSizeA) {
       sMapSizeA += 16;
       sMapA = (CharCodeToUnicodeString *)
                 grealloc(sMapA, sMapSizeA * sizeof(CharCodeToUnicodeString));
      }
      sMapA[sMapLenA].c = u0;
      for (i = 0; i < n; ++i) {
       sMapA[sMapLenA].u[i] = uBuf[i];
      }
      sMapA[sMapLenA].len = n;
      ++sMapLenA;
    }
    if (u0 >= len) {
      len = u0 + 1;
    }
  }
  fclose(f);

  ctu = new CharCodeToUnicode(fileName->copy(), mapA, len, gTrue,
                           sMapA, sMapLenA, sMapSizeA);
  gfree(mapA);
  return ctu;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 435 of file CharCodeToUnicode.cc.

                                                                  {
  int i;

  if (len == 1) {
    map[c] = u[0];
  } else {
    map[c] = 0;
    if (sMapLen == sMapSize) {
      sMapSize += 8;
      sMap = (CharCodeToUnicodeString *)
              grealloc(sMap, sMapSize * sizeof(CharCodeToUnicodeString));
    }
    sMap[sMapLen].c = c;
    sMap[sMapLen].len = len;
    for (i = 0; i < len && i < maxUnicodeString; ++i) {
      sMap[sMapLen].u[i] = u[i];
    }
    ++sMapLen;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 81 of file CharCodeToUnicode.h.

Definition at line 82 of file CharCodeToUnicode.h.

Definition at line 85 of file CharCodeToUnicode.h.

Definition at line 83 of file CharCodeToUnicode.h.

Definition at line 84 of file CharCodeToUnicode.h.

Definition at line 84 of file CharCodeToUnicode.h.

Definition at line 80 of file CharCodeToUnicode.h.


The documentation for this class was generated from the following files: