void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { m_pPage = pPageDict; if (m_pTreeRoot == NULL) { return; } CPDF_Object* pKids = m_pTreeRoot->GetElementValue(FX_BSTRC("K")); if (pKids == NULL) { return; } FX_DWORD dwKids = 0; if (pKids->GetType() == PDFOBJ_DICTIONARY) { dwKids = 1; } else if (pKids->GetType() == PDFOBJ_ARRAY) { dwKids = ((CPDF_Array*)pKids)->GetCount(); } else { return; } FX_DWORD i; m_Kids.SetSize(dwKids); for (i = 0; i < dwKids; i ++) { m_Kids[i] = NULL; } CFX_MapPtrToPtr element_map; CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDict(FX_BSTRC("ParentTree")); if (pParentTree == NULL) { return; } CPDF_NumberTree parent_tree(pParentTree); int parents_id = pPageDict->GetInteger(FX_BSTRC("StructParents"), -1); if (parents_id >= 0) { CPDF_Object* pParents = parent_tree.LookupValue(parents_id); if (pParents == NULL || pParents->GetType() != PDFOBJ_ARRAY) { return; } CPDF_Array* pParentArray = (CPDF_Array*)pParents; for (i = 0; i < pParentArray->GetCount(); i ++) { CPDF_Dictionary* pParent = pParentArray->GetDict(i); if (pParent == NULL) { continue; } AddPageNode(pParent, element_map); } } }
void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { m_pPage = pPageDict; if (!m_pTreeRoot) return; CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectBy("K"); if (!pKids) return; uint32_t dwKids = 0; if (pKids->IsDictionary()) dwKids = 1; else if (CPDF_Array* pArray = pKids->AsArray()) dwKids = pArray->GetCount(); else return; m_Kids.clear(); m_Kids.resize(dwKids); CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictBy("ParentTree"); if (!pParentTree) return; CPDF_NumberTree parent_tree(pParentTree); int parents_id = pPageDict->GetIntegerBy("StructParents", -1); if (parents_id < 0) return; CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); if (!pParentArray) return; std::map<CPDF_Dictionary*, CPDF_StructElementImpl*> element_map; for (size_t i = 0; i < pParentArray->GetCount(); i++) { if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) AddPageNode(pParent, element_map); } }