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 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_progressive.h" |
| 8 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 9 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 10 | #include "core/fpdfapi/fpdf_render/include/cpdf_progressiverenderer.h" |
thestig | 25fa42f | 2016-05-25 21:39:46 -0700 | [diff] [blame^] | 11 | #include "core/fxge/include/fx_ge.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 12 | #include "fpdfsdk/include/fsdk_define.h" |
| 13 | #include "fpdfsdk/include/fsdk_rendercontext.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 14 | #include "public/fpdfview.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 16 | // These checks are here because core/ and public/ cannot depend on each other. |
| 17 | static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER, |
| 18 | "CPDF_ProgressiveRenderer::Ready value mismatch"); |
| 19 | static_assert(CPDF_ProgressiveRenderer::ToBeContinued == |
| 20 | FPDF_RENDER_TOBECOUNTINUED, |
| 21 | "CPDF_ProgressiveRenderer::ToBeContinued value mismatch"); |
| 22 | static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE, |
| 23 | "CPDF_ProgressiveRenderer::Done value mismatch"); |
| 24 | static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED, |
| 25 | "CPDF_ProgressiveRenderer::Failed value mismatch"); |
| 26 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, |
| 28 | FPDF_PAGE page, |
| 29 | int start_x, |
| 30 | int start_y, |
| 31 | int size_x, |
| 32 | int size_y, |
| 33 | int rotate, |
| 34 | int flags, |
| 35 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 36 | if (!bitmap || !pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 39 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | if (!pPage) |
| 41 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 42 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 43 | CRenderContext* pContext = new CRenderContext; |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 44 | pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 45 | pContext->m_pDevice = new CFX_FxgeDevice; |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 46 | if (flags & FPDF_REVERSE_BYTE_ORDER) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | ((CFX_FxgeDevice*)pContext->m_pDevice) |
| 48 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 49 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 51 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 52 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 53 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 55 | rotate, flags, FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 58 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 59 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | } |
| 61 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 65 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 66 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 69 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | if (!pPage) |
| 71 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 73 | CRenderContext* pContext = |
| 74 | static_cast<CRenderContext*>(pPage->GetRenderContext()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | if (pContext && pContext->m_pRenderer) { |
| 76 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 77 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 78 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 79 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | } |
| 81 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 85 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | if (!pPage) |
| 87 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 89 | CRenderContext* pContext = |
| 90 | static_cast<CRenderContext*>(pPage->GetRenderContext()); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 91 | if (!pContext) |
| 92 | return; |
| 93 | |
| 94 | pContext->m_pDevice->RestoreState(); |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 95 | pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 96 | } |