1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
19 #include "FontEncoding.h"
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
28 enum GfxFontCharSet16 {
29 font16AdobeJapan12 // Adobe-Japan1-2
32 //------------------------------------------------------------------------
34 //------------------------------------------------------------------------
36 struct GfxFontEncoding16 {
37 int wMode; // writing mode (0=horizontal, 1=vertical)
38 Guchar codeLen[256]; // length of codes, in bytes, indexed by
40 Gushort map1[256]; // one-byte code mapping:
41 // map1[code] --> 16-bit char selector
42 Gushort *map2; // two-byte code mapping
43 // map2[2*i] --> first code in range
44 // map2[2*i+1] --> 16-bit char selector
46 int map2Len; // length of map2 array (divided by 2)
49 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
53 struct GfxFontWidthExcep {
54 int first; // this record applies to
55 int last; // chars <first>..<last>
56 double width; // char width
59 struct GfxFontWidthExcepV {
60 int first; // this record applies to
61 int last; // chars <first>..<last>
62 double height; // char height
63 double vx, vy; // origin position
66 struct GfxFontWidths16 {
67 double defWidth; // default char width
68 double defHeight; // default char height
69 double defVY; // default origin position
70 GfxFontWidthExcep *exceps; // exceptions
71 int numExceps; // number of valid entries in exceps
72 GfxFontWidthExcepV *excepsV; // exceptions for vertical font
73 int numExcepsV; // number of valid entries in excepsV
76 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
80 #define fontFixedWidth (1 << 0)
81 #define fontSerif (1 << 1)
82 #define fontSymbolic (1 << 2)
83 #define fontItalic (1 << 6)
84 #define fontBold (1 << 18)
99 GfxFont(char *tag1, Ref id1, Dict *fontDict);
105 GString *getTag() { return tag; }
107 // Get font dictionary ID.
108 Ref getID() { return id; }
110 // Does this font match the tag?
111 GBool matches(char *tag1) { return !tag->cmp(tag1); }
113 // Get base font name.
114 GString *getName() { return name; }
117 GfxFontType getType() { return type; }
119 // Does this font use 16-bit characters?
120 GBool is16Bit() { return is16; }
122 // Get embedded font ID, i.e., a ref for the font file stream.
123 // Returns false if there is no embedded font.
124 GBool getEmbeddedFontID(Ref *embID)
125 { *embID = embFontID; return embFontID.num >= 0; }
127 // Get the PostScript font name for the embedded font. Returns
128 // NULL if there is no embedded font.
129 char *getEmbeddedFontName()
130 { return embFontName ? embFontName->getCString() : (char *)NULL; }
132 // Get the name of the external font file. Returns NULL if there
133 // is no external font file.
134 char *getExtFontFile()
135 { return extFontFile ? extFontFile->getCString() : (char *)NULL; }
137 // Get font descriptor flags.
138 GBool isFixedWidth() { return flags & fontFixedWidth; }
139 GBool isSerif() { return flags & fontSerif; }
140 GBool isSymbolic() { return flags & fontSymbolic; }
141 GBool isItalic() { return flags & fontItalic; }
142 GBool isBold() { return flags & fontBold; }
144 // Get width of a character or string.
145 double getWidth(Guchar c) { return widths[c]; }
146 double getWidth(GString *s);
148 // Get character metrics for 16-bit font.
149 double getWidth16(int c);
150 double getHeight16(int c);
151 double getOriginX16(int c);
152 double getOriginY16(int c);
154 // Return the encoding.
155 FontEncoding *getEncoding() { return encoding; }
157 // Return the character name associated with <code>.
158 char *getCharName(int code) { return encoding->getCharName(code); }
160 // Return the code associated with <name>.
161 int getCharCode(char *charName) { return encoding->getCharCode(charName); }
163 // Return the 16-bit character set and encoding.
164 GfxFontCharSet16 getCharSet16() { return enc16.charSet; }
165 GfxFontEncoding16 *getEncoding16() { return enc16.enc; }
167 // Get the writing mode (0=horizontal, 1=vertical).
168 int getWMode16() { return enc16.enc->wMode; }
170 // Return the font matrix.
171 double *getFontMatrix() { return fontMat; }
173 // Read an external or embedded font file into a buffer.
174 char *readExtFontFile(int *len);
175 char *readEmbFontFile(int *len);
179 void getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont);
180 void findExtFontFile();
181 void makeWidths(Dict *fontDict, FontEncoding *builtinEncoding,
182 Gushort *builtinWidths);
183 void getType0EncAndWidths(Dict *fontDict);
185 GString *tag; // PDF font tag
186 Ref id; // reference (used as unique ID)
187 GString *name; // font name
188 int flags; // font descriptor flags
189 GfxFontType type; // type of font
190 GBool is16; // set if font uses 16-bit chars
191 GString *embFontName; // name of embedded font
192 Ref embFontID; // ref to embedded font file stream
193 GString *extFontFile; // external font file name
194 double fontMat[6]; // font matrix
196 FontEncoding *encoding; // 8-bit font encoding
198 GfxFontCharSet16 charSet; // 16-bit character set
199 GfxFontEncoding16 *enc; // 16-bit encoding (CMap)
203 double widths[256]; // width of each char for 8-bit font
204 GfxFontWidths16 widths16; // char widths for 16-bit font
208 //------------------------------------------------------------------------
210 //------------------------------------------------------------------------
215 // Build the font dictionary, given the PDF font dictionary.
216 GfxFontDict(Dict *fontDict);
221 // Get the specified font.
222 GfxFont *lookup(char *tag);
225 int getNumFonts() { return numFonts; }
226 GfxFont *getFont(int i) { return fonts[i]; }
230 GfxFont **fonts; // list of fonts
231 int numFonts; // number of fonts