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); }
CFX_ByteString _FPDF_LoadTableFromTT(FXSYS_FILE* pFile, FX_LPCBYTE pTables, FX_DWORD nTables, FX_DWORD tag) { for (FX_DWORD i = 0; i < nTables; i ++) { FX_LPCBYTE p = pTables + i * 16; if (GET_TT_LONG(p) == tag) { FX_DWORD offset = GET_TT_LONG(p + 8); FX_DWORD size = GET_TT_LONG(p + 12); FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); return _FPDF_ReadStringFromFile(pFile, size); } } return CFX_ByteString(); }
CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile, FX_LPCBYTE pTables, FX_DWORD nTables, FX_DWORD tag) { for (FX_DWORD i = 0; i < nTables; i ++) { FX_LPCBYTE p = pTables + i * 16; if (GET_TT_LONG(p) == tag) { FX_DWORD offset = GET_TT_LONG(p + 8); FX_DWORD size = GET_TT_LONG(p + 12); CFX_ByteString buffer; if (!pFile->ReadBlock(buffer.GetBuffer(size), offset, size)) { return CFX_ByteString(); } buffer.ReleaseBuffer(size); return buffer; } } return CFX_ByteString(); }
int GetTTCIndex(FX_LPCBYTE pFontData, FX_DWORD ttc_size, FX_DWORD font_offset) { int face_index = 0; FX_LPCBYTE p = pFontData + 8; FX_DWORD nfont = GET_TT_LONG(p); FX_DWORD index; for (index = 0; index < nfont; index ++) { p = pFontData + 12 + index * 4; if (GET_TT_LONG(p) == font_offset) { break; } } if(index >= nfont) { face_index = 0; } else { face_index = index; } return face_index; }
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 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); }
void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_DWORD filesize, FX_DWORD offset) { FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); char buffer[16]; if (!FXSYS_fread(buffer, 12, 1, pFile)) { return; } FX_DWORD nTables = GET_TT_SHORT(buffer + 4); CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16); CFX_ByteString names = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65); CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1); CFX_ByteString style = _FPDF_GetNameFromTT(names, 2); if (style != "Regular") { facename += " " + style; } FX_LPVOID p; if (m_FontList.Lookup(facename, p)) { return; } CFontFaceInfo* pInfo = FX_NEW CFontFaceInfo; if (!pInfo) { return; } pInfo->m_FilePath = path; pInfo->m_FaceName = facename; pInfo->m_FontTables = tables; pInfo->m_FontOffset = offset; pInfo->m_FileSize = filesize; pInfo->m_Charsets = 0; CFX_ByteString os2 = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32); if (os2.GetLength() >= 86) { FX_LPCBYTE p = (FX_LPCBYTE)os2 + 78; FX_DWORD codepages = GET_TT_LONG(p); if (codepages & (1 << 17)) { m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS; } if (codepages & (1 << 18)) { m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_GB; } if (codepages & (1 << 20)) { m_pMapper->AddInstalledFont(facename, FXFONT_CHINESEBIG5_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_BIG5; } if ((codepages & (1 << 19)) || (codepages & (1 << 21))) { m_pMapper->AddInstalledFont(facename, FXFONT_HANGEUL_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_KOREAN; } if (codepages & (1 << 31)) { m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL; } } m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET); pInfo->m_Charsets |= CHARSET_FLAG_ANSI; pInfo->m_Styles = 0; if (style.Find(FX_BSTRC("Bold")) > -1) { pInfo->m_Styles |= FXFONT_BOLD; } if (style.Find(FX_BSTRC("Italic")) > -1 || style.Find(FX_BSTRC("Oblique")) > -1) { pInfo->m_Styles |= FXFONT_ITALIC; } if (facename.Find(FX_BSTRC("Serif")) > -1) { pInfo->m_Styles |= FXFONT_SERIF; } m_FontList.SetAt(facename, pInfo); }