1 // 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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #ifndef PUBLIC_FPDF_DATAAVAIL_H_
8 #define PUBLIC_FPDF_DATAAVAIL_H_
10 #include <stddef.h> // For size_t.
14 /** The result of the process which check linearized PDF. */
15 #define FSDK_IS_LINEARIZED 1
16 #define FSDK_NOT_LINEARIZED 0
17 #define FSDK_UNKNOW_LINEARIZED -1
25 * Interface: FX_FILEAVAIL
26 * Interface for checking whether the section of the file is available.
28 typedef struct _FX_FILEAVAIL {
30 * Version number of the interface. Currently must be 1.
36 * Report whether the specified data section is available. A section is available only if all bytes in the section is available.
39 * Implementation Required:
42 * pThis - Pointer to the interface structure itself.
43 * offset - The offset of the data section in the file.
44 * size - The size of the data section
46 * true means the specified data section is available.
48 * Called by Foxit SDK to check whether the data section is ready.
50 FPDF_BOOL (*IsDataAvail)(struct _FX_FILEAVAIL* pThis, size_t offset, size_t size);
53 typedef void* FPDF_AVAIL;
56 * Function: FPDFAvail_Create
57 * Create a document availability provider.
60 * file_avail - Pointer to file availability interface to check availability of file data.
61 * file - Pointer to a file access interface for reading data from file.
63 * A handle to the document availability provider. NULL for error.
65 * Application must call FPDFAvail_Destroy when done with the availability provider.
67 * The method can not support to load a document which consists of dynamic XFA fields now.
69 DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file);
72 * Function: FPDFAvail_Destroy
73 * Destroy a document availibity provider.
76 * avail - Handle to document availability provider returned by FPDFAvail_Create
80 DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail);
83 * Interface: FX_DOWNLOADHINTS
84 * Download hints interface. Used to receive hints for further downloading.
86 typedef struct _FX_DOWNLOADHINTS {
88 * Version number of the interface. Currently must be 1.
94 * Add a section to be downloaded.
97 * Implementation Required:
100 * pThis - Pointer to the interface structure itself.
101 * offset - The offset of the hint reported to be downloaded.
102 * size - The size of the hint reported to be downloaded.
106 * Called by Foxit SDK to report some downloading hints for download manager.
107 * The position and size of section may be not accurate, part of the section might be already available.
108 * The download manager must deal with that to maximize download efficiency.
110 void (*AddSegment)(struct _FX_DOWNLOADHINTS* pThis, size_t offset, size_t size);
114 * Function: FPDFAvail_IsDocAvail
115 * Check whether the document is ready for loading, if not, get download hints.
118 * avail - Handle to document availability provider returned by FPDFAvail_Create
119 * hints - Pointer to a download hints interface, receiving generated hints
121 * Non-zero for page is fully available, 0 for page not yet available.
123 * The application should call this function whenever new data arrived, and process all the
124 * generated download hints if any, until the function returns non-zero value. Then the
125 * application can call FPDFAvail_GetDocument() to get a document handle.
127 DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints);
130 * Function: FPDFAvail_GetDocument
131 * Get document from the availability provider.
134 * avail - Handle to document availability provider returned by FPDFAvail_Create
135 * password - Optional password for decrypting the PDF file.
137 * Handle to the document.
139 * After FPDFAvail_IsDocAvail() returns TRUE, the application should call this function to
140 * get the document handle. To close the document, use FPDF_CloseDocument function.
142 DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail,
143 FPDF_BYTESTRING password);
146 * Function: FPDFAvail_GetFirstPageNum
147 * Get page number for the first available page in a linearized PDF
150 * doc - A document handle returned by FPDFAvail_GetDocument
152 * Zero-based index for the first available page.
154 * For most linearized PDFs, the first available page would be just the first page, however,
155 * some PDFs might make other page to be the first available page.
156 * For non-linearized PDF, this function will always return zero.
158 DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc);
161 * Function: FPDFAvail_IsPageAvail
162 * Check whether a page is ready for loading, if not, get download hints.
165 * avail - Handle to document availability provider returned by FPDFAvail_Create
166 * page_index - Index number of the page. 0 for the first page.
167 * hints - Pointer to a download hints interface, receiving generated hints
169 * Non-zero for page is fully available, 0 for page not yet available.
171 * This function call be called only after FPDFAvail_GetDocument if called.
172 * The application should call this function whenever new data arrived, and process all the
173 * generated download hints if any, until the function returns non-zero value. Then the
174 * application can perform page loading.
176 DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, int page_index, FX_DOWNLOADHINTS* hints);
179 * Function: FPDFAvail_ISFormAvail
180 * Check whether Form data is ready for init, if not, get download hints.
183 * avail - Handle to document availability provider returned by FPDFAvail_Create
184 * hints - Pointer to a download hints interface, receiving generated hints
186 * Non-zero for Form data is fully available, 0 for Form data not yet available.
187 * Details: -1 - error, the input parameter not correct, such as hints is null.
188 * 0 - data not available
192 * This function call be called only after FPDFAvail_GetDocument if called.
193 * The application should call this function whenever new data arrived, and process all the
194 * generated download hints if any, until the function returns non-zero value. Then the
195 * application can perform page loading. Recommend to call FPDFDOC_InitFormFillEnvironment
196 * after the function returns non-zero value.
198 DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints);
201 * Function: FPDFAvail_IsLinearized
202 * To check whether a document is Linearized PDF file.
205 * avail - Handle to document availability provider returned by FPDFAvail_Create
207 * return TRUE means the document is linearized PDF else not.
208 * FSDK_IS_LINEARIZED is a linearize file.
209 * FSDK_NOT_LINEARIZED is not a linearize file.
210 * FSDK_UNKNOW_LINEARIZED don't know whether the file is a linearize file.
212 * It return TRUE/FALSE as soon as we have first 1K data. If the file's size less than
213 * 1K,we don't known whether the PDF is a linearized file.
216 DLLEXPORT FPDF_BOOL STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail);
222 #endif // PUBLIC_FPDF_DATAAVAIL_H_