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

Side by Side Diff: fpdfsdk/fpdfview.cpp

Issue 2526473002: Add FPDF_RenderPageBitmapWithMatrix. (Closed)
Patch Set: rebase, nits Created 4 years 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 | « core/fpdfdoc/cpdf_annotlist.cpp ('k') | fpdfsdk/fpdfview_c_api_test.c » ('j') | 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 #include <utility> 10 #include <utility>
(...skipping 30 matching lines...) Expand all
41 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" 41 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
42 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" 42 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
43 #include "public/fpdf_formfill.h" 43 #include "public/fpdf_formfill.h"
44 #include "xfa/fxbarcode/BC_Library.h" 44 #include "xfa/fxbarcode/BC_Library.h"
45 #endif // PDF_ENABLE_XFA 45 #endif // PDF_ENABLE_XFA
46 46
47 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 47 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
48 #include "core/fxge/cfx_windowsdevice.h" 48 #include "core/fxge/cfx_windowsdevice.h"
49 #endif 49 #endif
50 50
51 namespace {
52
53 void RenderPageImpl(CPDF_PageRenderContext* pContext,
54 CPDF_Page* pPage,
55 const CFX_Matrix& matrix,
56 const FX_RECT& clipping_rect,
57 int flags,
58 bool bNeedToRestore,
59 IFSDK_PAUSE_Adapter* pause) {
60 if (!pContext->m_pOptions)
61 pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>();
62
63 if (flags & FPDF_LCD_TEXT)
64 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
65 else
66 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
67
68 if (flags & FPDF_NO_NATIVETEXT)
69 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
70 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
71 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
72 if (flags & FPDF_RENDER_FORCEHALFTONE)
73 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
74 #ifndef PDF_ENABLE_XFA
75 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
76 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
77 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
78 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
79 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
80 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
81 #endif // PDF_ENABLE_XFA
82
83 // Grayscale output
84 if (flags & FPDF_GRAYSCALE) {
85 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
86 pContext->m_pOptions->m_ForeColor = 0;
87 pContext->m_pOptions->m_BackColor = 0xffffff;
88 }
89
90 const CPDF_OCContext::UsageType usage =
91 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
92 pContext->m_pOptions->m_AddFlags = flags >> 8;
93 pContext->m_pOptions->m_pOCContext =
94 new CPDF_OCContext(pPage->m_pDocument, usage);
95
96 pContext->m_pDevice->SaveState();
97 pContext->m_pDevice->SetClip_Rect(clipping_rect);
98
99 pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage);
100 pContext->m_pContext->AppendLayer(pPage, &matrix);
101
102 if (flags & FPDF_ANNOT) {
103 pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage);
104 bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
105 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(),
106 bPrinting, &matrix, false, nullptr);
107 }
108
109 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>(
110 pContext->m_pContext.get(), pContext->m_pDevice.get(),
111 pContext->m_pOptions.get());
112 pContext->m_pRenderer->Start(pause);
113 if (bNeedToRestore)
114 pContext->m_pDevice->RestoreState(false);
115 }
116
117 } // namespace
118
51 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { 119 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) {
52 return static_cast<UnderlyingDocumentType*>(doc); 120 return static_cast<UnderlyingDocumentType*>(doc);
53 } 121 }
54 122
55 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { 123 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) {
56 return static_cast<FPDF_DOCUMENT>(doc); 124 return static_cast<FPDF_DOCUMENT>(doc);
57 } 125 }
58 126
59 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { 127 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) {
60 return static_cast<UnderlyingPageType*>(page); 128 return static_cast<UnderlyingPageType*>(page);
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 665
598 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, 666 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
599 rotate, flags, true, nullptr); 667 rotate, flags, true, nullptr);
600 668
601 #ifdef _SKIA_SUPPORT_PATHS_ 669 #ifdef _SKIA_SUPPORT_PATHS_
602 pBitmap->UnPreMultiply(); 670 pBitmap->UnPreMultiply();
603 #endif 671 #endif
604 pPage->SetRenderContext(nullptr); 672 pPage->SetRenderContext(nullptr);
605 } 673 }
606 674
675 DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
676 FPDF_PAGE page,
677 const FS_MATRIX* matrix,
678 const FS_RECTF* clipping,
679 int flags) {
680 if (!bitmap)
681 return;
682
683 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
684 if (!pPage)
685 return;
686
687 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
688 pPage->SetRenderContext(pdfium::WrapUnique(pContext));
689 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
690 pContext->m_pDevice.reset(pDevice);
691 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
692 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
693
694 CFX_Matrix transform_matrix = pPage->GetPageMatrix();
695 if (matrix) {
696 CFX_Matrix cmatrix;
697 cmatrix.a = matrix->a;
698 cmatrix.b = matrix->b;
699 cmatrix.c = matrix->c;
700 cmatrix.d = matrix->d;
701 cmatrix.e = matrix->e;
702 cmatrix.f = matrix->f;
703 transform_matrix.Concat(cmatrix);
704 }
705
706 CFX_FloatRect clipping_rect;
707 if (clipping) {
708 clipping_rect.left = clipping->left;
709 clipping_rect.bottom = clipping->bottom;
710 clipping_rect.right = clipping->right;
711 clipping_rect.top = clipping->top;
712 }
713 RenderPageImpl(pContext, pPage, transform_matrix, clipping_rect.ToFxRect(),
714 flags, true, nullptr);
715
716 pPage->SetRenderContext(nullptr);
717 }
718
607 #ifdef _SKIA_SUPPORT_ 719 #ifdef _SKIA_SUPPORT_
608 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, 720 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page,
609 int size_x, 721 int size_x,
610 int size_y) { 722 int size_y) {
611 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 723 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
612 if (!pPage) 724 if (!pPage)
613 return nullptr; 725 return nullptr;
614 726
615 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; 727 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
616 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); 728 pPage->SetRenderContext(pdfium::WrapUnique(pContext));
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 int size_x, 918 int size_x,
807 int size_y, 919 int size_y,
808 int rotate, 920 int rotate,
809 int flags, 921 int flags,
810 bool bNeedToRestore, 922 bool bNeedToRestore,
811 IFSDK_PAUSE_Adapter* pause) { 923 IFSDK_PAUSE_Adapter* pause) {
812 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 924 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
813 if (!pPage) 925 if (!pPage)
814 return; 926 return;
815 927
816 if (!pContext->m_pOptions)
817 pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>();
818
819 if (flags & FPDF_LCD_TEXT)
820 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
821 else
822 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
823 if (flags & FPDF_NO_NATIVETEXT)
824 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
825 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
826 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
827 if (flags & FPDF_RENDER_FORCEHALFTONE)
828 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
829 #ifndef PDF_ENABLE_XFA
830 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
831 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
832 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
833 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
834 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
835 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
836 #endif // PDF_ENABLE_XFA
837 // Grayscale output
838 if (flags & FPDF_GRAYSCALE) {
839 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
840 pContext->m_pOptions->m_ForeColor = 0;
841 pContext->m_pOptions->m_BackColor = 0xffffff;
842 }
843 const CPDF_OCContext::UsageType usage =
844 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
845 pContext->m_pOptions->m_AddFlags = flags >> 8;
846 pContext->m_pOptions->m_pOCContext =
847 new CPDF_OCContext(pPage->m_pDocument, usage);
848
849 CFX_Matrix matrix; 928 CFX_Matrix matrix;
850 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); 929 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
851 930 FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y);
852 pContext->m_pDevice->SaveState(); 931 RenderPageImpl(pContext, pPage, matrix, rect, flags, bNeedToRestore, pause);
853 pContext->m_pDevice->SetClip_Rect(
854 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y));
855
856 pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage);
857 pContext->m_pContext->AppendLayer(pPage, &matrix);
858
859 if (flags & FPDF_ANNOT) {
860 pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage);
861 bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
862 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(),
863 bPrinting, &matrix, false, nullptr);
864 }
865
866 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>(
867 pContext->m_pContext.get(), pContext->m_pDevice.get(),
868 pContext->m_pOptions.get());
869 pContext->m_pRenderer->Start(pause);
870 if (bNeedToRestore)
871 pContext->m_pDevice->RestoreState(false);
872 } 932 }
873 933
874 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 934 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
875 int page_index, 935 int page_index,
876 double* width, 936 double* width,
877 double* height) { 937 double* height) {
878 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 938 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
879 if (!pDoc) 939 if (!pDoc)
880 return false; 940 return false;
881 941
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 if (!buffer) { 1171 if (!buffer) {
1112 *buflen = len; 1172 *buflen = len;
1113 } else if (*buflen >= len) { 1173 } else if (*buflen >= len) {
1114 memcpy(buffer, utf16Name.c_str(), len); 1174 memcpy(buffer, utf16Name.c_str(), len);
1115 *buflen = len; 1175 *buflen = len;
1116 } else { 1176 } else {
1117 *buflen = -1; 1177 *buflen = -1;
1118 } 1178 }
1119 return (FPDF_DEST)pDestObj; 1179 return (FPDF_DEST)pDestObj;
1120 } 1180 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_annotlist.cpp ('k') | fpdfsdk/fpdfview_c_api_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698