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

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

Issue 361553002: Remove "this==NULL" and adjust corresponding callers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: change tab to spaces Created 6 years, 5 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 "../../../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 #include "../../../include/fpdfapi/fpdf_page.h" 9 #include "../../../include/fpdfapi/fpdf_page.h"
10 #include "../fpdf_page/pageint.h" 10 #include "../fpdf_page/pageint.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (m_pDocument && !bReParse) { 71 if (m_pDocument && !bReParse) {
72 delete m_pDocument; 72 delete m_pDocument;
73 m_pDocument = NULL; 73 m_pDocument = NULL;
74 } 74 }
75 if (m_pTrailer) { 75 if (m_pTrailer) {
76 m_pTrailer->Release(); 76 m_pTrailer->Release();
77 m_pTrailer = NULL; 77 m_pTrailer = NULL;
78 } 78 }
79 ReleaseEncryptHandler(); 79 ReleaseEncryptHandler();
80 SetEncryptDictionary(NULL); 80 SetEncryptDictionary(NULL);
81 if (m_bOwnFileRead && m_Syntax.m_pFileAccess != NULL) { 81 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) {
82 m_Syntax.m_pFileAccess->Release(); 82 m_Syntax.m_pFileAccess->Release();
83 m_Syntax.m_pFileAccess = NULL; 83 m_Syntax.m_pFileAccess = NULL;
84 } 84 }
85 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); 85 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
86 while (pos) { 86 while (pos) {
87 FX_LPVOID objnum; 87 FX_LPVOID objnum;
88 CPDF_StreamAcc* pStream; 88 CPDF_StreamAcc* pStream;
89 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); 89 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
90 delete pStream; 90 delete pStream;
91 } 91 }
92 m_ObjectStreamMap.RemoveAll(); 92 m_ObjectStreamMap.RemoveAll();
93 m_SortedOffset.RemoveAll(); 93 m_SortedOffset.RemoveAll();
94 m_CrossRef.RemoveAll(); 94 m_CrossRef.RemoveAll();
95 m_V5Type.RemoveAll(); 95 m_V5Type.RemoveAll();
96 m_ObjVersion.RemoveAll(); 96 m_ObjVersion.RemoveAll();
97 FX_INT32 iLen = m_Trailers.GetSize(); 97 FX_INT32 iLen = m_Trailers.GetSize();
98 CPDF_Dictionary* trailer;
98 for (FX_INT32 i = 0; i < iLen; ++i) { 99 for (FX_INT32 i = 0; i < iLen; ++i) {
99 m_Trailers.GetAt(i)->Release(); 100 if (trailer = m_Trailers.GetAt(i))
Nico 2014/06/28 01:01:07 Nit: If you want, you can write this as if (CPD
Bo Xu 2014/06/28 01:26:27 I was wondering if this will initialize |trailer|
101 trailer->Release();
100 } 102 }
101 m_Trailers.RemoveAll(); 103 m_Trailers.RemoveAll();
102 if (m_pLinearized) { 104 if (m_pLinearized) {
103 m_pLinearized->Release(); 105 m_pLinearized->Release();
104 m_pLinearized = NULL; 106 m_pLinearized = NULL;
105 } 107 }
106 } 108 }
107 static FX_INT32 GetHeaderOffset(IFX_FileRead* pFile) 109 static FX_INT32 GetHeaderOffset(IFX_FileRead* pFile)
108 { 110 {
109 FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025); 111 FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025);
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 } 1105 }
1104 } 1106 }
1105 } 1107 }
1106 segindex += count; 1108 segindex += count;
1107 } 1109 }
1108 pStream->Release(); 1110 pStream->Release();
1109 return TRUE; 1111 return TRUE;
1110 } 1112 }
1111 CPDF_Array* CPDF_Parser::GetIDArray() 1113 CPDF_Array* CPDF_Parser::GetIDArray()
1112 { 1114 {
1113 CPDF_Object* pID = m_pTrailer->GetElement(FX_BSTRC("ID")); 1115 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NUL L;
1114 if (pID == NULL) { 1116 if (pID == NULL) {
1115 return NULL; 1117 return NULL;
1116 } 1118 }
1117 if (pID->GetType() == PDFOBJ_REFERENCE) { 1119 if (pID->GetType() == PDFOBJ_REFERENCE) {
1118 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); 1120 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum());
1119 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); 1121 m_pTrailer->SetAt(FX_BSTRC("ID"), pID);
1120 } 1122 }
1121 if (pID == NULL || pID->GetType() != PDFOBJ_ARRAY) { 1123 if (pID == NULL || pID->GetType() != PDFOBJ_ARRAY) {
1122 return NULL; 1124 return NULL;
1123 } 1125 }
1124 return (CPDF_Array*)pID; 1126 return (CPDF_Array*)pID;
1125 } 1127 }
1126 FX_DWORD CPDF_Parser::GetRootObjNum() 1128 FX_DWORD CPDF_Parser::GetRootObjNum()
1127 { 1129 {
1128 CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Roo t")); 1130 CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement( FX_BSTRC("Root")) : NULL;
1129 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 1131 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
1130 return 0; 1132 return 0;
1131 } 1133 }
1132 return pRef->GetRefObjNum(); 1134 return pRef->GetRefObjNum();
1133 } 1135 }
1134 FX_DWORD CPDF_Parser::GetInfoObjNum() 1136 FX_DWORD CPDF_Parser::GetInfoObjNum()
1135 { 1137 {
1136 CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Inf o")); 1138 CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement( FX_BSTRC("Info")) : NULL;
1137 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 1139 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
1138 return 0; 1140 return 0;
1139 } 1141 }
1140 return pRef->GetRefObjNum(); 1142 return pRef->GetRefObjNum();
1141 } 1143 }
1142 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) 1144 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm)
1143 { 1145 {
1144 bForm = FALSE; 1146 bForm = FALSE;
1145 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 1147 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
1146 return TRUE; 1148 return TRUE;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 } 1486 }
1485 FX_DWORD gennum = FXSYS_atoi(word); 1487 FX_DWORD gennum = FXSYS_atoi(word);
1486 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { 1488 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) {
1487 m_Syntax.RestorePos(SavedPos); 1489 m_Syntax.RestorePos(SavedPos);
1488 return FALSE; 1490 return FALSE;
1489 } 1491 }
1490 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); 1492 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0);
1491 if (!m_pLinearized) { 1493 if (!m_pLinearized) {
1492 return FALSE; 1494 return FALSE;
1493 } 1495 }
1494 if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { 1496 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR C("Linearized"))) {
1495 m_Syntax.GetNextWord(bIsNumber); 1497 m_Syntax.GetNextWord(bIsNumber);
1496 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); 1498 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L"));
1497 if (!pLen) { 1499 if (!pLen) {
1498 m_pLinearized->Release(); 1500 m_pLinearized->Release();
1499 return FALSE; 1501 return FALSE;
1500 } 1502 }
1501 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { 1503 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) {
1502 return FALSE; 1504 return FALSE;
1503 } 1505 }
1504 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); 1506 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P"));
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 if (pContext) { 2145 if (pContext) {
2144 pContext->m_DictStart = SavedPos; 2146 pContext->m_DictStart = SavedPos;
2145 } 2147 }
2146 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); 2148 CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
2147 FX_INT32 nKeys = 0; 2149 FX_INT32 nKeys = 0;
2148 FX_FILESIZE dwSignValuePos = 0; 2150 FX_FILESIZE dwSignValuePos = 0;
2149 while (1) { 2151 while (1) {
2150 FX_BOOL bIsNumber; 2152 FX_BOOL bIsNumber;
2151 CFX_ByteString key = GetNextWord(bIsNumber); 2153 CFX_ByteString key = GetNextWord(bIsNumber);
2152 if (key.IsEmpty()) { 2154 if (key.IsEmpty()) {
2153 pDict->Release(); 2155 if (pDict)
2156 pDict->Release();
2154 return NULL; 2157 return NULL;
2155 } 2158 }
2156 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); 2159 FX_FILESIZE SavedPos = m_Pos - key.GetLength();
2157 if (key == FX_BSTRC(">>")) { 2160 if (key == FX_BSTRC(">>")) {
2158 dwDictSize = m_Pos - saveDictOffset; 2161 dwDictSize = m_Pos - saveDictOffset;
2159 break; 2162 break;
2160 } 2163 }
2161 if (key == FX_BSTRC("endobj")) { 2164 if (key == FX_BSTRC("endobj")) {
2162 dwDictSize = m_Pos - 6 - saveDictOffset; 2165 dwDictSize = m_Pos - 6 - saveDictOffset;
2163 m_Pos = SavedPos; 2166 m_Pos = SavedPos;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 } 2202 }
2200 } 2203 }
2201 FX_FILESIZE SavedPos = m_Pos; 2204 FX_FILESIZE SavedPos = m_Pos;
2202 FX_BOOL bIsNumber; 2205 FX_BOOL bIsNumber;
2203 CFX_ByteString nextword = GetNextWord(bIsNumber); 2206 CFX_ByteString nextword = GetNextWord(bIsNumber);
2204 if (nextword == FX_BSTRC("stream")) { 2207 if (nextword == FX_BSTRC("stream")) {
2205 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); 2208 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum);
2206 if (pStream) { 2209 if (pStream) {
2207 return pStream; 2210 return pStream;
2208 } 2211 }
2209 pDict->Release(); 2212 if (pDict)
2213 pDict->Release();
2210 return NULL; 2214 return NULL;
2211 } else { 2215 } else {
2212 m_Pos = SavedPos; 2216 m_Pos = SavedPos;
2213 return pDict; 2217 return pDict;
2214 } 2218 }
2215 } 2219 }
2216 if (word == FX_BSTRC(">>")) { 2220 if (word == FX_BSTRC(">>")) {
2217 m_Pos = SavedPos; 2221 m_Pos = SavedPos;
2218 return NULL; 2222 return NULL;
2219 } 2223 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 if (bTypeOnly) { 2304 if (bTypeOnly) {
2301 return (CPDF_Object*)PDFOBJ_ARRAY; 2305 return (CPDF_Object*)PDFOBJ_ARRAY;
2302 } 2306 }
2303 CPDF_Array* pArray = CPDF_Array::Create(); 2307 CPDF_Array* pArray = CPDF_Array::Create();
2304 while (1) { 2308 while (1) {
2305 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1); 2309 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1);
2306 if (pObj == NULL) { 2310 if (pObj == NULL) {
2307 if (m_WordBuffer[0] == ']') { 2311 if (m_WordBuffer[0] == ']') {
2308 return pArray; 2312 return pArray;
2309 } 2313 }
2310 pArray->Release(); 2314 if (pArray)
2315 pArray->Release();
2311 return NULL; 2316 return NULL;
2312 } 2317 }
2313 pArray->Add(pObj); 2318 pArray->Add(pObj);
2314 } 2319 }
2315 } 2320 }
2316 if (word[0] == '/') { 2321 if (word[0] == '/') {
2317 if (bTypeOnly) { 2322 if (bTypeOnly) {
2318 return (CPDF_Object*)PDFOBJ_NAME; 2323 return (CPDF_Object*)PDFOBJ_NAME;
2319 } 2324 }
2320 return CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1 , m_WordSize - 1))); 2325 return CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1 , m_WordSize - 1)));
2321 } 2326 }
2322 if (word == FX_BSTRC("<<")) { 2327 if (word == FX_BSTRC("<<")) {
2323 if (bTypeOnly) { 2328 if (bTypeOnly) {
2324 return (CPDF_Object*)PDFOBJ_DICTIONARY; 2329 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2325 } 2330 }
2326 if (pContext) { 2331 if (pContext) {
2327 pContext->m_DictStart = SavedPos; 2332 pContext->m_DictStart = SavedPos;
2328 } 2333 }
2329 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); 2334 CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
2330 while (1) { 2335 while (1) {
2331 FX_BOOL bIsNumber; 2336 FX_BOOL bIsNumber;
2332 FX_FILESIZE SavedPos = m_Pos; 2337 FX_FILESIZE SavedPos = m_Pos;
2333 CFX_ByteString key = GetNextWord(bIsNumber); 2338 CFX_ByteString key = GetNextWord(bIsNumber);
2334 if (key.IsEmpty()) { 2339 if (key.IsEmpty()) {
2335 pDict->Release(); 2340 if (pDict)
2341 pDict->Release();
2336 return NULL; 2342 return NULL;
2337 } 2343 }
2338 if (key == FX_BSTRC(">>")) { 2344 if (key == FX_BSTRC(">>")) {
2339 break; 2345 break;
2340 } 2346 }
2341 if (key == FX_BSTRC("endobj")) { 2347 if (key == FX_BSTRC("endobj")) {
2342 m_Pos = SavedPos; 2348 m_Pos = SavedPos;
2343 break; 2349 break;
2344 } 2350 }
2345 if (key[0] != '/') { 2351 if (key[0] != '/') {
2346 continue; 2352 continue;
2347 } 2353 }
2348 key = PDF_NameDecode(key); 2354 key = PDF_NameDecode(key);
2349 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1); 2355 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1);
2350 if (pObj == NULL) { 2356 if (pObj == NULL) {
2351 pDict->Release(); 2357 if (pDict)
2358 pDict->Release();
2352 FX_BYTE ch; 2359 FX_BYTE ch;
2353 while (1) { 2360 while (1) {
2354 if (!GetNextChar(ch)) { 2361 if (!GetNextChar(ch)) {
2355 break; 2362 break;
2356 } 2363 }
2357 if (ch == 0x0A || ch == 0x0D) { 2364 if (ch == 0x0A || ch == 0x0D) {
2358 break; 2365 break;
2359 } 2366 }
2360 } 2367 }
2361 return NULL; 2368 return NULL;
(...skipping 11 matching lines...) Expand all
2373 } 2380 }
2374 } 2381 }
2375 FX_FILESIZE SavedPos = m_Pos; 2382 FX_FILESIZE SavedPos = m_Pos;
2376 FX_BOOL bIsNumber; 2383 FX_BOOL bIsNumber;
2377 CFX_ByteString nextword = GetNextWord(bIsNumber); 2384 CFX_ByteString nextword = GetNextWord(bIsNumber);
2378 if (nextword == FX_BSTRC("stream")) { 2385 if (nextword == FX_BSTRC("stream")) {
2379 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); 2386 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum);
2380 if (pStream) { 2387 if (pStream) {
2381 return pStream; 2388 return pStream;
2382 } 2389 }
2383 pDict->Release(); 2390 if (pDict)
2391 pDict->Release();
2384 return NULL; 2392 return NULL;
2385 } else { 2393 } else {
2386 m_Pos = SavedPos; 2394 m_Pos = SavedPos;
2387 return pDict; 2395 return pDict;
2388 } 2396 }
2389 } 2397 }
2390 if (word == FX_BSTRC(">>")) { 2398 if (word == FX_BSTRC(">>")) {
2391 m_Pos = SavedPos; 2399 m_Pos = SavedPos;
2392 return NULL; 2400 return NULL;
2393 } 2401 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 CPDF_Array *pArray = pObj->GetArray(); 2836 CPDF_Array *pArray = pObj->GetArray();
2829 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) { 2837 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) {
2830 new_obj_array.Add(pArray->GetElement(k)); 2838 new_obj_array.Add(pArray->GetElement(k));
2831 } 2839 }
2832 } 2840 }
2833 break; 2841 break;
2834 case PDFOBJ_STREAM: 2842 case PDFOBJ_STREAM:
2835 pObj = pObj->GetDict(); 2843 pObj = pObj->GetDict();
2836 case PDFOBJ_DICTIONARY: { 2844 case PDFOBJ_DICTIONARY: {
2837 CPDF_Dictionary *pDict = pObj->GetDict(); 2845 CPDF_Dictionary *pDict = pObj->GetDict();
2838 if (pDict->GetString("Type") == "Page" && !bParsePage) { 2846 if (pDict && pDict->GetString("Type") == "Page" && !bParsePa ge) {
2839 continue; 2847 continue;
2840 } 2848 }
2841 FX_POSITION pos = pDict->GetStartPos(); 2849 FX_POSITION pos = pDict->GetStartPos();
2842 while (pos) { 2850 while (pos) {
2843 CPDF_Object *value; 2851 CPDF_Object *value;
2844 CFX_ByteString key; 2852 CFX_ByteString key;
2845 value = pDict->GetNextElement(pos, key); 2853 value = pDict->GetNextElement(pos, key);
2846 if (key != "Parent") { 2854 if (key != "Parent") {
2847 new_obj_array.Add(value); 2855 new_obj_array.Add(value);
2848 } 2856 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
3150 m_docStatus = PDF_DATAAVAIL_ACROFORM; 3158 m_docStatus = PDF_DATAAVAIL_ACROFORM;
3151 } else { 3159 } else {
3152 m_docStatus = PDF_DATAAVAIL_PAGETREE; 3160 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3153 } 3161 }
3154 } 3162 }
3155 return TRUE; 3163 return TRUE;
3156 } 3164 }
3157 FX_BOOL CPDF_DataAvail::PreparePageItem() 3165 FX_BOOL CPDF_DataAvail::PreparePageItem()
3158 { 3166 {
3159 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); 3167 CPDF_Dictionary *pRoot = m_pDocument->GetRoot();
3160 CPDF_Reference* pRef = (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) ; 3168 CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC(" Pages")) : NULL;
3161 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 3169 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
3162 m_docStatus = PDF_DATAAVAIL_ERROR; 3170 m_docStatus = PDF_DATAAVAIL_ERROR;
3163 return FALSE; 3171 return FALSE;
3164 } 3172 }
3165 m_PagesObjNum = pRef->GetRefObjNum(); 3173 m_PagesObjNum = pRef->GetRefObjNum();
3166 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser(); 3174 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser();
3167 m_docStatus = PDF_DATAAVAIL_PAGETREE; 3175 m_docStatus = PDF_DATAAVAIL_PAGETREE;
3168 return TRUE; 3176 return TRUE;
3169 } 3177 }
3170 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) 3178 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 return TRUE; 3271 return TRUE;
3264 } 3272 }
3265 return TRUE; 3273 return TRUE;
3266 } 3274 }
3267 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) 3275 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages)
3268 { 3276 {
3269 if (!pParser) { 3277 if (!pParser) {
3270 m_docStatus = PDF_DATAAVAIL_ERROR; 3278 m_docStatus = PDF_DATAAVAIL_ERROR;
3271 return FALSE; 3279 return FALSE;
3272 } 3280 }
3273 CPDF_Object *pKids = pPages->GetDict()->GetElement(FX_BSTRC("Kids")); 3281 CPDF_Dictionary* pDict = pPages->GetDict();
3282 CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL;
3274 if (!pKids) { 3283 if (!pKids) {
3275 return TRUE; 3284 return TRUE;
3276 } 3285 }
3277 switch (pKids->GetType()) { 3286 switch (pKids->GetType()) {
3278 case PDFOBJ_REFERENCE: { 3287 case PDFOBJ_REFERENCE: {
3279 CPDF_Reference *pKid = (CPDF_Reference *)pKids; 3288 CPDF_Reference *pKid = (CPDF_Reference *)pKids;
3280 m_PageObjList.Add(pKid->GetRefObjNum()); 3289 m_PageObjList.Add(pKid->GetRefObjNum());
3281 } 3290 }
3282 break; 3291 break;
3283 case PDFOBJ_ARRAY: { 3292 case PDFOBJ_ARRAY: {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 m_docStatus = PDF_DATAAVAIL_END; 3346 m_docStatus = PDF_DATAAVAIL_END;
3338 } 3347 }
3339 return TRUE; 3348 return TRUE;
3340 } 3349 }
3341 pHints->AddSegment(0, req_size); 3350 pHints->AddSegment(0, req_size);
3342 return FALSE; 3351 return FALSE;
3343 } 3352 }
3344 FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) 3353 FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints)
3345 { 3354 {
3346 FX_DWORD dwFirstPageEndOffset = 0; 3355 FX_DWORD dwFirstPageEndOffset = 0;
3347 CPDF_Object *pEndOffSet = m_pLinearized->GetDict()->GetElement(FX_BSTRC("E") ); 3356 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
3357 CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL;
3348 if (!pEndOffSet) { 3358 if (!pEndOffSet) {
3349 m_docStatus = PDF_DATAAVAIL_ERROR; 3359 m_docStatus = PDF_DATAAVAIL_ERROR;
3350 return FALSE; 3360 return FALSE;
3351 } 3361 }
3352 CPDF_Object *pXRefOffset = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T ")); 3362 CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL;
3353 if (!pXRefOffset) { 3363 if (!pXRefOffset) {
3354 m_docStatus = PDF_DATAAVAIL_ERROR; 3364 m_docStatus = PDF_DATAAVAIL_ERROR;
3355 return FALSE; 3365 return FALSE;
3356 } 3366 }
3357 CPDF_Object *pFileLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); 3367 CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL;
3358 if (!pFileLen) { 3368 if (!pFileLen) {
3359 m_docStatus = PDF_DATAAVAIL_ERROR; 3369 m_docStatus = PDF_DATAAVAIL_ERROR;
3360 return FALSE; 3370 return FALSE;
3361 } 3371 }
3362 FX_BOOL bNeedDownLoad = FALSE; 3372 FX_BOOL bNeedDownLoad = FALSE;
3363 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { 3373 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) {
3364 FX_DWORD dwEnd = pEndOffSet->GetInteger(); 3374 FX_DWORD dwEnd = pEndOffSet->GetInteger();
3365 dwEnd += 512; 3375 dwEnd += 512;
3366 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { 3376 if ((FX_FILESIZE)dwEnd > m_dwFileLen) {
3367 dwEnd = (FX_DWORD)m_dwFileLen; 3377 dwEnd = (FX_DWORD)m_dwFileLen;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
3466 } 3476 }
3467 FX_DWORD objnum = FXSYS_atoi(wordObjNum); 3477 FX_DWORD objnum = FXSYS_atoi(wordObjNum);
3468 if (m_pLinearized) { 3478 if (m_pLinearized) {
3469 m_pLinearized->Release(); 3479 m_pLinearized->Release();
3470 m_pLinearized = NULL; 3480 m_pLinearized = NULL;
3471 } 3481 }
3472 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj num); 3482 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj num);
3473 if (!m_pLinearized) { 3483 if (!m_pLinearized) {
3474 return FALSE; 3484 return FALSE;
3475 } 3485 }
3476 if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { 3486 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR C("Linearized"))) {
3477 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); 3487 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L"));
3478 if (!pLen) { 3488 if (!pLen) {
3479 return FALSE; 3489 return FALSE;
3480 } 3490 }
3481 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { 3491 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) {
3482 return FALSE; 3492 return FALSE;
3483 } 3493 }
3484 m_bLinearized = TRUE; 3494 m_bLinearized = TRUE;
3485 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); 3495 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P"));
3486 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { 3496 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); 3551 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber);
3542 if (!bNumber) { 3552 if (!bNumber) {
3543 return -1; 3553 return -1;
3544 } 3554 }
3545 FX_DWORD objNum = FXSYS_atoi(objnum); 3555 FX_DWORD objNum = FXSYS_atoi(objnum);
3546 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL ); 3556 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL );
3547 if (!pObj) { 3557 if (!pObj) {
3548 m_Pos += m_parser.m_Syntax.SavePos(); 3558 m_Pos += m_parser.m_Syntax.SavePos();
3549 return 0; 3559 return 0;
3550 } 3560 }
3551 CPDF_Object *pName = pObj->GetDict()->GetElement(FX_BSTRC("Type")); 3561 CPDF_Dictionary* pDict = pObj->GetDict();
3562 CPDF_Object *pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL;
3552 if (pName && pName->GetType() == PDFOBJ_NAME) { 3563 if (pName && pName->GetType() == PDFOBJ_NAME) {
3553 if (pName->GetString() == FX_BSTRC("XRef")) { 3564 if (pName->GetString() == FX_BSTRC("XRef")) {
3554 m_Pos += m_parser.m_Syntax.SavePos(); 3565 m_Pos += m_parser.m_Syntax.SavePos();
3555 xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev")); 3566 xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev"));
3556 pObj->Release(); 3567 pObj->Release();
3557 return 1; 3568 return 1;
3558 } else { 3569 } else {
3559 pObj->Release(); 3570 pObj->Release();
3560 return -1; 3571 return -1;
3561 } 3572 }
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3901 pPageNode->m_type = PDF_PAGENODE_ARRAY; 3912 pPageNode->m_type = PDF_PAGENODE_ARRAY;
3902 pPage->Release(); 3913 pPage->Release();
3903 return TRUE; 3914 return TRUE;
3904 } 3915 }
3905 if (pPage->GetType() != PDFOBJ_DICTIONARY) { 3916 if (pPage->GetType() != PDFOBJ_DICTIONARY) {
3906 pPage->Release(); 3917 pPage->Release();
3907 m_docStatus = PDF_DATAAVAIL_ERROR; 3918 m_docStatus = PDF_DATAAVAIL_ERROR;
3908 return FALSE; 3919 return FALSE;
3909 } 3920 }
3910 pPageNode->m_dwPageNo = dwPageNo; 3921 pPageNode->m_dwPageNo = dwPageNo;
3911 CFX_ByteString type = pPage->GetDict()->GetString(FX_BSTRC("Type")); 3922 CPDF_Dictionary* pDict = pPage->GetDict();
3923 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS tring();
3912 if (type == FX_BSTRC("Pages")) { 3924 if (type == FX_BSTRC("Pages")) {
3913 pPageNode->m_type = PDF_PAGENODE_PAGES; 3925 pPageNode->m_type = PDF_PAGENODE_PAGES;
3914 CPDF_Object *pKids = pPage->GetDict()->GetElement(FX_BSTRC("Kids")); 3926 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids"));
3915 if (!pKids) { 3927 if (!pKids) {
3916 m_docStatus = PDF_DATAAVAIL_PAGE; 3928 m_docStatus = PDF_DATAAVAIL_PAGE;
3917 return TRUE; 3929 return TRUE;
3918 } 3930 }
3919 switch (pKids->GetType()) { 3931 switch (pKids->GetType()) {
3920 case PDFOBJ_REFERENCE: { 3932 case PDFOBJ_REFERENCE: {
3921 CPDF_Reference *pKid = (CPDF_Reference *)pKids; 3933 CPDF_Reference *pKid = (CPDF_Reference *)pKids;
3922 CPDF_PageNode *pNode = FX_NEW CPDF_PageNode(); 3934 CPDF_PageNode *pNode = FX_NEW CPDF_PageNode();
3923 pPageNode->m_childNode.Add(pNode); 3935 pPageNode->m_childNode.Add(pNode);
3924 pNode->m_dwPageNo = pKid->GetRefObjNum(); 3936 pNode->m_dwPageNo = pKid->GetRefObjNum();
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 { 4381 {
4370 FX_INT32 iSize = m_childNode.GetSize(); 4382 FX_INT32 iSize = m_childNode.GetSize();
4371 for (FX_INT32 i = 0; i < iSize; ++i) { 4383 for (FX_INT32 i = 0; i < iSize; ++i) {
4372 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; 4384 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i];
4373 if (pNode) { 4385 if (pNode) {
4374 delete pNode; 4386 delete pNode;
4375 } 4387 }
4376 } 4388 }
4377 m_childNode.RemoveAll(); 4389 m_childNode.RemoveAll();
4378 } 4390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698