1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
22 //------------------------------------------------------------------------
24 //------------------------------------------------------------------------
26 #define gfxFontEncHashSize 419
28 class GfxFontEncoding {
31 // Construct an empty encoding.
34 // Construct an encoding from an array of char names.
35 GfxFontEncoding(char **encoding1, int encSize);
40 // Add a char to the encoding.
41 void addChar(int code, char *name);
43 // Return the character name associated with <code>.
44 char *getCharName(int code) { return encoding[code]; }
46 // Return the code associated with <name>.
47 int getCharCode(char *name);
52 void addChar1(int code, char *name);
54 char **encoding; // code --> name mapping
55 GBool freeEnc; // should we free the encoding array?
56 short // name --> code hash table
57 hashTab[gfxFontEncHashSize];
60 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
64 enum GfxFontCharSet16 {
65 font16AdobeJapan12 // Adobe-Japan1-2
68 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
72 struct GfxFontEncoding16 {
73 Guchar codeLen[256]; // length of codes, in bytes, indexed by
75 Gushort map1[256]; // one-byte code mapping:
76 // map1[code] --> 16-bit char selector
77 Gushort *map2; // two-byte code mapping
78 // map2[2*i] --> first code in range
79 // map2[2*i+1] --> 16-bit char selector
81 int map2Len; // length of map2 array (divided by 2)
84 //------------------------------------------------------------------------
86 //------------------------------------------------------------------------
88 struct GfxFontWidthExcep {
89 int first; // chars <first>..<last> have
90 int last; // width <width>
94 struct GfxFontWidths16 {
95 double defWidth; // default char width
96 GfxFontWidthExcep *exceps; // exceptions
97 int numExceps; // number of valid entries in exceps
100 //------------------------------------------------------------------------
102 //------------------------------------------------------------------------
104 #define fontFixedWidth (1 << 0)
105 #define fontSerif (1 << 1)
106 #define fontSymbolic (1 << 2)
107 #define fontItalic (1 << 6)
108 #define fontBold (1 << 18)
122 GfxFont(char *tag1, Ref id1, Dict *fontDict);
128 GString *getTag() { return tag; }
130 // Get font dictionary ID.
131 Ref getID() { return id; }
133 // Does this font match the tag?
134 GBool matches(char *tag1) { return !tag->cmp(tag1); }
136 // Get base font name.
137 GString *getName() { return name; }
140 GfxFontType getType() { return type; }
142 // Does this font use 16-bit characters?
143 GBool is16Bit() { return is16; }
145 // Get embedded font ID, i.e., a ref for the font file stream.
146 // Returns false if there is no embedded font.
147 GBool getEmbeddedFontID(Ref *embID)
148 { *embID = embFontID; return embFontID.num >= 0; }
150 // Get the PostScript font name for the embedded font. Returns
151 // NULL if there is no embedded font.
152 char *getEmbeddedFontName()
153 { return embFontName ? embFontName->getCString() : (char *)NULL; }
155 // Get the name of the external font file. Returns NULL if there
156 // is no external font file.
157 char *getExtFontFile()
158 { return extFontFile ? extFontFile->getCString() : (char *)NULL; }
160 // Get font descriptor flags.
161 GBool isFixedWidth() { return flags & fontFixedWidth; }
162 GBool isSerif() { return flags & fontSerif; }
163 GBool isSymbolic() { return flags & fontSymbolic; }
164 GBool isItalic() { return flags & fontItalic; }
165 GBool isBold() { return flags & fontBold; }
167 // Get width of a character or string.
168 double getWidth(Guchar c) { return widths[c]; }
169 double getWidth(GString *s);
170 double getWidth16(int c);
171 double getWidth16(GString *s);
173 // Return the character name associated with <code>.
174 char *getCharName(int code) { return encoding->getCharName(code); }
176 // Return the code associated with <name>.
177 int getCharCode(char *charName) { return encoding->getCharCode(charName); }
179 // Return the 16-bit character set and encoding.
180 GfxFontCharSet16 getCharSet16() { return enc16.charSet; }
181 GfxFontEncoding16 *getEncoding16() { return enc16.enc; }
183 // Return the font matrix.
184 double *getFontMatrix() { return fontMat; }
188 void makeEncoding(Dict *fontDict, GfxFontEncoding *builtinEncoding);
189 GfxFontEncoding *makeEncoding1(Object obj, Dict *fontDesc,
190 GfxFontEncoding *builtinEncoding);
191 void getType1Encoding(Stream *str);
192 void makeWidths(Dict *fontDict, GfxFontEncoding *builtinEncoding,
193 Gushort *builtinWidths);
194 void getType0EncAndWidths(Dict *fontDict);
196 GString *tag; // PDF font tag
197 Ref id; // reference (used as unique ID)
198 GString *name; // font name
199 int flags; // font descriptor flags
200 GfxFontType type; // type of font
201 GBool is16; // set if font uses 16-bit chars
202 GString *embFontName; // name of embedded font
203 Ref embFontID; // ref to embedded font file stream
204 GString *extFontFile; // external font file name
205 double fontMat[6]; // font matrix
207 GfxFontEncoding *encoding; // 8-bit font encoding
209 GfxFontCharSet16 charSet; // 16-bit character set
210 GfxFontEncoding16 *enc; // 16-bit encoding (CMap)
214 double widths[256]; // width of each char for 8-bit font
215 GfxFontWidths16 widths16; // char widths for 16-bit font
219 //------------------------------------------------------------------------
221 //------------------------------------------------------------------------
226 // Build the font dictionary, given the PDF font dictionary.
227 GfxFontDict(Dict *fontDict);
232 // Get the specified font.
233 GfxFont *lookup(char *tag);
236 int getNumFonts() { return numFonts; }
237 GfxFont *getFont(int i) { return fonts[i]; }
241 GfxFont **fonts; // list of fonts
242 int numFonts; // number of fonts