static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, const CFX_ByteString& csName, int& nIndex, CPDF_Array** ppFind, int nLevel = 0) { if (nLevel > nMaxRecursion) { return NULL; } CPDF_Array* pLimits = pNode->GetArrayBy("Limits"); if (pLimits) { CFX_ByteString csLeft = pLimits->GetStringAt(0); CFX_ByteString csRight = pLimits->GetStringAt(1); if (csLeft.Compare(csRight) > 0) { CFX_ByteString csTmp = csRight; csRight = csLeft; csLeft = csTmp; } if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { return NULL; } } CPDF_Array* pNames = pNode->GetArrayBy("Names"); if (pNames) { FX_DWORD dwCount = pNames->GetCount() / 2; for (FX_DWORD i = 0; i < dwCount; i++) { CFX_ByteString csValue = pNames->GetStringAt(i * 2); int32_t iCompare = csValue.Compare(csName); if (iCompare <= 0) { if (ppFind) { *ppFind = pNames; } if (iCompare < 0) { continue; } } else { break; } nIndex += i; return pNames->GetElementValue(i * 2 + 1); } nIndex += dwCount; return NULL; } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) { return NULL; } for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) { continue; } CPDF_Object* pFound = SearchNameNode(pKid, csName, nIndex, ppFind, nLevel + 1); if (pFound) { return pFound; } } return NULL; }
void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype(); if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT); } else if (nAnnotSubtype == CPDF_Annot::Subtype::SCREEN) { const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); CFX_ByteString cbString; if (pAnnotDict->KeyExist("IT")) cbString = pAnnotDict->GetStringFor("IT"); if (cbString.Compare("Img") != 0) FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); } else if (nAnnotSubtype == CPDF_Annot::Subtype::MOVIE) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE); } else if (nAnnotSubtype == CPDF_Annot::Subtype::SOUND) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND); } else if (nAnnotSubtype == CPDF_Annot::Subtype::RICHMEDIA) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); } else if (nAnnotSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); } else if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) { const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); CFX_ByteString cbString; if (pAnnotDict->KeyExist("FT")) cbString = pAnnotDict->GetStringFor("FT"); if (cbString.Compare("Sig") == 0) FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG); } }
void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { CFX_ByteString cbSubType = pPDFAnnot->GetSubType(); if (cbSubType.Compare("3D") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT); } else if (cbSubType.Compare("Screen") == 0) { const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); CFX_ByteString cbString; if (pAnnotDict->KeyExist("IT")) cbString = pAnnotDict->GetString("IT"); if (cbString.Compare("Img") != 0) FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); } else if (cbSubType.Compare("Movie") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE); } else if (cbSubType.Compare("Sound") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND); } else if (cbSubType.Compare("RichMedia") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); } else if (cbSubType.Compare("FileAttachment") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); } else if (cbSubType.Compare("Widget") == 0) { const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); CFX_ByteString cbString; if (pAnnotDict->KeyExist("FT")) { cbString = pAnnotDict->GetString("FT"); } if (cbString.Compare("Sig") == 0) { FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG); } } }
FX_INT32 CPDF_PageLabel::GetPageByLabel(FX_BSTR bsLabel) const { if (m_pDocument == NULL) { return -1; } CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); if (pPDFRoot == NULL) { return -1; } int nPages = m_pDocument->GetPageCount(); CFX_ByteString bsLbl; CFX_ByteString bsOrig = bsLabel; for (int i = 0; i < nPages; i++) { bsLbl = PDF_EncodeText(GetLabel(i)); if (!bsLbl.Compare(bsOrig)) { return i; } } bsLbl = bsOrig; int nPage = FXSYS_atoi(bsLbl); if (nPage > 0 && nPage <= nPages) { return nPage; } return -1; }
void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code) { // Security if (err_code == FPDF_ERR_SECURITY) { FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY); return; } if (!pDoc) return; // Portfolios and Packages CPDF_Dictionary* pRootDict = pDoc->GetRoot(); if (pRootDict) { CFX_ByteString cbString; if (pRootDict->KeyExist("Collection")) { FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); return; } if (pRootDict->KeyExist("Names")) { CPDF_Dictionary* pNameDict = pRootDict->GetDict("Names"); if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT); return; } if (pNameDict && pNameDict->KeyExist("JavaScript")) { CPDF_Dictionary* pJSDict = pNameDict->GetDict("JavaScript"); CPDF_Array* pArray = pJSDict ? pJSDict->GetArray("Names") : NULL; if (pArray) { int nCount = pArray->GetCount(); for (int i = 0; i < nCount; i++) { CFX_ByteString cbStr = pArray->GetString(i); if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); return; } } } } } } // SharedForm CPDF_Metadata metaData(pDoc); const CXML_Element* pElement = metaData.GetRoot(); if (pElement) CheckSharedForm(pElement, "workflowType"); // XFA Forms CPDF_InterForm* pInterForm = new CPDF_InterForm(pDoc, FALSE); if (pInterForm->HasXFAForm()) { FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); } delete pInterForm; }
void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { // Security if (err_code == FPDF_ERR_SECURITY) { FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY); return; } if (!pDoc) return; // Portfolios and Packages CPDF_Dictionary* pRootDict = pDoc->GetRoot(); if (pRootDict) { CFX_ByteString cbString; if (pRootDict->KeyExist("Collection")) { FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); return; } if (pRootDict->KeyExist("Names")) { CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names"); if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT); return; } if (pNameDict && pNameDict->KeyExist("JavaScript")) { CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript"); CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayFor("Names") : nullptr; if (pArray) { for (size_t i = 0; i < pArray->GetCount(); i++) { CFX_ByteString cbStr = pArray->GetStringAt(i); if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); return; } } } } } } // SharedForm CPDF_Metadata metaData(pDoc); const CXML_Element* pElement = metaData.GetRoot(); if (pElement) CheckSharedForm(pElement, "workflowType"); #ifndef PDF_ENABLE_XFA // XFA Forms CPDF_InterForm interform(pDoc); if (interform.HasXFAForm()) FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); #endif // PDF_ENABLE_XFA }
void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, std::vector<CFX_ByteString>* pCharNames, bool bEmbedded, 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->GetStringFor("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->GetArrayFor("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(); } } }
FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, CFX_WordArray* nPageNum, CPDF_Document* pDestPDFDoc, int nIndex) { int curpage = nIndex; nonstd::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap); for (int i = 0; i < nPageNum->GetSize(); ++i) { CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage); CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1); if (!pSrcPageDict || !pCurPageDict) return FALSE; // Clone the page dictionary/////////// FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); while (SrcPos) { CFX_ByteString cbSrcKeyStr; CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr); if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) { if (pCurPageDict->KeyExist(cbSrcKeyStr)) pCurPageDict->RemoveAt(cbSrcKeyStr); pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone()); } } // inheritable item/////////////////////// CPDF_Object* pInheritable = nullptr; // 1 MediaBox //required if (!pCurPageDict->KeyExist("MediaBox")) { pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox"); if (!pInheritable) { // Search the "CropBox" from source page dictionary, // if not exists,we take the letter size. pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); if (pInheritable) { pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); } else { // Make the default size to be letter size (8.5'x11') CPDF_Array* pArray = new CPDF_Array; pArray->AddNumber(0); pArray->AddNumber(0); pArray->AddNumber(612); pArray->AddNumber(792); pCurPageDict->SetAt("MediaBox", pArray); } } else { pCurPageDict->SetAt("MediaBox", pInheritable->Clone()); } } // 2 Resources //required if (!pCurPageDict->KeyExist("Resources")) { pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources"); if (!pInheritable) return FALSE; pCurPageDict->SetAt("Resources", pInheritable->Clone()); } // 3 CropBox //Optional if (!pCurPageDict->KeyExist("CropBox")) { pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox"); if (pInheritable) pCurPageDict->SetAt("CropBox", pInheritable->Clone()); } // 4 Rotate //Optional if (!pCurPageDict->KeyExist("Rotate")) { pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate"); if (pInheritable) pCurPageDict->SetAt("Rotate", pInheritable->Clone()); } ///////////////////////////////////////////// // Update the reference FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); (*pObjNumberMap)[dwOldPageObj] = dwNewPageObj; UpdateReference(pCurPageDict, pDestPDFDoc, pObjNumberMap.get()); ++curpage; } return TRUE; }