Coverage Report

Created: 2026-09-01 07:01

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