blob: 411ae17af4495aad4dffaaca619015a21c5b9214 [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));
Tom Sepezae51c812015-08-05 12:34:06 -070045 pContext->m_pDevice = new CFX_FxgeDevice;
tsepez1e2c5572016-05-25 14:58:09 -070046 if (flags & FPDF_REVERSE_BYTE_ORDER) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 ((CFX_FxgeDevice*)pContext->m_pDevice)
48 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
tsepez1e2c5572016-05-25 14:58:09 -070049 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
tsepez1e2c5572016-05-25 14:58:09 -070051 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070052
tsepez1e2c5572016-05-25 14:58:09 -070053 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
55 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 if (pContext->m_pRenderer) {
Tom Sepezb3b67622015-10-19 16:20:03 -070058 return CPDF_ProgressiveRenderer::ToFPDFStatus(
59 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 }
61 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
65 IFSDK_PAUSE* pause) {
Tom Sepezdb0be962015-10-16 14:00:21 -070066 if (!pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068
Tom Sepezdb0be962015-10-16 14:00:21 -070069 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 if (!pPage)
71 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
tsepez1e2c5572016-05-25 14:58:09 -070073 CRenderContext* pContext =
74 static_cast<CRenderContext*>(pPage->GetRenderContext());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (pContext && pContext->m_pRenderer) {
76 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
77 pContext->m_pRenderer->Continue(&IPauseAdapter);
Tom Sepezb3b67622015-10-19 16:20:03 -070078 return CPDF_ProgressiveRenderer::ToFPDFStatus(
79 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 }
81 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082}
83
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -070085 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 if (!pPage)
87 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088
tsepez1e2c5572016-05-25 14:58:09 -070089 CRenderContext* pContext =
90 static_cast<CRenderContext*>(pPage->GetRenderContext());
Tom Sepezdfbf8e72015-10-14 14:17:26 -070091 if (!pContext)
92 return;
93
94 pContext->m_pDevice->RestoreState();
tsepez1e2c5572016-05-25 14:58:09 -070095 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096}