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) { | 25 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
26 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; | 26 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; |
27 } | 27 } |
28 | 28 |
29 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | |
30 return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; | |
31 } | |
32 | |
29 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 33 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
30 m_pFS = pFS; | 34 m_pFS = pFS; |
31 m_nCurPos = 0; | 35 m_nCurPos = 0; |
32 } | 36 } |
33 | 37 |
34 IFX_FileStream* CFPDF_FileStream::Retain() { | 38 IFX_FileStream* CFPDF_FileStream::Retain() { |
35 return this; | 39 return this; |
36 } | 40 } |
37 | 41 |
38 void CFPDF_FileStream::Release() { | 42 void CFPDF_FileStream::Release() { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 return FALSE; | 102 return FALSE; |
99 } | 103 } |
100 | 104 |
101 FX_BOOL CFPDF_FileStream::Flush() { | 105 FX_BOOL CFPDF_FileStream::Flush() { |
102 if (!m_pFS || !m_pFS->Flush) | 106 if (!m_pFS || !m_pFS->Flush) |
103 return TRUE; | 107 return TRUE; |
104 | 108 |
105 return m_pFS->Flush(m_pFS->clientData) == 0; | 109 return m_pFS->Flush(m_pFS->clientData) == 0; |
106 } | 110 } |
107 | 111 |
112 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | |
Tom Sepez
2015/10/16 00:18:55
fixed.
Lei Zhang
2015/10/16 01:23:55
Wait, why do we have 2 impls in this file now?
Tom Sepez
2015/10/16 16:58:54
Twas deleted.
| |
113 return static_cast<CPDF_Page*>(page); | |
114 } | |
115 | |
108 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 116 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
109 m_FileAccess = *pFileAccess; | 117 m_FileAccess = *pFileAccess; |
110 m_BufferOffset = (FX_DWORD)-1; | 118 m_BufferOffset = (FX_DWORD)-1; |
111 } | 119 } |
112 | 120 |
113 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { | 121 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { |
114 if (pos >= m_FileAccess.m_FileLen) | 122 if (pos >= m_FileAccess.m_FileLen) |
115 return FALSE; | 123 return FALSE; |
116 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || | 124 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || |
117 pos >= m_BufferOffset + 512) { | 125 pos >= m_BufferOffset + 512) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) | 437 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
430 return nullptr; | 438 return nullptr; |
431 | 439 |
432 return pDoc->GetPage(page_index); | 440 return pDoc->GetPage(page_index); |
433 } | 441 } |
434 | 442 |
435 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 443 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
436 if (!page) | 444 if (!page) |
437 return 0.0; | 445 return 0.0; |
438 return ((CPDFXFA_Page*)page)->GetPageWidth(); | 446 return ((CPDFXFA_Page*)page)->GetPageWidth(); |
439 // return ((CPDF_Page*)page)->GetPageWidth(); | |
440 } | 447 } |
441 | 448 |
442 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 449 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
443 if (!page) | 450 if (!page) |
444 return 0.0; | 451 return 0.0; |
445 // return ((CPDF_Page*)page)->GetPageHeight(); | |
446 return ((CPDFXFA_Page*)page)->GetPageHeight(); | 452 return ((CPDFXFA_Page*)page)->GetPageHeight(); |
447 } | 453 } |
448 | 454 |
449 void DropContext(void* data) { | 455 void DropContext(void* data) { |
450 delete (CRenderContext*)data; | 456 delete (CRenderContext*)data; |
451 } | 457 } |
452 | 458 |
453 #if defined(_DEBUG) || defined(DEBUG) | 459 #if defined(_DEBUG) || defined(DEBUG) |
454 #define DEBUG_TRACE | 460 #define DEBUG_TRACE |
455 #endif | 461 #endif |
456 | 462 |
457 #if defined(_WIN32) | 463 #if defined(_WIN32) |
458 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, | 464 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
459 FPDF_PAGE page, | 465 FPDF_PAGE page, |
460 int start_x, | 466 int start_x, |
461 int start_y, | 467 int start_y, |
462 int size_x, | 468 int size_x, |
463 int size_y, | 469 int size_y, |
464 int rotate, | 470 int rotate, |
465 int flags) { | 471 int flags) { |
466 if (page == NULL) | 472 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
467 return; | |
468 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | |
469 if (!pPage) | 473 if (!pPage) |
470 return; | 474 return; |
471 | 475 |
472 CRenderContext* pContext = new CRenderContext; | 476 CRenderContext* pContext = new CRenderContext; |
473 pPage->SetPrivateData((void*)1, pContext, DropContext); | 477 pPage->SetPrivateData((void*)1, pContext, DropContext); |
474 | 478 |
475 #ifndef _WIN32_WCE | 479 #ifndef _WIN32_WCE |
476 CFX_DIBitmap* pBitmap = NULL; | 480 CFX_DIBitmap* pBitmap = NULL; |
477 FX_BOOL bBackgroundAlphaNeeded = FALSE; | 481 FX_BOOL bBackgroundAlphaNeeded = FALSE; |
478 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 482 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 #endif | 622 #endif |
619 | 623 |
620 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 624 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
621 FPDF_PAGE page, | 625 FPDF_PAGE page, |
622 int start_x, | 626 int start_x, |
623 int start_y, | 627 int start_y, |
624 int size_x, | 628 int size_x, |
625 int size_y, | 629 int size_y, |
626 int rotate, | 630 int rotate, |
627 int flags) { | 631 int flags) { |
628 if (bitmap == NULL || page == NULL) | 632 if (!bitmap) |
629 return; | 633 return; |
630 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 634 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
631 if (!pPage) | 635 if (!pPage) |
632 return; | 636 return; |
633 | |
634 CRenderContext* pContext = new CRenderContext; | 637 CRenderContext* pContext = new CRenderContext; |
635 pPage->SetPrivateData((void*)1, pContext, DropContext); | 638 pPage->SetPrivateData((void*)1, pContext, DropContext); |
636 #ifdef _SKIA_SUPPORT_ | 639 #ifdef _SKIA_SUPPORT_ |
637 pContext->m_pDevice = new CFX_SkiaDevice; | 640 pContext->m_pDevice = new CFX_SkiaDevice; |
638 | 641 |
639 if (flags & FPDF_REVERSE_BYTE_ORDER) | 642 if (flags & FPDF_REVERSE_BYTE_ORDER) |
640 ((CFX_SkiaDevice*)pContext->m_pDevice) | 643 ((CFX_SkiaDevice*)pContext->m_pDevice) |
641 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); | 644 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
642 else | 645 else |
643 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); | 646 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, | 698 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
696 int start_x, | 699 int start_x, |
697 int start_y, | 700 int start_y, |
698 int size_x, | 701 int size_x, |
699 int size_y, | 702 int size_y, |
700 int rotate, | 703 int rotate, |
701 double page_x, | 704 double page_x, |
702 double page_y, | 705 double page_y, |
703 int* device_x, | 706 int* device_x, |
704 int* device_y) { | 707 int* device_y) { |
705 if (page == NULL || device_x == NULL || device_y == NULL) | 708 if (!device_x || !device_y) |
706 return; | 709 return; |
707 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 710 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
711 if (!pPage) | |
712 return; | |
708 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, | 713 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, |
709 device_x, device_y); | 714 device_x, device_y); |
710 } | 715 } |
711 | 716 |
712 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 717 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
713 int height, | 718 int height, |
714 int alpha) { | 719 int alpha) { |
715 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 720 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
716 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { | 721 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { |
717 return NULL; | 722 return NULL; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 802 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
798 FPDF_PAGE page, | 803 FPDF_PAGE page, |
799 int start_x, | 804 int start_x, |
800 int start_y, | 805 int start_y, |
801 int size_x, | 806 int size_x, |
802 int size_y, | 807 int size_y, |
803 int rotate, | 808 int rotate, |
804 int flags, | 809 int flags, |
805 FX_BOOL bNeedToRestore, | 810 FX_BOOL bNeedToRestore, |
806 IFSDK_PAUSE_Adapter* pause) { | 811 IFSDK_PAUSE_Adapter* pause) { |
807 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 812 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
808 if (pPage == NULL) | 813 if (!pPage) |
809 return; | 814 return; |
810 | 815 |
811 if (!pContext->m_pOptions) | 816 if (!pContext->m_pOptions) |
812 pContext->m_pOptions = new CPDF_RenderOptions; | 817 pContext->m_pOptions = new CPDF_RenderOptions; |
813 | 818 |
814 if (flags & FPDF_LCD_TEXT) | 819 if (flags & FPDF_LCD_TEXT) |
815 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 820 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
816 else | 821 else |
817 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 822 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
818 if (flags & FPDF_NO_NATIVETEXT) | 823 if (flags & FPDF_NO_NATIVETEXT) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 if (!buffer) { | 1069 if (!buffer) { |
1065 *buflen = len; | 1070 *buflen = len; |
1066 } else if (*buflen >= len) { | 1071 } else if (*buflen >= len) { |
1067 memcpy(buffer, utf16Name.c_str(), len); | 1072 memcpy(buffer, utf16Name.c_str(), len); |
1068 *buflen = len; | 1073 *buflen = len; |
1069 } else { | 1074 } else { |
1070 *buflen = -1; | 1075 *buflen = -1; |
1071 } | 1076 } |
1072 return (FPDF_DEST)pDestObj; | 1077 return (FPDF_DEST)pDestObj; |
1073 } | 1078 } |
OLD | NEW |