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

Side by Side Diff: fpdfsdk/fpdfview.cpp

Issue 2526473002: Add FPDF_RenderPageBitmapWithMatrix. (Closed)
Patch Set: 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
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 if (flags & FPDF_NO_NATIVETEXT)
dsinclair 2016/11/22 14:21:27 blink line before to make it clear the if is separ
Lei Zhang 2016/11/22 23:56:06 Sure. This is all moved code.
68 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
69 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
70 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
71 if (flags & FPDF_RENDER_FORCEHALFTONE)
72 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
73 #ifndef PDF_ENABLE_XFA
74 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
75 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
76 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
77 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
78 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
79 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
80 #endif // PDF_ENABLE_XFA
81 // Grayscale output
82 if (flags & FPDF_GRAYSCALE) {
83 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
84 pContext->m_pOptions->m_ForeColor = 0;
85 pContext->m_pOptions->m_BackColor = 0xffffff;
86 }
87 const CPDF_OCContext::UsageType usage =
88 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
89 pContext->m_pOptions->m_AddFlags = flags >> 8;
90 pContext->m_pOptions->m_pOCContext =
91 new CPDF_OCContext(pPage->m_pDocument, usage);
92
93 pContext->m_pDevice->SaveState();
94 pContext->m_pDevice->SetClip_Rect(clipping_rect);
95
96 pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage);
97 pContext->m_pContext->AppendLayer(pPage, &matrix);
98
99 if (flags & FPDF_ANNOT) {
100 pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage);
101 bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
102 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(),
103 bPrinting, &matrix, false, nullptr);
104 }
105
106 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>(
107 pContext->m_pContext.get(), pContext->m_pDevice.get(),
108 pContext->m_pOptions.get());
109 pContext->m_pRenderer->Start(pause);
110 if (bNeedToRestore)
111 pContext->m_pDevice->RestoreState(false);
112 }
113
114 } // namespace
115
51 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { 116 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) {
52 return static_cast<UnderlyingDocumentType*>(doc); 117 return static_cast<UnderlyingDocumentType*>(doc);
53 } 118 }
54 119
55 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { 120 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) {
56 return static_cast<FPDF_DOCUMENT>(doc); 121 return static_cast<FPDF_DOCUMENT>(doc);
57 } 122 }
58 123
59 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { 124 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) {
60 return static_cast<UnderlyingPageType*>(page); 125 return static_cast<UnderlyingPageType*>(page);
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 pContext->m_pDevice.reset(pDevice); 659 pContext->m_pDevice.reset(pDevice);
595 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); 660 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
596 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); 661 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
597 662
598 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, 663 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
599 rotate, flags, true, nullptr); 664 rotate, flags, true, nullptr);
600 665
601 pPage->SetRenderContext(nullptr); 666 pPage->SetRenderContext(nullptr);
602 } 667 }
603 668
669 DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
670 FPDF_PAGE page,
671 const FS_MATRIX* matrix,
672 const FS_RECTF* clipping,
673 int flags) {
674 if (!bitmap)
675 return;
676
677 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
678 if (!pPage)
679 return;
680
681 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
682 pPage->SetRenderContext(pdfium::WrapUnique(pContext));
683 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
684 pContext->m_pDevice.reset(pDevice);
685 CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
686 pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
687
688 CFX_Matrix transform_matrix = pPage->GetPageMatrix();
689 if (matrix) {
690 CFX_Matrix cmatrix;
691 cmatrix.a = matrix->a;
692 cmatrix.b = matrix->b;
693 cmatrix.c = matrix->c;
694 cmatrix.d = matrix->d;
695 cmatrix.e = matrix->e;
696 cmatrix.f = matrix->f;
697 transform_matrix.Concat(cmatrix);
698 }
699
700 CFX_FloatRect clipping_rect;
701 if (clipping) {
702 clipping_rect.left = clipping->left;
703 clipping_rect.bottom = clipping->bottom;
704 clipping_rect.right = clipping->right;
705 clipping_rect.top = clipping->top;
706 }
707 RenderPageImpl(pContext, pPage, transform_matrix, clipping_rect.ToFxRect(),
708 flags, true, nullptr);
709
710 pPage->SetRenderContext(nullptr);
711 }
712
604 #ifdef _SKIA_SUPPORT_ 713 #ifdef _SKIA_SUPPORT_
605 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, 714 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page,
606 int size_x, 715 int size_x,
607 int size_y) { 716 int size_y) {
608 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 717 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
609 if (!pPage) 718 if (!pPage)
610 return nullptr; 719 return nullptr;
611 720
612 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; 721 CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
613 pPage->SetRenderContext(pdfium::WrapUnique(pContext)); 722 pPage->SetRenderContext(pdfium::WrapUnique(pContext));
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 int size_x, 912 int size_x,
804 int size_y, 913 int size_y,
805 int rotate, 914 int rotate,
806 int flags, 915 int flags,
807 bool bNeedToRestore, 916 bool bNeedToRestore,
808 IFSDK_PAUSE_Adapter* pause) { 917 IFSDK_PAUSE_Adapter* pause) {
809 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 918 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
810 if (!pPage) 919 if (!pPage)
811 return; 920 return;
812 921
813 if (!pContext->m_pOptions)
814 pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>();
815
816 if (flags & FPDF_LCD_TEXT)
817 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
818 else
819 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
820 if (flags & FPDF_NO_NATIVETEXT)
821 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
822 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
823 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
824 if (flags & FPDF_RENDER_FORCEHALFTONE)
825 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
826 #ifndef PDF_ENABLE_XFA
827 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
828 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
829 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
830 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
831 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
832 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
833 #endif // PDF_ENABLE_XFA
834 // Grayscale output
835 if (flags & FPDF_GRAYSCALE) {
836 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
837 pContext->m_pOptions->m_ForeColor = 0;
838 pContext->m_pOptions->m_BackColor = 0xffffff;
839 }
840 const CPDF_OCContext::UsageType usage =
841 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
842 pContext->m_pOptions->m_AddFlags = flags >> 8;
843 pContext->m_pOptions->m_pOCContext =
844 new CPDF_OCContext(pPage->m_pDocument, usage);
845
846 CFX_Matrix matrix; 922 CFX_Matrix matrix;
847 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); 923 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
848 924 FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y);
849 pContext->m_pDevice->SaveState(); 925 RenderPageImpl(pContext, pPage, matrix, rect, flags, bNeedToRestore, pause);
850 pContext->m_pDevice->SetClip_Rect(
851 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y));
852
853 pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage);
854 pContext->m_pContext->AppendLayer(pPage, &matrix);
855
856 if (flags & FPDF_ANNOT) {
857 pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage);
858 bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
859 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(),
860 bPrinting, &matrix, false, nullptr);
861 }
862
863 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>(
864 pContext->m_pContext.get(), pContext->m_pDevice.get(),
865 pContext->m_pOptions.get());
866 pContext->m_pRenderer->Start(pause);
867 if (bNeedToRestore)
868 pContext->m_pDevice->RestoreState(false);
869 } 926 }
870 927
871 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 928 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
872 int page_index, 929 int page_index,
873 double* width, 930 double* width,
874 double* height) { 931 double* height) {
875 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 932 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
876 if (!pDoc) 933 if (!pDoc)
877 return false; 934 return false;
878 935
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 if (!buffer) { 1165 if (!buffer) {
1109 *buflen = len; 1166 *buflen = len;
1110 } else if (*buflen >= len) { 1167 } else if (*buflen >= len) {
1111 memcpy(buffer, utf16Name.c_str(), len); 1168 memcpy(buffer, utf16Name.c_str(), len);
1112 *buflen = len; 1169 *buflen = len;
1113 } else { 1170 } else {
1114 *buflen = -1; 1171 *buflen = -1;
1115 } 1172 }
1116 return (FPDF_DEST)pDestObj; 1173 return (FPDF_DEST)pDestObj;
1117 } 1174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698