| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) | 433 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
| 430 return nullptr; | 434 return nullptr; |
| 431 | 435 |
| 432 return pDoc->GetPage(page_index); | 436 return pDoc->GetPage(page_index); |
| 433 } | 437 } |
| 434 | 438 |
| 435 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 439 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
| 436 if (!page) | 440 if (!page) |
| 437 return 0.0; | 441 return 0.0; |
| 438 return ((CPDFXFA_Page*)page)->GetPageWidth(); | 442 return ((CPDFXFA_Page*)page)->GetPageWidth(); |
| 439 // return ((CPDF_Page*)page)->GetPageWidth(); | |
| 440 } | 443 } |
| 441 | 444 |
| 442 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 445 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 443 if (!page) | 446 if (!page) |
| 444 return 0.0; | 447 return 0.0; |
| 445 // return ((CPDF_Page*)page)->GetPageHeight(); | |
| 446 return ((CPDFXFA_Page*)page)->GetPageHeight(); | 448 return ((CPDFXFA_Page*)page)->GetPageHeight(); |
| 447 } | 449 } |
| 448 | 450 |
| 449 void DropContext(void* data) { | 451 void DropContext(void* data) { |
| 450 delete (CRenderContext*)data; | 452 delete (CRenderContext*)data; |
| 451 } | 453 } |
| 452 | 454 |
| 453 #if defined(_DEBUG) || defined(DEBUG) | 455 #if defined(_DEBUG) || defined(DEBUG) |
| 454 #define DEBUG_TRACE | 456 #define DEBUG_TRACE |
| 455 #endif | 457 #endif |
| 456 | 458 |
| 457 #if defined(_WIN32) | 459 #if defined(_WIN32) |
| 458 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, | 460 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| 459 FPDF_PAGE page, | 461 FPDF_PAGE page, |
| 460 int start_x, | 462 int start_x, |
| 461 int start_y, | 463 int start_y, |
| 462 int size_x, | 464 int size_x, |
| 463 int size_y, | 465 int size_y, |
| 464 int rotate, | 466 int rotate, |
| 465 int flags) { | 467 int flags) { |
| 466 if (page == NULL) | 468 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 467 return; | |
| 468 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | |
| 469 if (!pPage) | 469 if (!pPage) |
| 470 return; | 470 return; |
| 471 | 471 |
| 472 CRenderContext* pContext = new CRenderContext; | 472 CRenderContext* pContext = new CRenderContext; |
| 473 pPage->SetPrivateData((void*)1, pContext, DropContext); | 473 pPage->SetPrivateData((void*)1, pContext, DropContext); |
| 474 | 474 |
| 475 #ifndef _WIN32_WCE | 475 #ifndef _WIN32_WCE |
| 476 CFX_DIBitmap* pBitmap = NULL; | 476 CFX_DIBitmap* pBitmap = NULL; |
| 477 FX_BOOL bBackgroundAlphaNeeded = FALSE; | 477 FX_BOOL bBackgroundAlphaNeeded = FALSE; |
| 478 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 478 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 #endif | 618 #endif |
| 619 | 619 |
| 620 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 620 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
| 621 FPDF_PAGE page, | 621 FPDF_PAGE page, |
| 622 int start_x, | 622 int start_x, |
| 623 int start_y, | 623 int start_y, |
| 624 int size_x, | 624 int size_x, |
| 625 int size_y, | 625 int size_y, |
| 626 int rotate, | 626 int rotate, |
| 627 int flags) { | 627 int flags) { |
| 628 if (bitmap == NULL || page == NULL) | 628 if (!bitmap) |
| 629 return; | 629 return; |
| 630 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 630 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 631 if (!pPage) | 631 if (!pPage) |
| 632 return; | 632 return; |
| 633 | |
| 634 CRenderContext* pContext = new CRenderContext; | 633 CRenderContext* pContext = new CRenderContext; |
| 635 pPage->SetPrivateData((void*)1, pContext, DropContext); | 634 pPage->SetPrivateData((void*)1, pContext, DropContext); |
| 636 #ifdef _SKIA_SUPPORT_ | 635 #ifdef _SKIA_SUPPORT_ |
| 637 pContext->m_pDevice = new CFX_SkiaDevice; | 636 pContext->m_pDevice = new CFX_SkiaDevice; |
| 638 | 637 |
| 639 if (flags & FPDF_REVERSE_BYTE_ORDER) | 638 if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 640 ((CFX_SkiaDevice*)pContext->m_pDevice) | 639 ((CFX_SkiaDevice*)pContext->m_pDevice) |
| 641 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); | 640 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 642 else | 641 else |
| 643 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); | 642 ((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, | 694 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
| 696 int start_x, | 695 int start_x, |
| 697 int start_y, | 696 int start_y, |
| 698 int size_x, | 697 int size_x, |
| 699 int size_y, | 698 int size_y, |
| 700 int rotate, | 699 int rotate, |
| 701 double page_x, | 700 double page_x, |
| 702 double page_y, | 701 double page_y, |
| 703 int* device_x, | 702 int* device_x, |
| 704 int* device_y) { | 703 int* device_y) { |
| 705 if (page == NULL || device_x == NULL || device_y == NULL) | 704 if (!device_x || !device_y) |
| 706 return; | 705 return; |
| 707 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 706 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
| 707 if (!pPage) |
| 708 return; |
| 708 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, | 709 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, |
| 709 device_x, device_y); | 710 device_x, device_y); |
| 710 } | 711 } |
| 711 | 712 |
| 712 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 713 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
| 713 int height, | 714 int height, |
| 714 int alpha) { | 715 int alpha) { |
| 715 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 716 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
| 716 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { | 717 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { |
| 717 return NULL; | 718 return NULL; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 798 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
| 798 FPDF_PAGE page, | 799 FPDF_PAGE page, |
| 799 int start_x, | 800 int start_x, |
| 800 int start_y, | 801 int start_y, |
| 801 int size_x, | 802 int size_x, |
| 802 int size_y, | 803 int size_y, |
| 803 int rotate, | 804 int rotate, |
| 804 int flags, | 805 int flags, |
| 805 FX_BOOL bNeedToRestore, | 806 FX_BOOL bNeedToRestore, |
| 806 IFSDK_PAUSE_Adapter* pause) { | 807 IFSDK_PAUSE_Adapter* pause) { |
| 807 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 808 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 808 if (pPage == NULL) | 809 if (!pPage) |
| 809 return; | 810 return; |
| 810 | 811 |
| 811 if (!pContext->m_pOptions) | 812 if (!pContext->m_pOptions) |
| 812 pContext->m_pOptions = new CPDF_RenderOptions; | 813 pContext->m_pOptions = new CPDF_RenderOptions; |
| 813 | 814 |
| 814 if (flags & FPDF_LCD_TEXT) | 815 if (flags & FPDF_LCD_TEXT) |
| 815 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 816 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
| 816 else | 817 else |
| 817 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 818 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
| 818 if (flags & FPDF_NO_NATIVETEXT) | 819 if (flags & FPDF_NO_NATIVETEXT) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 if (!buffer) { | 1065 if (!buffer) { |
| 1065 *buflen = len; | 1066 *buflen = len; |
| 1066 } else if (*buflen >= len) { | 1067 } else if (*buflen >= len) { |
| 1067 memcpy(buffer, utf16Name.c_str(), len); | 1068 memcpy(buffer, utf16Name.c_str(), len); |
| 1068 *buflen = len; | 1069 *buflen = len; |
| 1069 } else { | 1070 } else { |
| 1070 *buflen = -1; | 1071 *buflen = -1; |
| 1071 } | 1072 } |
| 1072 return (FPDF_DEST)pDestObj; | 1073 return (FPDF_DEST)pDestObj; |
| 1073 } | 1074 } |
| OLD | NEW |