Back to index

tetex-bin  3.0
CharCodeToUnicode.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // CharCodeToUnicode.h
00004 //
00005 // Mapping from character codes to Unicode.
00006 //
00007 // Copyright 2001-2003 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef CHARCODETOUNICODE_H
00012 #define CHARCODETOUNICODE_H
00013 
00014 #include <aconf.h>
00015 
00016 #ifdef USE_GCC_PRAGMAS
00017 #pragma interface
00018 #endif
00019 
00020 #include "CharTypes.h"
00021 
00022 #if MULTITHREADED
00023 #include "GMutex.h"
00024 #endif
00025 
00026 struct CharCodeToUnicodeString;
00027 
00028 //------------------------------------------------------------------------
00029 
00030 class CharCodeToUnicode {
00031 public:
00032 
00033   // Read the CID-to-Unicode mapping for <collection> from the file
00034   // specified by <fileName>.  Sets the initial reference count to 1.
00035   // Returns NULL on failure.
00036   static CharCodeToUnicode *parseCIDToUnicode(GString *fileName,
00037                                          GString *collection);
00038 
00039   // Create a Unicode-to-Unicode mapping from the file specified by
00040   // <fileName>.  Sets the initial reference count to 1.  Returns NULL
00041   // on failure.
00042   static CharCodeToUnicode *parseUnicodeToUnicode(GString *fileName);
00043 
00044   // Create the CharCode-to-Unicode mapping for an 8-bit font.
00045   // <toUnicode> is an array of 256 Unicode indexes.  Sets the initial
00046   // reference count to 1.
00047   static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
00048 
00049   // Parse a ToUnicode CMap for an 8- or 16-bit font.
00050   static CharCodeToUnicode *parseCMap(GString *buf, int nBits);
00051 
00052   // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
00053   // <this>.
00054   void mergeCMap(GString *buf, int nBits);
00055 
00056   ~CharCodeToUnicode();
00057 
00058   void incRefCnt();
00059   void decRefCnt();
00060 
00061   // Return true if this mapping matches the specified <tagA>.
00062   GBool match(GString *tagA);
00063 
00064   // Set the mapping for <c>.
00065   void setMapping(CharCode c, Unicode *u, int len);
00066 
00067   // Map a CharCode to Unicode.
00068   int mapToUnicode(CharCode c, Unicode *u, int size);
00069 
00070 private:
00071 
00072   void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
00073   void addMapping(CharCode code, char *uStr, int n, int offset);
00074   CharCodeToUnicode(GString *tagA);
00075   CharCodeToUnicode(GString *tagA, Unicode *mapA,
00076                   CharCode mapLenA, GBool copyMap,
00077                   CharCodeToUnicodeString *sMapA,
00078                   int sMapLenA, int sMapSizeA);
00079 
00080   GString *tag;
00081   Unicode *map;
00082   CharCode mapLen;
00083   CharCodeToUnicodeString *sMap;
00084   int sMapLen, sMapSize;
00085   int refCnt;
00086 #ifdef MULTITHREADED
00087   GMutex mutex;
00088 #endif
00089 };
00090 
00091 //------------------------------------------------------------------------
00092 
00093 class CharCodeToUnicodeCache {
00094 public:
00095 
00096   CharCodeToUnicodeCache(int sizeA);
00097   ~CharCodeToUnicodeCache();
00098 
00099   // Get the CharCodeToUnicode object for <tag>.  Increments its
00100   // reference count; there will be one reference for the cache plus
00101   // one for the caller of this function.  Returns NULL on failure.
00102   CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
00103 
00104   // Insert <ctu> into the cache, in the most-recently-used position.
00105   void add(CharCodeToUnicode *ctu);
00106 
00107 private:
00108 
00109   CharCodeToUnicode **cache;
00110   int size;
00111 };
00112 
00113 #endif