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 "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 | 656 |
657 CFPDF_FileStream fileWrite(pFileHandler); | 657 CFPDF_FileStream fileWrite(pFileHandler); |
658 CFX_ByteString content; | 658 CFX_ByteString content; |
659 if (fileType == FXFA_SAVEAS_XML) { | 659 if (fileType == FXFA_SAVEAS_XML) { |
660 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 660 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
661 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | 661 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), |
662 content.GetLength()); | 662 content.GetLength()); |
663 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, | 663 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, |
664 nullptr); | 664 nullptr); |
665 } else if (fileType == FXFA_SAVEAS_XDP) { | 665 } else if (fileType == FXFA_SAVEAS_XDP) { |
666 if (m_pPDFDoc == NULL) | 666 if (!m_pPDFDoc) |
667 return; | 667 return; |
668 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | 668 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); |
669 if (pRoot == NULL) | 669 if (!pRoot) |
670 return; | 670 return; |
671 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 671 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
672 if (NULL == pAcroForm) | 672 if (!pAcroForm) |
673 return; | 673 return; |
674 CPDF_Object* pXFA = pAcroForm->GetObjectBy("XFA"); | 674 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); |
675 if (pXFA == NULL) | 675 if (!pArray) |
676 return; | 676 return; |
677 if (!pXFA->IsArray()) | 677 |
678 return; | |
679 CPDF_Array* pArray = pXFA->GetArray(); | |
680 if (NULL == pArray) | |
681 return; | |
682 int size = pArray->GetCount(); | 678 int size = pArray->GetCount(); |
683 for (int i = 1; i < size; i += 2) { | 679 for (int i = 1; i < size; i += 2) { |
684 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | 680 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
685 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | 681 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
686 if (!pPrePDFObj->IsString()) | 682 if (!pPrePDFObj->IsString()) |
687 continue; | 683 continue; |
688 if (!pPDFObj->IsReference()) | 684 if (!pPDFObj->IsReference()) |
689 continue; | 685 continue; |
690 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | 686 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); |
691 if (!pDirectObj->IsStream()) | 687 if (!pDirectObj->IsStream()) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return FALSE; | 941 return FALSE; |
946 | 942 |
947 CFX_ByteString content; | 943 CFX_ByteString content; |
948 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 944 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
949 if (!pEnv) | 945 if (!pEnv) |
950 return FALSE; | 946 return FALSE; |
951 | 947 |
952 CFPDF_FileStream fileStream(pFileHandler); | 948 CFPDF_FileStream fileStream(pFileHandler); |
953 | 949 |
954 if (fileType == FXFA_SAVEAS_XML) { | 950 if (fileType == FXFA_SAVEAS_XML) { |
955 const char* content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 951 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
956 fileStream.WriteBlock(content, 0, strlen(content)); | 952 fileStream.WriteBlock(kContent, 0, strlen(kContent)); |
957 m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); | 953 m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); |
958 } else if (fileType == FXFA_SAVEAS_XDP) { | 954 return TRUE; |
959 if (flag == 0) | 955 } |
960 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | 956 |
961 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | 957 if (fileType != FXFA_SAVEAS_XDP) |
962 if (m_pPDFDoc == NULL) { | 958 return TRUE; |
963 fileStream.Flush(); | 959 |
964 return FALSE; | 960 if (!flag) { |
965 } | 961 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
966 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | 962 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
967 if (pRoot == NULL) { | 963 } |
968 fileStream.Flush(); | 964 if (!m_pPDFDoc) { |
969 return FALSE; | 965 fileStream.Flush(); |
970 } | 966 return FALSE; |
971 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 967 } |
972 if (NULL == pAcroForm) { | 968 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); |
973 fileStream.Flush(); | 969 if (!pRoot) { |
974 return FALSE; | 970 fileStream.Flush(); |
975 } | 971 return FALSE; |
976 CPDF_Object* pXFA = pAcroForm->GetObjectBy("XFA"); | 972 } |
977 if (pXFA == NULL) { | 973 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
978 fileStream.Flush(); | 974 if (!pAcroForm) { |
979 return FALSE; | 975 fileStream.Flush(); |
980 } | 976 return FALSE; |
981 if (!pXFA->IsArray()) { | 977 } |
982 fileStream.Flush(); | 978 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); |
983 return FALSE; | 979 if (!pArray) { |
984 } | 980 fileStream.Flush(); |
985 CPDF_Array* pArray = pXFA->GetArray(); | 981 return FALSE; |
986 if (NULL == pArray) { | 982 } |
987 fileStream.Flush(); | 983 |
988 return FALSE; | 984 int size = pArray->GetCount(); |
989 } | 985 for (int i = 1; i < size; i += 2) { |
990 int size = pArray->GetCount(); | 986 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
991 for (int i = 1; i < size; i += 2) { | 987 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
992 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | 988 if (!pPrePDFObj->IsString()) |
993 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | 989 continue; |
994 if (!pPrePDFObj->IsString()) | 990 if (!pPDFObj->IsReference()) |
995 continue; | 991 continue; |
996 if (!pPDFObj->IsReference()) | 992 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); |
997 continue; | 993 if (!pDirectObj->IsStream()) |
998 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | 994 continue; |
999 if (!pDirectObj->IsStream()) | 995 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) |
1000 continue; | 996 continue; |
1001 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) | 997 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) |
1002 continue; | 998 continue; |
1003 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) | 999 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) |
1004 continue; | 1000 continue; |
1005 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) | 1001 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) |
1006 continue; | 1002 continue; |
1007 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) | 1003 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) |
1008 continue; | 1004 continue; |
1009 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) | 1005 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) |
1010 continue; | 1006 continue; |
1011 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) | 1007 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) |
1012 continue; | 1008 continue; |
1013 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) | 1009 if (pPrePDFObj->GetString() == "form") { |
1014 continue; | 1010 m_pXFADoc->SavePackage(XFA_HASHCODE_Form, &fileStream, nullptr); |
1015 if (pPrePDFObj->GetString() == "form") { | 1011 } else if (pPrePDFObj->GetString() == "datasets") { |
1016 m_pXFADoc->SavePackage(XFA_HASHCODE_Form, &fileStream, nullptr); | 1012 m_pXFADoc->SavePackage(XFA_HASHCODE_Datasets, &fileStream, nullptr); |
1017 } else if (pPrePDFObj->GetString() == "datasets") { | 1013 } else { |
1018 m_pXFADoc->SavePackage(XFA_HASHCODE_Datasets, &fileStream, nullptr); | 1014 // PDF,creator. |
1019 } else { | |
1020 // PDF,creator. | |
1021 } | |
1022 } | 1015 } |
1023 } | 1016 } |
1024 return TRUE; | 1017 return TRUE; |
1025 } | 1018 } |
1026 | 1019 |
1027 void CPDFXFA_Document::_ClearChangeMark() { | 1020 void CPDFXFA_Document::_ClearChangeMark() { |
1028 if (m_pSDKDoc) | 1021 if (m_pSDKDoc) |
1029 m_pSDKDoc->ClearChangeMark(); | 1022 m_pSDKDoc->ClearChangeMark(); |
1030 } | 1023 } |
1031 | 1024 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 } | 1254 } |
1262 | 1255 |
1263 return _GetHValueByName(szPropName, hValue, | 1256 return _GetHValueByName(szPropName, hValue, |
1264 m_pSDKDoc->GetEnv()->GetJSRuntime()); | 1257 m_pSDKDoc->GetEnv()->GetJSRuntime()); |
1265 } | 1258 } |
1266 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, | 1259 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, |
1267 FXJSE_HVALUE hValue, | 1260 FXJSE_HVALUE hValue, |
1268 IJS_Runtime* runTime) { | 1261 IJS_Runtime* runTime) { |
1269 return runTime->GetHValueByName(utf8Name, hValue); | 1262 return runTime->GetHValueByName(utf8Name, hValue); |
1270 } | 1263 } |
OLD | NEW |