Chromium Code Reviews| 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 | 10 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 int size_y, | 568 int size_y, |
| 569 int rotate, | 569 int rotate, |
| 570 int flags) { | 570 int flags) { |
| 571 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 571 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 572 if (!pPage) | 572 if (!pPage) |
| 573 return; | 573 return; |
| 574 | 574 |
| 575 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; | 575 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
| 576 pPage->SetRenderContext(WrapUnique(pContext)); | 576 pPage->SetRenderContext(WrapUnique(pContext)); |
| 577 | 577 |
| 578 CFX_DIBitmap* pBitmap = nullptr; | 578 CFX_DIBitmap* pBitmap = nullptr; |
|
Tom Sepez
2016/09/27 21:25:32
Can this be an unique_ptr? It looks like it only
Lei Zhang
2016/09/27 21:49:46
Done.
| |
| 579 FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 579 const bool bNewBitmap = |
| 580 FX_BOOL bHasImageMask = pPage->HasImageMask(); | 580 pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); |
| 581 if (bBackgroundAlphaNeeded || bHasImageMask) { | 581 if (bNewBitmap) { |
| 582 pBitmap = new CFX_DIBitmap; | 582 pBitmap = new CFX_DIBitmap; |
| 583 pBitmap->Create(size_x, size_y, FXDIB_Argb); | 583 pBitmap->Create(size_x, size_y, FXDIB_Argb); |
| 584 pBitmap->Clear(0x00ffffff); | 584 pBitmap->Clear(0x00ffffff); |
| 585 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; | 585 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
| 586 pContext->m_pDevice.reset(pDevice); | 586 pContext->m_pDevice.reset(pDevice); |
| 587 pDevice->Attach(pBitmap, false, nullptr, false); | 587 pDevice->Attach(pBitmap, false, nullptr, false); |
| 588 } else { | 588 } else { |
| 589 pContext->m_pDevice.reset(new CFX_WindowsDevice(dc)); | 589 pContext->m_pDevice.reset(new CFX_WindowsDevice(dc)); |
| 590 } | 590 } |
| 591 | 591 |
| 592 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 592 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 593 rotate, flags, TRUE, nullptr); | 593 rotate, flags, TRUE, nullptr); |
| 594 | 594 |
| 595 if (bBackgroundAlphaNeeded || bHasImageMask) { | 595 if (bNewBitmap) { |
| 596 if (pBitmap) { | 596 ASSERT(pBitmap); |
| 597 CFX_WindowsDevice WinDC(dc); | |
| 598 | 597 |
| 599 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { | 598 CFX_WindowsDevice WinDC(dc); |
| 600 CFX_DIBitmap* pDst = new CFX_DIBitmap; | 599 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
| 601 int pitch = pBitmap->GetPitch(); | 600 std::unique_ptr<CFX_DIBitmap> pDst = WrapUnique(new CFX_DIBitmap); |
| 602 pDst->Create(size_x, size_y, FXDIB_Rgb32); | 601 int pitch = pBitmap->GetPitch(); |
| 603 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); | 602 pDst->Create(size_x, size_y, FXDIB_Rgb32); |
| 604 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, | 603 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); |
| 605 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); | 604 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, |
| 606 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); | 605 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); |
| 607 delete pDst; | 606 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); |
| 608 } else { | 607 } else { |
| 609 WinDC.SetDIBits(pBitmap, 0, 0); | 608 WinDC.SetDIBits(pBitmap, 0, 0); |
| 610 } | |
| 611 } | 609 } |
| 610 delete pBitmap; | |
| 612 } | 611 } |
| 613 if (bBackgroundAlphaNeeded || bHasImageMask) | |
| 614 delete pBitmap; | |
| 615 | 612 |
| 616 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); | 613 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); |
| 617 } | 614 } |
| 618 #endif // defined(_WIN32) | 615 #endif // defined(_WIN32) |
| 619 | 616 |
| 620 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 617 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
| 621 FPDF_PAGE page, | 618 FPDF_PAGE page, |
| 622 int start_x, | 619 int start_x, |
| 623 int start_y, | 620 int start_y, |
| 624 int size_x, | 621 int size_x, |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 if (!buffer) { | 1126 if (!buffer) { |
| 1130 *buflen = len; | 1127 *buflen = len; |
| 1131 } else if (*buflen >= len) { | 1128 } else if (*buflen >= len) { |
| 1132 memcpy(buffer, utf16Name.c_str(), len); | 1129 memcpy(buffer, utf16Name.c_str(), len); |
| 1133 *buflen = len; | 1130 *buflen = len; |
| 1134 } else { | 1131 } else { |
| 1135 *buflen = -1; | 1132 *buflen = -1; |
| 1136 } | 1133 } |
| 1137 return (FPDF_DEST)pDestObj; | 1134 return (FPDF_DEST)pDestObj; |
| 1138 } | 1135 } |
| OLD | NEW |