FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary* pOCGDict, FX_BOOL& bValidConfig) const { CPDF_Dictionary* pConfig = FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csConfig); if (!pConfig) { return TRUE; } bValidConfig = TRUE; FX_BOOL bState = pConfig->GetStringBy("BaseState", "ON") != "OFF"; CPDF_Array* pArray = pConfig->GetArrayBy("ON"); if (pArray) { if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { bState = TRUE; } } pArray = pConfig->GetArrayBy("OFF"); if (pArray) { if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { bState = FALSE; } } pArray = pConfig->GetArrayBy("AS"); if (pArray) { CFX_ByteString csFind = csConfig + "State"; int32_t iCount = pArray->GetCount(); for (int32_t i = 0; i < iCount; i++) { CPDF_Dictionary* pUsage = pArray->GetDictAt(i); if (!pUsage) { continue; } if (pUsage->GetStringBy("Event", "View") != csConfig) { continue; } CPDF_Array* pOCGs = pUsage->GetArrayBy("OCGs"); if (!pOCGs) { continue; } if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { continue; } CPDF_Dictionary* pState = pUsage->GetDictBy(csConfig); if (!pState) { continue; } bState = pState->GetStringBy(csFind) != "OFF"; } } return bState; }
CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_BOOL bInheritable, FX_FLOAT fLevel) { if (fLevel > nMaxRecursion) { return nullptr; } if (bInheritable) { CPDF_Object* pAttr = GetAttr(owner, name, FALSE); if (pAttr) { return pAttr; } if (!m_pParent) { return nullptr; } return m_pParent->GetAttr(owner, name, TRUE, fLevel + 1); } CPDF_Object* pA = m_pDict->GetDirectObjectBy("A"); if (pA) { CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner); if (pAttrDict) { CPDF_Object* pAttr = pAttrDict->GetDirectObjectBy(CFX_ByteString(name)); if (pAttr) { return pAttr; } } } CPDF_Object* pC = m_pDict->GetDirectObjectBy("C"); if (!pC) return nullptr; CPDF_Dictionary* pClassMap = m_pTree->m_pTreeRoot->GetDictBy("ClassMap"); if (!pClassMap) return nullptr; if (CPDF_Array* pArray = pC->AsArray()) { for (uint32_t i = 0; i < pArray->GetCount(); i++) { CFX_ByteString class_name = pArray->GetStringAt(i); CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); if (pClassDict && pClassDict->GetStringBy("O") == owner) return pClassDict->GetDirectObjectBy(CFX_ByteString(name)); } return nullptr; } CFX_ByteString class_name = pC->GetString(); CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); if (pClassDict && pClassDict->GetStringBy("O") == owner) return pClassDict->GetDirectObjectBy(CFX_ByteString(name)); return nullptr; }
CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) : m_pDocument(pPage->m_pDocument) { if (!pPage->m_pFormDict) return; CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); if (!pAnnots) return; CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); for (size_t i = 0; i < pAnnots->GetCount(); ++i) { CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); if (!pDict) continue; uint32_t dwObjNum = pDict->GetObjNum(); if (dwObjNum == 0) { dwObjNum = m_pDocument->AddIndirectObject(pDict); CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); pAnnots->InsertAt(i, pAction); pAnnots->RemoveAt(i + 1); pDict = pAnnots->GetDictAt(i); } // Skip creating Popup annotation in the PDF document since PDFium provides // its own Popup annotations. if (pDict->GetStringBy("Subtype") == "Popup") continue; m_AnnotList.push_back( std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument, false))); if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && CPDF_InterForm::IsUpdateAPEnabled()) { FPDF_GenerateAP(m_pDocument, pDict); } } size_t nAnnotListSize = m_AnnotList.size(); for (size_t i = 0; i < nAnnotListSize; ++i) { std::unique_ptr<CPDF_Annot> pPopupAnnot( CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); if (pPopupAnnot) m_AnnotList.push_back(std::move(pPopupAnnot)); } }
int CPDFSDK_BAAnnot::GetBorderStyle() const { CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); if (pBSDict) { CFX_ByteString sBorderStyle = pBSDict->GetStringBy("S", "S"); if (sBorderStyle == "S") return BBS_SOLID; if (sBorderStyle == "D") return BBS_DASH; if (sBorderStyle == "B") return BBS_BEVELED; if (sBorderStyle == "I") return BBS_INSET; if (sBorderStyle == "U") return BBS_UNDERLINE; } CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border"); if (pBorder) { if (pBorder->GetCount() >= 4) { CPDF_Array* pDP = pBorder->GetArrayAt(3); if (pDP && pDP->GetCount() > 0) return BBS_DASH; } } return BBS_SOLID; }
CPDF_FormField* CPDF_InterForm::CheckRequiredFields( const std::vector<CPDF_FormField*>* fields, bool bIncludeOrExclude) const { int nCount = m_pFieldTree->m_Root.CountFields(); for (int i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); if (!pField) continue; int32_t iType = pField->GetType(); if (iType == CPDF_FormField::PushButton || iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { continue; } uint32_t dwFlags = pField->GetFieldFlags(); // TODO(thestig): Look up these magic numbers and add constants for them. if (dwFlags & 0x04) continue; bool bFind = true; if (fields) bFind = pdfium::ContainsValue(*fields, pField); if (bIncludeOrExclude == bFind) { CPDF_Dictionary* pFieldDict = pField->m_pDict; if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty()) return pField; } } return nullptr; }
static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, const CFX_ByteStringC& owner, FX_FLOAT nLevel = 0.0F) { if (nLevel > nMaxRecursion) return nullptr; if (!pAttrs) return nullptr; CPDF_Dictionary* pDict = nullptr; if (pAttrs->IsDictionary()) { pDict = pAttrs->AsDictionary(); } else if (CPDF_Stream* pStream = pAttrs->AsStream()) { pDict = pStream->GetDict(); } else if (CPDF_Array* pArray = pAttrs->AsArray()) { for (uint32_t i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetDirectObjectAt(i); pDict = FindAttrDict(pElement, owner, nLevel + 1); if (pDict) return pDict; } } if (pDict && pDict->GetStringBy("O") == owner) return pDict; return nullptr; }
void CPDF_FormField::LoadDA() { CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; if (!pFormDict) return; CFX_ByteString DA; if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) DA = pObj->GetString(); if (DA.IsEmpty()) DA = pFormDict->GetStringBy("DA"); if (DA.IsEmpty()) return; CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) return; CPDF_Dictionary* pFont = pDR->GetDictBy("Font"); if (!pFont) return; CPDF_SimpleParser syntax(DA.AsStringC()); syntax.FindTagParamFromStart("Tf", 2); CFX_ByteString font_name(syntax.GetWord()); CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name); if (!pFontDict) return; m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); m_FontSize = FX_atof(syntax.GetWord()); }
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont, CFX_ByteString& csNameTag) { if (!pFormDict || !pFont) { return FALSE; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return FALSE; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return FALSE; } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) { continue; } CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") { continue; } if (pFont->GetFontDict() == pElement) { csNameTag = csKey; return TRUE; } } return FALSE; }
CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, FX_DWORD index, CFX_ByteString& csNameTag) { if (!pFormDict) { return NULL; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return NULL; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return NULL; } FX_DWORD dwCount = 0; for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) { continue; } CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") continue; if (dwCount == index) { csNameTag = csKey; return pDocument->LoadFont(pElement); } dwCount++; } return NULL; }
FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, FX_BOOL bNotify) { if (!pFDF) return FALSE; CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); if (!pMainDict) return FALSE; CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); if (!pFields) return FALSE; m_bsEncoding = pMainDict->GetStringBy("Encoding"); if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) return FALSE; for (size_t i = 0; i < pFields->GetCount(); i++) { CPDF_Dictionary* pField = pFields->GetDictAt(i); if (!pField) continue; FDF_ImportField(pField, L"", bNotify); } if (bNotify && m_pFormNotify) m_pFormNotify->AfterFormImportData(this); return TRUE; }
void CPDF_StructElementImpl::LoadKid(uint32_t PageObjNum, CPDF_Object* pKidObj, CPDF_StructKid* pKid) { pKid->m_Type = CPDF_StructKid::Invalid; if (!pKidObj) return; if (pKidObj->IsNumber()) { if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { return; } pKid->m_Type = CPDF_StructKid::PageContent; pKid->m_PageContent.m_ContentId = pKidObj->GetInteger(); pKid->m_PageContent.m_PageObjNum = PageObjNum; return; } CPDF_Dictionary* pKidDict = pKidObj->AsDictionary(); if (!pKidDict) return; if (CPDF_Reference* pRef = ToReference(pKidDict->GetObjectBy("Pg"))) PageObjNum = pRef->GetRefObjNum(); CFX_ByteString type = pKidDict->GetStringBy("Type"); if (type == "MCR") { if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { return; } pKid->m_Type = CPDF_StructKid::StreamContent; if (CPDF_Reference* pRef = ToReference(pKidDict->GetObjectBy("Stm"))) { pKid->m_StreamContent.m_RefObjNum = pRef->GetRefObjNum(); } else { pKid->m_StreamContent.m_RefObjNum = 0; } pKid->m_StreamContent.m_PageObjNum = PageObjNum; pKid->m_StreamContent.m_ContentId = pKidDict->GetIntegerBy("MCID"); } else if (type == "OBJR") { if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { return; } pKid->m_Type = CPDF_StructKid::Object; if (CPDF_Reference* pObj = ToReference(pKidDict->GetObjectBy("Obj"))) { pKid->m_Object.m_RefObjNum = pObj->GetRefObjNum(); } else { pKid->m_Object.m_RefObjNum = 0; } pKid->m_Object.m_PageObjNum = PageObjNum; } else { pKid->m_Type = CPDF_StructKid::Element; pKid->m_Element.m_pDict = pKidDict; if (!m_pTree->m_pPage) { pKid->m_Element.m_pElement = new CPDF_StructElementImpl(m_pTree, this, pKidDict); } else { pKid->m_Element.m_pElement = nullptr; } } }
FX_BOOL CPDF_ViewerPreferences::PrintScaling() const { CPDF_Dictionary* pDict = m_pDoc->GetRoot(); pDict = pDict->GetDictBy("ViewerPreferences"); if (!pDict) { return TRUE; } return "None" != pDict->GetStringBy("PrintScaling"); }
CFX_ByteString CPDF_ViewerPreferences::Duplex() const { CPDF_Dictionary* pDict = m_pDoc->GetRoot(); pDict = pDict->GetDictBy("ViewerPreferences"); if (!pDict) { return "None"; } return pDict->GetStringBy("Duplex"); }
FX_BOOL CPDF_ViewerPreferences::IsDirectionR2L() const { CPDF_Dictionary* pDict = m_pDoc->GetRoot(); pDict = pDict->GetDictBy("ViewerPreferences"); if (!pDict) { return FALSE; } return "R2L" == pDict->GetStringBy("Direction"); }
void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, std::vector<CPDF_Dictionary*>* pList) { CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); if (!pAnnotList) return; for (size_t i = 0; i < pAnnotList->GetCount(); ++i) { CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(i); bool add_link = (pAnnot && pAnnot->GetStringBy("Subtype") == "Link"); // Add non-links as nullptrs to preserve z-order. pList->push_back(add_link ? pAnnot : nullptr); } }
FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const { if (!FPDFDOC_OCG_HasIntent(pOCGDict, "View", "View")) { return TRUE; } CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType); CPDF_Dictionary* pUsage = pOCGDict->GetDictBy("Usage"); if (pUsage) { CPDF_Dictionary* pState = pUsage->GetDictBy(csState); if (pState) { CFX_ByteString csFind = csState + "State"; if (pState->KeyExist(csFind)) { return pState->GetStringBy(csFind) != "OFF"; } } if (csState != "View") { pState = pUsage->GetDictBy("View"); if (pState && pState->KeyExist("ViewState")) { return pState->GetStringBy("ViewState") != "OFF"; } } } FX_BOOL bDefValid = FALSE; return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid); }
void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { CPDF_Dictionary* pPageDict = pPage->m_pFormDict; if (!pPageDict) return; CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); if (!pAnnots) return; for (size_t i = 0; i < pAnnots->GetCount(); i++) { CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") LoadField(pAnnot); } }
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, CPDF_Font*& pFont, CFX_ByteString& csNameTag) { if (!pFormDict) { return FALSE; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return FALSE; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return FALSE; } if (csFontName.GetLength() > 0) { csFontName.Remove(' '); } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) { continue; } CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") { continue; } pFont = pDocument->LoadFont(pElement); if (!pFont) { continue; } CFX_ByteString csBaseFont; csBaseFont = pFont->GetBaseFont(); csBaseFont.Remove(' '); if (csBaseFont == csFontName) { csNameTag = csKey; return TRUE; } } return FALSE; }
static FX_BOOL LoadCryptInfo(CPDF_Dictionary* pEncryptDict, const CFX_ByteString& name, int& cipher, int& keylen) { int Version = pEncryptDict->GetIntegerBy("V"); cipher = FXCIPHER_RC4; keylen = 0; if (Version >= 4) { CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDictBy("CF"); if (!pCryptFilters) { return FALSE; } if (name == "Identity") { cipher = FXCIPHER_NONE; } else { CPDF_Dictionary* pDefFilter = pCryptFilters->GetDictBy(name); if (!pDefFilter) { return FALSE; } int nKeyBits = 0; if (Version == 4) { nKeyBits = pDefFilter->GetIntegerBy("Length", 0); if (nKeyBits == 0) { nKeyBits = pEncryptDict->GetIntegerBy("Length", 128); } } else { nKeyBits = pEncryptDict->GetIntegerBy("Length", 256); } if (nKeyBits < 40) { nKeyBits *= 8; } keylen = nKeyBits / 8; CFX_ByteString cipher_name = pDefFilter->GetStringBy("CFM"); if (cipher_name == "AESV2" || cipher_name == "AESV3") { cipher = FXCIPHER_AES; } } } else { keylen = Version > 1 ? pEncryptDict->GetIntegerBy("Length", 40) / 8 : 5; } if (keylen > 32 || keylen < 0) { return FALSE; } return TRUE; }
void CPDF_PageObjectList::LoadTransInfo() { if (!m_pFormDict) { return; } CPDF_Dictionary* pGroup = m_pFormDict->GetDictBy("Group"); if (!pGroup) { return; } if (pGroup->GetStringBy("S") != "Transparency") { return; } m_Transparency |= PDFTRANS_GROUP; if (pGroup->GetIntegerBy("I")) { m_Transparency |= PDFTRANS_ISOLATED; } if (pGroup->GetIntegerBy("K")) { m_Transparency |= PDFTRANS_KNOCKOUT; } }
CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, CFX_ByteString& csNameTag) { if (!pFormDict || csFontName.IsEmpty()) { return NULL; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return NULL; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return NULL; } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) { continue; } CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") continue; CPDF_Font* pFind = pDocument->LoadFont(pElement); if (!pFind) continue; CFX_ByteString csBaseFont; csBaseFont = pFind->GetBaseFont(); csBaseFont.Remove(' '); if (csBaseFont == csFontName) { csNameTag = csKey; return pFind; } } return NULL; }
CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, uint8_t charSet, CFX_ByteString& csNameTag) { if (!pFormDict) { return NULL; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return NULL; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return NULL; } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) { continue; } CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") continue; CPDF_Font* pFind = pDocument->LoadFont(pElement); if (!pFind) { continue; } CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); if (!pSubst) { continue; } if (pSubst->m_Charset == (int)charSet) { csNameTag = csKey; return pFind; } } return NULL; }
CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( CPDF_Dictionary* pDict, std::map<CPDF_Dictionary*, CPDF_StructElementImpl*>& map, int nLevel) { if (nLevel > nMaxRecursion) return nullptr; auto it = map.find(pDict); if (it != map.end()) return it->second; CPDF_StructElementImpl* pElement = new CPDF_StructElementImpl(this, nullptr, pDict); map[pDict] = pElement; CPDF_Dictionary* pParent = pDict->GetDictBy("P"); if (!pParent || pParent->GetStringBy("Type") == "StructTreeRoot") { if (!AddTopLevelNode(pDict, pElement)) { pElement->Release(); map.erase(pDict); } } else { CPDF_StructElementImpl* pParentElement = AddPageNode(pParent, map, nLevel + 1); FX_BOOL bSave = FALSE; for (CPDF_StructKid& kid : pParentElement->m_Kids) { if (kid.m_Type != CPDF_StructKid::Element) continue; if (kid.m_Element.m_pDict != pDict) continue; kid.m_Element.m_pElement = pElement->Retain(); bSave = TRUE; } if (!bSave) { pElement->Release(); map.erase(pDict); } } return pElement; }
CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode mode) { CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP"); if (!pAP) { return nullptr; } const FX_CHAR* ap_entry = "N"; if (mode == CPDF_Annot::Down) ap_entry = "D"; else if (mode == CPDF_Annot::Rollover) ap_entry = "R"; if (!pAP->KeyExist(ap_entry)) ap_entry = "N"; CPDF_Object* psub = pAP->GetDirectObjectBy(ap_entry); if (!psub) return nullptr; if (CPDF_Stream* pStream = psub->AsStream()) return pStream; if (CPDF_Dictionary* pDict = psub->AsDictionary()) { CFX_ByteString as = pAnnotDict->GetStringBy("AS"); if (as.IsEmpty()) { CFX_ByteString value = pAnnotDict->GetStringBy("V"); if (value.IsEmpty()) { CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent"); value = pParentDict ? pParentDict->GetStringBy("V") : CFX_ByteString(); } if (value.IsEmpty() || !pDict->KeyExist(value)) as = "Off"; else as = value; } return pDict->GetStreamBy(as); } return nullptr; }
CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, CFX_ByteString& sFontAlias, int32_t nCharset) { if (!pResDict) return nullptr; CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); if (!pFonts) return nullptr; CPDF_Document* pDocument = GetDocument(); CPDF_Font* pFind = nullptr; for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; CPDF_Object* pObj = it.second; if (!pObj) continue; CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); if (!pElement) continue; if (pElement->GetStringBy("Type") != "Font") continue; CPDF_Font* pFont = pDocument->LoadFont(pElement); if (!pFont) continue; const CFX_SubstFont* pSubst = pFont->GetSubstFont(); if (!pSubst) continue; if (pSubst->m_Charset == nCharset) { sFontAlias = csKey; pFind = pFont; } } return pFind; }
DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot) { if (!startPos || !linkAnnot) return FALSE; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage || !pPage->m_pFormDict) return FALSE; CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); if (!pAnnots) return FALSE; for (size_t i = *startPos; i < pAnnots->GetCount(); i++) { CPDF_Dictionary* pDict = ToDictionary(static_cast<CPDF_Object*>(pAnnots->GetDirectObjectAt(i))); if (!pDict) continue; if (pDict->GetStringBy("Subtype") == "Link") { *startPos = static_cast<int>(i + 1); *linkAnnot = static_cast<FPDF_LINK>(pDict); return TRUE; } } return FALSE; }
CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csNameTag) { CFX_ByteString csAlias = PDF_NameDecode(csNameTag); if (!pFormDict || csAlias.IsEmpty()) { return NULL; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { return NULL; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { return NULL; } CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias); if (!pElement) { return NULL; } if (pElement->GetStringBy("Type") == "Font") { return pDocument->LoadFont(pElement); } return NULL; }
void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CFX_Matrix* pUser2Device, const CPDF_RenderOptions* pOptions) { if (GetSubtype() == CPDF_Annot::Subtype::POPUP) return; uint32_t annot_flags = GetFlags(); if (annot_flags & ANNOTFLAG_HIDDEN) { return; } bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { return; } if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { return; } CPDF_Dictionary* pBS = m_pAnnotDict->GetDictBy("BS"); char style_char; FX_FLOAT width; CPDF_Array* pDashArray = nullptr; if (!pBS) { CPDF_Array* pBorderArray = m_pAnnotDict->GetArrayBy("Border"); style_char = 'S'; if (pBorderArray) { width = pBorderArray->GetNumberAt(2); if (pBorderArray->GetCount() == 4) { pDashArray = pBorderArray->GetArrayAt(3); if (!pDashArray) { return; } size_t nLen = pDashArray->GetCount(); size_t i = 0; for (; i < nLen; ++i) { CPDF_Object* pObj = pDashArray->GetDirectObjectAt(i); if (pObj && pObj->GetInteger()) { break; } } if (i == nLen) { return; } style_char = 'D'; } } else { width = 1; } } else { CFX_ByteString style = pBS->GetStringBy("S"); pDashArray = pBS->GetArrayBy("D"); style_char = style[1]; width = pBS->GetNumberBy("W"); } if (width <= 0) { return; } CPDF_Array* pColor = m_pAnnotDict->GetArrayBy("C"); uint32_t argb = 0xff000000; if (pColor) { int R = (int32_t)(pColor->GetNumberAt(0) * 255); int G = (int32_t)(pColor->GetNumberAt(1) * 255); int B = (int32_t)(pColor->GetNumberAt(2) * 255); argb = ArgbEncode(0xff, R, G, B); } CFX_GraphStateData graph_state; graph_state.m_LineWidth = width; if (style_char == 'D') { if (pDashArray) { size_t dash_count = pDashArray->GetCount(); if (dash_count % 2) { dash_count++; } graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count); graph_state.m_DashCount = dash_count; size_t i; for (i = 0; i < pDashArray->GetCount(); ++i) { graph_state.m_DashArray[i] = pDashArray->GetNumberAt(i); } if (i < dash_count) { graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1]; } } else { graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2); graph_state.m_DashCount = 2; graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f; } } CFX_FloatRect rect = GetRect(); CFX_PathData path; width /= 2; path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, rect.top - width); int fill_type = 0; if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { fill_type |= FXFILL_NOPATHSMOOTH; } pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); }
CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { if (!pFieldDict->KeyExist("T")) return nullptr; CPDF_Dictionary* pDict = pFieldDict; CFX_WideString csWName = FPDF_GetFullName(pFieldDict); if (csWName.IsEmpty()) return nullptr; CPDF_FormField* pField = nullptr; pField = m_pFieldTree->GetField(csWName); if (!pField) { CPDF_Dictionary* pParent = pFieldDict; if (!pFieldDict->KeyExist("T") && pFieldDict->GetStringBy("Subtype") == "Widget") { pParent = pFieldDict->GetDictBy("Parent"); if (!pParent) pParent = pFieldDict; } if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { if (pFieldDict->KeyExist("FT")) { CPDF_Object* pFTValue = pFieldDict->GetDirectObjectBy("FT"); if (pFTValue) pParent->SetAt("FT", pFTValue->Clone()); } if (pFieldDict->KeyExist("Ff")) { CPDF_Object* pFfValue = pFieldDict->GetDirectObjectBy("Ff"); if (pFfValue) pParent->SetAt("Ff", pFfValue->Clone()); } } pField = new CPDF_FormField(this, pParent); CPDF_Object* pTObj = pDict->GetObjectBy("T"); if (ToReference(pTObj)) { CPDF_Object* pClone = pTObj->CloneDirectObject(); if (pClone) pDict->SetAt("T", pClone); else pDict->SetAtName("T", ""); } m_pFieldTree->SetField(csWName, pField); } CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); if (!pKids) { if (pFieldDict->GetStringBy("Subtype") == "Widget") AddControl(pField, pFieldDict); } else { for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; if (pKid->GetStringBy("Subtype") != "Widget") continue; AddControl(pField, pKid); } } return pField; }
void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, std::vector<CFX_ByteString>* pCharNames, FX_BOOL bEmbedded, FX_BOOL bTrueType) { if (!pEncoding) { if (m_BaseFont == "Symbol") { iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL : PDFFONT_ENCODING_ADOBE_SYMBOL; } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) { iBaseEncoding = PDFFONT_ENCODING_WINANSI; } return; } if (pEncoding->IsName()) { if (iBaseEncoding == PDFFONT_ENCODING_ADOBE_SYMBOL || iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) { return; } if ((m_Flags & PDFFONT_SYMBOLIC) && m_BaseFont == "Symbol") { if (!bTrueType) { iBaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL; } return; } CFX_ByteString bsEncoding = pEncoding->GetString(); if (bsEncoding.Compare("MacExpertEncoding") == 0) { bsEncoding = "WinAnsiEncoding"; } GetPredefinedEncoding(bsEncoding, &iBaseEncoding); return; } CPDF_Dictionary* pDict = pEncoding->AsDictionary(); if (!pDict) return; if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) { CFX_ByteString bsEncoding = pDict->GetStringBy("BaseEncoding"); if (bsEncoding.Compare("MacExpertEncoding") == 0 && bTrueType) { bsEncoding = "WinAnsiEncoding"; } GetPredefinedEncoding(bsEncoding, &iBaseEncoding); } if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) iBaseEncoding = PDFFONT_ENCODING_STANDARD; CPDF_Array* pDiffs = pDict->GetArrayBy("Differences"); if (!pDiffs) return; pCharNames->resize(256); uint32_t cur_code = 0; for (uint32_t i = 0; i < pDiffs->GetCount(); i++) { CPDF_Object* pElement = pDiffs->GetDirectObjectAt(i); if (!pElement) continue; if (CPDF_Name* pName = pElement->AsName()) { if (cur_code < 256) (*pCharNames)[cur_code] = pName->GetString(); cur_code++; } else { cur_code = pElement->GetInteger(); } } }