Back to index

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

#include <CMap.h>

Collaboration diagram for CMap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ~CMap ()
void incRefCnt ()
void decRefCnt ()
GStringgetCollection ()
GBool match (GString *collectionA, GString *cMapNameA)
CID getCID (char *s, int len, int *nUsed)
int getWMode ()

Static Public Member Functions

static CMapparse (CMapCache *cache, GString *collectionA, GString *cMapNameA)

Private Member Functions

 CMap (GString *collectionA, GString *cMapNameA)
 CMap (GString *collectionA, GString *cMapNameA, int wModeA)
void useCMap (CMapCache *cache, char *useName)
void copyVector (CMapVectorEntry *dest, CMapVectorEntry *src)
void addCodeSpace (CMapVectorEntry *vec, Guint start, Guint end, Guint nBytes)
void addCIDs (Guint start, Guint end, Guint nBytes, CID firstCID)
void freeCMapVector (CMapVectorEntry *vec)

Private Attributes

GStringcollection
GStringcMapName
int wMode
CMapVectorEntryvector
int refCnt

Detailed Description

Definition at line 31 of file CMap.h.


Constructor & Destructor Documentation

Definition at line 255 of file CMap.cc.

            {
  delete collection;
  delete cMapName;
  if (vector) {
    freeCMapVector(vector);
  }
#if MULTITHREADED
  gDestroyMutex(&mutex);
#endif
}

Here is the call graph for this function:

CMap::CMap ( GString collectionA,
GString cMapNameA 
) [private]

