CFX_ByteString GetNameFromTT(const uint8_t* name_table, uint32_t name_table_size, uint32_t name_id) { if (!name_table || name_table_size < 6) { return CFX_ByteString(); } uint32_t name_count = GET_TT_SHORT(name_table + 2); uint32_t string_offset = GET_TT_SHORT(name_table + 4); // We will ignore the possibility of overlap of structures and // string table as if it's all corrupt there's not a lot we can do. if (name_table_size < string_offset) { return CFX_ByteString(); } const uint8_t* string_ptr = name_table + string_offset; uint32_t string_ptr_size = name_table_size - string_offset; name_table += 6; name_table_size -= 6; if (name_table_size < name_count * 12) { return CFX_ByteString(); } for (uint32_t i = 0; i < name_count; i++, name_table += 12) { if (GET_TT_SHORT(name_table + 6) == name_id && GET_TT_SHORT(name_table) == 1 && GET_TT_SHORT(name_table + 2) == 0) { return GetStringFromTable(string_ptr, string_ptr_size, GET_TT_SHORT(name_table + 10), GET_TT_SHORT(name_table + 8)); } } return CFX_ByteString(); }
CFX_ByteString _FPDF_GetNameFromTT(FX_LPCBYTE name_table, FX_DWORD name_id) { FX_LPCBYTE ptr = name_table + 2; int name_count = GET_TT_SHORT(ptr); int string_offset = GET_TT_SHORT(ptr + 2); FX_LPCBYTE string_ptr = name_table + string_offset; ptr += 4; for (int i = 0; i < name_count; i ++) { if (GET_TT_SHORT(ptr + 6) == name_id && GET_TT_SHORT(ptr) == 1 && GET_TT_SHORT(ptr + 2) == 0) { return CFX_ByteStringC(string_ptr + GET_TT_SHORT(ptr + 10), GET_TT_SHORT(ptr + 8)); } ptr += 12; } return CFX_ByteString(); }
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); }