beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / CharCodeToUnicode.h
blob1672105a8f401b158141bb368e9e585e72e256ed
1 //========================================================================
2 //
3 // CharCodeToUnicode.h
4 //
5 // Mapping from character codes to Unicode.
6 //
7 // Copyright 2001-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
11 //========================================================================
13 // Modified under the Poppler project - http://poppler.freedesktop.org
15 // All changes made under the Poppler project to this file are licensed
16 // under GPL version 2 or later
18 // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
19 // Copyright (C) 2007 Koji Otani <sho@bbr.jp>
20 // Copyright (C) 2008, 2011, 2012 Albert Astals Cid <aacid@kde.org>
22 // To see a description of the changes please see the Changelog file that
23 // came with your tarball or type make ChangeLog if you are building from git
25 //========================================================================
27 #ifndef CHARCODETOUNICODE_H
28 #define CHARCODETOUNICODE_H
30 #ifdef USE_GCC_PRAGMAS
31 #pragma interface
32 #endif
34 #include "poppler-config.h"
35 #include "CharTypes.h"
36 #include "goo/gtypes.h"
38 #if MULTITHREADED
39 #include "goo/GooMutex.h"
40 #endif
42 struct CharCodeToUnicodeString;
43 class GooString;
45 //------------------------------------------------------------------------
47 class CharCodeToUnicode {
48 friend class UnicodeToCharCode;
49 public:
51 // Create an identity mapping (Unicode = CharCode).
52 static CharCodeToUnicode *makeIdentityMapping();
54 // Read the CID-to-Unicode mapping for <collection> from the file
55 // specified by <fileName>. Sets the initial reference count to 1.
56 // Returns NULL on failure.
57 static CharCodeToUnicode *parseCIDToUnicode(GooString *fileName,
58 GooString *collection);
60 // Create a Unicode-to-Unicode mapping from the file specified by
61 // <fileName>. Sets the initial reference count to 1. Returns NULL
62 // on failure.
63 static CharCodeToUnicode *parseUnicodeToUnicode(GooString *fileName);
65 // Create the CharCode-to-Unicode mapping for an 8-bit font.
66 // <toUnicode> is an array of 256 Unicode indexes. Sets the initial
67 // reference count to 1.
68 static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
70 // Parse a ToUnicode CMap for an 8- or 16-bit font.
71 static CharCodeToUnicode *parseCMap(GooString *buf, int nBits);
72 static CharCodeToUnicode *parseCMapFromFile(GooString *fileName, int nBits);
74 // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
75 // <this>.
76 void mergeCMap(GooString *buf, int nBits);
78 ~CharCodeToUnicode();
80 void incRefCnt();
81 void decRefCnt();
83 // Return true if this mapping matches the specified <tagA>.
84 GBool match(GooString *tagA);
86 // Set the mapping for <c>.
87 void setMapping(CharCode c, Unicode *u, int len);
89 // Map a CharCode to Unicode. Returns a pointer in u to internal storage
90 // so never store the pointers it returns, just the data, otherwise
91 // your pointed values might get changed by future calls
92 int mapToUnicode(CharCode c, Unicode **u);
94 // Map a Unicode to CharCode.
95 int mapToCharCode(Unicode* u, CharCode *c, int usize);
97 // Return the mapping's length, i.e., one more than the max char
98 // code supported by the mapping.
99 CharCode getLength() { return mapLen; }
101 private:
103 void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
104 void addMapping(CharCode code, char *uStr, int n, int offset);
105 CharCodeToUnicode();
106 CharCodeToUnicode(GooString *tagA);
107 CharCodeToUnicode(GooString *tagA, Unicode *mapA,
108 CharCode mapLenA, GBool copyMap,
109 CharCodeToUnicodeString *sMapA,
110 int sMapLenA, int sMapSizeA);
112 GooString *tag;
113 Unicode *map;
114 CharCode mapLen;
115 CharCodeToUnicodeString *sMap;
116 int sMapLen, sMapSize;
117 int refCnt;
118 GBool isIdentity;
119 #if MULTITHREADED
120 GooMutex mutex;
121 #endif
124 //------------------------------------------------------------------------
126 class CharCodeToUnicodeCache {
127 public:
129 CharCodeToUnicodeCache(int sizeA);
130 ~CharCodeToUnicodeCache();
132 // Get the CharCodeToUnicode object for <tag>. Increments its
133 // reference count; there will be one reference for the cache plus
134 // one for the caller of this function. Returns NULL on failure.
135 CharCodeToUnicode *getCharCodeToUnicode(GooString *tag);
137 // Insert <ctu> into the cache, in the most-recently-used position.
138 void add(CharCodeToUnicode *ctu);
140 private:
142 CharCodeToUnicode **cache;
143 int size;
146 #endif