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

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

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 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
« no previous file with comments | « core/fpdfapi/edit/editint.h ('k') | core/fpdfapi/font/cpdf_cidfont.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/edit/editint.h" 7 #include "core/fpdfapi/edit/editint.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 if (pFile->AppendString(" ") < 0) { 53 if (pFile->AppendString(" ") < 0) {
54 return -1; 54 return -1;
55 } 55 }
56 if ((len = pFile->AppendString(pObj->GetString().AsStringC())) < 0) { 56 if ((len = pFile->AppendString(pObj->GetString().AsStringC())) < 0) {
57 return -1; 57 return -1;
58 } 58 }
59 offset += len + 1; 59 offset += len + 1;
60 break; 60 break;
61 case CPDF_Object::STRING: { 61 case CPDF_Object::STRING: {
62 CFX_ByteString str = pObj->GetString(); 62 CFX_ByteString str = pObj->GetString();
63 FX_BOOL bHex = pObj->AsString()->IsHex(); 63 bool bHex = pObj->AsString()->IsHex();
64 if ((len = pFile->AppendString(PDF_EncodeString(str, bHex).AsStringC())) < 64 if ((len = pFile->AppendString(PDF_EncodeString(str, bHex).AsStringC())) <
65 0) { 65 0) {
66 return -1; 66 return -1;
67 } 67 }
68 offset += len; 68 offset += len;
69 break; 69 break;
70 } 70 }
71 case CPDF_Object::NAME: { 71 case CPDF_Object::NAME: {
72 if (pFile->AppendString("/") < 0) { 72 if (pFile->AppendString("/") < 0) {
73 return -1; 73 return -1;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 case CPDF_Object::STREAM: { 162 case CPDF_Object::STREAM: {
163 const CPDF_Stream* p = pObj->AsStream(); 163 const CPDF_Stream* p = pObj->AsStream();
164 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) { 164 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) {
165 return -1; 165 return -1;
166 } 166 }
167 if (pFile->AppendString("stream\r\n") < 0) { 167 if (pFile->AppendString("stream\r\n") < 0) {
168 return -1; 168 return -1;
169 } 169 }
170 offset += 8; 170 offset += 8;
171 CPDF_StreamAcc acc; 171 CPDF_StreamAcc acc;
172 acc.LoadAllData(p, TRUE); 172 acc.LoadAllData(p, true);
173 if (pFile->AppendBlock(acc.GetData(), acc.GetSize()) < 0) { 173 if (pFile->AppendBlock(acc.GetData(), acc.GetSize()) < 0) {
174 return -1; 174 return -1;
175 } 175 }
176 offset += acc.GetSize(); 176 offset += acc.GetSize();
177 if ((len = pFile->AppendString("\r\nendstream")) < 0) { 177 if ((len = pFile->AppendString("\r\nendstream")) < 0) {
178 return -1; 178 return -1;
179 } 179 }
180 offset += len; 180 offset += len;
181 break; 181 break;
182 } 182 }
183 default: 183 default:
184 ASSERT(FALSE); 184 ASSERT(false);
185 break; 185 break;
186 } 186 }
187 return 1; 187 return 1;
188 } 188 }
189 189
190 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, 190 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument,
191 CFX_FileBufferArchive* pFile, 191 CFX_FileBufferArchive* pFile,
192 CPDF_Array* pIDArray) { 192 CPDF_Array* pIDArray) {
193 FX_FILESIZE offset = 0; 193 FX_FILESIZE offset = 0;
194 int32_t len = 0; 194 int32_t len = 0;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return -1; 378 return -1;
379 if (pFile->AppendByte(FX_GETBYTEOFFSET0(offset)) < 0) 379 if (pFile->AppendByte(FX_GETBYTEOFFSET0(offset)) < 0)
380 return -1; 380 return -1;
381 if (pFile->AppendByte(0) < 0) 381 if (pFile->AppendByte(0) < 0)
382 return -1; 382 return -1;
383 return 0; 383 return 0;
384 } 384 }
385 385
386 class CPDF_FlateEncoder { 386 class CPDF_FlateEncoder {
387 public: 387 public:
388 CPDF_FlateEncoder(CPDF_Stream* pStream, FX_BOOL bFlateEncode); 388 CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode);
389 CPDF_FlateEncoder(const uint8_t* pBuffer, 389 CPDF_FlateEncoder(const uint8_t* pBuffer,
390 uint32_t size, 390 uint32_t size,
391 bool bFlateEncode, 391 bool bFlateEncode,
392 bool bXRefStream); 392 bool bXRefStream);
393 ~CPDF_FlateEncoder(); 393 ~CPDF_FlateEncoder();
394 394
395 void CloneDict(); 395 void CloneDict();
396 396
397 uint8_t* m_pData; 397 uint8_t* m_pData;
398 uint32_t m_dwSize; 398 uint32_t m_dwSize;
399 CPDF_Dictionary* m_pDict; 399 CPDF_Dictionary* m_pDict;
400 FX_BOOL m_bCloned; 400 bool m_bCloned;
401 FX_BOOL m_bNewData; 401 bool m_bNewData;
402 CPDF_StreamAcc m_Acc; 402 CPDF_StreamAcc m_Acc;
403 }; 403 };
404 404
405 void CPDF_FlateEncoder::CloneDict() { 405 void CPDF_FlateEncoder::CloneDict() {
406 if (!m_bCloned) { 406 if (!m_bCloned) {
407 m_pDict = ToDictionary(m_pDict->Clone()); 407 m_pDict = ToDictionary(m_pDict->Clone());
408 ASSERT(m_pDict); 408 ASSERT(m_pDict);
409 m_bCloned = TRUE; 409 m_bCloned = true;
410 } 410 }
411 } 411 }
412 412
413 CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, FX_BOOL bFlateEncode) 413 CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode)
414 : m_pData(nullptr), 414 : m_pData(nullptr),
415 m_dwSize(0), 415 m_dwSize(0),
416 m_pDict(nullptr), 416 m_pDict(nullptr),
417 m_bCloned(FALSE), 417 m_bCloned(false),
418 m_bNewData(FALSE) { 418 m_bNewData(false) {
419 m_Acc.LoadAllData(pStream, TRUE); 419 m_Acc.LoadAllData(pStream, true);
420 if ((pStream && pStream->GetDict() && 420 if ((pStream && pStream->GetDict() &&
421 pStream->GetDict()->KeyExist("Filter")) || 421 pStream->GetDict()->KeyExist("Filter")) ||
422 !bFlateEncode) { 422 !bFlateEncode) {
423 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { 423 if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) {
424 CPDF_StreamAcc destAcc; 424 CPDF_StreamAcc destAcc;
425 destAcc.LoadAllData(pStream); 425 destAcc.LoadAllData(pStream);
426 m_dwSize = destAcc.GetSize(); 426 m_dwSize = destAcc.GetSize();
427 m_pData = (uint8_t*)destAcc.DetachData(); 427 m_pData = (uint8_t*)destAcc.DetachData();
428 m_pDict = ToDictionary(pStream->GetDict()->Clone()); 428 m_pDict = ToDictionary(pStream->GetDict()->Clone());
429 m_pDict->RemoveFor("Filter"); 429 m_pDict->RemoveFor("Filter");
430 m_bNewData = TRUE; 430 m_bNewData = true;
431 m_bCloned = TRUE; 431 m_bCloned = true;
432 } else { 432 } else {
433 m_pData = (uint8_t*)m_Acc.GetData(); 433 m_pData = (uint8_t*)m_Acc.GetData();
434 m_dwSize = m_Acc.GetSize(); 434 m_dwSize = m_Acc.GetSize();
435 m_pDict = pStream->GetDict(); 435 m_pDict = pStream->GetDict();
436 } 436 }
437 return; 437 return;
438 } 438 }
439 439
440 m_bNewData = TRUE; 440 m_bNewData = true;
441 m_bCloned = TRUE; 441 m_bCloned = true;
442 // TODO(thestig): Move to Init() and check return value. 442 // TODO(thestig): Move to Init() and check return value.
443 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize); 443 ::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), &m_pData, &m_dwSize);
444 m_pDict = ToDictionary(pStream->GetDict()->Clone()); 444 m_pDict = ToDictionary(pStream->GetDict()->Clone());
445 m_pDict->SetIntegerFor("Length", m_dwSize); 445 m_pDict->SetIntegerFor("Length", m_dwSize);
446 m_pDict->SetNameFor("Filter", "FlateDecode"); 446 m_pDict->SetNameFor("Filter", "FlateDecode");
447 m_pDict->RemoveFor("DecodeParms"); 447 m_pDict->RemoveFor("DecodeParms");
448 } 448 }
449 449
450 CPDF_FlateEncoder::CPDF_FlateEncoder(const uint8_t* pBuffer, 450 CPDF_FlateEncoder::CPDF_FlateEncoder(const uint8_t* pBuffer,
451 uint32_t size, 451 uint32_t size,
452 bool bFlateEncode, 452 bool bFlateEncode,
453 bool bXRefStream) 453 bool bXRefStream)
454 : m_pData(nullptr), 454 : m_pData(nullptr),
455 m_dwSize(0), 455 m_dwSize(0),
456 m_pDict(nullptr), 456 m_pDict(nullptr),
457 m_bCloned(FALSE), 457 m_bCloned(false),
458 m_bNewData(FALSE) { 458 m_bNewData(false) {
459 if (!bFlateEncode) { 459 if (!bFlateEncode) {
460 m_pData = (uint8_t*)pBuffer; 460 m_pData = (uint8_t*)pBuffer;
461 m_dwSize = size; 461 m_dwSize = size;
462 return; 462 return;
463 } 463 }
464 m_bNewData = TRUE; 464 m_bNewData = true;
465 // TODO(thestig): Move to Init() and check return value. 465 // TODO(thestig): Move to Init() and check return value.
466 if (bXRefStream) 466 if (bXRefStream)
467 ::PngEncode(pBuffer, size, &m_pData, &m_dwSize); 467 ::PngEncode(pBuffer, size, &m_pData, &m_dwSize);
468 else 468 else
469 ::FlateEncode(pBuffer, size, &m_pData, &m_dwSize); 469 ::FlateEncode(pBuffer, size, &m_pData, &m_dwSize);
470 } 470 }
471 471
472 CPDF_FlateEncoder::~CPDF_FlateEncoder() { 472 CPDF_FlateEncoder::~CPDF_FlateEncoder() {
473 if (m_bCloned && m_pDict) 473 if (m_bCloned && m_pDict)
474 m_pDict->Release(); 474 m_pDict->Release();
475 if (m_bNewData) 475 if (m_bNewData)
476 FX_Free(m_pData); 476 FX_Free(m_pData);
477 } 477 }
478 478
479 class CPDF_Encryptor { 479 class CPDF_Encryptor {
480 public: 480 public:
481 CPDF_Encryptor(CPDF_CryptoHandler* pHandler, 481 CPDF_Encryptor(CPDF_CryptoHandler* pHandler,
482 int objnum, 482 int objnum,
483 uint8_t* src_data, 483 uint8_t* src_data,
484 uint32_t src_size); 484 uint32_t src_size);
485 ~CPDF_Encryptor(); 485 ~CPDF_Encryptor();
486 486
487 uint8_t* m_pData; 487 uint8_t* m_pData;
488 uint32_t m_dwSize; 488 uint32_t m_dwSize;
489 FX_BOOL m_bNewBuf; 489 bool m_bNewBuf;
490 }; 490 };
491 491
492 CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler, 492 CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler,
493 int objnum, 493 int objnum,
494 uint8_t* src_data, 494 uint8_t* src_data,
495 uint32_t src_size) 495 uint32_t src_size)
496 : m_pData(nullptr), m_dwSize(0), m_bNewBuf(FALSE) { 496 : m_pData(nullptr), m_dwSize(0), m_bNewBuf(false) {
497 if (src_size == 0) 497 if (src_size == 0)
498 return; 498 return;
499 499
500 if (!pHandler) { 500 if (!pHandler) {
501 m_pData = (uint8_t*)src_data; 501 m_pData = (uint8_t*)src_data;
502 m_dwSize = src_size; 502 m_dwSize = src_size;
503 return; 503 return;
504 } 504 }
505 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size); 505 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size);
506 m_pData = FX_Alloc(uint8_t, m_dwSize); 506 m_pData = FX_Alloc(uint8_t, m_dwSize);
507 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); 507 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize);
508 m_bNewBuf = TRUE; 508 m_bNewBuf = true;
509 } 509 }
510 510
511 CPDF_Encryptor::~CPDF_Encryptor() { 511 CPDF_Encryptor::~CPDF_Encryptor() {
512 if (m_bNewBuf) 512 if (m_bNewBuf)
513 FX_Free(m_pData); 513 FX_Free(m_pData);
514 } 514 }
515 515
516 } // namespace 516 } // namespace
517 517
518 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} 518 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 604 }
605 offset += len; 605 offset += len;
606 return ObjOffset; 606 return ObjOffset;
607 } 607 }
608 608
609 CPDF_XRefStream::CPDF_XRefStream() 609 CPDF_XRefStream::CPDF_XRefStream()
610 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} 610 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {}
611 611
612 CPDF_XRefStream::~CPDF_XRefStream() {} 612 CPDF_XRefStream::~CPDF_XRefStream() {}
613 613
614 FX_BOOL CPDF_XRefStream::Start() { 614 bool CPDF_XRefStream::Start() {
615 m_IndexArray.clear(); 615 m_IndexArray.clear();
616 m_Buffer.Clear(); 616 m_Buffer.Clear();
617 m_iSeg = 0; 617 m_iSeg = 0;
618 return TRUE; 618 return true;
619 } 619 }
620 int32_t CPDF_XRefStream::CompressIndirectObject(uint32_t dwObjNum, 620 int32_t CPDF_XRefStream::CompressIndirectObject(uint32_t dwObjNum,
621 const CPDF_Object* pObj, 621 const CPDF_Object* pObj,
622 CPDF_Creator* pCreator) { 622 CPDF_Creator* pCreator) {
623 if (!pCreator) 623 if (!pCreator)
624 return 0; 624 return 0;
625 625
626 m_ObjStream.CompressIndirectObject(dwObjNum, pObj); 626 m_ObjStream.CompressIndirectObject(dwObjNum, pObj);
627 if (pdfium::CollectionSize<int32_t>(m_ObjStream.m_Items) < 627 if (pdfium::CollectionSize<int32_t>(m_ObjStream.m_Items) <
628 pCreator->m_ObjectStreamSize && 628 pCreator->m_ObjectStreamSize &&
(...skipping 11 matching lines...) Expand all
640 640
641 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); 641 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize);
642 if (pdfium::CollectionSize<int32_t>(m_ObjStream.m_Items) < 642 if (pdfium::CollectionSize<int32_t>(m_ObjStream.m_Items) <
643 pCreator->m_ObjectStreamSize && 643 pCreator->m_ObjectStreamSize &&
644 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { 644 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) {
645 return 1; 645 return 1;
646 } 646 }
647 return EndObjectStream(pCreator); 647 return EndObjectStream(pCreator);
648 } 648 }
649 649
650 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { 650 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, bool bEOF) {
651 FX_FILESIZE objOffset = 0; 651 FX_FILESIZE objOffset = 0;
652 if (bEOF) { 652 if (bEOF) {
653 objOffset = m_ObjStream.End(pCreator); 653 objOffset = m_ObjStream.End(pCreator);
654 if (objOffset < 0) { 654 if (objOffset < 0) {
655 return -1; 655 return -1;
656 } 656 }
657 } 657 }
658 uint32_t& dwObjStmNum = m_ObjStream.m_dwObjNum; 658 uint32_t& dwObjStmNum = m_ObjStream.m_dwObjNum;
659 if (!dwObjStmNum) { 659 if (!dwObjStmNum) {
660 dwObjStmNum = ++pCreator->m_dwLastObjNum; 660 dwObjStmNum = ++pCreator->m_dwLastObjNum;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 AppendIndex1(m_Buffer, objOffset); 706 AppendIndex1(m_Buffer, objOffset);
707 m_IndexArray.push_back({dwObjStmNum, 1}); 707 m_IndexArray.push_back({dwObjStmNum, 1});
708 iSeg += 1; 708 iSeg += 1;
709 } 709 }
710 m_iSeg = iSeg; 710 m_iSeg = iSeg;
711 if (bEOF) { 711 if (bEOF) {
712 m_ObjStream.Start(); 712 m_ObjStream.Start();
713 } 713 }
714 return 1; 714 return 1;
715 } 715 }
716 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, 716 bool CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, bool bEOF) {
717 FX_BOOL bEOF) {
718 FX_FILESIZE offset_tmp = pCreator->m_Offset; 717 FX_FILESIZE offset_tmp = pCreator->m_Offset;
719 uint32_t objnum = ++pCreator->m_dwLastObjNum; 718 uint32_t objnum = ++pCreator->m_dwLastObjNum;
720 CFX_FileBufferArchive* pFile = &pCreator->m_File; 719 CFX_FileBufferArchive* pFile = &pCreator->m_File;
721 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; 720 bool bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0;
722 if (bIncremental) { 721 if (bIncremental) {
723 AddObjectNumberToIndexArray(objnum); 722 AddObjectNumberToIndexArray(objnum);
724 } else { 723 } else {
725 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { 724 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) {
726 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); 725 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum);
727 if (offset) { 726 if (offset) {
728 AppendIndex1(m_Buffer, *offset); 727 AppendIndex1(m_Buffer, *offset);
729 } else { 728 } else {
730 AppendIndex0(m_Buffer, false); 729 AppendIndex0(m_Buffer, false);
731 } 730 }
732 } 731 }
733 } 732 }
734 AppendIndex1(m_Buffer, offset_tmp); 733 AppendIndex1(m_Buffer, offset_tmp);
735 FX_FILESIZE& offset = pCreator->m_Offset; 734 FX_FILESIZE& offset = pCreator->m_Offset;
736 int32_t len = pFile->AppendDWord(objnum); 735 int32_t len = pFile->AppendDWord(objnum);
737 if (len < 0) { 736 if (len < 0) {
738 return FALSE; 737 return false;
739 } 738 }
740 offset += len; 739 offset += len;
741 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) < 740 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) <
742 0) { 741 0) {
743 return FALSE; 742 return false;
744 } 743 }
745 offset += len; 744 offset += len;
746 if (!bIncremental) { 745 if (!bIncremental) {
747 if ((len = pFile->AppendDWord(0)) < 0) { 746 if ((len = pFile->AppendDWord(0)) < 0) {
748 return FALSE; 747 return false;
749 } 748 }
750 if ((len = pFile->AppendString(" ")) < 0) { 749 if ((len = pFile->AppendString(" ")) < 0) {
751 return FALSE; 750 return false;
752 } 751 }
753 offset += len + 1; 752 offset += len + 1;
754 if ((len = pFile->AppendDWord(objnum + 1)) < 0) { 753 if ((len = pFile->AppendDWord(objnum + 1)) < 0) {
755 return FALSE; 754 return false;
756 } 755 }
757 offset += len; 756 offset += len;
758 } else { 757 } else {
759 for (const auto& pair : m_IndexArray) { 758 for (const auto& pair : m_IndexArray) {
760 if ((len = pFile->AppendDWord(pair.objnum)) < 0) { 759 if ((len = pFile->AppendDWord(pair.objnum)) < 0) {
761 return FALSE; 760 return false;
762 } 761 }
763 if (pFile->AppendString(" ") < 0) { 762 if (pFile->AppendString(" ") < 0) {
764 return FALSE; 763 return false;
765 } 764 }
766 offset += len + 1; 765 offset += len + 1;
767 if ((len = pFile->AppendDWord(pair.count)) < 0) { 766 if ((len = pFile->AppendDWord(pair.count)) < 0) {
768 return FALSE; 767 return false;
769 } 768 }
770 if (pFile->AppendString(" ") < 0) { 769 if (pFile->AppendString(" ") < 0) {
771 return FALSE; 770 return false;
772 } 771 }
773 offset += len + 1; 772 offset += len + 1;
774 } 773 }
775 } 774 }
776 if (pFile->AppendString("]/Size ") < 0) { 775 if (pFile->AppendString("]/Size ") < 0) {
777 return FALSE; 776 return false;
778 } 777 }
779 if ((len = pFile->AppendDWord(objnum + 1)) < 0) { 778 if ((len = pFile->AppendDWord(objnum + 1)) < 0) {
780 return FALSE; 779 return false;
781 } 780 }
782 offset += len + 7; 781 offset += len + 7;
783 if (m_PrevOffset > 0) { 782 if (m_PrevOffset > 0) {
784 if (pFile->AppendString("/Prev ") < 0) { 783 if (pFile->AppendString("/Prev ") < 0) {
785 return FALSE; 784 return false;
786 } 785 }
787 FX_CHAR offset_buf[20]; 786 FX_CHAR offset_buf[20];
788 FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); 787 FXSYS_memset(offset_buf, 0, sizeof(offset_buf));
789 FXSYS_i64toa(m_PrevOffset, offset_buf, 10); 788 FXSYS_i64toa(m_PrevOffset, offset_buf, 10);
790 int32_t offset_len = (int32_t)FXSYS_strlen(offset_buf); 789 int32_t offset_len = (int32_t)FXSYS_strlen(offset_buf);
791 if (pFile->AppendBlock(offset_buf, offset_len) < 0) { 790 if (pFile->AppendBlock(offset_buf, offset_len) < 0) {
792 return FALSE; 791 return false;
793 } 792 }
794 offset += offset_len + 6; 793 offset += offset_len + 6;
795 } 794 }
796 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), TRUE, 795 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), true,
797 TRUE); 796 true);
798 if (pFile->AppendString("/Filter /FlateDecode") < 0) 797 if (pFile->AppendString("/Filter /FlateDecode") < 0)
799 return FALSE; 798 return false;
800 799
801 offset += 20; 800 offset += 20;
802 if ((len = pFile->AppendString("/DecodeParms<</Columns 7/Predictor 12>>")) < 801 if ((len = pFile->AppendString("/DecodeParms<</Columns 7/Predictor 12>>")) <
803 0) { 802 0) {
804 return FALSE; 803 return false;
805 } 804 }
806 805
807 offset += len; 806 offset += len;
808 if (pFile->AppendString("/Length ") < 0) 807 if (pFile->AppendString("/Length ") < 0)
809 return FALSE; 808 return false;
810 809
811 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) 810 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0)
812 return FALSE; 811 return false;
813 812
814 offset += len + 8; 813 offset += len + 8;
815 if (bEOF) { 814 if (bEOF) {
816 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, 815 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile,
817 pCreator->m_pIDArray.get())) < 0) { 816 pCreator->m_pIDArray.get())) < 0) {
818 return FALSE; 817 return false;
819 } 818 }
820 offset += len; 819 offset += len;
821 if (pCreator->m_pEncryptDict) { 820 if (pCreator->m_pEncryptDict) {
822 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); 821 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum();
823 if (dwEncryptObjNum == 0) { 822 if (dwEncryptObjNum == 0) {
824 dwEncryptObjNum = pCreator->m_dwEncryptObjNum; 823 dwEncryptObjNum = pCreator->m_dwEncryptObjNum;
825 } 824 }
826 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, 825 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict,
827 dwEncryptObjNum, pFile)) < 0) { 826 dwEncryptObjNum, pFile)) < 0) {
828 return FALSE; 827 return false;
829 } 828 }
830 offset += len; 829 offset += len;
831 } 830 }
832 } 831 }
833 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { 832 if ((len = pFile->AppendString(">>stream\r\n")) < 0) {
834 return FALSE; 833 return false;
835 } 834 }
836 offset += len; 835 offset += len;
837 if (pFile->AppendBlock(encoder.m_pData, encoder.m_dwSize) < 0) { 836 if (pFile->AppendBlock(encoder.m_pData, encoder.m_dwSize) < 0) {
838 return FALSE; 837 return false;
839 } 838 }
840 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) { 839 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) {
841 return FALSE; 840 return false;
842 } 841 }
843 offset += encoder.m_dwSize + len; 842 offset += encoder.m_dwSize + len;
844 m_PrevOffset = offset_tmp; 843 m_PrevOffset = offset_tmp;
845 return TRUE; 844 return true;
846 } 845 }
847 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { 846 bool CPDF_XRefStream::End(CPDF_Creator* pCreator, bool bEOF) {
848 if (EndObjectStream(pCreator, bEOF) < 0) { 847 if (EndObjectStream(pCreator, bEOF) < 0) {
849 return FALSE; 848 return false;
850 } 849 }
851 return GenerateXRefStream(pCreator, bEOF); 850 return GenerateXRefStream(pCreator, bEOF);
852 } 851 }
853 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { 852 bool CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) {
854 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { 853 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) {
855 AppendIndex0(m_Buffer, true); 854 AppendIndex0(m_Buffer, true);
856 for (uint32_t i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { 855 for (uint32_t i = 1; i < pCreator->m_dwLastObjNum + 1; i++) {
857 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); 856 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i);
858 if (offset) { 857 if (offset) {
859 AppendIndex1(m_Buffer, *offset); 858 AppendIndex1(m_Buffer, *offset);
860 } else { 859 } else {
861 AppendIndex0(m_Buffer, false); 860 AppendIndex0(m_Buffer, false);
862 } 861 }
863 } 862 }
864 } else { 863 } else {
865 for (const auto& pair : m_IndexArray) { 864 for (const auto& pair : m_IndexArray) {
866 for (uint32_t j = pair.objnum; j < pair.objnum + pair.count; ++j) 865 for (uint32_t j = pair.objnum; j < pair.objnum + pair.count; ++j)
867 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); 866 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]);
868 } 867 }
869 } 868 }
870 return GenerateXRefStream(pCreator, FALSE); 869 return GenerateXRefStream(pCreator, false);
871 } 870 }
872 void CPDF_XRefStream::AddObjectNumberToIndexArray(uint32_t objnum) { 871 void CPDF_XRefStream::AddObjectNumberToIndexArray(uint32_t objnum) {
873 if (m_IndexArray.empty()) { 872 if (m_IndexArray.empty()) {
874 m_IndexArray.push_back({objnum, 1}); 873 m_IndexArray.push_back({objnum, 1});
875 return; 874 return;
876 } 875 }
877 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; 876 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count;
878 if (objnum == next_objnum) 877 if (objnum == next_objnum)
879 m_IndexArray.back().count += 1; 878 m_IndexArray.back().count += 1;
880 else 879 else
881 m_IndexArray.push_back({objnum, 1}); 880 m_IndexArray.push_back({objnum, 1});
882 } 881 }
883 882
884 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) 883 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc)
885 : m_pDocument(pDoc), 884 : m_pDocument(pDoc),
886 m_pParser(pDoc->GetParser()), 885 m_pParser(pDoc->GetParser()),
887 m_bSecurityChanged(FALSE), 886 m_bSecurityChanged(false),
888 m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), 887 m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr),
889 m_dwEncryptObjNum(0), 888 m_dwEncryptObjNum(0),
890 m_bEncryptCloned(FALSE), 889 m_bEncryptCloned(false),
891 m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr), 890 m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr),
892 m_bLocalCryptoHandler(FALSE), 891 m_bLocalCryptoHandler(false),
893 m_pMetadata(nullptr), 892 m_pMetadata(nullptr),
894 m_ObjectStreamSize(200), 893 m_ObjectStreamSize(200),
895 m_dwLastObjNum(m_pDocument->GetLastObjNum()), 894 m_dwLastObjNum(m_pDocument->GetLastObjNum()),
896 m_Offset(0), 895 m_Offset(0),
897 m_iStage(-1), 896 m_iStage(-1),
898 m_dwFlags(0), 897 m_dwFlags(0),
899 m_Pos(nullptr), 898 m_Pos(nullptr),
900 m_XrefStart(0), 899 m_XrefStart(0),
901 m_pIDArray(nullptr), 900 m_pIDArray(nullptr),
902 m_FileVersion(0) {} 901 m_FileVersion(0) {}
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 } 1045 }
1047 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) { 1046 int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) {
1048 int32_t iRet = WriteIndirectObjectToStream(pObj); 1047 int32_t iRet = WriteIndirectObjectToStream(pObj);
1049 if (iRet < 1) { 1048 if (iRet < 1) {
1050 return iRet; 1049 return iRet;
1051 } 1050 }
1052 return WriteIndirectObj(pObj->GetObjNum(), pObj); 1051 return WriteIndirectObj(pObj->GetObjNum(), pObj);
1053 } 1052 }
1054 int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, 1053 int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum,
1055 const CPDF_Object* pObj, 1054 const CPDF_Object* pObj,
1056 FX_BOOL bEncrypt) { 1055 bool bEncrypt) {
1057 int32_t len = 0; 1056 int32_t len = 0;
1058 if (!pObj) { 1057 if (!pObj) {
1059 if (m_File.AppendString(" null") < 0) { 1058 if (m_File.AppendString(" null") < 0) {
1060 return -1; 1059 return -1;
1061 } 1060 }
1062 m_Offset += 5; 1061 m_Offset += 5;
1063 return 1; 1062 return 1;
1064 } 1063 }
1065 switch (pObj->GetType()) { 1064 switch (pObj->GetType()) {
1066 case CPDF_Object::NULLOBJ: 1065 case CPDF_Object::NULLOBJ:
1067 if (m_File.AppendString(" null") < 0) { 1066 if (m_File.AppendString(" null") < 0) {
1068 return -1; 1067 return -1;
1069 } 1068 }
1070 m_Offset += 5; 1069 m_Offset += 5;
1071 break; 1070 break;
1072 case CPDF_Object::BOOLEAN: 1071 case CPDF_Object::BOOLEAN:
1073 case CPDF_Object::NUMBER: 1072 case CPDF_Object::NUMBER:
1074 if (m_File.AppendString(" ") < 0) { 1073 if (m_File.AppendString(" ") < 0) {
1075 return -1; 1074 return -1;
1076 } 1075 }
1077 if ((len = m_File.AppendString(pObj->GetString().AsStringC())) < 0) { 1076 if ((len = m_File.AppendString(pObj->GetString().AsStringC())) < 0) {
1078 return -1; 1077 return -1;
1079 } 1078 }
1080 m_Offset += len + 1; 1079 m_Offset += len + 1;
1081 break; 1080 break;
1082 case CPDF_Object::STRING: { 1081 case CPDF_Object::STRING: {
1083 CFX_ByteString str = pObj->GetString(); 1082 CFX_ByteString str = pObj->GetString();
1084 FX_BOOL bHex = pObj->AsString()->IsHex(); 1083 bool bHex = pObj->AsString()->IsHex();
1085 if (!m_pCryptoHandler || !bEncrypt) { 1084 if (!m_pCryptoHandler || !bEncrypt) {
1086 CFX_ByteString content = PDF_EncodeString(str, bHex); 1085 CFX_ByteString content = PDF_EncodeString(str, bHex);
1087 if ((len = m_File.AppendString(content.AsStringC())) < 0) { 1086 if ((len = m_File.AppendString(content.AsStringC())) < 0) {
1088 return -1; 1087 return -1;
1089 } 1088 }
1090 m_Offset += len; 1089 m_Offset += len;
1091 break; 1090 break;
1092 } 1091 }
1093 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), 1092 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(),
1094 str.GetLength()); 1093 str.GetLength());
1095 CFX_ByteString content = PDF_EncodeString( 1094 CFX_ByteString content = PDF_EncodeString(
1096 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), 1095 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize),
1097 bHex); 1096 bHex);
1098 if ((len = m_File.AppendString(content.AsStringC())) < 0) { 1097 if ((len = m_File.AppendString(content.AsStringC())) < 0) {
1099 return -1; 1098 return -1;
1100 } 1099 }
1101 m_Offset += len; 1100 m_Offset += len;
1102 break; 1101 break;
1103 } 1102 }
1104 case CPDF_Object::STREAM: { 1103 case CPDF_Object::STREAM: {
1105 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), 1104 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()),
1106 TRUE); 1105 true);
1107 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData, 1106 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData,
1108 encoder.m_dwSize); 1107 encoder.m_dwSize);
1109 if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") != 1108 if ((uint32_t)encoder.m_pDict->GetIntegerFor("Length") !=
1110 encryptor.m_dwSize) { 1109 encryptor.m_dwSize) {
1111 encoder.CloneDict(); 1110 encoder.CloneDict();
1112 encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize); 1111 encoder.m_pDict->SetIntegerFor("Length", encryptor.m_dwSize);
1113 } 1112 }
1114 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { 1113 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) {
1115 return -1; 1114 return -1;
1116 } 1115 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 case CPDF_Object::DICTIONARY: { 1182 case CPDF_Object::DICTIONARY: {
1184 if (!m_pCryptoHandler || pObj == m_pEncryptDict) 1183 if (!m_pCryptoHandler || pObj == m_pEncryptDict)
1185 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); 1184 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset);
1186 if (m_File.AppendString("<<") < 0) 1185 if (m_File.AppendString("<<") < 0)
1187 return -1; 1186 return -1;
1188 1187
1189 m_Offset += 2; 1188 m_Offset += 2;
1190 const CPDF_Dictionary* p = pObj->AsDictionary(); 1189 const CPDF_Dictionary* p = pObj->AsDictionary();
1191 bool bSignDict = p->IsSignatureDict(); 1190 bool bSignDict = p->IsSignatureDict();
1192 for (const auto& it : *p) { 1191 for (const auto& it : *p) {
1193 FX_BOOL bSignValue = FALSE; 1192 bool bSignValue = false;
1194 const CFX_ByteString& key = it.first; 1193 const CFX_ByteString& key = it.first;
1195 CPDF_Object* pValue = it.second; 1194 CPDF_Object* pValue = it.second;
1196 if (m_File.AppendString("/") < 0) { 1195 if (m_File.AppendString("/") < 0) {
1197 return -1; 1196 return -1;
1198 } 1197 }
1199 if ((len = m_File.AppendString(PDF_NameEncode(key).AsStringC())) < 0) { 1198 if ((len = m_File.AppendString(PDF_NameEncode(key).AsStringC())) < 0) {
1200 return -1; 1199 return -1;
1201 } 1200 }
1202 m_Offset += len + 1; 1201 m_Offset += len + 1;
1203 if (bSignDict && key == "Contents") { 1202 if (bSignDict && key == "Contents") {
1204 bSignValue = TRUE; 1203 bSignValue = true;
1205 } 1204 }
1206 if (!pValue->IsInline()) { 1205 if (!pValue->IsInline()) {
1207 if (m_File.AppendString(" ") < 0) { 1206 if (m_File.AppendString(" ") < 0) {
1208 return -1; 1207 return -1;
1209 } 1208 }
1210 if ((len = m_File.AppendDWord(pValue->GetObjNum())) < 0) { 1209 if ((len = m_File.AppendDWord(pValue->GetObjNum())) < 0) {
1211 return -1; 1210 return -1;
1212 } 1211 }
1213 if (m_File.AppendString(" 0 R ") < 0) { 1212 if (m_File.AppendString(" 0 R ") < 0) {
1214 return -1; 1213 return -1;
(...skipping 12 matching lines...) Expand all
1227 break; 1226 break;
1228 } 1227 }
1229 } 1228 }
1230 return 1; 1229 return 1;
1231 } 1230 }
1232 int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) { 1231 int32_t CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) {
1233 if (m_pParser->IsObjectFreeOrNull(objnum)) 1232 if (m_pParser->IsObjectFreeOrNull(objnum))
1234 return 0; 1233 return 0;
1235 1234
1236 m_ObjectOffset[objnum] = m_Offset; 1235 m_ObjectOffset[objnum] = m_Offset;
1237 FX_BOOL bExistInMap = !!m_pDocument->GetIndirectObject(objnum); 1236 bool bExistInMap = !!m_pDocument->GetIndirectObject(objnum);
1238 const uint8_t object_type = m_pParser->GetObjectType(objnum); 1237 const uint8_t object_type = m_pParser->GetObjectType(objnum);
1239 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream; 1238 bool bObjStm = (object_type == 2) && m_pEncryptDict && !m_pXRefStream;
1240 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || 1239 if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap ||
1241 bObjStm) { 1240 bObjStm) {
1242 CPDF_Object* pObj = m_pDocument->GetOrParseIndirectObject(objnum); 1241 CPDF_Object* pObj = m_pDocument->GetOrParseIndirectObject(objnum);
1243 if (!pObj) { 1242 if (!pObj) {
1244 m_ObjectOffset[objnum] = 0; 1243 m_ObjectOffset[objnum] = 0;
1245 return 0; 1244 return 0;
1246 } 1245 }
1247 if (WriteIndirectObj(pObj)) { 1246 if (WriteIndirectObj(pObj)) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 if (!iRet) 1307 if (!iRet)
1309 continue; 1308 continue;
1310 1309
1311 if (pPause && pPause->NeedToPauseNow()) { 1310 if (pPause && pPause->NeedToPauseNow()) {
1312 m_Pos = (void*)(uintptr_t)(objnum + 1); 1311 m_Pos = (void*)(uintptr_t)(objnum + 1);
1313 return 1; 1312 return 1;
1314 } 1313 }
1315 } 1314 }
1316 return 0; 1315 return 0;
1317 } 1316 }
1318 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { 1317 int32_t CPDF_Creator::WriteNewObjs(bool bIncremental, IFX_Pause* pPause) {
1319 int32_t iCount = m_NewObjNumArray.GetSize(); 1318 int32_t iCount = m_NewObjNumArray.GetSize();
1320 int32_t index = (int32_t)(uintptr_t)m_Pos; 1319 int32_t index = (int32_t)(uintptr_t)m_Pos;
1321 while (index < iCount) { 1320 while (index < iCount) {
1322 uint32_t objnum = m_NewObjNumArray.ElementAt(index); 1321 uint32_t objnum = m_NewObjNumArray.ElementAt(index);
1323 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); 1322 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum);
1324 if (!pObj) { 1323 if (!pObj) {
1325 ++index; 1324 ++index;
1326 continue; 1325 continue;
1327 } 1326 }
1328 m_ObjectOffset[objnum] = m_Offset; 1327 m_ObjectOffset[objnum] = m_Offset;
(...skipping 25 matching lines...) Expand all
1354 j = dwStart; 1353 j = dwStart;
1355 while (j <= dwEnd && !m_pParser->IsObjectFreeOrNull(j)) 1354 while (j <= dwEnd && !m_pParser->IsObjectFreeOrNull(j))
1356 j++; 1355 j++;
1357 1356
1358 m_ObjectOffset.Add(dwStart, j - dwStart); 1357 m_ObjectOffset.Add(dwStart, j - dwStart);
1359 dwStart = j; 1358 dwStart = j;
1360 } 1359 }
1361 } 1360 }
1362 1361
1363 void CPDF_Creator::InitNewObjNumOffsets() { 1362 void CPDF_Creator::InitNewObjNumOffsets() {
1364 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; 1363 bool bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0;
1365 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; 1364 bool bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0;
1366 for (const auto& pair : *m_pDocument) { 1365 for (const auto& pair : *m_pDocument) {
1367 const uint32_t objnum = pair.first; 1366 const uint32_t objnum = pair.first;
1368 const CPDF_Object* pObj = pair.second.get(); 1367 const CPDF_Object* pObj = pair.second.get();
1369 if (bIncremental || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) 1368 if (bIncremental || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
1370 continue; 1369 continue;
1371 if (m_pParser && m_pParser->IsValidObjectNumber(objnum) && 1370 if (m_pParser && m_pParser->IsValidObjectNumber(objnum) &&
1372 m_pParser->GetObjectType(objnum)) { 1371 m_pParser->GetObjectType(objnum)) {
1373 continue; 1372 continue;
1374 } 1373 }
1375 AppendNewObjNum(objnum); 1374 AppendNewObjNum(objnum);
1376 } 1375 }
1377 1376
1378 int32_t iCount = m_NewObjNumArray.GetSize(); 1377 int32_t iCount = m_NewObjNumArray.GetSize();
1379 if (iCount == 0) 1378 if (iCount == 0)
1380 return; 1379 return;
1381 1380
1382 int32_t i = 0; 1381 int32_t i = 0;
1383 uint32_t dwStartObjNum = 0; 1382 uint32_t dwStartObjNum = 0;
1384 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0; 1383 bool bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0;
1385 while (i < iCount) { 1384 while (i < iCount) {
1386 dwStartObjNum = m_NewObjNumArray.ElementAt(i); 1385 dwStartObjNum = m_NewObjNumArray.ElementAt(i);
1387 if ((bIncremental && (bNoOriginal || bCrossRefValid)) || 1386 if ((bIncremental && (bNoOriginal || bCrossRefValid)) ||
1388 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) { 1387 !m_ObjectOffset.GetPtrAt(dwStartObjNum)) {
1389 break; 1388 break;
1390 } 1389 }
1391 i++; 1390 i++;
1392 } 1391 }
1393 if (i >= iCount) 1392 if (i >= iCount)
1394 return; 1393 return;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 m_iStage = 80; 1577 m_iStage = 80;
1579 } 1578 }
1580 return m_iStage; 1579 return m_iStage;
1581 } 1580 }
1582 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { 1581 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) {
1583 ASSERT(m_iStage >= 80 || m_iStage < 90); 1582 ASSERT(m_iStage >= 80 || m_iStage < 90);
1584 uint32_t dwLastObjNum = m_dwLastObjNum; 1583 uint32_t dwLastObjNum = m_dwLastObjNum;
1585 if (m_iStage == 80) { 1584 if (m_iStage == 80) {
1586 m_XrefStart = m_Offset; 1585 m_XrefStart = m_Offset;
1587 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { 1586 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) {
1588 m_pXRefStream->End(this, TRUE); 1587 m_pXRefStream->End(this, true);
1589 m_XrefStart = m_pXRefStream->m_PrevOffset; 1588 m_XrefStart = m_pXRefStream->m_PrevOffset;
1590 m_iStage = 90; 1589 m_iStage = 90;
1591 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || 1590 } else if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 ||
1592 !m_pParser->IsXRefStream()) { 1591 !m_pParser->IsXRefStream()) {
1593 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 || 1592 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0 ||
1594 m_pParser->GetLastXRefOffset() == 0) { 1593 m_pParser->GetLastXRefOffset() == 0) {
1595 CFX_ByteString str; 1594 CFX_ByteString str;
1596 str = m_ObjectOffset.GetPtrAt(1) 1595 str = m_ObjectOffset.GetPtrAt(1)
1597 ? "xref\r\n" 1596 ? "xref\r\n"
1598 : "xref\r\n0 1\r\n0000000000 65535 f\r\n"; 1597 : "xref\r\n0 1\r\n0000000000 65535 f\r\n";
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 } 1688 }
1690 } 1689 }
1691 m_iStage = 90; 1690 m_iStage = 90;
1692 } 1691 }
1693 return m_iStage; 1692 return m_iStage;
1694 } 1693 }
1695 1694
1696 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { 1695 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) {
1697 ASSERT(m_iStage >= 90); 1696 ASSERT(m_iStage >= 90);
1698 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { 1697 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) {
1699 FX_BOOL bXRefStream = 1698 bool bXRefStream =
1700 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); 1699 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream();
1701 if (!bXRefStream) { 1700 if (!bXRefStream) {
1702 if (m_File.AppendString("trailer\r\n<<") < 0) { 1701 if (m_File.AppendString("trailer\r\n<<") < 0) {
1703 return -1; 1702 return -1;
1704 } 1703 }
1705 } else { 1704 } else {
1706 if (m_File.AppendDWord(m_pDocument->GetLastObjNum() + 1) < 0) { 1705 if (m_File.AppendDWord(m_pDocument->GetLastObjNum() + 1) < 0) {
1707 return -1; 1706 return -1;
1708 } 1707 }
1709 if (m_File.AppendString(" 0 obj <<") < 0) { 1708 if (m_File.AppendString(" 0 obj <<") < 0) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 m_Offset = 0; 1917 m_Offset = 0;
1919 m_dwLastObjNum = m_pDocument->GetLastObjNum(); 1918 m_dwLastObjNum = m_pDocument->GetLastObjNum();
1920 m_ObjectOffset.Clear(); 1919 m_ObjectOffset.Clear();
1921 m_NewObjNumArray.RemoveAll(); 1920 m_NewObjNumArray.RemoveAll();
1922 InitID(); 1921 InitID();
1923 if (flags & FPDFCREATE_PROGRESSIVE) 1922 if (flags & FPDFCREATE_PROGRESSIVE)
1924 return true; 1923 return true;
1925 return Continue(nullptr) > -1; 1924 return Continue(nullptr) > -1;
1926 } 1925 }
1927 1926
1928 void CPDF_Creator::InitID(FX_BOOL bDefault) { 1927 void CPDF_Creator::InitID(bool bDefault) {
1929 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr; 1928 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : nullptr;
1930 FX_BOOL bNewId = !m_pIDArray; 1929 bool bNewId = !m_pIDArray;
1931 if (bNewId) { 1930 if (bNewId) {
1932 m_pIDArray.reset(new CPDF_Array); 1931 m_pIDArray.reset(new CPDF_Array);
1933 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr; 1932 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr;
1934 if (pID1) { 1933 if (pID1) {
1935 m_pIDArray->Add(pID1->Clone()); 1934 m_pIDArray->Add(pID1->Clone());
1936 } else { 1935 } else {
1937 std::vector<uint8_t> buffer = 1936 std::vector<uint8_t> buffer =
1938 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); 1937 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum);
1939 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); 1938 CFX_ByteString bsBuffer(buffer.data(), buffer.size());
1940 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); 1939 m_pIDArray->Add(new CPDF_String(bsBuffer, true));
1941 } 1940 }
1942 } 1941 }
1943 if (!bDefault) { 1942 if (!bDefault) {
1944 return; 1943 return;
1945 } 1944 }
1946 if (pOldIDArray) { 1945 if (pOldIDArray) {
1947 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1); 1946 CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1);
1948 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { 1947 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) {
1949 m_pIDArray->Add(pID2->Clone()); 1948 m_pIDArray->Add(pID2->Clone());
1950 return; 1949 return;
1951 } 1950 }
1952 std::vector<uint8_t> buffer = 1951 std::vector<uint8_t> buffer =
1953 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); 1952 PDF_GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum);
1954 CFX_ByteString bsBuffer(buffer.data(), buffer.size()); 1953 CFX_ByteString bsBuffer(buffer.data(), buffer.size());
1955 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE)); 1954 m_pIDArray->Add(new CPDF_String(bsBuffer, true));
1956 return; 1955 return;
1957 } 1956 }
1958 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); 1957 m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone());
1959 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { 1958 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) {
1960 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { 1959 if (m_pEncryptDict->GetStringFor("Filter") == "Standard") {
1961 CFX_ByteString user_pass = m_pParser->GetPassword(); 1960 CFX_ByteString user_pass = m_pParser->GetPassword();
1962 uint32_t flag = PDF_ENCRYPT_CONTENT; 1961 uint32_t flag = PDF_ENCRYPT_CONTENT;
1963 1962
1964 CPDF_SecurityHandler handler; 1963 CPDF_SecurityHandler handler;
1965 handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(), 1964 handler.OnCreate(m_pEncryptDict, m_pIDArray.get(), user_pass.raw_str(),
1966 user_pass.GetLength(), flag); 1965 user_pass.GetLength(), flag);
1967 if (m_bLocalCryptoHandler) 1966 if (m_bLocalCryptoHandler)
1968 delete m_pCryptoHandler; 1967 delete m_pCryptoHandler;
1969 m_pCryptoHandler = new CPDF_CryptoHandler; 1968 m_pCryptoHandler = new CPDF_CryptoHandler;
1970 m_pCryptoHandler->Init(m_pEncryptDict, &handler); 1969 m_pCryptoHandler->Init(m_pEncryptDict, &handler);
1971 m_bLocalCryptoHandler = TRUE; 1970 m_bLocalCryptoHandler = true;
1972 m_bSecurityChanged = TRUE; 1971 m_bSecurityChanged = true;
1973 } 1972 }
1974 } 1973 }
1975 } 1974 }
1976 int32_t CPDF_Creator::Continue(IFX_Pause* pPause) { 1975 int32_t CPDF_Creator::Continue(IFX_Pause* pPause) {
1977 if (m_iStage < 0) { 1976 if (m_iStage < 0) {
1978 return m_iStage; 1977 return m_iStage;
1979 } 1978 }
1980 int32_t iRet = 0; 1979 int32_t iRet = 0;
1981 while (m_iStage < 100) { 1980 while (m_iStage < 100) {
1982 if (m_iStage < 20) { 1981 if (m_iStage < 20) {
1983 iRet = WriteDoc_Stage1(pPause); 1982 iRet = WriteDoc_Stage1(pPause);
1984 } else if (m_iStage < 30) { 1983 } else if (m_iStage < 30) {
1985 iRet = WriteDoc_Stage2(pPause); 1984 iRet = WriteDoc_Stage2(pPause);
1986 } else if (m_iStage < 90) { 1985 } else if (m_iStage < 90) {
1987 iRet = WriteDoc_Stage3(pPause); 1986 iRet = WriteDoc_Stage3(pPause);
1988 } else { 1987 } else {
1989 iRet = WriteDoc_Stage4(pPause); 1988 iRet = WriteDoc_Stage4(pPause);
1990 } 1989 }
1991 if (iRet < m_iStage) { 1990 if (iRet < m_iStage) {
1992 break; 1991 break;
1993 } 1992 }
1994 } 1993 }
1995 if (iRet < 1 || m_iStage == 100) { 1994 if (iRet < 1 || m_iStage == 100) {
1996 m_iStage = -1; 1995 m_iStage = -1;
1997 Clear(); 1996 Clear();
1998 return iRet > 99 ? 0 : (iRet < 1 ? -1 : iRet); 1997 return iRet > 99 ? 0 : (iRet < 1 ? -1 : iRet);
1999 } 1998 }
2000 return m_iStage; 1999 return m_iStage;
2001 } 2000 }
2002 FX_BOOL CPDF_Creator::SetFileVersion(int32_t fileVersion) { 2001 bool CPDF_Creator::SetFileVersion(int32_t fileVersion) {
2003 if (fileVersion < 10 || fileVersion > 17) { 2002 if (fileVersion < 10 || fileVersion > 17) {
2004 return FALSE; 2003 return false;
2005 } 2004 }
2006 m_FileVersion = fileVersion; 2005 m_FileVersion = fileVersion;
2007 return TRUE; 2006 return true;
2008 } 2007 }
2009 void CPDF_Creator::RemoveSecurity() { 2008 void CPDF_Creator::RemoveSecurity() {
2010 ResetStandardSecurity(); 2009 ResetStandardSecurity();
2011 m_bSecurityChanged = TRUE; 2010 m_bSecurityChanged = true;
2012 m_pEncryptDict = nullptr; 2011 m_pEncryptDict = nullptr;
2013 m_pCryptoHandler = nullptr; 2012 m_pCryptoHandler = nullptr;
2014 } 2013 }
2015 void CPDF_Creator::ResetStandardSecurity() { 2014 void CPDF_Creator::ResetStandardSecurity() {
2016 if (!m_bLocalCryptoHandler) 2015 if (!m_bLocalCryptoHandler)
2017 return; 2016 return;
2018 2017
2019 delete m_pCryptoHandler; 2018 delete m_pCryptoHandler;
2020 m_pCryptoHandler = nullptr; 2019 m_pCryptoHandler = nullptr;
2021 m_bLocalCryptoHandler = FALSE; 2020 m_bLocalCryptoHandler = false;
2022 } 2021 }
OLDNEW
« no previous file with comments | « core/fpdfapi/edit/editint.h ('k') | core/fpdfapi/font/cpdf_cidfont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698