a patch for ttc fonts with bad index
[luatex.git] / source / libs / poppler / poppler-0.36.0 / poppler / UnicodeMap.h
blobba7df2cfb993d97247f6aded85dc91b79afe4718
1 //========================================================================
2 //
3 // UnicodeMap.h
4 //
5 // Mapping from Unicode to an encoding.
6 //
7 // Copyright 2001-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
11 #ifndef UNICODEMAP_H
12 #define UNICODEMAP_H
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "poppler-config.h"
19 #include "goo/gtypes.h"
20 #include "CharTypes.h"
22 #if MULTITHREADED
23 #include "goo/GooMutex.h"
24 #endif
26 class GooString;
28 //------------------------------------------------------------------------
30 enum UnicodeMapKind {
31 unicodeMapUser, // read from a file
32 unicodeMapResident, // static list of ranges
33 unicodeMapFunc // function pointer
36 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
38 struct UnicodeMapRange {
39 Unicode start, end; // range of Unicode chars
40 Guint code, nBytes; // first output code
43 struct UnicodeMapExt;
45 //------------------------------------------------------------------------
47 class UnicodeMap {
48 public:
50 // Create the UnicodeMap specified by <encodingName>. Sets the
51 // initial reference count to 1. Returns NULL on failure.
52 static UnicodeMap *parse(GooString *encodingNameA);
54 // Create a resident UnicodeMap.
55 UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
56 UnicodeMapRange *rangesA, int lenA);
58 // Create a resident UnicodeMap that uses a function instead of a
59 // list of ranges.
60 UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
61 UnicodeMapFunc funcA);
63 ~UnicodeMap();
65 void incRefCnt();
66 void decRefCnt();
68 GooString *getEncodingName() { return encodingName; }
70 GBool isUnicode() { return unicodeOut; }
72 // Return true if this UnicodeMap matches the specified
73 // <encodingNameA>.
74 GBool match(GooString *encodingNameA);
76 // Map Unicode to the target encoding. Fills in <buf> with the
77 // output and returns the number of bytes used. Output will be
78 // truncated at <bufSize> bytes. No string terminator is written.
79 // Returns 0 if no mapping is found.
80 int mapUnicode(Unicode u, char *buf, int bufSize);
82 private:
84 UnicodeMap(GooString *encodingNameA);
86 GooString *encodingName;
87 UnicodeMapKind kind;
88 GBool unicodeOut;
89 union {
90 UnicodeMapRange *ranges; // (user, resident)
91 UnicodeMapFunc func; // (func)
93 int len; // (user, resident)
94 UnicodeMapExt *eMaps; // (user)
95 int eMapsLen; // (user)
96 int refCnt;
97 #if MULTITHREADED
98 GooMutex mutex;
99 #endif
102 //------------------------------------------------------------------------
104 #define unicodeMapCacheSize 4
106 class UnicodeMapCache {
107 public:
109 UnicodeMapCache();
110 ~UnicodeMapCache();
112 // Get the UnicodeMap for <encodingName>. Increments its reference
113 // count; there will be one reference for the cache plus one for the
114 // caller of this function. Returns NULL on failure.
115 UnicodeMap *getUnicodeMap(GooString *encodingName);
117 private:
119 UnicodeMap *cache[unicodeMapCacheSize];
122 #endif