CMap.h 4.68 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8
//========================================================================
//
// CMap.h
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================

9 10 11 12
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16
// Copyright (C) 2008 Koji Otani <sho@bbr.jp>
17
// Copyright (C) 2009, 2018 Albert Astals Cid <aacid@kde.org>
18
// Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
19 20 21 22 23 24
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
25 26 27 28 29 30 31 32 33 34 35
#ifndef CMAP_H
#define CMAP_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "poppler-config.h"
#include "goo/gtypes.h"
#include "CharTypes.h"

36
#ifdef MULTITHREADED
Albert Astals Cid's avatar
Albert Astals Cid committed
37
#include "goo/GooMutex.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
38 39 40
#endif

class GooString;
41
class Object;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
42 43
struct CMapVectorEntry;
class CMapCache;
44
class Stream;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
45 46 47 48 49 50

//------------------------------------------------------------------------

class CMap {
public:

51 52 53 54 55 56 57 58 59 60 61 62 63
  // Parse a CMap from <obj>, which can be a name or a stream.  Sets
  // the initial reference count to 1.  Returns NULL on failure.
  static CMap *parse(CMapCache *cache, GooString *collectionA, Object *obj);

  // Create the CMap specified by <collection> and <cMapName>.  Sets
  // the initial reference count to 1.  Returns NULL on failure.
  static CMap *parse(CMapCache *cache, GooString *collectionA,
		     GooString *cMapNameA);

  // Parse a CMap from <str>.  Sets the initial reference count to 1.
  // Returns NULL on failure.
  static CMap *parse(CMapCache *cache, GooString *collectionA, Stream *str);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
64
  // Create the CMap specified by <collection> and <cMapName>.  Sets
65 66 67 68
  // the initial reference count to 1.
  // Stream is a stream containing the CMap, can be NULL and 
  // this means the CMap will be searched in the CMap files
  // Returns NULL on failure.
Kristian Høgsberg's avatar
Kristian Høgsberg committed
69
  static CMap *parse(CMapCache *cache, GooString *collectionA,
70
		     GooString *cMapNameA, Stream *stream);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
71 72 73

  ~CMap();

74 75 76
  CMap(const CMap &) = delete;
  CMap& operator=(const CMap &) = delete;

Kristian Høgsberg's avatar
Kristian Høgsberg committed
77 78 79 80 81 82
  void incRefCnt();
  void decRefCnt();

  // Return collection name (<registry>-<ordering>).
  GooString *getCollection() { return collection; }

83 84
  GooString *getCMapName() { return cMapName; }

Kristian Høgsberg's avatar
Kristian Høgsberg committed
85 86 87 88 89
  // Return true if this CMap matches the specified <collectionA>, and
  // <cMapNameA>.
  GBool match(GooString *collectionA, GooString *cMapNameA);

  // Return the CID corresponding to the character code starting at
90 91 92
  // <s>, which contains <len> bytes.  Sets *<c> to the char code, and
  // *<nUsed> to the number of bytes used by the char code.
  CID getCID(char *s, int len, CharCode *c, int *nUsed);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
93 94 95 96

  // Return the writing mode (0=horizontal, 1=vertical).
  int getWMode() { return wMode; }

97 98
  void setReverseMap(Guint *rmap, Guint rmapSize, Guint ncand);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
99 100
private:

101
  void parse2(CMapCache *cache, int (*getCharFunc)(void *), void *data);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
102 103 104
  CMap(GooString *collectionA, GooString *cMapNameA);
  CMap(GooString *collectionA, GooString *cMapNameA, int wModeA);
  void useCMap(CMapCache *cache, char *useName);
105
  void useCMap(CMapCache *cache, Object *obj);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
106 107 108
  void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src);
  void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID);
  void freeCMapVector(CMapVectorEntry *vec);
109 110
  void setReverseMapVector(Guint startCode, CMapVectorEntry *vec,
          Guint *rmap, Guint rmapSize, Guint ncand);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
111 112 113

  GooString *collection;
  GooString *cMapName;
114 115
  GBool isIdent;		// true if this CMap is an identity mapping,
				//   or is based on one (via usecmap)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
116 117 118 119
  int wMode;			// writing mode (0=horizontal, 1=vertical)
  CMapVectorEntry *vector;	// vector for first byte (NULL for
				//   identity CMap)
  int refCnt;
120
#ifdef MULTITHREADED
Kristian Høgsberg's avatar
Kristian Høgsberg committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134
  GooMutex mutex;
#endif
};

//------------------------------------------------------------------------

#define cMapCacheSize 4

class CMapCache {
public:

  CMapCache();
  ~CMapCache();

135 136 137
  CMapCache(const CMapCache &) = delete;
  CMapCache& operator=(const CMapCache &) = delete;

Kristian Høgsberg's avatar
Kristian Høgsberg committed
138 139
  // Get the <cMapName> CMap for the specified character collection.
  // Increments its reference count; there will be one reference for
140 141 142 143 144
  // the cache plus one for the caller of this function.
  // Stream is a stream containing the CMap, can be NULL and 
  // this means the CMap will be searched in the CMap files
  // Returns NULL on failure.
  CMap *getCMap(GooString *collection, GooString *cMapName, Stream *stream);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
145 146 147 148 149 150 151

private:

  CMap *cache[cMapCacheSize];
};

#endif