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

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

Issue 1541703003: Use std::map as CPDF_Dictionary's underlying store. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase + address comments 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
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 offset += 1; 102 offset += 1;
103 break; 103 break;
104 } 104 }
105 case PDFOBJ_DICTIONARY: { 105 case PDFOBJ_DICTIONARY: {
106 if (pFile->AppendString("<<") < 0) { 106 if (pFile->AppendString("<<") < 0) {
107 return -1; 107 return -1;
108 } 108 }
109 offset += 2; 109 offset += 2;
110 const CPDF_Dictionary* p = pObj->AsDictionary(); 110 const CPDF_Dictionary* p = pObj->AsDictionary();
111 FX_POSITION pos = p->GetStartPos(); 111 for (const auto& it : *p) {
112 while (pos) { 112 const CFX_ByteString& key = it.first;
113 CFX_ByteString key; 113 CPDF_Object* pValue = it.second;
114 CPDF_Object* pValue = p->GetNextElement(pos, key);
115 if (pFile->AppendString("/") < 0) { 114 if (pFile->AppendString("/") < 0) {
116 return -1; 115 return -1;
117 } 116 }
118 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) { 117 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) {
119 return -1; 118 return -1;
120 } 119 }
121 offset += len + 1; 120 offset += len + 1;
122 if (pValue->GetObjNum()) { 121 if (pValue->GetObjNum()) {
123 if (pFile->AppendString(" ") < 0) { 122 if (pFile->AppendString(" ") < 0) {
124 return -1; 123 return -1;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, 171 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument,
173 CFX_FileBufferArchive* pFile, 172 CFX_FileBufferArchive* pFile,
174 CPDF_Array* pIDArray, 173 CPDF_Array* pIDArray,
175 FX_BOOL bCompress) { 174 FX_BOOL bCompress) {
176 FX_FILESIZE offset = 0; 175 FX_FILESIZE offset = 0;
177 int32_t len = 0; 176 int32_t len = 0;
178 FXSYS_assert(pDocument && pFile); 177 FXSYS_assert(pDocument && pFile);
179 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); 178 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser();
180 if (pParser) { 179 if (pParser) {
181 CPDF_Dictionary* p = pParser->GetTrailer(); 180 CPDF_Dictionary* p = pParser->GetTrailer();
182 FX_POSITION pos = p->GetStartPos(); 181 for (const auto& it : *p) {
183 while (pos) { 182 const CFX_ByteString& key = it.first;
184 CFX_ByteString key; 183 CPDF_Object* pValue = it.second;
185 CPDF_Object* pValue = p->GetNextElement(pos, key);
186 if (key == "Encrypt" || key == "Size" || key == "Filter" || 184 if (key == "Encrypt" || key == "Size" || key == "Filter" ||
187 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 185 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
188 key == "XRefStm" || key == "Type" || key == "ID") { 186 key == "XRefStm" || key == "Type" || key == "ID") {
189 continue; 187 continue;
190 } 188 }
191 if (bCompress && key == "DecodeParms") { 189 if (bCompress && key == "DecodeParms") {
192 continue; 190 continue;
193 } 191 }
194 if (pFile->AppendString(("/")) < 0) { 192 if (pFile->AppendString(("/")) < 0) {
195 return -1; 193 return -1;
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 case PDFOBJ_DICTIONARY: { 1199 case PDFOBJ_DICTIONARY: {
1202 if (!m_pCryptoHandler || pObj == m_pEncryptDict) { 1200 if (!m_pCryptoHandler || pObj == m_pEncryptDict) {
1203 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); 1201 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset);
1204 } 1202 }
1205 if (m_File.AppendString("<<") < 0) { 1203 if (m_File.AppendString("<<") < 0) {
1206 return -1; 1204 return -1;
1207 } 1205 }
1208 m_Offset += 2; 1206 m_Offset += 2;
1209 const CPDF_Dictionary* p = pObj->AsDictionary(); 1207 const CPDF_Dictionary* p = pObj->AsDictionary();
1210 bool bSignDict = IsSignatureDict(p); 1208 bool bSignDict = IsSignatureDict(p);
1211 FX_POSITION pos = p->GetStartPos(); 1209 for (const auto& it : *p) {
1212 while (pos) {
1213 FX_BOOL bSignValue = FALSE; 1210 FX_BOOL bSignValue = FALSE;
1214 CFX_ByteString key; 1211 const CFX_ByteString& key = it.first;
1215 CPDF_Object* pValue = p->GetNextElement(pos, key); 1212 CPDF_Object* pValue = it.second;
1216 if (m_File.AppendString("/") < 0) { 1213 if (m_File.AppendString("/") < 0) {
1217 return -1; 1214 return -1;
1218 } 1215 }
1219 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) { 1216 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) {
1220 return -1; 1217 return -1;
1221 } 1218 }
1222 m_Offset += len + 1; 1219 m_Offset += len + 1;
1223 if (bSignDict && key == "Contents") { 1220 if (bSignDict && key == "Contents") {
1224 bSignValue = TRUE; 1221 bSignValue = TRUE;
1225 } 1222 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 } else { 1767 } else {
1771 if (m_File.AppendDWord(m_pDocument->m_LastObjNum + 1) < 0) { 1768 if (m_File.AppendDWord(m_pDocument->m_LastObjNum + 1) < 0) {
1772 return -1; 1769 return -1;
1773 } 1770 }
1774 if (m_File.AppendString(" 0 obj <<") < 0) { 1771 if (m_File.AppendString(" 0 obj <<") < 0) {
1775 return -1; 1772 return -1;
1776 } 1773 }
1777 } 1774 }
1778 if (m_pParser) { 1775 if (m_pParser) {
1779 CPDF_Dictionary* p = m_pParser->m_pTrailer; 1776 CPDF_Dictionary* p = m_pParser->m_pTrailer;
1780 FX_POSITION pos = p->GetStartPos(); 1777 for (const auto& it : *p) {
1781 while (pos) { 1778 const CFX_ByteString& key = it.first;
1782 CFX_ByteString key; 1779 CPDF_Object* pValue = it.second;
1783 CPDF_Object* pValue = p->GetNextElement(pos, key);
1784 if (key == "Encrypt" || key == "Size" || key == "Filter" || 1780 if (key == "Encrypt" || key == "Size" || key == "Filter" ||
Tom Sepez 2016/01/08 00:33:52 NB: similar to line 184, but missing "Type". Wond
Oliver Chang 2016/01/08 23:14:58 ack. added a TODO.
1785 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 1781 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
1786 key == "XRefStm" || key == "ID") { 1782 key == "XRefStm" || key == "ID") {
1787 continue; 1783 continue;
1788 } 1784 }
1789 if (m_File.AppendString(("/")) < 0) { 1785 if (m_File.AppendString(("/")) < 0) {
1790 return -1; 1786 return -1;
1791 } 1787 }
1792 if (m_File.AppendString(PDF_NameEncode(key)) < 0) { 1788 if (m_File.AppendString(PDF_NameEncode(key)) < 0) {
1793 return -1; 1789 return -1;
1794 } 1790 }
1795 if (pValue->GetObjNum()) { 1791 if (pValue->GetObjNum()) {
1796 if (m_File.AppendString(" ") < 0) { 1792 if (m_File.AppendString(" ") < 0) {
1797 return -1; 1793 return -1;
1798 } 1794 }
1799 if (m_File.AppendDWord(pValue->GetObjNum()) < 0) { 1795 if (m_File.AppendDWord(pValue->GetObjNum()) < 0) {
Tom Sepez 2016/01/08 00:33:52 NB: also a helper method to append "objnum 0 R" -
Oliver Chang 2016/01/08 23:14:58 ack. added a TODO.
1800 return -1; 1796 return -1;
1801 } 1797 }
1802 if (m_File.AppendString(" 0 R ") < 0) { 1798 if (m_File.AppendString(" 0 R ") < 0) {
1803 return -1; 1799 return -1;
1804 } 1800 }
1805 } else { 1801 } else {
1806 FX_FILESIZE offset = 0; 1802 FX_FILESIZE offset = 0;
1807 if (PDF_CreatorAppendObject(pValue, &m_File, offset) < 0) { 1803 if (PDF_CreatorAppendObject(pValue, &m_File, offset) < 0) {
1808 return -1; 1804 return -1;
1809 } 1805 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 m_bNewCrypto = FALSE; 2089 m_bNewCrypto = FALSE;
2094 if (!m_bStandardSecurity) { 2090 if (!m_bStandardSecurity) {
2095 return; 2091 return;
2096 } 2092 }
2097 if (m_pEncryptDict) { 2093 if (m_pEncryptDict) {
2098 m_pEncryptDict->Release(); 2094 m_pEncryptDict->Release();
2099 m_pEncryptDict = NULL; 2095 m_pEncryptDict = NULL;
2100 } 2096 }
2101 m_bStandardSecurity = FALSE; 2097 m_bStandardSecurity = FALSE;
2102 } 2098 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698