John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 7 | #include "../../public/fpdf_progressive.h" |
| 8 | #include "../../public/fpdfview.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | #include "../include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 10 | #include "../include/fsdk_rendercontext.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 11 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 12 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 14 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page, |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | int start_x, int start_y, int size_x, |
| 16 | int size_y, int rotate, int flags, |
| 17 | IFSDK_PAUSE * pause ) |
| 18 | { |
| 19 | if (bitmap == NULL || page == NULL) |
| 20 | return FPDF_RENDER_FAILED; |
| 21 | |
| 22 | if (!pause) |
| 23 | return FPDF_RENDER_FAILED; |
| 24 | |
| 25 | if (pause->version !=1) |
| 26 | return FPDF_RENDER_FAILED; |
| 27 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 28 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 29 | if (!pPage) |
| 30 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 31 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 33 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | CRenderContext* pContext = FX_NEW CRenderContext; |
| 35 | pPage->SetPrivateData((void*)1, pContext, DropContext ); |
| 36 | #ifdef _SKIA_SUPPORT_ |
| 37 | pContext->m_pDevice = FX_NEW CFX_SkiaDevice; |
| 38 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 39 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); |
| 40 | else |
| 41 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| 42 | #else |
| 43 | pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
| 44 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 45 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); |
| 46 | else |
| 47 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| 48 | #endif |
| 49 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 50 | |
Tom Sepez | 75f43c4 | 2015-07-15 16:35:53 -0700 | [diff] [blame] | 51 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 52 | rotate, flags,FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 53 | |
| 54 | if ( pContext->m_pRenderer ) |
| 55 | { |
| 56 | CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed; |
| 57 | status = pContext->m_pRenderer->GetStatus(); |
| 58 | return status; |
| 59 | } |
| 60 | return FPDF_RENDER_FAILED; |
| 61 | } |
| 62 | |
| 63 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause) |
| 64 | { |
| 65 | if (page == NULL) |
| 66 | return FPDF_RENDER_FAILED; |
| 67 | |
| 68 | if (!pause) |
| 69 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 70 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | if (pause->version !=1) |
| 72 | return FPDF_RENDER_FAILED; |
| 73 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 74 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 75 | if (!pPage) |
| 76 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | |
| 78 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
| 79 | |
| 80 | CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 81 | if (pContext && pContext->m_pRenderer) |
| 82 | { |
| 83 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 84 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
| 85 | |
| 86 | CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed; |
| 87 | status = pContext->m_pRenderer->GetStatus(); |
| 88 | return status; |
| 89 | } |
| 90 | return FPDF_RENDER_FAILED; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) |
| 95 | { |
| 96 | if (page == NULL) return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 97 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 98 | if (!pPage) return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | |
| 100 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
| 101 | |
| 102 | CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 103 | if (pContext) |
| 104 | { |
| 105 | pContext->m_pDevice->RestoreState(); |
| 106 | delete pContext; |
| 107 | pPage->RemovePrivateData((void*)1); |
| 108 | } |
| 109 | } |
| 110 | |