1 //========================================================================
5 // Mapping from Unicode to an encoding.
7 // Copyright 2001-2003 Glyph & Cog, LLC
9 //========================================================================
16 #ifdef USE_GCC_PRAGMAS
21 #include "CharTypes.h"
29 //------------------------------------------------------------------------
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
46 //------------------------------------------------------------------------
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
61 UnicodeMap(char *encodingNameA
, GBool unicodeOutA
,
62 UnicodeMapFunc funcA
);
69 GString
*getEncodingName() { return encodingName
; }
71 GBool
isUnicode() { return unicodeOut
; }
73 // Return true if this UnicodeMap matches the specified
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
);
85 UnicodeMap(GString
*encodingNameA
);
87 GString
*encodingName
;
91 UnicodeMapRange
*ranges
; // (user, resident)
92 UnicodeMapFunc func
; // (func)
94 int len
; // (user, resident)
95 UnicodeMapExt
*eMaps
; // (user)
96 int eMapsLen
; // (user)
103 //------------------------------------------------------------------------
105 #define unicodeMapCacheSize 4
107 class 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
);
120 UnicodeMap
*cache
[unicodeMapCacheSize
];