1 //========================================================================
5 // Mapping from character codes to Unicode.
7 // Copyright 2001-2003 Glyph & Cog, LLC
9 //========================================================================
11 #ifndef CHARCODETOUNICODE_H
12 #define CHARCODETOUNICODE_H
16 #ifdef USE_GCC_PRAGMAS
20 #include "CharTypes.h"
26 struct CharCodeToUnicodeString;
28 //------------------------------------------------------------------------
30 class CharCodeToUnicode {
33 // Read the CID-to-Unicode mapping for <collection> from the file
34 // specified by <fileName>. Sets the initial reference count to 1.
35 // Returns NULL on failure.
36 static CharCodeToUnicode *parseCIDToUnicode(GString *fileName,
39 // Create a Unicode-to-Unicode mapping from the file specified by
40 // <fileName>. Sets the initial reference count to 1. Returns NULL
42 static CharCodeToUnicode *parseUnicodeToUnicode(GString *fileName);
44 // Create the CharCode-to-Unicode mapping for an 8-bit font.
45 // <toUnicode> is an array of 256 Unicode indexes. Sets the initial
46 // reference count to 1.
47 static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
49 // Parse a ToUnicode CMap for an 8- or 16-bit font.
50 static CharCodeToUnicode *parseCMap(GString *buf, int nBits);
52 // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
54 void mergeCMap(GString *buf, int nBits);
61 // Return true if this mapping matches the specified <tagA>.
62 GBool match(GString *tagA);
64 // Set the mapping for <c>.
65 void setMapping(CharCode c, Unicode *u, int len);
67 // Map a CharCode to Unicode.
68 int mapToUnicode(CharCode c, Unicode *u, int size);
70 // Return the mapping's length, i.e., one more than the max char
71 // code supported by the mapping.
72 CharCode getLength() { return mapLen; }
76 void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
77 void addMapping(CharCode code, char *uStr, int n, int offset);
78 CharCodeToUnicode(GString *tagA);
79 CharCodeToUnicode(GString *tagA, Unicode *mapA,
80 CharCode mapLenA, GBool copyMap,
81 CharCodeToUnicodeString *sMapA,
82 int sMapLenA, int sMapSizeA);
87 CharCodeToUnicodeString *sMap;
88 int sMapLen, sMapSize;
95 //------------------------------------------------------------------------
97 class CharCodeToUnicodeCache {
100 CharCodeToUnicodeCache(int sizeA);
101 ~CharCodeToUnicodeCache();
103 // Get the CharCodeToUnicode object for <tag>. Increments its
104 // reference count; there will be one reference for the cache plus
105 // one for the caller of this function. Returns NULL on failure.
106 CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
108 // Insert <ctu> into the cache, in the most-recently-used position.
109 void add(CharCodeToUnicode *ctu);
113 CharCodeToUnicode **cache;