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