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)); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame^] | 45 | CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
| 46 | pContext->m_pDevice = pDevice; |
| 47 | CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
| 48 | pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 49 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 50 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 55 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 56 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | } |
| 58 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 62 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 63 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 66 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | if (!pPage) |
| 68 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 70 | CRenderContext* pContext = |
| 71 | static_cast<CRenderContext*>(pPage->GetRenderContext()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | if (pContext && pContext->m_pRenderer) { |
| 73 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 74 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 75 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 76 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | } |
| 78 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 82 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | if (!pPage) |
| 84 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 86 | CRenderContext* pContext = |
| 87 | static_cast<CRenderContext*>(pPage->GetRenderContext()); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 88 | if (!pContext) |
| 89 | return; |
| 90 | |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 91 | pContext->m_pDevice->RestoreState(false); |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 92 | pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | } |