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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 if (!pDoc) | 481 if (!pDoc) |
482 return nullptr; | 482 return nullptr; |
483 | 483 |
484 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 484 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
485 return nullptr; | 485 return nullptr; |
486 | 486 |
487 #ifdef PDF_ENABLE_XFA | 487 #ifdef PDF_ENABLE_XFA |
488 return pDoc->GetPage(page_index); | 488 return pDoc->GetPage(page_index); |
489 #else // PDF_ENABLE_XFA | 489 #else // PDF_ENABLE_XFA |
490 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 490 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
491 if (pDict == NULL) | 491 if (!pDict) |
492 return NULL; | 492 return NULL; |
493 CPDF_Page* pPage = new CPDF_Page; | 493 CPDF_Page* pPage = new CPDF_Page; |
494 pPage->Load(pDoc, pDict); | 494 pPage->Load(pDoc, pDict); |
495 pPage->ParseContent(); | 495 pPage->ParseContent(); |
496 return pPage; | 496 return pPage; |
497 #endif // PDF_ENABLE_XFA | 497 #endif // PDF_ENABLE_XFA |
498 } | 498 } |
499 | 499 |
500 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 500 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 LPVOID pBuffer; | 595 LPVOID pBuffer; |
596 BITMAPINFOHEADER bmih; | 596 BITMAPINFOHEADER bmih; |
597 FXSYS_memset(&bmih, 0, sizeof bmih); | 597 FXSYS_memset(&bmih, 0, sizeof bmih); |
598 bmih.biSize = sizeof bmih; | 598 bmih.biSize = sizeof bmih; |
599 bmih.biBitCount = 24; | 599 bmih.biBitCount = 24; |
600 bmih.biHeight = -height; | 600 bmih.biHeight = -height; |
601 bmih.biPlanes = 1; | 601 bmih.biPlanes = 1; |
602 bmih.biWidth = width; | 602 bmih.biWidth = width; |
603 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, | 603 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, |
604 &pBuffer, NULL, 0); | 604 &pBuffer, NULL, 0); |
605 if (pContext->m_hBitmap == NULL) { | 605 if (!pContext->m_hBitmap) { |
606 #if defined(DEBUG) || defined(_DEBUG) | 606 #if defined(DEBUG) || defined(_DEBUG) |
607 char str[128]; | 607 char str[128]; |
608 memset(str, 0, sizeof(str)); | 608 memset(str, 0, sizeof(str)); |
609 FXSYS_snprintf(str, sizeof(str) - 1, | 609 FXSYS_snprintf(str, sizeof(str) - 1, |
610 "Error CreateDIBSection: %d x %d, error code = %d", width, | 610 "Error CreateDIBSection: %d x %d, error code = %d", width, |
611 height, GetLastError()); | 611 height, GetLastError()); |
612 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); | 612 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); |
613 #else | 613 #else |
614 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); | 614 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); |
615 #endif | 615 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
633 // output to bitmap device | 633 // output to bitmap device |
634 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, | 634 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, |
635 start_y - rect.top, size_x, size_y, rotate, flags); | 635 start_y - rect.top, size_x, size_y, rotate, flags); |
636 | 636 |
637 #ifdef DEBUG_TRACE | 637 #ifdef DEBUG_TRACE |
638 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); | 638 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); |
639 #endif | 639 #endif |
640 | 640 |
641 // Now output to real device | 641 // Now output to real device |
642 HDC hMemDC = CreateCompatibleDC(dc); | 642 HDC hMemDC = CreateCompatibleDC(dc); |
643 if (hMemDC == NULL) { | 643 if (!hMemDC) { |
644 #if defined(DEBUG) || defined(_DEBUG) | 644 #if defined(DEBUG) || defined(_DEBUG) |
645 char str[128]; | 645 char str[128]; |
646 memset(str, 0, sizeof(str)); | 646 memset(str, 0, sizeof(str)); |
647 FXSYS_snprintf(str, sizeof(str) - 1, | 647 FXSYS_snprintf(str, sizeof(str) - 1, |
648 "Error CreateCompatibleDC. Error code = %d", GetLastError()); | 648 "Error CreateCompatibleDC. Error code = %d", GetLastError()); |
649 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); | 649 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); |
650 #else | 650 #else |
651 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); | 651 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); |
652 #endif | 652 #endif |
653 } | 653 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 756 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, |
757 int start_x, | 757 int start_x, |
758 int start_y, | 758 int start_y, |
759 int size_x, | 759 int size_x, |
760 int size_y, | 760 int size_y, |
761 int rotate, | 761 int rotate, |
762 int device_x, | 762 int device_x, |
763 int device_y, | 763 int device_y, |
764 double* page_x, | 764 double* page_x, |
765 double* page_y) { | 765 double* page_y) { |
766 if (page == NULL || page_x == NULL || page_y == NULL) | 766 if (!page || !page_x || !page_y) |
767 return; | 767 return; |
768 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 768 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
769 #ifdef PDF_ENABLE_XFA | 769 #ifdef PDF_ENABLE_XFA |
770 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, | 770 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, |
771 device_y, page_x, page_y); | 771 device_y, page_x, page_y); |
772 #else // PDF_ENABLE_XFA | 772 #else // PDF_ENABLE_XFA |
773 CFX_Matrix page2device; | 773 CFX_Matrix page2device; |
774 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, | 774 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
775 rotate); | 775 rotate); |
776 CFX_Matrix device2page; | 776 CFX_Matrix device2page; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); | 849 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); |
850 return pBitmap; | 850 return pBitmap; |
851 } | 851 } |
852 | 852 |
853 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, | 853 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
854 int left, | 854 int left, |
855 int top, | 855 int top, |
856 int width, | 856 int width, |
857 int height, | 857 int height, |
858 FPDF_DWORD color) { | 858 FPDF_DWORD color) { |
859 if (bitmap == NULL) | 859 if (!bitmap) |
860 return; | 860 return; |
861 #ifdef _SKIA_SUPPORT_ | 861 #ifdef _SKIA_SUPPORT_ |
862 CFX_SkiaDevice device; | 862 CFX_SkiaDevice device; |
863 #else | 863 #else |
864 CFX_FxgeDevice device; | 864 CFX_FxgeDevice device; |
865 #endif | 865 #endif |
866 device.Attach((CFX_DIBitmap*)bitmap); | 866 device.Attach((CFX_DIBitmap*)bitmap); |
867 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) | 867 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) |
868 color |= 0xFF000000; | 868 color |= 0xFF000000; |
869 FX_RECT rect(left, top, left + width, top + height); | 869 FX_RECT rect(left, top, left + width, top + height); |
870 device.FillRect(&rect, color); | 870 device.FillRect(&rect, color); |
871 } | 871 } |
872 | 872 |
873 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { | 873 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { |
874 if (bitmap == NULL) | 874 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetBuffer() : nullptr; |
875 return NULL; | |
876 return ((CFX_DIBitmap*)bitmap)->GetBuffer(); | |
877 } | 875 } |
878 | 876 |
879 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { | 877 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { |
880 if (bitmap == NULL) | 878 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetWidth() : 0; |
881 return 0; | |
882 return ((CFX_DIBitmap*)bitmap)->GetWidth(); | |
883 } | 879 } |
884 | 880 |
885 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { | 881 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { |
886 if (bitmap == NULL) | 882 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetHeight() : 0; |
887 return 0; | |
888 return ((CFX_DIBitmap*)bitmap)->GetHeight(); | |
889 } | 883 } |
890 | 884 |
891 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { | 885 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { |
892 if (bitmap == NULL) | 886 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetPitch() : 0; |
893 return 0; | |
894 return ((CFX_DIBitmap*)bitmap)->GetPitch(); | |
895 } | 887 } |
896 | 888 |
897 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { | 889 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { |
898 delete (CFX_DIBitmap*)bitmap; | 890 delete (CFX_DIBitmap*)bitmap; |
899 } | 891 } |
900 | 892 |
901 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 893 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
902 FPDF_PAGE page, | 894 FPDF_PAGE page, |
903 int start_x, | 895 int start_x, |
904 int start_y, | 896 int start_y, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 if (!buffer) { | 1180 if (!buffer) { |
1189 *buflen = len; | 1181 *buflen = len; |
1190 } else if (*buflen >= len) { | 1182 } else if (*buflen >= len) { |
1191 memcpy(buffer, utf16Name.c_str(), len); | 1183 memcpy(buffer, utf16Name.c_str(), len); |
1192 *buflen = len; | 1184 *buflen = len; |
1193 } else { | 1185 } else { |
1194 *buflen = -1; | 1186 *buflen = -1; |
1195 } | 1187 } |
1196 return (FPDF_DEST)pDestObj; | 1188 return (FPDF_DEST)pDestObj; |
1197 } | 1189 } |
OLD | NEW |