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

Side by Side Diff: fpdfsdk/src/javascript/Document.cpp

Issue 1243883003: Fix else-after-returns throughout pdfium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 5 months 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
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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 { 630 {
631 // Unsafe, not supported. 631 // Unsafe, not supported.
632 return TRUE; 632 return TRUE;
633 } 633 }
634 634
635 635
636 FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError) 636 FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError)
637 { 637 {
638 ASSERT(m_pDocument != NULL); 638 ASSERT(m_pDocument != NULL);
639 CJS_Context* pContext = (CJS_Context*)cc; 639 CJS_Context* pContext = (CJS_Context*)cc;
640 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Lei Zhang 2015/07/21 21:44:47 Why move this up here when we don't use it until m
Tom Sepez 2015/07/22 20:38:24 Ah, right. I was de-duplicating them but the can
640 int nSize = params.size(); 641 int nSize = params.size();
641 if (nSize < 1) { 642 if (nSize < 1) {
642 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 643 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
643 return FALSE; 644 return FALSE;
644 } 645 }
645 646
646 CFX_WideString strURL; 647 CFX_WideString strURL;
647 FX_BOOL bFDF = TRUE; 648 FX_BOOL bFDF = TRUE;
648 FX_BOOL bEmpty = FALSE; 649 FX_BOOL bEmpty = FALSE;
649 v8::Isolate* isolate = GetIsolate(cc); 650 v8::Isolate* isolate = GetIsolate(cc);
(...skipping 18 matching lines...) Expand all
668 strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValu e)).ToCFXWideString(); 669 strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValu e)).ToCFXWideString();
669 pValue = JS_GetObjectElement(isolate, pObj, L"bFDF"); 670 pValue = JS_GetObjectElement(isolate, pObj, L"bFDF");
670 bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool (); 671 bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool ();
671 pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty"); 672 pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty");
672 bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBo ol(); 673 bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBo ol();
673 pValue = JS_GetObjectElement(isolate, pObj,L"aFields"); 674 pValue = JS_GetObjectElement(isolate, pObj,L"aFields");
674 aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue) ).ToV8Array()); 675 aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue) ).ToV8Array());
675 } 676 }
676 677
677 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInte rForm(); 678 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInte rForm();
678 ASSERT(pInterForm != NULL);
679 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 679 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
680 ASSERT(pPDFInterForm != NULL);
681
682 FX_BOOL bAll = (aFields.GetLength() == 0); 680 FX_BOOL bAll = (aFields.GetLength() == 0);
683
684 if (bAll && bEmpty) 681 if (bAll && bEmpty)
685 { 682 {
686 CJS_Context* pContext = (CJS_Context*)cc;
687 ASSERT(pContext != NULL);
688 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
689 ASSERT(pRuntime != NULL);
690
691
692 if (pPDFInterForm->CheckRequiredFields()) 683 if (pPDFInterForm->CheckRequiredFields())
693 { 684 {
694 pRuntime->BeginBlock(); 685 pRuntime->BeginBlock();
695 pInterForm->SubmitForm(strURL, FALSE); 686 pInterForm->SubmitForm(strURL, FALSE);
696 pRuntime->EndBlock(); 687 pRuntime->EndBlock();
697 } 688 }
698
699 return TRUE;
700 }
701 else
702 {
703 CFX_PtrArray fieldObjects;
704
705 for (int i=0,sz=aFields.GetLength(); i<sz; i++)
706 {
707 CJS_Value valName(isolate);
708 aFields.GetElement(i, valName);
709 CFX_WideString sName = valName.ToCFXWideString();
710
711 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
712 ASSERT(pPDFForm != NULL);
713
714 for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j ++)
715 {
716 CPDF_FormField* pField = pPDFForm->GetField(j, s Name);
717 if (!bEmpty && pField->GetValue().IsEmpty())
718 continue;
719
720 fieldObjects.Add(pField);
721 }
722 }
723
724 CJS_Context* pContext = (CJS_Context*)cc;
725 ASSERT(pContext != NULL);
726 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
727 ASSERT(pRuntime != NULL);
728
729
730 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
731 {
732 pRuntime->BeginBlock();
733 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bF DF);
734 pRuntime->EndBlock();
735 }
736
737 return TRUE; 689 return TRUE;
738 } 690 }
739 691
692 CFX_PtrArray fieldObjects;
693 for (int i=0,sz=aFields.GetLength(); i<sz; i++)
694 {
695 CJS_Value valName(isolate);
696 aFields.GetElement(i, valName);
697
698 CFX_WideString sName = valName.ToCFXWideString();
699 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
700 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j)
701 {
702 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
703 if (!bEmpty && pField->GetValue().IsEmpty())
704 continue;
705
706 fieldObjects.Add(pField);
707 }
708 }
709
710 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
711 {
712 pRuntime->BeginBlock();
713 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
714 pRuntime->EndBlock();
715 }
716 return TRUE;
740 } 717 }
741 718
742 //////////////////////////////////////////////////////////////////////////////// ////////////// 719 //////////////////////////////////////////////////////////////////////////////// //////////////
743 720
744 void Document::AttachDoc(CPDFSDK_Document *pDoc) 721 void Document::AttachDoc(CPDFSDK_Document *pDoc)
745 { 722 {
746 m_pDocument = pDoc; 723 m_pDocument = pDoc;
747 } 724 }
748 725
749 CPDFSDK_Document * Document::GetReaderDoc() 726 CPDFSDK_Document * Document::GetReaderDoc()
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 m_pDocument->SetChangeMark(); 828 m_pDocument->SetChangeMark();
852 return TRUE; 829 return TRUE;
853 } 830 }
854 } 831 }
855 832
856 FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr ror) 833 FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr ror)
857 { 834 {
858 ASSERT(m_pDocument != NULL); 835 ASSERT(m_pDocument != NULL);
859 836
860 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 837 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
861 » if (!pDictionary)return FALSE; 838 » if (!pDictionary)
839 return FALSE;
862 840
863 CFX_WideString cwAuthor = pDictionary->GetUnicodeText("A uthor"); 841 CFX_WideString cwAuthor = pDictionary->GetUnicodeText("A uthor");
864 CFX_WideString cwTitle = pDictionary->GetUnicodeText("T itle"); 842 CFX_WideString cwTitle = pDictionary->GetUnicodeText("T itle");
865 CFX_WideString cwSubject = pDictionary->GetUnicodeText("S ubject"); 843 CFX_WideString cwSubject = pDictionary->GetUnicodeText("S ubject");
866 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("K eywords"); 844 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("K eywords");
867 CFX_WideString cwCreator = pDictionary->GetUnicodeText("C reator"); 845 CFX_WideString cwCreator = pDictionary->GetUnicodeText("C reator");
868 CFX_WideString cwProducer = pDictionary->GetUnicodeText("P roducer"); 846 CFX_WideString cwProducer = pDictionary->GetUnicodeText("P roducer");
869 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationD ate"); 847 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationD ate");
870 CFX_WideString cwModDate = pDictionary->GetUnicodeText("M odDate"); 848 CFX_WideString cwModDate = pDictionary->GetUnicodeText("M odDate");
871 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("T rapped"); 849 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("T rapped");
872 850
873 v8::Isolate* isolate = GetIsolate(cc); 851 v8::Isolate* isolate = GetIsolate(cc);
874 if (vp.IsGetting()) 852 if (vp.IsGetting())
875 { 853 {
876 CJS_Context* pContext = (CJS_Context *)cc; 854 CJS_Context* pContext = (CJS_Context *)cc;
877 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 855 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
878
879 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); 856 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
880
881 JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); 857 JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
882 JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); 858 JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
883 JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()) ; 859 JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()) ;
884 JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str( )); 860 JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str( ));
885 JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()) ; 861 JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()) ;
886 JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str( )); 862 JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str( ));
887 JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDat e.c_str()); 863 JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDat e.c_str());
888 JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()) ; 864 JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()) ;
889 JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()) ; 865 JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()) ;
890 866
891 // It's to be compatible to non-standard info dictionary. 867 // It's to be compatible to non-standard info dictionary.
892 FX_POSITION pos = pDictionary->GetStartPos(); 868 FX_POSITION pos = pDictionary->GetStartPos();
893 while(pos) 869 while(pos)
894 { 870 {
895 CFX_ByteString bsKey; 871 CFX_ByteString bsKey;
896 CPDF_Object* pValueObj = pDictionary->GetNextElement(pos , bsKey); 872 CPDF_Object* pValueObj = pDictionary->GetNextElement(pos , bsKey);
897 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); 873 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
898 if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj-> GetType()==PDFOBJ_NAME) ) 874 if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj-> GetType()==PDFOBJ_NAME) )
899 JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str()); 875 JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str());
900 if(pValueObj->GetType()==PDFOBJ_NUMBER) 876 if(pValueObj->GetType()==PDFOBJ_NUMBER)
901 JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber()); 877 JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber());
902 if(pValueObj->GetType()==PDFOBJ_BOOLEAN) 878 if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
903 JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); 879 JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger());
904 } 880 }
905
906 vp << pObj; 881 vp << pObj;
907 return TRUE;
908 } 882 }
909 » else 883 return TRUE;
910 » {
911 » » return TRUE;
912 » }
913 } 884 }
914 885
915 FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStr ing& sError) 886 FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStr ing& sError)
916 { 887 {
917 ASSERT(m_pDocument != NULL);
918
919 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 888 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
920 » if (!pDictionary)return FALSE; 889 » if (!pDictionary)
890 return FALSE;
921 891
922 if (vp.IsGetting()) 892 if (vp.IsGetting())
923 { 893 {
924 vp << pDictionary->GetUnicodeText("CreationDate"); 894 vp << pDictionary->GetUnicodeText("CreationDate");
925 return TRUE;
926 } 895 }
927 else 896 else
928 { 897 {
929 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 898 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
899 return FALSE;
930 900
931 CFX_WideString csCreationDate; 901 CFX_WideString csCreationDate;
932 vp >> csCreationDate; 902 vp >> csCreationDate;
933 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreati onDate)); 903 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreati onDate));
934 m_pDocument->SetChangeMark(); 904 m_pDocument->SetChangeMark();
935
936 return TRUE;
937 } 905 }
906 return TRUE;
938 } 907 }
939 908
940 FX_BOOL Document::creator(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 909 FX_BOOL Document::creator(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
941 { 910 {
942 ASSERT(m_pDocument != NULL);
943
944 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 911 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
945 » if (!pDictionary)return FALSE; 912 » if (!pDictionary)
913 return FALSE;
946 914
947 if (vp.IsGetting()) 915 if (vp.IsGetting())
948 { 916 {
949 vp << pDictionary->GetUnicodeText("Creator"); 917 vp << pDictionary->GetUnicodeText("Creator");
950 return TRUE;
951 } 918 }
952 else 919 else
953 { 920 {
954 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 921 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
922 return FALSE;
955 923
956 CFX_WideString csCreator; 924 CFX_WideString csCreator;
957 vp >> csCreator; 925 vp >> csCreator;
958 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); 926 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
959 m_pDocument->SetChangeMark(); 927 m_pDocument->SetChangeMark();
960 return TRUE;
961 } 928 }
929 return TRUE;
962 } 930 }
963 931
964 FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 932 FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror)
965 { 933 {
966 if (vp.IsGetting()) 934 if (vp.IsGetting())
967 { 935 {
968 vp << m_bDelay; 936 vp << m_bDelay;
969 return TRUE;
970 } 937 }
971 else 938 else
972 { 939 {
973 » » ASSERT(m_pDocument != NULL); 940 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
974 941 return FALSE;
975 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
976 942
977 bool b; 943 bool b;
978 vp >> b; 944 vp >> b;
979
980 m_bDelay = b; 945 m_bDelay = b;
981
982 if (m_bDelay) 946 if (m_bDelay)
983 { 947 {
984 for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++) 948 for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
985 delete m_DelayData.GetAt(i); 949 delete m_DelayData.GetAt(i);
986 950
987 m_DelayData.RemoveAll(); 951 m_DelayData.RemoveAll();
988 } 952 }
989 else 953 else
990 { 954 {
991 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; 955 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
992
993 for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++) 956 for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++)
994 { 957 {
995 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) 958 if (CJS_DelayData* pData = m_DelayData.GetAt(i))
996 { 959 {
997 DelayDataToProcess.Add(pData); 960 DelayDataToProcess.Add(pData);
998 m_DelayData.SetAt(i, NULL); 961 m_DelayData.SetAt(i, NULL);
999 } 962 }
1000 } 963 }
1001 m_DelayData.RemoveAll(); 964 m_DelayData.RemoveAll();
1002
1003 for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i+ +) 965 for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i+ +)
1004 { 966 {
1005 CJS_DelayData* pData = DelayDataToProcess.GetAt( i); 967 CJS_DelayData* pData = DelayDataToProcess.GetAt( i);
1006 Field::DoDelay(m_pDocument, pData); 968 Field::DoDelay(m_pDocument, pData);
1007 DelayDataToProcess.SetAt(i,NULL); 969 DelayDataToProcess.SetAt(i,NULL);
1008 delete pData; 970 delete pData;
1009 } 971 }
1010 } 972 }
1011 973 }
1012 » » return TRUE; 974 return TRUE;
1013 » }
1014 } 975 }
1015 976
1016 FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 977 FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1017 { 978 {
1018 ASSERT(m_pDocument != NULL);
1019
1020 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 979 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
1021 » if (!pDictionary)return FALSE; 980 » if (!pDictionary)
981 return FALSE;
1022 982
1023 if (vp.IsGetting()) 983 if (vp.IsGetting())
1024 { 984 {
1025 vp << pDictionary->GetUnicodeText("Keywords"); 985 vp << pDictionary->GetUnicodeText("Keywords");
1026 return TRUE;
1027 } 986 }
1028 else 987 else
1029 { 988 {
1030 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 989 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
990 return FALSE;
1031 991
1032 CFX_WideString csKeywords; 992 CFX_WideString csKeywords;
1033 vp >> csKeywords; 993 vp >> csKeywords;
1034 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)) ; 994 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)) ;
1035 m_pDocument->SetChangeMark(); 995 m_pDocument->SetChangeMark();
1036 return TRUE;
1037 } 996 }
997 return TRUE;
1038 } 998 }
1039 999
1040 FX_BOOL Document::modDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 1000 FX_BOOL Document::modDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1041 { 1001 {
1042 ASSERT(m_pDocument != NULL);
1043
1044 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 1002 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
1045 » if (!pDictionary)return FALSE; 1003 » if (!pDictionary)
1004 return FALSE;
1046 1005
1047 if (vp.IsGetting()) 1006 if (vp.IsGetting())
1048 { 1007 {
1049 vp << pDictionary->GetUnicodeText("ModDate"); 1008 vp << pDictionary->GetUnicodeText("ModDate");
1050 return TRUE;
1051 } 1009 }
1052 else 1010 else
1053 { 1011 {
1054 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 1012 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1013 return FALSE;
1055 1014
1056 CFX_WideString csmodDate; 1015 CFX_WideString csmodDate;
1057 vp >> csmodDate; 1016 vp >> csmodDate;
1058 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); 1017 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
1059 m_pDocument->SetChangeMark(); 1018 m_pDocument->SetChangeMark();
1060 return TRUE;
1061 } 1019 }
1020 return TRUE;
1062 } 1021 }
1063 1022
1064 FX_BOOL Document::producer(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 1023 FX_BOOL Document::producer(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1065 { 1024 {
1066 ASSERT(m_pDocument != NULL);
1067
1068 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 1025 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
1069 » if (!pDictionary)return FALSE; 1026 » if (!pDictionary)
1027 return FALSE;
1070 1028
1071 if (vp.IsGetting()) 1029 if (vp.IsGetting())
1072 { 1030 {
1073 vp << pDictionary->GetUnicodeText("Producer"); 1031 vp << pDictionary->GetUnicodeText("Producer");
1074 return TRUE;
1075 } 1032 }
1076 else 1033 else
1077 { 1034 {
1078 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 1035 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1036 return FALSE;
1079 1037
1080 CFX_WideString csproducer; 1038 CFX_WideString csproducer;
1081 vp >> csproducer; 1039 vp >> csproducer;
1082 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)) ; 1040 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)) ;
1083 m_pDocument->SetChangeMark(); 1041 m_pDocument->SetChangeMark();
1084 return TRUE;
1085 } 1042 }
1043 return TRUE;
1086 } 1044 }
1087 1045
1088 FX_BOOL Document::subject(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 1046 FX_BOOL Document::subject(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1089 { 1047 {
1090 ASSERT(m_pDocument != NULL);
1091
1092 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 1048 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
1093 » if (!pDictionary)return FALSE; 1049 » if (!pDictionary)
1050 return FALSE;
1094 1051
1095 if (vp.IsGetting()) 1052 if (vp.IsGetting())
1096 { 1053 {
1097 vp << pDictionary->GetUnicodeText("Subject"); 1054 vp << pDictionary->GetUnicodeText("Subject");
1098 return TRUE;
1099 } 1055 }
1100 else 1056 else
1101 { 1057 {
1102 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 1058 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1059 return FALSE;
1103 1060
1104 CFX_WideString cssubject; 1061 CFX_WideString cssubject;
1105 vp >> cssubject; 1062 vp >> cssubject;
1106 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); 1063 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
1107 m_pDocument->SetChangeMark(); 1064 m_pDocument->SetChangeMark();
1108 return TRUE;
1109 } 1065 }
1066 return TRUE;
1110 } 1067 }
1111 1068
1112 FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 1069 FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror)
1113 { 1070 {
1114 ASSERT(m_pDocument != NULL);
1115
1116 if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) 1071 if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
1117 return FALSE; 1072 return FALSE;
1118 1073
1119 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); 1074 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
1120 » if (!pDictionary)return FALSE; 1075 » if (!pDictionary)
1076 return FALSE;
1121 1077
1122 if (vp.IsGetting()) 1078 if (vp.IsGetting())
1123 { 1079 {
1124 vp << pDictionary->GetUnicodeText("Title"); 1080 vp << pDictionary->GetUnicodeText("Title");
1125 return TRUE;
1126 } 1081 }
1127 else 1082 else
1128 { 1083 {
1129 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; 1084 » » if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1085 return FALSE;
1130 1086
1131 CFX_WideString cstitle; 1087 CFX_WideString cstitle;
1132 vp >> cstitle; 1088 vp >> cstitle;
1133 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); 1089 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
1134 m_pDocument->SetChangeMark(); 1090 m_pDocument->SetChangeMark();
1135 return TRUE;
1136 } 1091 }
1092 return TRUE;
1137 } 1093 }
1138 1094
1139 FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 1095 FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
1140 { 1096 {
1141 if (vp.IsSetting()) { 1097 if (vp.IsSetting()) {
1142 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1098 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1143 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); 1099 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1144 return FALSE; 1100 return FALSE;
1145 } 1101 }
1146 vp << m_pDocument->GetPageCount(); 1102 vp << m_pDocument->GetPageCount();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 return TRUE; 1306 return TRUE;
1351 } 1307 }
1352 1308
1353 FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError) 1309 FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError)
1354 { 1310 {
1355 return TRUE; 1311 return TRUE;
1356 } 1312 }
1357 1313
1358 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) 1314 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
1359 { 1315 {
1360 » if (rect.left <= LinkRect.left 1316 » return (rect.left <= LinkRect.left &&
1361 » && rect.top <= LinkRect.top 1317 rect.top <= LinkRect.top &&
1362 » && rect.right >= LinkRect.right 1318 rect.right >= LinkRect.right &&
1363 » && rect.bottom >= LinkRect.bottom) 1319 rect.bottom >= LinkRect.bottom);
1364 » » return true;
1365 » else
1366 » » return false;
1367 } 1320 }
1368 1321
1369 void IconTree::InsertIconElement(IconElement* pNewIcon) 1322 void IconTree::InsertIconElement(IconElement* pNewIcon)
1370 { 1323 {
1371 if (!pNewIcon)return; 1324 if (!pNewIcon)return;
1372 1325
1373 if (m_pHead == NULL && m_pEnd == NULL) 1326 if (m_pHead == NULL && m_pEnd == NULL)
1374 { 1327 {
1375 m_pHead = m_pEnd = pNewIcon; 1328 m_pHead = m_pEnd = pNewIcon;
1376 m_iLength++; 1329 m_iLength++;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 { 1362 {
1410 if (iIndex >= 0 && iIndex <= m_iLength) 1363 if (iIndex >= 0 && iIndex <= m_iLength)
1411 { 1364 {
1412 IconElement* pTemp = m_pHead; 1365 IconElement* pTemp = m_pHead;
1413 for (int i = 0; i < iIndex; i++) 1366 for (int i = 0; i < iIndex; i++)
1414 { 1367 {
1415 pTemp = pTemp->NextIcon; 1368 pTemp = pTemp->NextIcon;
1416 } 1369 }
1417 return pTemp; 1370 return pTemp;
1418 } 1371 }
1419 » else 1372 return NULL;
1420 » » return NULL;
1421 } 1373 }
1422 1374
1423 FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) 1375 FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError)
1424 { 1376 {
1425 CJS_Context* pContext = (CJS_Context*)cc; 1377 CJS_Context* pContext = (CJS_Context*)cc;
1426 if (params.size() != 2) { 1378 if (params.size() != 2) {
1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1379 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1428 return FALSE; 1380 return FALSE;
1429 } 1381 }
1430 1382
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 { 1835 {
1884 m_DelayData.RemoveAt(DelArray[j]); 1836 m_DelayData.RemoveAt(DelArray[j]);
1885 } 1837 }
1886 } 1838 }
1887 1839
1888 CJS_Document* Document::GetCJSDoc() const 1840 CJS_Document* Document::GetCJSDoc() const
1889 { 1841 {
1890 return static_cast<CJS_Document*>(m_pJSObject); 1842 return static_cast<CJS_Document*>(m_pJSObject);
1891 } 1843 }
1892 1844
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698