void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) { FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); if (pFile == NULL) { return; } FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); FX_DWORD filesize = FXSYS_ftell(pFile); FX_BYTE buffer[16]; FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); if (GET_TT_LONG(buffer) == 0x74746366) { FX_DWORD nFaces = GET_TT_LONG(buffer + 8); FX_LPBYTE offsets = FX_Alloc(FX_BYTE, nFaces * 4); if (!offsets) { FXSYS_fclose(pFile); return; } readCnt = FXSYS_fread(offsets, nFaces * 4, 1, pFile); for (FX_DWORD i = 0; i < nFaces; i ++) { FX_LPBYTE p = offsets + i * 4; ReportFace(path, pFile, filesize, GET_TT_LONG(p)); } FX_Free(offsets); } else { ReportFace(path, pFile, filesize, 0); } FXSYS_fclose(pFile); }
void CFXCRT_FileAccess_CRT::Close() { if (!m_hFile) { return; } FXSYS_fclose(m_hFile); m_hFile = NULL; }
void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) { FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); if (pFile == NULL) { return; } FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); FX_DWORD filesize = FXSYS_ftell(pFile); uint8_t buffer[16]; FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); if (readCnt != 1) { FXSYS_fclose(pFile); return; } if (GET_TT_LONG(buffer) == 0x74746366) { FX_DWORD nFaces = GET_TT_LONG(buffer + 8); if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) { FXSYS_fclose(pFile); return; } FX_DWORD face_bytes = nFaces * 4; uint8_t* offsets = FX_Alloc(uint8_t, face_bytes); readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); if (readCnt != face_bytes) { FX_Free(offsets); FXSYS_fclose(pFile); return; } for (FX_DWORD i = 0; i < nFaces; i ++) { uint8_t* p = offsets + i * 4; ReportFace(path, pFile, filesize, GET_TT_LONG(p)); } FX_Free(offsets); } else { ReportFace(path, pFile, filesize, 0); } FXSYS_fclose(pFile); }
FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name) { FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR)"rb"); if (file == NULL) { return NULL; } FX_BYTE buf[256]; FXSYS_fread(buf, 1, 20, file); if (*(FX_DWORD*)buf != 0x43465846) { FXSYS_fclose(file); return NULL; } FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1); pPackage->m_pFile = file; pPackage->m_nFiles = *(int*)(buf + 8); pPackage->m_IndexSize = *(int*)(buf + 12); pPackage->m_IndexOffset = *(int*)(buf + 16); return pPackage; }
FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) { if (hFont == NULL) { return 0; } CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; FXSYS_FILE* pFile = NULL; if (size > 0) { pFile = FXSYS_fopen(pFont->m_FilePath, "rb"); if (pFile == NULL) { return 0; } } FX_DWORD datasize = 0; FX_DWORD offset; if (table == 0) { datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize; offset = 0; } else if (table == 0x74746366) { datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0; offset = 0; } else { FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16; for (FX_DWORD i = 0; i < nTables; i ++) { FX_LPCBYTE p = (FX_LPCBYTE)pFont->m_FontTables + i * 16; if (GET_TT_LONG(p) == table) { offset = GET_TT_LONG(p + 8); datasize = GET_TT_LONG(p + 12); } } } if (datasize && size >= datasize && pFile) { FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); size_t readCnt = FXSYS_fread(buffer, datasize, 1, pFile); } if (pFile) { FXSYS_fclose(pFile); } return datasize; }
void FXFC_ClosePackage(FX_LPVOID p) { FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; FXSYS_fclose(pPackage->m_pFile); FX_Free(pPackage); }