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

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

Issue 1402413004: Add type cast definitions for CPDF_Stream. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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 "../../../include/fxcrt/fx_ext.h" 7 #include "../../../include/fxcrt/fx_ext.h"
8 #include "../../../include/fpdfapi/fpdf_serial.h" 8 #include "../../../include/fpdfapi/fpdf_serial.h"
9 #include "../../../include/fpdfapi/fpdf_parser.h" 9 #include "../../../include/fpdfapi/fpdf_parser.h"
10 #include "editint.h" 10 #include "editint.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 } 140 }
141 } 141 }
142 if (pFile->AppendString(FX_BSTRC(">>")) < 0) { 142 if (pFile->AppendString(FX_BSTRC(">>")) < 0) {
143 return -1; 143 return -1;
144 } 144 }
145 offset += 2; 145 offset += 2;
146 break; 146 break;
147 } 147 }
148 case PDFOBJ_STREAM: { 148 case PDFOBJ_STREAM: {
149 CPDF_Stream* p = (CPDF_Stream*)pObj; 149 const CPDF_Stream* p = pObj->AsStream();
150 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) { 150 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) {
151 return -1; 151 return -1;
152 } 152 }
153 if (pFile->AppendString(FX_BSTRC("stream\r\n")) < 0) { 153 if (pFile->AppendString(FX_BSTRC("stream\r\n")) < 0) {
154 return -1; 154 return -1;
155 } 155 }
156 offset += 8; 156 offset += 8;
157 CPDF_StreamAcc acc; 157 CPDF_StreamAcc acc;
158 acc.LoadAllData(p, TRUE); 158 acc.LoadAllData(p, TRUE);
159 if (pFile->AppendBlock(acc.GetData(), acc.GetSize()) < 0) { 159 if (pFile->AppendBlock(acc.GetData(), acc.GetSize()) < 0) {
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 return FALSE; 922 return FALSE;
923 } 923 }
924 int32_t iSize = pXRef->m_IndexArray.GetSize() / 2; 924 int32_t iSize = pXRef->m_IndexArray.GetSize() / 2;
925 int32_t iCount = 0; 925 int32_t iCount = 0;
926 for (int32_t i = 0; i < iSize; i++) { 926 for (int32_t i = 0; i < iSize; i++) {
927 iCount += pXRef->m_IndexArray.ElementAt(i * 2 + 1); 927 iCount += pXRef->m_IndexArray.ElementAt(i * 2 + 1);
928 } 928 }
929 return (iCount >= PDF_XREFSTREAM_MAXSIZE); 929 return (iCount >= PDF_XREFSTREAM_MAXSIZE);
930 } 930 }
931 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { 931 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) {
932 if (!m_pXRefStream) { 932 if (!m_pXRefStream)
933 return 1; 933 return 1;
934 } 934
935 FX_DWORD objnum = pObj->GetObjNum(); 935 FX_DWORD objnum = pObj->GetObjNum();
936 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && 936 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum &&
937 m_pParser->m_ObjVersion[objnum] > 0) { 937 m_pParser->m_ObjVersion[objnum] > 0) {
938 return 1; 938 return 1;
939 } 939 }
940 940
941 if (pObj->IsNumber()) 941 if (pObj->IsNumber())
942 return 1; 942 return 1;
943 943
944 CPDF_Dictionary* pDict = pObj->GetDict(); 944 CPDF_Dictionary* pDict = pObj->GetDict();
945 if (pObj->GetType() == PDFOBJ_STREAM) { 945 if (pObj->IsStream())
946 if (pDict && pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("XRef")) { 946 return !pDict || pDict->GetString(FX_BSTRC("Type")) != FX_BSTRC("XRef");
Tom Sepez 2015/10/22 17:16:45 nit: this is an int32_t function so it probably sh
dsinclair 2015/10/22 17:42:56 Done.
947 return 0; 947
948 } 948 if (pDict) {
949 return 1; 949 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict)
950 return 1;
951 if (IsSignatureDict(pDict))
952 return 1;
953 if (pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("Page"))
954 return 1;
950 } 955 }
951 if (pDict) { 956
952 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) {
953 return 1;
954 }
955 if (IsSignatureDict(pDict)) {
956 return 1;
957 }
958 if (pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("Page")) {
959 return 1;
960 }
961 }
962 m_pXRefStream->AddObjectNumberToIndexArray(objnum); 957 m_pXRefStream->AddObjectNumberToIndexArray(objnum);
963 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) { 958 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0)
964 return -1; 959 return -1;
965 } 960 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags))
966 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) {
967 return 0; 961 return 0;
968 } 962 if (!m_pXRefStream->End(this))
969 if (!m_pXRefStream->End(this)) {
970 return -1; 963 return -1;
971 } 964 if (!m_pXRefStream->Start())
972 if (!m_pXRefStream->Start()) {
973 return -1; 965 return -1;
974 }
975 return 0; 966 return 0;
976 } 967 }
977 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, 968 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum,
978 const uint8_t* pBuffer, 969 const uint8_t* pBuffer,
979 FX_DWORD dwSize) { 970 FX_DWORD dwSize) {
980 if (!m_pXRefStream) { 971 if (!m_pXRefStream) {
981 return 1; 972 return 1;
982 } 973 }
983 m_pXRefStream->AddObjectNumberToIndexArray(objnum); 974 m_pXRefStream->AddObjectNumberToIndexArray(objnum);
984 int32_t iRet = 975 int32_t iRet =
(...skipping 25 matching lines...) Expand all
1010 } 1001 }
1011 if (!m_pXRefStream->Start()) { 1002 if (!m_pXRefStream->Start()) {
1012 return -1; 1003 return -1;
1013 } 1004 }
1014 return 0; 1005 return 0;
1015 } 1006 }
1016 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, 1007 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream,
1017 FX_DWORD objnum, 1008 FX_DWORD objnum,
1018 CPDF_CryptoHandler* pCrypto) { 1009 CPDF_CryptoHandler* pCrypto) {
1019 CPDF_FlateEncoder encoder; 1010 CPDF_FlateEncoder encoder;
1020 encoder.Initialize((CPDF_Stream*)pStream, 1011 encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()),
1021 pStream == m_pMetadata ? FALSE : m_bCompress); 1012 pStream == m_pMetadata ? FALSE : m_bCompress);
1022 CPDF_Encryptor encryptor; 1013 CPDF_Encryptor encryptor;
1023 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData, 1014 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData,
1024 encoder.m_dwSize)) { 1015 encoder.m_dwSize)) {
1025 return -1; 1016 return -1;
1026 } 1017 }
1027 if ((FX_DWORD)encoder.m_pDict->GetInteger(FX_BSTRC("Length")) != 1018 if ((FX_DWORD)encoder.m_pDict->GetInteger(FX_BSTRC("Length")) !=
1028 encryptor.m_dwSize) { 1019 encryptor.m_dwSize) {
1029 encoder.CloneDict(); 1020 encoder.CloneDict();
1030 encoder.m_pDict->SetAtInteger(FX_BSTRC("Length"), encryptor.m_dwSize); 1021 encoder.m_pDict->SetAtInteger(FX_BSTRC("Length"), encryptor.m_dwSize);
(...skipping 12 matching lines...) Expand all
1043 m_Offset += encryptor.m_dwSize; 1034 m_Offset += encryptor.m_dwSize;
1044 if ((len = m_File.AppendString(FX_BSTRC("\r\nendstream"))) < 0) { 1035 if ((len = m_File.AppendString(FX_BSTRC("\r\nendstream"))) < 0) {
1045 return -1; 1036 return -1;
1046 } 1037 }
1047 m_Offset += len; 1038 m_Offset += len;
1048 return 1; 1039 return 1;
1049 } 1040 }
1050 int32_t CPDF_Creator::WriteIndirectObj(FX_DWORD objnum, 1041 int32_t CPDF_Creator::WriteIndirectObj(FX_DWORD objnum,
1051 const CPDF_Object* pObj) { 1042 const CPDF_Object* pObj) {
1052 int32_t len = m_File.AppendDWord(objnum); 1043 int32_t len = m_File.AppendDWord(objnum);
1053 if (len < 0) { 1044 if (len < 0)
1054 return -1; 1045 return -1;
1055 } 1046
1056 m_Offset += len; 1047 m_Offset += len;
1057 if ((len = m_File.AppendString(FX_BSTRC(" 0 obj\r\n"))) < 0) { 1048 if ((len = m_File.AppendString(FX_BSTRC(" 0 obj\r\n"))) < 0)
1058 return -1; 1049 return -1;
1059 } 1050
1060 m_Offset += len; 1051 m_Offset += len;
1061 if (pObj->GetType() == PDFOBJ_STREAM) { 1052 if (pObj->IsStream()) {
1062 CPDF_CryptoHandler* pHandler = NULL; 1053 CPDF_CryptoHandler* pHandler = nullptr;
1063 pHandler = 1054 pHandler =
1064 (pObj == m_pMetadata && !m_bEncryptMetadata) ? NULL : m_pCryptoHandler; 1055 (pObj == m_pMetadata && !m_bEncryptMetadata) ? NULL : m_pCryptoHandler;
1065 if (WriteStream(pObj, objnum, pHandler) < 0) { 1056 if (WriteStream(pObj, objnum, pHandler) < 0)
1066 return -1; 1057 return -1;
1067 }
1068 } else { 1058 } else {
1069 if (WriteDirectObj(objnum, pObj) < 0) { 1059 if (WriteDirectObj(objnum, pObj) < 0)
1070 return -1; 1060 return -1;
1071 }
1072 } 1061 }
1073 if ((len = m_File.AppendString(FX_BSTRC("\r\nendobj\r\n"))) < 0) { 1062 if ((len = m_File.AppendString(FX_BSTRC("\r\nendobj\r\n"))) < 0)
1074 return -1; 1063 return -1;
1075 } 1064
1076 m_Offset += len; 1065 m_Offset += len;
1077 if (AppendObjectNumberToXRef(objnum) < 0) { 1066 if (AppendObjectNumberToXRef(objnum) < 0)
1078 return -1; 1067 return -1;
1079 }
1080 return 0; 1068 return 0;
1081 } 1069 }
1082 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) { 1070 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) {
1083 int32_t iRet = WriteIndirectObjectToStream(pObj); 1071 int32_t iRet = WriteIndirectObjectToStream(pObj);
1084 if (iRet < 1) { 1072 if (iRet < 1) {
1085 return iRet; 1073 return iRet;
1086 } 1074 }
1087 return WriteIndirectObj(pObj->GetObjNum(), pObj); 1075 return WriteIndirectObj(pObj->GetObjNum(), pObj);
1088 } 1076 }
1089 int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, 1077 int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), 1120 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize),
1133 bHex); 1121 bHex);
1134 if ((len = m_File.AppendString(content)) < 0) { 1122 if ((len = m_File.AppendString(content)) < 0) {
1135 return -1; 1123 return -1;
1136 } 1124 }
1137 m_Offset += len; 1125 m_Offset += len;
1138 break; 1126 break;
1139 } 1127 }
1140 case PDFOBJ_STREAM: { 1128 case PDFOBJ_STREAM: {
1141 CPDF_FlateEncoder encoder; 1129 CPDF_FlateEncoder encoder;
1142 encoder.Initialize((CPDF_Stream*)pObj, m_bCompress); 1130 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()),
1131 m_bCompress);
1143 CPDF_Encryptor encryptor; 1132 CPDF_Encryptor encryptor;
1144 CPDF_CryptoHandler* pHandler = m_pCryptoHandler; 1133 CPDF_CryptoHandler* pHandler = m_pCryptoHandler;
1145 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); 1134 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize);
1146 if ((FX_DWORD)encoder.m_pDict->GetInteger(FX_BSTRC("Length")) != 1135 if ((FX_DWORD)encoder.m_pDict->GetInteger(FX_BSTRC("Length")) !=
1147 encryptor.m_dwSize) { 1136 encryptor.m_dwSize) {
1148 encoder.CloneDict(); 1137 encoder.CloneDict();
1149 encoder.m_pDict->SetAtInteger(FX_BSTRC("Length"), encryptor.m_dwSize); 1138 encoder.m_pDict->SetAtInteger(FX_BSTRC("Length"), encryptor.m_dwSize);
1150 } 1139 }
1151 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { 1140 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) {
1152 return -1; 1141 return -1;
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 m_bNewCrypto = FALSE; 2117 m_bNewCrypto = FALSE;
2129 if (!m_bStandardSecurity) { 2118 if (!m_bStandardSecurity) {
2130 return; 2119 return;
2131 } 2120 }
2132 if (m_pEncryptDict) { 2121 if (m_pEncryptDict) {
2133 m_pEncryptDict->Release(); 2122 m_pEncryptDict->Release();
2134 m_pEncryptDict = NULL; 2123 m_pEncryptDict = NULL;
2135 } 2124 }
2136 m_bStandardSecurity = FALSE; 2125 m_bStandardSecurity = FALSE;
2137 } 2126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698