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

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

Issue 1862123003: Rename both As{Byte,Wide}StringC() helpers to AsStringC(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase, fix new usage. Created 4 years, 8 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (pFile->AppendString(" null") < 0) { 47 if (pFile->AppendString(" null") < 0) {
48 return -1; 48 return -1;
49 } 49 }
50 offset += 5; 50 offset += 5;
51 break; 51 break;
52 case CPDF_Object::BOOLEAN: 52 case CPDF_Object::BOOLEAN:
53 case CPDF_Object::NUMBER: 53 case CPDF_Object::NUMBER:
54 if (pFile->AppendString(" ") < 0) { 54 if (pFile->AppendString(" ") < 0) {
55 return -1; 55 return -1;
56 } 56 }
57 if ((len = pFile->AppendString(pObj->GetString().AsByteStringC())) < 0) { 57 if ((len = pFile->AppendString(pObj->GetString().AsStringC())) < 0) {
58 return -1; 58 return -1;
59 } 59 }
60 offset += len + 1; 60 offset += len + 1;
61 break; 61 break;
62 case CPDF_Object::STRING: { 62 case CPDF_Object::STRING: {
63 CFX_ByteString str = pObj->GetString(); 63 CFX_ByteString str = pObj->GetString();
64 FX_BOOL bHex = pObj->AsString()->IsHex(); 64 FX_BOOL bHex = pObj->AsString()->IsHex();
65 if ((len = pFile->AppendString( 65 if ((len = pFile->AppendString(PDF_EncodeString(str, bHex).AsStringC())) <
66 PDF_EncodeString(str, bHex).AsByteStringC())) < 0) { 66 0) {
67 return -1; 67 return -1;
68 } 68 }
69 offset += len; 69 offset += len;
70 break; 70 break;
71 } 71 }
72 case CPDF_Object::NAME: { 72 case CPDF_Object::NAME: {
73 if (pFile->AppendString("/") < 0) { 73 if (pFile->AppendString("/") < 0) {
74 return -1; 74 return -1;
75 } 75 }
76 CFX_ByteString str = pObj->GetString(); 76 CFX_ByteString str = pObj->GetString();
77 if ((len = pFile->AppendString(PDF_NameEncode(str).AsByteStringC())) < 77 if ((len = pFile->AppendString(PDF_NameEncode(str).AsStringC())) < 0) {
78 0) {
79 return -1; 78 return -1;
80 } 79 }
81 offset += len + 1; 80 offset += len + 1;
82 break; 81 break;
83 } 82 }
84 case CPDF_Object::REFERENCE: { 83 case CPDF_Object::REFERENCE: {
85 if (pFile->AppendString(" ") < 0) 84 if (pFile->AppendString(" ") < 0)
86 return -1; 85 return -1;
87 if ((len = pFile->AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) 86 if ((len = pFile->AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0)
88 return -1; 87 return -1;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return -1; 126 return -1;
128 } 127 }
129 offset += 2; 128 offset += 2;
130 const CPDF_Dictionary* p = pObj->AsDictionary(); 129 const CPDF_Dictionary* p = pObj->AsDictionary();
131 for (const auto& it : *p) { 130 for (const auto& it : *p) {
132 const CFX_ByteString& key = it.first; 131 const CFX_ByteString& key = it.first;
133 CPDF_Object* pValue = it.second; 132 CPDF_Object* pValue = it.second;
134 if (pFile->AppendString("/") < 0) { 133 if (pFile->AppendString("/") < 0) {
135 return -1; 134 return -1;
136 } 135 }
137 if ((len = pFile->AppendString(PDF_NameEncode(key).AsByteStringC())) < 136 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) {
138 0) {
139 return -1; 137 return -1;
140 } 138 }
141 offset += len + 1; 139 offset += len + 1;
142 if (pValue->GetObjNum()) { 140 if (pValue->GetObjNum()) {
143 if (pFile->AppendString(" ") < 0) { 141 if (pFile->AppendString(" ") < 0) {
144 return -1; 142 return -1;
145 } 143 }
146 if ((len = pFile->AppendDWord(pValue->GetObjNum())) < 0) { 144 if ((len = pFile->AppendDWord(pValue->GetObjNum())) < 0) {
147 return -1; 145 return -1;
148 } 146 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 205 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
208 key == "XRefStm" || key == "Type" || key == "ID") { 206 key == "XRefStm" || key == "Type" || key == "ID") {
209 continue; 207 continue;
210 } 208 }
211 if (bCompress && key == "DecodeParms") { 209 if (bCompress && key == "DecodeParms") {
212 continue; 210 continue;
213 } 211 }
214 if (pFile->AppendString(("/")) < 0) { 212 if (pFile->AppendString(("/")) < 0) {
215 return -1; 213 return -1;
216 } 214 }
217 if ((len = pFile->AppendString(PDF_NameEncode(key).AsByteStringC())) < 215 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) {
218 0) {
219 return -1; 216 return -1;
220 } 217 }
221 offset += len + 1; 218 offset += len + 1;
222 if (pValue->GetObjNum()) { 219 if (pValue->GetObjNum()) {
223 if (pFile->AppendString(" ") < 0) { 220 if (pFile->AppendString(" ") < 0) {
224 return -1; 221 return -1;
225 } 222 }
226 if ((len = pFile->AppendDWord(pValue->GetObjNum())) < 0) { 223 if ((len = pFile->AppendDWord(pValue->GetObjNum())) < 0) {
227 return -1; 224 return -1;
228 } 225 }
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 if (m_File.AppendString(" null") < 0) { 1108 if (m_File.AppendString(" null") < 0) {
1112 return -1; 1109 return -1;
1113 } 1110 }
1114 m_Offset += 5; 1111 m_Offset += 5;
1115 break; 1112 break;
1116 case CPDF_Object::BOOLEAN: 1113 case CPDF_Object::BOOLEAN:
1117 case CPDF_Object::NUMBER: 1114 case CPDF_Object::NUMBER:
1118 if (m_File.AppendString(" ") < 0) { 1115 if (m_File.AppendString(" ") < 0) {
1119 return -1; 1116 return -1;
1120 } 1117 }
1121 if ((len = m_File.AppendString(pObj->GetString().AsByteStringC())) < 0) { 1118 if ((len = m_File.AppendString(pObj->GetString().AsStringC())) < 0) {
1122 return -1; 1119 return -1;
1123 } 1120 }
1124 m_Offset += len + 1; 1121 m_Offset += len + 1;
1125 break; 1122 break;
1126 case CPDF_Object::STRING: { 1123 case CPDF_Object::STRING: {
1127 CFX_ByteString str = pObj->GetString(); 1124 CFX_ByteString str = pObj->GetString();
1128 FX_BOOL bHex = pObj->AsString()->IsHex(); 1125 FX_BOOL bHex = pObj->AsString()->IsHex();
1129 if (!m_pCryptoHandler || !bEncrypt) { 1126 if (!m_pCryptoHandler || !bEncrypt) {
1130 CFX_ByteString content = PDF_EncodeString(str, bHex); 1127 CFX_ByteString content = PDF_EncodeString(str, bHex);
1131 if ((len = m_File.AppendString(content.AsByteStringC())) < 0) { 1128 if ((len = m_File.AppendString(content.AsStringC())) < 0) {
1132 return -1; 1129 return -1;
1133 } 1130 }
1134 m_Offset += len; 1131 m_Offset += len;
1135 break; 1132 break;
1136 } 1133 }
1137 CPDF_Encryptor encryptor; 1134 CPDF_Encryptor encryptor;
1138 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), 1135 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(),
1139 str.GetLength()); 1136 str.GetLength());
1140 CFX_ByteString content = PDF_EncodeString( 1137 CFX_ByteString content = PDF_EncodeString(
1141 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), 1138 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize),
1142 bHex); 1139 bHex);
1143 if ((len = m_File.AppendString(content.AsByteStringC())) < 0) { 1140 if ((len = m_File.AppendString(content.AsStringC())) < 0) {
1144 return -1; 1141 return -1;
1145 } 1142 }
1146 m_Offset += len; 1143 m_Offset += len;
1147 break; 1144 break;
1148 } 1145 }
1149 case CPDF_Object::STREAM: { 1146 case CPDF_Object::STREAM: {
1150 CPDF_FlateEncoder encoder; 1147 CPDF_FlateEncoder encoder;
1151 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), 1148 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()),
1152 m_bCompress); 1149 m_bCompress);
1153 CPDF_Encryptor encryptor; 1150 CPDF_Encryptor encryptor;
(...skipping 19 matching lines...) Expand all
1173 return -1; 1170 return -1;
1174 } 1171 }
1175 m_Offset += len; 1172 m_Offset += len;
1176 break; 1173 break;
1177 } 1174 }
1178 case CPDF_Object::NAME: { 1175 case CPDF_Object::NAME: {
1179 if (m_File.AppendString("/") < 0) { 1176 if (m_File.AppendString("/") < 0) {
1180 return -1; 1177 return -1;
1181 } 1178 }
1182 CFX_ByteString str = pObj->GetString(); 1179 CFX_ByteString str = pObj->GetString();
1183 if ((len = m_File.AppendString(PDF_NameEncode(str).AsByteStringC())) < 1180 if ((len = m_File.AppendString(PDF_NameEncode(str).AsStringC())) < 0) {
1184 0) {
1185 return -1; 1181 return -1;
1186 } 1182 }
1187 m_Offset += len + 1; 1183 m_Offset += len + 1;
1188 break; 1184 break;
1189 } 1185 }
1190 case CPDF_Object::REFERENCE: { 1186 case CPDF_Object::REFERENCE: {
1191 if (m_File.AppendString(" ") < 0) 1187 if (m_File.AppendString(" ") < 0)
1192 return -1; 1188 return -1;
1193 if ((len = m_File.AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) 1189 if ((len = m_File.AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0)
1194 return -1; 1190 return -1;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 m_Offset += 2; 1234 m_Offset += 2;
1239 const CPDF_Dictionary* p = pObj->AsDictionary(); 1235 const CPDF_Dictionary* p = pObj->AsDictionary();
1240 bool bSignDict = p->IsSignatureDict(); 1236 bool bSignDict = p->IsSignatureDict();
1241 for (const auto& it : *p) { 1237 for (const auto& it : *p) {
1242 FX_BOOL bSignValue = FALSE; 1238 FX_BOOL bSignValue = FALSE;
1243 const CFX_ByteString& key = it.first; 1239 const CFX_ByteString& key = it.first;
1244 CPDF_Object* pValue = it.second; 1240 CPDF_Object* pValue = it.second;
1245 if (m_File.AppendString("/") < 0) { 1241 if (m_File.AppendString("/") < 0) {
1246 return -1; 1242 return -1;
1247 } 1243 }
1248 if ((len = m_File.AppendString(PDF_NameEncode(key).AsByteStringC())) < 1244 if ((len = m_File.AppendString(PDF_NameEncode(key).AsStringC())) < 0) {
1249 0) {
1250 return -1; 1245 return -1;
1251 } 1246 }
1252 m_Offset += len + 1; 1247 m_Offset += len + 1;
1253 if (bSignDict && key == "Contents") { 1248 if (bSignDict && key == "Contents") {
1254 bSignValue = TRUE; 1249 bSignValue = TRUE;
1255 } 1250 }
1256 if (pValue->GetObjNum()) { 1251 if (pValue->GetObjNum()) {
1257 if (m_File.AppendString(" ") < 0) { 1252 if (m_File.AppendString(" ") < 0) {
1258 return -1; 1253 return -1;
1259 } 1254 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 m_XrefStart = m_pXRefStream->m_PrevOffset; 1636 m_XrefStart = m_pXRefStream->m_PrevOffset;
1642 m_iStage = 90; 1637 m_iStage = 90;
1643 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || 1638 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 ||
1644 !m_pParser->IsXRefStream()) { 1639 !m_pParser->IsXRefStream()) {
1645 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || 1640 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 ||
1646 m_pParser->GetLastXRefOffset() == 0) { 1641 m_pParser->GetLastXRefOffset() == 0) {
1647 CFX_ByteString str; 1642 CFX_ByteString str;
1648 str = m_ObjectOffset.GetPtrAt(1) 1643 str = m_ObjectOffset.GetPtrAt(1)
1649 ? "xref\r\n" 1644 ? "xref\r\n"
1650 : "xref\r\n0 1\r\n0000000000 65535 f\r\n"; 1645 : "xref\r\n0 1\r\n0000000000 65535 f\r\n";
1651 if (m_File.AppendString(str.AsByteStringC()) < 0) { 1646 if (m_File.AppendString(str.AsStringC()) < 0) {
1652 return -1; 1647 return -1;
1653 } 1648 }
1654 m_Pos = (void*)(uintptr_t)1; 1649 m_Pos = (void*)(uintptr_t)1;
1655 m_iStage = 81; 1650 m_iStage = 81;
1656 } else { 1651 } else {
1657 if (m_File.AppendString("xref\r\n") < 0) { 1652 if (m_File.AppendString("xref\r\n") < 0) {
1658 return -1; 1653 return -1;
1659 } 1654 }
1660 m_Pos = (void*)(uintptr_t)0; 1655 m_Pos = (void*)(uintptr_t)0;
1661 m_iStage = 82; 1656 m_iStage = 82;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 // TODO(ochang): Consolidate with similar check in 1765 // TODO(ochang): Consolidate with similar check in
1771 // PDF_CreatorWriteTrailer. 1766 // PDF_CreatorWriteTrailer.
1772 if (key == "Encrypt" || key == "Size" || key == "Filter" || 1767 if (key == "Encrypt" || key == "Size" || key == "Filter" ||
1773 key == "Index" || key == "Length" || key == "Prev" || key == "W" || 1768 key == "Index" || key == "Length" || key == "Prev" || key == "W" ||
1774 key == "XRefStm" || key == "ID") { 1769 key == "XRefStm" || key == "ID") {
1775 continue; 1770 continue;
1776 } 1771 }
1777 if (m_File.AppendString(("/")) < 0) { 1772 if (m_File.AppendString(("/")) < 0) {
1778 return -1; 1773 return -1;
1779 } 1774 }
1780 if (m_File.AppendString(PDF_NameEncode(key).AsByteStringC()) < 0) { 1775 if (m_File.AppendString(PDF_NameEncode(key).AsStringC()) < 0) {
1781 return -1; 1776 return -1;
1782 } 1777 }
1783 if (pValue->GetObjNum()) { 1778 if (pValue->GetObjNum()) {
1784 if (m_File.AppendString(" ") < 0) { 1779 if (m_File.AppendString(" ") < 0) {
1785 return -1; 1780 return -1;
1786 } 1781 }
1787 if (m_File.AppendDWord(pValue->GetObjNum()) < 0) { 1782 if (m_File.AppendDWord(pValue->GetObjNum()) < 0) {
1788 return -1; 1783 return -1;
1789 } 1784 }
1790 if (m_File.AppendString(" 0 R ") < 0) { 1785 if (m_File.AppendString(" 0 R ") < 0) {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 m_bNewCrypto = FALSE; 2070 m_bNewCrypto = FALSE;
2076 if (!m_bStandardSecurity) { 2071 if (!m_bStandardSecurity) {
2077 return; 2072 return;
2078 } 2073 }
2079 if (m_pEncryptDict) { 2074 if (m_pEncryptDict) {
2080 m_pEncryptDict->Release(); 2075 m_pEncryptDict->Release();
2081 m_pEncryptDict = NULL; 2076 m_pEncryptDict = NULL;
2082 } 2077 }
2083 m_bStandardSecurity = FALSE; 2078 m_bStandardSecurity = FALSE;
2084 } 2079 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp ('k') | core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698