1 //========================================================================
5 // Mapping from character codes to Unicode.
7 // Copyright 2001-2003 Glyph & Cog, LLC
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
34 #include "poppler-config.h"
35 #include "CharTypes.h"
36 #include "goo/gtypes.h"
39 #include "goo/GooMutex.h"
42 struct CharCodeToUnicodeString
;
45 //------------------------------------------------------------------------
47 class CharCodeToUnicode
{
48 friend class UnicodeToCharCode
;
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
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
76 void mergeCMap(GooString
*buf
, int nBits
);
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
; }
103 void parseCMap1(int (*getCharFunc
)(void *), void *data
, int nBits
);
104 void addMapping(CharCode code
, char *uStr
, int n
, int offset
);
106 CharCodeToUnicode(GooString
*tagA
);
107 CharCodeToUnicode(GooString
*tagA
, Unicode
*mapA
,
108 CharCode mapLenA
, GBool copyMap
,
109 CharCodeToUnicodeString
*sMapA
,
110 int sMapLenA
, int sMapSizeA
);
115 CharCodeToUnicodeString
*sMap
;
116 int sMapLen
, sMapSize
;
124 //------------------------------------------------------------------------
126 class CharCodeToUnicodeCache
{
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
);
142 CharCodeToUnicode
**cache
;