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

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

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