| 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 "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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 return -1; | 88 return -1; |
| 89 offset += len + 6; | 89 offset += len + 6; |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 case CPDF_Object::ARRAY: { | 92 case CPDF_Object::ARRAY: { |
| 93 if (pFile->AppendString("[") < 0) { | 93 if (pFile->AppendString("[") < 0) { |
| 94 return -1; | 94 return -1; |
| 95 } | 95 } |
| 96 offset += 1; | 96 offset += 1; |
| 97 const CPDF_Array* p = pObj->AsArray(); | 97 const CPDF_Array* p = pObj->AsArray(); |
| 98 for (FX_DWORD i = 0; i < p->GetCount(); i++) { | 98 for (uint32_t i = 0; i < p->GetCount(); i++) { |
| 99 CPDF_Object* pElement = p->GetElement(i); | 99 CPDF_Object* pElement = p->GetElement(i); |
| 100 if (pElement->GetObjNum()) { | 100 if (pElement->GetObjNum()) { |
| 101 if (pFile->AppendString(" ") < 0) { | 101 if (pFile->AppendString(" ") < 0) { |
| 102 return -1; | 102 return -1; |
| 103 } | 103 } |
| 104 if ((len = pFile->AppendDWord(pElement->GetObjNum())) < 0) { | 104 if ((len = pFile->AppendDWord(pElement->GetObjNum())) < 0) { |
| 105 return -1; | 105 return -1; |
| 106 } | 106 } |
| 107 if (pFile->AppendString(" 0 R") < 0) { | 107 if (pFile->AppendString(" 0 R") < 0) { |
| 108 return -1; | 108 return -1; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 271 } |
| 272 offset += 3; | 272 offset += 3; |
| 273 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { | 273 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { |
| 274 return -1; | 274 return -1; |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 return offset; | 277 return offset; |
| 278 } | 278 } |
| 279 | 279 |
| 280 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, | 280 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, |
| 281 FX_DWORD dwObjNum, | 281 uint32_t dwObjNum, |
| 282 CFX_FileBufferArchive* pFile) { | 282 CFX_FileBufferArchive* pFile) { |
| 283 if (!pEncryptDict) { | 283 if (!pEncryptDict) { |
| 284 return 0; | 284 return 0; |
| 285 } | 285 } |
| 286 FXSYS_assert(pFile); | 286 FXSYS_assert(pFile); |
| 287 FX_FILESIZE offset = 0; | 287 FX_FILESIZE offset = 0; |
| 288 int32_t len = 0; | 288 int32_t len = 0; |
| 289 if (pFile->AppendString("/Encrypt") < 0) { | 289 if (pFile->AppendString("/Encrypt") < 0) { |
| 290 return -1; | 290 return -1; |
| 291 } | 291 } |
| 292 offset += 8; | 292 offset += 8; |
| 293 if (pFile->AppendString(" ") < 0) { | 293 if (pFile->AppendString(" ") < 0) { |
| 294 return -1; | 294 return -1; |
| 295 } | 295 } |
| 296 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { | 296 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { |
| 297 return -1; | 297 return -1; |
| 298 } | 298 } |
| 299 if (pFile->AppendString(" 0 R ") < 0) { | 299 if (pFile->AppendString(" 0 R ") < 0) { |
| 300 return -1; | 300 return -1; |
| 301 } | 301 } |
| 302 offset += len + 6; | 302 offset += len + 6; |
| 303 return offset; | 303 return offset; |
| 304 } | 304 } |
| 305 | 305 |
| 306 std::vector<uint8_t> PDF_GenerateFileID(FX_DWORD dwSeed1, FX_DWORD dwSeed2) { | 306 std::vector<uint8_t> PDF_GenerateFileID(uint32_t dwSeed1, uint32_t dwSeed2) { |
| 307 std::vector<uint8_t> buffer(sizeof(FX_DWORD) * 4); | 307 std::vector<uint8_t> buffer(sizeof(uint32_t) * 4); |
| 308 FX_DWORD* pBuffer = reinterpret_cast<FX_DWORD*>(buffer.data()); | 308 uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer.data()); |
| 309 void* pContext = FX_Random_MT_Start(dwSeed1); | 309 void* pContext = FX_Random_MT_Start(dwSeed1); |
| 310 for (int i = 0; i < 2; ++i) | 310 for (int i = 0; i < 2; ++i) |
| 311 *pBuffer++ = FX_Random_MT_Generate(pContext); | 311 *pBuffer++ = FX_Random_MT_Generate(pContext); |
| 312 FX_Random_MT_Close(pContext); | 312 FX_Random_MT_Close(pContext); |
| 313 pContext = FX_Random_MT_Start(dwSeed2); | 313 pContext = FX_Random_MT_Start(dwSeed2); |
| 314 for (int i = 0; i < 2; ++i) | 314 for (int i = 0; i < 2; ++i) |
| 315 *pBuffer++ = FX_Random_MT_Generate(pContext); | 315 *pBuffer++ = FX_Random_MT_Generate(pContext); |
| 316 FX_Random_MT_Close(pContext); | 316 FX_Random_MT_Close(pContext); |
| 317 return buffer; | 317 return buffer; |
| 318 } | 318 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 331 void AppendIndex1(CFX_ByteTextBuf& buffer, FX_FILESIZE offset) { | 331 void AppendIndex1(CFX_ByteTextBuf& buffer, FX_FILESIZE offset) { |
| 332 buffer.AppendByte(1); | 332 buffer.AppendByte(1); |
| 333 buffer.AppendByte(FX_GETBYTEOFFSET24(offset)); | 333 buffer.AppendByte(FX_GETBYTEOFFSET24(offset)); |
| 334 buffer.AppendByte(FX_GETBYTEOFFSET16(offset)); | 334 buffer.AppendByte(FX_GETBYTEOFFSET16(offset)); |
| 335 buffer.AppendByte(FX_GETBYTEOFFSET8(offset)); | 335 buffer.AppendByte(FX_GETBYTEOFFSET8(offset)); |
| 336 buffer.AppendByte(FX_GETBYTEOFFSET0(offset)); | 336 buffer.AppendByte(FX_GETBYTEOFFSET0(offset)); |
| 337 buffer.AppendByte(0); | 337 buffer.AppendByte(0); |
| 338 buffer.AppendByte(0); | 338 buffer.AppendByte(0); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void AppendIndex2(CFX_ByteTextBuf& buffer, FX_DWORD objnum, int32_t index) { | 341 void AppendIndex2(CFX_ByteTextBuf& buffer, uint32_t objnum, int32_t index) { |
| 342 buffer.AppendByte(2); | 342 buffer.AppendByte(2); |
| 343 buffer.AppendByte(FX_GETBYTEOFFSET24(objnum)); | 343 buffer.AppendByte(FX_GETBYTEOFFSET24(objnum)); |
| 344 buffer.AppendByte(FX_GETBYTEOFFSET16(objnum)); | 344 buffer.AppendByte(FX_GETBYTEOFFSET16(objnum)); |
| 345 buffer.AppendByte(FX_GETBYTEOFFSET8(objnum)); | 345 buffer.AppendByte(FX_GETBYTEOFFSET8(objnum)); |
| 346 buffer.AppendByte(FX_GETBYTEOFFSET0(objnum)); | 346 buffer.AppendByte(FX_GETBYTEOFFSET0(objnum)); |
| 347 buffer.AppendByte(FX_GETBYTEOFFSET8(index)); | 347 buffer.AppendByte(FX_GETBYTEOFFSET8(index)); |
| 348 buffer.AppendByte(FX_GETBYTEOFFSET0(index)); | 348 buffer.AppendByte(FX_GETBYTEOFFSET0(index)); |
| 349 } | 349 } |
| 350 | 350 |
| 351 bool IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) { | 351 bool IsXRefNeedEnd(CPDF_XRefStream* pXRef, uint32_t flag) { |
| 352 if (!(flag & FPDFCREATE_INCREMENTAL)) | 352 if (!(flag & FPDFCREATE_INCREMENTAL)) |
| 353 return false; | 353 return false; |
| 354 | 354 |
| 355 FX_DWORD iCount = 0; | 355 uint32_t iCount = 0; |
| 356 for (const auto& pair : pXRef->m_IndexArray) | 356 for (const auto& pair : pXRef->m_IndexArray) |
| 357 iCount += pair.count; | 357 iCount += pair.count; |
| 358 | 358 |
| 359 return iCount >= PDF_XREFSTREAM_MAXSIZE; | 359 return iCount >= PDF_XREFSTREAM_MAXSIZE; |
| 360 } | 360 } |
| 361 | 361 |
| 362 int32_t OutputIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { | 362 int32_t OutputIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { |
| 363 if (sizeof(offset) > 4) { | 363 if (sizeof(offset) > 4) { |
| 364 if (FX_GETBYTEOFFSET32(offset)) { | 364 if (FX_GETBYTEOFFSET32(offset)) { |
| 365 if (pFile->AppendByte(FX_GETBYTEOFFSET56(offset)) < 0) | 365 if (pFile->AppendByte(FX_GETBYTEOFFSET56(offset)) < 0) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 384 return -1; | 384 return -1; |
| 385 return 0; | 385 return 0; |
| 386 } | 386 } |
| 387 | 387 |
| 388 class CPDF_FlateEncoder { | 388 class CPDF_FlateEncoder { |
| 389 public: | 389 public: |
| 390 CPDF_FlateEncoder(); | 390 CPDF_FlateEncoder(); |
| 391 ~CPDF_FlateEncoder(); | 391 ~CPDF_FlateEncoder(); |
| 392 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); | 392 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); |
| 393 FX_BOOL Initialize(const uint8_t* pBuffer, | 393 FX_BOOL Initialize(const uint8_t* pBuffer, |
| 394 FX_DWORD size, | 394 uint32_t size, |
| 395 FX_BOOL bFlateEncode, | 395 FX_BOOL bFlateEncode, |
| 396 FX_BOOL bXRefStream = FALSE); | 396 FX_BOOL bXRefStream = FALSE); |
| 397 void CloneDict(); | 397 void CloneDict(); |
| 398 uint8_t* m_pData; | 398 uint8_t* m_pData; |
| 399 FX_DWORD m_dwSize; | 399 uint32_t m_dwSize; |
| 400 CPDF_Dictionary* m_pDict; | 400 CPDF_Dictionary* m_pDict; |
| 401 FX_BOOL m_bCloned; | 401 FX_BOOL m_bCloned; |
| 402 FX_BOOL m_bNewData; | 402 FX_BOOL m_bNewData; |
| 403 CPDF_StreamAcc m_Acc; | 403 CPDF_StreamAcc m_Acc; |
| 404 }; | 404 }; |
| 405 CPDF_FlateEncoder::CPDF_FlateEncoder() { | 405 CPDF_FlateEncoder::CPDF_FlateEncoder() { |
| 406 m_pData = NULL; | 406 m_pData = NULL; |
| 407 m_dwSize = 0; | 407 m_dwSize = 0; |
| 408 m_pDict = NULL; | 408 m_pDict = NULL; |
| 409 m_bCloned = FALSE; | 409 m_bCloned = FALSE; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 m_bNewData = TRUE; | 443 m_bNewData = TRUE; |
| 444 m_bCloned = TRUE; | 444 m_bCloned = TRUE; |
| 445 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), m_pData, m_dwSize); | 445 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), m_pData, m_dwSize); |
| 446 m_pDict = ToDictionary(pStream->GetDict()->Clone()); | 446 m_pDict = ToDictionary(pStream->GetDict()->Clone()); |
| 447 m_pDict->SetAtInteger("Length", m_dwSize); | 447 m_pDict->SetAtInteger("Length", m_dwSize); |
| 448 m_pDict->SetAtName("Filter", "FlateDecode"); | 448 m_pDict->SetAtName("Filter", "FlateDecode"); |
| 449 m_pDict->RemoveAt("DecodeParms"); | 449 m_pDict->RemoveAt("DecodeParms"); |
| 450 return TRUE; | 450 return TRUE; |
| 451 } | 451 } |
| 452 FX_BOOL CPDF_FlateEncoder::Initialize(const uint8_t* pBuffer, | 452 FX_BOOL CPDF_FlateEncoder::Initialize(const uint8_t* pBuffer, |
| 453 FX_DWORD size, | 453 uint32_t size, |
| 454 FX_BOOL bFlateEncode, | 454 FX_BOOL bFlateEncode, |
| 455 FX_BOOL bXRefStream) { | 455 FX_BOOL bXRefStream) { |
| 456 if (!bFlateEncode) { | 456 if (!bFlateEncode) { |
| 457 m_pData = (uint8_t*)pBuffer; | 457 m_pData = (uint8_t*)pBuffer; |
| 458 m_dwSize = size; | 458 m_dwSize = size; |
| 459 return TRUE; | 459 return TRUE; |
| 460 } | 460 } |
| 461 m_bNewData = TRUE; | 461 m_bNewData = TRUE; |
| 462 if (bXRefStream) { | 462 if (bXRefStream) { |
| 463 ::FlateEncode(pBuffer, size, 12, 1, 8, 7, m_pData, m_dwSize); | 463 ::FlateEncode(pBuffer, size, 12, 1, 8, 7, m_pData, m_dwSize); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 474 FX_Free(m_pData); | 474 FX_Free(m_pData); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 class CPDF_Encryptor { | 477 class CPDF_Encryptor { |
| 478 public: | 478 public: |
| 479 CPDF_Encryptor(); | 479 CPDF_Encryptor(); |
| 480 ~CPDF_Encryptor(); | 480 ~CPDF_Encryptor(); |
| 481 FX_BOOL Initialize(IPDF_CryptoHandler* pHandler, | 481 FX_BOOL Initialize(IPDF_CryptoHandler* pHandler, |
| 482 int objnum, | 482 int objnum, |
| 483 uint8_t* src_data, | 483 uint8_t* src_data, |
| 484 FX_DWORD src_size); | 484 uint32_t src_size); |
| 485 uint8_t* m_pData; | 485 uint8_t* m_pData; |
| 486 FX_DWORD m_dwSize; | 486 uint32_t m_dwSize; |
| 487 FX_BOOL m_bNewBuf; | 487 FX_BOOL m_bNewBuf; |
| 488 }; | 488 }; |
| 489 CPDF_Encryptor::CPDF_Encryptor() { | 489 CPDF_Encryptor::CPDF_Encryptor() { |
| 490 m_pData = NULL; | 490 m_pData = NULL; |
| 491 m_dwSize = 0; | 491 m_dwSize = 0; |
| 492 m_bNewBuf = FALSE; | 492 m_bNewBuf = FALSE; |
| 493 } | 493 } |
| 494 FX_BOOL CPDF_Encryptor::Initialize(IPDF_CryptoHandler* pHandler, | 494 FX_BOOL CPDF_Encryptor::Initialize(IPDF_CryptoHandler* pHandler, |
| 495 int objnum, | 495 int objnum, |
| 496 uint8_t* src_data, | 496 uint8_t* src_data, |
| 497 FX_DWORD src_size) { | 497 uint32_t src_size) { |
| 498 if (src_size == 0) { | 498 if (src_size == 0) { |
| 499 return TRUE; | 499 return TRUE; |
| 500 } | 500 } |
| 501 if (!pHandler) { | 501 if (!pHandler) { |
| 502 m_pData = (uint8_t*)src_data; | 502 m_pData = (uint8_t*)src_data; |
| 503 m_dwSize = src_size; | 503 m_dwSize = src_size; |
| 504 m_bNewBuf = FALSE; | 504 m_bNewBuf = FALSE; |
| 505 return TRUE; | 505 return TRUE; |
| 506 } | 506 } |
| 507 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); | 507 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 520 | 520 |
| 521 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} | 521 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} |
| 522 FX_BOOL CPDF_ObjectStream::Start() { | 522 FX_BOOL CPDF_ObjectStream::Start() { |
| 523 m_ObjNumArray.RemoveAll(); | 523 m_ObjNumArray.RemoveAll(); |
| 524 m_OffsetArray.RemoveAll(); | 524 m_OffsetArray.RemoveAll(); |
| 525 m_Buffer.Clear(); | 525 m_Buffer.Clear(); |
| 526 m_dwObjNum = 0; | 526 m_dwObjNum = 0; |
| 527 m_index = 0; | 527 m_index = 0; |
| 528 return TRUE; | 528 return TRUE; |
| 529 } | 529 } |
| 530 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, | 530 int32_t CPDF_ObjectStream::CompressIndirectObject(uint32_t dwObjNum, |
| 531 const CPDF_Object* pObj) { | 531 const CPDF_Object* pObj) { |
| 532 m_ObjNumArray.Add(dwObjNum); | 532 m_ObjNumArray.Add(dwObjNum); |
| 533 m_OffsetArray.Add(m_Buffer.GetLength()); | 533 m_OffsetArray.Add(m_Buffer.GetLength()); |
| 534 m_Buffer << pObj; | 534 m_Buffer << pObj; |
| 535 return 1; | 535 return 1; |
| 536 } | 536 } |
| 537 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, | 537 int32_t CPDF_ObjectStream::CompressIndirectObject(uint32_t dwObjNum, |
| 538 const uint8_t* pBuffer, | 538 const uint8_t* pBuffer, |
| 539 FX_DWORD dwSize) { | 539 uint32_t dwSize) { |
| 540 m_ObjNumArray.Add(dwObjNum); | 540 m_ObjNumArray.Add(dwObjNum); |
| 541 m_OffsetArray.Add(m_Buffer.GetLength()); | 541 m_OffsetArray.Add(m_Buffer.GetLength()); |
| 542 m_Buffer.AppendBlock(pBuffer, dwSize); | 542 m_Buffer.AppendBlock(pBuffer, dwSize); |
| 543 return 1; | 543 return 1; |
| 544 } | 544 } |
| 545 FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) { | 545 FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) { |
| 546 FXSYS_assert(pCreator); | 546 FXSYS_assert(pCreator); |
| 547 if (m_ObjNumArray.GetSize() == 0) { | 547 if (m_ObjNumArray.GetSize() == 0) { |
| 548 return 0; | 548 return 0; |
| 549 } | 549 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 562 FX_FILESIZE& offset = pCreator->m_Offset; | 562 FX_FILESIZE& offset = pCreator->m_Offset; |
| 563 int32_t len = pFile->AppendDWord(m_dwObjNum); | 563 int32_t len = pFile->AppendDWord(m_dwObjNum); |
| 564 if (len < 0) { | 564 if (len < 0) { |
| 565 return -1; | 565 return -1; |
| 566 } | 566 } |
| 567 offset += len; | 567 offset += len; |
| 568 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /ObjStm /N ")) < 0) { | 568 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /ObjStm /N ")) < 0) { |
| 569 return -1; | 569 return -1; |
| 570 } | 570 } |
| 571 offset += len; | 571 offset += len; |
| 572 if ((len = pFile->AppendDWord((FX_DWORD)iCount)) < 0) { | 572 if ((len = pFile->AppendDWord((uint32_t)iCount)) < 0) { |
| 573 return -1; | 573 return -1; |
| 574 } | 574 } |
| 575 offset += len; | 575 offset += len; |
| 576 if (pFile->AppendString("/First ") < 0) { | 576 if (pFile->AppendString("/First ") < 0) { |
| 577 return -1; | 577 return -1; |
| 578 } | 578 } |
| 579 if ((len = pFile->AppendDWord((FX_DWORD)tempBuffer.GetLength())) < 0) { | 579 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { |
| 580 return -1; | 580 return -1; |
| 581 } | 581 } |
| 582 if (pFile->AppendString("/Length ") < 0) { | 582 if (pFile->AppendString("/Length ") < 0) { |
| 583 return -1; | 583 return -1; |
| 584 } | 584 } |
| 585 offset += len + 15; | 585 offset += len + 15; |
| 586 if (!pCreator->m_bCompress && !pHandler) { | 586 if (!pCreator->m_bCompress && !pHandler) { |
| 587 if ((len = pFile->AppendDWord( | 587 if ((len = pFile->AppendDWord( |
| 588 (FX_DWORD)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { | 588 (uint32_t)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { |
| 589 return -1; | 589 return -1; |
| 590 } | 590 } |
| 591 offset += len; | 591 offset += len; |
| 592 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 592 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
| 593 return -1; | 593 return -1; |
| 594 } | 594 } |
| 595 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < | 595 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < |
| 596 0) { | 596 0) { |
| 597 return -1; | 597 return -1; |
| 598 } | 598 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return ObjOffset; | 633 return ObjOffset; |
| 634 } | 634 } |
| 635 CPDF_XRefStream::CPDF_XRefStream() | 635 CPDF_XRefStream::CPDF_XRefStream() |
| 636 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} | 636 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} |
| 637 FX_BOOL CPDF_XRefStream::Start() { | 637 FX_BOOL CPDF_XRefStream::Start() { |
| 638 m_IndexArray.clear(); | 638 m_IndexArray.clear(); |
| 639 m_Buffer.Clear(); | 639 m_Buffer.Clear(); |
| 640 m_iSeg = 0; | 640 m_iSeg = 0; |
| 641 return TRUE; | 641 return TRUE; |
| 642 } | 642 } |
| 643 int32_t CPDF_XRefStream::CompressIndirectObject(FX_DWORD dwObjNum, | 643 int32_t CPDF_XRefStream::CompressIndirectObject(uint32_t dwObjNum, |
| 644 const CPDF_Object* pObj, | 644 const CPDF_Object* pObj, |
| 645 CPDF_Creator* pCreator) { | 645 CPDF_Creator* pCreator) { |
| 646 if (!pCreator) { | 646 if (!pCreator) { |
| 647 return 0; | 647 return 0; |
| 648 } | 648 } |
| 649 m_ObjStream.CompressIndirectObject(dwObjNum, pObj); | 649 m_ObjStream.CompressIndirectObject(dwObjNum, pObj); |
| 650 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && | 650 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && |
| 651 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { | 651 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { |
| 652 return 1; | 652 return 1; |
| 653 } | 653 } |
| 654 return EndObjectStream(pCreator); | 654 return EndObjectStream(pCreator); |
| 655 } | 655 } |
| 656 int32_t CPDF_XRefStream::CompressIndirectObject(FX_DWORD dwObjNum, | 656 int32_t CPDF_XRefStream::CompressIndirectObject(uint32_t dwObjNum, |
| 657 const uint8_t* pBuffer, | 657 const uint8_t* pBuffer, |
| 658 FX_DWORD dwSize, | 658 uint32_t dwSize, |
| 659 CPDF_Creator* pCreator) { | 659 CPDF_Creator* pCreator) { |
| 660 if (!pCreator) { | 660 if (!pCreator) { |
| 661 return 0; | 661 return 0; |
| 662 } | 662 } |
| 663 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); | 663 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); |
| 664 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && | 664 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && |
| 665 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { | 665 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { |
| 666 return 1; | 666 return 1; |
| 667 } | 667 } |
| 668 return EndObjectStream(pCreator); | 668 return EndObjectStream(pCreator); |
| 669 } | 669 } |
| 670 | 670 |
| 671 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { | 671 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 672 FX_FILESIZE objOffset = 0; | 672 FX_FILESIZE objOffset = 0; |
| 673 if (bEOF) { | 673 if (bEOF) { |
| 674 objOffset = m_ObjStream.End(pCreator); | 674 objOffset = m_ObjStream.End(pCreator); |
| 675 if (objOffset < 0) { | 675 if (objOffset < 0) { |
| 676 return -1; | 676 return -1; |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 FX_DWORD& dwObjStmNum = m_ObjStream.m_dwObjNum; | 679 uint32_t& dwObjStmNum = m_ObjStream.m_dwObjNum; |
| 680 if (!dwObjStmNum) { | 680 if (!dwObjStmNum) { |
| 681 dwObjStmNum = ++pCreator->m_dwLastObjNum; | 681 dwObjStmNum = ++pCreator->m_dwLastObjNum; |
| 682 } | 682 } |
| 683 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); | 683 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); |
| 684 size_t iSeg = m_IndexArray.size(); | 684 size_t iSeg = m_IndexArray.size(); |
| 685 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 685 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 686 if (m_dwTempObjNum == 0) { | 686 if (m_dwTempObjNum == 0) { |
| 687 AppendIndex0(m_Buffer, true); | 687 AppendIndex0(m_Buffer, true); |
| 688 m_dwTempObjNum++; | 688 m_dwTempObjNum++; |
| 689 } | 689 } |
| 690 FX_DWORD end_num = m_IndexArray.back().objnum + m_IndexArray.back().count; | 690 uint32_t end_num = m_IndexArray.back().objnum + m_IndexArray.back().count; |
| 691 int index = 0; | 691 int index = 0; |
| 692 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { | 692 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { |
| 693 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 693 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 694 if (offset) { | 694 if (offset) { |
| 695 if (index >= iSize || | 695 if (index >= iSize || |
| 696 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { | 696 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { |
| 697 AppendIndex1(m_Buffer, *offset); | 697 AppendIndex1(m_Buffer, *offset); |
| 698 } else { | 698 } else { |
| 699 AppendIndex2(m_Buffer, dwObjStmNum, index++); | 699 AppendIndex2(m_Buffer, dwObjStmNum, index++); |
| 700 } | 700 } |
| 701 } else { | 701 } else { |
| 702 AppendIndex0(m_Buffer, false); | 702 AppendIndex0(m_Buffer, false); |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 if (iSize > 0 && bEOF) { | 705 if (iSize > 0 && bEOF) { |
| 706 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); | 706 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); |
| 707 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; | 707 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; |
| 708 } | 708 } |
| 709 m_iSeg = iSeg; | 709 m_iSeg = iSeg; |
| 710 if (bEOF) { | 710 if (bEOF) { |
| 711 m_ObjStream.Start(); | 711 m_ObjStream.Start(); |
| 712 } | 712 } |
| 713 return 1; | 713 return 1; |
| 714 } | 714 } |
| 715 for (auto it = m_IndexArray.begin() + m_iSeg; it != m_IndexArray.end(); | 715 for (auto it = m_IndexArray.begin() + m_iSeg; it != m_IndexArray.end(); |
| 716 ++it) { | 716 ++it) { |
| 717 for (FX_DWORD m = it->objnum; m < it->objnum + it->count; ++m) { | 717 for (uint32_t m = it->objnum; m < it->objnum + it->count; ++m) { |
| 718 if (m_ObjStream.m_index >= iSize || | 718 if (m_ObjStream.m_index >= iSize || |
| 719 m != m_ObjStream.m_ObjNumArray.ElementAt(it - m_IndexArray.begin())) { | 719 m != m_ObjStream.m_ObjNumArray.ElementAt(it - m_IndexArray.begin())) { |
| 720 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); | 720 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); |
| 721 } else { | 721 } else { |
| 722 AppendIndex2(m_Buffer, dwObjStmNum, m_ObjStream.m_index++); | 722 AppendIndex2(m_Buffer, dwObjStmNum, m_ObjStream.m_index++); |
| 723 } | 723 } |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 if (iSize > 0 && bEOF) { | 726 if (iSize > 0 && bEOF) { |
| 727 AppendIndex1(m_Buffer, objOffset); | 727 AppendIndex1(m_Buffer, objOffset); |
| 728 m_IndexArray.push_back({dwObjStmNum, 1}); | 728 m_IndexArray.push_back({dwObjStmNum, 1}); |
| 729 iSeg += 1; | 729 iSeg += 1; |
| 730 } | 730 } |
| 731 m_iSeg = iSeg; | 731 m_iSeg = iSeg; |
| 732 if (bEOF) { | 732 if (bEOF) { |
| 733 m_ObjStream.Start(); | 733 m_ObjStream.Start(); |
| 734 } | 734 } |
| 735 return 1; | 735 return 1; |
| 736 } | 736 } |
| 737 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, | 737 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, |
| 738 FX_BOOL bEOF) { | 738 FX_BOOL bEOF) { |
| 739 FX_FILESIZE offset_tmp = pCreator->m_Offset; | 739 FX_FILESIZE offset_tmp = pCreator->m_Offset; |
| 740 FX_DWORD objnum = ++pCreator->m_dwLastObjNum; | 740 uint32_t objnum = ++pCreator->m_dwLastObjNum; |
| 741 CFX_FileBufferArchive* pFile = &pCreator->m_File; | 741 CFX_FileBufferArchive* pFile = &pCreator->m_File; |
| 742 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; | 742 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; |
| 743 if (bIncremental) { | 743 if (bIncremental) { |
| 744 AddObjectNumberToIndexArray(objnum); | 744 AddObjectNumberToIndexArray(objnum); |
| 745 } else { | 745 } else { |
| 746 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { | 746 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { |
| 747 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 747 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 748 if (offset) { | 748 if (offset) { |
| 749 AppendIndex1(m_Buffer, *offset); | 749 AppendIndex1(m_Buffer, *offset); |
| 750 } else { | 750 } else { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 839 } |
| 840 offset += len + 8; | 840 offset += len + 8; |
| 841 if (bEOF) { | 841 if (bEOF) { |
| 842 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, | 842 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, |
| 843 pCreator->m_pIDArray, | 843 pCreator->m_pIDArray, |
| 844 pCreator->m_bCompress)) < 0) { | 844 pCreator->m_bCompress)) < 0) { |
| 845 return FALSE; | 845 return FALSE; |
| 846 } | 846 } |
| 847 offset += len; | 847 offset += len; |
| 848 if (pCreator->m_pEncryptDict) { | 848 if (pCreator->m_pEncryptDict) { |
| 849 FX_DWORD dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); | 849 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); |
| 850 if (dwEncryptObjNum == 0) { | 850 if (dwEncryptObjNum == 0) { |
| 851 dwEncryptObjNum = pCreator->m_dwEnryptObjNum; | 851 dwEncryptObjNum = pCreator->m_dwEnryptObjNum; |
| 852 } | 852 } |
| 853 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, | 853 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, |
| 854 dwEncryptObjNum, pFile)) < 0) { | 854 dwEncryptObjNum, pFile)) < 0) { |
| 855 return FALSE; | 855 return FALSE; |
| 856 } | 856 } |
| 857 offset += len; | 857 offset += len; |
| 858 } | 858 } |
| 859 } | 859 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 873 } | 873 } |
| 874 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { | 874 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 875 if (EndObjectStream(pCreator, bEOF) < 0) { | 875 if (EndObjectStream(pCreator, bEOF) < 0) { |
| 876 return FALSE; | 876 return FALSE; |
| 877 } | 877 } |
| 878 return GenerateXRefStream(pCreator, bEOF); | 878 return GenerateXRefStream(pCreator, bEOF); |
| 879 } | 879 } |
| 880 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { | 880 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { |
| 881 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 881 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 882 AppendIndex0(m_Buffer, true); | 882 AppendIndex0(m_Buffer, true); |
| 883 for (FX_DWORD i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { | 883 for (uint32_t i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { |
| 884 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); | 884 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); |
| 885 if (offset) { | 885 if (offset) { |
| 886 AppendIndex1(m_Buffer, *offset); | 886 AppendIndex1(m_Buffer, *offset); |
| 887 } else { | 887 } else { |
| 888 AppendIndex0(m_Buffer, false); | 888 AppendIndex0(m_Buffer, false); |
| 889 } | 889 } |
| 890 } | 890 } |
| 891 } else { | 891 } else { |
| 892 for (const auto& pair : m_IndexArray) { | 892 for (const auto& pair : m_IndexArray) { |
| 893 for (FX_DWORD j = pair.objnum; j < pair.objnum + pair.count; ++j) | 893 for (uint32_t j = pair.objnum; j < pair.objnum + pair.count; ++j) |
| 894 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); | 894 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); |
| 895 } | 895 } |
| 896 } | 896 } |
| 897 return GenerateXRefStream(pCreator, FALSE); | 897 return GenerateXRefStream(pCreator, FALSE); |
| 898 } | 898 } |
| 899 void CPDF_XRefStream::AddObjectNumberToIndexArray(FX_DWORD objnum) { | 899 void CPDF_XRefStream::AddObjectNumberToIndexArray(uint32_t objnum) { |
| 900 if (m_IndexArray.empty()) { | 900 if (m_IndexArray.empty()) { |
| 901 m_IndexArray.push_back({objnum, 1}); | 901 m_IndexArray.push_back({objnum, 1}); |
| 902 return; | 902 return; |
| 903 } | 903 } |
| 904 FX_DWORD next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; | 904 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; |
| 905 if (objnum == next_objnum) | 905 if (objnum == next_objnum) |
| 906 m_IndexArray.back().count += 1; | 906 m_IndexArray.back().count += 1; |
| 907 else | 907 else |
| 908 m_IndexArray.push_back({objnum, 1}); | 908 m_IndexArray.push_back({objnum, 1}); |
| 909 } | 909 } |
| 910 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) { | 910 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) { |
| 911 m_pDocument = pDoc; | 911 m_pDocument = pDoc; |
| 912 m_pParser = (CPDF_Parser*)pDoc->m_pParser; | 912 m_pParser = (CPDF_Parser*)pDoc->m_pParser; |
| 913 m_bCompress = TRUE; | 913 m_bCompress = TRUE; |
| 914 if (m_pParser) { | 914 if (m_pParser) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 942 m_pEncryptDict->Release(); | 942 m_pEncryptDict->Release(); |
| 943 m_pEncryptDict = NULL; | 943 m_pEncryptDict = NULL; |
| 944 } | 944 } |
| 945 Clear(); | 945 Clear(); |
| 946 } | 946 } |
| 947 | 947 |
| 948 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 948 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
| 949 if (!m_pXRefStream) | 949 if (!m_pXRefStream) |
| 950 return 1; | 950 return 1; |
| 951 | 951 |
| 952 FX_DWORD objnum = pObj->GetObjNum(); | 952 uint32_t objnum = pObj->GetObjNum(); |
| 953 if (m_pParser && m_pParser->GetObjectGenNum(objnum) > 0) | 953 if (m_pParser && m_pParser->GetObjectGenNum(objnum) > 0) |
| 954 return 1; | 954 return 1; |
| 955 | 955 |
| 956 if (pObj->IsNumber()) | 956 if (pObj->IsNumber()) |
| 957 return 1; | 957 return 1; |
| 958 | 958 |
| 959 CPDF_Dictionary* pDict = pObj->GetDict(); | 959 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 960 if (pObj->IsStream()) { | 960 if (pObj->IsStream()) { |
| 961 if (pDict && pDict->GetStringBy("Type") == "XRef") | 961 if (pDict && pDict->GetStringBy("Type") == "XRef") |
| 962 return 0; | 962 return 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 976 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 976 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
| 977 return -1; | 977 return -1; |
| 978 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 978 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) |
| 979 return 0; | 979 return 0; |
| 980 if (!m_pXRefStream->End(this)) | 980 if (!m_pXRefStream->End(this)) |
| 981 return -1; | 981 return -1; |
| 982 if (!m_pXRefStream->Start()) | 982 if (!m_pXRefStream->Start()) |
| 983 return -1; | 983 return -1; |
| 984 return 0; | 984 return 0; |
| 985 } | 985 } |
| 986 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, | 986 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, |
| 987 const uint8_t* pBuffer, | 987 const uint8_t* pBuffer, |
| 988 FX_DWORD dwSize) { | 988 uint32_t dwSize) { |
| 989 if (!m_pXRefStream) { | 989 if (!m_pXRefStream) { |
| 990 return 1; | 990 return 1; |
| 991 } | 991 } |
| 992 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 992 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 993 int32_t iRet = | 993 int32_t iRet = |
| 994 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 994 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
| 995 if (iRet < 1) { | 995 if (iRet < 1) { |
| 996 return iRet; | 996 return iRet; |
| 997 } | 997 } |
| 998 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 998 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 999 return 0; | 999 return 0; |
| 1000 } | 1000 } |
| 1001 if (!m_pXRefStream->End(this)) { | 1001 if (!m_pXRefStream->End(this)) { |
| 1002 return -1; | 1002 return -1; |
| 1003 } | 1003 } |
| 1004 if (!m_pXRefStream->Start()) { | 1004 if (!m_pXRefStream->Start()) { |
| 1005 return -1; | 1005 return -1; |
| 1006 } | 1006 } |
| 1007 return 0; | 1007 return 0; |
| 1008 } | 1008 } |
| 1009 int32_t CPDF_Creator::AppendObjectNumberToXRef(FX_DWORD objnum) { | 1009 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { |
| 1010 if (!m_pXRefStream) { | 1010 if (!m_pXRefStream) { |
| 1011 return 1; | 1011 return 1; |
| 1012 } | 1012 } |
| 1013 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 1013 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 1014 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 1014 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 1015 return 0; | 1015 return 0; |
| 1016 } | 1016 } |
| 1017 if (!m_pXRefStream->End(this)) { | 1017 if (!m_pXRefStream->End(this)) { |
| 1018 return -1; | 1018 return -1; |
| 1019 } | 1019 } |
| 1020 if (!m_pXRefStream->Start()) { | 1020 if (!m_pXRefStream->Start()) { |
| 1021 return -1; | 1021 return -1; |
| 1022 } | 1022 } |
| 1023 return 0; | 1023 return 0; |
| 1024 } | 1024 } |
| 1025 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, | 1025 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, |
| 1026 FX_DWORD objnum, | 1026 uint32_t objnum, |
| 1027 IPDF_CryptoHandler* pCrypto) { | 1027 IPDF_CryptoHandler* pCrypto) { |
| 1028 CPDF_FlateEncoder encoder; | 1028 CPDF_FlateEncoder encoder; |
| 1029 encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()), | 1029 encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()), |
| 1030 pStream == m_pMetadata ? FALSE : m_bCompress); | 1030 pStream == m_pMetadata ? FALSE : m_bCompress); |
| 1031 CPDF_Encryptor encryptor; | 1031 CPDF_Encryptor encryptor; |
| 1032 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData, | 1032 if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData, |
| 1033 encoder.m_dwSize)) { | 1033 encoder.m_dwSize)) { |
| 1034 return -1; | 1034 return -1; |
| 1035 } | 1035 } |
| 1036 if ((FX_DWORD)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { | 1036 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { |
| 1037 encoder.CloneDict(); | 1037 encoder.CloneDict(); |
| 1038 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1038 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
| 1039 } | 1039 } |
| 1040 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1040 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
| 1041 return -1; | 1041 return -1; |
| 1042 } | 1042 } |
| 1043 int len = m_File.AppendString("stream\r\n"); | 1043 int len = m_File.AppendString("stream\r\n"); |
| 1044 if (len < 0) { | 1044 if (len < 0) { |
| 1045 return -1; | 1045 return -1; |
| 1046 } | 1046 } |
| 1047 m_Offset += len; | 1047 m_Offset += len; |
| 1048 if (m_File.AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { | 1048 if (m_File.AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { |
| 1049 return -1; | 1049 return -1; |
| 1050 } | 1050 } |
| 1051 m_Offset += encryptor.m_dwSize; | 1051 m_Offset += encryptor.m_dwSize; |
| 1052 if ((len = m_File.AppendString("\r\nendstream")) < 0) { | 1052 if ((len = m_File.AppendString("\r\nendstream")) < 0) { |
| 1053 return -1; | 1053 return -1; |
| 1054 } | 1054 } |
| 1055 m_Offset += len; | 1055 m_Offset += len; |
| 1056 return 1; | 1056 return 1; |
| 1057 } | 1057 } |
| 1058 int32_t CPDF_Creator::WriteIndirectObj(FX_DWORD objnum, | 1058 int32_t CPDF_Creator::WriteIndirectObj(uint32_t objnum, |
| 1059 const CPDF_Object* pObj) { | 1059 const CPDF_Object* pObj) { |
| 1060 int32_t len = m_File.AppendDWord(objnum); | 1060 int32_t len = m_File.AppendDWord(objnum); |
| 1061 if (len < 0) | 1061 if (len < 0) |
| 1062 return -1; | 1062 return -1; |
| 1063 | 1063 |
| 1064 m_Offset += len; | 1064 m_Offset += len; |
| 1065 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) | 1065 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) |
| 1066 return -1; | 1066 return -1; |
| 1067 | 1067 |
| 1068 m_Offset += len; | 1068 m_Offset += len; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1084 return -1; | 1084 return -1; |
| 1085 return 0; | 1085 return 0; |
| 1086 } | 1086 } |
| 1087 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) { | 1087 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) { |
| 1088 int32_t iRet = WriteIndirectObjectToStream(pObj); | 1088 int32_t iRet = WriteIndirectObjectToStream(pObj); |
| 1089 if (iRet < 1) { | 1089 if (iRet < 1) { |
| 1090 return iRet; | 1090 return iRet; |
| 1091 } | 1091 } |
| 1092 return WriteIndirectObj(pObj->GetObjNum(), pObj); | 1092 return WriteIndirectObj(pObj->GetObjNum(), pObj); |
| 1093 } | 1093 } |
| 1094 int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, | 1094 int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, |
| 1095 const CPDF_Object* pObj, | 1095 const CPDF_Object* pObj, |
| 1096 FX_BOOL bEncrypt) { | 1096 FX_BOOL bEncrypt) { |
| 1097 int32_t len = 0; | 1097 int32_t len = 0; |
| 1098 if (!pObj) { | 1098 if (!pObj) { |
| 1099 if (m_File.AppendString(" null") < 0) { | 1099 if (m_File.AppendString(" null") < 0) { |
| 1100 return -1; | 1100 return -1; |
| 1101 } | 1101 } |
| 1102 m_Offset += 5; | 1102 m_Offset += 5; |
| 1103 return 1; | 1103 return 1; |
| 1104 } | 1104 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 m_Offset += len; | 1142 m_Offset += len; |
| 1143 break; | 1143 break; |
| 1144 } | 1144 } |
| 1145 case CPDF_Object::STREAM: { | 1145 case CPDF_Object::STREAM: { |
| 1146 CPDF_FlateEncoder encoder; | 1146 CPDF_FlateEncoder encoder; |
| 1147 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), | 1147 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), |
| 1148 m_bCompress); | 1148 m_bCompress); |
| 1149 CPDF_Encryptor encryptor; | 1149 CPDF_Encryptor encryptor; |
| 1150 IPDF_CryptoHandler* pHandler = m_pCryptoHandler; | 1150 IPDF_CryptoHandler* pHandler = m_pCryptoHandler; |
| 1151 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); | 1151 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); |
| 1152 if ((FX_DWORD)encoder.m_pDict->GetIntegerBy("Length") != | 1152 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != |
| 1153 encryptor.m_dwSize) { | 1153 encryptor.m_dwSize) { |
| 1154 encoder.CloneDict(); | 1154 encoder.CloneDict(); |
| 1155 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1155 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
| 1156 } | 1156 } |
| 1157 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1157 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
| 1158 return -1; | 1158 return -1; |
| 1159 } | 1159 } |
| 1160 if ((len = m_File.AppendString("stream\r\n")) < 0) { | 1160 if ((len = m_File.AppendString("stream\r\n")) < 0) { |
| 1161 return -1; | 1161 return -1; |
| 1162 } | 1162 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1191 return -1; | 1191 return -1; |
| 1192 m_Offset += len + 5; | 1192 m_Offset += len + 5; |
| 1193 break; | 1193 break; |
| 1194 } | 1194 } |
| 1195 case CPDF_Object::ARRAY: { | 1195 case CPDF_Object::ARRAY: { |
| 1196 if (m_File.AppendString("[") < 0) { | 1196 if (m_File.AppendString("[") < 0) { |
| 1197 return -1; | 1197 return -1; |
| 1198 } | 1198 } |
| 1199 m_Offset += 1; | 1199 m_Offset += 1; |
| 1200 const CPDF_Array* p = pObj->AsArray(); | 1200 const CPDF_Array* p = pObj->AsArray(); |
| 1201 for (FX_DWORD i = 0; i < p->GetCount(); i++) { | 1201 for (uint32_t i = 0; i < p->GetCount(); i++) { |
| 1202 CPDF_Object* pElement = p->GetElement(i); | 1202 CPDF_Object* pElement = p->GetElement(i); |
| 1203 if (pElement->GetObjNum()) { | 1203 if (pElement->GetObjNum()) { |
| 1204 if (m_File.AppendString(" ") < 0) { | 1204 if (m_File.AppendString(" ") < 0) { |
| 1205 return -1; | 1205 return -1; |
| 1206 } | 1206 } |
| 1207 if ((len = m_File.AppendDWord(pElement->GetObjNum())) < 0) { | 1207 if ((len = m_File.AppendDWord(pElement->GetObjNum())) < 0) { |
| 1208 return -1; | 1208 return -1; |
| 1209 } | 1209 } |
| 1210 if (m_File.AppendString(" 0 R") < 0) { | 1210 if (m_File.AppendString(" 0 R") < 0) { |
| 1211 return -1; | 1211 return -1; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 } | 1266 } |
| 1267 if (m_File.AppendString(">>") < 0) { | 1267 if (m_File.AppendString(">>") < 0) { |
| 1268 return -1; | 1268 return -1; |
| 1269 } | 1269 } |
| 1270 m_Offset += 2; | 1270 m_Offset += 2; |
| 1271 break; | 1271 break; |
| 1272 } | 1272 } |
| 1273 } | 1273 } |
| 1274 return 1; | 1274 return 1; |
| 1275 } | 1275 } |
| 1276 int32_t CPDF_Creator::WriteOldIndirectObject(FX_DWORD objnum) { | 1276 int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) { |
| 1277 if (m_pParser->IsObjectFreeOrNull(objnum)) | 1277 if (m_pParser->IsObjectFreeOrNull(objnum)) |
| 1278 return 0; | 1278 return 0; |
| 1279 | 1279 |
| 1280 m_ObjectOffset[objnum] = m_Offset; | 1280 m_ObjectOffset[objnum] = m_Offset; |
| 1281 FX_BOOL bExistInMap = | 1281 FX_BOOL bExistInMap = |
| 1282 pdfium::ContainsKey(m_pDocument->m_IndirectObjs, objnum); | 1282 pdfium::ContainsKey(m_pDocument->m_IndirectObjs, objnum); |
| 1283 const uint8_t object_type = m_pParser->GetObjectType(objnum); | 1283 const uint8_t object_type = m_pParser->GetObjectType(objnum); |
| 1284 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; | 1284 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; |
| 1285 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || | 1285 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || |
| 1286 bObjStm) { | 1286 bObjStm) { |
| 1287 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); | 1287 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); |
| 1288 if (!pObj) { | 1288 if (!pObj) { |
| 1289 m_ObjectOffset[objnum] = 0; | 1289 m_ObjectOffset[objnum] = 0; |
| 1290 return 0; | 1290 return 0; |
| 1291 } | 1291 } |
| 1292 if (WriteIndirectObj(pObj)) { | 1292 if (WriteIndirectObj(pObj)) { |
| 1293 return -1; | 1293 return -1; |
| 1294 } | 1294 } |
| 1295 if (!bExistInMap) { | 1295 if (!bExistInMap) { |
| 1296 m_pDocument->ReleaseIndirectObject(objnum); | 1296 m_pDocument->ReleaseIndirectObject(objnum); |
| 1297 } | 1297 } |
| 1298 } else { | 1298 } else { |
| 1299 uint8_t* pBuffer; | 1299 uint8_t* pBuffer; |
| 1300 FX_DWORD size; | 1300 uint32_t size; |
| 1301 m_pParser->GetIndirectBinary(objnum, pBuffer, size); | 1301 m_pParser->GetIndirectBinary(objnum, pBuffer, size); |
| 1302 if (!pBuffer) { | 1302 if (!pBuffer) { |
| 1303 return 0; | 1303 return 0; |
| 1304 } | 1304 } |
| 1305 if (object_type == 2) { | 1305 if (object_type == 2) { |
| 1306 if (m_pXRefStream) { | 1306 if (m_pXRefStream) { |
| 1307 if (WriteIndirectObjectToStream(objnum, pBuffer, size) < 0) { | 1307 if (WriteIndirectObjectToStream(objnum, pBuffer, size) < 0) { |
| 1308 FX_Free(pBuffer); | 1308 FX_Free(pBuffer); |
| 1309 return -1; | 1309 return -1; |
| 1310 } | 1310 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1333 m_Offset += size; | 1333 m_Offset += size; |
| 1334 if (AppendObjectNumberToXRef(objnum) < 0) { | 1334 if (AppendObjectNumberToXRef(objnum) < 0) { |
| 1335 return -1; | 1335 return -1; |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| 1338 FX_Free(pBuffer); | 1338 FX_Free(pBuffer); |
| 1339 } | 1339 } |
| 1340 return 1; | 1340 return 1; |
| 1341 } | 1341 } |
| 1342 int32_t CPDF_Creator::WriteOldObjs(IFX_Pause* pPause) { | 1342 int32_t CPDF_Creator::WriteOldObjs(IFX_Pause* pPause) { |
| 1343 FX_DWORD nLastObjNum = m_pParser->GetLastObjNum(); | 1343 uint32_t nLastObjNum = m_pParser->GetLastObjNum(); |
| 1344 if (!m_pParser->IsValidObjectNumber(nLastObjNum)) | 1344 if (!m_pParser->IsValidObjectNumber(nLastObjNum)) |
| 1345 return 0; | 1345 return 0; |
| 1346 | 1346 |
| 1347 FX_DWORD objnum = (FX_DWORD)(uintptr_t)m_Pos; | 1347 uint32_t objnum = (uint32_t)(uintptr_t)m_Pos; |
| 1348 for (; objnum <= nLastObjNum; ++objnum) { | 1348 for (; objnum <= nLastObjNum; ++objnum) { |
| 1349 int32_t iRet = WriteOldIndirectObject(objnum); | 1349 int32_t iRet = WriteOldIndirectObject(objnum); |
| 1350 if (iRet < 0) | 1350 if (iRet < 0) |
| 1351 return iRet; | 1351 return iRet; |
| 1352 | 1352 |
| 1353 if (!iRet) | 1353 if (!iRet) |
| 1354 continue; | 1354 continue; |
| 1355 | 1355 |
| 1356 if (pPause && pPause->NeedToPauseNow()) { | 1356 if (pPause && pPause->NeedToPauseNow()) { |
| 1357 m_Pos = (void*)(uintptr_t)(objnum + 1); | 1357 m_Pos = (void*)(uintptr_t)(objnum + 1); |
| 1358 return 1; | 1358 return 1; |
| 1359 } | 1359 } |
| 1360 } | 1360 } |
| 1361 return 0; | 1361 return 0; |
| 1362 } | 1362 } |
| 1363 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { | 1363 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { |
| 1364 int32_t iCount = m_NewObjNumArray.GetSize(); | 1364 int32_t iCount = m_NewObjNumArray.GetSize(); |
| 1365 int32_t index = (int32_t)(uintptr_t)m_Pos; | 1365 int32_t index = (int32_t)(uintptr_t)m_Pos; |
| 1366 while (index < iCount) { | 1366 while (index < iCount) { |
| 1367 FX_DWORD objnum = m_NewObjNumArray.ElementAt(index); | 1367 uint32_t objnum = m_NewObjNumArray.ElementAt(index); |
| 1368 auto it = m_pDocument->m_IndirectObjs.find(objnum); | 1368 auto it = m_pDocument->m_IndirectObjs.find(objnum); |
| 1369 if (it == m_pDocument->m_IndirectObjs.end()) { | 1369 if (it == m_pDocument->m_IndirectObjs.end()) { |
| 1370 ++index; | 1370 ++index; |
| 1371 continue; | 1371 continue; |
| 1372 } | 1372 } |
| 1373 m_ObjectOffset[objnum] = m_Offset; | 1373 m_ObjectOffset[objnum] = m_Offset; |
| 1374 if (WriteIndirectObj(it->second)) { | 1374 if (WriteIndirectObj(it->second)) { |
| 1375 return -1; | 1375 return -1; |
| 1376 } | 1376 } |
| 1377 index++; | 1377 index++; |
| 1378 if (pPause && pPause->NeedToPauseNow()) { | 1378 if (pPause && pPause->NeedToPauseNow()) { |
| 1379 m_Pos = (FX_POSITION)(uintptr_t)index; | 1379 m_Pos = (FX_POSITION)(uintptr_t)index; |
| 1380 return 1; | 1380 return 1; |
| 1381 } | 1381 } |
| 1382 } | 1382 } |
| 1383 return 0; | 1383 return 0; |
| 1384 } | 1384 } |
| 1385 void CPDF_Creator::InitOldObjNumOffsets() { | 1385 void CPDF_Creator::InitOldObjNumOffsets() { |
| 1386 if (!m_pParser) { | 1386 if (!m_pParser) { |
| 1387 return; | 1387 return; |
| 1388 } | 1388 } |
| 1389 FX_DWORD j = 0; | 1389 uint32_t j = 0; |
| 1390 FX_DWORD dwStart = 0; | 1390 uint32_t dwStart = 0; |
| 1391 FX_DWORD dwEnd = m_pParser->GetLastObjNum(); | 1391 uint32_t dwEnd = m_pParser->GetLastObjNum(); |
| 1392 while (dwStart <= dwEnd) { | 1392 while (dwStart <= dwEnd) { |
| 1393 while (dwStart <= dwEnd && m_pParser->IsObjectFreeOrNull(dwStart)) | 1393 while (dwStart <= dwEnd && m_pParser->IsObjectFreeOrNull(dwStart)) |
| 1394 dwStart++; | 1394 dwStart++; |
| 1395 | 1395 |
| 1396 if (dwStart > dwEnd) | 1396 if (dwStart > dwEnd) |
| 1397 break; | 1397 break; |
| 1398 | 1398 |
| 1399 j = dwStart; | 1399 j = dwStart; |
| 1400 while (j <= dwEnd && !m_pParser->IsObjectFreeOrNull(j)) | 1400 while (j <= dwEnd && !m_pParser->IsObjectFreeOrNull(j)) |
| 1401 j++; | 1401 j++; |
| 1402 | 1402 |
| 1403 m_ObjectOffset.Add(dwStart, j - dwStart); | 1403 m_ObjectOffset.Add(dwStart, j - dwStart); |
| 1404 dwStart = j; | 1404 dwStart = j; |
| 1405 } | 1405 } |
| 1406 } | 1406 } |
| 1407 void CPDF_Creator::InitNewObjNumOffsets() { | 1407 void CPDF_Creator::InitNewObjNumOffsets() { |
| 1408 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; | 1408 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; |
| 1409 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; | 1409 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; |
| 1410 for (const auto& pair : m_pDocument->m_IndirectObjs) { | 1410 for (const auto& pair : m_pDocument->m_IndirectObjs) { |
| 1411 const FX_DWORD objnum = pair.first; | 1411 const uint32_t objnum = pair.first; |
| 1412 const CPDF_Object* pObj = pair.second; | 1412 const CPDF_Object* pObj = pair.second; |
| 1413 if (pObj->GetObjNum() == -1) | 1413 if (pObj->GetObjNum() == -1) |
| 1414 continue; | 1414 continue; |
| 1415 if (bIncremental) { | 1415 if (bIncremental) { |
| 1416 if (!pObj->IsModified()) | 1416 if (!pObj->IsModified()) |
| 1417 continue; | 1417 continue; |
| 1418 } else if (m_pParser && m_pParser->IsValidObjectNumber(objnum) && | 1418 } else if (m_pParser && m_pParser->IsValidObjectNumber(objnum) && |
| 1419 m_pParser->GetObjectType(objnum)) { | 1419 m_pParser->GetObjectType(objnum)) { |
| 1420 continue; | 1420 continue; |
| 1421 } | 1421 } |
| 1422 AppendNewObjNum(objnum); | 1422 AppendNewObjNum(objnum); |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 int32_t iCount = m_NewObjNumArray.GetSize(); | 1425 int32_t iCount = m_NewObjNumArray.GetSize(); |
| 1426 if (iCount == 0) { | 1426 if (iCount == 0) { |
| 1427 return; | 1427 return; |
| 1428 } | 1428 } |
| 1429 int32_t i = 0; | 1429 int32_t i = 0; |
| 1430 FX_DWORD dwStartObjNum = 0; | 1430 uint32_t dwStartObjNum = 0; |
| 1431 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0; | 1431 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0; |
| 1432 while (i < iCount) { | 1432 while (i < iCount) { |
| 1433 dwStartObjNum = m_NewObjNumArray.ElementAt(i); | 1433 dwStartObjNum = m_NewObjNumArray.ElementAt(i); |
| 1434 if ((bIncremental && (bNoOriginal || bCrossRefValid)) || | 1434 if ((bIncremental && (bNoOriginal || bCrossRefValid)) || |
| 1435 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) { | 1435 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) { |
| 1436 break; | 1436 break; |
| 1437 } | 1437 } |
| 1438 i++; | 1438 i++; |
| 1439 } | 1439 } |
| 1440 if (i >= iCount) { | 1440 if (i >= iCount) { |
| 1441 return; | 1441 return; |
| 1442 } | 1442 } |
| 1443 FX_DWORD dwLastObjNum = dwStartObjNum; | 1443 uint32_t dwLastObjNum = dwStartObjNum; |
| 1444 i++; | 1444 i++; |
| 1445 FX_BOOL bNewStart = FALSE; | 1445 FX_BOOL bNewStart = FALSE; |
| 1446 for (; i < iCount; i++) { | 1446 for (; i < iCount; i++) { |
| 1447 FX_DWORD dwCurObjNum = m_NewObjNumArray.ElementAt(i); | 1447 uint32_t dwCurObjNum = m_NewObjNumArray.ElementAt(i); |
| 1448 bool bExist = m_pParser && m_pParser->IsValidObjectNumber(dwCurObjNum) && | 1448 bool bExist = m_pParser && m_pParser->IsValidObjectNumber(dwCurObjNum) && |
| 1449 m_ObjectOffset.GetPtrAt(dwCurObjNum); | 1449 m_ObjectOffset.GetPtrAt(dwCurObjNum); |
| 1450 if (bExist || dwCurObjNum - dwLastObjNum > 1) { | 1450 if (bExist || dwCurObjNum - dwLastObjNum > 1) { |
| 1451 if (!bNewStart) | 1451 if (!bNewStart) |
| 1452 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); | 1452 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); |
| 1453 dwStartObjNum = dwCurObjNum; | 1453 dwStartObjNum = dwCurObjNum; |
| 1454 } | 1454 } |
| 1455 if (bNewStart) { | 1455 if (bNewStart) { |
| 1456 dwStartObjNum = dwCurObjNum; | 1456 dwStartObjNum = dwCurObjNum; |
| 1457 } | 1457 } |
| 1458 bNewStart = bExist; | 1458 bNewStart = bExist; |
| 1459 dwLastObjNum = dwCurObjNum; | 1459 dwLastObjNum = dwCurObjNum; |
| 1460 } | 1460 } |
| 1461 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); | 1461 m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1); |
| 1462 } | 1462 } |
| 1463 void CPDF_Creator::AppendNewObjNum(FX_DWORD objbum) { | 1463 void CPDF_Creator::AppendNewObjNum(uint32_t objbum) { |
| 1464 int32_t iStart = 0, iFind = 0; | 1464 int32_t iStart = 0, iFind = 0; |
| 1465 int32_t iEnd = m_NewObjNumArray.GetUpperBound(); | 1465 int32_t iEnd = m_NewObjNumArray.GetUpperBound(); |
| 1466 while (iStart <= iEnd) { | 1466 while (iStart <= iEnd) { |
| 1467 int32_t iMid = (iStart + iEnd) / 2; | 1467 int32_t iMid = (iStart + iEnd) / 2; |
| 1468 FX_DWORD dwMid = m_NewObjNumArray.ElementAt(iMid); | 1468 uint32_t dwMid = m_NewObjNumArray.ElementAt(iMid); |
| 1469 if (objbum < dwMid) { | 1469 if (objbum < dwMid) { |
| 1470 iEnd = iMid - 1; | 1470 iEnd = iMid - 1; |
| 1471 } else { | 1471 } else { |
| 1472 if (iMid == iEnd) { | 1472 if (iMid == iEnd) { |
| 1473 iFind = iMid + 1; | 1473 iFind = iMid + 1; |
| 1474 break; | 1474 break; |
| 1475 } | 1475 } |
| 1476 FX_DWORD dwNext = m_NewObjNumArray.ElementAt(iMid + 1); | 1476 uint32_t dwNext = m_NewObjNumArray.ElementAt(iMid + 1); |
| 1477 if (objbum < dwNext) { | 1477 if (objbum < dwNext) { |
| 1478 iFind = iMid + 1; | 1478 iFind = iMid + 1; |
| 1479 break; | 1479 break; |
| 1480 } | 1480 } |
| 1481 iStart = iMid + 1; | 1481 iStart = iMid + 1; |
| 1482 } | 1482 } |
| 1483 } | 1483 } |
| 1484 m_NewObjNumArray.InsertAt(iFind, objbum); | 1484 m_NewObjNumArray.InsertAt(iFind, objbum); |
| 1485 } | 1485 } |
| 1486 int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) { | 1486 int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 IFX_FileRead* pSrcFile = m_pParser->GetFileAccess(); | 1531 IFX_FileRead* pSrcFile = m_pParser->GetFileAccess(); |
| 1532 m_Offset = pSrcFile->GetSize(); | 1532 m_Offset = pSrcFile->GetSize(); |
| 1533 m_Pos = (void*)(uintptr_t)m_Offset; | 1533 m_Pos = (void*)(uintptr_t)m_Offset; |
| 1534 m_iStage = 15; | 1534 m_iStage = 15; |
| 1535 } | 1535 } |
| 1536 } | 1536 } |
| 1537 if (m_iStage == 15) { | 1537 if (m_iStage == 15) { |
| 1538 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && m_Pos) { | 1538 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && m_Pos) { |
| 1539 IFX_FileRead* pSrcFile = m_pParser->GetFileAccess(); | 1539 IFX_FileRead* pSrcFile = m_pParser->GetFileAccess(); |
| 1540 uint8_t buffer[4096]; | 1540 uint8_t buffer[4096]; |
| 1541 FX_DWORD src_size = (FX_DWORD)(uintptr_t)m_Pos; | 1541 uint32_t src_size = (uint32_t)(uintptr_t)m_Pos; |
| 1542 while (src_size) { | 1542 while (src_size) { |
| 1543 FX_DWORD block_size = src_size > 4096 ? 4096 : src_size; | 1543 uint32_t block_size = src_size > 4096 ? 4096 : src_size; |
| 1544 if (!pSrcFile->ReadBlock(buffer, m_Offset - src_size, block_size)) { | 1544 if (!pSrcFile->ReadBlock(buffer, m_Offset - src_size, block_size)) { |
| 1545 return -1; | 1545 return -1; |
| 1546 } | 1546 } |
| 1547 if (m_File.AppendBlock(buffer, block_size) < 0) { | 1547 if (m_File.AppendBlock(buffer, block_size) < 0) { |
| 1548 return -1; | 1548 return -1; |
| 1549 } | 1549 } |
| 1550 src_size -= block_size; | 1550 src_size -= block_size; |
| 1551 if (pPause && pPause->NeedToPauseNow()) { | 1551 if (pPause && pPause->NeedToPauseNow()) { |
| 1552 m_Pos = (void*)(uintptr_t)src_size; | 1552 m_Pos = (void*)(uintptr_t)src_size; |
| 1553 return 1; | 1553 return 1; |
| 1554 } | 1554 } |
| 1555 } | 1555 } |
| 1556 } | 1556 } |
| 1557 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && | 1557 if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && |
| 1558 m_pParser->GetLastXRefOffset() == 0) { | 1558 m_pParser->GetLastXRefOffset() == 0) { |
| 1559 InitOldObjNumOffsets(); | 1559 InitOldObjNumOffsets(); |
| 1560 FX_DWORD dwEnd = m_pParser->GetLastObjNum(); | 1560 uint32_t dwEnd = m_pParser->GetLastObjNum(); |
| 1561 bool bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0; | 1561 bool bObjStm = (m_dwFlags & FPDFCREATE_OBJECTSTREAM) != 0; |
| 1562 for (FX_DWORD objnum = 0; objnum <= dwEnd; objnum++) { | 1562 for (uint32_t objnum = 0; objnum <= dwEnd; objnum++) { |
| 1563 if (m_pParser->IsObjectFreeOrNull(objnum)) | 1563 if (m_pParser->IsObjectFreeOrNull(objnum)) |
| 1564 continue; | 1564 continue; |
| 1565 | 1565 |
| 1566 m_ObjectOffset[objnum] = m_pParser->GetObjectPositionOrZero(objnum); | 1566 m_ObjectOffset[objnum] = m_pParser->GetObjectPositionOrZero(objnum); |
| 1567 if (bObjStm) { | 1567 if (bObjStm) { |
| 1568 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 1568 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 1569 } | 1569 } |
| 1570 } | 1570 } |
| 1571 if (bObjStm) { | 1571 if (bObjStm) { |
| 1572 m_pXRefStream->EndXRefStream(this); | 1572 m_pXRefStream->EndXRefStream(this); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { | 1620 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { |
| 1621 m_NewObjNumArray.Add(m_dwLastObjNum); | 1621 m_NewObjNumArray.Add(m_dwLastObjNum); |
| 1622 } | 1622 } |
| 1623 } | 1623 } |
| 1624 m_iStage = 80; | 1624 m_iStage = 80; |
| 1625 } | 1625 } |
| 1626 return m_iStage; | 1626 return m_iStage; |
| 1627 } | 1627 } |
| 1628 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { | 1628 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { |
| 1629 FXSYS_assert(m_iStage >= 80 || m_iStage < 90); | 1629 FXSYS_assert(m_iStage >= 80 || m_iStage < 90); |
| 1630 FX_DWORD dwLastObjNum = m_dwLastObjNum; | 1630 uint32_t dwLastObjNum = m_dwLastObjNum; |
| 1631 if (m_iStage == 80) { | 1631 if (m_iStage == 80) { |
| 1632 m_XrefStart = m_Offset; | 1632 m_XrefStart = m_Offset; |
| 1633 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1633 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
| 1634 m_pXRefStream->End(this, TRUE); | 1634 m_pXRefStream->End(this, TRUE); |
| 1635 m_XrefStart = m_pXRefStream->m_PrevOffset; | 1635 m_XrefStart = m_pXRefStream->m_PrevOffset; |
| 1636 m_iStage = 90; | 1636 m_iStage = 90; |
| 1637 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || | 1637 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || |
| 1638 !m_pParser->IsXRefStream()) { | 1638 !m_pParser->IsXRefStream()) { |
| 1639 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || | 1639 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || |
| 1640 m_pParser->GetLastXRefOffset() == 0) { | 1640 m_pParser->GetLastXRefOffset() == 0) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1653 } | 1653 } |
| 1654 m_Pos = (void*)(uintptr_t)0; | 1654 m_Pos = (void*)(uintptr_t)0; |
| 1655 m_iStage = 82; | 1655 m_iStage = 82; |
| 1656 } | 1656 } |
| 1657 } else { | 1657 } else { |
| 1658 m_iStage = 90; | 1658 m_iStage = 90; |
| 1659 } | 1659 } |
| 1660 } | 1660 } |
| 1661 if (m_iStage == 81) { | 1661 if (m_iStage == 81) { |
| 1662 CFX_ByteString str; | 1662 CFX_ByteString str; |
| 1663 FX_DWORD i = (FX_DWORD)(uintptr_t)m_Pos, j; | 1663 uint32_t i = (uint32_t)(uintptr_t)m_Pos, j; |
| 1664 while (i <= dwLastObjNum) { | 1664 while (i <= dwLastObjNum) { |
| 1665 while (i <= dwLastObjNum && !m_ObjectOffset.GetPtrAt(i)) { | 1665 while (i <= dwLastObjNum && !m_ObjectOffset.GetPtrAt(i)) { |
| 1666 i++; | 1666 i++; |
| 1667 } | 1667 } |
| 1668 if (i > dwLastObjNum) { | 1668 if (i > dwLastObjNum) { |
| 1669 break; | 1669 break; |
| 1670 } | 1670 } |
| 1671 j = i; | 1671 j = i; |
| 1672 while (j <= dwLastObjNum && m_ObjectOffset.GetPtrAt(j)) { | 1672 while (j <= dwLastObjNum && m_ObjectOffset.GetPtrAt(j)) { |
| 1673 j++; | 1673 j++; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1695 } | 1695 } |
| 1696 } | 1696 } |
| 1697 m_iStage = 90; | 1697 m_iStage = 90; |
| 1698 } | 1698 } |
| 1699 if (m_iStage == 82) { | 1699 if (m_iStage == 82) { |
| 1700 CFX_ByteString str; | 1700 CFX_ByteString str; |
| 1701 int32_t iCount = m_NewObjNumArray.GetSize(); | 1701 int32_t iCount = m_NewObjNumArray.GetSize(); |
| 1702 int32_t i = (int32_t)(uintptr_t)m_Pos; | 1702 int32_t i = (int32_t)(uintptr_t)m_Pos; |
| 1703 while (i < iCount) { | 1703 while (i < iCount) { |
| 1704 int32_t j = i; | 1704 int32_t j = i; |
| 1705 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1705 uint32_t objnum = m_NewObjNumArray.ElementAt(i); |
| 1706 while (j < iCount) { | 1706 while (j < iCount) { |
| 1707 if (++j == iCount) { | 1707 if (++j == iCount) { |
| 1708 break; | 1708 break; |
| 1709 } | 1709 } |
| 1710 FX_DWORD dwCurrent = m_NewObjNumArray.ElementAt(j); | 1710 uint32_t dwCurrent = m_NewObjNumArray.ElementAt(j); |
| 1711 if (dwCurrent - objnum > 1) { | 1711 if (dwCurrent - objnum > 1) { |
| 1712 break; | 1712 break; |
| 1713 } | 1713 } |
| 1714 objnum = dwCurrent; | 1714 objnum = dwCurrent; |
| 1715 } | 1715 } |
| 1716 objnum = m_NewObjNumArray.ElementAt(i); | 1716 objnum = m_NewObjNumArray.ElementAt(i); |
| 1717 if (objnum == 1) { | 1717 if (objnum == 1) { |
| 1718 str.Format("0 %d\r\n0000000000 65535 f\r\n", j - i + 1); | 1718 str.Format("0 %d\r\n0000000000 65535 f\r\n", j - i + 1); |
| 1719 } else { | 1719 } else { |
| 1720 str.Format("%d %d\r\n", objnum, j - i); | 1720 str.Format("%d %d\r\n", objnum, j - i); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 } | 1810 } |
| 1811 if (m_File.AppendString(" 0 R\r\n") < 0) { | 1811 if (m_File.AppendString(" 0 R\r\n") < 0) { |
| 1812 return -1; | 1812 return -1; |
| 1813 } | 1813 } |
| 1814 } | 1814 } |
| 1815 } | 1815 } |
| 1816 if (m_pEncryptDict) { | 1816 if (m_pEncryptDict) { |
| 1817 if (m_File.AppendString("/Encrypt") < 0) { | 1817 if (m_File.AppendString("/Encrypt") < 0) { |
| 1818 return -1; | 1818 return -1; |
| 1819 } | 1819 } |
| 1820 FX_DWORD dwObjNum = m_pEncryptDict->GetObjNum(); | 1820 uint32_t dwObjNum = m_pEncryptDict->GetObjNum(); |
| 1821 if (dwObjNum == 0) { | 1821 if (dwObjNum == 0) { |
| 1822 dwObjNum = m_pDocument->GetLastObjNum() + 1; | 1822 dwObjNum = m_pDocument->GetLastObjNum() + 1; |
| 1823 } | 1823 } |
| 1824 if (m_File.AppendString(" ") < 0) { | 1824 if (m_File.AppendString(" ") < 0) { |
| 1825 return -1; | 1825 return -1; |
| 1826 } | 1826 } |
| 1827 if (m_File.AppendDWord(dwObjNum) < 0) { | 1827 if (m_File.AppendDWord(dwObjNum) < 0) { |
| 1828 return -1; | 1828 return -1; |
| 1829 } | 1829 } |
| 1830 if (m_File.AppendString(" 0 R ") < 0) { | 1830 if (m_File.AppendString(" 0 R ") < 0) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 if (!bXRefStream) { | 1863 if (!bXRefStream) { |
| 1864 if (m_File.AppendString(">>") < 0) { | 1864 if (m_File.AppendString(">>") < 0) { |
| 1865 return -1; | 1865 return -1; |
| 1866 } | 1866 } |
| 1867 } else { | 1867 } else { |
| 1868 if (m_File.AppendString("/W[0 4 1]/Index[") < 0) { | 1868 if (m_File.AppendString("/W[0 4 1]/Index[") < 0) { |
| 1869 return -1; | 1869 return -1; |
| 1870 } | 1870 } |
| 1871 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser && | 1871 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser && |
| 1872 m_pParser->GetLastXRefOffset() == 0) { | 1872 m_pParser->GetLastXRefOffset() == 0) { |
| 1873 FX_DWORD i = 0; | 1873 uint32_t i = 0; |
| 1874 for (i = 0; i < m_dwLastObjNum; i++) { | 1874 for (i = 0; i < m_dwLastObjNum; i++) { |
| 1875 if (!m_ObjectOffset.GetPtrAt(i)) { | 1875 if (!m_ObjectOffset.GetPtrAt(i)) { |
| 1876 continue; | 1876 continue; |
| 1877 } | 1877 } |
| 1878 if (m_File.AppendDWord(i) < 0) { | 1878 if (m_File.AppendDWord(i) < 0) { |
| 1879 return -1; | 1879 return -1; |
| 1880 } | 1880 } |
| 1881 if (m_File.AppendString(" 1 ") < 0) { | 1881 if (m_File.AppendString(" 1 ") < 0) { |
| 1882 return -1; | 1882 return -1; |
| 1883 } | 1883 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1895 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); | 1895 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); |
| 1896 if (!offset) { | 1896 if (!offset) { |
| 1897 continue; | 1897 continue; |
| 1898 } | 1898 } |
| 1899 OutputIndex(&m_File, *offset); | 1899 OutputIndex(&m_File, *offset); |
| 1900 } | 1900 } |
| 1901 } else { | 1901 } else { |
| 1902 int count = m_NewObjNumArray.GetSize(); | 1902 int count = m_NewObjNumArray.GetSize(); |
| 1903 int32_t i = 0; | 1903 int32_t i = 0; |
| 1904 for (i = 0; i < count; i++) { | 1904 for (i = 0; i < count; i++) { |
| 1905 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1905 uint32_t objnum = m_NewObjNumArray.ElementAt(i); |
| 1906 if (m_File.AppendDWord(objnum) < 0) { | 1906 if (m_File.AppendDWord(objnum) < 0) { |
| 1907 return -1; | 1907 return -1; |
| 1908 } | 1908 } |
| 1909 if (m_File.AppendString(" 1 ") < 0) { | 1909 if (m_File.AppendString(" 1 ") < 0) { |
| 1910 return -1; | 1910 return -1; |
| 1911 } | 1911 } |
| 1912 } | 1912 } |
| 1913 if (m_File.AppendString("]/Length ") < 0) { | 1913 if (m_File.AppendString("]/Length ") < 0) { |
| 1914 return -1; | 1914 return -1; |
| 1915 } | 1915 } |
| 1916 if (m_File.AppendDWord(count * 5) < 0) { | 1916 if (m_File.AppendDWord(count * 5) < 0) { |
| 1917 return -1; | 1917 return -1; |
| 1918 } | 1918 } |
| 1919 if (m_File.AppendString(">>stream\r\n") < 0) { | 1919 if (m_File.AppendString(">>stream\r\n") < 0) { |
| 1920 return -1; | 1920 return -1; |
| 1921 } | 1921 } |
| 1922 for (i = 0; i < count; i++) { | 1922 for (i = 0; i < count; i++) { |
| 1923 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1923 uint32_t objnum = m_NewObjNumArray.ElementAt(i); |
| 1924 FX_FILESIZE offset = m_ObjectOffset[objnum]; | 1924 FX_FILESIZE offset = m_ObjectOffset[objnum]; |
| 1925 OutputIndex(&m_File, offset); | 1925 OutputIndex(&m_File, offset); |
| 1926 } | 1926 } |
| 1927 } | 1927 } |
| 1928 if (m_File.AppendString("\r\nendstream") < 0) { | 1928 if (m_File.AppendString("\r\nendstream") < 0) { |
| 1929 return -1; | 1929 return -1; |
| 1930 } | 1930 } |
| 1931 } | 1931 } |
| 1932 } | 1932 } |
| 1933 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { | 1933 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1949 delete m_pXRefStream; | 1949 delete m_pXRefStream; |
| 1950 m_pXRefStream = NULL; | 1950 m_pXRefStream = NULL; |
| 1951 m_File.Clear(); | 1951 m_File.Clear(); |
| 1952 m_NewObjNumArray.RemoveAll(); | 1952 m_NewObjNumArray.RemoveAll(); |
| 1953 if (m_pIDArray) { | 1953 if (m_pIDArray) { |
| 1954 m_pIDArray->Release(); | 1954 m_pIDArray->Release(); |
| 1955 m_pIDArray = NULL; | 1955 m_pIDArray = NULL; |
| 1956 } | 1956 } |
| 1957 } | 1957 } |
| 1958 | 1958 |
| 1959 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, FX_DWORD flags) { | 1959 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { |
| 1960 m_File.AttachFile(pFile); | 1960 m_File.AttachFile(pFile); |
| 1961 return Create(flags); | 1961 return Create(flags); |
| 1962 } | 1962 } |
| 1963 | 1963 |
| 1964 bool CPDF_Creator::Create(FX_DWORD flags) { | 1964 bool CPDF_Creator::Create(uint32_t flags) { |
| 1965 m_dwFlags = flags; | 1965 m_dwFlags = flags; |
| 1966 m_iStage = 0; | 1966 m_iStage = 0; |
| 1967 m_Offset = 0; | 1967 m_Offset = 0; |
| 1968 m_dwLastObjNum = m_pDocument->GetLastObjNum(); | 1968 m_dwLastObjNum = m_pDocument->GetLastObjNum(); |
| 1969 m_ObjectOffset.Clear(); | 1969 m_ObjectOffset.Clear(); |
| 1970 m_NewObjNumArray.RemoveAll(); | 1970 m_NewObjNumArray.RemoveAll(); |
| 1971 InitID(); | 1971 InitID(); |
| 1972 if (flags & FPDFCREATE_PROGRESSIVE) { | 1972 if (flags & FPDFCREATE_PROGRESSIVE) { |
| 1973 return true; | 1973 return true; |
| 1974 } | 1974 } |
| 1975 return Continue(NULL) > -1; | 1975 return Continue(NULL) > -1; |
| 1976 } | 1976 } |
| 1977 void CPDF_Creator::InitID(FX_BOOL bDefault) { | 1977 void CPDF_Creator::InitID(FX_BOOL bDefault) { |
| 1978 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; | 1978 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; |
| 1979 FX_BOOL bNewId = !m_pIDArray; | 1979 FX_BOOL bNewId = !m_pIDArray; |
| 1980 if (!m_pIDArray) { | 1980 if (!m_pIDArray) { |
| 1981 m_pIDArray = new CPDF_Array; | 1981 m_pIDArray = new CPDF_Array; |
| 1982 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; | 1982 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; |
| 1983 if (pID1) { | 1983 if (pID1) { |
| 1984 m_pIDArray->Add(pID1->Clone()); | 1984 m_pIDArray->Add(pID1->Clone()); |
| 1985 } else { | 1985 } else { |
| 1986 std::vector<uint8_t> buffer = | 1986 std::vector<uint8_t> buffer = |
| 1987 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); | 1987 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
| 1988 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); | 1988 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 1989 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 1989 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 1990 } | 1990 } |
| 1991 } | 1991 } |
| 1992 if (!bDefault) { | 1992 if (!bDefault) { |
| 1993 return; | 1993 return; |
| 1994 } | 1994 } |
| 1995 if (pOldIDArray) { | 1995 if (pOldIDArray) { |
| 1996 CPDF_Object* pID2 = pOldIDArray->GetElement(1); | 1996 CPDF_Object* pID2 = pOldIDArray->GetElement(1); |
| 1997 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { | 1997 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { |
| 1998 m_pIDArray->Add(pID2->Clone()); | 1998 m_pIDArray->Add(pID2->Clone()); |
| 1999 return; | 1999 return; |
| 2000 } | 2000 } |
| 2001 std::vector<uint8_t> buffer = | 2001 std::vector<uint8_t> buffer = |
| 2002 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); | 2002 PDF_GenerateFileID((uint32_t)(uintptr_t) this, m_dwLastObjNum); |
| 2003 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); | 2003 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 2004 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2004 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 2005 return; | 2005 return; |
| 2006 } | 2006 } |
| 2007 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); | 2007 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); |
| 2008 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 2008 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
| 2009 if (m_pEncryptDict->GetStringBy("Filter") == "Standard") { | 2009 if (m_pEncryptDict->GetStringBy("Filter") == "Standard") { |
| 2010 CPDF_StandardSecurityHandler handler; | 2010 CPDF_StandardSecurityHandler handler; |
| 2011 CFX_ByteString user_pass = m_pParser->GetPassword(); | 2011 CFX_ByteString user_pass = m_pParser->GetPassword(); |
| 2012 FX_DWORD flag = PDF_ENCRYPT_CONTENT; | 2012 uint32_t flag = PDF_ENCRYPT_CONTENT; |
| 2013 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, | 2013 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, |
| 2014 user_pass.GetLength(), flag); | 2014 user_pass.GetLength(), flag); |
| 2015 if (m_bNewCrypto) { | 2015 if (m_bNewCrypto) { |
| 2016 delete m_pCryptoHandler; | 2016 delete m_pCryptoHandler; |
| 2017 } | 2017 } |
| 2018 m_pCryptoHandler = new CPDF_StandardCryptoHandler; | 2018 m_pCryptoHandler = new CPDF_StandardCryptoHandler; |
| 2019 m_pCryptoHandler->Init(m_pEncryptDict, &handler); | 2019 m_pCryptoHandler->Init(m_pEncryptDict, &handler); |
| 2020 m_bNewCrypto = TRUE; | 2020 m_bNewCrypto = TRUE; |
| 2021 m_bSecurityChanged = TRUE; | 2021 m_bSecurityChanged = TRUE; |
| 2022 } | 2022 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2069 m_bNewCrypto = FALSE; | 2069 m_bNewCrypto = FALSE; |
| 2070 if (!m_bStandardSecurity) { | 2070 if (!m_bStandardSecurity) { |
| 2071 return; | 2071 return; |
| 2072 } | 2072 } |
| 2073 if (m_pEncryptDict) { | 2073 if (m_pEncryptDict) { |
| 2074 m_pEncryptDict->Release(); | 2074 m_pEncryptDict->Release(); |
| 2075 m_pEncryptDict = NULL; | 2075 m_pEncryptDict = NULL; |
| 2076 } | 2076 } |
| 2077 m_bStandardSecurity = FALSE; | 2077 m_bStandardSecurity = FALSE; |
| 2078 } | 2078 } |
| OLD | NEW |