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

Side by Side Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp

Issue 1539573003: Convert CPDF_Parser::m_CrossRef to a std::map. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: add comments, separate two constants, rebase Created 4 years, 12 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
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "editint.h" 7 #include "editint.h"
8 8
9 #include "core/include/fxcrt/fx_ext.h" 9 #include "core/include/fxcrt/fx_ext.h"
10 #include "core/include/fpdfapi/fpdf_serial.h" 10 #include "core/include/fpdfapi/fpdf_serial.h"
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 m_Offset += size; 1312 m_Offset += size;
1313 if (AppendObjectNumberToXRef(objnum) < 0) { 1313 if (AppendObjectNumberToXRef(objnum) < 0) {
1314 return -1; 1314 return -1;
1315 } 1315 }
1316 } 1316 }
1317 FX_Free(pBuffer); 1317 FX_Free(pBuffer);
1318 } 1318 }
1319 return 1; 1319 return 1;
1320 } 1320 }
1321 int32_t CPDF_Creator::WriteOldObjs(IFX_Pause* pPause) { 1321 int32_t CPDF_Creator::WriteOldObjs(IFX_Pause* pPause) {
1322 FX_DWORD nOldSize = m_pParser->m_CrossRef.GetSize(); 1322 FX_DWORD nLastObjNum = m_pParser->GetLastObjNum();
1323 if (!m_pParser->IsValidObjectNumber(nLastObjNum))
1324 return 0;
1325
1323 FX_DWORD objnum = (FX_DWORD)(uintptr_t)m_Pos; 1326 FX_DWORD objnum = (FX_DWORD)(uintptr_t)m_Pos;
1324 for (; objnum < nOldSize; objnum++) { 1327 for (; objnum <= nLastObjNum; ++objnum) {
1325 int32_t iRet = WriteOldIndirectObject(objnum); 1328 int32_t iRet = WriteOldIndirectObject(objnum);
1326 if (!iRet) { 1329 if (iRet < 0)
1330 return iRet;
1331
1332 if (!iRet)
1327 continue; 1333 continue;
1328 } 1334
1329 if (iRet < 0) {
1330 return iRet;
1331 }
1332 m_ObjectSize[objnum] = (FX_DWORD)(m_Offset - m_ObjectOffset[objnum]); 1335 m_ObjectSize[objnum] = (FX_DWORD)(m_Offset - m_ObjectOffset[objnum]);
1333 if (pPause && pPause->NeedToPauseNow()) { 1336 if (pPause && pPause->NeedToPauseNow()) {
1334 m_Pos = (void*)(uintptr_t)(objnum + 1); 1337 m_Pos = (void*)(uintptr_t)(objnum + 1);
1335 return 1; 1338 return 1;
1336 } 1339 }
1337 } 1340 }
1338 return 0; 1341 return 0;
1339 } 1342 }
1340 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { 1343 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) {
1341 int32_t iCount = m_NewObjNumArray.GetSize(); 1344 int32_t iCount = m_NewObjNumArray.GetSize();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 j++; 1385 j++;
1383 } 1386 }
1384 m_ObjectOffset.Add(dwStart, j - dwStart); 1387 m_ObjectOffset.Add(dwStart, j - dwStart);
1385 m_ObjectSize.Add(dwStart, j - dwStart); 1388 m_ObjectSize.Add(dwStart, j - dwStart);
1386 dwStart = j; 1389 dwStart = j;
1387 } 1390 }
1388 } 1391 }
1389 void CPDF_Creator::InitNewObjNumOffsets() { 1392 void CPDF_Creator::InitNewObjNumOffsets() {
1390 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; 1393 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0;
1391 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; 1394 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0;
1392 FX_DWORD nOldSize = m_pParser ? m_pParser->m_CrossRef.GetSize() : 0;
1393 FX_POSITION pos = m_pDocument->m_IndirectObjs.GetStartPosition(); 1395 FX_POSITION pos = m_pDocument->m_IndirectObjs.GetStartPosition();
1394 while (pos) { 1396 while (pos) {
1395 size_t key = 0; 1397 size_t key = 0;
1396 CPDF_Object* pObj; 1398 CPDF_Object* pObj;
1397 m_pDocument->m_IndirectObjs.GetNextAssoc(pos, (void*&)key, (void*&)pObj); 1399 m_pDocument->m_IndirectObjs.GetNextAssoc(pos, (void*&)key, (void*&)pObj);
1398 FX_DWORD objnum = (FX_DWORD)key; 1400 FX_DWORD objnum = (FX_DWORD)key;
1399 if (pObj->GetObjNum() == -1) { 1401 if (pObj->GetObjNum() == -1) {
1400 continue; 1402 continue;
1401 } 1403 }
1402 if (bIncremental) { 1404 if (bIncremental) {
1403 if (!pObj->IsModified()) { 1405 if (!pObj->IsModified()) {
1404 continue; 1406 continue;
1405 } 1407 }
1406 } else { 1408 } else if (m_pParser->IsValidObjectNumber(objnum) &&
1407 if (objnum < nOldSize && m_pParser->m_V5Type[objnum] != 0) { 1409 m_pParser->m_V5Type[objnum]) {
1408 continue; 1410 continue;
1409 }
1410 } 1411 }
1411 AppendNewObjNum(objnum); 1412 AppendNewObjNum(objnum);
1412 } 1413 }
1413 int32_t iCount = m_NewObjNumArray.GetSize(); 1414 int32_t iCount = m_NewObjNumArray.GetSize();
1414 if (iCount == 0) { 1415 if (iCount == 0) {
1415 return; 1416 return;
1416 } 1417 }
1417 int32_t i = 0; 1418 int32_t i = 0;
1418 FX_DWORD dwStartObjNum = 0; 1419 FX_DWORD dwStartObjNum = 0;
1419 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0; 1420 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0;
1420 while (i < iCount) { 1421 while (i < iCount) {
1421 dwStartObjNum = m_NewObjNumArray.ElementAt(i); 1422 dwStartObjNum = m_NewObjNumArray.ElementAt(i);
1422 if ((bIncremental && (bNoOriginal || bCrossRefValid)) || 1423 if ((bIncremental && (bNoOriginal || bCrossRefValid)) ||
1423 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) { 1424 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) {
1424 break; 1425 break;
1425 } 1426 }
1426 i++; 1427 i++;
1427 } 1428 }
1428 if (i >= iCount) { 1429 if (i >= iCount) {
1429 return; 1430 return;
1430 } 1431 }
1431 FX_DWORD dwLastObjNum = dwStartObjNum; 1432 FX_DWORD dwLastObjNum = dwStartObjNum;
1432 i++; 1433 i++;
1433 FX_BOOL bNewStart = FALSE; 1434 FX_BOOL bNewStart = FALSE;
1434 for (; i < iCount; i++) { 1435 for (; i < iCount; i++) {
1435 FX_DWORD dwCurObjNum = m_NewObjNumArray.ElementAt(i); 1436 FX_DWORD dwCurObjNum = m_NewObjNumArray.ElementAt(i);
1436 FX_BOOL bExist = 1437 bool bExist = m_pParser->IsValidObjectNumber(dwCurObjNum) &&
1437 (dwCurObjNum < nOldSize && m_ObjectOffset.GetPtrAt(dwCurObjNum)); 1438 m_ObjectOffset.GetPtrAt(dwCurObjNum);
1438 if (bExist || dwCurObjNum - dwLastObjNum > 1) { 1439 if (bExist || dwCurObjNum - dwLastObjNum > 1) {
1439 if (!bNewStart) { 1440 if (!bNewStart) {
1440 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); 1441 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1);
1441 m_ObjectSize.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); 1442 m_ObjectSize.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1);
1442 } 1443 }
1443 dwStartObjNum = dwCurObjNum; 1444 dwStartObjNum = dwCurObjNum;
1444 } 1445 }
1445 if (bNewStart) { 1446 if (bNewStart) {
1446 dwStartObjNum = dwCurObjNum; 1447 dwStartObjNum = dwCurObjNum;
1447 } 1448 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && 1549 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 &&
1549 m_pParser->GetLastXRefOffset() == 0) { 1550 m_pParser->GetLastXRefOffset() == 0) {
1550 InitOldObjNumOffsets(); 1551 InitOldObjNumOffsets();
1551 FX_DWORD dwEnd = m_pParser->GetLastObjNum(); 1552 FX_DWORD dwEnd = m_pParser->GetLastObjNum();
1552 FX_BOOL bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0; 1553 FX_BOOL bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0;
1553 for (FX_DWORD objnum = 0; objnum <= dwEnd; objnum++) { 1554 for (FX_DWORD objnum = 0; objnum <= dwEnd; objnum++) {
1554 if (m_pParser->m_V5Type[objnum] == 0 || 1555 if (m_pParser->m_V5Type[objnum] == 0 ||
1555 m_pParser->m_V5Type[objnum] == 255) { 1556 m_pParser->m_V5Type[objnum] == 255) {
1556 continue; 1557 continue;
1557 } 1558 }
1558 m_ObjectOffset[objnum] = m_pParser->m_CrossRef[objnum]; 1559 m_ObjectOffset[objnum] = m_pParser->m_ObjectInfo[objnum].pos;
1559 if (bObjStm) { 1560 if (bObjStm) {
1560 m_pXRefStream->AddObjectNumberToIndexArray(objnum); 1561 m_pXRefStream->AddObjectNumberToIndexArray(objnum);
1561 } 1562 }
1562 } 1563 }
1563 if (bObjStm) { 1564 if (bObjStm) {
1564 m_pXRefStream->EndXRefStream(this); 1565 m_pXRefStream->EndXRefStream(this);
1565 m_pXRefStream->Start(); 1566 m_pXRefStream->Start();
1566 } 1567 }
1567 } 1568 }
1568 m_iStage = 20; 1569 m_iStage = 20;
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 m_bNewCrypto = FALSE; 2104 m_bNewCrypto = FALSE;
2104 if (!m_bStandardSecurity) { 2105 if (!m_bStandardSecurity) {
2105 return; 2106 return;
2106 } 2107 }
2107 if (m_pEncryptDict) { 2108 if (m_pEncryptDict) {
2108 m_pEncryptDict->Release(); 2109 m_pEncryptDict->Release();
2109 m_pEncryptDict = NULL; 2110 m_pEncryptDict = NULL;
2110 } 2111 }
2111 m_bStandardSecurity = FALSE; 2112 m_bStandardSecurity = FALSE;
2112 } 2113 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698