Back to index

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

#include <UnicodeMap.h>

Collaboration diagram for UnicodeMap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UnicodeMap (char *encodingNameA, GBool unicodeOutA, UnicodeMapRange *rangesA, int lenA)
 UnicodeMap (char *encodingNameA, GBool unicodeOutA, UnicodeMapFunc funcA)
 ~UnicodeMap ()
void incRefCnt ()
void decRefCnt ()
GStringgetEncodingName ()
GBool isUnicode ()
GBool match (GString *encodingNameA)
int mapUnicode (Unicode u, char *buf, int bufSize)

Static Public Member Functions

static UnicodeMapparse (GString *encodingNameA)

Private Member Functions

 UnicodeMap (GString *encodingNameA)

Private Attributes

GStringencodingName
UnicodeMapKind kind
GBool unicodeOut
union {
UnicodeMapRangeranges
UnicodeMapFunc func
}; 
int len
UnicodeMapExteMaps
int eMapsLen
int refCnt

Detailed Description

Definition at line 48 of file UnicodeMap.h.


Constructor & Destructor Documentation

UnicodeMap::UnicodeMap ( char *  encodingNameA,
GBool  unicodeOutA,
UnicodeMapRange rangesA,
int  lenA 
)

Definition at line 124 of file UnicodeMap.cc.

                                                         {
  encodingName = new GString(encodingNameA);
  unicodeOut = unicodeOutA;
  kind = unicodeMapResident;
  ranges = rangesA;
  len = lenA;
  eMaps = NULL;
  eMapsLen = 0;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Here is the caller graph for this function:

UnicodeMap::UnicodeMap ( char *  encodingNameA,
GBool  unicodeOutA,
UnicodeMapFunc  funcA 
)

Definition at line 139 of file UnicodeMap.cc.

                                           {
  encodingName = new GString(encodingNameA);
  unicodeOut = unicodeOutA;
  kind = unicodeMapFunc;
  func = funcA;
  eMaps = NULL;
  eMapsLen = 0;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Definition at line 153 of file UnicodeMap.cc.

                        {
  delete encodingName;
  if (kind == unicodeMapUser && ranges) {
    gfree(ranges);
  }
  if (eMaps) {
    gfree(eMaps);
  }
#if MULTITHREADED
  gDestroyMutex(&mutex);
#endif
}

Here is the call graph for this function:

UnicodeMap::UnicodeMap ( GString encodingNameA) [private]

Definition at line 110 of file UnicodeMap.cc.

                                             {
  encodingName = encodingNameA;
  unicodeOut = gFalse;
  kind = unicodeMapUser;
  ranges = NULL;
  len = 0;
  eMaps = NULL;
  eMapsLen = 0;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Member Function Documentation

Definition at line 176 of file UnicodeMap.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 69 of file UnicodeMap.h.

{ return encodingName; }

Here is the caller graph for this function:

Definition at line 166 of file UnicodeMap.cc.

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

Here is the caller graph for this function:

Definition at line 71 of file UnicodeMap.h.

{ return unicodeOut; }
int UnicodeMap::mapUnicode ( Unicode  u,
char *  buf,
int  bufSize 
)

Definition at line 195 of file UnicodeMap.cc.

                                                            {
  int a, b, m, n, i, j;
  Guint code;

  if (kind == unicodeMapFunc) {
    return (*func)(u, buf, bufSize);
  }

  a = 0;
  b = len;
  if (u >= ranges[a].start) {
    // invariant: ranges[a].start <= u < ranges[b].start
    while (b - a > 1) {
      m = (a + b) / 2;
      if (u >= ranges[m].start) {
       a = m;
      } else if (u < ranges[m].start) {
       b = m;
      }
    }
    if (u <= ranges[a].end) {
      n = ranges[a].nBytes;
      if (n > bufSize) {
       return 0;
      }
      code = ranges[a].code + (u - ranges[a].start);
      for (i = n - 1; i >= 0; --i) {
       buf[i] = (char)(code & 0xff);
       code >>= 8;
      }
      return n;
    }
  }

  for (i = 0; i < eMapsLen; ++i) {
    if (eMaps[i].u == u) {
      n = eMaps[i].nBytes;
      for (j = 0; j < n; ++j) {
       buf[j] = eMaps[i].code[j];
      }
      return n;
    }
  }

  return 0;
}
GBool UnicodeMap::match ( GString encodingNameA)

Definition at line 191 of file UnicodeMap.cc.

                                              {
  return !encodingName->cmp(encodingNameA);
}

Here is the call graph for this function:

UnicodeMap * UnicodeMap::parse ( GString encodingNameA) [static]

Definition at line 37 of file UnicodeMap.cc.

                                                    {
  FILE *f;
  UnicodeMap *map;
  UnicodeMapRange *range;
  UnicodeMapExt *eMap;
  int size, eMapsSize;
  char buf[256];
  int line, nBytes, i, x;
  char *tok1, *tok2, *tok3;

  if (!(f = globalParams->getUnicodeMapFile(encodingNameA))) {
    error(-1, "Couldn't find unicodeMap file for the '%s' encoding",
         encodingNameA->getCString());
    return NULL;
  }

  map = new UnicodeMap(encodingNameA->copy());

  size = 8;
  map->ranges = (UnicodeMapRange *)gmalloc(size * sizeof(UnicodeMapRange));
  eMapsSize = 0;

  line = 1;
  while (getLine(buf, sizeof(buf), f)) {
    if ((tok1 = strtok(buf, " \t\r\n")) &&
       (tok2 = strtok(NULL, " \t\r\n"))) {
      if (!(tok3 = strtok(NULL, " \t\r\n"))) {
       tok3 = tok2;
       tok2 = tok1;
      }
      nBytes = strlen(tok3) / 2;
      if (nBytes <= 4) {
       if (map->len == size) {
         size *= 2;
         map->ranges = (UnicodeMapRange *)
           grealloc(map->ranges, size * sizeof(UnicodeMapRange));
       }
       range = &map->ranges[map->len];
       sscanf(tok1, "%x", &range->start);
       sscanf(tok2, "%x", &range->end);
       sscanf(tok3, "%x", &range->code);
       range->nBytes = nBytes;
       ++map->len;
      } else if (tok2 == tok1) {
       if (map->eMapsLen == eMapsSize) {
         eMapsSize += 16;
         map->eMaps = (UnicodeMapExt *)
           grealloc(map->eMaps, eMapsSize * sizeof(UnicodeMapExt));
       }
       eMap = &map->eMaps[map->eMapsLen];
       sscanf(tok1, "%x", &eMap->u);
       for (i = 0; i < nBytes; ++i) {
         sscanf(tok3 + i*2, "%2x", &x);
         eMap->code[i] = (char)x;
       }
       eMap->nBytes = nBytes;
       ++map->eMapsLen;
      } else {
       error(-1, "Bad line (%d) in unicodeMap file for the '%s' encoding",
             line, encodingNameA->getCString());
      }
    } else {
      error(-1, "Bad line (%d) in unicodeMap file for the '%s' encoding",
           line, encodingNameA->getCString());
    }
    ++line;
  }

  fclose(f);

  return map;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

union { ... } [private]

Definition at line 95 of file UnicodeMap.h.

Definition at line 96 of file UnicodeMap.h.

Definition at line 87 of file UnicodeMap.h.

Definition at line 88 of file UnicodeMap.h.

int UnicodeMap::len [private]

Definition at line 94 of file UnicodeMap.h.

Definition at line 97 of file UnicodeMap.h.

Definition at line 89 of file UnicodeMap.h.


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