beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / CMap.h
blobf4f5a9141c83fffaef46ccd8b922ba151dc2d259
1 //========================================================================
2 //
3 // CMap.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2008 Koji Otani <sho@bbr.jp>
17 // Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
18 // Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
20 // To see a description of the changes please see the Changelog file that
21 // came with your tarball or type make ChangeLog if you are building from git
23 //========================================================================
25 #ifndef CMAP_H
26 #define CMAP_H
28 #ifdef USE_GCC_PRAGMAS
29 #pragma interface
30 #endif
32 #include "poppler-config.h"
33 #include "goo/gtypes.h"
34 #include "CharTypes.h"
36 #if MULTITHREADED
37 #include "goo/GooMutex.h"
38 #endif
40 class GooString;
41 class Object;
42 struct CMapVectorEntry;
43 class CMapCache;
44 class Stream;
46 //------------------------------------------------------------------------
48 class CMap {
49 public:
51 // Parse a CMap from <obj>, which can be a name or a stream. Sets
52 // the initial reference count to 1. Returns NULL on failure.
53 static CMap *parse(CMapCache *cache, GooString *collectionA, Object *obj);
55 // Create the CMap specified by <collection> and <cMapName>. Sets
56 // the initial reference count to 1. Returns NULL on failure.
57 static CMap *parse(CMapCache *cache, GooString *collectionA,
58 GooString *cMapNameA);
60 // Parse a CMap from <str>. Sets the initial reference count to 1.
61 // Returns NULL on failure.
62 static CMap *parse(CMapCache *cache, GooString *collectionA, Stream *str);
64 // Create the CMap specified by <collection> and <cMapName>. Sets
65 // the initial reference count to 1.
66 // Stream is a stream containing the CMap, can be NULL and
67 // this means the CMap will be searched in the CMap files
68 // Returns NULL on failure.
69 static CMap *parse(CMapCache *cache, GooString *collectionA,
70 GooString *cMapNameA, Stream *stream);
72 ~CMap();
74 void incRefCnt();
75 void decRefCnt();
77 // Return collection name (<registry>-<ordering>).
78 GooString *getCollection() { return collection; }
80 GooString *getCMapName() { return cMapName; }
82 // Return true if this CMap matches the specified <collectionA>, and
83 // <cMapNameA>.
84 GBool match(GooString *collectionA, GooString *cMapNameA);
86 // Return the CID corresponding to the character code starting at
87 // <s>, which contains <len> bytes. Sets *<c> to the char code, and
88 // *<nUsed> to the number of bytes used by the char code.
89 CID getCID(char *s, int len, CharCode *c, int *nUsed);
91 // Return the writing mode (0=horizontal, 1=vertical).
92 int getWMode() { return wMode; }
94 void setReverseMap(Guint *rmap, Guint rmapSize, Guint ncand);
96 private:
98 void parse2(CMapCache *cache, int (*getCharFunc)(void *), void *data);
99 CMap(GooString *collectionA, GooString *cMapNameA);
100 CMap(GooString *collectionA, GooString *cMapNameA, int wModeA);
101 void useCMap(CMapCache *cache, char *useName);
102 void useCMap(CMapCache *cache, Object *obj);
103 void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src);
104 void addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID);
105 void freeCMapVector(CMapVectorEntry *vec);
106 void setReverseMapVector(Guint startCode, CMapVectorEntry *vec,
107 Guint *rmap, Guint rmapSize, Guint ncand);
109 GooString *collection;
110 GooString *cMapName;
111 GBool isIdent; // true if this CMap is an identity mapping,
112 // or is based on one (via usecmap)
113 int wMode; // writing mode (0=horizontal, 1=vertical)
114 CMapVectorEntry *vector; // vector for first byte (NULL for
115 // identity CMap)
116 int refCnt;
117 #if MULTITHREADED
118 GooMutex mutex;
119 #endif
122 //------------------------------------------------------------------------
124 #define cMapCacheSize 4
126 class CMapCache {
127 public:
129 CMapCache();
130 ~CMapCache();
132 // Get the <cMapName> CMap for the specified character collection.
133 // Increments its reference count; there will be one reference for
134 // the cache plus one for the caller of this function.
135 // Stream is a stream containing the CMap, can be NULL and
136 // this means the CMap will be searched in the CMap files
137 // Returns NULL on failure.
138 CMap *getCMap(GooString *collection, GooString *cMapName, Stream *stream);
140 private:
142 CMap *cache[cMapCacheSize];
145 #endif