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

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1395353004: Merge to XFA: Introduce CPDFDocumentFromFPDFDocument(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Fix build. Created 5 years, 2 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
« fpdfsdk/src/fpdfdoc.cpp ('K') | « fpdfsdk/src/fpdfppo.cpp ('k') | no next file » | 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/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
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;
Lei Zhang 2015/10/15 22:44:27 There's a subtle behavior change, but I don't thin
Tom Sepez 2015/10/15 23:18:09 Yes, intentional, was trying to avoid an uninitial
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;
Lei Zhang 2015/10/15 22:44:27 :\
385 CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser();
386 389
390 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
Lei Zhang 2015/10/15 22:44:27 Same pointless cast? More below.
Tom Sepez 2015/10/15 23:18:09 And you know what we do to pointless casts.
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_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
406 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
407 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
408 } 408 }
409 409
410 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { 410 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
411 if (document == NULL) 411 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
412 if (!pDoc)
412 return -1; 413 return -1;
413 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); 414
414 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 415 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
415 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 416 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
416 if (pDict == NULL) 417 return pDict ? pDict->GetInteger("R") : -1;
417 return -1;
418
419 return pDict->GetInteger("R");
420 } 418 }
421 419
422 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { 420 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
423 if (document == NULL) 421 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
424 return 0; 422 return pDoc ? pDoc->GetPageCount() : 0;
425 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
426 return pDoc->GetPageCount();
427 //» return ((CPDF_Document*)document)->GetPageCount();
428 } 423 }
429 424
430 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, 425 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
431 int page_index) { 426 int page_index) {
432 if (document == NULL) 427 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
433 return NULL; 428 if (!pDoc)
434 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; 429 return nullptr;
435 if (page_index < 0 || page_index >= pDoc->GetPageCount()) 430
436 return NULL; 431 if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
437 //» CPDF_Parser* pParser = (CPDF_Parser*)document; 432 return nullptr;
433
438 return pDoc->GetPage(page_index); 434 return pDoc->GetPage(page_index);
439 } 435 }
440 436
441 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { 437 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
442 if (!page) 438 if (!page)
443 return 0.0; 439 return 0.0;
444 return ((CPDFXFA_Page*)page)->GetPageWidth(); 440 return ((CPDFXFA_Page*)page)->GetPageWidth();
445 // return ((CPDF_Page*)page)->GetPageWidth(); 441 // return ((CPDF_Page*)page)->GetPageWidth();
446 } 442 }
447 443
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 662
667 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { 663 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
668 if (!page) 664 if (!page)
669 return; 665 return;
670 666
671 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; 667 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
672 pPage->Release(); 668 pPage->Release();
673 } 669 }
674 670
675 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { 671 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
676 if (!document) 672 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
Lei Zhang 2015/10/15 22:44:27 Do we even need the variable anymore?
Tom Sepez 2015/10/15 23:18:09 Done.
677 return;
678
679 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
680 delete pDoc; 673 delete pDoc;
681 } 674 }
682 675
683 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { 676 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
684 return GetLastError(); 677 return GetLastError();
685 } 678 }
686 679
687 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, 680 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
688 int start_x, 681 int start_x,
689 int start_y, 682 int start_y,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 return FALSE; 885 return FALSE;
893 886
894 *width = pPage->GetPageWidth(); 887 *width = pPage->GetPageWidth();
895 *height = pPage->GetPageHeight(); 888 *height = pPage->GetPageHeight();
896 889
897 return TRUE; 890 return TRUE;
898 } 891 }
899 892
900 DLLEXPORT FPDF_BOOL STDCALL 893 DLLEXPORT FPDF_BOOL STDCALL
901 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { 894 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
902 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; 895 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
903 if (!pDoc) 896 if (!pDoc)
904 return TRUE; 897 return TRUE;
905 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); 898 CPDF_ViewerPreferences viewRef(pDoc);
906 if (!pPDFDoc)
907 return TRUE;
908 CPDF_ViewerPreferences viewRef(pPDFDoc);
909 return viewRef.PrintScaling(); 899 return viewRef.PrintScaling();
910 } 900 }
911 901
912 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { 902 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
913 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); 903 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
914 if (!pDoc) 904 if (!pDoc)
915 return 1; 905 return 1;
916 CPDF_ViewerPreferences viewRef(pDoc); 906 CPDF_ViewerPreferences viewRef(pDoc);
917 return viewRef.NumCopies(); 907 return viewRef.NumCopies();
918 } 908 }
919 909
920 DLLEXPORT FPDF_PAGERANGE STDCALL 910 DLLEXPORT FPDF_PAGERANGE STDCALL
921 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { 911 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
922 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); 912 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
923 if (!pDoc) 913 if (!pDoc)
924 return NULL; 914 return NULL;
925 CPDF_ViewerPreferences viewRef(pDoc); 915 CPDF_ViewerPreferences viewRef(pDoc);
926 return viewRef.PrintPageRange(); 916 return viewRef.PrintPageRange();
927 } 917 }
928 918
929 DLLEXPORT FPDF_DUPLEXTYPE STDCALL 919 DLLEXPORT FPDF_DUPLEXTYPE STDCALL
930 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { 920 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
931 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); 921 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
932 if (!pDoc) 922 if (!pDoc)
933 return DuplexUndefined; 923 return DuplexUndefined;
934 CPDF_ViewerPreferences viewRef(pDoc); 924 CPDF_ViewerPreferences viewRef(pDoc);
935 CFX_ByteString duplex = viewRef.Duplex(); 925 CFX_ByteString duplex = viewRef.Duplex();
936 if (FX_BSTRC("Simplex") == duplex) 926 if (FX_BSTRC("Simplex") == duplex)
937 return Simplex; 927 return Simplex;
938 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) 928 if (FX_BSTRC("DuplexFlipShortEdge") == duplex)
939 return DuplexFlipShortEdge; 929 return DuplexFlipShortEdge;
940 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) 930 if (FX_BSTRC("DuplexFlipLongEdge") == duplex)
941 return DuplexFlipLongEdge; 931 return DuplexFlipLongEdge;
942 return DuplexUndefined; 932 return DuplexUndefined;
943 } 933 }
944 934
945 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { 935 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
946 if (!document) 936 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
937 if (!pDoc)
947 return 0; 938 return 0;
948 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
949 939
950 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 940 CPDF_Dictionary* pRoot = pDoc->GetRoot();
951 if (!pRoot) 941 if (!pRoot)
952 return 0; 942 return 0;
953 943
954 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); 944 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
955 int count = nameTree.GetCount(); 945 int count = nameTree.GetCount();
956 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); 946 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
957 if (pDest) 947 if (pDest)
958 count += pDest->GetCount(); 948 count += pDest->GetCount();
959 return count; 949 return count;
960 } 950 }
961 951
962 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, 952 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
963 FPDF_BYTESTRING name) { 953 FPDF_BYTESTRING name) {
964 if (!document)
965 return NULL;
966 if (!name || name[0] == 0) 954 if (!name || name[0] == 0)
967 return NULL; 955 return nullptr;
968 956
969 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; 957 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
970 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); 958 if (!pDoc)
971 if (!pPDFDoc) 959 return nullptr;
972 return NULL; 960
973 CPDF_NameTree name_tree(pPDFDoc, FX_BSTRC("Dests")); 961 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
974 return name_tree.LookupNamedDest(pPDFDoc, name); 962 return name_tree.LookupNamedDest(pDoc, name);
975 } 963 }
976 964
977 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { 965 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {
978 if (!str) 966 if (!str)
979 return -1; 967 return -1;
980 968
981 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); 969 FXSYS_memset(str, 0, sizeof(FPDF_BSTR));
982 return 0; 970 return 0;
983 } 971 }
984 972
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 if (!buffer) { 1067 if (!buffer) {
1080 *buflen = len; 1068 *buflen = len;
1081 } else if (*buflen >= len) { 1069 } else if (*buflen >= len) {
1082 memcpy(buffer, utf16Name.c_str(), len); 1070 memcpy(buffer, utf16Name.c_str(), len);
1083 *buflen = len; 1071 *buflen = len;
1084 } else { 1072 } else {
1085 *buflen = -1; 1073 *buflen = -1;
1086 } 1074 }
1087 return (FPDF_DEST)pDestObj; 1075 return (FPDF_DEST)pDestObj;
1088 } 1076 }
OLDNEW
« fpdfsdk/src/fpdfdoc.cpp ('K') | « fpdfsdk/src/fpdfppo.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698