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

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

Issue 1576033002: Merge to XFA: Use std::map as CPDF_Dictionary's underlying store. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 11 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/fpdfdoc/fpdf_doc.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_colors.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 "core/src/fpdfapi/fpdf_edit/editint.h" 7 #include "core/src/fpdfapi/fpdf_edit/editint.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "core/include/fxcrt/fx_ext.h" 11 #include "core/include/fxcrt/fx_ext.h"
12 #include "core/include/fpdfapi/fpdf_serial.h" 12 #include "core/include/fpdfapi/fpdf_serial.h"
13 #include "core/include/fpdfapi/fpdf_parser.h" 13 #include "core/include/fpdfapi/fpdf_parser.h"
14 14
15 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) 15 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024)
16 #define PDF_XREFSTREAM_MAXSIZE 10000 16 #define PDF_XREFSTREAM_MAXSIZE 10000
17 17
18 // TODO(ochang): Make helper for appending "objnum 0 R ".
19
18 namespace { 20 namespace {
19 21
20 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, 22 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
21 CFX_FileBufferArchive* pFile, 23 CFX_FileBufferArchive* pFile,
22 FX_FILESIZE& offset) { 24 FX_FILESIZE& offset) {
23 int32_t len = 0; 25 int32_t len = 0;
24 if (!pObj) { 26 if (!pObj) {
25 if (pFile->AppendString(" null") < 0) { 27 if (pFile->AppendString(" null") < 0) {
26 return -1; 28 return -1;
27 } 29 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 107 }
106 offset += 1; 108 offset += 1;
107 break; 109 break;
108 } 110 }
109 case PDFOBJ_DICTIONARY: { 111 case PDFOBJ_DICTIONARY: {
110 if (pFile->AppendString("<<") < 0) { 112 if (pFile->AppendString("<<") < 0) {
111 return -1; 113 return -1;
112 } 114 }
113 offset += 2; 115 offset += 2;
114 const CPDF_Dictionary* p = pObj->AsDictionary(); 116 const CPDF_Dictionary* p = pObj->AsDictionary();
115 FX_POSITION pos = p->GetStartPos(); 117 for (const auto& it : *p) {
116 while (pos) { 118 const CFX_ByteString& key = it.first;
117 CFX_ByteString key; 119 CPDF_Object* pValue = it.second;
118 CPDF_Object* pValue = p->GetNextElement(pos, key);
119 if (pFile->AppendString("/") < 0) { 120 if (pFile->AppendString("/") < 0) {
120 return -1; 121 return -1;
121 } 122 }
122 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) { 123 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) {
123 return -1; 124 return -1;
124 } 125 }
125 offset += len + 1; 126 offset += len + 1;
126 if (pValue->GetObjNum()) { 127 if (pValue->GetObjNum()) {
127 if (pFile->AppendString(" ") < 0) { 128 if (pFile->AppendString(" ") < 0) {
128 return -1; 129 return -1;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, 178 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument,
178 CFX_FileBufferArchive* pFile, 179 CFX_FileBufferArchive* pFile,
179 CPDF_Array* pIDArray, 180 CPDF_Array* pIDArray,
180 FX_BOOL bCompress) { 181 FX_BOOL bCompress) {
181 FX_FILESIZE offset = 0; 182 FX_FILESIZE offset = 0;
182 int32_t len = 0; 183 int32_t len = 0;
183 FXSYS_assert(pDocument && pFile); 184 FXSYS_assert(pDocument && pFile);
184 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); 185 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser();
185 if (pParser) { 186 if (pParser) {
186 CPDF_Dictionary* p = pParser->GetTrailer(); 187 CPDF_Dictionary* p = pParser->GetTrailer();
187 FX_POSITION pos = p->GetStartPos(); 188 for (const auto& it : *p) {
188 while (pos) { 189 const CFX_ByteString& key = it.first;
189 CFX_ByteString key; 190 CPDF_Object* pValue = it.second;
190 CPDF_Object* pValue = p->GetNextElement(pos, key);
191 if (key == "Encrypt" || key == "Size" || key == "Filter" || 191 if (key == "Encrypt" || key == "Size" || key == "Filter" ||
192 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 192 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
193 key == "XRefStm" || key == "Type" || key == "ID") { 193 key == "XRefStm" || key == "Type" || key == "ID") {
194 continue; 194 continue;
195 } 195 }
196 if (bCompress && key == "DecodeParms") { 196 if (bCompress && key == "DecodeParms") {
197 continue; 197 continue;
198 } 198 }
199 if (pFile->AppendString(("/")) < 0) { 199 if (pFile->AppendString(("/")) < 0) {
200 return -1; 200 return -1;
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 case PDFOBJ_DICTIONARY: { 1231 case PDFOBJ_DICTIONARY: {
1232 if (!m_pCryptoHandler || pObj == m_pEncryptDict) { 1232 if (!m_pCryptoHandler || pObj == m_pEncryptDict) {
1233 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); 1233 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset);
1234 } 1234 }
1235 if (m_File.AppendString("<<") < 0) { 1235 if (m_File.AppendString("<<") < 0) {
1236 return -1; 1236 return -1;
1237 } 1237 }
1238 m_Offset += 2; 1238 m_Offset += 2;
1239 const CPDF_Dictionary* p = pObj->AsDictionary(); 1239 const CPDF_Dictionary* p = pObj->AsDictionary();
1240 bool bSignDict = IsSignatureDict(p); 1240 bool bSignDict = IsSignatureDict(p);
1241 FX_POSITION pos = p->GetStartPos(); 1241 for (const auto& it : *p) {
1242 while (pos) {
1243 FX_BOOL bSignValue = FALSE; 1242 FX_BOOL bSignValue = FALSE;
1244 CFX_ByteString key; 1243 const CFX_ByteString& key = it.first;
1245 CPDF_Object* pValue = p->GetNextElement(pos, key); 1244 CPDF_Object* pValue = it.second;
1246 if (m_File.AppendString("/") < 0) { 1245 if (m_File.AppendString("/") < 0) {
1247 return -1; 1246 return -1;
1248 } 1247 }
1249 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) { 1248 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) {
1250 return -1; 1249 return -1;
1251 } 1250 }
1252 m_Offset += len + 1; 1251 m_Offset += len + 1;
1253 if (bSignDict && key == "Contents") { 1252 if (bSignDict && key == "Contents") {
1254 bSignValue = TRUE; 1253 bSignValue = TRUE;
1255 } 1254 }
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 } else { 1765 } else {
1767 if (m_File.AppendDWord(m_pDocument->m_LastObjNum + 1) < 0) { 1766 if (m_File.AppendDWord(m_pDocument->m_LastObjNum + 1) < 0) {
1768 return -1; 1767 return -1;
1769 } 1768 }
1770 if (m_File.AppendString(" 0 obj <<") < 0) { 1769 if (m_File.AppendString(" 0 obj <<") < 0) {
1771 return -1; 1770 return -1;
1772 } 1771 }
1773 } 1772 }
1774 if (m_pParser) { 1773 if (m_pParser) {
1775 CPDF_Dictionary* p = m_pParser->m_pTrailer; 1774 CPDF_Dictionary* p = m_pParser->m_pTrailer;
1776 FX_POSITION pos = p->GetStartPos(); 1775 for (const auto& it : *p) {
1777 while (pos) { 1776 const CFX_ByteString& key = it.first;
1778 CFX_ByteString key; 1777 CPDF_Object* pValue = it.second;
1779 CPDF_Object* pValue = p->GetNextElement(pos, key); 1778 // TODO(ochang): Consolidate with similar check in
1779 // PDF_CreatorWriteTrailer.
1780 if (key == "Encrypt" || key == "Size" || key == "Filter" || 1780 if (key == "Encrypt" || key == "Size" || key == "Filter" ||
1781 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 1781 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
1782 key == "XRefStm" || key == "ID") { 1782 key == "XRefStm" || key == "ID") {
1783 continue; 1783 continue;
1784 } 1784 }
1785 if (m_File.AppendString(("/")) < 0) { 1785 if (m_File.AppendString(("/")) < 0) {
1786 return -1; 1786 return -1;
1787 } 1787 }
1788 if (m_File.AppendString(PDF_NameEncode(key)) < 0) { 1788 if (m_File.AppendString(PDF_NameEncode(key)) < 0) {
1789 return -1; 1789 return -1;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 m_bNewCrypto = FALSE; 2086 m_bNewCrypto = FALSE;
2087 if (!m_bStandardSecurity) { 2087 if (!m_bStandardSecurity) {
2088 return; 2088 return;
2089 } 2089 }
2090 if (m_pEncryptDict) { 2090 if (m_pEncryptDict) {
2091 m_pEncryptDict->Release(); 2091 m_pEncryptDict->Release();
2092 m_pEncryptDict = NULL; 2092 m_pEncryptDict = NULL;
2093 } 2093 }
2094 m_bStandardSecurity = FALSE; 2094 m_bStandardSecurity = FALSE;
2095 } 2095 }
OLDNEW
« no previous file with comments | « core/include/fpdfdoc/fpdf_doc.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698