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

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

Issue 1417893003: Add type cast definitions for CPDF_Array. (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 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 } 1147 }
1148 } 1148 }
1149 } 1149 }
1150 segindex += count; 1150 segindex += count;
1151 } 1151 }
1152 pStream->Release(); 1152 pStream->Release();
1153 return TRUE; 1153 return TRUE;
1154 } 1154 }
1155 CPDF_Array* CPDF_Parser::GetIDArray() { 1155 CPDF_Array* CPDF_Parser::GetIDArray() {
1156 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; 1156 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL;
1157 if (pID == NULL) { 1157 if (!pID)
1158 return NULL; 1158 return nullptr;
1159 } 1159
1160 if (pID->GetType() == PDFOBJ_REFERENCE) { 1160 if (pID->GetType() == PDFOBJ_REFERENCE) {
1161 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); 1161 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum());
1162 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); 1162 m_pTrailer->SetAt(FX_BSTRC("ID"), pID);
1163 } 1163 }
1164 if (pID == NULL || pID->GetType() != PDFOBJ_ARRAY) { 1164 return ToArray(pID);
1165 return NULL;
1166 }
1167 return (CPDF_Array*)pID;
1168 } 1165 }
1169 FX_DWORD CPDF_Parser::GetRootObjNum() { 1166 FX_DWORD CPDF_Parser::GetRootObjNum() {
1170 CPDF_Object* pRef = 1167 CPDF_Object* pRef =
1171 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL; 1168 m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL;
1172 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { 1169 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
1173 return 0; 1170 return 0;
1174 } 1171 }
1175 return ((CPDF_Reference*)pRef)->GetRefObjNum(); 1172 return ((CPDF_Reference*)pRef)->GetRefObjNum();
1176 } 1173 }
1177 FX_DWORD CPDF_Parser::GetInfoObjNum() { 1174 FX_DWORD CPDF_Parser::GetInfoObjNum() {
(...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 for (FX_DWORD i = 0; i < iPageObjs; ++i) { 3464 for (FX_DWORD i = 0; i < iPageObjs; ++i) {
3468 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); 3465 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i);
3469 FX_BOOL bExist = FALSE; 3466 FX_BOOL bExist = FALSE;
3470 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); 3467 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist);
3471 if (!pObj) { 3468 if (!pObj) {
3472 if (bExist) { 3469 if (bExist) {
3473 UnavailObjList.Add(dwPageObjNum); 3470 UnavailObjList.Add(dwPageObjNum);
3474 } 3471 }
3475 continue; 3472 continue;
3476 } 3473 }
3477 if (pObj->GetType() == PDFOBJ_ARRAY) { 3474 if (pObj->IsArray()) {
3478 CPDF_Array* pArray = pObj->GetArray(); 3475 CPDF_Array* pArray = pObj->GetArray();
3479 if (pArray) { 3476 if (pArray) {
3480 int32_t iSize = pArray->GetCount(); 3477 int32_t iSize = pArray->GetCount();
3481 CPDF_Object* pItem = NULL; 3478 CPDF_Object* pItem = NULL;
3482 for (int32_t j = 0; j < iSize; ++j) { 3479 for (int32_t j = 0; j < iSize; ++j) {
3483 pItem = pArray->GetElement(j); 3480 pItem = pArray->GetElement(j);
3484 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { 3481 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) {
3485 UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum()); 3482 UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum());
3486 } 3483 }
3487 } 3484 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3536 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; 3533 CPDF_Object* pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL;
3537 if (!pKids) { 3534 if (!pKids) {
3538 return TRUE; 3535 return TRUE;
3539 } 3536 }
3540 switch (pKids->GetType()) { 3537 switch (pKids->GetType()) {
3541 case PDFOBJ_REFERENCE: { 3538 case PDFOBJ_REFERENCE: {
3542 CPDF_Reference* pKid = (CPDF_Reference*)pKids; 3539 CPDF_Reference* pKid = (CPDF_Reference*)pKids;
3543 m_PageObjList.Add(pKid->GetRefObjNum()); 3540 m_PageObjList.Add(pKid->GetRefObjNum());
3544 } break; 3541 } break;
3545 case PDFOBJ_ARRAY: { 3542 case PDFOBJ_ARRAY: {
3546 CPDF_Array* pKidsArray = (CPDF_Array*)pKids; 3543 CPDF_Array* pKidsArray = pKids->AsArray();
3547 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 3544 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
3548 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); 3545 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
3549 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { 3546 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) {
3550 m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum()); 3547 m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum());
3551 } 3548 }
3552 } 3549 }
3553 } break; 3550 } break;
3554 default: 3551 default:
3555 m_docStatus = PDF_DATAAVAIL_ERROR; 3552 m_docStatus = PDF_DATAAVAIL_ERROR;
3556 return FALSE; 3553 return FALSE;
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
4109 m_docStatus = PDF_DATAAVAIL_ERROR; 4106 m_docStatus = PDF_DATAAVAIL_ERROR;
4110 return FALSE; 4107 return FALSE;
4111 } 4108 }
4112 if (!pPages) { 4109 if (!pPages) {
4113 if (m_docStatus == PDF_DATAAVAIL_ERROR) { 4110 if (m_docStatus == PDF_DATAAVAIL_ERROR) {
4114 m_docStatus = PDF_DATAAVAIL_ERROR; 4111 m_docStatus = PDF_DATAAVAIL_ERROR;
4115 return FALSE; 4112 return FALSE;
4116 } 4113 }
4117 return FALSE; 4114 return FALSE;
4118 } 4115 }
4119 if (pPages->GetType() != PDFOBJ_ARRAY) { 4116
4117 CPDF_Array* pArray = pPages->AsArray();
4118 if (!pArray) {
4120 pPages->Release(); 4119 pPages->Release();
4121 m_docStatus = PDF_DATAAVAIL_ERROR; 4120 m_docStatus = PDF_DATAAVAIL_ERROR;
4122 return FALSE; 4121 return FALSE;
4123 } 4122 }
4123
4124 pPageNode->m_type = PDF_PAGENODE_PAGES; 4124 pPageNode->m_type = PDF_PAGENODE_PAGES;
4125 CPDF_Array* pArray = (CPDF_Array*)pPages;
4126 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { 4125 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) {
4127 CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i); 4126 CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i);
4128 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { 4127 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
4129 continue; 4128 continue;
4130 } 4129 }
4131 CPDF_PageNode* pNode = new CPDF_PageNode(); 4130 CPDF_PageNode* pNode = new CPDF_PageNode();
4132 pPageNode->m_childNode.Add(pNode); 4131 pPageNode->m_childNode.Add(pNode);
4133 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); 4132 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
4134 } 4133 }
4135 pPages->Release(); 4134 pPages->Release();
4136 return TRUE; 4135 return TRUE;
4137 } 4136 }
4138 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, 4137 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
4139 CPDF_PageNode* pPageNode, 4138 CPDF_PageNode* pPageNode,
4140 IFX_DownloadHints* pHints) { 4139 IFX_DownloadHints* pHints) {
4141 FX_BOOL bExist = FALSE; 4140 FX_BOOL bExist = FALSE;
4142 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist); 4141 CPDF_Object* pPage = GetObject(dwPageNo, pHints, &bExist);
4143 if (!bExist) { 4142 if (!bExist) {
4144 m_docStatus = PDF_DATAAVAIL_ERROR; 4143 m_docStatus = PDF_DATAAVAIL_ERROR;
4145 return FALSE; 4144 return FALSE;
4146 } 4145 }
4147 if (!pPage) { 4146 if (!pPage) {
4148 if (m_docStatus == PDF_DATAAVAIL_ERROR) { 4147 if (m_docStatus == PDF_DATAAVAIL_ERROR) {
4149 m_docStatus = PDF_DATAAVAIL_ERROR; 4148 m_docStatus = PDF_DATAAVAIL_ERROR;
4150 return FALSE; 4149 return FALSE;
4151 } 4150 }
4152 return FALSE; 4151 return FALSE;
4153 } 4152 }
4154 if (pPage->GetType() == PDFOBJ_ARRAY) { 4153 if (pPage->IsArray()) {
4155 pPageNode->m_dwPageNo = dwPageNo; 4154 pPageNode->m_dwPageNo = dwPageNo;
4156 pPageNode->m_type = PDF_PAGENODE_ARRAY; 4155 pPageNode->m_type = PDF_PAGENODE_ARRAY;
4157 pPage->Release(); 4156 pPage->Release();
4158 return TRUE; 4157 return TRUE;
4159 } 4158 }
4160 if (!pPage->IsDictionary()) { 4159 if (!pPage->IsDictionary()) {
4161 pPage->Release(); 4160 pPage->Release();
4162 m_docStatus = PDF_DATAAVAIL_ERROR; 4161 m_docStatus = PDF_DATAAVAIL_ERROR;
4163 return FALSE; 4162 return FALSE;
4164 } 4163 }
4165 pPageNode->m_dwPageNo = dwPageNo; 4164 pPageNode->m_dwPageNo = dwPageNo;
4166 CPDF_Dictionary* pDict = pPage->GetDict(); 4165 CPDF_Dictionary* pDict = pPage->GetDict();
4167 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type")); 4166 CFX_ByteString type = pDict->GetString(FX_BSTRC("Type"));
4168 if (type == FX_BSTRC("Pages")) { 4167 if (type == FX_BSTRC("Pages")) {
4169 pPageNode->m_type = PDF_PAGENODE_PAGES; 4168 pPageNode->m_type = PDF_PAGENODE_PAGES;
4170 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids")); 4169 CPDF_Object* pKids = pDict->GetElement(FX_BSTRC("Kids"));
4171 if (!pKids) { 4170 if (!pKids) {
4172 m_docStatus = PDF_DATAAVAIL_PAGE; 4171 m_docStatus = PDF_DATAAVAIL_PAGE;
4173 return TRUE; 4172 return TRUE;
4174 } 4173 }
4175 switch (pKids->GetType()) { 4174 switch (pKids->GetType()) {
4176 case PDFOBJ_REFERENCE: { 4175 case PDFOBJ_REFERENCE: {
4177 CPDF_Reference* pKid = (CPDF_Reference*)pKids; 4176 CPDF_Reference* pKid = (CPDF_Reference*)pKids;
4178 CPDF_PageNode* pNode = new CPDF_PageNode(); 4177 CPDF_PageNode* pNode = new CPDF_PageNode();
4179 pPageNode->m_childNode.Add(pNode); 4178 pPageNode->m_childNode.Add(pNode);
4180 pNode->m_dwPageNo = pKid->GetRefObjNum(); 4179 pNode->m_dwPageNo = pKid->GetRefObjNum();
4181 } break; 4180 } break;
4182 case PDFOBJ_ARRAY: { 4181 case PDFOBJ_ARRAY: {
4183 CPDF_Array* pKidsArray = (CPDF_Array*)pKids; 4182 CPDF_Array* pKidsArray = pKids->AsArray();
4184 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { 4183 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
4185 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); 4184 CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
4186 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { 4185 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
4187 continue; 4186 continue;
4188 } 4187 }
4189 CPDF_PageNode* pNode = new CPDF_PageNode(); 4188 CPDF_PageNode* pNode = new CPDF_PageNode();
4190 pPageNode->m_childNode.Add(pNode); 4189 pPageNode->m_childNode.Add(pNode);
4191 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); 4190 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
4192 } 4191 }
4193 } break; 4192 } break;
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
4616 return FALSE; 4615 return FALSE;
4617 } 4616 }
4618 CPDF_PageNode::~CPDF_PageNode() { 4617 CPDF_PageNode::~CPDF_PageNode() {
4619 int32_t iSize = m_childNode.GetSize(); 4618 int32_t iSize = m_childNode.GetSize();
4620 for (int32_t i = 0; i < iSize; ++i) { 4619 for (int32_t i = 0; i < iSize; ++i) {
4621 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; 4620 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i];
4622 delete pNode; 4621 delete pNode;
4623 } 4622 }
4624 m_childNode.RemoveAll(); 4623 m_childNode.RemoveAll();
4625 } 4624 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698