Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fpdf_progressive.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "public/fpdf_progressive.h"
8
9#include <memory>
10#include <utility>
11
12#include "core/fpdfapi/page/cpdf_page.h"
13#include "core/fpdfapi/render/cpdf_pagerendercontext.h"
14#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
15#include "core/fxge/cfx_defaultrenderdevice.h"
16#include "core/fxge/dib/cfx_dibitmap.h"
17#include "fpdfsdk/cpdfsdk_helpers.h"
18#include "fpdfsdk/cpdfsdk_pauseadapter.h"
19#include "fpdfsdk/cpdfsdk_renderpage.h"
20#include "public/fpdfview.h"
21
22// These checks are here because core/ and public/ cannot depend on each other.
24 "CPDF_ProgressiveRenderer::kReady value mismatch");
27 "CPDF_ProgressiveRenderer::kToBeContinued value mismatch");
29 "CPDF_ProgressiveRenderer::kDone value mismatch");
31 "CPDF_ProgressiveRenderer::kFailed value mismatch");
32
33namespace {
34
35int ToFPDFStatus(CPDF_ProgressiveRenderer::Status status) {
36 return static_cast<int>(status);
37}
38
39} // namespace
40
43 FPDF_PAGE page,
44 int start_x,
45 int start_y,
46 int size_x,
47 int size_y,
48 int rotate,
49 int flags,
50 const FPDF_COLORSCHEME* color_scheme,
51 IFSDK_PAUSE* pause) {
52 if (!bitmap || !pause || pause->version != 1)
53 return FPDF_RENDER_FAILED;
54
55 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
56 if (!pPage)
57 return FPDF_RENDER_FAILED;
58
59 auto owned_context = std::make_unique<CPDF_PageRenderContext>();
60 CPDF_PageRenderContext* context = owned_context.get();
61 pPage->SetRenderContext(std::move(owned_context));
62
63 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
64 auto device = std::make_unique<CFX_DefaultRenderDevice>();
65 device->AttachWithRgbByteOrder(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER));
66 context->m_pDevice = std::move(device);
67
68 CPDFSDK_PauseAdapter pause_adapter(pause);
69 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
70 size_y, rotate, flags, color_scheme,
71 /*need_to_restore=*/false, &pause_adapter);
72
73#if defined(PDF_USE_SKIA)
74 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
75 pBitmap->UnPreMultiply();
76 }
77#endif // defined(PDF_USE_SKIA)
78
79 if (!context->m_pRenderer) {
80 return FPDF_RENDER_FAILED;
81 }
82
83 return ToFPDFStatus(context->m_pRenderer->GetStatus());
84}
85
87 FPDF_PAGE page,
88 int start_x,
89 int start_y,
90 int size_x,
91 int size_y,
92 int rotate,
93 int flags,
94 IFSDK_PAUSE* pause) {
96 bitmap, page, start_x, start_y, size_x, size_y, rotate, flags,
97 /*color_scheme=*/nullptr, pause);
98}
99
101 IFSDK_PAUSE* pause) {
102 if (!pause || pause->version != 1)
103 return FPDF_RENDER_FAILED;
104
105 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
106 if (!pPage)
107 return FPDF_RENDER_FAILED;
108
109 auto* pContext =
110 static_cast<CPDF_PageRenderContext*>(pPage->GetRenderContext());
111 if (!pContext || !pContext->m_pRenderer)
112 return FPDF_RENDER_FAILED;
113
114 CPDFSDK_PauseAdapter pause_adapter(pause);
115 pContext->m_pRenderer->Continue(&pause_adapter);
116
117#if defined(PDF_USE_SKIA)
118 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
119 pContext->m_pDevice->GetBitmap()->UnPreMultiply();
120 }
121#endif // defined(PDF_USE_SKIA)
122 return ToFPDFStatus(pContext->m_pRenderer->GetStatus());
123}
124
126 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
127 if (pPage)
129}
CPDFSDK_PauseAdapter(IFSDK_PAUSE *IPause)
RenderContextIface * GetRenderContext()
Definition cpdf_page.h:84
void ClearRenderContext()
CPDF_Page * CPDFPageFromFPDFPage(FPDF_PAGE page)
void CPDFSDK_RenderPageWithContext(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, const FPDF_COLORSCHEME *color_scheme, bool need_to_restore, CPDFSDK_PauseAdapter *pause)
#define FPDF_RENDER_TOBECONTINUED
FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmapWithColorScheme_Start(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, const FPDF_COLORSCHEME *color_scheme, IFSDK_PAUSE *pause)
#define FPDF_RENDER_DONE
#define FPDF_RENDER_READY
FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage_Close(FPDF_PAGE page)
FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, IFSDK_PAUSE *pause)
FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, IFSDK_PAUSE *pause)
#define FPDF_RENDER_FAILED
#define FPDF_REVERSE_BYTE_ORDER
Definition fpdfview.h:831
#define FPDF_CALLCONV
Definition fpdfview.h:227
#define FPDF_EXPORT
Definition fpdfview.h:221