blob: efde1eb029fa918f308e6adc2af60f1819e157a4 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_progressive.h"
8
Dan Sinclair455a4192016-03-16 09:48:56 -04009#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040010#include "core/fpdfapi/fpdf_render/include/cpdf_progressiverenderer.h"
thestig25fa42f2016-05-25 21:39:46 -070011#include "core/fxge/include/fx_ge.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080012#include "fpdfsdk/include/fsdk_define.h"
13#include "fpdfsdk/include/fsdk_rendercontext.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080014#include "public/fpdfview.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
Lei Zhang8fec3e42015-11-04 15:32:02 -080016// These checks are here because core/ and public/ cannot depend on each other.
17static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER,
18 "CPDF_ProgressiveRenderer::Ready value mismatch");
19static_assert(CPDF_ProgressiveRenderer::ToBeContinued ==
20 FPDF_RENDER_TOBECOUNTINUED,
21 "CPDF_ProgressiveRenderer::ToBeContinued value mismatch");
22static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE,
23 "CPDF_ProgressiveRenderer::Done value mismatch");
24static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED,
25 "CPDF_ProgressiveRenderer::Failed value mismatch");
26
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027DLLEXPORT 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 Sepezdb0be962015-10-16 14:00:21 -070036 if (!bitmap || !pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
Tom Sepezdb0be962015-10-16 14:00:21 -070039 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 if (!pPage)
41 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070042
Tom Sepezae51c812015-08-05 12:34:06 -070043 CRenderContext* pContext = new CRenderContext;
tsepez1e2c5572016-05-25 14:58:09 -070044 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext));
thestigbefa4502016-05-26 20:15:19 -070045 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 Zhanga6d9f0e2015-06-13 00:48:38 -070049
tsepez1e2c5572016-05-25 14:58:09 -070050 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
52 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 if (pContext->m_pRenderer) {
Tom Sepezb3b67622015-10-19 16:20:03 -070055 return CPDF_ProgressiveRenderer::ToFPDFStatus(
56 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 }
58 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059}
60
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
62 IFSDK_PAUSE* pause) {
Tom Sepezdb0be962015-10-16 14:00:21 -070063 if (!pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065
Tom Sepezdb0be962015-10-16 14:00:21 -070066 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 if (!pPage)
68 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069
tsepez1e2c5572016-05-25 14:58:09 -070070 CRenderContext* pContext =
71 static_cast<CRenderContext*>(pPage->GetRenderContext());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 if (pContext && pContext->m_pRenderer) {
73 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
74 pContext->m_pRenderer->Continue(&IPauseAdapter);
Tom Sepezb3b67622015-10-19 16:20:03 -070075 return CPDF_ProgressiveRenderer::ToFPDFStatus(
76 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 }
78 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079}
80
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -070082 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 if (!pPage)
84 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085
tsepez1e2c5572016-05-25 14:58:09 -070086 CRenderContext* pContext =
87 static_cast<CRenderContext*>(pPage->GetRenderContext());
Tom Sepezdfbf8e72015-10-14 14:17:26 -070088 if (!pContext)
89 return;
90
thestig41846a02016-05-26 10:45:30 -070091 pContext->m_pDevice->RestoreState(false);
tsepez1e2c5572016-05-25 14:58:09 -070092 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093}