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 15 matching lines...) Expand all Loading... |
26 #include "core/fxcrt/fx_safe_types.h" | 26 #include "core/fxcrt/fx_safe_types.h" |
27 #include "core/fxge/cfx_fxgedevice.h" | 27 #include "core/fxge/cfx_fxgedevice.h" |
28 #include "core/fxge/cfx_gemodule.h" | 28 #include "core/fxge/cfx_gemodule.h" |
29 #include "fpdfsdk/cpdfsdk_pageview.h" | 29 #include "fpdfsdk/cpdfsdk_pageview.h" |
30 #include "fpdfsdk/fsdk_define.h" | 30 #include "fpdfsdk/fsdk_define.h" |
31 #include "fpdfsdk/fsdk_pauseadapter.h" | 31 #include "fpdfsdk/fsdk_pauseadapter.h" |
32 #include "fpdfsdk/javascript/ijs_runtime.h" | 32 #include "fpdfsdk/javascript/ijs_runtime.h" |
33 #include "public/fpdf_ext.h" | 33 #include "public/fpdf_ext.h" |
34 #include "public/fpdf_progressive.h" | 34 #include "public/fpdf_progressive.h" |
35 #include "third_party/base/numerics/safe_conversions_impl.h" | 35 #include "third_party/base/numerics/safe_conversions_impl.h" |
| 36 #include "third_party/base/ptr_util.h" |
36 | 37 |
37 #ifdef PDF_ENABLE_XFA | 38 #ifdef PDF_ENABLE_XFA |
38 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" | 39 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" |
39 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" | 40 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" |
40 #include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" | 41 #include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" |
41 #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" | 42 #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" |
42 #include "public/fpdf_formfill.h" | 43 #include "public/fpdf_formfill.h" |
43 #endif // PDF_ENABLE_XFA | 44 #endif // PDF_ENABLE_XFA |
44 | 45 |
45 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 46 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
(...skipping 16 matching lines...) Expand all Loading... |
62 #ifdef PDF_ENABLE_XFA | 63 #ifdef PDF_ENABLE_XFA |
63 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | 64 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; |
64 #else // PDF_ENABLE_XFA | 65 #else // PDF_ENABLE_XFA |
65 return UnderlyingFromFPDFDocument(doc); | 66 return UnderlyingFromFPDFDocument(doc); |
66 #endif // PDF_ENABLE_XFA | 67 #endif // PDF_ENABLE_XFA |
67 } | 68 } |
68 | 69 |
69 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 70 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
70 #ifdef PDF_ENABLE_XFA | 71 #ifdef PDF_ENABLE_XFA |
71 return doc ? FPDFDocumentFromUnderlying(new CPDFXFA_Document( | 72 return doc ? FPDFDocumentFromUnderlying(new CPDFXFA_Document( |
72 WrapUnique(doc), CPDFXFA_App::GetInstance())) | 73 pdfium::WrapUnique(doc), CPDFXFA_App::GetInstance())) |
73 : nullptr; | 74 : nullptr; |
74 #else // PDF_ENABLE_XFA | 75 #else // PDF_ENABLE_XFA |
75 return FPDFDocumentFromUnderlying(doc); | 76 return FPDFDocumentFromUnderlying(doc); |
76 #endif // PDF_ENABLE_XFA | 77 #endif // PDF_ENABLE_XFA |
77 } | 78 } |
78 | 79 |
79 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 80 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
80 #ifdef PDF_ENABLE_XFA | 81 #ifdef PDF_ENABLE_XFA |
81 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | 82 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
82 #else // PDF_ENABLE_XFA | 83 #else // PDF_ENABLE_XFA |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 int start_y, | 568 int start_y, |
568 int size_x, | 569 int size_x, |
569 int size_y, | 570 int size_y, |
570 int rotate, | 571 int rotate, |
571 int flags) { | 572 int flags) { |
572 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 573 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
573 if (!pPage) | 574 if (!pPage) |
574 return; | 575 return; |
575 | 576 |
576 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; | 577 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
577 pPage->SetRenderContext(WrapUnique(pContext)); | 578 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
578 | 579 |
579 std::unique_ptr<CFX_DIBitmap> pBitmap; | 580 std::unique_ptr<CFX_DIBitmap> pBitmap; |
580 const bool bNewBitmap = | 581 const bool bNewBitmap = |
581 pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); | 582 pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); |
582 if (bNewBitmap) { | 583 if (bNewBitmap) { |
583 pBitmap = WrapUnique(new CFX_DIBitmap); | 584 pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); |
584 pBitmap->Create(size_x, size_y, FXDIB_Argb); | 585 pBitmap->Create(size_x, size_y, FXDIB_Argb); |
585 pBitmap->Clear(0x00ffffff); | 586 pBitmap->Clear(0x00ffffff); |
586 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; | 587 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
587 pContext->m_pDevice = WrapUnique(pDevice); | 588 pContext->m_pDevice = pdfium::WrapUnique(pDevice); |
588 pDevice->Attach(pBitmap.get(), false, nullptr, false); | 589 pDevice->Attach(pBitmap.get(), false, nullptr, false); |
589 } else { | 590 } else { |
590 pContext->m_pDevice = WrapUnique(new CFX_WindowsDevice(dc)); | 591 pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc); |
591 } | 592 } |
592 | 593 |
593 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 594 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
594 rotate, flags, TRUE, nullptr); | 595 rotate, flags, TRUE, nullptr); |
595 | 596 |
596 if (bNewBitmap) { | 597 if (bNewBitmap) { |
597 CFX_WindowsDevice WinDC(dc); | 598 CFX_WindowsDevice WinDC(dc); |
598 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { | 599 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
599 std::unique_ptr<CFX_DIBitmap> pDst = WrapUnique(new CFX_DIBitmap); | 600 std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>(); |
600 int pitch = pBitmap->GetPitch(); | 601 int pitch = pBitmap->GetPitch(); |
601 pDst->Create(size_x, size_y, FXDIB_Rgb32); | 602 pDst->Create(size_x, size_y, FXDIB_Rgb32); |
602 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); | 603 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); |
603 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0, | 604 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0, |
604 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); | 605 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); |
605 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); | 606 WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); |
606 } else { | 607 } else { |
607 WinDC.SetDIBits(pBitmap.get(), 0, 0); | 608 WinDC.SetDIBits(pBitmap.get(), 0, 0); |
608 } | 609 } |
609 } | 610 } |
(...skipping 11 matching lines...) Expand all Loading... |
621 int rotate, | 622 int rotate, |
622 int flags) { | 623 int flags) { |
623 if (!bitmap) | 624 if (!bitmap) |
624 return; | 625 return; |
625 | 626 |
626 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 627 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
627 if (!pPage) | 628 if (!pPage) |
628 return; | 629 return; |
629 | 630 |
630 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; | 631 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
631 pPage->SetRenderContext(WrapUnique(pContext)); | 632 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
632 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; | 633 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
633 pContext->m_pDevice.reset(pDevice); | 634 pContext->m_pDevice.reset(pDevice); |
634 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); | 635 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
635 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); | 636 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
636 | 637 |
637 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 638 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
638 rotate, flags, TRUE, nullptr); | 639 rotate, flags, TRUE, nullptr); |
639 | 640 |
640 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); | 641 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); |
641 } | 642 } |
642 | 643 |
643 #ifdef _SKIA_SUPPORT_ | 644 #ifdef _SKIA_SUPPORT_ |
644 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, | 645 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, |
645 int size_x, | 646 int size_x, |
646 int size_y) { | 647 int size_y) { |
647 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 648 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
648 if (!pPage) | 649 if (!pPage) |
649 return nullptr; | 650 return nullptr; |
650 | 651 |
651 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; | 652 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
652 pPage->SetRenderContext(WrapUnique(pContext)); | 653 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
653 CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; | 654 CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; |
654 FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); | 655 FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); |
655 pContext->m_pDevice.reset(skDevice); | 656 pContext->m_pDevice.reset(skDevice); |
656 FPDF_RenderPage_Retail(pContext, page, 0, 0, size_x, size_y, 0, 0, TRUE, | 657 FPDF_RenderPage_Retail(pContext, page, 0, 0, size_x, size_y, 0, 0, TRUE, |
657 nullptr); | 658 nullptr); |
658 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); | 659 pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); |
659 return recorder; | 660 return recorder; |
660 } | 661 } |
661 #endif | 662 #endif |
662 | 663 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 int size_y, | 840 int size_y, |
840 int rotate, | 841 int rotate, |
841 int flags, | 842 int flags, |
842 FX_BOOL bNeedToRestore, | 843 FX_BOOL bNeedToRestore, |
843 IFSDK_PAUSE_Adapter* pause) { | 844 IFSDK_PAUSE_Adapter* pause) { |
844 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 845 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
845 if (!pPage) | 846 if (!pPage) |
846 return; | 847 return; |
847 | 848 |
848 if (!pContext->m_pOptions) | 849 if (!pContext->m_pOptions) |
849 pContext->m_pOptions = WrapUnique(new CPDF_RenderOptions); | 850 pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); |
850 | 851 |
851 if (flags & FPDF_LCD_TEXT) | 852 if (flags & FPDF_LCD_TEXT) |
852 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 853 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
853 else | 854 else |
854 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 855 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
855 if (flags & FPDF_NO_NATIVETEXT) | 856 if (flags & FPDF_NO_NATIVETEXT) |
856 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; | 857 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; |
857 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) | 858 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) |
858 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; | 859 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; |
859 if (flags & FPDF_RENDER_FORCEHALFTONE) | 860 if (flags & FPDF_RENDER_FORCEHALFTONE) |
(...skipping 18 matching lines...) Expand all Loading... |
878 pContext->m_pOptions->m_pOCContext = | 879 pContext->m_pOptions->m_pOCContext = |
879 new CPDF_OCContext(pPage->m_pDocument, usage); | 880 new CPDF_OCContext(pPage->m_pDocument, usage); |
880 | 881 |
881 CFX_Matrix matrix; | 882 CFX_Matrix matrix; |
882 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); | 883 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
883 | 884 |
884 pContext->m_pDevice->SaveState(); | 885 pContext->m_pDevice->SaveState(); |
885 pContext->m_pDevice->SetClip_Rect( | 886 pContext->m_pDevice->SetClip_Rect( |
886 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y)); | 887 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y)); |
887 | 888 |
888 pContext->m_pContext = WrapUnique(new CPDF_RenderContext(pPage)); | 889 pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage); |
889 pContext->m_pContext->AppendLayer(pPage, &matrix); | 890 pContext->m_pContext->AppendLayer(pPage, &matrix); |
890 | 891 |
891 if (flags & FPDF_ANNOT) { | 892 if (flags & FPDF_ANNOT) { |
892 pContext->m_pAnnots = WrapUnique(new CPDF_AnnotList(pPage)); | 893 pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage); |
893 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; | 894 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; |
894 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(), | 895 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(), |
895 bPrinting, &matrix, FALSE, nullptr); | 896 bPrinting, &matrix, FALSE, nullptr); |
896 } | 897 } |
897 | 898 |
898 pContext->m_pRenderer = WrapUnique(new CPDF_ProgressiveRenderer( | 899 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( |
899 pContext->m_pContext.get(), pContext->m_pDevice.get(), | 900 pContext->m_pContext.get(), pContext->m_pDevice.get(), |
900 pContext->m_pOptions.get())); | 901 pContext->m_pOptions.get()); |
901 pContext->m_pRenderer->Start(pause); | 902 pContext->m_pRenderer->Start(pause); |
902 if (bNeedToRestore) | 903 if (bNeedToRestore) |
903 pContext->m_pDevice->RestoreState(false); | 904 pContext->m_pDevice->RestoreState(false); |
904 } | 905 } |
905 | 906 |
906 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, | 907 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, |
907 int page_index, | 908 int page_index, |
908 double* width, | 909 double* width, |
909 double* height) { | 910 double* height) { |
910 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 911 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 if (!buffer) { | 1125 if (!buffer) { |
1125 *buflen = len; | 1126 *buflen = len; |
1126 } else if (*buflen >= len) { | 1127 } else if (*buflen >= len) { |
1127 memcpy(buffer, utf16Name.c_str(), len); | 1128 memcpy(buffer, utf16Name.c_str(), len); |
1128 *buflen = len; | 1129 *buflen = len; |
1129 } else { | 1130 } else { |
1130 *buflen = -1; | 1131 *buflen = -1; |
1131 } | 1132 } |
1132 return (FPDF_DEST)pDestObj; | 1133 return (FPDF_DEST)pDestObj; |
1133 } | 1134 } |
OLD | NEW |