From bf81c14cdb2b336a62f97119315f6bc43502e840 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 26 Oct 2015 16:54:39 -0400 Subject: Merge to XFA: Revert "Revert "Add type cast definitions for CPDF_Reference."" This reverts commit 7e155865c90cc1115cc7193b7646a341d8f9093e. Add type cast definitions for CPDF_Reference. This Cl adds ToReference, CPDF_Object::AsReference and CPDF_Object::IsReference and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1418923005 . (cherry picked from commit 6ee3484bcb413f4cce303e237fe15e2bdaf51ade) Review URL: https://codereview.chromium.org/1410073007 . --- core/src/fpdfdoc/doc_form.cpp | 7 +++---- core/src/fpdfdoc/doc_tagged.cpp | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) (limited to 'core/src/fpdfdoc') diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 8078608883..3192445d90 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -1086,13 +1086,12 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { } pField = new CPDF_FormField(this, pParent); CPDF_Object* pTObj = pDict->GetElement("T"); - if (pTObj && pTObj->GetType() == PDFOBJ_REFERENCE) { + if (ToReference(pTObj)) { CPDF_Object* pClone = pTObj->Clone(TRUE); - if (pClone) { + if (pClone) pDict->SetAt("T", pClone); - } else { + else pDict->SetAtName("T", ""); - } } m_pFieldTree->SetField(csWName, pField); } diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp index f74aa7f6f5..f1877c6573 100644 --- a/core/src/fpdfdoc/doc_tagged.cpp +++ b/core/src/fpdfdoc/doc_tagged.cpp @@ -173,10 +173,10 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, FX_DWORD i; FX_BOOL bSave = FALSE; for (i = 0; i < pTopKids->GetCount(); i++) { - CPDF_Object* pKidRef = pTopKids->GetElement(i); - if (!pKidRef || pKidRef->GetType() != PDFOBJ_REFERENCE) + CPDF_Reference* pKidRef = ToReference(pTopKids->GetElement(i)); + if (!pKidRef) continue; - if (((CPDF_Reference*)pKidRef)->GetRefObjNum() != pDict->GetObjNum()) + if (pKidRef->GetRefObjNum() != pDict->GetObjNum()) continue; if (m_Kids[i]) @@ -225,8 +225,8 @@ void CPDF_StructElementImpl::Release() { void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) { CPDF_Object* pObj = pDict->GetElement(FX_BSTRC("Pg")); FX_DWORD PageObjNum = 0; - if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) - PageObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum(); + if (CPDF_Reference* pRef = ToReference(pObj)) + PageObjNum = pRef->GetRefObjNum(); CPDF_Object* pKids = pDict->GetElementValue(FX_BSTRC("K")); if (!pKids) @@ -264,20 +264,18 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, if (!pKidDict) return; - CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg")); - if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) { - PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum(); - } + if (CPDF_Reference* pRef = ToReference(pKidDict->GetElement(FX_BSTRC("Pg")))) + PageObjNum = pRef->GetRefObjNum(); + CFX_ByteString type = pKidDict->GetString(FX_BSTRC("Type")); if (type == FX_BSTRC("MCR")) { if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { return; } pKid->m_Type = CPDF_StructKid::StreamContent; - CPDF_Object* pStreamObj = pKidDict->GetElement(FX_BSTRC("Stm")); - if (pStreamObj && pStreamObj->GetType() == PDFOBJ_REFERENCE) { - pKid->m_StreamContent.m_RefObjNum = - ((CPDF_Reference*)pStreamObj)->GetRefObjNum(); + if (CPDF_Reference* pRef = + ToReference(pKidDict->GetElement(FX_BSTRC("Stm")))) { + pKid->m_StreamContent.m_RefObjNum = pRef->GetRefObjNum(); } else { pKid->m_StreamContent.m_RefObjNum = 0; } @@ -288,9 +286,9 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, return; } pKid->m_Type = CPDF_StructKid::Object; - CPDF_Object* pObj = pKidDict->GetElement(FX_BSTRC("Obj")); - if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) { - pKid->m_Object.m_RefObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum(); + if (CPDF_Reference* pObj = + ToReference(pKidDict->GetElement(FX_BSTRC("Obj")))) { + pKid->m_Object.m_RefObjNum = pObj->GetRefObjNum(); } else { pKid->m_Object.m_RefObjNum = 0; } -- cgit v1.2.3