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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 } | 67 } |
68 | 68 |
69 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 69 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
70 #ifdef PDF_ENABLE_XFA | 70 #ifdef PDF_ENABLE_XFA |
71 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | 71 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
72 #else // PDF_ENABLE_XFA | 72 #else // PDF_ENABLE_XFA |
73 return UnderlyingFromFPDFPage(page); | 73 return UnderlyingFromFPDFPage(page); |
74 #endif // PDF_ENABLE_XFA | 74 #endif // PDF_ENABLE_XFA |
75 } | 75 } |
76 | 76 |
77 CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { | |
78 return static_cast<CFX_DIBitmap*>(bitmap); | |
79 } | |
80 | |
77 #ifdef PDF_ENABLE_XFA | 81 #ifdef PDF_ENABLE_XFA |
78 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 82 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
79 m_pFS = pFS; | 83 m_pFS = pFS; |
80 m_nCurPos = 0; | 84 m_nCurPos = 0; |
81 } | 85 } |
82 | 86 |
83 IFX_FileStream* CFPDF_FileStream::Retain() { | 87 IFX_FileStream* CFPDF_FileStream::Retain() { |
84 return this; | 88 return this; |
85 } | 89 } |
86 | 90 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 int size_y, | 534 int size_y, |
531 int rotate, | 535 int rotate, |
532 int flags) { | 536 int flags) { |
533 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 537 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
534 if (!pPage) | 538 if (!pPage) |
535 return; | 539 return; |
536 | 540 |
537 CRenderContext* pContext = new CRenderContext; | 541 CRenderContext* pContext = new CRenderContext; |
538 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); | 542 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
539 | 543 |
540 #if !defined(_WIN32_WCE) | |
Lei Zhang
2016/05/26 18:11:29
I have separate CL to delete other WinCE code, but
| |
541 CFX_DIBitmap* pBitmap = nullptr; | 544 CFX_DIBitmap* pBitmap = nullptr; |
542 FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 545 FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
543 FX_BOOL bHasImageMask = pPage->HasImageMask(); | 546 FX_BOOL bHasImageMask = pPage->HasImageMask(); |
544 if (bBackgroundAlphaNeeded || bHasImageMask) { | 547 if (bBackgroundAlphaNeeded || bHasImageMask) { |
545 pBitmap = new CFX_DIBitmap; | 548 pBitmap = new CFX_DIBitmap; |
546 pBitmap->Create(size_x, size_y, FXDIB_Argb); | 549 pBitmap->Create(size_x, size_y, FXDIB_Argb); |
547 pBitmap->Clear(0x00ffffff); | 550 pBitmap->Clear(0x00ffffff); |
548 pContext->m_pDevice = new CFX_FxgeDevice; | 551 pContext->m_pDevice = new CFX_FxgeDevice; |
549 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); | 552 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach(pBitmap); |
550 } else { | 553 } else { |
551 pContext->m_pDevice = new CFX_WindowsDevice(dc); | 554 pContext->m_pDevice = new CFX_WindowsDevice(dc); |
552 } | 555 } |
553 | 556 |
554 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 557 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
555 rotate, flags, TRUE, NULL); | 558 rotate, flags, TRUE, NULL); |
556 | 559 |
557 if (bBackgroundAlphaNeeded || bHasImageMask) { | 560 if (bBackgroundAlphaNeeded || bHasImageMask) { |
558 if (pBitmap) { | 561 if (pBitmap) { |
559 CFX_WindowsDevice WinDC(dc); | 562 CFX_WindowsDevice WinDC(dc); |
560 | 563 |
561 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { | 564 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
562 CFX_DIBitmap* pDst = new CFX_DIBitmap; | 565 CFX_DIBitmap* pDst = new CFX_DIBitmap; |
563 int pitch = pBitmap->GetPitch(); | 566 int pitch = pBitmap->GetPitch(); |
564 pDst->Create(size_x, size_y, FXDIB_Rgb32); | 567 pDst->Create(size_x, size_y, FXDIB_Rgb32); |
565 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); | 568 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); |
566 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, | 569 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, |
567 FXDIB_BLEND_NORMAL, NULL, FALSE, NULL); | 570 FXDIB_BLEND_NORMAL, NULL, FALSE, NULL); |
568 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); | 571 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); |
569 delete pDst; | 572 delete pDst; |
570 } else { | 573 } else { |
571 WinDC.SetDIBits(pBitmap, 0, 0); | 574 WinDC.SetDIBits(pBitmap, 0, 0); |
572 } | 575 } |
573 } | 576 } |
574 } | 577 } |
575 #else | |
576 // get clip region | |
577 RECT rect, cliprect; | |
578 rect.left = start_x; | |
579 rect.top = start_y; | |
580 rect.right = start_x + size_x; | |
581 rect.bottom = start_y + size_y; | |
582 GetClipBox(dc, &cliprect); | |
583 IntersectRect(&rect, &rect, &cliprect); | |
584 int width = rect.right - rect.left; | |
585 int height = rect.bottom - rect.top; | |
586 | |
587 // Create a DIB section | |
588 LPVOID pBuffer; | |
589 BITMAPINFOHEADER bmih; | |
590 FXSYS_memset(&bmih, 0, sizeof bmih); | |
591 bmih.biSize = sizeof bmih; | |
592 bmih.biBitCount = 24; | |
593 bmih.biHeight = -height; | |
594 bmih.biPlanes = 1; | |
595 bmih.biWidth = width; | |
596 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, | |
597 &pBuffer, NULL, 0); | |
598 FXSYS_memset(pBuffer, 0xff, height * ((width * 3 + 3) / 4 * 4)); | |
599 | |
600 // Create a device with this external buffer | |
601 pContext->m_pBitmap = new CFX_DIBitmap; | |
602 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer); | |
603 pContext->m_pDevice = new CPDF_FxgeDevice; | |
604 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); | |
605 | |
606 // output to bitmap device | |
607 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, | |
608 start_y - rect.top, size_x, size_y, rotate, flags); | |
609 | |
610 // Now output to real device | |
611 HDC hMemDC = CreateCompatibleDC(dc); | |
612 HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); | |
613 | |
614 BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); | |
615 SelectObject(hMemDC, hOldBitmap); | |
616 DeleteDC(hMemDC); | |
617 | |
618 #endif // !defined(_WIN32_WCE) | |
619 if (bBackgroundAlphaNeeded || bHasImageMask) | 578 if (bBackgroundAlphaNeeded || bHasImageMask) |
620 delete pBitmap; | 579 delete pBitmap; |
621 | 580 |
622 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); | 581 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
623 } | 582 } |
624 #endif // defined(_WIN32) | 583 #endif // defined(_WIN32) |
625 | 584 |
626 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 585 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
627 FPDF_PAGE page, | 586 FPDF_PAGE page, |
628 int start_x, | 587 int start_x, |
629 int start_y, | 588 int start_y, |
630 int size_x, | 589 int size_x, |
631 int size_y, | 590 int size_y, |
632 int rotate, | 591 int rotate, |
633 int flags) { | 592 int flags) { |
634 if (!bitmap) | 593 if (!bitmap) |
635 return; | 594 return; |
636 | 595 |
637 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 596 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
638 if (!pPage) | 597 if (!pPage) |
639 return; | 598 return; |
640 | 599 |
641 CRenderContext* pContext = new CRenderContext; | 600 CRenderContext* pContext = new CRenderContext; |
642 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); | 601 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
643 pContext->m_pDevice = new CFX_FxgeDevice; | 602 pContext->m_pDevice = new CFX_FxgeDevice; |
603 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); | |
644 if (flags & FPDF_REVERSE_BYTE_ORDER) { | 604 if (flags & FPDF_REVERSE_BYTE_ORDER) { |
645 ((CFX_FxgeDevice*)pContext->m_pDevice) | 605 ((CFX_FxgeDevice*)pContext->m_pDevice) |
646 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); | 606 ->AttachEx(pBitmap, true, nullptr, false); |
647 } else { | 607 } else { |
648 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); | 608 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach(pBitmap); |
649 } | 609 } |
650 | 610 |
651 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 611 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
652 rotate, flags, TRUE, nullptr); | 612 rotate, flags, TRUE, nullptr); |
653 | 613 |
654 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); | 614 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
655 } | 615 } |
656 | 616 |
657 #ifdef _SKIA_SUPPORT_ | 617 #ifdef _SKIA_SUPPORT_ |
658 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, | 618 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 } | 769 } |
810 | 770 |
811 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, | 771 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
812 int left, | 772 int left, |
813 int top, | 773 int top, |
814 int width, | 774 int width, |
815 int height, | 775 int height, |
816 FPDF_DWORD color) { | 776 FPDF_DWORD color) { |
817 if (!bitmap) | 777 if (!bitmap) |
818 return; | 778 return; |
779 | |
819 CFX_FxgeDevice device; | 780 CFX_FxgeDevice device; |
820 device.Attach((CFX_DIBitmap*)bitmap); | 781 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
821 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) | 782 device.Attach(pBitmap); |
783 if (!pBitmap->HasAlpha()) | |
822 color |= 0xFF000000; | 784 color |= 0xFF000000; |
823 FX_RECT rect(left, top, left + width, top + height); | 785 FX_RECT rect(left, top, left + width, top + height); |
824 device.FillRect(&rect, color); | 786 device.FillRect(&rect, color); |
825 } | 787 } |
826 | 788 |
827 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { | 789 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { |
828 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetBuffer() : nullptr; | 790 return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetBuffer() : nullptr; |
829 } | 791 } |
830 | 792 |
831 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { | 793 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { |
832 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetWidth() : 0; | 794 return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetWidth() : 0; |
833 } | 795 } |
834 | 796 |
835 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { | 797 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { |
836 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetHeight() : 0; | 798 return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetHeight() : 0; |
837 } | 799 } |
838 | 800 |
839 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { | 801 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { |
840 return bitmap ? ((CFX_DIBitmap*)bitmap)->GetPitch() : 0; | 802 return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetPitch() : 0; |
841 } | 803 } |
842 | 804 |
843 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { | 805 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { |
844 delete (CFX_DIBitmap*)bitmap; | 806 delete CFXBitmapFromFPDFBitmap(bitmap); |
845 } | 807 } |
846 | 808 |
847 void FPDF_RenderPage_Retail(CRenderContext* pContext, | 809 void FPDF_RenderPage_Retail(CRenderContext* pContext, |
848 FPDF_PAGE page, | 810 FPDF_PAGE page, |
849 int start_x, | 811 int start_x, |
850 int start_y, | 812 int start_y, |
851 int size_x, | 813 int size_x, |
852 int size_y, | 814 int size_y, |
853 int rotate, | 815 int rotate, |
854 int flags, | 816 int flags, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 if (!buffer) { | 1101 if (!buffer) { |
1140 *buflen = len; | 1102 *buflen = len; |
1141 } else if (*buflen >= len) { | 1103 } else if (*buflen >= len) { |
1142 memcpy(buffer, utf16Name.c_str(), len); | 1104 memcpy(buffer, utf16Name.c_str(), len); |
1143 *buflen = len; | 1105 *buflen = len; |
1144 } else { | 1106 } else { |
1145 *buflen = -1; | 1107 *buflen = -1; |
1146 } | 1108 } |
1147 return (FPDF_DEST)pDestObj; | 1109 return (FPDF_DEST)pDestObj; |
1148 } | 1110 } |
OLD | NEW |