Coverage Report

Created: 2025-07-12 06:54

/src/xpdf-4.05/xpdf/UnicodeMap.h
Line
Count
Source (jump to first uncovered 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
#include <aconf.h>
15
16
#include "gtypes.h"
17
#include "CharTypes.h"
18
19
#if MULTITHREADED
20
#include "GMutex.h"
21
#endif
22
23
class GString;
24
25
//------------------------------------------------------------------------
26
27
enum UnicodeMapKind {
28
  unicodeMapUser,   // read from a file
29
  unicodeMapResident,   // static list of ranges
30
  unicodeMapFunc    // function pointer
31
};
32
33
typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
34
35
struct UnicodeMapRange {
36
  Unicode start, end;   // range of Unicode chars
37
  Guint code, nBytes;   // first output code
38
};
39
40
struct UnicodeMapExt;
41
42
//------------------------------------------------------------------------
43
44
class UnicodeMap {
45
public:
46
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);
50
51
  // Create a resident UnicodeMap.
52
  UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
53
       UnicodeMapRange *rangesA, int lenA);
54
55
  // Create a resident UnicodeMap that uses a function instead of a
56
  // list of ranges.
57
  UnicodeMap(const char *encodingNameA, GBool unicodeOutA,
58
       UnicodeMapFunc funcA);
59
60
  ~UnicodeMap();
61
62
  void incRefCnt();
63
  void decRefCnt();
64
65
14.0k
  GString *getEncodingName() { return encodingName; }
66
67
0
  GBool isUnicode() { return unicodeOut; }
68
69
  // Return true if this UnicodeMap matches the specified
70
  // <encodingNameA>.
71
  GBool match(GString *encodingNameA);
72
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);
78
79
private:
80
81
  UnicodeMap(GString *encodingNameA);
82
83
  GString *encodingName;
84
  UnicodeMapKind kind;
85
  GBool unicodeOut;
86
  union {
87
    UnicodeMapRange *ranges;  // (user, resident)
88
    UnicodeMapFunc func;  // (func)
89
  };
90
  int len;      // (user, resident)
91
  UnicodeMapExt *eMaps;   // (user)
92
  int eMapsLen;     // (user)
93
#if MULTITHREADED
94
  GAtomicCounter refCnt;
95
#else
96
  int refCnt;
97
#endif
98
};
99
100
//------------------------------------------------------------------------
101
102
23.4k
#define unicodeMapCacheSize 4
103
104
class UnicodeMapCache {
105
public:
106
107
  UnicodeMapCache();
108
  ~UnicodeMapCache();
109
110
  // Get the UnicodeMap for <encodingName>.  Increments its reference
111
  // count; there will be one reference for the cache plus one for the
112
  // caller of this function.  Returns NULL on failure.
113
  UnicodeMap *getUnicodeMap(GString *encodingName);
114
115
private:
116
117
  UnicodeMap *cache[unicodeMapCacheSize];
118
};
119
120
#endif