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 "core/include/fxcodec/fx_codec.h" | 9 #include "core/include/fxcodec/fx_codec.h" |
10 #include "core/include/fxcrt/fx_safe_types.h" | 10 #include "core/include/fxcrt/fx_safe_types.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, | 285 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, |
286 int page_index) { | 286 int page_index) { |
287 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 287 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
288 if (!pDoc) | 288 if (!pDoc) |
289 return nullptr; | 289 return nullptr; |
290 | 290 |
291 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 291 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
292 return nullptr; | 292 return nullptr; |
293 | 293 |
294 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 294 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
295 if (pDict == NULL) | 295 if (!pDict) |
296 return NULL; | 296 return NULL; |
297 CPDF_Page* pPage = new CPDF_Page; | 297 CPDF_Page* pPage = new CPDF_Page; |
298 pPage->Load(pDoc, pDict); | 298 pPage->Load(pDoc, pDict); |
299 pPage->ParseContent(); | 299 pPage->ParseContent(); |
300 return pPage; | 300 return pPage; |
301 } | 301 } |
302 | 302 |
303 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 303 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
304 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 304 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
305 return pPage ? pPage->GetPageWidth() : 0.0; | 305 return pPage ? pPage->GetPageWidth() : 0.0; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 LPVOID pBuffer; | 398 LPVOID pBuffer; |
399 BITMAPINFOHEADER bmih; | 399 BITMAPINFOHEADER bmih; |
400 FXSYS_memset(&bmih, 0, sizeof bmih); | 400 FXSYS_memset(&bmih, 0, sizeof bmih); |
401 bmih.biSize = sizeof bmih; | 401 bmih.biSize = sizeof bmih; |
402 bmih.biBitCount = 24; | 402 bmih.biBitCount = 24; |
403 bmih.biHeight = -height; | 403 bmih.biHeight = -height; |
404 bmih.biPlanes = 1; | 404 bmih.biPlanes = 1; |
405 bmih.biWidth = width; | 405 bmih.biWidth = width; |
406 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, | 406 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, |
407 &pBuffer, NULL, 0); | 407 &pBuffer, NULL, 0); |
408 if (pContext->m_hBitmap == NULL) { | 408 if (!pContext->m_hBitmap) { |
409 #if defined(DEBUG) || defined(_DEBUG) | 409 #if defined(DEBUG) || defined(_DEBUG) |
410 char str[128]; | 410 char str[128]; |
411 memset(str, 0, sizeof(str)); | 411 memset(str, 0, sizeof(str)); |
412 FXSYS_snprintf(str, sizeof(str) - 1, | 412 FXSYS_snprintf(str, sizeof(str) - 1, |
413 "Error CreateDIBSection: %d x %d, error code = %d", width, | 413 "Error CreateDIBSection: %d x %d, error code = %d", width, |
414 height, GetLastError()); | 414 height, GetLastError()); |
415 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); | 415 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); |
416 #else | 416 #else |
417 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); | 417 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); |
418 #endif | 418 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
436 // output to bitmap device | 436 // output to bitmap device |
437 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, | 437 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, |
438 start_y - rect.top, size_x, size_y, rotate, flags); | 438 start_y - rect.top, size_x, size_y, rotate, flags); |
439 | 439 |
440 #ifdef DEBUG_TRACE | 440 #ifdef DEBUG_TRACE |
441 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); | 441 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); |
442 #endif | 442 #endif |
443 | 443 |
444 // Now output to real device | 444 // Now output to real device |
445 HDC hMemDC = CreateCompatibleDC(dc); | 445 HDC hMemDC = CreateCompatibleDC(dc); |
446 if (hMemDC == NULL) { | 446 if (!hMemDC) { |
447 #if defined(DEBUG) || defined(_DEBUG) | 447 #if defined(DEBUG) || defined(_DEBUG) |
448 char str[128]; | 448 char str[128]; |
449 memset(str, 0, sizeof(str)); | 449 memset(str, 0, sizeof(str)); |
450 FXSYS_snprintf(str, sizeof(str) - 1, | 450 FXSYS_snprintf(str, sizeof(str) - 1, |
451 "Error CreateCompatibleDC. Error code = %d", GetLastError()); | 451 "Error CreateCompatibleDC. Error code = %d", GetLastError()); |
452 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); | 452 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); |
453 #else | 453 #else |
454 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); | 454 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); |
455 #endif | 455 #endif |
456 } | 456 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 551 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, |
552 int start_x, | 552 int start_x, |
553 int start_y, | 553 int start_y, |
554 int size_x, | 554 int size_x, |
555 int size_y, | 555 int size_y, |
556 int rotate, | 556 int rotate, |
557 int device_x, | 557 int device_x, |
558 int device_y, | 558 int device_y, |
559 double* page_x, | 559 double* page_x, |
560 double* page_y) { | 560 double* page_y) { |
561 if (page == NULL || page_x == NULL || page_y == NULL) | 561 if (!page || !page_x || !page_y) |
562 return; | 562 return; |
563 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 563 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
564 | 564 |
565 CFX_Matrix page2device; | 565 CFX_Matrix page2device; |
566 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, | 566 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
567 rotate); | 567 rotate); |
568 CFX_Matrix device2page; | 568 CFX_Matrix device2page; |
569 device2page.SetReverse(page2device); | 569 device2page.SetReverse(page2device); |
570 | 570 |
571 FX_FLOAT page_x_f, page_y_f; | 571 FX_FLOAT page_x_f, page_y_f; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); | 639 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); |
640 return pBitmap; | 640 return pBitmap; |
641 } | 641 } |
642 | 642 |
643 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, | 643 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
644 int left, | 644 int left, |
645 int top, | 645 int top, |
646 int width, | 646 int width, |
647 int height, | 647 int height, |
648 FPDF_DWORD color) { | 648 FPDF_DWORD color) { |
649 if (bitmap == NULL) | 649 if (!bitmap) |
650 return; | 650 return; |
651 #ifdef _SKIA_SUPPORT_ | 651 #ifdef _SKIA_SUPPORT_ |
652 CFX_SkiaDevice device; | 652 CFX_SkiaDevice device; |
653 #else | 653 #else |
654 CFX_FxgeDevice device; | 654 CFX_FxgeDevice device; |
655 #endif | 655 #endif |
656 device.Attach((CFX_DIBitmap*)bitmap); | 656 device.Attach((CFX_DIBitmap*)bitmap); |
657 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) | 657 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) |
658 color |= 0xFF000000; | 658 color |= 0xFF000000; |
659 FX_RECT rect(left, top, left + width, top + height); | 659 FX_RECT rect(left, top, left + width, top + height); |
660 device.FillRect(&rect, color); | 660 device.FillRect(&rect, color); |
661 } | 661 } |
662 | 662 |
663 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { | 663 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { |
664 if (bitmap == NULL) | 664 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetBuffer() : nullptr; |
665 return NULL; | |
666 return ((CFX_DIBitmap*)bitmap)->GetBuffer(); | |
667 } | 665 } |
668 | 666 |
669 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { | 667 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { |
670 if (bitmap == NULL) | 668 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetWidth() : 0; |
671 return 0; | |
672 return ((CFX_DIBitmap*)bitmap)->GetWidth(); | |
673 } | 669 } |
674 | 670 |
675 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { | 671 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { |
676 if (bitmap == NULL) | 672 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetHeight() : 0; |
677 return 0; | |
678 return ((CFX_DIBitmap*)bitmap)->GetHeight(); | |
679 } | 673 } |
680 | 674 |
681 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { | 675 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { |
682 if (bitmap == NULL) | 676 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetPitch() : 0; |
683 return 0; | |
684 return ((CFX_DIBitmap*)bitmap)->GetPitch(); | |
685 } | 677 } |
686 | 678 |
687 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { | 679 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { |
688 delete (CFX_DIBitmap*)bitmap; | 680 delete (CFX_DIBitmap*)bitmap; |
689 } | 681 } |
690 | 682 |
691 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 683 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
692 FPDF_PAGE page, | 684 FPDF_PAGE page, |
693 int start_x, | 685 int start_x, |
694 int start_y, | 686 int start_y, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 if (!buffer) { | 904 if (!buffer) { |
913 *buflen = len; | 905 *buflen = len; |
914 } else if (*buflen >= len) { | 906 } else if (*buflen >= len) { |
915 memcpy(buffer, utf16Name.c_str(), len); | 907 memcpy(buffer, utf16Name.c_str(), len); |
916 *buflen = len; | 908 *buflen = len; |
917 } else { | 909 } else { |
918 *buflen = -1; | 910 *buflen = -1; |
919 } | 911 } |
920 return (FPDF_DEST)pDestObj; | 912 return (FPDF_DEST)pDestObj; |
921 } | 913 } |
OLD | NEW |