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 <crtdbg.h> | 7 #include <crtdbg.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 RestoreDC(m_hDC, -1); | 788 RestoreDC(m_hDC, -1); |
789 if (bKeepSaved) | 789 if (bKeepSaved) |
790 SaveDC(m_hDC); | 790 SaveDC(m_hDC); |
791 } | 791 } |
792 | 792 |
793 bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, | 793 bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, |
794 const FX_RECT* pSrcRect, | 794 const FX_RECT* pSrcRect, |
795 int left, | 795 int left, |
796 int top) { | 796 int top) { |
797 if (m_DeviceClass == FXDC_PRINTER) { | 797 if (m_DeviceClass == FXDC_PRINTER) { |
798 std::unique_ptr<CFX_DIBitmap> pBitmap(pBitmap1->FlipImage(false, true)); | 798 std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true); |
799 if (!pBitmap) | 799 if (!pBitmap) |
800 return false; | 800 return false; |
801 | 801 |
802 if (pBitmap->IsCmykImage() && !pBitmap->ConvertFormat(FXDIB_Rgb)) | 802 if (pBitmap->IsCmykImage() && !pBitmap->ConvertFormat(FXDIB_Rgb)) |
803 return false; | 803 return false; |
804 | 804 |
805 int width = pSrcRect->Width(), height = pSrcRect->Height(); | 805 int width = pSrcRect->Width(), height = pSrcRect->Height(); |
806 LPBYTE pBuffer = pBitmap->GetBuffer(); | 806 LPBYTE pBuffer = pBitmap->GetBuffer(); |
807 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get()); | 807 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get()); |
808 ((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1; | 808 ((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1; |
809 FX_RECT dst_rect(0, 0, width, height); | 809 FX_RECT dst_rect(0, 0, width, height); |
810 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); | 810 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); |
811 int dst_width = dst_rect.Width(); | 811 int dst_width = dst_rect.Width(); |
812 int dst_height = dst_rect.Height(); | 812 int dst_height = dst_rect.Height(); |
813 ::StretchDIBits(m_hDC, left, top, dst_width, dst_height, 0, 0, dst_width, | 813 ::StretchDIBits(m_hDC, left, top, dst_width, dst_height, 0, 0, dst_width, |
814 dst_height, pBuffer, (BITMAPINFO*)info.c_str(), | 814 dst_height, pBuffer, (BITMAPINFO*)info.c_str(), |
815 DIB_RGB_COLORS, SRCCOPY); | 815 DIB_RGB_COLORS, SRCCOPY); |
816 } else { | 816 } else { |
817 CFX_DIBitmap* pBitmap = pBitmap1; | 817 CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1); |
818 if (pBitmap->IsCmykImage()) { | 818 if (pBitmap->IsCmykImage()) { |
819 pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release(); | 819 pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release(); |
820 if (!pBitmap) | 820 if (!pBitmap) |
821 return false; | 821 return false; |
822 } | 822 } |
823 int width = pSrcRect->Width(), height = pSrcRect->Height(); | 823 int width = pSrcRect->Width(), height = pSrcRect->Height(); |
824 LPBYTE pBuffer = pBitmap->GetBuffer(); | 824 LPBYTE pBuffer = pBitmap->GetBuffer(); |
825 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); | 825 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get()); |
826 ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, | 826 ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, |
827 pBitmap->GetHeight() - pSrcRect->bottom, 0, | 827 pBitmap->GetHeight() - pSrcRect->bottom, 0, |
828 pBitmap->GetHeight(), pBuffer, | 828 pBitmap->GetHeight(), pBuffer, |
829 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); | 829 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); |
830 if (pBitmap != pBitmap1) { | |
831 delete pBitmap; | |
832 } | |
833 } | 830 } |
834 return true; | 831 return true; |
835 } | 832 } |
836 | 833 |
837 bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1, | 834 bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1, |
838 int dest_left, | 835 int dest_left, |
839 int dest_top, | 836 int dest_top, |
840 int dest_width, | 837 int dest_width, |
841 int dest_height, | 838 int dest_height, |
842 uint32_t flags) { | 839 uint32_t flags) { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 // static | 1383 // static |
1387 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC) { | 1384 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC) { |
1388 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY); | 1385 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY); |
1389 int obj_type = ::GetObjectType(hDC); | 1386 int obj_type = ::GetObjectType(hDC); |
1390 bool use_printer = device_type == DT_RASPRINTER || | 1387 bool use_printer = device_type == DT_RASPRINTER || |
1391 device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC; | 1388 device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC; |
1392 if (use_printer) | 1389 if (use_printer) |
1393 return new CGdiPrinterDriver(hDC); | 1390 return new CGdiPrinterDriver(hDC); |
1394 return new CGdiDisplayDriver(hDC); | 1391 return new CGdiDisplayDriver(hDC); |
1395 } | 1392 } |
OLD | NEW |