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

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

Issue 2253723002: Move parser pointer to CPDF_Document (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 4 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 "core/fpdfapi/fpdf_edit/editint.h" 7 #include "core/fpdfapi/fpdf_edit/editint.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 break; 1226 break;
1227 } 1227 }
1228 } 1228 }
1229 return 1; 1229 return 1;
1230 } 1230 }
1231 int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) { 1231 int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) {
1232 if (m_pParser->IsObjectFreeOrNull(objnum)) 1232 if (m_pParser->IsObjectFreeOrNull(objnum))
1233 return 0; 1233 return 0;
1234 1234
1235 m_ObjectOffset[objnum] = m_Offset; 1235 m_ObjectOffset[objnum] = m_Offset;
1236 FX_BOOL bExistInMap = 1236 FX_BOOL bExistInMap = !!m_pDocument->GetIndirectObject(objnum);
1237 pdfium::ContainsKey(m_pDocument->m_IndirectObjs, objnum);
1238 const uint8_t object_type = m_pParser->GetObjectType(objnum); 1237 const uint8_t object_type = m_pParser->GetObjectType(objnum);
1239 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; 1238 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream;
1240 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || 1239 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap ||
1241 bObjStm) { 1240 bObjStm) {
1242 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); 1241 CPDF_Object* pObj = m_pDocument->GetIndirectObjectIfValid(objnum);
1243 if (!pObj) { 1242 if (!pObj) {
1244 m_ObjectOffset[objnum] = 0; 1243 m_ObjectOffset[objnum] = 0;
1245 return 0; 1244 return 0;
1246 } 1245 }
1247 if (WriteIndirectObj(pObj)) { 1246 if (WriteIndirectObj(pObj)) {
1248 return -1; 1247 return -1;
1249 } 1248 }
1250 if (!bExistInMap) { 1249 if (!bExistInMap) {
1251 m_pDocument->ReleaseIndirectObject(objnum); 1250 m_pDocument->ReleaseIndirectObject(objnum);
1252 } 1251 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 return 1; 1312 return 1;
1314 } 1313 }
1315 } 1314 }
1316 return 0; 1315 return 0;
1317 } 1316 }
1318 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { 1317 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) {
1319 int32_t iCount = m_NewObjNumArray.GetSize(); 1318 int32_t iCount = m_NewObjNumArray.GetSize();
1320 int32_t index = (int32_t)(uintptr_t)m_Pos; 1319 int32_t index = (int32_t)(uintptr_t)m_Pos;
1321 while (index < iCount) { 1320 while (index < iCount) {
1322 uint32_t objnum = m_NewObjNumArray.ElementAt(index); 1321 uint32_t objnum = m_NewObjNumArray.ElementAt(index);
1323 auto it = m_pDocument->m_IndirectObjs.find(objnum); 1322 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum);
1324 if (it == m_pDocument->m_IndirectObjs.end()) { 1323 if (!pObj) {
1325 ++index; 1324 ++index;
1326 continue; 1325 continue;
1327 } 1326 }
1328 m_ObjectOffset[objnum] = m_Offset; 1327 m_ObjectOffset[objnum] = m_Offset;
1329 if (WriteIndirectObj(it->second)) { 1328 if (WriteIndirectObj(pObj)) {
1330 return -1; 1329 return -1;
1331 } 1330 }
1332 index++; 1331 index++;
1333 if (pPause && pPause->NeedToPauseNow()) { 1332 if (pPause && pPause->NeedToPauseNow()) {
1334 m_Pos = (FX_POSITION)(uintptr_t)index; 1333 m_Pos = (FX_POSITION)(uintptr_t)index;
1335 return 1; 1334 return 1;
1336 } 1335 }
1337 } 1336 }
1338 return 0; 1337 return 0;
1339 } 1338 }
(...skipping 16 matching lines...) Expand all
1356 j++; 1355 j++;
1357 1356
1358 m_ObjectOffset.Add(dwStart, j - dwStart); 1357 m_ObjectOffset.Add(dwStart, j - dwStart);
1359 dwStart = j; 1358 dwStart = j;
1360 } 1359 }
1361 } 1360 }
1362 1361
1363 void CPDF_Creator::InitNewObjNumOffsets() { 1362 void CPDF_Creator::InitNewObjNumOffsets() {
1364 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; 1363 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0;
1365 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; 1364 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0;
1366 for (const auto& pair : m_pDocument->m_IndirectObjs) { 1365 for (auto it = m_pDocument->begin(); it != m_pDocument->end(); it++) {
1367 const uint32_t objnum = pair.first; 1366 const uint32_t objnum = it->first;
1368 const CPDF_Object* pObj = pair.second; 1367 const CPDF_Object* pObj = it->second;
1369 if (bIncremental || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) 1368 if (bIncremental || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
1370 continue; 1369 continue;
1371 if (m_pParser && m_pParser->IsValidObjectNumber(objnum) && 1370 if (m_pParser && m_pParser->IsValidObjectNumber(objnum) &&
1372 m_pParser->GetObjectType(objnum)) { 1371 m_pParser->GetObjectType(objnum)) {
1373 continue; 1372 continue;
1374 } 1373 }
1375 AppendNewObjNum(objnum); 1374 AppendNewObjNum(objnum);
1376 } 1375 }
1377 1376
1378 int32_t iCount = m_NewObjNumArray.GetSize(); 1377 int32_t iCount = m_NewObjNumArray.GetSize();
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { 1695 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) {
1697 ASSERT(m_iStage >= 90); 1696 ASSERT(m_iStage >= 90);
1698 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { 1697 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) {
1699 FX_BOOL bXRefStream = 1698 FX_BOOL bXRefStream =
1700 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); 1699 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream();
1701 if (!bXRefStream) { 1700 if (!bXRefStream) {
1702 if (m_File.AppendString("trailer\r\n<<") < 0) { 1701 if (m_File.AppendString("trailer\r\n<<") < 0) {
1703 return -1; 1702 return -1;
1704 } 1703 }
1705 } else { 1704 } else {
1706 if (m_File.AppendDWord(m_pDocument->m_LastObjNum + 1) < 0) { 1705 if (m_File.AppendDWord(m_pDocument->GetLastObjNum() + 1) < 0) {
1707 return -1; 1706 return -1;
1708 } 1707 }
1709 if (m_File.AppendString(" 0 obj <<") < 0) { 1708 if (m_File.AppendString(" 0 obj <<") < 0) {
1710 return -1; 1709 return -1;
1711 } 1710 }
1712 } 1711 }
1713 if (m_pParser) { 1712 if (m_pParser) {
1714 CPDF_Dictionary* p = m_pParser->GetTrailer(); 1713 CPDF_Dictionary* p = m_pParser->GetTrailer();
1715 for (const auto& it : *p) { 1714 for (const auto& it : *p) {
1716 const CFX_ByteString& key = it.first; 1715 const CFX_ByteString& key = it.first;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 m_pCryptoHandler = nullptr; 2015 m_pCryptoHandler = nullptr;
2017 } 2016 }
2018 void CPDF_Creator::ResetStandardSecurity() { 2017 void CPDF_Creator::ResetStandardSecurity() {
2019 if (!m_bLocalCryptoHandler) 2018 if (!m_bLocalCryptoHandler)
2020 return; 2019 return;
2021 2020
2022 delete m_pCryptoHandler; 2021 delete m_pCryptoHandler;
2023 m_pCryptoHandler = nullptr; 2022 m_pCryptoHandler = nullptr;
2024 m_bLocalCryptoHandler = FALSE; 2023 m_bLocalCryptoHandler = FALSE;
2025 } 2024 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_parser/cfdf_document.cpp » ('j') | core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698