Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Side by Side Diff: fpdfsdk/fpdfview.cpp

Issue 2369323004: Simplify FPDF_RenderPage(). (Closed)
Patch Set: More unique_ptr Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 std::unique_ptr<CFX_DIBitmap> pBitmap;
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 = WrapUnique(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 = WrapUnique(pDevice);
587 pDevice->Attach(pBitmap, false, nullptr, false); 587 pDevice->Attach(pBitmap.get(), false, nullptr, false);
588 } else { 588 } else {
589 pContext->m_pDevice.reset(new CFX_WindowsDevice(dc)); 589 pContext->m_pDevice = WrapUnique(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 CFX_WindowsDevice WinDC(dc);
597 CFX_WindowsDevice WinDC(dc); 597 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
598 598 std::unique_ptr<CFX_DIBitmap> pDst = WrapUnique(new CFX_DIBitmap);
599 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { 599 int pitch = pBitmap->GetPitch();
600 CFX_DIBitmap* pDst = new CFX_DIBitmap; 600 pDst->Create(size_x, size_y, FXDIB_Rgb32);
601 int pitch = pBitmap->GetPitch(); 601 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y);
602 pDst->Create(size_x, size_y, FXDIB_Rgb32); 602 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0,
603 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); 603 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr);
604 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, 604 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y);
605 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); 605 } else {
606 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); 606 WinDC.SetDIBits(pBitmap.get(), 0, 0);
607 delete pDst;
608 } else {
609 WinDC.SetDIBits(pBitmap, 0, 0);
610 }
611 } 607 }
612 } 608 }
613 if (bBackgroundAlphaNeeded || bHasImageMask)
614 delete pBitmap;
615 609
616 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); 610 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>());
617 } 611 }
618 #endif // defined(_WIN32) 612 #endif // defined(_WIN32)
619 613
620 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, 614 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
621 FPDF_PAGE page, 615 FPDF_PAGE page,
622 int start_x, 616 int start_x,
623 int start_y, 617 int start_y,
624 int size_x, 618 int size_x,
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 if (!buffer) { 1123 if (!buffer) {
1130 *buflen = len; 1124 *buflen = len;
1131 } else if (*buflen >= len) { 1125 } else if (*buflen >= len) {
1132 memcpy(buffer, utf16Name.c_str(), len); 1126 memcpy(buffer, utf16Name.c_str(), len);
1133 *buflen = len; 1127 *buflen = len;
1134 } else { 1128 } else {
1135 *buflen = -1; 1129 *buflen = -1;
1136 } 1130 }
1137 return (FPDF_DEST)pDestObj; 1131 return (FPDF_DEST)pDestObj;
1138 } 1132 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698