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);
72 void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
73 void addMapping(CharCode code, char *uStr, int n, int offset);
74 CharCodeToUnicode(GString *tagA);
75 CharCodeToUnicode(GString *tagA, Unicode *mapA,
76 CharCode mapLenA, GBool copyMap,
77 CharCodeToUnicodeString *sMapA,
78 int sMapLenA, int sMapSizeA);
83 CharCodeToUnicodeString *sMap;
84 int sMapLen, sMapSize;
91 //------------------------------------------------------------------------
93 class CharCodeToUnicodeCache {
96 CharCodeToUnicodeCache(int sizeA);
97 ~CharCodeToUnicodeCache();
99 // Get the CharCodeToUnicode object for <tag>. Increments its
100 // reference count; there will be one reference for the cache plus
101 // one for the caller of this function. Returns NULL on failure.
102 CharCodeToUnicode *getCharCodeToUnicode(GString *tag);
104 // Insert <ctu> into the cache, in the most-recently-used position.
105 void add(CharCodeToUnicode *ctu);
109 CharCodeToUnicode **cache;