blob: 754974e6d612caa8fbe88f873dd9a0f9b7dde381 [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
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_progressive.h"
8#include "../../public/fpdfview.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010#include "../include/fsdk_rendercontext.h"
Bo Xufdc00a72014-10-28 23:03:33 -070011#include "../include/fpdfxfa/fpdfxfa_doc.h"
12#include "../include/fpdfxfa/fpdfxfa_page.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014DLLEXPORT 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 Sepezdb0be962015-10-16 14:00:21 -070023 if (!bitmap || !pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Tom Sepezdb0be962015-10-16 14:00:21 -070026 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 if (!pPage)
28 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070029
Tom Sepezae51c812015-08-05 12:34:06 -070030 CRenderContext* pContext = new CRenderContext;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 pPage->SetPrivateData((void*)1, pContext, DropContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032#ifdef _SKIA_SUPPORT_
Tom Sepezae51c812015-08-05 12:34:06 -070033 pContext->m_pDevice = new CFX_SkiaDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 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-Malek3f3b45c2014-05-23 17:28:10 -070039#else
Tom Sepezae51c812015-08-05 12:34:06 -070040 pContext->m_pDevice = new CFX_FxgeDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 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-Malek3f3b45c2014-05-23 17:28:10 -070046#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070048
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
50 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 if (pContext->m_pRenderer) {
Tom Sepezb3b67622015-10-19 16:20:03 -070053 return CPDF_ProgressiveRenderer::ToFPDFStatus(
54 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 }
56 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057}
58
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
60 IFSDK_PAUSE* pause) {
Tom Sepezdb0be962015-10-16 14:00:21 -070061 if (!pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063
Tom Sepezdb0be962015-10-16 14:00:21 -070064 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 if (!pPage)
66 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 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 Sepezb3b67622015-10-19 16:20:03 -070072 return CPDF_ProgressiveRenderer::ToFPDFStatus(
73 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 }
75 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076}
77
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -070079 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 if (!pPage)
81 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070084 if (!pContext)
85 return;
86
87 pContext->m_pDevice->RestoreState();
88 delete pContext;
89 pPage->RemovePrivateData((void*)1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090}