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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_BOOL bCompress) { | |
194 FX_FILESIZE offset = 0; | 193 FX_FILESIZE offset = 0; |
195 int32_t len = 0; | 194 int32_t len = 0; |
196 ASSERT(pDocument && pFile); | 195 ASSERT(pDocument && pFile); |
Tom Sepez
2016/05/13 20:05:11
nit: pDocument de-ref'd below, move pFile assert a
Lei Zhang
2016/05/14 01:06:33
pFile also gets deref'd before being passed to any
| |
197 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); | 196 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); |
Tom Sepez
2016/05/13 20:05:11
nit: cast not needed.
Lei Zhang
2016/05/14 01:06:33
Done.
| |
198 if (pParser) { | 197 if (pParser) { |
199 CPDF_Dictionary* p = pParser->GetTrailer(); | 198 CPDF_Dictionary* p = pParser->GetTrailer(); |
200 for (const auto& it : *p) { | 199 for (const auto& it : *p) { |
201 const CFX_ByteString& key = it.first; | 200 const CFX_ByteString& key = it.first; |
202 CPDF_Object* pValue = it.second; | 201 CPDF_Object* pValue = it.second; |
203 if (key == "Encrypt" || key == "Size" || key == "Filter" || | 202 if (key == "Encrypt" || key == "Size" || key == "Filter" || |
204 key == "Index" || key == "Length" || key == "Prev" || key == "W" || | 203 key == "Index" || key == "Length" || key == "Prev" || key == "W" || |
205 key == "XRefStm" || key == "Type" || key == "ID") { | 204 key == "XRefStm" || key == "Type" || key == "ID") { |
206 continue; | 205 continue; |
207 } | 206 } |
208 if (bCompress && key == "DecodeParms") { | 207 if (key == "DecodeParms") |
209 continue; | 208 continue; |
210 } | 209 |
211 if (pFile->AppendString(("/")) < 0) { | 210 if (pFile->AppendString(("/")) < 0) { |
Tom Sepez
2016/05/13 20:05:11
nit: OK, we can leave all these extra {} for anoth
Lei Zhang
2016/05/14 01:06:33
There's too many in this file. Another day.
| |
212 return -1; | 211 return -1; |
213 } | 212 } |
214 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) { | 213 if ((len = pFile->AppendString(PDF_NameEncode(key).AsStringC())) < 0) { |
215 return -1; | 214 return -1; |
216 } | 215 } |
217 offset += len + 1; | 216 offset += len + 1; |
218 if (pValue->GetObjNum()) { | 217 if (pValue->GetObjNum()) { |
219 if (pFile->AppendString(" ") < 0) { | 218 if (pFile->AppendString(" ") < 0) { |
220 return -1; | 219 return -1; |
221 } | 220 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 return -1; | 569 return -1; |
571 } | 570 } |
572 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { | 571 if ((len = pFile->AppendDWord((uint32_t)tempBuffer.GetLength())) < 0) { |
573 return -1; | 572 return -1; |
574 } | 573 } |
575 if (pFile->AppendString("/Length ") < 0) { | 574 if (pFile->AppendString("/Length ") < 0) { |
576 return -1; | 575 return -1; |
577 } | 576 } |
578 offset += len + 15; | 577 offset += len + 15; |
579 | 578 |
580 if (!pCreator->m_bCompress && !pCreator->m_pCryptoHandler) { | 579 tempBuffer << m_Buffer; |
581 if ((len = pFile->AppendDWord( | 580 CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(), |
582 (uint32_t)(tempBuffer.GetLength() + m_Buffer.GetLength()))) < 0) { | 581 TRUE); |
583 return -1; | 582 CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler, m_dwObjNum, |
584 } | 583 encoder.m_pData, encoder.m_dwSize); |
585 offset += len; | 584 if ((len = pFile->AppendDWord(encryptor.m_dwSize)) < 0) { |
586 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 585 return -1; |
587 return -1; | |
588 } | |
589 if (pFile->AppendBlock(tempBuffer.GetBuffer(), tempBuffer.GetLength()) < | |
590 0) { | |
591 return -1; | |
592 } | |
593 if (pFile->AppendBlock(m_Buffer.GetBuffer(), m_Buffer.GetLength()) < 0) { | |
594 return -1; | |
595 } | |
596 offset += len + tempBuffer.GetLength() + m_Buffer.GetLength(); | |
597 } else { | |
598 tempBuffer << m_Buffer; | |
599 CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(), | |
600 pCreator->m_bCompress); | |
601 CPDF_Encryptor encryptor(pCreator->m_pCryptoHandler, m_dwObjNum, | |
602 encoder.m_pData, encoder.m_dwSize); | |
603 if ((len = pFile->AppendDWord(encryptor.m_dwSize)) < 0) { | |
604 return -1; | |
605 } | |
606 offset += len; | |
607 if (pCreator->m_bCompress) { | |
608 if (pFile->AppendString("/Filter /FlateDecode") < 0) { | |
609 return -1; | |
610 } | |
611 offset += 20; | |
612 } | |
613 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | |
614 return -1; | |
615 } | |
616 if (pFile->AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { | |
617 return -1; | |
618 } | |
619 offset += len + encryptor.m_dwSize; | |
620 } | 586 } |
587 offset += len; | |
588 if (pFile->AppendString("/Filter /FlateDecode") < 0) { | |
589 return -1; | |
590 } | |
591 offset += 20; | |
592 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | |
593 return -1; | |
594 } | |
595 if (pFile->AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { | |
596 return -1; | |
597 } | |
598 offset += len + encryptor.m_dwSize; | |
621 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) { | 599 if ((len = pFile->AppendString("\r\nendstream\r\nendobj\r\n")) < 0) { |
622 return -1; | 600 return -1; |
623 } | 601 } |
624 offset += len; | 602 offset += len; |
625 return ObjOffset; | 603 return ObjOffset; |
626 } | 604 } |
627 CPDF_XRefStream::CPDF_XRefStream() | 605 CPDF_XRefStream::CPDF_XRefStream() |
628 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} | 606 : m_PrevOffset(0), m_dwTempObjNum(0), m_iSeg(0) {} |
629 FX_BOOL CPDF_XRefStream::Start() { | 607 FX_BOOL CPDF_XRefStream::Start() { |
630 m_IndexArray.clear(); | 608 m_IndexArray.clear(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 FX_CHAR offset_buf[20]; | 780 FX_CHAR offset_buf[20]; |
803 FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); | 781 FXSYS_memset(offset_buf, 0, sizeof(offset_buf)); |
804 FXSYS_i64toa(m_PrevOffset, offset_buf, 10); | 782 FXSYS_i64toa(m_PrevOffset, offset_buf, 10); |
805 int32_t len = (int32_t)FXSYS_strlen(offset_buf); | 783 int32_t len = (int32_t)FXSYS_strlen(offset_buf); |
806 if (pFile->AppendBlock(offset_buf, len) < 0) { | 784 if (pFile->AppendBlock(offset_buf, len) < 0) { |
807 return FALSE; | 785 return FALSE; |
808 } | 786 } |
809 offset += len + 6; | 787 offset += len + 6; |
810 } | 788 } |
811 FX_BOOL bPredictor = TRUE; | 789 FX_BOOL bPredictor = TRUE; |
812 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), | 790 CPDF_FlateEncoder encoder(m_Buffer.GetBuffer(), m_Buffer.GetLength(), TRUE, |
813 pCreator->m_bCompress, bPredictor); | 791 bPredictor); |
814 if (pCreator->m_bCompress) { | 792 if (pFile->AppendString("/Filter /FlateDecode") < 0) { |
815 if (pFile->AppendString("/Filter /FlateDecode") < 0) { | 793 return FALSE; |
794 } | |
795 offset += 20; | |
796 if (bPredictor) { | |
797 if ((len = pFile->AppendString("/DecodeParms<</Columns 7/Predictor 12>>")) < | |
798 0) { | |
816 return FALSE; | 799 return FALSE; |
817 } | 800 } |
818 offset += 20; | 801 offset += len; |
819 if (bPredictor) { | |
820 if ((len = pFile->AppendString( | |
821 "/DecodeParms<</Columns 7/Predictor 12>>")) < 0) { | |
822 return FALSE; | |
823 } | |
824 offset += len; | |
825 } | |
826 } | 802 } |
827 if (pFile->AppendString("/Length ") < 0) { | 803 if (pFile->AppendString("/Length ") < 0) { |
828 return FALSE; | 804 return FALSE; |
829 } | 805 } |
830 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) { | 806 if ((len = pFile->AppendDWord(encoder.m_dwSize)) < 0) { |
831 return FALSE; | 807 return FALSE; |
832 } | 808 } |
833 offset += len + 8; | 809 offset += len + 8; |
834 if (bEOF) { | 810 if (bEOF) { |
835 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, | 811 if ((len = PDF_CreatorWriteTrailer(pCreator->m_pDocument, pFile, |
836 pCreator->m_pIDArray, | 812 pCreator->m_pIDArray)) < 0) { |
837 pCreator->m_bCompress)) < 0) { | |
838 return FALSE; | 813 return FALSE; |
839 } | 814 } |
840 offset += len; | 815 offset += len; |
841 if (pCreator->m_pEncryptDict) { | 816 if (pCreator->m_pEncryptDict) { |
842 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); | 817 uint32_t dwEncryptObjNum = pCreator->m_pEncryptDict->GetObjNum(); |
843 if (dwEncryptObjNum == 0) { | 818 if (dwEncryptObjNum == 0) { |
844 dwEncryptObjNum = pCreator->m_dwEnryptObjNum; | 819 dwEncryptObjNum = pCreator->m_dwEncryptObjNum; |
845 } | 820 } |
846 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, | 821 if ((len = PDF_CreatorWriteEncrypt(pCreator->m_pEncryptDict, |
847 dwEncryptObjNum, pFile)) < 0) { | 822 dwEncryptObjNum, pFile)) < 0) { |
848 return FALSE; | 823 return FALSE; |
849 } | 824 } |
850 offset += len; | 825 offset += len; |
851 } | 826 } |
852 } | 827 } |
853 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { | 828 if ((len = pFile->AppendString(">>stream\r\n")) < 0) { |
854 return FALSE; | 829 return FALSE; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 if (m_IndexArray.empty()) { | 868 if (m_IndexArray.empty()) { |
894 m_IndexArray.push_back({objnum, 1}); | 869 m_IndexArray.push_back({objnum, 1}); |
895 return; | 870 return; |
896 } | 871 } |
897 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; | 872 uint32_t next_objnum = m_IndexArray.back().objnum + m_IndexArray.back().count; |
898 if (objnum == next_objnum) | 873 if (objnum == next_objnum) |
899 m_IndexArray.back().count += 1; | 874 m_IndexArray.back().count += 1; |
900 else | 875 else |
901 m_IndexArray.push_back({objnum, 1}); | 876 m_IndexArray.push_back({objnum, 1}); |
902 } | 877 } |
903 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) { | 878 |
904 m_pDocument = pDoc; | 879 CPDF_Creator::CPDF_Creator(CPDF_Document* pDoc) |
905 m_pParser = (CPDF_Parser*)pDoc->m_pParser; | 880 : m_pDocument(pDoc), |
906 m_bCompress = TRUE; | 881 m_pParser(pDoc->GetParser()), |
907 if (m_pParser) { | 882 m_bSecurityChanged(FALSE), |
908 m_pEncryptDict = m_pParser->GetEncryptDict(); | 883 m_pEncryptDict(m_pParser ? m_pParser->GetEncryptDict() : nullptr), |
909 m_pCryptoHandler = m_pParser->GetCryptoHandler(); | 884 m_dwEncryptObjNum(0), |
910 } else { | 885 m_pCryptoHandler(m_pParser ? m_pParser->GetCryptoHandler() : nullptr), |
911 m_pEncryptDict = nullptr; | 886 m_pMetadata(nullptr), |
912 m_pCryptoHandler = nullptr; | 887 m_ObjectStreamSize(200), |
913 } | 888 m_dwLastObjNum(m_pDocument->GetLastObjNum()), |
914 m_bSecurityChanged = FALSE; | 889 m_Offset(0), |
915 m_pMetadata = nullptr; | 890 m_iStage(-1), |
916 m_bEncryptCloned = FALSE; | 891 m_dwFlags(0), |
917 m_bEncryptMetadata = FALSE; | 892 m_Pos(nullptr), |
918 m_Offset = 0; | 893 m_XrefStart(0), |
919 m_iStage = -1; | 894 m_pIDArray(nullptr), |
920 m_dwFlags = 0; | 895 m_FileVersion(0) {} |
921 m_Pos = nullptr; | 896 |
922 m_XrefStart = 0; | |
923 m_pXRefStream = nullptr; | |
924 m_ObjectStreamSize = 200; | |
925 m_dwLastObjNum = m_pDocument->GetLastObjNum(); | |
926 m_pIDArray = nullptr; | |
927 m_FileVersion = 0; | |
928 m_dwEnryptObjNum = 0; | |
929 m_bLocalCryptoHandler = FALSE; | |
930 } | |
931 CPDF_Creator::~CPDF_Creator() { | 897 CPDF_Creator::~CPDF_Creator() { |
932 ResetStandardSecurity(); | 898 ResetStandardSecurity(); |
933 if (m_bEncryptCloned && m_pEncryptDict) { | 899 if (m_bEncryptCloned && m_pEncryptDict) { |
934 m_pEncryptDict->Release(); | 900 m_pEncryptDict->Release(); |
935 m_pEncryptDict = NULL; | 901 m_pEncryptDict = NULL; |
936 } | 902 } |
937 Clear(); | 903 Clear(); |
938 } | 904 } |
939 | 905 |
940 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 906 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
(...skipping 19 matching lines...) Expand all Loading... | |
960 return 1; | 926 return 1; |
961 if (pDict->IsSignatureDict()) | 927 if (pDict->IsSignatureDict()) |
962 return 1; | 928 return 1; |
963 if (pDict->GetStringBy("Type") == "Page") | 929 if (pDict->GetStringBy("Type") == "Page") |
964 return 1; | 930 return 1; |
965 } | 931 } |
966 | 932 |
967 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 933 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
968 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 934 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
969 return -1; | 935 return -1; |
970 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 936 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) |
971 return 0; | 937 return 0; |
972 if (!m_pXRefStream->End(this)) | 938 if (!m_pXRefStream->End(this)) |
973 return -1; | 939 return -1; |
974 if (!m_pXRefStream->Start()) | 940 if (!m_pXRefStream->Start()) |
975 return -1; | 941 return -1; |
976 return 0; | 942 return 0; |
977 } | 943 } |
978 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, | 944 int32_t CPDF_Creator::WriteIndirectObjectToStream(uint32_t objnum, |
979 const uint8_t* pBuffer, | 945 const uint8_t* pBuffer, |
980 uint32_t dwSize) { | 946 uint32_t dwSize) { |
981 if (!m_pXRefStream) { | 947 if (!m_pXRefStream) { |
982 return 1; | 948 return 1; |
983 } | 949 } |
984 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 950 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
985 int32_t iRet = | 951 int32_t iRet = |
986 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 952 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
987 if (iRet < 1) { | 953 if (iRet < 1) { |
988 return iRet; | 954 return iRet; |
989 } | 955 } |
990 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 956 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
991 return 0; | 957 return 0; |
992 } | 958 } |
993 if (!m_pXRefStream->End(this)) { | 959 if (!m_pXRefStream->End(this)) { |
994 return -1; | 960 return -1; |
995 } | 961 } |
996 if (!m_pXRefStream->Start()) { | 962 if (!m_pXRefStream->Start()) { |
997 return -1; | 963 return -1; |
998 } | 964 } |
999 return 0; | 965 return 0; |
1000 } | 966 } |
1001 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { | 967 int32_t CPDF_Creator::AppendObjectNumberToXRef(uint32_t objnum) { |
1002 if (!m_pXRefStream) { | 968 if (!m_pXRefStream) { |
1003 return 1; | 969 return 1; |
1004 } | 970 } |
1005 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 971 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
1006 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 972 if (!IsXRefNeedEnd(m_pXRefStream.get(), m_dwFlags)) { |
1007 return 0; | 973 return 0; |
1008 } | 974 } |
1009 if (!m_pXRefStream->End(this)) { | 975 if (!m_pXRefStream->End(this)) { |
1010 return -1; | 976 return -1; |
1011 } | 977 } |
1012 if (!m_pXRefStream->Start()) { | 978 if (!m_pXRefStream->Start()) { |
1013 return -1; | 979 return -1; |
1014 } | 980 } |
1015 return 0; | 981 return 0; |
1016 } | 982 } |
1017 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, | 983 int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream, |
1018 uint32_t objnum, | 984 uint32_t objnum, |
1019 CPDF_CryptoHandler* pCrypto) { | 985 CPDF_CryptoHandler* pCrypto) { |
1020 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pStream->AsStream()), | 986 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pStream->AsStream()), |
1021 pStream == m_pMetadata ? FALSE : m_bCompress); | 987 pStream != m_pMetadata); |
1022 CPDF_Encryptor encryptor(pCrypto, objnum, encoder.m_pData, encoder.m_dwSize); | 988 CPDF_Encryptor encryptor(pCrypto, objnum, encoder.m_pData, encoder.m_dwSize); |
1023 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { | 989 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != encryptor.m_dwSize) { |
1024 encoder.CloneDict(); | 990 encoder.CloneDict(); |
1025 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 991 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
1026 } | 992 } |
1027 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 993 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
1028 return -1; | 994 return -1; |
1029 } | 995 } |
1030 int len = m_File.AppendString("stream\r\n"); | 996 int len = m_File.AppendString("stream\r\n"); |
1031 if (len < 0) { | 997 if (len < 0) { |
(...skipping 15 matching lines...) Expand all Loading... | |
1047 int32_t len = m_File.AppendDWord(objnum); | 1013 int32_t len = m_File.AppendDWord(objnum); |
1048 if (len < 0) | 1014 if (len < 0) |
1049 return -1; | 1015 return -1; |
1050 | 1016 |
1051 m_Offset += len; | 1017 m_Offset += len; |
1052 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) | 1018 if ((len = m_File.AppendString(" 0 obj\r\n")) < 0) |
1053 return -1; | 1019 return -1; |
1054 | 1020 |
1055 m_Offset += len; | 1021 m_Offset += len; |
1056 if (pObj->IsStream()) { | 1022 if (pObj->IsStream()) { |
1057 CPDF_CryptoHandler* pHandler = (pObj == m_pMetadata && !m_bEncryptMetadata) | 1023 CPDF_CryptoHandler* pHandler = |
1058 ? nullptr | 1024 (pObj != m_pMetadata) ? m_pCryptoHandler : nullptr; |
Tom Sepez
2016/05/13 20:05:11
nit: overparenthesized.
Lei Zhang
2016/05/14 01:06:33
Done.
| |
1059 : m_pCryptoHandler; | |
1060 if (WriteStream(pObj, objnum, pHandler) < 0) | 1025 if (WriteStream(pObj, objnum, pHandler) < 0) |
1061 return -1; | 1026 return -1; |
1062 } else { | 1027 } else { |
1063 if (WriteDirectObj(objnum, pObj) < 0) | 1028 if (WriteDirectObj(objnum, pObj) < 0) |
1064 return -1; | 1029 return -1; |
1065 } | 1030 } |
1066 if ((len = m_File.AppendString("\r\nendobj\r\n")) < 0) | 1031 if ((len = m_File.AppendString("\r\nendobj\r\n")) < 0) |
1067 return -1; | 1032 return -1; |
1068 | 1033 |
1069 m_Offset += len; | 1034 m_Offset += len; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), | 1088 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), |
1124 bHex); | 1089 bHex); |
1125 if ((len = m_File.AppendString(content.AsStringC())) < 0) { | 1090 if ((len = m_File.AppendString(content.AsStringC())) < 0) { |
1126 return -1; | 1091 return -1; |
1127 } | 1092 } |
1128 m_Offset += len; | 1093 m_Offset += len; |
1129 break; | 1094 break; |
1130 } | 1095 } |
1131 case CPDF_Object::STREAM: { | 1096 case CPDF_Object::STREAM: { |
1132 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), | 1097 CPDF_FlateEncoder encoder(const_cast<CPDF_Stream*>(pObj->AsStream()), |
1133 m_bCompress); | 1098 TRUE); |
1134 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData, | 1099 CPDF_Encryptor encryptor(m_pCryptoHandler, objnum, encoder.m_pData, |
1135 encoder.m_dwSize); | 1100 encoder.m_dwSize); |
1136 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != | 1101 if ((uint32_t)encoder.m_pDict->GetIntegerBy("Length") != |
1137 encryptor.m_dwSize) { | 1102 encryptor.m_dwSize) { |
1138 encoder.CloneDict(); | 1103 encoder.CloneDict(); |
1139 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1104 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
1140 } | 1105 } |
1141 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1106 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
1142 return -1; | 1107 return -1; |
1143 } | 1108 } |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1471 if (m_iStage == 0) { | 1436 if (m_iStage == 0) { |
1472 if (!m_pParser) { | 1437 if (!m_pParser) { |
1473 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1438 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1474 } | 1439 } |
1475 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { | 1440 if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { |
1476 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; | 1441 m_dwFlags &= ~FPDFCREATE_INCREMENTAL; |
1477 } | 1442 } |
1478 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1443 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
1479 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; | 1444 m_pMetadata = pDict ? pDict->GetDirectObjectBy("Metadata") : NULL; |
1480 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { | 1445 if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { |
1481 m_pXRefStream = new CPDF_XRefStream; | 1446 m_pXRefStream.reset(new CPDF_XRefStream); |
1482 m_pXRefStream->Start(); | 1447 m_pXRefStream->Start(); |
1483 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { | 1448 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser) { |
1484 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); | 1449 FX_FILESIZE prev = m_pParser->GetLastXRefOffset(); |
1485 m_pXRefStream->m_PrevOffset = prev; | 1450 m_pXRefStream->m_PrevOffset = prev; |
1486 } | 1451 } |
1487 } | 1452 } |
1488 m_iStage = 10; | 1453 m_iStage = 10; |
1489 } | 1454 } |
1490 if (m_iStage == 10) { | 1455 if (m_iStage == 10) { |
1491 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { | 1456 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) == 0) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1592 } | 1557 } |
1593 if (m_iStage == 27) { | 1558 if (m_iStage == 27) { |
1594 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { | 1559 if (NULL != m_pEncryptDict && 0 == m_pEncryptDict->GetObjNum()) { |
1595 m_dwLastObjNum += 1; | 1560 m_dwLastObjNum += 1; |
1596 FX_FILESIZE saveOffset = m_Offset; | 1561 FX_FILESIZE saveOffset = m_Offset; |
1597 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { | 1562 if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { |
1598 return -1; | 1563 return -1; |
1599 } | 1564 } |
1600 m_ObjectOffset.Add(m_dwLastObjNum, 1); | 1565 m_ObjectOffset.Add(m_dwLastObjNum, 1); |
1601 m_ObjectOffset[m_dwLastObjNum] = saveOffset; | 1566 m_ObjectOffset[m_dwLastObjNum] = saveOffset; |
1602 m_dwEnryptObjNum = m_dwLastObjNum; | 1567 m_dwEncryptObjNum = m_dwLastObjNum; |
1603 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { | 1568 if (m_dwFlags & FPDFCREATE_INCREMENTAL) { |
1604 m_NewObjNumArray.Add(m_dwLastObjNum); | 1569 m_NewObjNumArray.Add(m_dwLastObjNum); |
1605 } | 1570 } |
1606 } | 1571 } |
1607 m_iStage = 80; | 1572 m_iStage = 80; |
1608 } | 1573 } |
1609 return m_iStage; | 1574 return m_iStage; |
1610 } | 1575 } |
1611 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { | 1576 int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) { |
1612 ASSERT(m_iStage >= 80 || m_iStage < 90); | 1577 ASSERT(m_iStage >= 80 || m_iStage < 90); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1922 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { | 1887 if (m_File.AppendBlock(offset_buf, FXSYS_strlen(offset_buf)) < 0) { |
1923 return -1; | 1888 return -1; |
1924 } | 1889 } |
1925 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { | 1890 if (m_File.AppendString("\r\n%%EOF\r\n") < 0) { |
1926 return -1; | 1891 return -1; |
1927 } | 1892 } |
1928 m_File.Flush(); | 1893 m_File.Flush(); |
1929 return m_iStage = 100; | 1894 return m_iStage = 100; |
1930 } | 1895 } |
1931 void CPDF_Creator::Clear() { | 1896 void CPDF_Creator::Clear() { |
1932 delete m_pXRefStream; | 1897 m_pXRefStream.reset(); |
1933 m_pXRefStream = NULL; | |
1934 m_File.Clear(); | 1898 m_File.Clear(); |
1935 m_NewObjNumArray.RemoveAll(); | 1899 m_NewObjNumArray.RemoveAll(); |
1936 if (m_pIDArray) { | 1900 if (m_pIDArray) { |
1937 m_pIDArray->Release(); | 1901 m_pIDArray->Release(); |
1938 m_pIDArray = NULL; | 1902 m_pIDArray = NULL; |
1939 } | 1903 } |
1940 } | 1904 } |
1941 | 1905 |
1942 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { | 1906 bool CPDF_Creator::Create(IFX_StreamWrite* pFile, uint32_t flags) { |
1943 m_File.AttachFile(pFile); | 1907 m_File.AttachFile(pFile); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 m_pCryptoHandler = nullptr; | 2009 m_pCryptoHandler = nullptr; |
2046 } | 2010 } |
2047 void CPDF_Creator::ResetStandardSecurity() { | 2011 void CPDF_Creator::ResetStandardSecurity() { |
2048 if (!m_bLocalCryptoHandler) | 2012 if (!m_bLocalCryptoHandler) |
2049 return; | 2013 return; |
2050 | 2014 |
2051 delete m_pCryptoHandler; | 2015 delete m_pCryptoHandler; |
2052 m_pCryptoHandler = nullptr; | 2016 m_pCryptoHandler = nullptr; |
2053 m_bLocalCryptoHandler = FALSE; | 2017 m_bLocalCryptoHandler = FALSE; |
2054 } | 2018 } |
OLD | NEW |