| 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 <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (flags & FPDF_RENDER_FORCEHALFTONE) | 75 if (flags & FPDF_RENDER_FORCEHALFTONE) |
| 76 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; | 76 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; |
| 77 #ifndef PDF_ENABLE_XFA | 77 #ifndef PDF_ENABLE_XFA |
| 78 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) | 78 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) |
| 79 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; | 79 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; |
| 80 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) | 80 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) |
| 81 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; | 81 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; |
| 82 if (flags & FPDF_RENDER_NO_SMOOTHPATH) | 82 if (flags & FPDF_RENDER_NO_SMOOTHPATH) |
| 83 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; | 83 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; |
| 84 #endif // PDF_ENABLE_XFA | 84 #endif // PDF_ENABLE_XFA |
| 85 #ifdef _WIN32 |
| 86 if (flags & FPDF_COMPRESS_IMAGES) |
| 87 pContext->m_pOptions->m_Flags |= RENDER_COMPRESS_IMAGES; |
| 88 #endif |
| 85 | 89 |
| 86 // Grayscale output | 90 // Grayscale output |
| 87 if (flags & FPDF_GRAYSCALE) { | 91 if (flags & FPDF_GRAYSCALE) { |
| 88 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; | 92 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; |
| 89 pContext->m_pOptions->m_ForeColor = 0; | 93 pContext->m_pOptions->m_ForeColor = 0; |
| 90 pContext->m_pOptions->m_BackColor = 0xffffff; | 94 pContext->m_pOptions->m_BackColor = 0xffffff; |
| 91 } | 95 } |
| 92 | 96 |
| 93 const CPDF_OCContext::UsageType usage = | 97 const CPDF_OCContext::UsageType usage = |
| 94 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; | 98 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 } | 639 } |
| 636 | 640 |
| 637 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 641 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 638 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 642 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 639 return pPage ? pPage->GetPageHeight() : 0.0; | 643 return pPage ? pPage->GetPageHeight() : 0.0; |
| 640 } | 644 } |
| 641 | 645 |
| 642 #if defined(_WIN32) | 646 #if defined(_WIN32) |
| 643 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, | 647 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| 644 FPDF_PAGE page, | 648 FPDF_PAGE page, |
| 649 int driver_type, |
| 645 int start_x, | 650 int start_x, |
| 646 int start_y, | 651 int start_y, |
| 647 int size_x, | 652 int size_x, |
| 648 int size_y, | 653 int size_y, |
| 649 int rotate, | 654 int rotate, |
| 650 int flags) { | 655 int flags) { |
| 651 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 656 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 652 if (!pPage) | 657 if (!pPage) |
| 653 return; | 658 return; |
| 654 | 659 |
| 655 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; | 660 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
| 656 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); | 661 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
| 657 | 662 |
| 658 std::unique_ptr<CFX_DIBitmap> pBitmap; | 663 std::unique_ptr<CFX_DIBitmap> pBitmap; |
| 664 // TODO: This results in unnecessary rasterization of some PDFs due to |
| 665 // HasImageMask() returning true. If any image on the page is a mask, the |
| 666 // entire page gets rasterized and the spool size gets huge. |
| 659 const bool bNewBitmap = | 667 const bool bNewBitmap = |
| 660 pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); | 668 pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); |
| 661 if (bNewBitmap) { | 669 if (bNewBitmap) { |
| 662 pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); | 670 pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); |
| 663 pBitmap->Create(size_x, size_y, FXDIB_Argb); | 671 pBitmap->Create(size_x, size_y, FXDIB_Argb); |
| 664 pBitmap->Clear(0x00ffffff); | 672 pBitmap->Clear(0x00ffffff); |
| 665 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; | 673 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
| 666 pContext->m_pDevice = pdfium::WrapUnique(pDevice); | 674 pContext->m_pDevice = pdfium::WrapUnique(pDevice); |
| 667 pDevice->Attach(pBitmap.get(), false, nullptr, false); | 675 pDevice->Attach(pBitmap.get(), false, nullptr, false); |
| 668 } else { | 676 } else { |
| 669 pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc); | 677 pContext->m_pDevice = |
| 678 pdfium::MakeUnique<CFX_WindowsDevice>(dc, driver_type); |
| 670 } | 679 } |
| 671 | 680 |
| 672 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 681 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 673 rotate, flags, true, nullptr); | 682 rotate, flags, true, nullptr); |
| 674 | 683 |
| 675 if (bNewBitmap) { | 684 if (bNewBitmap) { |
| 676 CFX_WindowsDevice WinDC(dc); | 685 CFX_WindowsDevice WinDC(dc, driver_type); |
| 677 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { | 686 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
| 678 std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>(); | 687 std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>(); |
| 679 int pitch = pBitmap->GetPitch(); | 688 int pitch = pBitmap->GetPitch(); |
| 680 pDst->Create(size_x, size_y, FXDIB_Rgb32); | 689 pDst->Create(size_x, size_y, FXDIB_Rgb32); |
| 681 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); | 690 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); |
| 682 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0, | 691 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0, |
| 683 FXDIB_BLEND_NORMAL, nullptr, false, nullptr); | 692 FXDIB_BLEND_NORMAL, nullptr, false, nullptr); |
| 684 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); | 693 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); |
| 685 } else { | 694 } else { |
| 686 WinDC.SetDIBits(pBitmap.get(), 0, 0); | 695 WinDC.SetDIBits(pBitmap.get(), 0, 0); |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 if (!buffer) { | 1231 if (!buffer) { |
| 1223 *buflen = len; | 1232 *buflen = len; |
| 1224 } else if (len <= *buflen) { | 1233 } else if (len <= *buflen) { |
| 1225 memcpy(buffer, utf16Name.c_str(), len); | 1234 memcpy(buffer, utf16Name.c_str(), len); |
| 1226 *buflen = len; | 1235 *buflen = len; |
| 1227 } else { | 1236 } else { |
| 1228 *buflen = -1; | 1237 *buflen = -1; |
| 1229 } | 1238 } |
| 1230 return (FPDF_DEST)pDestObj; | 1239 return (FPDF_DEST)pDestObj; |
| 1231 } | 1240 } |
| OLD | NEW |