// // Copyright (c) 1997-1999 Microsoft Corporation. // #include "stdafx.h" #pragma pack(2) #include "vdata.h" #include "ttfstruc.h" #include "extfunc.h" /* * Win3.1J EUDC fontfile i/o */ #define EUDCCODEBASE ((unsigned short)0xe000) /* File Structure */ struct W31_Header { char identify[72]; short segCnt; /* ??? */ unsigned short sCode, eCode; short cCnt; long ofsCmap; short sizCmap; long ofsFil; short sizFil; long ofsStbl; /* search tbl*/ short sizStbl; long ofsBdatSub; }; struct BDatSubTbl { long tail; long filler1; long head; short filler2; /* Following Pointer tbl. */ }; struct BMPHeader { long bitmapSiz; short xsiz, ysiz; }; static int ReadBdatSub(HANDLE hdl,long ofs,struct BDatSubTbl *tbl); static int WriteBdatSub(HANDLE hdl,long ofs,struct BDatSubTbl *tbl); static int ReadBDatEntry(HANDLE hdl,long *ofs,long rec); static int WriteBDatEntry(HANDLE hdl,long ofs,long rec); static int ReadBMPHdr(HANDLE hdl,long ofs,struct BMPHeader *hdr); static int WriteBMPHdr(HANDLE hdl,long ofs,struct BMPHeader *hdr); static int init = 0; static long bdathead; static long bdatptr; static int maxRec; static TCHAR fpath[128]; /*************************************************************** * Initialize */ /* */ int /* */ OpenW31JEUDC( TCHAR *path) /* * returns : 0, -1 ***************************************************************/ { HANDLE fHdl; struct W31_Header hdr; DWORD nByte; BOOL res; makeUniCodeTbl(); lstrcpy( fpath, path); /* open EUDC Font File */ fHdl = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( fHdl == INVALID_HANDLE_VALUE) return -1; /* Read Header */ res = ReadFile( fHdl, &hdr, sizeof(struct W31_Header), &nByte, NULL); if (!res || nByte !=sizeof(struct W31_Header)) { CloseHandle(fHdl); return -1; } bdathead = hdr.ofsBdatSub; bdatptr = hdr.ofsBdatSub + sizeof(struct BDatSubTbl); maxRec = hdr.cCnt-1; /* close Font File */ CloseHandle( fHdl); init = 1; return 0; } /*************************************************************** * Terminate Close */ /* */ void /* */ CloseW31JEUDC() /* * returns : none ***************************************************************/ { init = 0; return; } static int codeToRec( unsigned short code, BOOL bUnicode) { return (int)((bUnicode ? code : sjisToUniEUDC(code)) - EUDCCODEBASE); } /*************************************************************** * Read Bitmap */ /* */ int /* */ GetW31JEUDCFont( /* */ unsigned short code, /* native-code */ /* */ LPBYTE buf, /* buffer to set bitmap */ /* */ int bufsiz, /* Buffer Size */ /* */ int *xsiz, /* Bitmap X,Ysiz */ /* */ int *ysiz, /* */ BOOL bUnicode) /* * returns : >=0, -1 ***************************************************************/ { HANDLE fHdl; long ofs; struct BMPHeader fhdr; int bmpsiz; int rdsiz; int rec; DWORD nByte; BOOL res; rec = codeToRec( code, bUnicode); if (init==0) return -1; else if ( maxRec < rec || rec < 0) return -1; /* Open Font File */ fHdl = CreateFile(fpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( fHdl == INVALID_HANDLE_VALUE) return -1; /* read bitmap ptr on subTable */ ofs = bdatptr + sizeof(long)*rec; if ( (long) SetFilePointer( fHdl, ofs, NULL, FILE_BEGIN)!=ofs) goto ECLOSE_RET; res = ReadFile( fHdl, &ofs, sizeof(long), &nByte, NULL); if (!res || nByte !=sizeof(long)) goto ECLOSE_RET; if ( ofs==0L) goto ECLOSE_RET; ofs += bdathead; /* read Bitmap Header bitmap is Word aligned */ if ( (long) SetFilePointer( fHdl, ofs, NULL, FILE_BEGIN)!=ofs) goto ECLOSE_RET; res = ReadFile( fHdl, &fhdr, sizeof(struct BMPHeader), &nByte, NULL); if (!res || nByte != sizeof( struct BMPHeader)) goto ECLOSE_RET; bmpsiz = ((int)fhdr.xsiz+15)/16 *2 * (int)fhdr.ysiz; /* Read Bitmap Body */ rdsiz = bmpsiz > bufsiz ? bufsiz : bmpsiz; res = ReadFile( fHdl, buf, (unsigned short)rdsiz, &nByte, NULL); if (!res || nByte !=(unsigned short)rdsiz) goto ECLOSE_RET; rdsiz = bmpsiz > bufsiz ? bmpsiz - bufsiz : 0; *xsiz = fhdr.xsiz; *ysiz = fhdr.ysiz; CloseHandle (fHdl); return rdsiz; ECLOSE_RET: CloseHandle (fHdl); return -1; } /*************************************************************** * Write Bitmap */ /* */ int /* */ PutW31JEUDCFont( /* */ unsigned short code, /* native code */ /* */ LPBYTE buf, /* buffer to set bitmap */ /* */ int xsiz, /* Bitmap X,Ysiz */ /* */ int ysiz, /* */ BOOL bUnicode) /* * returns : 0, -1 ***************************************************************/ { HANDLE fHdl; long ofs; struct BMPHeader fhdr; int bmpsiz; int wbmpsiz; struct BDatSubTbl subTbl; int rec; DWORD nByte; BOOL res; rec = codeToRec( code, bUnicode); if (init==0) return -1; else if ( maxRec < rec || rec < 0) return -1; /* Open Font File */ fHdl = CreateFile(fpath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( fHdl == INVALID_HANDLE_VALUE) return -1; /* read bitmap ptr on subTable */ if (ReadBDatEntry( fHdl, &ofs, rec)) goto ECLOSE_RET; wbmpsiz = (xsiz+15)/16 *2 * ysiz; if ( ofs != 0L) { /* read Bitmap Header bitmap is Word aligned */ if ( ReadBMPHdr( fHdl, ofs, &fhdr)) goto ECLOSE_RET; bmpsiz = ((int)fhdr.xsiz+15)/16 *2 * (int)fhdr.ysiz; if ( bmpsiz>3] |= (0x80>>(wc%8)); } Done: CloseHandle(fHdl); return bRet; }