Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/UnicodeMap.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/UnicodeMap.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/UnicodeMap.h b/noncore/unsupported/qpdf/xpdf/UnicodeMap.h new file mode 100644 index 0000000..4d982c8 --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/UnicodeMap.h | |||
@@ -0,0 +1,110 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // UnicodeMap.h | ||
4 | // | ||
5 | // Mapping from Unicode to an encoding. | ||
6 | // | ||
7 | // Copyright 2001 Derek B. Noonburg | ||
8 | // | ||
9 | //======================================================================== | ||
10 | |||
11 | #ifndef UNICODEMAP_H | ||
12 | #define UNICODEMAP_H | ||
13 | |||
14 | #ifdef __GNUC__ | ||
15 | #pragma interface | ||
16 | #endif | ||
17 | |||
18 | #include "gtypes.h" | ||
19 | #include "CharTypes.h" | ||
20 | |||
21 | class GString; | ||
22 | |||
23 | //------------------------------------------------------------------------ | ||
24 | |||
25 | enum UnicodeMapKind { | ||
26 | unicodeMapUser, // read from a file | ||
27 | unicodeMapResident, // static list of ranges | ||
28 | unicodeMapFunc // function pointer | ||
29 | }; | ||
30 | |||
31 | typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize); | ||
32 | |||
33 | struct UnicodeMapRange { | ||
34 | Unicode start, end; // range of Unicode chars | ||
35 | Guint code, nBytes; // first output code | ||
36 | }; | ||
37 | |||
38 | struct UnicodeMapExt; | ||
39 | |||
40 | //------------------------------------------------------------------------ | ||
41 | |||
42 | class UnicodeMap { | ||
43 | public: | ||
44 | |||
45 | // Create the UnicodeMap specified by <encodingName>. Sets the | ||
46 | // initial reference count to 1. Returns NULL on failure. | ||
47 | static UnicodeMap *parse(GString *encodingNameA); | ||
48 | |||
49 | // Create a resident UnicodeMap. | ||
50 | UnicodeMap(char *encodingNameA, | ||
51 | UnicodeMapRange *rangesA, int lenA); | ||
52 | |||
53 | // Create a resident UnicodeMap that uses a function instead of a | ||
54 | // list of ranges. | ||
55 | UnicodeMap(char *encodingNameA, UnicodeMapFunc funcA); | ||
56 | |||
57 | ~UnicodeMap(); | ||
58 | |||
59 | void incRefCnt(); | ||
60 | void decRefCnt(); | ||
61 | |||
62 | GString *getEncodingName() { return encodingName; } | ||
63 | |||
64 | // Return true if this UnicodeMap matches the specified | ||
65 | // <encodingNameA>. | ||
66 | GBool match(GString *encodingNameA); | ||
67 | |||
68 | // Map Unicode to the target encoding. Fills in <buf> with the | ||
69 | // output and returns the number of bytes used. Output will be | ||
70 | // truncated at <bufSize> bytes. No string terminator is written. | ||
71 | // Returns 0 if no mapping is found. | ||
72 | int mapUnicode(Unicode u, char *buf, int bufSize); | ||
73 | |||
74 | private: | ||
75 | |||
76 | UnicodeMap(GString *encodingNameA); | ||
77 | |||
78 | GString *encodingName; | ||
79 | UnicodeMapKind kind; | ||
80 | union { | ||
81 | UnicodeMapRange *ranges;// (user, resident) | ||
82 | UnicodeMapFunc func;// (func) | ||
83 | }; | ||
84 | int len; // (user, resident) | ||
85 | UnicodeMapExt *eMaps; // (user) | ||
86 | int eMapsLen; // (user) | ||
87 | int refCnt; | ||
88 | }; | ||
89 | |||
90 | //------------------------------------------------------------------------ | ||
91 | |||
92 | #define unicodeMapCacheSize 4 | ||
93 | |||
94 | class UnicodeMapCache { | ||
95 | public: | ||
96 | |||
97 | UnicodeMapCache(); | ||
98 | ~UnicodeMapCache(); | ||
99 | |||
100 | // Get the UnicodeMap for <encodingName>. Increments its reference | ||
101 | // count; there will be one reference for the cache plus one for the | ||
102 | // caller of this function. Returns NULL on failure. | ||
103 | UnicodeMap *getUnicodeMap(GString *encodingName); | ||
104 | |||
105 | private: | ||
106 | |||
107 | UnicodeMap *cache[unicodeMapCacheSize]; | ||
108 | }; | ||
109 | |||
110 | #endif | ||