/src/xpdf-4.04/xpdf/CharCodeToUnicode.h
Line | Count | Source (jump to first uncovered line) |
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 | | // Create an identity mapping (Unicode = CharCode). |
34 | | static CharCodeToUnicode *makeIdentityMapping(); |
35 | | |
36 | | // Read the CID-to-Unicode mapping for <collection> from the file |
37 | | // specified by <fileName>. Sets the initial reference count to 1. |
38 | | // Returns NULL on failure. |
39 | | static CharCodeToUnicode *parseCIDToUnicode(GString *fileName, |
40 | | GString *collection); |
41 | | |
42 | | // Create a Unicode-to-Unicode mapping from the file specified by |
43 | | // <fileName>. Sets the initial reference count to 1. Returns NULL |
44 | | // on failure. |
45 | | static CharCodeToUnicode *parseUnicodeToUnicode(GString *fileName); |
46 | | |
47 | | // Create the CharCode-to-Unicode mapping for an 8-bit font. |
48 | | // <toUnicode> is an array of 256 Unicode indexes. Sets the initial |
49 | | // reference count to 1. |
50 | | static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode); |
51 | | |
52 | | // Create the CharCode-to-Unicode mapping for a 16-bit font. |
53 | | // <toUnicode> is an array of 65536 Unicode indexes. Sets the |
54 | | // initial reference count to 1. |
55 | | static CharCodeToUnicode *make16BitToUnicode(Unicode *toUnicode); |
56 | | |
57 | | // Parse a ToUnicode CMap for an 8- or 16-bit font. |
58 | | static CharCodeToUnicode *parseCMap(GString *buf, int nBits); |
59 | | |
60 | | // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into |
61 | | // <this>. |
62 | | void mergeCMap(GString *buf, int nBits); |
63 | | |
64 | | ~CharCodeToUnicode(); |
65 | | |
66 | | void incRefCnt(); |
67 | | void decRefCnt(); |
68 | | |
69 | | // Return true if this mapping matches the specified <tagA>. |
70 | | GBool match(GString *tagA); |
71 | | |
72 | | // Set the mapping for <c>. |
73 | | void setMapping(CharCode c, Unicode *u, int len); |
74 | | |
75 | | // Map a CharCode to Unicode. |
76 | | int mapToUnicode(CharCode c, Unicode *u, int size); |
77 | | |
78 | | // Return the mapping's length, i.e., one more than the max char |
79 | | // code supported by the mapping. |
80 | 0 | CharCode getLength() { return mapLen; } |
81 | | |
82 | 0 | GBool isIdentity() { return !map; } |
83 | | |
84 | | private: |
85 | | |
86 | | GBool parseCMap1(int (*getCharFunc)(void *), void *data, int nBits); |
87 | | void addMapping(CharCode code, char *uStr, int n, int offset); |
88 | | int parseUTF16String(char *uStr, int n, Unicode *uOut); |
89 | | void addMappingInt(CharCode code, Unicode u); |
90 | | CharCodeToUnicode(); |
91 | | CharCodeToUnicode(GString *tagA); |
92 | | CharCodeToUnicode(GString *tagA, Unicode *mapA, |
93 | | CharCode mapLenA, GBool copyMap, |
94 | | CharCodeToUnicodeString *sMapA, |
95 | | int sMapLenA, int sMapSizeA); |
96 | | |
97 | | GString *tag; |
98 | | Unicode *map; |
99 | | CharCode mapLen; |
100 | | CharCodeToUnicodeString *sMap; |
101 | | int sMapLen, sMapSize; |
102 | | #if MULTITHREADED |
103 | | GAtomicCounter refCnt; |
104 | | #else |
105 | | int refCnt; |
106 | | #endif |
107 | | }; |
108 | | |
109 | | //------------------------------------------------------------------------ |
110 | | |
111 | | class CharCodeToUnicodeCache { |
112 | | public: |
113 | | |
114 | | CharCodeToUnicodeCache(int sizeA); |
115 | | ~CharCodeToUnicodeCache(); |
116 | | |
117 | | // Get the CharCodeToUnicode object for <tag>. Increments its |
118 | | // reference count; there will be one reference for the cache plus |
119 | | // one for the caller of this function. Returns NULL on failure. |
120 | | CharCodeToUnicode *getCharCodeToUnicode(GString *tag); |
121 | | |
122 | | // Insert <ctu> into the cache, in the most-recently-used position. |
123 | | void add(CharCodeToUnicode *ctu); |
124 | | |
125 | | private: |
126 | | |
127 | | CharCodeToUnicode **cache; |
128 | | int size; |
129 | | }; |
130 | | |
131 | | #endif |