OLD | NEW |
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return -1; | 103 return -1; |
104 } | 104 } |
105 offset += 1; | 105 offset += 1; |
106 break; | 106 break; |
107 } | 107 } |
108 case PDFOBJ_DICTIONARY: { | 108 case PDFOBJ_DICTIONARY: { |
109 if (pFile->AppendString(FX_BSTRC("<<")) < 0) { | 109 if (pFile->AppendString(FX_BSTRC("<<")) < 0) { |
110 return -1; | 110 return -1; |
111 } | 111 } |
112 offset += 2; | 112 offset += 2; |
113 CPDF_Dictionary* p = (CPDF_Dictionary*)pObj; | 113 const CPDF_Dictionary* p = pObj->AsDictionary(); |
114 FX_POSITION pos = p->GetStartPos(); | 114 FX_POSITION pos = p->GetStartPos(); |
115 while (pos) { | 115 while (pos) { |
116 CFX_ByteString key; | 116 CFX_ByteString key; |
117 CPDF_Object* pValue = p->GetNextElement(pos, key); | 117 CPDF_Object* pValue = p->GetNextElement(pos, key); |
118 if (pFile->AppendString(FX_BSTRC("/")) < 0) { | 118 if (pFile->AppendString(FX_BSTRC("/")) < 0) { |
119 return -1; | 119 return -1; |
120 } | 120 } |
121 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) { | 121 if ((len = pFile->AppendString(PDF_NameEncode(key))) < 0) { |
122 return -1; | 122 return -1; |
123 } | 123 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 }; | 327 }; |
328 CPDF_FlateEncoder::CPDF_FlateEncoder() { | 328 CPDF_FlateEncoder::CPDF_FlateEncoder() { |
329 m_pData = NULL; | 329 m_pData = NULL; |
330 m_dwSize = 0; | 330 m_dwSize = 0; |
331 m_pDict = NULL; | 331 m_pDict = NULL; |
332 m_bCloned = FALSE; | 332 m_bCloned = FALSE; |
333 m_bNewData = FALSE; | 333 m_bNewData = FALSE; |
334 } | 334 } |
335 void CPDF_FlateEncoder::CloneDict() { | 335 void CPDF_FlateEncoder::CloneDict() { |
336 if (!m_bCloned) { | 336 if (!m_bCloned) { |
337 m_pDict = (CPDF_Dictionary*)m_pDict->Clone(); | 337 m_pDict = ToDictionary(m_pDict->Clone()); |
| 338 ASSERT(m_pDict); |
338 m_bCloned = TRUE; | 339 m_bCloned = TRUE; |
339 } | 340 } |
340 } | 341 } |
341 FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream, | 342 FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream, |
342 FX_BOOL bFlateEncode) { | 343 FX_BOOL bFlateEncode) { |
343 m_Acc.LoadAllData(pStream, TRUE); | 344 m_Acc.LoadAllData(pStream, TRUE); |
344 if ((pStream && pStream->GetDict() && | 345 if ((pStream && pStream->GetDict() && |
345 pStream->GetDict()->KeyExist("Filter")) || | 346 pStream->GetDict()->KeyExist("Filter")) || |
346 !bFlateEncode) { | 347 !bFlateEncode) { |
347 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { | 348 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { |
348 CPDF_StreamAcc destAcc; | 349 CPDF_StreamAcc destAcc; |
349 destAcc.LoadAllData(pStream); | 350 destAcc.LoadAllData(pStream); |
350 m_dwSize = destAcc.GetSize(); | 351 m_dwSize = destAcc.GetSize(); |
351 m_pData = (uint8_t*)destAcc.DetachData(); | 352 m_pData = (uint8_t*)destAcc.DetachData(); |
352 m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone(); | 353 m_pDict = ToDictionary(pStream->GetDict()->Clone()); |
353 m_pDict->RemoveAt(FX_BSTRC("Filter")); | 354 m_pDict->RemoveAt(FX_BSTRC("Filter")); |
354 m_bNewData = TRUE; | 355 m_bNewData = TRUE; |
355 m_bCloned = TRUE; | 356 m_bCloned = TRUE; |
356 } else { | 357 } else { |
357 m_pData = (uint8_t*)m_Acc.GetData(); | 358 m_pData = (uint8_t*)m_Acc.GetData(); |
358 m_dwSize = m_Acc.GetSize(); | 359 m_dwSize = m_Acc.GetSize(); |
359 m_pDict = pStream->GetDict(); | 360 m_pDict = pStream->GetDict(); |
360 } | 361 } |
361 return TRUE; | 362 return TRUE; |
362 } | 363 } |
363 m_pData = NULL; | 364 m_pData = NULL; |
364 m_dwSize = 0; | 365 m_dwSize = 0; |
365 m_bNewData = TRUE; | 366 m_bNewData = TRUE; |
366 m_bCloned = TRUE; | 367 m_bCloned = TRUE; |
367 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), m_pData, m_dwSize); | 368 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), m_pData, m_dwSize); |
368 m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone(); | 369 m_pDict = ToDictionary(pStream->GetDict()->Clone()); |
369 m_pDict->SetAtInteger("Length", m_dwSize); | 370 m_pDict->SetAtInteger("Length", m_dwSize); |
370 m_pDict->SetAtName("Filter", "FlateDecode"); | 371 m_pDict->SetAtName("Filter", "FlateDecode"); |
371 m_pDict->RemoveAt("DecodeParms"); | 372 m_pDict->RemoveAt("DecodeParms"); |
372 return TRUE; | 373 return TRUE; |
373 } | 374 } |
374 FX_BOOL CPDF_FlateEncoder::Initialize(const uint8_t* pBuffer, | 375 FX_BOOL CPDF_FlateEncoder::Initialize(const uint8_t* pBuffer, |
375 FX_DWORD size, | 376 FX_DWORD size, |
376 FX_BOOL bFlateEncode, | 377 FX_BOOL bFlateEncode, |
377 FX_BOOL bXRefStream) { | 378 FX_BOOL bXRefStream) { |
378 if (!bFlateEncode) { | 379 if (!bFlateEncode) { |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 break; | 1221 break; |
1221 } | 1222 } |
1222 case PDFOBJ_DICTIONARY: { | 1223 case PDFOBJ_DICTIONARY: { |
1223 if (m_pCryptoHandler == NULL || pObj == m_pEncryptDict) { | 1224 if (m_pCryptoHandler == NULL || pObj == m_pEncryptDict) { |
1224 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); | 1225 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); |
1225 } | 1226 } |
1226 if (m_File.AppendString(FX_BSTRC("<<")) < 0) { | 1227 if (m_File.AppendString(FX_BSTRC("<<")) < 0) { |
1227 return -1; | 1228 return -1; |
1228 } | 1229 } |
1229 m_Offset += 2; | 1230 m_Offset += 2; |
1230 CPDF_Dictionary* p = (CPDF_Dictionary*)pObj; | 1231 const CPDF_Dictionary* p = pObj->AsDictionary(); |
1231 FX_BOOL bSignDict = IsSignatureDict(p); | 1232 FX_BOOL bSignDict = IsSignatureDict(p); |
1232 FX_POSITION pos = p->GetStartPos(); | 1233 FX_POSITION pos = p->GetStartPos(); |
1233 while (pos) { | 1234 while (pos) { |
1234 FX_BOOL bSignValue = FALSE; | 1235 FX_BOOL bSignValue = FALSE; |
1235 CFX_ByteString key; | 1236 CFX_ByteString key; |
1236 CPDF_Object* pValue = p->GetNextElement(pos, key); | 1237 CPDF_Object* pValue = p->GetNextElement(pos, key); |
1237 if (m_File.AppendString(FX_BSTRC("/")) < 0) { | 1238 if (m_File.AppendString(FX_BSTRC("/")) < 0) { |
1238 return -1; | 1239 return -1; |
1239 } | 1240 } |
1240 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) { | 1241 if ((len = m_File.AppendString(PDF_NameEncode(key))) < 0) { |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 m_bNewCrypto = FALSE; | 2127 m_bNewCrypto = FALSE; |
2127 if (!m_bStandardSecurity) { | 2128 if (!m_bStandardSecurity) { |
2128 return; | 2129 return; |
2129 } | 2130 } |
2130 if (m_pEncryptDict) { | 2131 if (m_pEncryptDict) { |
2131 m_pEncryptDict->Release(); | 2132 m_pEncryptDict->Release(); |
2132 m_pEncryptDict = NULL; | 2133 m_pEncryptDict = NULL; |
2133 } | 2134 } |
2134 m_bStandardSecurity = FALSE; | 2135 m_bStandardSecurity = FALSE; |
2135 } | 2136 } |
OLD | NEW |