CPDF_Font* CPDF_DocPageData::GetStandardFont(FX_BSTR fontName, CPDF_FontEncoding* pEncoding) { if (fontName.IsEmpty()) { return NULL; } FX_POSITION pos = m_FontMap.GetStartPosition(); while (pos) { CPDF_Dictionary* fontDict; CPDF_CountedObject<CPDF_Font*>* fontData; m_FontMap.GetNextAssoc(pos, fontDict, fontData); CPDF_Font* pFont = fontData->m_Obj; if (!pFont) { continue; } if (pFont->GetBaseFont() != fontName) { continue; } if (pFont->IsEmbedded()) { continue; } if (pFont->GetFontType() != PDFFONT_TYPE1) { continue; } if (pFont->GetFontDict()->KeyExist(FX_BSTRC("Widths"))) { continue; } CPDF_Type1Font* pT1Font = pFont->GetType1Font(); if (pEncoding && !pT1Font->GetEncoding()->IsIdentical(pEncoding)) { continue; } fontData->m_nCount ++; return pFont; } CPDF_Dictionary* pDict = FX_NEW CPDF_Dictionary; pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Font")); pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Type1")); pDict->SetAtName(FX_BSTRC("BaseFont"), fontName); if (pEncoding) { pDict->SetAt(FX_BSTRC("Encoding"), pEncoding->Realize()); } m_pPDFDoc->AddIndirectObject(pDict); CPDF_CountedObject<CPDF_Font*>* fontData = FX_NEW CPDF_CountedObject<CPDF_Font*>; if (!fontData) { return NULL; } CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); if (!pFont) { delete fontData; return NULL; } fontData->m_nCount = 2; fontData->m_Obj = pFont; m_FontMap.SetAt(pDict, fontData); return pFont; }
void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, const CPDF_Dictionary* pResDict, CPDF_Font*& pSysFont, CFX_ByteString& sSysFontAlias) { if (!pDoc || !pResDict) return; CFX_ByteString sFontAlias; CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictBy("AcroForm"); CPDF_Font* pPDFFont = AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias); if (!pPDFFont) return; if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) { if (!pFontList->KeyExist(sSysFontAlias)) pFontList->SetAtReference(sSysFontAlias, pDoc, pPDFFont->GetFontDict()); } pSysFont = pPDFFont; }
CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteStringC& fontName, CPDF_FontEncoding* pEncoding) { if (fontName.IsEmpty()) return nullptr; for (auto& it : m_FontMap) { CPDF_CountedFont* fontData = it.second; CPDF_Font* pFont = fontData->get(); if (!pFont) continue; if (pFont->GetBaseFont() != fontName) continue; if (pFont->IsEmbedded()) continue; if (!pFont->IsType1Font()) continue; if (pFont->GetFontDict()->KeyExist("Widths")) continue; CPDF_Type1Font* pT1Font = pFont->AsType1Font(); if (pEncoding && !pT1Font->GetEncoding()->IsIdentical(pEncoding)) continue; return fontData->AddRef(); } CPDF_Dictionary* pDict = new CPDF_Dictionary; pDict->SetAtName("Type", "Font"); pDict->SetAtName("Subtype", "Type1"); pDict->SetAtName("BaseFont", fontName); if (pEncoding) { pDict->SetAt("Encoding", pEncoding->Realize()); } m_pPDFDoc->AddIndirectObject(pDict); CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); if (!pFont) { return nullptr; } CPDF_CountedFont* fontData = new CPDF_CountedFont(pFont); m_FontMap[pDict] = fontData; return fontData->AddRef(); }