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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 14 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, |
| 15 | FPDF_PAGE page, |
| 16 | int start_x, |
| 17 | int start_y, |
| 18 | int size_x, |
| 19 | int size_y, |
| 20 | int rotate, |
| 21 | int flags, |
| 22 | IFSDK_PAUSE* pause) { |
| 23 | if (bitmap == NULL || page == NULL) |
| 24 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 26 | if (!pause) |
| 27 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 29 | if (pause->version != 1) |
| 30 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 32 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 33 | if (!pPage) |
| 34 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 36 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 38 | CRenderContext* pContext = FX_NEW CRenderContext; |
| 39 | pPage->SetPrivateData((void*)1, pContext, DropContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | #ifdef _SKIA_SUPPORT_ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 41 | pContext->m_pDevice = FX_NEW CFX_SkiaDevice; |
| 42 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 43 | ((CFX_SkiaDevice*)pContext->m_pDevice) |
| 44 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 45 | else |
| 46 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 48 | pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
| 49 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 50 | ((CFX_FxgeDevice*)pContext->m_pDevice) |
| 51 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 52 | else |
| 53 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 55 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 57 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 58 | rotate, flags, FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 60 | if (pContext->m_pRenderer) { |
| 61 | CPDF_ProgressiveRenderer::RenderStatus status = |
| 62 | CPDF_ProgressiveRenderer::Failed; |
| 63 | status = pContext->m_pRenderer->GetStatus(); |
| 64 | return status; |
| 65 | } |
| 66 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 69 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 70 | IFSDK_PAUSE* pause) { |
| 71 | if (page == NULL) |
| 72 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 74 | if (!pause) |
| 75 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 76 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 77 | if (pause->version != 1) |
| 78 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 80 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 81 | if (!pPage) |
| 82 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 84 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 86 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 87 | if (pContext && pContext->m_pRenderer) { |
| 88 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 89 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 91 | CPDF_ProgressiveRenderer::RenderStatus status = |
| 92 | CPDF_ProgressiveRenderer::Failed; |
| 93 | status = pContext->m_pRenderer->GetStatus(); |
| 94 | return status; |
| 95 | } |
| 96 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 99 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
| 100 | if (page == NULL) |
| 101 | return; |
| 102 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 103 | if (!pPage) |
| 104 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 106 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame^] | 108 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 109 | if (pContext) { |
| 110 | pContext->m_pDevice->RestoreState(); |
| 111 | delete pContext; |
| 112 | pPage->RemovePrivateData((void*)1); |
| 113 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | } |