Back to index

tetex-bin  3.0
CMap.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // CMap.h
00004 //
00005 // Copyright 2001-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef CMAP_H
00010 #define CMAP_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "gtypes.h"
00019 #include "CharTypes.h"
00020 
00021 #if MULTITHREADED
00022 #include "GMutex.h"
00023 #endif
00024 
00025 class GString;
00026 struct CMapVectorEntry;
00027 class CMapCache;
00028 
00029 //------------------------------------------------------------------------
00030 
00031 class CMap {
00032 public:
00033 
00034   // Create the CMap specified by <collection> and <cMapName>.  Sets
00035   // the initial reference count to 1.  Returns NULL on failure.
00036   static CMap *parse(CMapCache *cache, GString *collectionA,
00037                    GString *cMapNameA);
00038 
00039   ~CMap();
00040 
00041   void incRefCnt();
00042   void decRefCnt();
00043 
00044   // Return collection name (<registry>-<ordering>).
00045   GString *getCollection() { return collection; }
00046 
00047   // Return true if this CMap matches the specified <collectionA>, and
00048   // <cMapNameA>.
00049   GBool match(GString *collectionA, GString *cMapNameA);
00050 
00051   // Return the CID corresponding to the character code starting at
00052   // <s>, which contains <len> bytes.  Sets *<nUsed> to the number of
00053   // bytes used by the char code.
00054   CID getCID(char *s, int len, int *nUsed);
00055 
00056   // Return the writing mode (0=horizontal, 1=vertical).
00057   int getWMode() { return wMode; }
00058 
00059 private:
00060 
00061   CMap(GString *collectionA, GString *cMapNameA);
00062   CMap(GString *collectionA, GString *cMapNameA, int wModeA);
00063   void useCMap(CMapCache *cache, char *useName);
00064   void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src);
00065   void addCodeSpace(CMapVectorEntry *vec, Guint start, Guint end,
00066                   Guint nBytes);
00067   void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID);
00068   void freeCMapVector(CMapVectorEntry *vec);
00069 
00070   GString *collection;
00071   GString *cMapName;
00072   int wMode;                // writing mode (0=horizontal, 1=vertical)
00073   CMapVectorEntry *vector;  // vector for first byte (NULL for
00074                             //   identity CMap)
00075   int refCnt;
00076 #ifdef MULTITHREADED
00077   GMutex mutex;
00078 #endif
00079 };
00080 
00081 //------------------------------------------------------------------------
00082 
00083 #define cMapCacheSize 4
00084 
00085 class CMapCache {
00086 public:
00087 
00088   CMapCache();
00089   ~CMapCache();
00090 
00091   // Get the <cMapName> CMap for the specified character collection.
00092   // Increments its reference count; there will be one reference for
00093   // the cache plus one for the caller of this function.  Returns NULL
00094   // on failure.
00095   CMap *getCMap(GString *collection, GString *cMapName);
00096 
00097 private:
00098 
00099   CMap *cache[cMapCacheSize];
00100 };
00101 
00102 #endif