upgraded to xpdf-3.01pl1
[swftools.git] / pdf2swf / xpdf / CharCodeToUnicode.h
1 //========================================================================
2 //
3 // CharCodeToUnicode.h
4 //
5 // Mapping from character codes to Unicode.
6 //
7 // Copyright 2001-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
10
11 #ifndef CHARCODETOUNICODE_H
12 #define CHARCODETOUNICODE_H
13
14 #include <aconf.h>
15
16 #ifdef USE_GCC_PRAGMAS
17 #pragma interface
18 #endif
19
20 #include "CharTypes.h"
21
22 #if MULTITHREADED
23 #include "GMutex.h"
24 #endif
25
26 struct CharCodeToUnicodeString;
27
28 //------------------------------------------------------------------------
29
30 class CharCodeToUnicode {
31 public:
32
33   // Read the CID-to-Unicode mapping for <collection> from the file
34   // specified by <fileName>.  Sets the initial reference count to 1.
35   // Returns NULL on failure.
36   static CharCodeToUnicode *parseCIDToUnicode(GString *fileName,
37                                               GString *collection);
38
39   // Create a Unicode-to-Unicode mapping from the file specified by
40   // <fileName>.  Sets the initial reference count to 1.  Returns NULL
41   // on failure.
42   static CharCodeToUnicode *parseUnicodeToUnicode(GString *fileName);
43
44   // Create the CharCode-to-Unicode mapping for an 8-bit font.
45   // <toUnicode> is an array of 256 Unicode indexes.  Sets the initial
46   // reference count to 1.
47   static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
48
49   // Parse a ToUnicode CMap for an 8- or 16-bit font.
50   static CharCodeToUnicode *parseCMap(GString *buf, int nBits);
51
52   // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
53   // <this>.
54   void mergeCMap(GString *buf, int nBits);
55
56   ~CharCodeToUnicode();
57
58   void incRefCnt();
59   void decRefCnt();
60
61   // Return true if this mapping matches the specified <tagA>.
62   GBool match(GString *tagA);
63
64   // Set the mapping for <c>.
65   void setMapping(CharCode c, Unicode *u, int len);
66
67   // Map a CharCode to Unicode.
68   int mapToUnicode(CharCode c, Unicode *u, int size);
69
70   // Return the mapping's length, i.e., one more than the max char
71   // code supported by the mapping.
72   CharCode getLength() { return mapLen; }
73
74 private:
75
76   void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
77   void addMapping(CharCode code, char *uStr, int n, int offset);
78   CharCodeToUnicode(GString *tagA);
79   CharCodeToUnicode(GString *tagA, Unicode *mapA,
80                     CharCode mapLenA, GBool copyMap,
81                     CharCodeToUnicodeString *sMapA,
82                     int sMapLenA, int sMapSizeA);
83
84   GString *tag;
85   Unicode *map;
86   CharCode mapLen;
87   CharCodeToUnicodeString *sMap;
88   int sMapLen, sMapSize;
89   int refCnt;
90 #if MULTITHREADED
91   GMutex mutex;
92 #endif
93 };
94
95 //------------------------------------------------------------------------
96
97 class CharCodeToUnicodeCache {
98 public:
99
100   CharCodeToUnicodeCache(int sizeA);
101   ~CharCodeToUnicodeCache();
102
103   // Get the CharCodeToUnicode object for <tag>.  Increments its
104   // reference count; there will be one reference for the cache plus
105   // one for the caller of this function.  Returns NULL on failure.
106   CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
107
108   // Insert <ctu> into the cache, in the most-recently-used position.
109   void add(CharCodeToUnicode *ctu);
110
111 private:
112
113   CharCodeToUnicode **cache;
114   int size;
115 };
116
117 #endif