source: trunk/poppler/mypoppler/poppler/UnicodeMap.h @ 461

Last change on this file since 461 was 250, checked in by Eugene Romanenko, 13 years ago

PDF plugin: poppler library updated to version 0.8.3

File size: 2.9 KB
Line 
1//========================================================================
2//
3// UnicodeMap.h
4//
5// Mapping from Unicode to an encoding.
6//
7// Copyright 2001-2003 Glyph & Cog, LLC
8//
9//========================================================================
10
11#ifndef UNICODEMAP_H
12#define UNICODEMAP_H
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "poppler-config.h"
19#include "goo/gtypes.h"
20#include "CharTypes.h"
21
22#if MULTITHREADED
23#include "goo/GooMutex.h"
24#endif
25
26class GooString;
27
28//------------------------------------------------------------------------
29
30enum UnicodeMapKind {
31  unicodeMapUser,               // read from a file
32  unicodeMapResident,           // static list of ranges
33  unicodeMapFunc                // function pointer
34};
35
36typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
37
38struct UnicodeMapRange {
39  Unicode start, end;           // range of Unicode chars
40  Guint code, nBytes;           // first output code
41};
42
43struct UnicodeMapExt;
44
45//------------------------------------------------------------------------
46
47class UnicodeMap {
48public:
49
50  // Create the UnicodeMap specified by <encodingName>.  Sets the
51  // initial reference count to 1.  Returns NULL on failure.
52  static UnicodeMap *parse(GooString *encodingNameA);
53
54  // Create a resident UnicodeMap.
55  UnicodeMap(char *encodingNameA, GBool unicodeOutA,
56             UnicodeMapRange *rangesA, int lenA);
57
58  // Create a resident UnicodeMap that uses a function instead of a
59  // list of ranges.
60  UnicodeMap(char *encodingNameA, GBool unicodeOutA,
61             UnicodeMapFunc funcA);
62
63  ~UnicodeMap();
64
65  void incRefCnt();
66  void decRefCnt();
67
68  GooString *getEncodingName() { return encodingName; }
69
70  GBool isUnicode() { return unicodeOut; }
71
72  // Return true if this UnicodeMap matches the specified
73  // <encodingNameA>.
74  GBool match(GooString *encodingNameA);
75
76  // Map Unicode to the target encoding.  Fills in <buf> with the
77  // output and returns the number of bytes used.  Output will be
78  // truncated at <bufSize> bytes.  No string terminator is written.
79  // Returns 0 if no mapping is found.
80  int mapUnicode(Unicode u, char *buf, int bufSize);
81
82private:
83
84  UnicodeMap(GooString *encodingNameA);
85
86  GooString *encodingName;
87  UnicodeMapKind kind;
88  GBool unicodeOut;
89  union {
90    UnicodeMapRange *ranges;    // (user, resident)
91    UnicodeMapFunc func;        // (func)
92  };
93  int len;                      // (user, resident)
94  UnicodeMapExt *eMaps;         // (user)
95  int eMapsLen;                 // (user)
96  int refCnt;
97#if MULTITHREADED
98  GooMutex mutex;
99#endif
100};
101
102//------------------------------------------------------------------------
103
104#define unicodeMapCacheSize 4
105
106class UnicodeMapCache {
107public:
108
109  UnicodeMapCache();
110  ~UnicodeMapCache();
111
112  // Get the UnicodeMap for <encodingName>.  Increments its reference
113  // count; there will be one reference for the cache plus one for the
114  // caller of this function.  Returns NULL on failure.
115  UnicodeMap *getUnicodeMap(GooString *encodingName);
116
117private:
118
119  UnicodeMap *cache[unicodeMapCacheSize];
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.