void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, const CFX_WideString* pFaceName) { if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) return; std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor); pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; pFont->m_dwFontStyles |= GetFlags(pFace); std::vector<uint16_t> charsets = GetCharsets(pFace); GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); FT_ULong dwTag; FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e'); std::vector<uint8_t> table; unsigned long nLength = 0; unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength); if (error == 0 && nLength != 0) { table.resize(nLength); if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr)) table.clear(); } GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames); pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); pFont->m_wsFaceName = pFaceName ? *pFaceName : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); pFont->m_nFaceIndex = pFace->face_index; m_InstalledFonts.Add(pFont.release()); }
IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont) { if (!pFont) { return NULL; } if (NULL == pFont->m_pGsubData) { unsigned long length = 0; int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length); if (!error) { pFont->m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length); } if (!pFont->m_pGsubData) { return NULL; } } int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, pFont->m_pGsubData, NULL); if (!error && pFont->m_pGsubData) { CFX_GSUBTable* pGsubTable = FX_NEW CFX_GSUBTable; if (!pGsubTable) { return NULL; } if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->m_pGsubData)) { return pGsubTable; } pGsubTable->Release(); } return NULL; }
int CPDF_CIDFont::GetGlyphIndex(uint32_t unicode, bool* pVertGlyph) { if (pVertGlyph) *pVertGlyph = false; FXFT_Face face = m_Font.GetFace(); int index = FXFT_Get_Char_Index(face, unicode); if (unicode == 0x2502) return index; if (!index || !IsVertWriting()) return index; if (m_pTTGSUBTable) return GetVerticalGlyph(index, pVertGlyph); if (!m_Font.GetSubData()) { unsigned long length = 0; int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, nullptr, &length); if (!error) m_Font.SetSubData(FX_Alloc(uint8_t, length)); } int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, m_Font.GetSubData(), nullptr); if (error || !m_Font.GetSubData()) return index; m_pTTGSUBTable = pdfium::MakeUnique<CFX_CTTGSUBTable>(); m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); return GetVerticalGlyph(index, pVertGlyph); }
// static IFX_GSUBTable* IFX_GSUBTable::Create(CFX_Font* pFont) { if (!pFont) { return NULL; } if (!pFont->GetSubData()) { unsigned long length = 0; int error = FXFT_Load_Sfnt_Table( pFont->GetFace(), FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length); if (!error) { pFont->SetSubData((uint8_t*)FX_Alloc(uint8_t, length)); } if (!pFont->GetSubData()) { return NULL; } } int error = FXFT_Load_Sfnt_Table(pFont->GetFace(), FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, pFont->GetSubData(), NULL); if (!error && pFont->GetSubData()) { nonstd::unique_ptr<CFX_GSUBTable> pGsubTable(new CFX_GSUBTable); if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->GetSubData())) { return pGsubTable.release(); } } return NULL; }
FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable, FX_LPBYTE pBuffer, FX_DWORD dwSize) { if (!m_Face) { return FALSE; } if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, (unsigned long*)&dwSize)) { return 0; } return dwSize; }
FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable, uint8_t* pBuffer, FX_DWORD dwSize) { if (!m_Face) { return 0; } FT_ULong ulSize = pdfium::base::checked_cast<FT_ULong>(dwSize); if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, &ulSize)) { return 0; } return pdfium::base::checked_cast<FX_DWORD>(ulSize); }