1 /* 2 * Internal header for the AFM library. 3 * Copyright (c) 1995-1999 Markku Rossi. 4 * 5 * Author: Markku Rossi <mtr@iki.fi> 6 */ 7 8 /* 9 * Enscript is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * Enscript is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with Enscript. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef AFMINT_H 24 #define AFMINT_H 25 26 /* 27 * Config stuffs. 28 */ 29 30 #ifdef HAVE_CONFIG_H 31 #include <config.h> 32 #endif 33 34 #include <stdio.h> 35 36 #ifndef ___P 37 #if PROTOTYPES 38 #define ___P(protos) protos 39 #else /* no PROTOTYPES */ 40 #define ___P(protos) () 41 #endif /* no PROTOTYPES */ 42 #endif 43 44 #if STDC_HEADERS 45 46 #include <stdlib.h> 47 #include <string.h> 48 49 #else /* no STDC_HEADERS */ 50 51 #if HAVE_STDLIB_H 52 #include <stdlib.h> 53 #endif 54 55 #if HAVE_STRING_H 56 #include <string.h> 57 #endif 58 59 #ifndef HAVE_STRCHR 60 #define strchr index 61 #define strrchr rindex 62 #endif 63 char *strchr (); 64 char *strrchr (); 65 66 #ifndef HAVE_MEMCPY 67 #define memcpy(d, s, n) bcopy((s), (d), (n)) 68 #endif 69 70 #ifndef HAVE_STRERROR 71 extern char *strerror ___P ((int)); 72 #endif 73 74 #endif /* no STDC_HEADERS */ 75 76 #if HAVE_UNISTD_H 77 #include <unistd.h> 78 #endif 79 80 #include <setjmp.h> 81 #include <assert.h> 82 #include <errno.h> 83 84 #include <sys/types.h> 85 #include <sys/stat.h> 86 87 #include "afm.h" 88 #include "strhash.h" 89 90 91 /* 92 * Types and definitions. 93 */ 94 95 /* Error codes. */ 96 #define AFM_ERROR 1 97 #define AFM_ERROR_MEMORY 2 98 #define AFM_ERROR_ARGUMENT 3 99 #define AFM_ERROR_UNKNOWN_FONT 4 100 #define AFM_ERROR_SYNTAX 5 101 #define AFM_ERROR_UNSUPPORTED_FORMAT 6 102 #define AFM_ERROR_FILE_IO 7 103 #define AFM_ERROR_NOT_AFM_FILE 8 104 #define NUM_ERRORS 9 105 106 /* Pack error and global errno. */ 107 #define SYSERROR(code) (errno << 16 | (code)) 108 109 110 /* Keys. */ 111 112 typedef enum 113 { 114 kComment, 115 116 /* File structure. */ 117 kStartFontMetrics, 118 kEndFontMetrics, 119 kStartCompFontMetrics, 120 kEndCompFontMetrics, 121 kStartDescendent, 122 kEndDescendent, 123 kStartMasterFontMetrics, 124 kEndMasterFontMetrics, 125 126 /* Control information. */ 127 kMetricsSets, 128 kDescendents, 129 kMasters, 130 kAxes, 131 132 /* Global font information. */ 133 kFontName, 134 kFullName, 135 kFamilyName, 136 kWeight, 137 kFontBBox, 138 kVersion, 139 kNotice, 140 kEncodingScheme, 141 kMappingScheme, 142 kEscChar, 143 kCharacterSet, 144 kCharacters, 145 kIsBaseFont, 146 kVVector, 147 kIsFixedV, 148 kCapHeight, 149 kXHeight, 150 kAscender, 151 kDescender, 152 kWeightVector, 153 kBlendDesignPositions, 154 kBlendDesignMap, 155 kBlendAxisTypes, 156 157 /* Writing direction information. */ 158 kStartDirection, 159 kEndDirection, 160 kUnderlinePosition, 161 kUnderlineThickness, 162 kItalicAngle, 163 kCharWidth, 164 kIsFixedPitch, 165 166 /* Individual character metrics. */ 167 kStartCharMetrics, 168 kEndCharMetrics, 169 kC, 170 kCH, 171 kWX, 172 kW0X, 173 kW1X, 174 kWY, 175 kW0Y, 176 kW1Y, 177 kW, 178 kW0, 179 kW1, 180 kVV, 181 kN, 182 kB, 183 kL, 184 185 /* Kerning data. */ 186 kStartKernData, 187 kEndKernData, 188 kStartTrackKern, 189 kEndTrackKern, 190 kTrackKern, 191 kStartKernPairs, 192 kEndKernPairs, 193 kKP, 194 kKPH, 195 kKPX, 196 kKPY, 197 198 /* Composite character data. */ 199 kStartComposites, 200 kEndComposites, 201 kCC, 202 kPCC, 203 204 /* Axis information. */ 205 kStartAxis, 206 kEndAxis, 207 kAxisType, 208 kAxisLabel, 209 210 /* Master Design Information */ 211 kStartMaster, 212 kEndMaster 213 214 } AFMKey; 215 216 217 struct afm_handle_st 218 { 219 unsigned int verbose; /* verbose level */ 220 StringHashPtr font_map; /* fontname -> AFM filename mapping */ 221 222 /* Parse support. */ 223 jmp_buf jmpbuf; 224 AFMError parse_error; /* Error that caused longjmp(). */ 225 }; 226 227 228 /* Store library's private font data to this structure. */ 229 struct afm_font_private_data_st 230 { 231 /* Character that is used for undefined codes (' '). */ 232 AFMIndividualCharacterMetrics *undef; 233 234 StringHashPtr fontnames; /* fontname -> character info mapping */ 235 StringHashPtr compositenames; /* composite -> AFMComposite mapping */ 236 }; 237 238 239 /* 240 * Encoding tables. 241 */ 242 243 struct encoding_table_st 244 { 245 int code; 246 char *character; 247 }; 248 249 typedef struct encoding_table_st AFMEncodingTable; 250 251 extern AFMEncodingTable afm_88591_encoding[]; 252 extern AFMEncodingTable afm_88592_encoding[]; 253 extern AFMEncodingTable afm_88593_encoding[]; 254 extern AFMEncodingTable afm_88594_encoding[]; 255 extern AFMEncodingTable afm_88595_encoding[]; 256 extern AFMEncodingTable afm_88597_encoding[]; 257 extern AFMEncodingTable afm_88599_encoding[]; 258 extern AFMEncodingTable afm_885910_encoding[]; 259 extern AFMEncodingTable afm_ibmpc_encoding[]; 260 extern AFMEncodingTable afm_mac_encoding[]; 261 extern AFMEncodingTable afm_vms_encoding[]; 262 extern AFMEncodingTable afm_hp8_encoding[]; 263 extern AFMEncodingTable afm_koi8_encoding[]; 264 265 266 /* 267 * Global help functions. 268 */ 269 270 /* Print message if <level> is larger than library's verbose level. */ 271 void afm_message ___P ((AFMHandle handle, unsigned int level, char *message)); 272 273 /* Print error message to stderr. */ 274 void afm_error ___P ((AFMHandle handle, char *message)); 275 276 277 /* 278 * AFM file parsing 279 */ 280 281 /* Parse AFM file <filename> and fill up font <font>. */ 282 void afm_parse_file ___P ((AFMHandle handle, const char *filename, 283 AFMFont font)); 284 285 #endif /* not AFMINT_H */ 286