blob: 2413e2be7a7d2a35ee9491230807790940ee405f [file] [log] [blame]
Svet Ganove6986e12015-06-04 14:52:15 -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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef PUBLIC_FPDF_DATAAVAIL_H_
8#define PUBLIC_FPDF_DATAAVAIL_H_
9
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070010#include <stddef.h>
Svet Ganove6986e12015-06-04 14:52:15 -070011
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070012// NOLINTNEXTLINE(build/include)
Svet Ganove6986e12015-06-04 14:52:15 -070013#include "fpdfview.h"
14
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080015#define PDF_LINEARIZATION_UNKNOWN -1
16#define PDF_NOT_LINEARIZED 0
17#define PDF_LINEARIZED 1
Svet Ganove6986e12015-06-04 14:52:15 -070018
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080019#define PDF_DATA_ERROR -1
20#define PDF_DATA_NOTAVAIL 0
21#define PDF_DATA_AVAIL 1
22
23#define PDF_FORM_ERROR -1
24#define PDF_FORM_NOTAVAIL 0
25#define PDF_FORM_AVAIL 1
26#define PDF_FORM_NOTEXIST 2
Svet Ganove6986e12015-06-04 14:52:15 -070027
28#ifdef __cplusplus
29extern "C" {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070030#endif // __cplusplus
Svet Ganove6986e12015-06-04 14:52:15 -070031
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070032// Interface for checking whether sections of the file are available.
Svet Ganove6986e12015-06-04 14:52:15 -070033typedef struct _FX_FILEAVAIL {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070034 // Version number of the interface. Must be 1.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080035 int version;
Svet Ganove6986e12015-06-04 14:52:15 -070036
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070037 // 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.
49 FPDF_BOOL (*IsDataAvail)(struct _FX_FILEAVAIL* pThis,
50 size_t offset,
51 size_t size);
Svet Ganove6986e12015-06-04 14:52:15 -070052} FX_FILEAVAIL;
Svet Ganove6986e12015-06-04 14:52:15 -070053typedef void* FPDF_AVAIL;
54
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070055// Create a document availability provider.
56//
57// file_avail - pointer to file availability interface.
58// file - pointer to a file access interface.
59//
60// Returns a handle to the document availability provider, or NULL on error.
61//
62// |FPDFAvail_Destroy| must be called when done with the availability provider.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080063DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail,
64 FPDF_FILEACCESS* file);
Svet Ganove6986e12015-06-04 14:52:15 -070065
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070066// Destroy the |avail| document availability provider.
67//
68// avail - handle to document availability provider to be destroyed.
Svet Ganove6986e12015-06-04 14:52:15 -070069DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail);
70
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070071// Download hints interface. Used to receive hints for further downloading.
Svet Ganove6986e12015-06-04 14:52:15 -070072typedef struct _FX_DOWNLOADHINTS {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070073 // Version number of the interface. Must be 1.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080074 int version;
Svet Ganove6986e12015-06-04 14:52:15 -070075
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070076 // Add a section to be downloaded.
77 //
78 // Interface Version: 1
79 // Implementation Required: Yes
80 //
81 // pThis - pointer to the interface structure.
82 // offset - the offset of the hint reported to be downloaded.
83 // size - the size of the hint reported to be downloaded.
84 //
85 // The |offset| and |size| of the section may not be unique. Part of the
86 // section might be already available. The download manager must deal with
87 // overlapping sections.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080088 void (*AddSegment)(struct _FX_DOWNLOADHINTS* pThis,
89 size_t offset,
90 size_t size);
Svet Ganove6986e12015-06-04 14:52:15 -070091} FX_DOWNLOADHINTS;
92
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070093// Checks if the document is ready for loading, if not, gets download hints.
94//
95// avail - handle to document availability provider.
96// hints - pointer to a download hints interface.
97//
98// Returns one of:
99// PDF_DATA_ERROR: A common error is returned. Data availability unknown.
100// PDF_DATA_NOTAVAIL: Data not yet available.
101// PDF_DATA_AVAIL: Data available.
102//
103// Applications should call this function whenever new data arrives, and process
104// all the generated download hints, if any, until the function returns
105// |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|.
106//
107// Once all data is available, call |FPDFAvail_GetDocument| to get a document
108// handle.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800109DLLEXPORT int STDCALL
110FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints);
Svet Ganove6986e12015-06-04 14:52:15 -0700111
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700112// 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//
119// When |FPDFAvail_IsDocAvail| returns TRUE, call |FPDFAvail_GetDocument| to
120// retrieve the document handle.
Svet Ganove6986e12015-06-04 14:52:15 -0700121DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail,
122 FPDF_BYTESTRING password);
123
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700124// Get the page number for the first available page in a linearized PDF.
125//
126// doc - document handle.
127//
128// Returns the zero-based index for the first available page.
129//
130// For most linearized PDFs, the first available page will be the first page,
131// however, some PDFs might make another page the first available page.
132// For non-linearized PDFs, this function will always return zero.
Svet Ganove6986e12015-06-04 14:52:15 -0700133DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc);
134
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700135// Check if |page_index| is ready for loading, if not, get the
136// |FX_DOWNLOADHINTS|.
137//
138// avail - handle to document availability provider.
139// page_index - index number of the page. Zero for the first page.
140// hints - pointer to a download hints interface. Populated if
141// |page_index| is not available.
142//
143// Returns one of:
144// PDF_DATA_ERROR: A common error is returned. Data availability unknown.
145// PDF_DATA_NOTAVAIL: Data not yet available.
146// PDF_DATA_AVAIL: Data available.
147//
148// This function can be called only after |FPDFAvail_GetDocument| is called.
149// Applications should call this function whenever new data arrives and process
150// all the generated download |hints|, if any, until this function returns
151// |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|. Applications can then perform page
152// loading.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800153DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail,
154 int page_index,
155 FX_DOWNLOADHINTS* hints);
Svet Ganove6986e12015-06-04 14:52:15 -0700156
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700157// Check if form data is ready for initialization, if not, get the
158// |FX_DOWNLOADHINTS|.
159//
160// avail - handle to document availability provider.
161// hints - pointer to a download hints interface. Populated if form is not
162// ready for initialization.
163//
164// Returns one of:
165// PDF_FORM_ERROR: A common eror, in general incorrect parameters.
166// PDF_FORM_NOTAVAIL: Data not available.
167// PDF_FORM_AVAIL: Data available.
168// PDF_FORM_NOTEXIST: No form data.
169//
170// This function can be called only after |FPDFAvail_GetDocument| is called.
171// The application should call this function whenever new data arrives and
172// process all the generated download |hints|, if any, until the function
173// |PDF_FORM_ERROR|, |PDF_FORM_AVAIL| or |PDF_FORM_NOTEXIST|.
174// Applications can then perform page loading. It is recommend to call
175// |FPDFDOC_InitFormFillEnvironment| when |PDF_FORM_AVAIL| is returned.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800176DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail,
177 FX_DOWNLOADHINTS* hints);
Svet Ganove6986e12015-06-04 14:52:15 -0700178
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700179// Check whether a document is a linearized PDF.
180//
181// avail - handle to document availability provider.
182//
183// Returns one of:
184// PDF_LINEARIZED
185// PDF_NOT_LINEARIZED
186// PDF_LINEARIZATION_UNKNOWN
187//
188// |FPDFAvail_IsLinearized| will return |PDF_LINEARIZED| or |PDF_NOT_LINEARIZED|
189// when we have 1k of data. If the files size less than 1k, it returns
190// |PDF_LINEARIZATION_UNKNOWN| as there is insufficient information to determine
191// if the PDF is linearlized.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800192DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail);
Svet Ganove6986e12015-06-04 14:52:15 -0700193
194#ifdef __cplusplus
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700195} // extern "C"
196#endif // __cplusplus
Svet Ganove6986e12015-06-04 14:52:15 -0700197
198#endif // PUBLIC_FPDF_DATAAVAIL_H_