void CPDF_CIDFont::LoadSubstFont() { pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); safeStemV *= 5; m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, g_CharsetCPs[m_Charset], IsVertWriting()); }
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); }
uint32_t CPDF_Font::FallbackFontFromCharcode(uint32_t charcode) { if (m_FontFallbacks.empty()) { m_FontFallbacks.push_back(pdfium::MakeUnique<CFX_Font>()); m_FontFallbacks[0]->LoadSubst("Arial", IsTrueTypeFont(), m_Flags, m_StemV * 5, m_ItalicAngle, 0, IsVertWriting()); } return 0; }
bool CPDF_CIDFont::Load() { if (m_pFontDict->GetStringFor("Subtype") == "TrueType") { LoadGB2312(); return true; } CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); if (!pFonts || pFonts->GetCount() != 1) return false; CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); if (!pCIDFontDict) return false; m_BaseFont = pCIDFontDict->GetStringFor("BaseFont"); if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd-Bold") == 0 || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.Compare("CourierStd-Oblique") == 0) && !IsEmbedded()) { m_bAdobeCourierStd = true; } CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); if (pFontDesc) LoadFontDescriptor(pFontDesc); CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding"); if (!pEncoding) return false; CFX_ByteString subtype = pCIDFontDict->GetStringFor("Subtype"); m_bType1 = (subtype == "CIDFontType0"); CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager; if (pEncoding->IsName()) { CFX_ByteString cmap = pEncoding->GetString(); bool bPromptCJK = m_pFontFile && m_bType1; m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK); if (!m_pCMap) return false; } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { m_pCMap = pdfium::MakeUnique<CPDF_CMap>(); CPDF_StreamAcc acc; acc.LoadAllData(pStream, false); m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); } else { return false; } m_Charset = m_pCMap->m_Charset; if (m_Charset == CIDSET_UNKNOWN) { CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); if (pCIDInfo) { m_Charset = CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC()); } } if (m_Charset != CIDSET_UNKNOWN) { bool bPromptCJK = !m_pFontFile && (m_pCMap->m_Coding == CIDCODING_CID || pCIDFontDict->KeyExist("W")); m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, bPromptCJK); } if (m_Font.GetFace()) { if (m_bType1) FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); else FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding); } m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000); CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_WidthList, 1); if (!IsEmbedded()) LoadSubstFont(); if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); if (pmap) { if (CPDF_Stream* pStream = pmap->AsStream()) { m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>(); m_pStreamAcc->LoadAllData(pStream, false); } else if (pmap->GetString() == "Identity") { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ if (m_pFontFile) m_bCIDIsGID = true; #else m_bCIDIsGID = true; #endif } } } CheckFontMetrics(); if (IsVertWriting()) { pWidthArray = pCIDFontDict->GetArrayFor("W2"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_VertMetrics, 3); CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); if (pDefaultArray) { m_DefaultVY = pDefaultArray->GetIntegerAt(0); m_DefaultW1 = pDefaultArray->GetIntegerAt(1); } else { m_DefaultVY = 880; m_DefaultW1 = -1000; } } return true; }
bool CPDF_CIDFont::Load() { if (m_pFontDict->GetStringFor("Subtype") == "TrueType") { LoadGB2312(); return true; } const CPDF_Array* pFonts = m_pFontDict->GetArrayFor("DescendantFonts"); if (!pFonts || pFonts->size() != 1) return false; const CPDF_Dictionary* pCIDFontDict = pFonts->GetDictAt(0); if (!pCIDFontDict) return false; m_BaseFont = pCIDFontDict->GetStringFor("BaseFont"); if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd-Bold") == 0 || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.Compare("CourierStd-Oblique") == 0) && !IsEmbedded()) { m_bAdobeCourierStd = true; } const CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor"); if (pFontDesc) LoadFontDescriptor(pFontDesc); CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding"); if (!pEncoding) return false; ByteString subtype = pCIDFontDict->GetStringFor("Subtype"); m_bType1 = (subtype == "CIDFontType0"); CPDF_CMapManager* manager = GetFontGlobals()->GetCMapManager(); if (pEncoding->IsName()) { ByteString cmap = pEncoding->GetString(); m_pCMap = manager->GetPredefinedCMap(cmap); if (!m_pCMap) return false; } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); pAcc->LoadAllDataFiltered(); m_pCMap = pdfium::MakeRetain<CPDF_CMap>(); m_pCMap->LoadEmbedded(pAcc->GetSpan()); } else { return false; } m_Charset = m_pCMap->GetCharset(); if (m_Charset == CIDSET_UNKNOWN) { const CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); if (pCIDInfo) { m_Charset = CPDF_CMapParser::CharsetFromOrdering( pCIDInfo->GetStringFor("Ordering").AsStringView()); } } if (m_Charset != CIDSET_UNKNOWN) { m_pCID2UnicodeMap = manager->GetCID2UnicodeMap(m_Charset); } if (m_Font.GetFace()) { if (m_bType1) FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); else FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->GetCoding()); } m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000); const CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_WidthList, 1); if (!IsEmbedded()) LoadSubstFont(); const CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); if (pmap) { if (const CPDF_Stream* pStream = pmap->AsStream()) { m_pStreamAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); m_pStreamAcc->LoadAllDataFiltered(); } else if (m_pFontFile && pmap->GetString() == "Identity") { m_bCIDIsGID = true; } } CheckFontMetrics(); if (IsVertWriting()) { pWidthArray = pCIDFontDict->GetArrayFor("W2"); if (pWidthArray) LoadMetricsArray(pWidthArray, &m_VertMetrics, 3); const CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2"); if (pDefaultArray) { m_DefaultVY = pDefaultArray->GetIntegerAt(0); m_DefaultW1 = pDefaultArray->GetIntegerAt(1); } } return true; }