1 //========================================================================
5 // Mapping from Unicode to an encoding.
7 // Copyright 2001-2002 Glyph & Cog, LLC
9 //========================================================================
19 #include "CharTypes.h"
23 //------------------------------------------------------------------------
26 unicodeMapUser, // read from a file
27 unicodeMapResident, // static list of ranges
28 unicodeMapFunc // function pointer
31 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
33 struct UnicodeMapRange {
34 Unicode start, end; // range of Unicode chars
35 Guint code, nBytes; // first output code
40 //------------------------------------------------------------------------
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);
49 // Create a resident UnicodeMap.
50 UnicodeMap(char *encodingNameA,
51 UnicodeMapRange *rangesA, int lenA);
53 // Create a resident UnicodeMap that uses a function instead of a
55 UnicodeMap(char *encodingNameA, UnicodeMapFunc funcA);
62 GString *getEncodingName() { return encodingName; }
64 // Return true if this UnicodeMap matches the specified
66 GBool match(GString *encodingNameA);
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);
76 UnicodeMap(GString *encodingNameA);
78 GString *encodingName;
81 UnicodeMapRange *ranges; // (user, resident)
82 UnicodeMapFunc func; // (func)
84 int len; // (user, resident)
85 UnicodeMapExt *eMaps; // (user)
86 int eMapsLen; // (user)
90 //------------------------------------------------------------------------
92 #define unicodeMapCacheSize 4
94 class UnicodeMapCache {
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);
107 UnicodeMap *cache[unicodeMapCacheSize];