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 "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
8 | 8 |
9 #include "../include/fpdfxfa/fpdfxfa_app.h" | 9 #include "../include/fpdfxfa/fpdfxfa_app.h" |
10 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 10 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
11 #include "../include/fpdfxfa/fpdfxfa_page.h" | 11 #include "../include/fpdfxfa/fpdfxfa_page.h" |
12 #include "../include/fpdfxfa/fpdfxfa_util.h" | 12 #include "../include/fpdfxfa/fpdfxfa_util.h" |
13 #include "core/include/fpdfapi/fpdf_module.h" | 13 #include "core/include/fpdfapi/fpdf_module.h" |
14 #include "core/include/fxcodec/fx_codec.h" | 14 #include "core/include/fxcodec/fx_codec.h" |
15 #include "core/include/fxcrt/fx_safe_types.h" | 15 #include "core/include/fxcrt/fx_safe_types.h" |
16 #include "fpdfsdk/include/fsdk_define.h" | 16 #include "fpdfsdk/include/fsdk_define.h" |
17 #include "fpdfsdk/include/fsdk_mgr.h" | 17 #include "fpdfsdk/include/fsdk_mgr.h" |
18 #include "fpdfsdk/include/fsdk_rendercontext.h" | 18 #include "fpdfsdk/include/fsdk_rendercontext.h" |
19 #include "fpdfsdk/include/javascript/IJavaScript.h" | 19 #include "fpdfsdk/include/javascript/IJavaScript.h" |
20 #include "public/fpdf_ext.h" | 20 #include "public/fpdf_ext.h" |
21 #include "public/fpdf_formfill.h" | 21 #include "public/fpdf_formfill.h" |
22 #include "public/fpdf_progressive.h" | 22 #include "public/fpdf_progressive.h" |
23 #include "third_party/base/nonstd_unique_ptr.h" | 23 #include "third_party/base/nonstd_unique_ptr.h" |
24 #include "third_party/base/numerics/safe_conversions_impl.h" | 24 #include "third_party/base/numerics/safe_conversions_impl.h" |
25 | 25 |
| 26 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 27 return static_cast<UnderlyingDocumentType*>(doc); |
| 28 } |
| 29 |
| 30 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { |
| 31 return static_cast<FPDF_DOCUMENT>(doc); |
| 32 } |
| 33 |
| 34 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { |
| 35 return static_cast<UnderlyingPageType*>(page); |
| 36 } |
| 37 |
26 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 38 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
27 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; | 39 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; |
28 } | 40 } |
29 | 41 |
30 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 42 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
31 return doc ? new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()) : nullptr; | 43 return doc ? FPDFDocumentFromUnderlying( |
| 44 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) |
| 45 : nullptr; |
32 } | 46 } |
33 | 47 |
34 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 48 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
35 return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; | 49 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
36 } | 50 } |
37 | 51 |
38 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 52 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
39 m_pFS = pFS; | 53 m_pFS = pFS; |
40 m_nCurPos = 0; | 54 m_nCurPos = 0; |
41 } | 55 } |
42 | 56 |
43 IFX_FileStream* CFPDF_FileStream::Retain() { | 57 IFX_FileStream* CFPDF_FileStream::Retain() { |
44 return this; | 58 return this; |
45 } | 59 } |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { | 423 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
410 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 424 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
411 if (!pDoc) | 425 if (!pDoc) |
412 return -1; | 426 return -1; |
413 | 427 |
414 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 428 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
415 return pDict ? pDict->GetInteger("R") : -1; | 429 return pDict ? pDict->GetInteger("R") : -1; |
416 } | 430 } |
417 | 431 |
418 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { | 432 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { |
419 CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); | 433 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
420 return pDoc ? pDoc->GetPageCount() : 0; | 434 return pDoc ? pDoc->GetPageCount() : 0; |
421 } | 435 } |
422 | 436 |
423 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, | 437 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, |
424 int page_index) { | 438 int page_index) { |
425 if (!document) | 439 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
| 440 if (!pDoc) |
426 return nullptr; | 441 return nullptr; |
427 CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); | |
428 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 442 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
429 return nullptr; | 443 return nullptr; |
430 | 444 |
431 return pDoc->GetPage(page_index); | 445 return pDoc->GetPage(page_index); |
432 } | 446 } |
433 | 447 |
434 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 448 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
435 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); | 449 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
436 return pPage ? pPage->GetPageWidth() : 0.0; | 450 return pPage ? pPage->GetPageWidth() : 0.0; |
437 } | 451 } |
438 | 452 |
439 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 453 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
440 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); | 454 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
441 return pPage ? pPage->GetPageHeight() : 0.0; | 455 return pPage ? pPage->GetPageHeight() : 0.0; |
442 } | 456 } |
443 | 457 |
444 void DropContext(void* data) { | 458 void DropContext(void* data) { |
445 delete (CRenderContext*)data; | 459 delete (CRenderContext*)data; |
446 } | 460 } |
447 | 461 |
448 #if defined(_DEBUG) || defined(DEBUG) | 462 #if defined(_DEBUG) || defined(DEBUG) |
449 #define DEBUG_TRACE | 463 #define DEBUG_TRACE |
450 #endif | 464 #endif |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 int start_y, | 685 int start_y, |
672 int size_x, | 686 int size_x, |
673 int size_y, | 687 int size_y, |
674 int rotate, | 688 int rotate, |
675 int device_x, | 689 int device_x, |
676 int device_y, | 690 int device_y, |
677 double* page_x, | 691 double* page_x, |
678 double* page_y) { | 692 double* page_y) { |
679 if (page == NULL || page_x == NULL || page_y == NULL) | 693 if (page == NULL || page_x == NULL || page_y == NULL) |
680 return; | 694 return; |
681 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 695 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
682 | |
683 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, | 696 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, |
684 device_y, page_x, page_y); | 697 device_y, page_x, page_y); |
685 } | 698 } |
686 | 699 |
687 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, | 700 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
688 int start_x, | 701 int start_x, |
689 int start_y, | 702 int start_y, |
690 int size_x, | 703 int size_x, |
691 int size_y, | 704 int size_y, |
692 int rotate, | 705 int rotate, |
693 double page_x, | 706 double page_x, |
694 double page_y, | 707 double page_y, |
695 int* device_x, | 708 int* device_x, |
696 int* device_y) { | 709 int* device_y) { |
697 if (!device_x || !device_y) | 710 if (!device_x || !device_y) |
698 return; | 711 return; |
699 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 712 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
700 if (!pPage) | 713 if (!pPage) |
701 return; | 714 return; |
702 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, | 715 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, |
703 device_x, device_y); | 716 device_x, device_y); |
704 } | 717 } |
705 | 718 |
706 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 719 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
707 int height, | 720 int height, |
708 int alpha) { | 721 int alpha) { |
709 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 722 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 if (!buffer) { | 1069 if (!buffer) { |
1057 *buflen = len; | 1070 *buflen = len; |
1058 } else if (*buflen >= len) { | 1071 } else if (*buflen >= len) { |
1059 memcpy(buffer, utf16Name.c_str(), len); | 1072 memcpy(buffer, utf16Name.c_str(), len); |
1060 *buflen = len; | 1073 *buflen = len; |
1061 } else { | 1074 } else { |
1062 *buflen = -1; | 1075 *buflen = -1; |
1063 } | 1076 } |
1064 return (FPDF_DEST)pDestObj; | 1077 return (FPDF_DEST)pDestObj; |
1065 } | 1078 } |
OLD | NEW |