| 1 | /*DDK*************************************************************************/
|
|---|
| 2 | /* */
|
|---|
| 3 | /* COPYRIGHT Copyright (C) 1991, 2003 IBM Corporation */
|
|---|
| 4 | /* */
|
|---|
| 5 | /* The following IBM OS/2 source code is provided to you solely for */
|
|---|
| 6 | /* the purpose of assisting you in your development of OS/2 device */
|
|---|
| 7 | /* drivers. You may use this code in accordance with the IBM License */
|
|---|
| 8 | /* Agreement provided in the IBM Developer Connection Device Driver */
|
|---|
| 9 | /* Source Kit for OS/2. This Copyright statement may not be removed. */
|
|---|
| 10 | /* */
|
|---|
| 11 | /*****************************************************************************/
|
|---|
| 12 | /**************************************************************************
|
|---|
| 13 | *
|
|---|
| 14 | * SOURCE FILE NAME = AFM2BIN.H
|
|---|
| 15 | *
|
|---|
| 16 | * DESCRIPTIVE NAME = Header file for AFM2BIN.C
|
|---|
| 17 | *
|
|---|
| 18 | *
|
|---|
| 19 | * VERSION = V2.0
|
|---|
| 20 | *
|
|---|
| 21 | * DATE 02/25/88
|
|---|
| 22 | *
|
|---|
| 23 | * DESCRIPTION
|
|---|
| 24 | *
|
|---|
| 25 | *
|
|---|
| 26 | * FUNCTIONS
|
|---|
| 27 | *
|
|---|
| 28 | *
|
|---|
| 29 | * NOTES
|
|---|
| 30 | *
|
|---|
| 31 | *
|
|---|
| 32 | * STRUCTURES
|
|---|
| 33 | *
|
|---|
| 34 | * EXTERNAL REFERENCES
|
|---|
| 35 | *
|
|---|
| 36 | * EXTERNAL FUNCTIONS
|
|---|
| 37 | *
|
|---|
| 38 | */
|
|---|
| 39 |
|
|---|
| 40 | #define AFM2BIN 1
|
|---|
| 41 | //#define TRUE 1
|
|---|
| 42 | //#define FALSE 0
|
|---|
| 43 | #define FACESIZE 32
|
|---|
| 44 |
|
|---|
| 45 | /*
|
|---|
| 46 | ** values of fsSelection field of FATTRS structure : NOTE! -> os2def.h
|
|---|
| 47 | */
|
|---|
| 48 |
|
|---|
| 49 | #define FATTR_SEL_ITALIC 0x0001
|
|---|
| 50 |
|
|---|
| 51 | /*
|
|---|
| 52 | ** values of sFamilyClass as defined by DCR24415
|
|---|
| 53 | */
|
|---|
| 54 |
|
|---|
| 55 | #define FATTR_FAM_NO_CLASSIFICATION 0
|
|---|
| 56 | #define FATTR_FAM_OLD_STYLE_SERIF 1
|
|---|
| 57 | #define FATTR_FAM_TRANSITIONAL_SERIF 2
|
|---|
| 58 | #define FATTR_FAM_MODERN_SERIF 3
|
|---|
| 59 | #define FATTR_FAM_CLARENDON_SERIF 4
|
|---|
| 60 | #define FATTR_FAM_SLAB_SERIF 5
|
|---|
| 61 | #define FATTR_FAM_RESERVED1 6
|
|---|
| 62 | #define FATTR_FAM_FREEFORM_SERIF 7
|
|---|
| 63 | #define FATTR_FAM_SANS_SERIF 8
|
|---|
| 64 | #define FATTR_FAM_ORNAMENTAL 9
|
|---|
| 65 | #define FATTR_FAM_SCRIPT 10
|
|---|
| 66 | #define FATTR_FAM_RESERVED2 11
|
|---|
| 67 | #define FATTR_FAM_SYMBOLIC 12
|
|---|
| 68 | #define FATTR_FAM_IDEOGRAPHIC 13
|
|---|
| 69 | #define FATTR_FAM_SYLLABIC 14
|
|---|
| 70 | #define FATTR_FAM_MISCELLANEOUS 15
|
|---|
| 71 |
|
|---|
| 72 | /*
|
|---|
| 73 | ** weight classes
|
|---|
| 74 | */
|
|---|
| 75 |
|
|---|
| 76 | #define FW_ULTRALIGHT 1
|
|---|
| 77 | #define FW_EXTRALIGHT 2
|
|---|
| 78 | #define FW_LIGHT 3
|
|---|
| 79 | #define FW_SEMILIGHT 4
|
|---|
| 80 | #define FW_NORMAL 5
|
|---|
| 81 | #define FW_SEMIBOLD 6
|
|---|
| 82 | #define FW_BOLD 7
|
|---|
| 83 | #define FW_EXTRABOLD 8
|
|---|
| 84 | #define FW_ULTRABOLD 9
|
|---|
| 85 | #define FIRST_CHAR 1
|
|---|
| 86 | #define LAST_CHAR 332
|
|---|
| 87 | #define CODE_PAGE 850
|
|---|
| 88 | #define MAX_STR 80
|
|---|
| 89 | #define MAX_CHARS 512
|
|---|
| 90 | #define MAX_KPAIRS 2048
|
|---|
| 91 | #define MAX_KTRACKS 10
|
|---|
| 92 | #define MAX_COMPOSITES 64
|
|---|
| 93 | #define MAX_COMP_PARTS 4
|
|---|
| 94 | #define DEF_IEXT ".afm"
|
|---|
| 95 | #define DEF_OEXT ".pfm"
|
|---|
| 96 | #define MAX_FNAMESIZE 128
|
|---|
| 97 | #define MAX_LINESIZE 160
|
|---|
| 98 | #define MAX_IBUFFSIZE 2048
|
|---|
| 99 | #define MAX_OBUFFSIZE 8192
|
|---|
| 100 | #define ULTRACONDENSED 1
|
|---|
| 101 | #define EXTRACONDENSED 2
|
|---|
| 102 | #define CONDENSED 3
|
|---|
| 103 | #define SEMICONDENSED 4
|
|---|
| 104 | #define MEDIUM 5
|
|---|
| 105 | #define SEMIEXPANDED 6
|
|---|
| 106 | #define EXPANDED 7
|
|---|
| 107 | #define EXTRAEXPANDED 8
|
|---|
| 108 | #define ULTRAEXPANDED 9
|
|---|
| 109 |
|
|---|
| 110 | //#define CHAR char /* ch */
|
|---|
| 111 | //#define SHORT short /* s */
|
|---|
| 112 | //#define LONG long /* l */
|
|---|
| 113 | //#define INT int /* i */
|
|---|
| 114 | //typedef unsigned short USHORT; /* us */
|
|---|
| 115 | //typedef unsigned long ULONG; /* ul */
|
|---|
| 116 | //typedef unsigned char BYTE; /* b */
|
|---|
| 117 | //typedef unsigned BOOL;
|
|---|
| 118 | //typedef unsigned char Byte;
|
|---|
| 119 | //typedef unsigned Word;
|
|---|
| 120 | typedef unsigned WORD;
|
|---|
| 121 | //typedef unsigned long Dword;
|
|---|
| 122 |
|
|---|
| 123 | typedef struct
|
|---|
| 124 | {
|
|---|
| 125 | char *pszName;
|
|---|
| 126 | SHORT iCP850Code, ipscriptCode;
|
|---|
| 127 | } CharData;
|
|---|
| 128 | /* cd */
|
|---|
| 129 | typedef struct
|
|---|
| 130 | {
|
|---|
| 131 | SHORT left;
|
|---|
| 132 | SHORT bottom;
|
|---|
| 133 | SHORT right;
|
|---|
| 134 | SHORT top;
|
|---|
| 135 | } Rect;
|
|---|
| 136 |
|
|---|
| 137 | typedef struct
|
|---|
| 138 | {
|
|---|
| 139 | SHORT x;
|
|---|
| 140 | SHORT y;
|
|---|
| 141 | } Vector;
|
|---|
| 142 |
|
|---|
| 143 | typedef struct
|
|---|
| 144 | { /* metric info for a single char */
|
|---|
| 145 | SHORT ipscriptCode; /* char code to use in postscript */
|
|---|
| 146 | /* show */
|
|---|
| 147 | Rect rc; /* bounding box */
|
|---|
| 148 | Vector cvec; /* vector */
|
|---|
| 149 | } CMData;
|
|---|
| 150 |
|
|---|
| 151 | typedef struct
|
|---|
| 152 | { /* info for a single kern pair */
|
|---|
| 153 | SHORT iKey1, iKey2; /* Code page 850 words of the two */
|
|---|
| 154 | /* chars */
|
|---|
| 155 | SHORT sAmount; /* kerning amount for pair */
|
|---|
| 156 | } KPair;
|
|---|
| 157 |
|
|---|
| 158 | typedef struct
|
|---|
| 159 | { /* info for a single AFM file */
|
|---|
| 160 |
|
|---|
| 161 | /*
|
|---|
| 162 | ** global info
|
|---|
| 163 | */
|
|---|
| 164 |
|
|---|
| 165 | WORD version;
|
|---|
| 166 | SHORT iMaxWidth;
|
|---|
| 167 | SHORT iCapHeight;
|
|---|
| 168 | BOOL fVariablePitch;
|
|---|
| 169 | Rect rcBBox;
|
|---|
| 170 | char szFontName[MAX_STR];
|
|---|
| 171 | char szEncodingScheme[MAX_STR];
|
|---|
| 172 | char szComment[MAX_STR];
|
|---|
| 173 | char szWeight[MAX_STR];
|
|---|
| 174 | char szVersion[MAX_STR];
|
|---|
| 175 | char szNotice[MAX_STR];
|
|---|
| 176 | CMData rgcm[MAX_CHARS]; /* the character metrics */
|
|---|
| 177 | SHORT cKPairs; /* the number of kerning pairs */
|
|---|
| 178 | KPair rgKPairs[MAX_KPAIRS];
|
|---|
| 179 | } AfmData;
|
|---|
| 180 |
|
|---|
| 181 | /*
|
|---|
| 182 | ** weighting factors for computing lAveWidth
|
|---|
| 183 | */
|
|---|
| 184 |
|
|---|
| 185 | SHORT iWeightFactor[] =
|
|---|
| 186 | {
|
|---|
| 187 | 64, /* a */
|
|---|
| 188 | 14, /* b */
|
|---|
| 189 | 27, /* c */
|
|---|
| 190 | 35, /* d */
|
|---|
| 191 | 100, /* e */
|
|---|
| 192 | 20, /* f */
|
|---|
| 193 | 14, /* g */
|
|---|
| 194 | 42, /* h */
|
|---|
| 195 | 63, /* i */
|
|---|
| 196 | 3, /* j */
|
|---|
| 197 | 6, /* k */
|
|---|
| 198 | 35, /* l */
|
|---|
| 199 | 20, /* m */
|
|---|
| 200 | 56, /* n */
|
|---|
| 201 | 56, /* o */
|
|---|
| 202 | 17, /* p */
|
|---|
| 203 | 4, /* q */
|
|---|
| 204 | 49, /* r */
|
|---|
| 205 | 56, /* s */
|
|---|
| 206 | 71, /* t */
|
|---|
| 207 | 31, /* u */
|
|---|
| 208 | 10, /* v */
|
|---|
| 209 | 18, /* w */
|
|---|
| 210 | 3, /* x */
|
|---|
| 211 | 18, /* y */
|
|---|
| 212 | 2, /* z */
|
|---|
| 213 | 166
|
|---|
| 214 | } ;
|
|---|
| 215 | /* space */
|
|---|
| 216 | #if 0
|
|---|
| 217 | typedef struct _FONTMETRICS
|
|---|
| 218 | { /* !!!CR this should be from OS2DEF */
|
|---|
| 219 | CHAR szFamilyname[FACESIZE];
|
|---|
| 220 | CHAR szFacename[FACESIZE];
|
|---|
| 221 | SHORT idRegistry;
|
|---|
| 222 | SHORT usCodePage;
|
|---|
| 223 | LONG lEmHeight;
|
|---|
| 224 | LONG lXHeight;
|
|---|
| 225 | LONG lMaxAscender;
|
|---|
| 226 | LONG lMaxDescender;
|
|---|
| 227 | LONG lLowerCaseAscent;
|
|---|
| 228 | LONG lLowerCaseDescent;
|
|---|
| 229 | LONG lInternalLeading;
|
|---|
| 230 | LONG lExternalLeading;
|
|---|
| 231 | LONG lAveCharWidth;
|
|---|
| 232 | LONG lMaxCharInc;
|
|---|
| 233 | LONG lEmInc;
|
|---|
| 234 | LONG lMaxBaselineExt;
|
|---|
| 235 | SHORT sCharSlope;
|
|---|
| 236 | SHORT sInlineDir;
|
|---|
| 237 | SHORT sCharRot;
|
|---|
| 238 | USHORT usWeightClass;
|
|---|
| 239 | USHORT usWidthClass;
|
|---|
| 240 | SHORT sXDeviceRes;
|
|---|
| 241 | SHORT sYDeviceRes;
|
|---|
| 242 | SHORT sFirstChar;
|
|---|
| 243 | SHORT sLastChar;
|
|---|
| 244 | SHORT sDefaultChar;
|
|---|
| 245 | SHORT sBreakChar;
|
|---|
| 246 | SHORT sNominalPointSize;
|
|---|
| 247 | SHORT sMinimumPointSize;
|
|---|
| 248 | SHORT sMaximumPointSize;
|
|---|
| 249 | USHORT fsType;
|
|---|
| 250 | USHORT fsDefn;
|
|---|
| 251 | USHORT fsSelection;
|
|---|
| 252 | USHORT fsCapabilities;
|
|---|
| 253 | LONG lSubscriptXSize;
|
|---|
| 254 | LONG lSubscriptYSize;
|
|---|
| 255 | LONG lSubscriptXOffset;
|
|---|
| 256 | LONG lSubscriptYOffset;
|
|---|
| 257 | LONG lSuperscriptXSize;
|
|---|
| 258 | LONG lSuperscriptYSize;
|
|---|
| 259 | LONG lSuperscriptXOffset;
|
|---|
| 260 | LONG lSuperscriptYOffset;
|
|---|
| 261 | LONG lUnderscoreSize;
|
|---|
| 262 | LONG lUnderscorePosition;
|
|---|
| 263 | LONG lStrikeoutSize;
|
|---|
| 264 | LONG lStrikeoutPosition;
|
|---|
| 265 | SHORT sKerningPairs;
|
|---|
| 266 | SHORT sFamilyClass;
|
|---|
| 267 | LONG lMatch;
|
|---|
| 268 | } FONTMETRICS;
|
|---|
| 269 | #endif
|
|---|
| 270 |
|
|---|
| 271 | /* DBCS enabling start */ //@DBCS
|
|---|
| 272 | /* values of fsType field of FONTMETRICS structure */
|
|---|
| 273 | #define FM_TYPE_FIXED 0x0001
|
|---|
| 274 | #define FM_TYPE_LICENSED 0x0002
|
|---|
| 275 | #define FM_TYPE_KERNING 0x0004
|
|---|
| 276 | #define FM_TYPE_DBCS 0x0010
|
|---|
| 277 | #define FM_TYPE_MBCS 0x0018
|
|---|
| 278 | #define FM_TYPE_64K 0x8000
|
|---|
| 279 | #define FM_TYPE_ATOMS 0x4000
|
|---|
| 280 | #define FM_TYPE_FAMTRUNC 0x2000
|
|---|
| 281 | #define FM_TYPE_FACETRUNC 0x1000
|
|---|
| 282 | /* DBCS enabling end */ //@DBCS
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 | CharData *ParseNextCharCode(CharData *,CharData *);
|
|---|
| 286 | CharData *ParseCharName(CharData *);
|
|---|
| 287 | enum errtype
|
|---|
| 288 | {
|
|---|
| 289 | err_ver, err_usage, err_option, err_arg, err_cantopen
|
|---|
| 290 | , err_cantcreate, err_badoutput, err_eof, err_eofin,
|
|---|
| 291 | err_badnum, err_badreal, err_expected, err_unkfontw,
|
|---|
| 292 | err_missingbbox, err_missingsemi,
|
|---|
| 293 | err_expectedname, err_zerocharw, err_badccode, err_unkchar,
|
|---|
| 294 | err_overflow, err_max
|
|---|
| 295 | } ;
|
|---|
| 296 |
|
|---|
| 297 | typedef enum errtype ErrType;
|
|---|
| 298 | char *errmsgs[err_max] =
|
|---|
| 299 | {
|
|---|
| 300 | "Microsoft (R) Metric File Compiler Version 2.00\nCopyright (c) Microsoft Co\
|
|---|
| 301 | rp 1988. All rights reserved.\n",
|
|---|
| 302 | "Usage: afm2bin [-esmv] afmfile [outputfile]", "unknown option",
|
|---|
| 303 | "unknown argument", "cannot open", "cannot create",
|
|---|
| 304 | "cannot write to input file", "unexpected eof",
|
|---|
| 305 | "unexpected eof in", "invalid number",
|
|---|
| 306 | "invalid real number", "expected", "unknown font weight",
|
|---|
| 307 | "missing bounding box", "missing semicolon",
|
|---|
| 308 | "expected name field", "zero character width",
|
|---|
| 309 | "invalid character code", "unknown character",
|
|---|
| 310 | "output buffer overflow"
|
|---|
| 311 | } ;
|
|---|
| 312 |
|
|---|
| 313 | enum toktype
|
|---|
| 314 | {
|
|---|
| 315 | tok_fontname, /* added: FullName, EncodingScheme, */
|
|---|
| 316 | /* FamilyName */
|
|---|
| 317 | tok_fullname, tok_encodingscheme, tok_familyname, tok_comment,
|
|---|
| 318 | tok_weight, tok_italicangle, tok_isfixedpitch,
|
|---|
| 319 | tok_fontbox, tok_underlineposition, tok_underlinethickness,
|
|---|
| 320 | tok_version, tok_notice, tok_capheight, tok_xheight, tok_ascender
|
|---|
| 321 | , tok_descender, tok_startcharmetrics, tok_c,
|
|---|
| 322 | tok_wx, tok_w, tok_n, tok_b, tok_l,
|
|---|
| 323 | tok_endcharmetrics, tok_startkerndata,
|
|---|
| 324 | tok_startkernpairs, tok_kp, tok_kpx,
|
|---|
| 325 | tok_endkernpairs, tok_starttrackkern,
|
|---|
| 326 | tok_trackkern, tok_endtrackkern, tok_endkerndata,
|
|---|
| 327 | tok_startfontmetrics, tok_endfontmetrics,
|
|---|
| 328 | tok_startcomposites, tok_cc, tok_pcc,
|
|---|
| 329 | tok_isbasefont, //@DBCS
|
|---|
| 330 | tok_endcomposites, tok_max, tok_unknown
|
|---|
| 331 | } ;
|
|---|
| 332 |
|
|---|
| 333 | typedef enum toktype TokType;
|
|---|
| 334 | char *tokens[tok_max] =
|
|---|
| 335 | {
|
|---|
| 336 | "FontName", "FullName", "EncodingScheme", "FamilyName"
|
|---|
| 337 | , "Comment", "Weight", "ItalicAngle",
|
|---|
| 338 | "IsFixedPitch", "FontBBox", "UnderlinePosition",
|
|---|
| 339 | "UnderlineThickness", "Version", "Notice", "CapHeight",
|
|---|
| 340 | "XHeight", "Ascender", "Descender", "StartCharMetrics",
|
|---|
| 341 | "C", "WX", "W", "N", "B",
|
|---|
| 342 | "L", "EndCharMetrics", "StartKernData",
|
|---|
| 343 | "StartKernPairs", "KP", "KPX",
|
|---|
| 344 | "EndKernPairs", "StartTrackKern", "TrackKern",
|
|---|
| 345 | "EndTrackKern", "EndKernData", "StartFontMetrics",
|
|---|
| 346 | "EndFontMetrics", "StartComposites", "CC",
|
|---|
| 347 | //"PCC", "EndComposites", //@DBCS
|
|---|
| 348 | "PCC", "IsBaseFont", "EndComposites", //@DBCS
|
|---|
| 349 | } ;
|
|---|