| 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/fxcodec/fx_codec.h" | 7 #include "../../core/include/fxcodec/fx_codec.h" |
| 8 #include "../../core/include/fxcrt/fx_safe_types.h" | 8 #include "../../core/include/fxcrt/fx_safe_types.h" |
| 9 #include "../../public/fpdf_ext.h" | 9 #include "../../public/fpdf_ext.h" |
| 10 #include "../../public/fpdf_progressive.h" | 10 #include "../../public/fpdf_progressive.h" |
| 11 #include "../../public/fpdfview.h" | 11 #include "../../public/fpdfview.h" |
| 12 #include "../../third_party/base/nonstd_unique_ptr.h" | 12 #include "../../third_party/base/nonstd_unique_ptr.h" |
| 13 #include "../../third_party/base/numerics/safe_conversions_impl.h" | 13 #include "../../third_party/base/numerics/safe_conversions_impl.h" |
| 14 #include "../include/fsdk_define.h" | 14 #include "../include/fsdk_define.h" |
| 15 #include "../include/fsdk_mgr.h" | 15 #include "../include/fsdk_mgr.h" |
| 16 #include "../include/fsdk_rendercontext.h" | 16 #include "../include/fsdk_rendercontext.h" |
| 17 #include "../include/javascript/IJavaScript.h" | 17 #include "../include/javascript/IJavaScript.h" |
| 18 | 18 |
| 19 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 19 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 20 return static_cast<CPDF_Document*>(doc); | 20 return static_cast<CPDF_Document*>(doc); |
| 21 } | 21 } |
| 22 | 22 |
| 23 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
| 24 return static_cast<CPDF_Page*>(page); |
| 25 } |
| 26 |
| 23 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 27 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
| 24 if (pFileAccess) | 28 if (pFileAccess) |
| 25 m_FileAccess = *pFileAccess; | 29 m_FileAccess = *pFileAccess; |
| 26 } | 30 } |
| 27 | 31 |
| 28 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 32 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, |
| 29 FX_FILESIZE offset, | 33 FX_FILESIZE offset, |
| 30 size_t size) { | 34 size_t size) { |
| 31 if (offset < 0) { | 35 if (offset < 0) { |
| 32 return FALSE; | 36 return FALSE; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 281 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
| 278 if (pDict == NULL) | 282 if (pDict == NULL) |
| 279 return NULL; | 283 return NULL; |
| 280 CPDF_Page* pPage = new CPDF_Page; | 284 CPDF_Page* pPage = new CPDF_Page; |
| 281 pPage->Load(pDoc, pDict); | 285 pPage->Load(pDoc, pDict); |
| 282 pPage->ParseContent(); | 286 pPage->ParseContent(); |
| 283 return pPage; | 287 return pPage; |
| 284 } | 288 } |
| 285 | 289 |
| 286 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 290 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
| 287 if (!page) | 291 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 288 return 0.0; | 292 return pPage ? pPage->GetPageWidth() : 0.0; |
| 289 return ((CPDF_Page*)page)->GetPageWidth(); | |
| 290 } | 293 } |
| 291 | 294 |
| 292 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 295 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 293 if (!page) | 296 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 294 return 0.0; | 297 return pPage ? pPage->GetPageHeight() : 0.0; |
| 295 return ((CPDF_Page*)page)->GetPageHeight(); | |
| 296 } | 298 } |
| 297 | 299 |
| 298 void DropContext(void* data) { | 300 void DropContext(void* data) { |
| 299 delete (CRenderContext*)data; | 301 delete (CRenderContext*)data; |
| 300 } | 302 } |
| 301 | 303 |
| 302 #if defined(_DEBUG) || defined(DEBUG) | 304 #if defined(_DEBUG) || defined(DEBUG) |
| 303 #define DEBUG_TRACE | 305 #define DEBUG_TRACE |
| 304 #endif | 306 #endif |
| 305 | 307 |
| 306 #if defined(_WIN32) | 308 #if defined(_WIN32) |
| 307 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, | 309 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| 308 FPDF_PAGE page, | 310 FPDF_PAGE page, |
| 309 int start_x, | 311 int start_x, |
| 310 int start_y, | 312 int start_y, |
| 311 int size_x, | 313 int size_x, |
| 312 int size_y, | 314 int size_y, |
| 313 int rotate, | 315 int rotate, |
| 314 int flags) { | 316 int flags) { |
| 315 if (page == NULL) | 317 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 318 if (!pPage) |
| 316 return; | 319 return; |
| 317 CPDF_Page* pPage = (CPDF_Page*)page; | |
| 318 | 320 |
| 319 CRenderContext* pContext = new CRenderContext; | 321 CRenderContext* pContext = new CRenderContext; |
| 320 pPage->SetPrivateData((void*)1, pContext, DropContext); | 322 pPage->SetPrivateData((void*)1, pContext, DropContext); |
| 321 | 323 |
| 322 #ifndef _WIN32_WCE | 324 #ifndef _WIN32_WCE |
| 323 CFX_DIBitmap* pBitmap = NULL; | 325 CFX_DIBitmap* pBitmap = NULL; |
| 324 FX_BOOL bBackgroundAlphaNeeded = FALSE; | 326 FX_BOOL bBackgroundAlphaNeeded = FALSE; |
| 325 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 327 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
| 326 if (bBackgroundAlphaNeeded) { | 328 if (bBackgroundAlphaNeeded) { |
| 327 pBitmap = new CFX_DIBitmap; | 329 pBitmap = new CFX_DIBitmap; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 #endif | 467 #endif |
| 466 | 468 |
| 467 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 469 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
| 468 FPDF_PAGE page, | 470 FPDF_PAGE page, |
| 469 int start_x, | 471 int start_x, |
| 470 int start_y, | 472 int start_y, |
| 471 int size_x, | 473 int size_x, |
| 472 int size_y, | 474 int size_y, |
| 473 int rotate, | 475 int rotate, |
| 474 int flags) { | 476 int flags) { |
| 475 if (bitmap == NULL || page == NULL) | 477 if (!bitmap) |
| 476 return; | 478 return; |
| 477 CPDF_Page* pPage = (CPDF_Page*)page; | 479 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 478 | 480 if (!pPage) |
| 481 return; |
| 479 CRenderContext* pContext = new CRenderContext; | 482 CRenderContext* pContext = new CRenderContext; |
| 480 pPage->SetPrivateData((void*)1, pContext, DropContext); | 483 pPage->SetPrivateData((void*)1, pContext, DropContext); |
| 481 #ifdef _SKIA_SUPPORT_ | 484 #ifdef _SKIA_SUPPORT_ |
| 482 pContext->m_pDevice = new CFX_SkiaDevice; | 485 pContext->m_pDevice = new CFX_SkiaDevice; |
| 483 | 486 |
| 484 if (flags & FPDF_REVERSE_BYTE_ORDER) | 487 if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 485 ((CFX_SkiaDevice*)pContext->m_pDevice) | 488 ((CFX_SkiaDevice*)pContext->m_pDevice) |
| 486 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); | 489 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 487 else | 490 else |
| 488 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); | 491 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, | 566 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
| 564 int start_x, | 567 int start_x, |
| 565 int start_y, | 568 int start_y, |
| 566 int size_x, | 569 int size_x, |
| 567 int size_y, | 570 int size_y, |
| 568 int rotate, | 571 int rotate, |
| 569 double page_x, | 572 double page_x, |
| 570 double page_y, | 573 double page_y, |
| 571 int* device_x, | 574 int* device_x, |
| 572 int* device_y) { | 575 int* device_y) { |
| 573 if (page == NULL || device_x == NULL || device_y == NULL) | 576 if (!device_x || !device_y) |
| 574 return; | 577 return; |
| 575 CPDF_Page* pPage = (CPDF_Page*)page; | 578 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 576 | 579 if (!pPage) |
| 580 return; |
| 577 CPDF_Matrix page2device; | 581 CPDF_Matrix page2device; |
| 578 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, | 582 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
| 579 rotate); | 583 rotate); |
| 580 | 584 |
| 581 FX_FLOAT device_x_f, device_y_f; | 585 FX_FLOAT device_x_f, device_y_f; |
| 582 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, | 586 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, |
| 583 device_y_f); | 587 device_y_f); |
| 584 | 588 |
| 585 *device_x = FXSYS_round(device_x_f); | 589 *device_x = FXSYS_round(device_x_f); |
| 586 *device_y = FXSYS_round(device_y_f); | 590 *device_y = FXSYS_round(device_y_f); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 678 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
| 675 FPDF_PAGE page, | 679 FPDF_PAGE page, |
| 676 int start_x, | 680 int start_x, |
| 677 int start_y, | 681 int start_y, |
| 678 int size_x, | 682 int size_x, |
| 679 int size_y, | 683 int size_y, |
| 680 int rotate, | 684 int rotate, |
| 681 int flags, | 685 int flags, |
| 682 FX_BOOL bNeedToRestore, | 686 FX_BOOL bNeedToRestore, |
| 683 IFSDK_PAUSE_Adapter* pause) { | 687 IFSDK_PAUSE_Adapter* pause) { |
| 684 CPDF_Page* pPage = (CPDF_Page*)page; | 688 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 685 if (pPage == NULL) | 689 if (!pPage) |
| 686 return; | 690 return; |
| 687 | 691 |
| 688 if (!pContext->m_pOptions) | 692 if (!pContext->m_pOptions) |
| 689 pContext->m_pOptions = new CPDF_RenderOptions; | 693 pContext->m_pOptions = new CPDF_RenderOptions; |
| 690 | 694 |
| 691 if (flags & FPDF_LCD_TEXT) | 695 if (flags & FPDF_LCD_TEXT) |
| 692 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 696 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
| 693 else | 697 else |
| 694 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 698 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
| 695 if (flags & FPDF_NO_NATIVETEXT) | 699 if (flags & FPDF_NO_NATIVETEXT) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 if (!buffer) { | 894 if (!buffer) { |
| 891 *buflen = len; | 895 *buflen = len; |
| 892 } else if (*buflen >= len) { | 896 } else if (*buflen >= len) { |
| 893 memcpy(buffer, utf16Name.c_str(), len); | 897 memcpy(buffer, utf16Name.c_str(), len); |
| 894 *buflen = len; | 898 *buflen = len; |
| 895 } else { | 899 } else { |
| 896 *buflen = -1; | 900 *buflen = -1; |
| 897 } | 901 } |
| 898 return (FPDF_DEST)pDestObj; | 902 return (FPDF_DEST)pDestObj; |
| 899 } | 903 } |
| OLD | NEW |