605e2bd19d9b29eeaaea560bd1b05d231596b24b
[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 private:
71
72   void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
73   void addMapping(CharCode code, char *uStr, int n, int offset);
74   CharCodeToUnicode(GString *tagA);
75   CharCodeToUnicode(GString *tagA, Unicode *mapA,
76                     CharCode mapLenA, GBool copyMap,
77                     CharCodeToUnicodeString *sMapA,
78                     int sMapLenA, int sMapSizeA);
79
80   GString *tag;
81   Unicode *map;
82   CharCode mapLen;
83   CharCodeToUnicodeString *sMap;
84   int sMapLen, sMapSize;
85   int refCnt;
86 #ifdef MULTITHREADED
87   GMutex mutex;
88 #endif
89 };
90
91 //------------------------------------------------------------------------
92
93 class CharCodeToUnicodeCache {
94 public:
95
96   CharCodeToUnicodeCache(int sizeA);
97   ~CharCodeToUnicodeCache();
98
99   // Get the CharCodeToUnicode object for <tag>.  Increments its
100   // reference count; there will be one reference for the cache plus
101   // one for the caller of this function.  Returns NULL on failure.
102   CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
103
104   // Insert <ctu> into the cache, in the most-recently-used position.
105   void add(CharCodeToUnicode *ctu);
106
107 private:
108
109   CharCodeToUnicode **cache;
110   int size;
111 };
112
113 #endif