blob: 125f2617c2f1b522d93e7b521a8207a5780b5a53 [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.
Tom Sepez9857e202015-05-13 17:09:26 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez9857e202015-05-13 17:09:26 -07007#ifndef PUBLIC_FPDF_DATAAVAIL_H_
8#define PUBLIC_FPDF_DATAAVAIL_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
dan sinclairea10a0d2016-03-23 19:36:46 -040010#include <stddef.h>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012// NOLINTNEXTLINE(build/include)
Tom Sepez245c80e2015-04-08 16:19:33 -070013#include "fpdfview.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Jun Fangdf7f3662015-11-10 18:29:18 +080015#define PDF_LINEARIZATION_UNKNOWN -1
16#define PDF_NOT_LINEARIZED 0
17#define PDF_LINEARIZED 1
Tom Sepez326a2a72015-11-20 10:47:32 -080018
Jun Fangdf7f3662015-11-10 18:29:18 +080019#define PDF_DATA_ERROR -1
20#define PDF_DATA_NOTAVAIL 0
21#define PDF_DATA_AVAIL 1
Tom Sepez326a2a72015-11-20 10:47:32 -080022
Jun Fangdf7f3662015-11-10 18:29:18 +080023#define PDF_FORM_ERROR -1
24#define PDF_FORM_NOTAVAIL 0
25#define PDF_FORM_AVAIL 1
26#define PDF_FORM_NOTEXIST 2
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
28#ifdef __cplusplus
29extern "C" {
dan sinclairea10a0d2016-03-23 19:36:46 -040030#endif // __cplusplus
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
dan sinclairea10a0d2016-03-23 19:36:46 -040032// Interface for checking whether sections of the file are available.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033typedef struct _FX_FILEAVAIL {
dan sinclairea10a0d2016-03-23 19:36:46 -040034 // Version number of the interface. Must be 1.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 int version;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
dan sinclairea10a0d2016-03-23 19:36:46 -040037 // Reports if the specified data section is currently available. A section is
38 // available if all bytes in the section are available.
39 //
40 // Interface Version: 1
41 // Implementation Required: Yes
42 //
43 // pThis - pointer to the interface structure.
44 // offset - the offset of the data section in the file.
45 // size - the size of the data section.
46 //
47 // Returns true if the specified data section at |offset| of |size|
48 // is available.
Dan Sinclair3ebd1212016-03-09 09:59:23 -050049 FPDF_BOOL (*IsDataAvail)(struct _FX_FILEAVAIL* pThis,
50 size_t offset,
51 size_t size);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052} FX_FILEAVAIL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
dan sinclairea10a0d2016-03-23 19:36:46 -040054// Create a document availability provider.
55//
56// file_avail - pointer to file availability interface.
57// file - pointer to a file access interface.
58//
59// Returns a handle to the document availability provider, or NULL on error.
60//
Lei Zhang600df802019-01-12 00:28:02 +000061// FPDFAvail_Destroy() must be called when done with the availability provider.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040062FPDF_EXPORT FPDF_AVAIL FPDF_CALLCONV FPDFAvail_Create(FX_FILEAVAIL* file_avail,
63 FPDF_FILEACCESS* file);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064
dan sinclairea10a0d2016-03-23 19:36:46 -040065// Destroy the |avail| document availability provider.
66//
dsinclair860193b2016-04-25 19:44:20 -070067// avail - handle to document availability provider to be destroyed.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040068FPDF_EXPORT void FPDF_CALLCONV FPDFAvail_Destroy(FPDF_AVAIL avail);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069
dan sinclairea10a0d2016-03-23 19:36:46 -040070// Download hints interface. Used to receive hints for further downloading.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071typedef struct _FX_DOWNLOADHINTS {
dan sinclairea10a0d2016-03-23 19:36:46 -040072 // Version number of the interface. Must be 1.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 int version;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074
dan sinclairea10a0d2016-03-23 19:36:46 -040075 // Add a section to be downloaded.
76 //
77 // Interface Version: 1
78 // Implementation Required: Yes
79 //
80 // pThis - pointer to the interface structure.
81 // offset - the offset of the hint reported to be downloaded.
82 // size - the size of the hint reported to be downloaded.
83 //
84 // The |offset| and |size| of the section may not be unique. Part of the
85 // section might be already available. The download manager must deal with
86 // overlapping sections.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 void (*AddSegment)(struct _FX_DOWNLOADHINTS* pThis,
88 size_t offset,
89 size_t size);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090} FX_DOWNLOADHINTS;
91
dan sinclairea10a0d2016-03-23 19:36:46 -040092// Checks if the document is ready for loading, if not, gets download hints.
93//
94// avail - handle to document availability provider.
95// hints - pointer to a download hints interface.
96//
97// Returns one of:
98// PDF_DATA_ERROR: A common error is returned. Data availability unknown.
99// PDF_DATA_NOTAVAIL: Data not yet available.
100// PDF_DATA_AVAIL: Data available.
101//
102// Applications should call this function whenever new data arrives, and process
103// all the generated download hints, if any, until the function returns
104// |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|.
Artem Strygin73784e82017-09-29 16:36:50 +0300105// if hints is nullptr, the function just check current document availability.
dan sinclairea10a0d2016-03-23 19:36:46 -0400106//
Lei Zhang600df802019-01-12 00:28:02 +0000107// Once all data is available, call FPDFAvail_GetDocument() to get a document
dan sinclairea10a0d2016-03-23 19:36:46 -0400108// handle.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400109FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsDocAvail(FPDF_AVAIL avail,
110 FX_DOWNLOADHINTS* hints);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
dan sinclairea10a0d2016-03-23 19:36:46 -0400112// Get document from the availability provider.
113//
114// avail - handle to document availability provider.
115// password - password for decrypting the PDF file. Optional.
116//
117// Returns a handle to the document.
118//
Lei Zhang600df802019-01-12 00:28:02 +0000119// When FPDFAvail_IsDocAvail() returns TRUE, call FPDFAvail_GetDocument() to
dan sinclairea10a0d2016-03-23 19:36:46 -0400120// retrieve the document handle.
Lei Zhang0783da52019-01-14 21:27:27 +0000121// See the comments for FPDF_LoadDocument() regarding the encoding for
122// |password|.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400123FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
124FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
dan sinclairea10a0d2016-03-23 19:36:46 -0400126// Get the page number for the first available page in a linearized PDF.
127//
128// doc - document handle.
129//
130// Returns the zero-based index for the first available page.
131//
132// For most linearized PDFs, the first available page will be the first page,
133// however, some PDFs might make another page the first available page.
134// For non-linearized PDFs, this function will always return zero.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400135FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136
dan sinclairea10a0d2016-03-23 19:36:46 -0400137// Check if |page_index| is ready for loading, if not, get the
138// |FX_DOWNLOADHINTS|.
139//
140// avail - handle to document availability provider.
141// page_index - index number of the page. Zero for the first page.
142// hints - pointer to a download hints interface. Populated if
143// |page_index| is not available.
144//
145// Returns one of:
146// PDF_DATA_ERROR: A common error is returned. Data availability unknown.
147// PDF_DATA_NOTAVAIL: Data not yet available.
148// PDF_DATA_AVAIL: Data available.
149//
Lei Zhang600df802019-01-12 00:28:02 +0000150// This function can be called only after FPDFAvail_GetDocument() is called.
dan sinclairea10a0d2016-03-23 19:36:46 -0400151// Applications should call this function whenever new data arrives and process
152// all the generated download |hints|, if any, until this function returns
153// |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|. Applications can then perform page
154// loading.
Artem Strygin73784e82017-09-29 16:36:50 +0300155// if hints is nullptr, the function just check current availability of
156// specified page.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400157FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsPageAvail(FPDF_AVAIL avail,
158 int page_index,
159 FX_DOWNLOADHINTS* hints);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
dan sinclairea10a0d2016-03-23 19:36:46 -0400161// Check if form data is ready for initialization, if not, get the
162// |FX_DOWNLOADHINTS|.
163//
164// avail - handle to document availability provider.
165// hints - pointer to a download hints interface. Populated if form is not
166// ready for initialization.
167//
168// Returns one of:
169// PDF_FORM_ERROR: A common eror, in general incorrect parameters.
170// PDF_FORM_NOTAVAIL: Data not available.
171// PDF_FORM_AVAIL: Data available.
172// PDF_FORM_NOTEXIST: No form data.
173//
Lei Zhang600df802019-01-12 00:28:02 +0000174// This function can be called only after FPDFAvail_GetDocument() is called.
dan sinclairea10a0d2016-03-23 19:36:46 -0400175// The application should call this function whenever new data arrives and
176// process all the generated download |hints|, if any, until the function
177// |PDF_FORM_ERROR|, |PDF_FORM_AVAIL| or |PDF_FORM_NOTEXIST|.
Artem Strygin73784e82017-09-29 16:36:50 +0300178// if hints is nullptr, the function just check current form availability.
179//
dan sinclairea10a0d2016-03-23 19:36:46 -0400180// Applications can then perform page loading. It is recommend to call
Lei Zhang600df802019-01-12 00:28:02 +0000181// FPDFDOC_InitFormFillEnvironment() when |PDF_FORM_AVAIL| is returned.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400182FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsFormAvail(FPDF_AVAIL avail,
183 FX_DOWNLOADHINTS* hints);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
dan sinclairea10a0d2016-03-23 19:36:46 -0400185// Check whether a document is a linearized PDF.
186//
187// avail - handle to document availability provider.
188//
189// Returns one of:
190// PDF_LINEARIZED
191// PDF_NOT_LINEARIZED
192// PDF_LINEARIZATION_UNKNOWN
193//
Lei Zhang600df802019-01-12 00:28:02 +0000194// FPDFAvail_IsLinearized() will return |PDF_LINEARIZED| or |PDF_NOT_LINEARIZED|
dan sinclairea10a0d2016-03-23 19:36:46 -0400195// when we have 1k of data. If the files size less than 1k, it returns
196// |PDF_LINEARIZATION_UNKNOWN| as there is insufficient information to determine
197// if the PDF is linearlized.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400198FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsLinearized(FPDF_AVAIL avail);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
200#ifdef __cplusplus
dan sinclairea10a0d2016-03-23 19:36:46 -0400201} // extern "C"
202#endif // __cplusplus
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203
Tom Sepez9857e202015-05-13 17:09:26 -0700204#endif // PUBLIC_FPDF_DATAAVAIL_H_