filters

UnicodeMap.h

00001 //========================================================================
00002 //
00003 // UnicodeMap.h
00004 //
00005 // Mapping from Unicode to an encoding.
00006 //
00007 // Copyright 2001-2002 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef UNICODEMAP_H
00012 #define UNICODEMAP_H
00013 
00014 #include <aconf.h>
00015 
00016 #ifdef USE_GCC_PRAGMAS
00017 #pragma interface
00018 #endif
00019 
00020 #include "gtypes.h"
00021 #include "CharTypes.h"
00022 
00023 class GString;
00024 
00025 //------------------------------------------------------------------------
00026 
00027 enum UnicodeMapKind {
00028   unicodeMapUser,       // read from a file
00029   unicodeMapResident,       // static list of ranges
00030   unicodeMapFunc        // function pointer
00031 };
00032 
00033 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
00034 
00035 struct UnicodeMapRange {
00036   Unicode start, end;       // range of Unicode chars
00037   Guint code, nBytes;       // first output code
00038 };
00039 
00040 struct UnicodeMapExt;
00041 
00042 //------------------------------------------------------------------------
00043 
00044 class UnicodeMap {
00045 public:
00046 
00047   // Create the UnicodeMap specified by <encodingName>.  Sets the
00048   // initial reference count to 1.  Returns NULL on failure.
00049   static UnicodeMap *parse(GString *encodingNameA);
00050 
00051   // Create a resident UnicodeMap.
00052   UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
00053          UnicodeMapRange *rangesA, int lenA);
00054 
00055   // Create a resident UnicodeMap that uses a function instead of a
00056   // list of ranges.
00057   UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
00058          UnicodeMapFunc funcA);
00059 
00060   ~UnicodeMap();
00061 
00062   void incRefCnt();
00063   void decRefCnt();
00064 
00065   GString *getEncodingName() { return encodingName; }
00066 
00067   GBool isUnicode() { return unicodeOut; }
00068 
00069   // Return true if this UnicodeMap matches the specified
00070   // <encodingNameA>.
00071   GBool match(GString *encodingNameA);
00072 
00073   // Map Unicode to the target encoding.  Fills in <buf> with the
00074   // output and returns the number of bytes used.  Output will be
00075   // truncated at <bufSize> bytes.  No string terminator is written.
00076   // Returns 0 if no mapping is found.
00077   int mapUnicode(Unicode u, char *buf, int bufSize);
00078 
00079 private:
00080 
00081   UnicodeMap(GString *encodingNameA);
00082 
00083   GString *encodingName;
00084   UnicodeMapKind kind;
00085   GBool unicodeOut;
00086   union {
00087     UnicodeMapRange *ranges;    // (user, resident)
00088     UnicodeMapFunc func;    // (func)
00089   };
00090   int len;          // (user, resident)
00091   UnicodeMapExt *eMaps;     // (user)
00092   int eMapsLen;         // (user)
00093   int refCnt;
00094 };
00095 
00096 //------------------------------------------------------------------------
00097 
00098 #define unicodeMapCacheSize 4
00099 
00100 class UnicodeMapCache {
00101 public:
00102 
00103   UnicodeMapCache();
00104   ~UnicodeMapCache();
00105 
00106   // Get the UnicodeMap for <encodingName>.  Increments its reference
00107   // count; there will be one reference for the cache plus one for the
00108   // caller of this function.  Returns NULL on failure.
00109   UnicodeMap *getUnicodeMap(GString *encodingName);
00110 
00111 private:
00112 
00113   UnicodeMap *cache[unicodeMapCacheSize];
00114 };
00115 
00116 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys