Coverage Report

Created: 2025-07-12 06:54

/src/xpdf-4.05/xpdf/CMap.h
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// CMap.h
4
//
5
// Copyright 2001-2003 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#ifndef CMAP_H
10
#define CMAP_H
11
12
#include <aconf.h>
13
14
#include "gtypes.h"
15
#include "CharTypes.h"
16
17
#if MULTITHREADED
18
#include "GMutex.h"
19
#endif
20
21
class GString;
22
class Object;
23
class Stream;
24
struct CMapVectorEntry;
25
class CMapCache;
26
27
//------------------------------------------------------------------------
28
29
class CMap {
30
public:
31
32
  // Parse a CMap from <obj>, which can be a name or a stream.  Sets
33
  // the initial reference count to 1.  Returns NULL on failure.
34
  static CMap *parse(CMapCache *cache, GString *collectionA, Object *obj);
35
36
  // Create the CMap specified by <collection> and <cMapName>.  Sets
37
  // the initial reference count to 1.  Returns NULL on failure.
38
  static CMap *parse(CMapCache *cache, GString *collectionA,
39
         GString *cMapNameA);
40
41
  // Parse a CMap from <str>.  Sets the initial reference count to 1.
42
  // Returns NULL on failure.
43
  static CMap *parse(CMapCache *cache, GString *collectionA, Stream *str);
44
45
  ~CMap();
46
47
  void incRefCnt();
48
  void decRefCnt();
49
50
  // Return collection name (<registry>-<ordering>).
51
0
  GString *getCollection() { return collection; }
52
53
  // Return true if this CMap matches the specified <collectionA>, and
54
  // <cMapNameA>.
55
  GBool match(GString *collectionA, GString *cMapNameA);
56
57
  // Return the CID corresponding to the character code starting at
58
  // <s>, which contains <len> bytes.  Sets *<c> to the char code, and
59
  // *<nUsed> to the number of bytes used by the char code.
60
  CID getCID(char *s, int len, CharCode *c, int *nUsed);
61
62
  // Return the writing mode (0=horizontal, 1=vertical).
63
0
  int getWMode() { return wMode; }
64
65
private:
66
67
  void parse2(CMapCache *cache, int (*getCharFunc)(void *), void *data);
68
  CMap(GString *collectionA, GString *cMapNameA);
69
  CMap(GString *collectionA, GString *cMapNameA, int wModeA);
70
  void useCMap(CMapCache *cache, char *useName);
71
  void useCMap(CMapCache *cache, Object *obj);
72
  void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src);
73
  void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID);
74
  void freeCMapVector(CMapVectorEntry *vec);
75
76
  GString *collection;
77
  GString *cMapName;
78
  GBool isIdent;    // true if this CMap is an identity mapping,
79
        //   or is based on one (via usecmap)
80
  int wMode;      // writing mode (0=horizontal, 1=vertical)
81
  CMapVectorEntry *vector;  // vector for first byte (NULL for
82
        //   identity CMap)
83
#if MULTITHREADED
84
  GAtomicCounter refCnt;
85
#else
86
  int refCnt;
87
#endif
88
};
89
90
//------------------------------------------------------------------------
91
92
23.4k
#define cMapCacheSize 4
93
94
class CMapCache {
95
public:
96
97
  CMapCache();
98
  ~CMapCache();
99
100
  // Get the <cMapName> CMap for the specified character collection.
101
  // Increments its reference count; there will be one reference for
102
  // the cache plus one for the caller of this function.  Returns NULL
103
  // on failure.
104
  CMap *getCMap(GString *collection, GString *cMapName);
105
106
private:
107
108
  CMap *cache[cMapCacheSize];
109
};
110
111
#endif