FX_FILESIZE CFXCRT_FileAccess_CRT::GetSize() const { if (!m_hFile) { return 0; } FX_FILESIZE pos = (FX_FILESIZE)FXSYS_ftell(m_hFile); FXSYS_fseek(m_hFile, 0, FXSYS_SEEK_END); FX_FILESIZE size = (FX_FILESIZE)FXSYS_ftell(m_hFile); FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); return size; }
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); }
FX_FILESIZE CFXCRT_FileAccess_CRT::GetPosition() const { if (!m_hFile) { return (FX_FILESIZE) - 1; } return (FX_FILESIZE)FXSYS_ftell(m_hFile); }
FX_FILESIZE CFXCRT_FileAccess_CRT::SetPosition(FX_FILESIZE pos) { if (!m_hFile) { return (FX_FILESIZE) - 1; } FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); return (FX_FILESIZE)FXSYS_ftell(m_hFile); }
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); }