~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/UnicodeMap.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
26
class GooString;
 
27
 
 
28
//------------------------------------------------------------------------
 
29
 
 
30
enum UnicodeMapKind {
 
31
  unicodeMapUser,               // read from a file
 
32
  unicodeMapResident,           // static list of ranges
 
33
  unicodeMapFunc                // function pointer
 
34
};
 
35
 
 
36
typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
 
37
 
 
38
struct UnicodeMapRange {
 
39
  Unicode start, end;           // range of Unicode chars
 
40
  Guint code, nBytes;           // first output code
 
41
};
 
42
 
 
43
struct UnicodeMapExt;
 
44
 
 
45
//------------------------------------------------------------------------
 
46
 
 
47
class UnicodeMap {
 
48
public:
 
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
 
 
82
private:
 
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
 
 
106
class UnicodeMapCache {
 
107
public:
 
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
 
 
117
private:
 
118
 
 
119
  UnicodeMap *cache[unicodeMapCacheSize];
 
120
};
 
121
 
 
122
#endif