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) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 23 | if (!bitmap || !pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 26 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | if (!pPage) |
| 28 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 29 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 30 | CRenderContext* pContext = new CRenderContext; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | pPage->SetPrivateData((void*)1, pContext, DropContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | #ifdef _SKIA_SUPPORT_ |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 33 | pContext->m_pDevice = new CFX_SkiaDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 35 | ((CFX_SkiaDevice*)pContext->m_pDevice) |
| 36 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 37 | else |
| 38 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | #else |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 40 | pContext->m_pDevice = new CFX_FxgeDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 42 | ((CFX_FxgeDevice*)pContext->m_pDevice) |
| 43 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 44 | else |
| 45 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 48 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 50 | rotate, flags, FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame^] | 53 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 54 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | } |
| 56 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 60 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 61 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 64 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | if (!pPage) |
| 66 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 69 | if (pContext && pContext->m_pRenderer) { |
| 70 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 71 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame^] | 72 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 73 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | } |
| 75 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 79 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | if (!pPage) |
| 81 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 84 | if (!pContext) |
| 85 | return; |
| 86 | |
| 87 | pContext->m_pDevice->RestoreState(); |
| 88 | delete pContext; |
| 89 | pPage->RemovePrivateData((void*)1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | } |