CPDF_Dictionary* CPDF_Document::FindPDFPage(CPDF_Dictionary* pPages, int iPage, int nPagesToGo, int level) { CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); if (!pKidList) return nPagesToGo == 0 ? pPages : nullptr; if (level >= FX_MAX_PAGE_LEVEL) return nullptr; for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid) { nPagesToGo--; continue; } if (pKid == pPages) continue; if (!pKid->KeyExist("Kids")) { if (nPagesToGo == 0) return pKid; m_PageList.SetAt(iPage - nPagesToGo, pKid->GetObjNum()); nPagesToGo--; } else { int nPages = pKid->GetIntegerFor("Count"); if (nPagesToGo < nPages) return FindPDFPage(pKid, iPage, nPagesToGo, level + 1); nPagesToGo -= nPages; } } return nullptr; }
CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_Matrix& parentMatrix) : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); m_Pattern2Form = pDict->GetMatrixFor("Matrix"); m_bColored = pDict->GetIntegerFor("PaintType") == 1; m_Pattern2Form.Concat(parentMatrix); }
void CPDF_PageObjectHolder::LoadTransInfo() { if (!m_pFormDict) { return; } CPDF_Dictionary* pGroup = m_pFormDict->GetDictFor("Group"); if (!pGroup) { return; } if (pGroup->GetStringFor("S") != "Transparency") { return; } m_Transparency |= PDFTRANS_GROUP; if (pGroup->GetIntegerFor("I")) { m_Transparency |= PDFTRANS_ISOLATED; } if (pGroup->GetIntegerFor("K")) { m_Transparency |= PDFTRANS_KNOCKOUT; } }
int CPDF_FormField::GetMaxLen() const { if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) return pObj->GetInteger(); for (int i = 0; i < m_ControlList.GetSize(); i++) { CPDF_FormControl* pControl = m_ControlList.GetAt(i); if (!pControl) continue; CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; if (pWidgetDict->KeyExist("MaxLen")) return pWidgetDict->GetIntegerFor("MaxLen"); } return 0; }
void CPDF_Document::DeletePage(int iPage) { CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) return; int nPages = pPages->GetIntegerFor("Count"); if (iPage < 0 || iPage >= nPages) return; std::set<CPDF_Dictionary*> stack = {pPages}; if (InsertDeletePDFPage(this, pPages, iPage, nullptr, FALSE, &stack) < 0) return; m_PageList.RemoveAt(iPage); }
static FX_BOOL LoadCryptInfo(CPDF_Dictionary* pEncryptDict, const CFX_ByteString& name, int& cipher, int& keylen) { int Version = pEncryptDict->GetIntegerFor("V"); cipher = FXCIPHER_RC4; keylen = 0; if (Version >= 4) { CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDictFor("CF"); if (!pCryptFilters) { return FALSE; } if (name == "Identity") { cipher = FXCIPHER_NONE; } else { CPDF_Dictionary* pDefFilter = pCryptFilters->GetDictFor(name); if (!pDefFilter) { return FALSE; } int nKeyBits = 0; if (Version == 4) { nKeyBits = pDefFilter->GetIntegerFor("Length", 0); if (nKeyBits == 0) { nKeyBits = pEncryptDict->GetIntegerFor("Length", 128); } } else { nKeyBits = pEncryptDict->GetIntegerFor("Length", 256); } if (nKeyBits < 40) { nKeyBits *= 8; } keylen = nKeyBits / 8; CFX_ByteString cipher_name = pDefFilter->GetStringFor("CFM"); if (cipher_name == "AESV2" || cipher_name == "AESV3") { cipher = FXCIPHER_AES; } } } else { keylen = Version > 1 ? pEncryptDict->GetIntegerFor("Length", 40) / 8 : 5; } if (keylen > 32 || keylen < 0) { return FALSE; } return TRUE; }
bool CPDF_TilingPattern::Load() { if (m_pForm) return true; CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); if (!pDict) return false; m_bColored = pDict->GetIntegerFor("PaintType") == 1; m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("XStep")); m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("YStep")); CPDF_Stream* pStream = m_pPatternObj->AsStream(); if (!pStream) return false; m_pForm.reset(new CPDF_Form(m_pDocument, nullptr, pStream)); m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr); m_BBox = pDict->GetRectFor("BBox"); return true; }
int ParserAnnots(CPDF_Document* pSourceDoc, CPDF_Dictionary* pPageDic, CPDF_RectArray* pRectArray, CPDF_ObjectArray* pObjectArray, int nUsage) { if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL; GetContentsRect(pSourceDoc, pPageDic, pRectArray); CPDF_Array* pAnnots = pPageDic->GetArrayFor("Annots"); if (!pAnnots) return FLATTEN_NOTHINGTODO; uint32_t dwSize = pAnnots->GetCount(); for (int i = 0; i < (int)dwSize; i++) { CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i)); if (!pAnnotDic) continue; CFX_ByteString sSubtype = pAnnotDic->GetStringFor("Subtype"); if (sSubtype == "Popup") continue; int nAnnotFlag = pAnnotDic->GetIntegerFor("F"); if (nAnnotFlag & ANNOTFLAG_HIDDEN) continue; if (nUsage == FLAT_NORMALDISPLAY) { if (nAnnotFlag & ANNOTFLAG_INVISIBLE) continue; ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); } else { if (nAnnotFlag & ANNOTFLAG_PRINT) ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); } } return FLATTEN_SUCCESS; }
bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { bool bExist = false; std::unique_ptr<CPDF_Object> pPages = GetObject(m_PagesObjNum, pHints, &bExist); if (!bExist) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } if (!pPages) return false; CPDF_Dictionary* pPagesDict = pPages->GetDict(); if (!pPagesDict) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } if (!pPagesDict->KeyExist("Kids")) return true; return pPagesDict->GetIntegerFor("Count") > 0; }
bool CPDF_ShadingPattern::Load() { if (m_ShadingType != kInvalidShading) return true; CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : nullptr; if (!pShadingDict) return false; m_pFunctions.clear(); CPDF_Object* pFunc = pShadingDict->GetDirectObjectFor("Function"); if (pFunc) { if (CPDF_Array* pArray = pFunc->AsArray()) { m_pFunctions.resize(std::min<size_t>(pArray->GetCount(), 4)); for (size_t i = 0; i < m_pFunctions.size(); ++i) m_pFunctions[i] = CPDF_Function::Load(pArray->GetDirectObjectAt(i)); } else { m_pFunctions.push_back(CPDF_Function::Load(pFunc)); } } CPDF_Object* pCSObj = pShadingDict->GetDirectObjectFor("ColorSpace"); if (!pCSObj) return false; CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); m_pCS = pDocPageData->GetColorSpace(pCSObj, nullptr); if (m_pCS) m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); m_ShadingType = ToShadingType(pShadingDict->GetIntegerFor("ShadingType")); // We expect to have a stream if our shading type is a mesh. if (IsMeshShading() && !ToStream(m_pShadingObj)) return false; return true; }
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; }