blob: f5e11e8c811cf9f182d3446ed40bed383eff7fd2 [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) {
23 if (bitmap == NULL || page == NULL)
24 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 if (!pause)
27 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 if (pause->version != 1)
30 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
33 if (!pPage)
34 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070035
Tom Sepezae51c812015-08-05 12:34:06 -070036 CRenderContext* pContext = new CRenderContext;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 pPage->SetPrivateData((void*)1, pContext, DropContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038#ifdef _SKIA_SUPPORT_
Tom Sepezae51c812015-08-05 12:34:06 -070039 pContext->m_pDevice = new CFX_SkiaDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 if (flags & FPDF_REVERSE_BYTE_ORDER)
41 ((CFX_SkiaDevice*)pContext->m_pDevice)
42 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
43 else
44 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045#else
Tom Sepezae51c812015-08-05 12:34:06 -070046 pContext->m_pDevice = new CFX_FxgeDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 if (flags & FPDF_REVERSE_BYTE_ORDER)
48 ((CFX_FxgeDevice*)pContext->m_pDevice)
49 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
50 else
51 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
56 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 if (pContext->m_pRenderer) {
59 CPDF_ProgressiveRenderer::RenderStatus status =
60 CPDF_ProgressiveRenderer::Failed;
61 status = pContext->m_pRenderer->GetStatus();
62 return status;
63 }
64 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
68 IFSDK_PAUSE* pause) {
69 if (page == NULL)
70 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 if (!pause)
73 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070074
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (pause->version != 1)
76 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
79 if (!pPage)
80 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
83 if (pContext && pContext->m_pRenderer) {
84 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
85 pContext->m_pRenderer->Continue(&IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 CPDF_ProgressiveRenderer::RenderStatus status =
88 CPDF_ProgressiveRenderer::Failed;
89 status = pContext->m_pRenderer->GetStatus();
90 return status;
91 }
92 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093}
94
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -070096 if (!page)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 return;
98 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
99 if (!pPage)
100 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700103 if (!pContext)
104 return;
105
106 pContext->m_pDevice->RestoreState();
107 delete pContext;
108 pPage->RemovePrivateData((void*)1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}