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/include/fpdfapi/fpdf_module.h" | 7 #include "../../core/include/fpdfapi/fpdf_module.h" |
8 #include "../../core/include/fxcodec/fx_codec.h" | 8 #include "../../core/include/fxcodec/fx_codec.h" |
9 #include "../../core/include/fxcrt/fx_safe_types.h" | 9 #include "../../core/include/fxcrt/fx_safe_types.h" |
10 #include "../../public/fpdf_ext.h" | 10 #include "../../public/fpdf_ext.h" |
11 #include "../../public/fpdf_formfill.h" | 11 #include "../../public/fpdf_formfill.h" |
12 #include "../../public/fpdf_progressive.h" | 12 #include "../../public/fpdf_progressive.h" |
13 #include "../../public/fpdfview.h" | 13 #include "../../public/fpdfview.h" |
14 #include "../../third_party/base/nonstd_unique_ptr.h" | 14 #include "../../third_party/base/nonstd_unique_ptr.h" |
15 #include "../../third_party/base/numerics/safe_conversions_impl.h" | 15 #include "../../third_party/base/numerics/safe_conversions_impl.h" |
16 #include "../include/fsdk_define.h" | 16 #include "../include/fsdk_define.h" |
17 #include "../include/fsdk_mgr.h" | 17 #include "../include/fsdk_mgr.h" |
18 #include "../include/fsdk_rendercontext.h" | 18 #include "../include/fsdk_rendercontext.h" |
19 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 19 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
20 #include "../include/fpdfxfa/fpdfxfa_app.h" | 20 #include "../include/fpdfxfa/fpdfxfa_app.h" |
21 #include "../include/fpdfxfa/fpdfxfa_page.h" | 21 #include "../include/fpdfxfa/fpdfxfa_page.h" |
22 #include "../include/fpdfxfa/fpdfxfa_util.h" | 22 #include "../include/fpdfxfa/fpdfxfa_util.h" |
23 #include "../include/javascript/IJavaScript.h" | 23 #include "../include/javascript/IJavaScript.h" |
24 | 24 |
| 25 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 26 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; |
| 27 } |
| 28 |
25 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 29 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
26 m_pFS = pFS; | 30 m_pFS = pFS; |
27 m_nCurPos = 0; | 31 m_nCurPos = 0; |
28 } | 32 } |
29 | 33 |
30 IFX_FileStream* CFPDF_FileStream::Retain() { | 34 IFX_FileStream* CFPDF_FileStream::Retain() { |
31 return this; | 35 return this; |
32 } | 36 } |
33 | 37 |
34 void CFPDF_FileStream::Release() { | 38 void CFPDF_FileStream::Release() { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 372 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
369 if (!pPDFDoc) | 373 if (!pPDFDoc) |
370 return NULL; | 374 return NULL; |
371 | 375 |
372 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 376 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
373 return new CPDFXFA_Document(pPDFDoc, pProvider); | 377 return new CPDFXFA_Document(pPDFDoc, pProvider); |
374 } | 378 } |
375 | 379 |
376 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 380 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, |
377 int* fileVersion) { | 381 int* fileVersion) { |
378 if (!doc || !fileVersion) | 382 if (!fileVersion) |
379 return FALSE; | 383 return FALSE; |
| 384 |
380 *fileVersion = 0; | 385 *fileVersion = 0; |
381 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)doc; | 386 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
382 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); | 387 if (!pDoc) |
383 if (!pPDFDoc) | 388 return FALSE; |
384 return (FX_DWORD)-1; | |
385 CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser(); | |
386 | 389 |
| 390 CPDF_Parser* pParser = pDoc->GetParser(); |
387 if (!pParser) | 391 if (!pParser) |
388 return FALSE; | 392 return FALSE; |
| 393 |
389 *fileVersion = pParser->GetFileVersion(); | 394 *fileVersion = pParser->GetFileVersion(); |
390 return TRUE; | 395 return TRUE; |
391 } | 396 } |
392 | 397 |
393 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match | 398 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match |
394 // header). | 399 // header). |
395 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { | 400 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { |
396 if (document == NULL) | 401 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
397 return 0; | 402 if (!pDoc) |
398 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | |
399 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); | |
400 if (!pPDFDoc) | |
401 return (FX_DWORD)-1; | |
402 CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser(); | |
403 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); | |
404 if (pDict == NULL) | |
405 return (FX_DWORD)-1; | 403 return (FX_DWORD)-1; |
406 | 404 |
407 return pDict->GetInteger("P"); | 405 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 406 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; |
408 } | 407 } |
409 | 408 |
410 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { | 409 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
411 if (document == NULL) | 410 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
412 return -1; | 411 if (!pDoc) |
413 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | |
414 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); | |
415 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); | |
416 if (pDict == NULL) | |
417 return -1; | 412 return -1; |
418 | 413 |
419 return pDict->GetInteger("R"); | 414 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 415 return pDict ? pDict->GetInteger("R") : -1; |
420 } | 416 } |
421 | 417 |
422 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { | 418 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { |
423 if (document == NULL) | 419 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
424 return 0; | 420 return pDoc ? pDoc->GetPageCount() : 0; |
425 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | |
426 return pDoc->GetPageCount(); | |
427 //» return ((CPDF_Document*)document)->GetPageCount(); | |
428 } | 421 } |
429 | 422 |
430 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, | 423 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, |
431 int page_index) { | 424 int page_index) { |
432 if (document == NULL) | 425 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
433 return NULL; | 426 if (!pDoc) |
434 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 427 return nullptr; |
435 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 428 |
436 return NULL; | 429 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
437 //» CPDF_Parser* pParser = (CPDF_Parser*)document; | 430 return nullptr; |
| 431 |
438 return pDoc->GetPage(page_index); | 432 return pDoc->GetPage(page_index); |
439 } | 433 } |
440 | 434 |
441 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 435 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
442 if (!page) | 436 if (!page) |
443 return 0.0; | 437 return 0.0; |
444 return ((CPDFXFA_Page*)page)->GetPageWidth(); | 438 return ((CPDFXFA_Page*)page)->GetPageWidth(); |
445 // return ((CPDF_Page*)page)->GetPageWidth(); | 439 // return ((CPDF_Page*)page)->GetPageWidth(); |
446 } | 440 } |
447 | 441 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 | 660 |
667 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { | 661 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { |
668 if (!page) | 662 if (!page) |
669 return; | 663 return; |
670 | 664 |
671 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 665 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
672 pPage->Release(); | 666 pPage->Release(); |
673 } | 667 } |
674 | 668 |
675 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 669 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { |
676 if (!document) | 670 delete CPDFDocumentFromFPDFDocument(document); |
677 return; | |
678 | |
679 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | |
680 delete pDoc; | |
681 } | 671 } |
682 | 672 |
683 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { | 673 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { |
684 return GetLastError(); | 674 return GetLastError(); |
685 } | 675 } |
686 | 676 |
687 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 677 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, |
688 int start_x, | 678 int start_x, |
689 int start_y, | 679 int start_y, |
690 int size_x, | 680 int size_x, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 return FALSE; | 882 return FALSE; |
893 | 883 |
894 *width = pPage->GetPageWidth(); | 884 *width = pPage->GetPageWidth(); |
895 *height = pPage->GetPageHeight(); | 885 *height = pPage->GetPageHeight(); |
896 | 886 |
897 return TRUE; | 887 return TRUE; |
898 } | 888 } |
899 | 889 |
900 DLLEXPORT FPDF_BOOL STDCALL | 890 DLLEXPORT FPDF_BOOL STDCALL |
901 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { | 891 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { |
902 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 892 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
903 if (!pDoc) | 893 if (!pDoc) |
904 return TRUE; | 894 return TRUE; |
905 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); | 895 CPDF_ViewerPreferences viewRef(pDoc); |
906 if (!pPDFDoc) | |
907 return TRUE; | |
908 CPDF_ViewerPreferences viewRef(pPDFDoc); | |
909 return viewRef.PrintScaling(); | 896 return viewRef.PrintScaling(); |
910 } | 897 } |
911 | 898 |
912 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { | 899 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { |
913 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 900 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
914 if (!pDoc) | 901 if (!pDoc) |
915 return 1; | 902 return 1; |
916 CPDF_ViewerPreferences viewRef(pDoc); | 903 CPDF_ViewerPreferences viewRef(pDoc); |
917 return viewRef.NumCopies(); | 904 return viewRef.NumCopies(); |
918 } | 905 } |
919 | 906 |
920 DLLEXPORT FPDF_PAGERANGE STDCALL | 907 DLLEXPORT FPDF_PAGERANGE STDCALL |
921 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { | 908 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { |
922 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 909 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
923 if (!pDoc) | 910 if (!pDoc) |
924 return NULL; | 911 return NULL; |
925 CPDF_ViewerPreferences viewRef(pDoc); | 912 CPDF_ViewerPreferences viewRef(pDoc); |
926 return viewRef.PrintPageRange(); | 913 return viewRef.PrintPageRange(); |
927 } | 914 } |
928 | 915 |
929 DLLEXPORT FPDF_DUPLEXTYPE STDCALL | 916 DLLEXPORT FPDF_DUPLEXTYPE STDCALL |
930 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { | 917 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { |
931 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 918 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
932 if (!pDoc) | 919 if (!pDoc) |
933 return DuplexUndefined; | 920 return DuplexUndefined; |
934 CPDF_ViewerPreferences viewRef(pDoc); | 921 CPDF_ViewerPreferences viewRef(pDoc); |
935 CFX_ByteString duplex = viewRef.Duplex(); | 922 CFX_ByteString duplex = viewRef.Duplex(); |
936 if (FX_BSTRC("Simplex") == duplex) | 923 if (FX_BSTRC("Simplex") == duplex) |
937 return Simplex; | 924 return Simplex; |
938 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) | 925 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) |
939 return DuplexFlipShortEdge; | 926 return DuplexFlipShortEdge; |
940 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) | 927 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) |
941 return DuplexFlipLongEdge; | 928 return DuplexFlipLongEdge; |
942 return DuplexUndefined; | 929 return DuplexUndefined; |
943 } | 930 } |
944 | 931 |
945 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { | 932 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { |
946 if (!document) | 933 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 934 if (!pDoc) |
947 return 0; | 935 return 0; |
948 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | |
949 | 936 |
950 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 937 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
951 if (!pRoot) | 938 if (!pRoot) |
952 return 0; | 939 return 0; |
953 | 940 |
954 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); | 941 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); |
955 int count = nameTree.GetCount(); | 942 int count = nameTree.GetCount(); |
956 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); | 943 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); |
957 if (pDest) | 944 if (pDest) |
958 count += pDest->GetCount(); | 945 count += pDest->GetCount(); |
959 return count; | 946 return count; |
960 } | 947 } |
961 | 948 |
962 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, | 949 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, |
963 FPDF_BYTESTRING name) { | 950 FPDF_BYTESTRING name) { |
964 if (!document) | |
965 return NULL; | |
966 if (!name || name[0] == 0) | 951 if (!name || name[0] == 0) |
967 return NULL; | 952 return nullptr; |
968 | 953 |
969 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 954 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
970 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); | 955 if (!pDoc) |
971 if (!pPDFDoc) | 956 return nullptr; |
972 return NULL; | 957 |
973 CPDF_NameTree name_tree(pPDFDoc, FX_BSTRC("Dests")); | 958 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
974 return name_tree.LookupNamedDest(pPDFDoc, name); | 959 return name_tree.LookupNamedDest(pDoc, name); |
975 } | 960 } |
976 | 961 |
977 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { | 962 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { |
978 if (!str) | 963 if (!str) |
979 return -1; | 964 return -1; |
980 | 965 |
981 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); | 966 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); |
982 return 0; | 967 return 0; |
983 } | 968 } |
984 | 969 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 if (!buffer) { | 1064 if (!buffer) { |
1080 *buflen = len; | 1065 *buflen = len; |
1081 } else if (*buflen >= len) { | 1066 } else if (*buflen >= len) { |
1082 memcpy(buffer, utf16Name.c_str(), len); | 1067 memcpy(buffer, utf16Name.c_str(), len); |
1083 *buflen = len; | 1068 *buflen = len; |
1084 } else { | 1069 } else { |
1085 *buflen = -1; | 1070 *buflen = -1; |
1086 } | 1071 } |
1087 return (FPDF_DEST)pDestObj; | 1072 return (FPDF_DEST)pDestObj; |
1088 } | 1073 } |
OLD | NEW |