file(s) added by xpdf 1.01.
[swftools.git] / pdf2swf / xpdf / CharCodeToUnicode.h
1 //========================================================================
2 //
3 // CharCodeToUnicode.h
4 //
5 // Mapping from character codes to Unicode.
6 //
7 // Copyright 2001-2002 Glyph & Cog, LLC
8 //
9 //========================================================================
10
11 #ifndef CHARCODETOUNICODE_H
12 #define CHARCODETOUNICODE_H
13
14 #ifdef __GNUC__
15 #pragma interface
16 #endif
17
18 #include "CharTypes.h"
19
20 struct CharCodeToUnicodeString;
21
22 //------------------------------------------------------------------------
23
24 class CharCodeToUnicode {
25 public:
26
27   // Create the CID-to-Unicode mapping specified by <collection>.
28   // This reads a .cidToUnicode file from disk.  Sets the initial
29   // reference count to 1.  Returns NULL on failure.
30   static CharCodeToUnicode *parseCIDToUnicode(GString *collectionA);
31
32   // Create the CharCode-to-Unicode mapping for an 8-bit font.
33   // <toUnicode> is an array of 256 Unicode indexes.  Sets the initial
34   // reference count to 1.
35   static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
36
37   // Parse a ToUnicode CMap for an 8- or 16-bit font.
38   static CharCodeToUnicode *parseCMap(GString *buf, int nBits);
39
40   ~CharCodeToUnicode();
41
42   void incRefCnt();
43   void decRefCnt();
44
45   // Return true if this mapping matches the specified <collectionA>.
46   GBool match(GString *collectionA);
47
48   // Map a CharCode to Unicode.
49   int mapToUnicode(CharCode c, Unicode *u, int size);
50
51 private:
52
53   void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
54   CharCodeToUnicode(GString *collectionA);
55   CharCodeToUnicode(GString *collectionA, Unicode *mapA,
56                     CharCode mapLenA, GBool copyMap,
57                     CharCodeToUnicodeString *sMapA, int sMapLenA);
58
59   GString *collection;
60   Unicode *map;
61   CharCode mapLen;
62   CharCodeToUnicodeString *sMap;
63   int sMapLen, sMapSize;
64   int refCnt;
65 };
66
67 //------------------------------------------------------------------------
68
69 #define cidToUnicodeCacheSize 4
70
71 class CIDToUnicodeCache {
72 public:
73
74   CIDToUnicodeCache();
75   ~CIDToUnicodeCache();
76
77   // Get the CharCodeToUnicode object for <collection>.  Increments
78   // its reference count; there will be one reference for the cache
79   // plus one for the caller of this function.  Returns NULL on
80   // failure.
81   CharCodeToUnicode *getCIDToUnicode(GString *collection);
82
83 private:
84
85   CharCodeToUnicode *cache[cidToUnicodeCacheSize];
86 };
87
88 #endif