1
//========================================================================
5
// Mapping from Unicode to an encoding.
7
// Copyright 2001-2002 Glyph & Cog, LLC
9
//========================================================================
16
#ifdef USE_GCC_PRAGMAS
21
#include "CharTypes.h"
25
//------------------------------------------------------------------------
28
unicodeMapUser, // read from a file
29
unicodeMapResident, // static list of ranges
30
unicodeMapFunc // function pointer
33
typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
35
struct UnicodeMapRange {
36
Unicode start, end; // range of Unicode chars
37
Guint code, nBytes; // first output code
42
//------------------------------------------------------------------------
47
// Create the UnicodeMap specified by <encodingName>. Sets the
48
// initial reference count to 1. Returns NULL on failure.
49
static UnicodeMap *parse(GString *encodingNameA);
51
// Create a resident UnicodeMap.
52
UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
53
UnicodeMapRange *rangesA, int lenA);
55
// Create a resident UnicodeMap that uses a function instead of a
57
UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
58
UnicodeMapFunc funcA);
65
GString *getEncodingName() { return encodingName; }
67
GBool isUnicode() { return unicodeOut; }
69
// Return true if this UnicodeMap matches the specified
71
GBool match(GString *encodingNameA);
73
// Map Unicode to the target encoding. Fills in <buf> with the
74
// output and returns the number of bytes used. Output will be
75
// truncated at <bufSize> bytes. No string terminator is written.
76
// Returns 0 if no mapping is found.
77
int mapUnicode(Unicode u, char *buf, int bufSize);
81
UnicodeMap(GString *encodingNameA);
83
GString *encodingName;
87
UnicodeMapRange *ranges; // (user, resident)
88
UnicodeMapFunc func; // (func)
90
int len; // (user, resident)
91
UnicodeMapExt *eMaps; // (user)
92
int eMapsLen; // (user)
96
//------------------------------------------------------------------------
98
#define unicodeMapCacheSize 4
100
class UnicodeMapCache {
106
// Get the UnicodeMap for <encodingName>. Increments its reference
107
// count; there will be one reference for the cache plus one for the
108
// caller of this function. Returns NULL on failure.
109
UnicodeMap *getUnicodeMap(GString *encodingName);
113
UnicodeMap *cache[unicodeMapCacheSize];