|
|
1.1 ! root 1: //-------------------------------------------------------------------------- ! 2: // ! 3: // Module Name: AFMTOPFM.C ! 4: // ! 5: // This module of the afm compiler parses the afm file and collects ! 6: // information in the NTfM structure. It then passes control to the ! 7: // pfm module which outputs the pfm file. ! 8: // ! 9: // Author: Kent Settle (kentse) ! 10: // Created: 18-Mar-1991 ! 11: // ! 12: // Copyright (c) 1988 - 1993 Microsoft Corporation ! 13: //-------------------------------------------------------------------------- ! 14: ! 15: #include <string.h> ! 16: #include "pscript.h" ! 17: #include "mapping.h" ! 18: #include "pscrptui.h" ! 19: ! 20: int _fltused; // HEY, it shut's up the linker. That's why it's here. ! 21: ! 22: //#define ALL_METRICS ! 23: ! 24: // external declarations. ! 25: ! 26: extern VOID InitPfm(PPARSEDATA); ! 27: extern VOID ParseAfm(PPARSEDATA); ! 28: extern BOOL GetFirstLastChar(PPARSEDATA); ! 29: extern VOID SetWidths(PPARSEDATA); ! 30: extern BOOL WritePFM(PWSTR, PPARSEDATA); ! 31: extern VOID BuildNTFM(PPARSEDATA, PSTR); ! 32: ! 33: //-------------------------------------------------------------------------- ! 34: // BOOL CreatePFMFromAFM(pwstrAFMFile, pwstrPFMFile) ! 35: // PSZ pszAFMFile; ! 36: // PSZ pszPFMFile; ! 37: // ! 38: // Returns: ! 39: // This routine returns TRUE for success, FALSE otherwise. ! 40: // ! 41: // History: ! 42: // 15-Jan-1992 -by- Kent Settle (kentse) ! 43: // Modified to become part of PSCRPTUI. ! 44: // 20-Mar-1991 -by- Kent Settle (kentse) ! 45: // ReWrote it, got rid of PFM.C and CHARCODE.C. ! 46: // 18-Mar-1991 -by- Kent Settle (kentse) ! 47: // Brought in from PM, and cleaned up. ! 48: //-------------------------------------------------------------------------- ! 49: ! 50: BOOL CreatePFMFromAFM(pwstrAFMFile, pwstrPFMFile) ! 51: PWSTR pwstrAFMFile; ! 52: PWSTR pwstrPFMFile; ! 53: { ! 54: WCHAR wcbuf[MAX_PATH]; ! 55: PWSTR pwstrPFAFile; ! 56: CHAR *pPFA; ! 57: PPARSEDATA pdata; ! 58: BOOL bReturn; ! 59: ! 60: // allocate memory for parsing data. ! 61: ! 62: if (!(pdata = (PPARSEDATA)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT), ! 63: sizeof(PARSEDATA)))) ! 64: { ! 65: RIP("PSCRPTUI!CreatePFMFromAFM: LocalAlloc for pdata failed.\n"); ! 66: return(FALSE); ! 67: } ! 68: ! 69: // allocate temporary storage to build metrics into. ! 70: ! 71: if (!(pdata->pntfm = (PNTFM)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT), INIT_PFM))) ! 72: { ! 73: RIP("PSCRPTUI!CreatePFMFromAFM: LocalAlloc for pdata->pntfm failed.\n"); ! 74: LocalFree((LOCALHANDLE)pdata); ! 75: return(FALSE); ! 76: } ! 77: ! 78: // build the IFIMETRICS structure in temporary storage, until we ! 79: // know its exact size. ! 80: ! 81: if (!(pdata->pTmpIFI = (PIFIMETRICS)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT), ! 82: INIT_IFI))) ! 83: { ! 84: RIP("PSCRPTUI!CreatePFMFromAFM: LocalAlloc for pTmpIFI failed.\n"); ! 85: LocalFree((LOCALHANDLE)pdata->pntfm); ! 86: LocalFree((LOCALHANDLE)pdata); ! 87: return(FALSE); ! 88: } ! 89: ! 90: // initialize the NTFM structure. ! 91: ! 92: InitPfm(pdata); ! 93: ! 94: // open AFM file for input. ! 95: ! 96: pdata->hFile = CreateFile(pwstrAFMFile, GENERIC_READ, ! 97: FILE_SHARE_READ, NULL, OPEN_EXISTING, ! 98: FILE_ATTRIBUTE_NORMAL, NULL); ! 99: ! 100: if (pdata->hFile == INVALID_HANDLE_VALUE) ! 101: { ! 102: #if DBG ! 103: DbgPrint("PSCRPTUI!CreatePFMFromAFM: CreateFile for %s failed.\n", ! 104: pwstrAFMFile); ! 105: #endif ! 106: LocalFree((LOCALHANDLE)pdata->pntfm); ! 107: LocalFree((LOCALHANDLE)pdata); ! 108: return(FALSE); ! 109: } ! 110: ! 111: // parse the AFM file, filling in the NTFM structure. ! 112: ! 113: ParseAfm(pdata); ! 114: ! 115: // close the AFM file. ! 116: ! 117: if (!CloseHandle(pdata->hFile)) ! 118: RIP("PSCRPTUI!CreatePFMFromAFM: CloseHandle failed to close afm file.\n"); ! 119: ! 120: // open the corresponding .PFA file, which had been created just ! 121: // prior to calling this routine. ! 122: ! 123: wcsncpy(wcbuf, pwstrPFMFile, (sizeof(wcbuf) / 2)); ! 124: pwstrPFAFile = wcbuf; ! 125: ! 126: while(*pwstrPFAFile) ! 127: pwstrPFAFile++; ! 128: ! 129: pwstrPFAFile--; ! 130: *pwstrPFAFile = (WCHAR)'A'; ! 131: ! 132: // reset pointer. ! 133: ! 134: pwstrPFAFile = wcbuf; ! 135: ! 136: if (!(pPFA = MapFile(pwstrPFAFile))) ! 137: { ! 138: RIP("PSCRPTUI!CreatePFMFromAFM: MapFile failed.\n"); ! 139: LocalFree((LOCALHANDLE)pdata->pntfm); ! 140: LocalFree((LOCALHANDLE)pdata->pTmpIFI); ! 141: LocalFree((LOCALHANDLE)pdata); ! 142: return(FALSE); ! 143: } ! 144: ! 145: BuildNTFM(pdata, pPFA); ! 146: ! 147: // we are, in fact, done with the .PFA file, so unmap it, and ! 148: // even delete it. ! 149: ! 150: UnmapViewOfFile((PVOID)pPFA); ! 151: DeleteFile(pwstrPFAFile); ! 152: ! 153: // create the PFM file from the NTFM structure. ! 154: ! 155: #ifdef ALL_METRICS ! 156: DbgPrint("Size of PFM file = %d\n", pntfm->cjThis); ! 157: #endif ! 158: ! 159: bReturn = WritePFM(pwstrPFMFile, pdata); ! 160: ! 161: LocalFree((LOCALHANDLE)pdata->pntfm); ! 162: LocalFree((LOCALHANDLE)pdata->pTmpIFI); ! 163: LocalFree((LOCALHANDLE)pdata); ! 164: ! 165: return(bReturn); ! 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.