i hope the node casts are correct here.
[AROS-Contrib.git] / arospdf / xpdf / UnicodeMap.h
blob0f86101e06c8e20191d23275fe068e508a4f7e1f
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 #include <aconf.h>
16 #ifdef USE_GCC_PRAGMAS
17 #pragma interface
18 #endif
20 #include "gtypes.h"
21 #include "CharTypes.h"
23 #if MULTITHREADED
24 #include "GMutex.h"
25 #endif
27 class GString;
29 //------------------------------------------------------------------------
31 enum UnicodeMapKind {
32 unicodeMapUser, // read from a file
33 unicodeMapResident, // static list of ranges
34 unicodeMapFunc // function pointer
37 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
39 struct UnicodeMapRange {
40 Unicode start, end; // range of Unicode chars
41 Guint code, nBytes; // first output code
44 struct UnicodeMapExt;
46 //------------------------------------------------------------------------
48 class UnicodeMap {
49 public:
51 // Create the UnicodeMap specified by <encodingName>. Sets the
52 // initial reference count to 1. Returns NULL on failure.
53 static UnicodeMap *parse(GString *encodingNameA);
55 // Create a resident UnicodeMap.
56 UnicodeMap(char *encodingNameA, GBool unicodeOutA,
57 UnicodeMapRange *rangesA, int lenA);
59 // Create a resident UnicodeMap that uses a function instead of a
60 // list of ranges.
61 UnicodeMap(char *encodingNameA, GBool unicodeOutA,
62 UnicodeMapFunc funcA);
64 ~UnicodeMap();
66 void incRefCnt();
67 void decRefCnt();
69 GString *getEncodingName() { return encodingName; }
71 GBool isUnicode() { return unicodeOut; }
73 // Return true if this UnicodeMap matches the specified
74 // <encodingNameA>.
75 GBool match(GString *encodingNameA);
77 // Map Unicode to the target encoding. Fills in <buf> with the
78 // output and returns the number of bytes used. Output will be
79 // truncated at <bufSize> bytes. No string terminator is written.
80 // Returns 0 if no mapping is found.
81 int mapUnicode(Unicode u, char *buf, int bufSize);
83 private:
85 UnicodeMap(GString *encodingNameA);
87 GString *encodingName;
88 UnicodeMapKind kind;
89 GBool unicodeOut;
90 union {
91 UnicodeMapRange *ranges; // (user, resident)
92 UnicodeMapFunc func; // (func)
94 int len; // (user, resident)
95 UnicodeMapExt *eMaps; // (user)
96 int eMapsLen; // (user)
97 int refCnt;
98 #if MULTITHREADED
99 GMutex mutex;
100 #endif
103 //------------------------------------------------------------------------
105 #define unicodeMapCacheSize 4
107 class UnicodeMapCache {
108 public:
110 UnicodeMapCache();
111 ~UnicodeMapCache();
113 // Get the UnicodeMap for <encodingName>. Increments its reference
114 // count; there will be one reference for the cache plus one for the
115 // caller of this function. Returns NULL on failure.
116 UnicodeMap *getUnicodeMap(GString *encodingName);
118 private:
120 UnicodeMap *cache[unicodeMapCacheSize];
123 #endif