| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 | 9 |
| 10 CPDF_Document::CPDF_Document(CPDF_Parser* pParser) : CPDF_IndirectObjects(pParse
r) | 10 CPDF_Document::CPDF_Document(CPDF_Parser* pParser) : CPDF_IndirectObjects(pParse
r) |
| 11 { | 11 { |
| 12 ASSERT(pParser != NULL); | 12 ASSERT(pParser != NULL); |
| 13 m_pRootDict = NULL; | 13 m_pRootDict = NULL; |
| 14 m_pInfoDict = NULL; | 14 m_pInfoDict = NULL; |
| 15 m_bLinearized = FALSE; | 15 m_bLinearized = false; |
| 16 m_dwFirstPageNo = 0; | 16 m_dwFirstPageNo = 0; |
| 17 m_dwFirstPageObjNum = 0; | 17 m_dwFirstPageObjNum = 0; |
| 18 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); | 18 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); |
| 19 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this)
; | 19 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this)
; |
| 20 } | 20 } |
| 21 CPDF_DocPageData* CPDF_Document::GetValidatePageData() | 21 CPDF_DocPageData* CPDF_Document::GetValidatePageData() |
| 22 { | 22 { |
| 23 if (m_pDocPage) { | 23 if (m_pDocPage) { |
| 24 return m_pDocPage; | 24 return m_pDocPage; |
| 25 } | 25 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 51 } | 51 } |
| 52 CPDF_Array* pIDArray = m_pParser->GetIDArray(); | 52 CPDF_Array* pIDArray = m_pParser->GetIDArray(); |
| 53 if (pIDArray) { | 53 if (pIDArray) { |
| 54 m_ID1 = pIDArray->GetString(0); | 54 m_ID1 = pIDArray->GetString(0); |
| 55 m_ID2 = pIDArray->GetString(1); | 55 m_ID2 = pIDArray->GetString(1); |
| 56 } | 56 } |
| 57 m_PageList.SetSize(_GetPageCount()); | 57 m_PageList.SetSize(_GetPageCount()); |
| 58 } | 58 } |
| 59 void CPDF_Document::LoadAsynDoc(CPDF_Dictionary *pLinearized) | 59 void CPDF_Document::LoadAsynDoc(CPDF_Dictionary *pLinearized) |
| 60 { | 60 { |
| 61 m_bLinearized = TRUE; | 61 m_bLinearized = true; |
| 62 m_LastObjNum = m_pParser->GetLastObjNum(); | 62 m_LastObjNum = m_pParser->GetLastObjNum(); |
| 63 CPDF_Object* indirectObj = GetIndirectObject(m_pParser->GetRootObjNum()); | 63 CPDF_Object* indirectObj = GetIndirectObject(m_pParser->GetRootObjNum()); |
| 64 m_pRootDict = indirectObj ? indirectObj->GetDict() : NULL; | 64 m_pRootDict = indirectObj ? indirectObj->GetDict() : NULL; |
| 65 if (m_pRootDict == NULL) { | 65 if (m_pRootDict == NULL) { |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 indirectObj = GetIndirectObject(m_pParser->GetInfoObjNum()); | 68 indirectObj = GetIndirectObject(m_pParser->GetInfoObjNum()); |
| 69 m_pInfoDict = indirectObj ? indirectObj->GetDict() : NULL; | 69 m_pInfoDict = indirectObj ? indirectObj->GetDict() : NULL; |
| 70 CPDF_Array* pIDArray = m_pParser->GetIDArray(); | 70 CPDF_Array* pIDArray = m_pParser->GetIDArray(); |
| 71 if (pIDArray) { | 71 if (pIDArray) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 skip_count--; | 221 skip_count--; |
| 222 } | 222 } |
| 223 index ++; | 223 index ++; |
| 224 } | 224 } |
| 225 return -1; | 225 return -1; |
| 226 } | 226 } |
| 227 int CPDF_Document::GetPageIndex(FX_DWORD objnum) | 227 int CPDF_Document::GetPageIndex(FX_DWORD objnum) |
| 228 { | 228 { |
| 229 FX_DWORD nPages = m_PageList.GetSize(); | 229 FX_DWORD nPages = m_PageList.GetSize(); |
| 230 FX_DWORD skip_count = 0; | 230 FX_DWORD skip_count = 0; |
| 231 FX_BOOL bSkipped = FALSE; | 231 bool bSkipped = false; |
| 232 for (FX_DWORD i = 0; i < nPages; i ++) { | 232 for (FX_DWORD i = 0; i < nPages; i ++) { |
| 233 FX_DWORD objnum1 = m_PageList.GetAt(i); | 233 FX_DWORD objnum1 = m_PageList.GetAt(i); |
| 234 if (objnum1 == objnum) { | 234 if (objnum1 == objnum) { |
| 235 return i; | 235 return i; |
| 236 } | 236 } |
| 237 if (!bSkipped && objnum1 == 0) { | 237 if (!bSkipped && objnum1 == 0) { |
| 238 skip_count = i; | 238 skip_count = i; |
| 239 bSkipped = TRUE; | 239 bSkipped = true; |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 CPDF_Dictionary* pRoot = GetRoot(); | 242 CPDF_Dictionary* pRoot = GetRoot(); |
| 243 if (pRoot == NULL) { | 243 if (pRoot == NULL) { |
| 244 return -1; | 244 return -1; |
| 245 } | 245 } |
| 246 CPDF_Dictionary* pPages = pRoot->GetDict(FX_BSTRC("Pages")); | 246 CPDF_Dictionary* pPages = pRoot->GetDict(FX_BSTRC("Pages")); |
| 247 if (pPages == NULL) { | 247 if (pPages == NULL) { |
| 248 return -1; | 248 return -1; |
| 249 } | 249 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 CPDF_Dictionary* pPages = pRoot->GetDict(FX_BSTRC("Pages")); | 291 CPDF_Dictionary* pPages = pRoot->GetDict(FX_BSTRC("Pages")); |
| 292 if (pPages == NULL) { | 292 if (pPages == NULL) { |
| 293 return 0; | 293 return 0; |
| 294 } | 294 } |
| 295 if (!pPages->KeyExist(FX_BSTRC("Kids"))) { | 295 if (!pPages->KeyExist(FX_BSTRC("Kids"))) { |
| 296 return 1; | 296 return 1; |
| 297 } | 297 } |
| 298 return _CountPages(pPages, 0); | 298 return _CountPages(pPages, 0); |
| 299 } | 299 } |
| 300 FX_BOOL CPDF_Document::IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary*
pThisPageDict) | 300 bool CPDF_Document::IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pTh
isPageDict) |
| 301 { | 301 { |
| 302 for (int i = 0; i < m_PageList.GetSize(); i ++) { | 302 for (int i = 0; i < m_PageList.GetSize(); i ++) { |
| 303 CPDF_Dictionary* pPageDict = GetPage(i); | 303 CPDF_Dictionary* pPageDict = GetPage(i); |
| 304 if (pPageDict == pThisPageDict) { | 304 if (pPageDict == pThisPageDict) { |
| 305 continue; | 305 continue; |
| 306 } | 306 } |
| 307 CPDF_Object* pContents = pPageDict ? pPageDict->GetElement(FX_BSTRC("Con
tents")) : NULL; | 307 CPDF_Object* pContents = pPageDict ? pPageDict->GetElement(FX_BSTRC("Con
tents")) : NULL; |
| 308 if (pContents == NULL) { | 308 if (pContents == NULL) { |
| 309 continue; | 309 continue; |
| 310 } | 310 } |
| 311 if (pContents->GetDirectType() == PDFOBJ_ARRAY) { | 311 if (pContents->GetDirectType() == PDFOBJ_ARRAY) { |
| 312 CPDF_Array* pArray = (CPDF_Array*)pContents->GetDirect(); | 312 CPDF_Array* pArray = (CPDF_Array*)pContents->GetDirect(); |
| 313 for (FX_DWORD j = 0; j < pArray->GetCount(); j ++) { | 313 for (FX_DWORD j = 0; j < pArray->GetCount(); j ++) { |
| 314 CPDF_Object* pRef = pArray->GetElement(j); | 314 CPDF_Object* pRef = pArray->GetElement(j); |
| 315 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 315 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| 316 continue; | 316 continue; |
| 317 } | 317 } |
| 318 if (((CPDF_Reference*) pRef)->GetRefObjNum() == objnum) { | 318 if (((CPDF_Reference*) pRef)->GetRefObjNum() == objnum) { |
| 319 return TRUE; | 319 return true; |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 } else if (pContents->GetObjNum() == objnum) { | 322 } else if (pContents->GetObjNum() == objnum) { |
| 323 return TRUE; | 323 return true; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 return FALSE; | 326 return false; |
| 327 } | 327 } |
| 328 FX_DWORD CPDF_Document::GetUserPermissions(FX_BOOL bCheckRevision) const | 328 FX_DWORD CPDF_Document::GetUserPermissions(bool bCheckRevision) const |
| 329 { | 329 { |
| 330 if (m_pParser == NULL) { | 330 if (m_pParser == NULL) { |
| 331 return (FX_DWORD) - 1; | 331 return (FX_DWORD) - 1; |
| 332 } | 332 } |
| 333 return m_pParser->GetPermissions(bCheckRevision); | 333 return m_pParser->GetPermissions(bCheckRevision); |
| 334 } | 334 } |
| 335 FX_BOOL CPDF_Document::IsOwner() const | 335 bool CPDF_Document::IsOwner() const |
| 336 { | 336 { |
| 337 if (m_pParser == NULL) { | 337 if (m_pParser == NULL) { |
| 338 return TRUE; | 338 return true; |
| 339 } | 339 } |
| 340 return m_pParser->IsOwner(); | 340 return m_pParser->IsOwner(); |
| 341 } | 341 } |
| 342 FX_BOOL CPDF_Document::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const | 342 bool CPDF_Document::IsFormStream(FX_DWORD objnum, bool& bForm) const |
| 343 { | 343 { |
| 344 { | 344 { |
| 345 CPDF_Object* pObj; | 345 CPDF_Object* pObj; |
| 346 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, (void*&)pObj)) { | 346 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, (void*&)pObj)) { |
| 347 bForm = pObj->GetType() == PDFOBJ_STREAM && | 347 bForm = pObj->GetType() == PDFOBJ_STREAM && |
| 348 ((CPDF_Stream*)pObj)->GetDict()->GetString(FX_BSTRC("Subtype
")) == FX_BSTRC("Form"); | 348 ((CPDF_Stream*)pObj)->GetDict()->GetString(FX_BSTRC("Subtype
")) == FX_BSTRC("Form"); |
| 349 return TRUE; | 349 return true; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 if (m_pParser == NULL) { | 352 if (m_pParser == NULL) { |
| 353 bForm = FALSE; | 353 bForm = false; |
| 354 return TRUE; | 354 return true; |
| 355 } | 355 } |
| 356 return m_pParser->IsFormStream(objnum, bForm); | 356 return m_pParser->IsFormStream(objnum, bForm); |
| 357 } | 357 } |
| 358 void CPDF_Document::ClearPageData() | 358 void CPDF_Document::ClearPageData() |
| 359 { | 359 { |
| 360 if (m_pDocPage) { | 360 if (m_pDocPage) { |
| 361 CPDF_ModuleMgr::Get()->GetPageModule()->ClearDoc(this); | 361 CPDF_ModuleMgr::Get()->GetPageModule()->ClearDoc(this); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 void CPDF_Document::ClearRenderData() | 364 void CPDF_Document::ClearRenderData() |
| 365 { | 365 { |
| 366 if (m_pDocRender) { | 366 if (m_pDocRender) { |
| 367 CPDF_ModuleMgr::Get()->GetRenderModule()->ClearDocData(m_pDocRender); | 367 CPDF_ModuleMgr::Get()->GetRenderModule()->ClearDocData(m_pDocRender); |
| 368 } | 368 } |
| 369 } | 369 } |
| OLD | NEW |