Definition at line 135 of file CMap.cc.

                                                   {
  int i;

  collection = collectionA;
  cMapName = cMapNameA;
  wMode = 0;
  vector = (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
  for (i = 0; i < 256; ++i) {
    vector[i].isVector = gFalse;
    vector[i].cid = 0;
  }
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

CMap::CMap ( GString collectionA,
GString cMapNameA,
int  wModeA 
) [private]

Definition at line 152 of file CMap.cc.

                                                               {
  collection = collectionA;
  cMapName = cMapNameA;
  wMode = wModeA;
  vector = NULL;
  refCnt = 1;
#if MULTITHREADED
  gInitMutex(&mutex);
#endif
}

Member Function Documentation

void CMap::addCIDs ( Guint  start,
Guint  end,
Guint  nBytes,
CID  firstCID 
) [private]

Definition at line 227 of file CMap.cc.

                                                                     {
  CMapVectorEntry *vec;
  CID cid;
  int byte;
  Guint i;

  vec = vector;
  for (i = nBytes - 1; i >= 1; --i) {
    byte = (start >> (8 * i)) & 0xff;
    if (!vec[byte].isVector) {
      error(-1, "Invalid CID (%*x - %*x) in CMap",
           2*nBytes, start, 2*nBytes, end);
      return;
    }
    vec = vec[byte].vector;
  }
  cid = firstCID;
  for (byte = (int)(start & 0xff); byte <= (int)(end & 0xff); ++byte) {
    if (vec[byte].isVector) {
      error(-1, "Invalid CID (%*x - %*x) in CMap",
           2*nBytes, start, 2*nBytes, end);
    } else {
      vec[byte].cid = cid;
    }
    ++cid;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CMap::addCodeSpace ( CMapVectorEntry vec,
Guint  start,
Guint  end,
Guint  nBytes 
) [private]

Definition at line 202 of file CMap.cc.

                                   {
  Guint start2, end2;
  int startByte, endByte, i, j;

  if (nBytes > 1) {
    startByte = (start >> (8 * (nBytes - 1))) & 0xff;
    endByte = (end >> (8 * (nBytes - 1))) & 0xff;
    start2 = start & ((1 << (8 * (nBytes - 1))) - 1);
    end2 = end & ((1 << (8 * (nBytes - 1))) - 1);
    for (i = startByte; i <= endByte; ++i) {
      if (!vec[i].isVector) {
       vec[i].isVector = gTrue;
       vec[i].vector =
         (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
       for (j = 0; j < 256; ++j) {
         vec[i].vector[j].isVector = gFalse;
         vec[i].vector[j].cid = 0;
       }
      }
      addCodeSpace(vec[i].vector, start2, end2, nBytes - 1);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CMap::copyVector ( CMapVectorEntry dest,
CMapVectorEntry src 
) [private]

Definition at line 177 of file CMap.cc.

                                                                 {
  int i, j;

  for (i = 0; i < 256; ++i) {
    if (src[i].isVector) {
      if (!dest[i].isVector) {
       dest[i].isVector = gTrue;
       dest[i].vector =
         (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
       for (j = 0; j < 256; ++j) {
         dest[i].vector[j].isVector = gFalse;
         dest[i].vector[j].cid = 0;
       }
      }
      copyVector(dest[i].vector, src[i].vector);
    } else {
      if (dest[i].isVector) {
       error(-1, "Collision in usecmap");
      } else {
       dest[i].cid = src[i].cid;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 287 of file CMap.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 266 of file CMap.cc.

                                              {
  int i;

  for (i = 0; i < 256; ++i) {
    if (vec[i].isVector) {
      freeCMapVector(vec[i].vector);
    }
  }
  gfree(vec);
}

Here is the call graph for this function:

Here is the caller graph for this function:

CID CMap::getCID ( char *  s,
int  len,
int nUsed 
)

Definition at line 306 of file CMap.cc.

                                             {
  CMapVectorEntry *vec;
  int n, i;

  if (!(vec = vector)) {
    // identity CMap
    *nUsed = 2;
    if (len < 2) {
      return 0;
    }
    return ((s[0] & 0xff) << 8) + (s[1] & 0xff);
  }
  n = 0;
  while (1) {
    if (n >= len) {
      *nUsed = n;
      return 0;
    }
    i = s[n++] & 0xff;
    if (!vec[i].isVector) {
      *nUsed = n;
      return vec[i].cid;
    }
    vec = vec[i].vector;
  }
}

Here is the caller graph for this function:

Definition at line 45 of file CMap.h.

{ return collection; }

Here is the caller graph for this function:

int CMap::getWMode ( ) [inline]

Definition at line 57 of file CMap.h.

{ return wMode; }

Here is the caller graph for this function:

Definition at line 277 of file CMap.cc.

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

Here is the caller graph for this function:

GBool CMap::match ( GString collectionA,
GString cMapNameA 
)

Definition at line 302 of file CMap.cc.

                                                          {
  return !collection->cmp(collectionA) && !cMapName->cmp(cMapNameA);
}

Here is the call graph for this function:

CMap * CMap::parse ( CMapCache cache,
GString collectionA,
GString cMapNameA 
) [static]

Definition at line 45 of file CMap.cc.

                                    {
  FILE *f;
  CMap *cmap;
  PSTokenizer *pst;
  char tok1[256], tok2[256], tok3[256];
  int n1, n2, n3;
  Guint start, end;

  if (!(f = globalParams->findCMapFile(collectionA, cMapNameA))) {

    // Check for an identity CMap.
    if (!cMapNameA->cmp("Identity") || !cMapNameA->cmp("Identity-H")) {
      return new CMap(collectionA->copy(), cMapNameA->copy(), 0);
    }
    if (!cMapNameA->cmp("Identity-V")) {
      return new CMap(collectionA->copy(), cMapNameA->copy(), 1);
    }

    error(-1, "Couldn't find '%s' CMap file for '%s' collection",
         cMapNameA->getCString(), collectionA->getCString());
    return NULL;
  }

  cmap = new CMap(collectionA->copy(), cMapNameA->copy());

  pst = new PSTokenizer(&getCharFromFile, f);
  pst->getToken(tok1, sizeof(tok1), &n1);
  while (pst->getToken(tok2, sizeof(tok2), &n2)) {
    if (!strcmp(tok2, "usecmap")) {
      if (tok1[0] == '/') {
       cmap->useCMap(cache, tok1 + 1);
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else if (!strcmp(tok1, "/WMode")) {
      cmap->wMode = atoi(tok2);
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else if (!strcmp(tok2, "begincodespacerange")) {
      while (pst->getToken(tok1, sizeof(tok1), &n1)) {
       if (!strcmp(tok1, "endcodespacerange")) {
         break;
       }
       if (!pst->getToken(tok2, sizeof(tok2), &n2) ||
           !strcmp(tok2, "endcodespacerange")) {
         error(-1, "Illegal entry in codespacerange block in CMap");
         break;
       }
       if (tok1[0] == '<' && tok2[0] == '<' &&
           n1 == n2 && n1 >= 4 && (n1 & 1) == 0) {
         tok1[n1 - 1] = tok2[n1 - 1] = '\0';
         sscanf(tok1 + 1, "%x", &start);
         sscanf(tok2 + 1, "%x", &end);
         n1 = (n1 - 2) / 2;
         cmap->addCodeSpace(cmap->vector, start, end, n1);
       }
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else if (!strcmp(tok2, "begincidrange")) {
      while (pst->getToken(tok1, sizeof(tok1), &n1)) {
       if (!strcmp(tok1, "endcidrange")) {
         break;
       }
       if (!pst->getToken(tok2, sizeof(tok2), &n2) ||
           !strcmp(tok2, "endcidrange") ||
           !pst->getToken(tok3, sizeof(tok3), &n3) ||
           !strcmp(tok3, "endcidrange")) {
         error(-1, "Illegal entry in cidrange block in CMap");
         break;
       }
       if (tok1[0] == '<' && tok2[0] == '<' &&
           n1 == n2 && n1 >= 4 && (n1 & 1) == 0) {
         tok1[n1 - 1] = tok2[n1 - 1] = '\0';
         sscanf(tok1 + 1, "%x", &start);
         sscanf(tok2 + 1, "%x", &end);
         n1 = (n1 - 2) / 2;
         cmap->addCIDs(start, end, n1, (CID)atoi(tok3));
       }
      }
      pst->getToken(tok1, sizeof(tok1), &n1);
    } else {
      strcpy(tok1, tok2);
    }
  }
  delete pst;

  fclose(f);

  return cmap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CMap::useCMap ( CMapCache cache,
char *  useName 
) [private]

Definition at line 163 of file CMap.cc.

                                                  {
  GString *useNameStr;
  CMap *subCMap;

  useNameStr = new GString(useName);
  subCMap = cache->getCMap(collection, useNameStr);
  delete useNameStr;
  if (!subCMap) {
    return;
  }
  copyVector(vector, subCMap->vector);
  subCMap->decRefCnt();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

GString* CMap::cMapName [private]

Definition at line 71 of file CMap.h.

Definition at line 70 of file CMap.h.

int CMap::refCnt [private]

Definition at line 75 of file CMap.h.

Definition at line 73 of file CMap.h.

int CMap::wMode [private]

Definition at line 72 of file CMap.h.


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