Coverage Report

Created: 2025-07-12 07:51

/src/xpdf-4.05/xpdf/CharCodeToUnicode.h
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// CharCodeToUnicode.h
4
//
5
// Mapping from character codes to Unicode.
6
//
7
// Copyright 2001-2003 Glyph & Cog, LLC
8
//
9
//========================================================================
10
11
#ifndef CHARCODETOUNICODE_H
12
#define CHARCODETOUNICODE_H
13
14
#include <aconf.h>
15
16
#include "CharTypes.h"
17
18
#if MULTITHREADED
19
#include "GMutex.h"
20
#endif
21
22
struct CharCodeToUnicodeString;
23
24
//------------------------------------------------------------------------
25
26
class CharCodeToUnicode {
27
public:
28
29
  // Create an identity mapping (Unicode = CharCode).
30
  static CharCodeToUnicode *makeIdentityMapping();
31
32
  // Read the CID-to-Unicode mapping for <collection> from the file
33
  // specified by <fileName>.  Sets the initial reference count to 1.
34
  // Returns NULL on failure.
35
  static CharCodeToUnicode *parseCIDToUnicode(GString *fileName,
36
                GString *collection);
37
38
  // Create a Unicode-to-Unicode mapping from the file specified by
39
  // <fileName>.  Sets the initial reference count to 1.  Returns NULL
40
  // on failure.
41
  static CharCodeToUnicode *parseUnicodeToUnicode(GString *fileName);
42
43
  // Create the CharCode-to-Unicode mapping for an 8-bit font.
44
  // <toUnicode> is an array of 256 Unicode indexes.  Sets the initial
45
  // reference count to 1.
46
  static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
47
48
  // Create the CharCode-to-Unicode mapping for a 16-bit font.
49
  // <toUnicode> is an array of 65536 Unicode indexes.  Sets the
50
  // initial reference count to 1.
51
  static CharCodeToUnicode *make16BitToUnicode(Unicode *toUnicode);
52
53
  // Parse a ToUnicode CMap for an 8- or 16-bit font.
54
  static CharCodeToUnicode *parseCMap(GString *buf, int nBits);
55
56
  // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
57
  // <this>.
58
  void mergeCMap(GString *buf, int nBits);
59
60
  ~CharCodeToUnicode();
61
62
  void incRefCnt();
63
  void decRefCnt();
64
65
  // Return true if this mapping matches the specified <tagA>.
66
  GBool match(GString *tagA);
67
68
  // Set the mapping for <c>.
69
  void setMapping(CharCode c, Unicode *u, int len);
70
71
  // Map a CharCode to Unicode.
72
  int mapToUnicode(CharCode c, Unicode *u, int size);
73
74
  // Return the mapping's length, i.e., one more than the max char
75
  // code supported by the mapping.
76
0
  CharCode getLength() { return mapLen; }
77
78
0
  GBool isIdentity() { return !map; }
79
80
private:
81
82
  GBool parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
83
  void addMapping(CharCode code, char *uStr, int n, int offset);
84
  int parseUTF16String(char *uStr, int n, Unicode *uOut);
85
  void addMappingInt(CharCode code, Unicode u);
86
  CharCodeToUnicode();
87
  CharCodeToUnicode(GString *tagA);
88
  CharCodeToUnicode(GString *tagA, Unicode *mapA,
89
        CharCode mapLenA, GBool copyMap,
90
        CharCodeToUnicodeString *sMapA,
91
        int sMapLenA, int sMapSizeA);
92
93
  GString *tag;
94
  Unicode *map;
95
  CharCode mapLen;
96
  CharCodeToUnicodeString *sMap;
97
  int sMapLen, sMapSize;
98
#if MULTITHREADED
99
  GAtomicCounter refCnt;
100
#else
101
  int refCnt;
102
#endif
103
};
104
105
//------------------------------------------------------------------------
106
107
class CharCodeToUnicodeCache {
108
public:
109
110
  CharCodeToUnicodeCache(int sizeA);
111
  ~CharCodeToUnicodeCache();
112
113
  // Get the CharCodeToUnicode object for <tag>.  Increments its
114
  // reference count; there will be one reference for the cache plus
115
  // one for the caller of this function.  Returns NULL on failure.
116
  CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
117
118
  // Insert <ctu> into the cache, in the most-recently-used position.
119
  void add(CharCodeToUnicode *ctu);
120
121
private:
122
123
  CharCodeToUnicode **cache;
124
  int size;
125
};
126
127
#endif