John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 7 | #ifndef PUBLIC_FPDF_DATAAVAIL_H_ |
| 8 | #define PUBLIC_FPDF_DATAAVAIL_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 10 | #include <stddef.h> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 11 | |
Tom Sepez | 245c80e | 2015-04-08 16:19:33 -0700 | [diff] [blame] | 12 | #include "fpdfview.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 14 | #define PDF_LINEARIZATION_UNKNOWN -1 |
| 15 | #define PDF_NOT_LINEARIZED 0 |
| 16 | #define PDF_LINEARIZED 1 |
Tom Sepez | 326a2a7 | 2015-11-20 10:47:32 -0800 | [diff] [blame] | 17 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 18 | #define PDF_DATA_ERROR -1 |
| 19 | #define PDF_DATA_NOTAVAIL 0 |
| 20 | #define PDF_DATA_AVAIL 1 |
Tom Sepez | 326a2a7 | 2015-11-20 10:47:32 -0800 | [diff] [blame] | 21 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 22 | #define PDF_FORM_ERROR -1 |
| 23 | #define PDF_FORM_NOTAVAIL 0 |
| 24 | #define PDF_FORM_AVAIL 1 |
| 25 | #define PDF_FORM_NOTEXIST 2 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 29 | #endif // __cplusplus |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 31 | // Interface for checking whether sections of the file are available. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | typedef struct _FX_FILEAVAIL { |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 33 | // Version number of the interface. Must be 1. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | int version; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 36 | // Reports if the specified data section is currently available. A section is |
| 37 | // available if all bytes in the section are available. |
| 38 | // |
| 39 | // Interface Version: 1 |
| 40 | // Implementation Required: Yes |
| 41 | // |
| 42 | // pThis - pointer to the interface structure. |
| 43 | // offset - the offset of the data section in the file. |
| 44 | // size - the size of the data section. |
| 45 | // |
| 46 | // Returns true if the specified data section at |offset| of |size| |
| 47 | // is available. |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 48 | FPDF_BOOL (*IsDataAvail)(struct _FX_FILEAVAIL* pThis, |
| 49 | size_t offset, |
| 50 | size_t size); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | } FX_FILEAVAIL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | typedef void* FPDF_AVAIL; |
| 53 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 54 | // 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 | // |
| 61 | // |FPDFAvail_Destroy| must be called when done with the availability provider. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, |
| 63 | FPDF_FILEACCESS* file); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 65 | // Destroy the |avail| document availability provider. |
| 66 | // |
| 67 | // |avail| - handle to document availability provider to be destroyed. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail); |
| 69 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 70 | // Download hints interface. Used to receive hints for further downloading. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | typedef struct _FX_DOWNLOADHINTS { |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 72 | // Version number of the interface. Must be 1. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | int version; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 75 | // 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 Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | void (*AddSegment)(struct _FX_DOWNLOADHINTS* pThis, |
| 88 | size_t offset, |
| 89 | size_t size); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | } FX_DOWNLOADHINTS; |
| 91 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 92 | // 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|. |
| 105 | // |
| 106 | // Once all data is available, call |FPDFAvail_GetDocument| to get a document |
| 107 | // handle. |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 108 | DLLEXPORT int STDCALL |
| 109 | FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 111 | // Get document from the availability provider. |
| 112 | // |
| 113 | // avail - handle to document availability provider. |
| 114 | // password - password for decrypting the PDF file. Optional. |
| 115 | // |
| 116 | // Returns a handle to the document. |
| 117 | // |
| 118 | // When |FPDFAvail_IsDocAvail| returns TRUE, call |FPDFAvail_GetDocument| to |
| 119 | // retrieve the document handle. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, |
| 121 | FPDF_BYTESTRING password); |
| 122 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 123 | // Get the page number for the first available page in a linearized PDF. |
| 124 | // |
| 125 | // doc - document handle. |
| 126 | // |
| 127 | // Returns the zero-based index for the first available page. |
| 128 | // |
| 129 | // For most linearized PDFs, the first available page will be the first page, |
| 130 | // however, some PDFs might make another page the first available page. |
| 131 | // For non-linearized PDFs, this function will always return zero. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc); |
| 133 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 134 | // Check if |page_index| is ready for loading, if not, get the |
| 135 | // |FX_DOWNLOADHINTS|. |
| 136 | // |
| 137 | // avail - handle to document availability provider. |
| 138 | // page_index - index number of the page. Zero for the first page. |
| 139 | // hints - pointer to a download hints interface. Populated if |
| 140 | // |page_index| is not available. |
| 141 | // |
| 142 | // Returns one of: |
| 143 | // PDF_DATA_ERROR: A common error is returned. Data availability unknown. |
| 144 | // PDF_DATA_NOTAVAIL: Data not yet available. |
| 145 | // PDF_DATA_AVAIL: Data available. |
| 146 | // |
| 147 | // This function can be called only after |FPDFAvail_GetDocument| is called. |
| 148 | // Applications should call this function whenever new data arrives and process |
| 149 | // all the generated download |hints|, if any, until this function returns |
| 150 | // |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|. Applications can then perform page |
| 151 | // loading. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, |
| 153 | int page_index, |
| 154 | FX_DOWNLOADHINTS* hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 155 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 156 | // Check if form data is ready for initialization, if not, get the |
| 157 | // |FX_DOWNLOADHINTS|. |
| 158 | // |
| 159 | // avail - handle to document availability provider. |
| 160 | // hints - pointer to a download hints interface. Populated if form is not |
| 161 | // ready for initialization. |
| 162 | // |
| 163 | // Returns one of: |
| 164 | // PDF_FORM_ERROR: A common eror, in general incorrect parameters. |
| 165 | // PDF_FORM_NOTAVAIL: Data not available. |
| 166 | // PDF_FORM_AVAIL: Data available. |
| 167 | // PDF_FORM_NOTEXIST: No form data. |
| 168 | // |
| 169 | // This function can be called only after |FPDFAvail_GetDocument| is called. |
| 170 | // The application should call this function whenever new data arrives and |
| 171 | // process all the generated download |hints|, if any, until the function |
| 172 | // |PDF_FORM_ERROR|, |PDF_FORM_AVAIL| or |PDF_FORM_NOTEXIST|. |
| 173 | // Applications can then perform page loading. It is recommend to call |
| 174 | // |FPDFDOC_InitFormFillEnvironment| when |PDF_FORM_AVAIL| is returned. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, |
| 176 | FX_DOWNLOADHINTS* hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 177 | |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 178 | // Check whether a document is a linearized PDF. |
| 179 | // |
| 180 | // avail - handle to document availability provider. |
| 181 | // |
| 182 | // Returns one of: |
| 183 | // PDF_LINEARIZED |
| 184 | // PDF_NOT_LINEARIZED |
| 185 | // PDF_LINEARIZATION_UNKNOWN |
| 186 | // |
| 187 | // |FPDFAvail_IsLinearized| will return |PDF_LINEARIZED| or |PDF_NOT_LINEARIZED| |
| 188 | // when we have 1k of data. If the files size less than 1k, it returns |
| 189 | // |PDF_LINEARIZATION_UNKNOWN| as there is insufficient information to determine |
| 190 | // if the PDF is linearlized. |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 191 | DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 192 | |
| 193 | #ifdef __cplusplus |
dan sinclair | ea10a0d | 2016-03-23 19:36:46 -0400 | [diff] [blame] | 194 | } // extern "C" |
| 195 | #endif // __cplusplus |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 196 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 197 | #endif // PUBLIC_FPDF_DATAAVAIL_H_ |