Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1420973002: Add type cast definitions for CPDF_Reference. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (RootObjNum == 0) { 252 if (RootObjNum == 0) {
253 return PDFPARSE_ERROR_FORMAT; 253 return PDFPARSE_ERROR_FORMAT;
254 } 254 }
255 dwRet = SetEncryptHandler(); 255 dwRet = SetEncryptHandler();
256 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 256 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
257 return dwRet; 257 return dwRet;
258 } 258 }
259 } 259 }
260 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 260 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
261 CPDF_Reference* pMetadata = 261 CPDF_Reference* pMetadata =
262 (CPDF_Reference*)m_pDocument->GetRoot()->GetElement( 262 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")));
263 FX_BSTRC("Metadata")); 263 if (pMetadata)
264 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) {
265 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 264 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
266 }
267 } 265 }
268 return PDFPARSE_ERROR_SUCCESS; 266 return PDFPARSE_ERROR_SUCCESS;
269 } 267 }
270 FX_DWORD CPDF_Parser::SetEncryptHandler() { 268 FX_DWORD CPDF_Parser::SetEncryptHandler() {
271 ReleaseEncryptHandler(); 269 ReleaseEncryptHandler();
272 SetEncryptDictionary(NULL); 270 SetEncryptDictionary(NULL);
273 if (m_pTrailer == NULL) { 271 if (m_pTrailer == NULL) {
274 return PDFPARSE_ERROR_FORMAT; 272 return PDFPARSE_ERROR_FORMAT;
275 } 273 }
276 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt")); 274 CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt"));
277 if (pEncryptObj) { 275 if (pEncryptObj) {
278 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { 276 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
279 SetEncryptDictionary(pEncryptDict); 277 SetEncryptDictionary(pEncryptDict);
280 } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { 278 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) {
281 pEncryptObj = m_pDocument->GetIndirectObject( 279 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum());
282 ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); 280 if (pEncryptObj)
283 if (pEncryptObj) {
284 SetEncryptDictionary(pEncryptObj->GetDict()); 281 SetEncryptDictionary(pEncryptObj->GetDict());
285 }
286 } 282 }
287 } 283 }
288 if (m_bForceUseSecurityHandler) { 284 if (m_bForceUseSecurityHandler) {
289 FX_DWORD err = PDFPARSE_ERROR_HANDLER; 285 FX_DWORD err = PDFPARSE_ERROR_HANDLER;
290 if (m_pSecurityHandler == NULL) { 286 if (m_pSecurityHandler == NULL) {
291 return PDFPARSE_ERROR_HANDLER; 287 return PDFPARSE_ERROR_HANDLER;
292 } 288 }
293 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { 289 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) {
294 return err; 290 return err;
295 } 291 }
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 if (pObj) { 844 if (pObj) {
849 if (!pObj->IsDictionary() && !pObj->AsStream()) { 845 if (!pObj->IsDictionary() && !pObj->AsStream()) {
850 pObj->Release(); 846 pObj->Release();
851 } else { 847 } else {
852 CPDF_Stream* pStream = pObj->AsStream(); 848 CPDF_Stream* pStream = pObj->AsStream();
853 if (CPDF_Dictionary* pTrailer = 849 if (CPDF_Dictionary* pTrailer =
854 pStream ? pStream->GetDict() : pObj->AsDictionary()) { 850 pStream ? pStream->GetDict() : pObj->AsDictionary()) {
855 if (m_pTrailer) { 851 if (m_pTrailer) {
856 CPDF_Object* pRoot = 852 CPDF_Object* pRoot =
857 pTrailer->GetElement(FX_BSTRC("Root")); 853 pTrailer->GetElement(FX_BSTRC("Root"));
858 if (pRoot == NULL || 854 CPDF_Reference* pRef = ToReference(pRoot);
859 (pRoot->GetType() == PDFOBJ_REFERENCE && 855 if (!pRoot ||
856 (pRef &&
860 (FX_DWORD)m_CrossRef.GetSize() > 857 (FX_DWORD)m_CrossRef.GetSize() >
861 ((CPDF_Reference*)pRoot)->GetRefObjNum() && 858 pRef->GetRefObjNum() &&
862 m_CrossRef.GetAt(((CPDF_Reference*)pRoot) 859 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) {
863 ->GetRefObjNum()) != 0)) {
864 FX_POSITION pos = pTrailer->GetStartPos(); 860 FX_POSITION pos = pTrailer->GetStartPos();
865 while (pos) { 861 while (pos) {
866 CFX_ByteString key; 862 CFX_ByteString key;
867 CPDF_Object* pObj = 863 CPDF_Object* pObj =
868 pTrailer->GetNextElement(pos, key); 864 pTrailer->GetNextElement(pos, key);
869 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); 865 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument);
870 } 866 }
871 pObj->Release(); 867 pObj->Release();
872 } else { 868 } else {
873 pObj->Release(); 869 pObj->Release();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 segindex += count; 1133 segindex += count;
1138 } 1134 }
1139 pStream->Release(); 1135 pStream->Release();
1140 return TRUE; 1136 return TRUE;
1141 } 1137 }
1142 CPDF_Array* CPDF_Parser::GetIDArray() { 1138 CPDF_Array* CPDF_Parser::GetIDArray() {
1143 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; 1139 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL;
1144 if (!pID) 1140 if (!pID)
1145 return nullptr; 1141 return nullptr;
1146 1142
1147 if (pID->GetType() == PDFOBJ_REFERENCE) { 1143 if (CPDF_Reference* pRef = pID->AsReference()) {
1148 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); 1144 pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum());
1149 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); 1145 m_pTrailer->SetAt(FX_BSTRC("ID"), pID);
1150 } 1146 }
1151 return ToArray(pID); 1147 return ToArray(pID);
1152 } 1148 }
1153 FX_DWORD CPDF_Parser::GetRootObjNum() { 1149 FX_DWORD CPDF_Parser::GetRootObjNum() {
1154 CPDF_Object* pRef = 1150 CPDF_Reference* pRef = ToReference(
1155 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL; 1151 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : nullptr);
1156 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 1152 return pRef ? pRef->GetRefObjNum() : 0;
1157 return 0;
1158 }
1159 return ((CPDF_Reference*)pRef)->GetRefObjNum();
1160 } 1153 }
1161 FX_DWORD CPDF_Parser::GetInfoObjNum() { 1154 FX_DWORD CPDF_Parser::GetInfoObjNum() {
1162 CPDF_Object* pRef = 1155 CPDF_Reference* pRef = ToReference(
1163 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL; 1156 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : nullptr);
1164 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 1157 return pRef ? pRef->GetRefObjNum() : 0;
1165 return 0;
1166 }
1167 return ((CPDF_Reference*)pRef)->GetRefObjNum();
1168 } 1158 }
1169 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { 1159 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) {
1170 bForm = FALSE; 1160 bForm = FALSE;
1171 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 1161 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
1172 return TRUE; 1162 return TRUE;
1173 } 1163 }
1174 if (m_V5Type[objnum] == 0) { 1164 if (m_V5Type[objnum] == 0) {
1175 return TRUE; 1165 return TRUE;
1176 } 1166 }
1177 if (m_V5Type[objnum] == 2) { 1167 if (m_V5Type[objnum] == 2) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 RootObjNum = GetRootObjNum(); 1620 RootObjNum = GetRootObjNum();
1631 if (RootObjNum == 0) { 1621 if (RootObjNum == 0) {
1632 return PDFPARSE_ERROR_FORMAT; 1622 return PDFPARSE_ERROR_FORMAT;
1633 } 1623 }
1634 dwRet = SetEncryptHandler(); 1624 dwRet = SetEncryptHandler();
1635 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1625 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1636 return dwRet; 1626 return dwRet;
1637 } 1627 }
1638 } 1628 }
1639 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { 1629 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
1640 CPDF_Object* pMetadata = 1630 if (CPDF_Reference* pMetadata = ToReference(
1641 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")); 1631 m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))))
1642 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { 1632 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
1643 m_Syntax.m_MetadataObjnum = ((CPDF_Reference*)pMetadata)->GetRefObjNum();
1644 }
1645 } 1633 }
1646 return PDFPARSE_ERROR_SUCCESS; 1634 return PDFPARSE_ERROR_SUCCESS;
1647 } 1635 }
1648 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { 1636 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
1649 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { 1637 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
1650 return FALSE; 1638 return FALSE;
1651 } 1639 }
1652 while (xrefpos) 1640 while (xrefpos)
1653 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { 1641 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) {
1654 return FALSE; 1642 return FALSE;
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 markers = 1; 2376 markers = 1;
2389 } 2377 }
2390 return markers; 2378 return markers;
2391 } 2379 }
2392 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, 2380 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict,
2393 PARSE_CONTEXT* pContext, 2381 PARSE_CONTEXT* pContext,
2394 FX_DWORD objnum, 2382 FX_DWORD objnum,
2395 FX_DWORD gennum) { 2383 FX_DWORD gennum) {
2396 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length")); 2384 CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length"));
2397 FX_FILESIZE len = -1; 2385 FX_FILESIZE len = -1;
2398 if (pLenObj && ((pLenObj->GetType() != PDFOBJ_REFERENCE) || 2386 CPDF_Reference* pLenObjRef = ToReference(pLenObj);
2399 ((((CPDF_Reference*)pLenObj)->GetObjList()) && 2387 if (pLenObj && ((!pLenObjRef || ((pLenObjRef->GetObjList()) &&
Lei Zhang 2015/10/22 21:26:51 There's some extra parenthesis in there? Consider
dsinclair 2015/10/26 13:55:45 Done.
2400 ((CPDF_Reference*)pLenObj)->GetRefObjNum() != objnum))) { 2388 pLenObjRef->GetRefObjNum() != objnum)))) {
2401 len = pLenObj->GetInteger(); 2389 len = pLenObj->GetInteger();
2402 } 2390 }
2403 // Locate the start of stream. 2391 // Locate the start of stream.
2404 ToNextLine(); 2392 ToNextLine();
2405 FX_FILESIZE streamStartPos = m_Pos; 2393 FX_FILESIZE streamStartPos = m_Pos;
2406 if (pContext) { 2394 if (pContext) {
2407 pContext->m_DataStart = streamStartPos; 2395 pContext->m_DataStart = streamStartPos;
2408 } 2396 }
2409 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1; 2397 const unsigned int ENDSTREAM_LEN = sizeof("endstream") - 1;
2410 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1; 2398 const unsigned int ENDOBJ_LEN = sizeof("endobj") - 1;
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 while (pos) { 3064 while (pos) {
3077 CPDF_Object* value; 3065 CPDF_Object* value;
3078 CFX_ByteString key; 3066 CFX_ByteString key;
3079 value = pDict->GetNextElement(pos, key); 3067 value = pDict->GetNextElement(pos, key);
3080 if (key != "Parent") { 3068 if (key != "Parent") {
3081 new_obj_array.Add(value); 3069 new_obj_array.Add(value);
3082 } 3070 }
3083 } 3071 }
3084 } break; 3072 } break;
3085 case PDFOBJ_REFERENCE: { 3073 case PDFOBJ_REFERENCE: {
3086 CPDF_Reference* pRef = (CPDF_Reference*)pObj; 3074 CPDF_Reference* pRef = pObj->AsReference();
3087 FX_DWORD dwNum = pRef->GetRefObjNum(); 3075 FX_DWORD dwNum = pRef->GetRefObjNum();
3088 FX_FILESIZE offset; 3076 FX_FILESIZE offset;
3089 FX_DWORD original_size = GetObjectSize(dwNum, offset); 3077 FX_DWORD original_size = GetObjectSize(dwNum, offset);
3090 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; 3078 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size;
3091 if (size.ValueOrDefault(0) == 0 || offset < 0 || 3079 if (size.ValueOrDefault(0) == 0 || offset < 0 ||
3092 offset >= m_dwFileLen) { 3080 offset >= m_dwFileLen) {
3093 break; 3081 break;
3094 } 3082 }
3095 3083
3096 size += offset; 3084 size += offset;
(...skipping 21 matching lines...) Expand all
3118 new_obj_array.Add(pReferred); 3106 new_obj_array.Add(pReferred);
3119 } 3107 }
3120 } 3108 }
3121 } break; 3109 } break;
3122 } 3110 }
3123 } 3111 }
3124 if (count > 0) { 3112 if (count > 0) {
3125 int32_t iSize = new_obj_array.GetSize(); 3113 int32_t iSize = new_obj_array.GetSize();
3126 for (i = 0; i < iSize; ++i) { 3114 for (i = 0; i < iSize; ++i) {
3127 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; 3115 CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i];
3128 int32_t type = pObj->GetType(); 3116 if (CPDF_Reference* pRef = pObj->AsReference()) {
3129 if (type == PDFOBJ_REFERENCE) {
3130 CPDF_Reference* pRef = (CPDF_Reference*)pObj;
3131 FX_DWORD dwNum = pRef->GetRefObjNum(); 3117 FX_DWORD dwNum = pRef->GetRefObjNum();
3132 if (!m_objnum_array.Find(dwNum)) { 3118 if (!m_objnum_array.Find(dwNum))
3133 ret_array.Add(pObj); 3119 ret_array.Add(pObj);
3134 }
3135 } else { 3120 } else {
3136 ret_array.Add(pObj); 3121 ret_array.Add(pObj);
3137 } 3122 }
3138 } 3123 }
3139 return FALSE; 3124 return FALSE;
3140 } 3125 }
3141 obj_array.RemoveAll(); 3126 obj_array.RemoveAll();
3142 obj_array.Append(new_obj_array); 3127 obj_array.Append(new_obj_array);
3143 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); 3128 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array);
3144 } 3129 }
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3392 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 3377 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
3393 return TRUE; 3378 return TRUE;
3394 } 3379 }
3395 return FALSE; 3380 return FALSE;
3396 } 3381 }
3397 CPDF_Dictionary* pDict = m_pRoot->GetDict(); 3382 CPDF_Dictionary* pDict = m_pRoot->GetDict();
3398 if (!pDict) { 3383 if (!pDict) {
3399 m_docStatus = PDF_DATAAVAIL_ERROR; 3384 m_docStatus = PDF_DATAAVAIL_ERROR;
3400 return FALSE; 3385 return FALSE;
3401 } 3386 }
3402 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages")); 3387 CPDF_Reference* pRef = ToReference(pDict->GetElement(FX_BSTRC("Pages")));
3403 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 3388 if (!pRef) {
3404 m_docStatus = PDF_DATAAVAIL_ERROR; 3389 m_docStatus = PDF_DATAAVAIL_ERROR;
3405 return FALSE; 3390 return FALSE;
3406 } 3391 }
3392
3407 m_PagesObjNum = pRef->GetRefObjNum(); 3393 m_PagesObjNum = pRef->GetRefObjNum();
3408 CPDF_Reference* pAcroFormRef = 3394 CPDF_Reference* pAcroFormRef =
3409 (CPDF_Reference*)m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm")); 3395 ToReference(m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm")));
3410 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { 3396 if (pAcroFormRef) {
3411 m_bHaveAcroForm = TRUE; 3397 m_bHaveAcroForm = TRUE;
3412 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); 3398 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum();
3413 } 3399 }
3414 if (m_dwInfoObjNum) { 3400
3401 if (m_dwInfoObjNum)
Lei Zhang 2015/10/22 21:26:51 braces
dsinclair 2015/10/26 13:55:45 Done.
3415 m_docStatus = PDF_DATAAVAIL_INFO; 3402 m_docStatus = PDF_DATAAVAIL_INFO;
3416 } else { 3403 else
3417 if (m_bHaveAcroForm) { 3404 m_docStatus =
3418 m_docStatus = PDF_DATAAVAIL_ACROFORM; 3405 m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE;
3419 } else {
3420 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3421 }
3422 }
3423 return TRUE; 3406 return TRUE;
3424 } 3407 }
3425 FX_BOOL CPDF_DataAvail::PreparePageItem() { 3408 FX_BOOL CPDF_DataAvail::PreparePageItem() {
3426 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 3409 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
3427 CPDF_Reference* pRef = 3410 CPDF_Reference* pRef =
3428 pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL; 3411 ToReference(pRoot ? pRoot->GetElement(FX_BSTRC("Pages")) : nullptr);
3429 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 3412 if (!pRef) {
3430 m_docStatus = PDF_DATAAVAIL_ERROR; 3413 m_docStatus = PDF_DATAAVAIL_ERROR;
3431 return FALSE; 3414 return FALSE;
3432 } 3415 }
3416
3433 m_PagesObjNum = pRef->GetRefObjNum(); 3417 m_PagesObjNum = pRef->GetRefObjNum();
3434 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); 3418 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser();
3435 m_docStatus = PDF_DATAAVAIL_PAGETREE; 3419 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3436 return TRUE; 3420 return TRUE;
3437 } 3421 }
3438 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { 3422 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) {
3439 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) 3423 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end())
3440 return FALSE; 3424 return FALSE;
3441 3425
3442 m_pageMapCheckState.insert(iPage); 3426 m_pageMapCheckState.insert(iPage);
(...skipping 12 matching lines...) Expand all
3455 if (!pObj) { 3439 if (!pObj) {
3456 if (bExist) { 3440 if (bExist) {
3457 UnavailObjList.Add(dwPageObjNum); 3441 UnavailObjList.Add(dwPageObjNum);
3458 } 3442 }
3459 continue; 3443 continue;
3460 } 3444 }
3461 if (pObj->IsArray()) { 3445 if (pObj->IsArray()) {
3462 CPDF_Array* pArray = pObj->GetArray(); 3446 CPDF_Array* pArray = pObj->GetArray();
3463 if (pArray) { 3447 if (pArray) {
3464 int32_t iSize = pArray->GetCount(); 3448 int32_t iSize = pArray->GetCount();
3465 CPDF_Object* pItem = NULL;
3466 for (int32_t j = 0; j < iSize; ++j) { 3449 for (int32_t j = 0; j < iSize; ++j) {
3467 pItem = pArray->GetElement(j); 3450 if (CPDF_Reference* pRef = ToReference(pArray->GetElement(j)))
3468 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { 3451 UnavailObjList.Add(pRef->GetRefObjNum());
3469 UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum());
3470 }
3471 } 3452 }
3472 } 3453 }
3473 } 3454 }
3474 if (!pObj->IsDictionary()) { 3455 if (!pObj->IsDictionary()) {
3475 pObj->Release(); 3456 pObj->Release();
3476 continue; 3457 continue;
3477 } 3458 }
3478 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); 3459 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type"));
3479 if (type == FX_BSTRC("Pages")) { 3460 if (type == FX_BSTRC("Pages")) {
3480 m_PagesArray.Add(pObj); 3461 m_PagesArray.Add(pObj);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3516 m_docStatus = PDF_DATAAVAIL_ERROR; 3497 m_docStatus = PDF_DATAAVAIL_ERROR;
3517 return FALSE; 3498 return FALSE;
3518 } 3499 }
3519 CPDF_Dictionary* pDict = pPages->GetDict(); 3500 CPDF_Dictionary* pDict = pPages->GetDict();
3520 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; 3501 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL;
3521 if (!pKids) { 3502 if (!pKids) {
3522 return TRUE; 3503 return TRUE;
3523 } 3504 }
3524 switch (pKids->GetType()) { 3505 switch (pKids->GetType()) {
3525 case PDFOBJ_REFERENCE: { 3506 case PDFOBJ_REFERENCE: {
3526 CPDF_Reference* pKid = (CPDF_Reference*)pKids; 3507 CPDF_Reference* pKid = pKids->AsReference();
Lei Zhang 2015/10/22 21:26:51 fold into next line?
dsinclair 2015/10/26 13:55:45 Done.
3527 m_PageObjList.Add(pKid->GetRefObjNum()); 3508 m_PageObjList.Add(pKid->GetRefObjNum());
3528 } break; 3509 } break;
3529 case PDFOBJ_ARRAY: { 3510 case PDFOBJ_ARRAY: {
3530 CPDF_Array* pKidsArray = pKids->AsArray(); 3511 CPDF_Array* pKidsArray = pKids->AsArray();
3531 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 3512 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
3532 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); 3513 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i)))
3533 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { 3514 m_PageObjList.Add(pRef->GetRefObjNum());
3534 m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum());
3535 }
3536 } 3515 }
3537 } break; 3516 } break;
3538 default: 3517 default:
3539 m_docStatus = PDF_DATAAVAIL_ERROR; 3518 m_docStatus = PDF_DATAAVAIL_ERROR;
3540 return FALSE; 3519 return FALSE;
3541 } 3520 }
3542 return TRUE; 3521 return TRUE;
3543 } 3522 }
3544 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) { 3523 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) {
3545 FX_BOOL bExist = FALSE; 3524 FX_BOOL bExist = FALSE;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
4024 if (!pTrailer) { 4003 if (!pTrailer) {
4025 m_Pos += m_syntaxParser.SavePos(); 4004 m_Pos += m_syntaxParser.SavePos();
4026 pHints->AddSegment(m_Pos, iTrailerSize); 4005 pHints->AddSegment(m_Pos, iTrailerSize);
4027 return FALSE; 4006 return FALSE;
4028 } 4007 }
4029 if (!pTrailer->IsDictionary()) 4008 if (!pTrailer->IsDictionary())
4030 return FALSE; 4009 return FALSE;
4031 4010
4032 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); 4011 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict();
4033 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); 4012 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt");
4034 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { 4013 if (ToReference(pEncrypt)) {
4035 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 4014 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
4036 return TRUE; 4015 return TRUE;
4037 } 4016 }
4038 4017
4039 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev")); 4018 FX_DWORD xrefpos = GetDirectInteger(pTrailerDict, FX_BSTRC("Prev"));
4040 if (xrefpos) { 4019 if (xrefpos) {
4041 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm")); 4020 m_dwPrevXRefOffset = GetDirectInteger(pTrailerDict, FX_BSTRC("XRefStm"));
4042 if (m_dwPrevXRefOffset) { 4021 if (m_dwPrevXRefOffset) {
4043 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 4022 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
4044 } else { 4023 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 4082
4104 CPDF_Array* pArray = pPages->AsArray(); 4083 CPDF_Array* pArray = pPages->AsArray();
4105 if (!pArray) { 4084 if (!pArray) {
4106 pPages->Release(); 4085 pPages->Release();
4107 m_docStatus = PDF_DATAAVAIL_ERROR; 4086 m_docStatus = PDF_DATAAVAIL_ERROR;
4108 return FALSE; 4087 return FALSE;
4109 } 4088 }
4110 4089
4111 pPageNode->m_type = PDF_PAGENODE_PAGES; 4090 pPageNode->m_type = PDF_PAGENODE_PAGES;
4112 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { 4091 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) {
4113 CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i); 4092 CPDF_Reference* pKid = ToReference(pArray->GetElement(i));
4114 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { 4093 if (!pKid)
4115 continue; 4094 continue;
4116 } 4095
4117 CPDF_PageNode* pNode = new CPDF_PageNode(); 4096 CPDF_PageNode* pNode = new CPDF_PageNode();
4118 pPageNode->m_childNode.Add(pNode); 4097 pPageNode->m_childNode.Add(pNode);
4119 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); 4098 pNode->m_dwPageNo = pKid->GetRefObjNum();
4120 } 4099 }
4121 pPages->Release(); 4100 pPages->Release();
4122 return TRUE; 4101 return TRUE;
4123 } 4102 }
4124 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, 4103 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
4125 CPDF_PageNode* pPageNode, 4104 CPDF_PageNode* pPageNode,
4126 IFX_DownloadHints* pHints) { 4105 IFX_DownloadHints* pHints) {
4127 FX_BOOL bExist = FALSE; 4106 FX_BOOL bExist = FALSE;
4128 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); 4107 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist);
4129 if (!bExist) { 4108 if (!bExist) {
(...skipping 23 matching lines...) Expand all
4153 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type")); 4132 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type"));
4154 if (type == FX_BSTRC("Pages")) { 4133 if (type == FX_BSTRC("Pages")) {
4155 pPageNode->m_type = PDF_PAGENODE_PAGES; 4134 pPageNode->m_type = PDF_PAGENODE_PAGES;
4156 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids")); 4135 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids"));
4157 if (!pKids) { 4136 if (!pKids) {
4158 m_docStatus = PDF_DATAAVAIL_PAGE; 4137 m_docStatus = PDF_DATAAVAIL_PAGE;
4159 return TRUE; 4138 return TRUE;
4160 } 4139 }
4161 switch (pKids->GetType()) { 4140 switch (pKids->GetType()) {
4162 case PDFOBJ_REFERENCE: { 4141 case PDFOBJ_REFERENCE: {
4163 CPDF_Reference* pKid = (CPDF_Reference*)pKids; 4142 CPDF_Reference* pKid = pKids->AsReference();
4164 CPDF_PageNode* pNode = new CPDF_PageNode(); 4143 CPDF_PageNode* pNode = new CPDF_PageNode();
4165 pPageNode->m_childNode.Add(pNode); 4144 pPageNode->m_childNode.Add(pNode);
4166 pNode->m_dwPageNo = pKid->GetRefObjNum(); 4145 pNode->m_dwPageNo = pKid->GetRefObjNum();
4167 } break; 4146 } break;
4168 case PDFOBJ_ARRAY: { 4147 case PDFOBJ_ARRAY: {
4169 CPDF_Array* pKidsArray = pKids->AsArray(); 4148 CPDF_Array* pKidsArray = pKids->AsArray();
4170 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 4149 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
4171 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); 4150 CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i));
4172 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { 4151 if (!pKid)
4173 continue; 4152 continue;
4174 } 4153
4175 CPDF_PageNode* pNode = new CPDF_PageNode(); 4154 CPDF_PageNode* pNode = new CPDF_PageNode();
4176 pPageNode->m_childNode.Add(pNode); 4155 pPageNode->m_childNode.Add(pNode);
4177 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); 4156 pNode->m_dwPageNo = pKid->GetRefObjNum();
4178 } 4157 }
4179 } break; 4158 } break;
4180 default: 4159 default:
4181 break; 4160 break;
4182 } 4161 }
4183 } else if (type == FX_BSTRC("Page")) { 4162 } else if (type == FX_BSTRC("Page")) {
4184 pPageNode->m_type = PDF_PAGENODE_PAGE; 4163 pPageNode->m_type = PDF_PAGENODE_PAGE;
4185 } else { 4164 } else {
4186 pPage->Release(); 4165 pPage->Release();
4187 m_docStatus = PDF_DATAAVAIL_ERROR; 4166 m_docStatus = PDF_DATAAVAIL_ERROR;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4602 return FALSE; 4581 return FALSE;
4603 } 4582 }
4604 CPDF_PageNode::~CPDF_PageNode() { 4583 CPDF_PageNode::~CPDF_PageNode() {
4605 int32_t iSize = m_childNode.GetSize(); 4584 int32_t iSize = m_childNode.GetSize();
4606 for (int32_t i = 0; i < iSize; ++i) { 4585 for (int32_t i = 0; i < iSize; ++i) {
4607 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; 4586 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i];
4608 delete pNode; 4587 delete pNode;
4609 } 4588 }
4610 m_childNode.RemoveAll(); 4589 m_childNode.RemoveAll();
4611 } 4590 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698