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_EDIT_H_ |
| 8 | #define PUBLIC_FPDF_EDIT_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | #include "fpdfview.h" |
| 13 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 14 | #define FPDF_ARGB(a, r, g, b) \ |
| 15 | ((uint32_t)(((uint32_t)(b)&0xff) | (((uint32_t)(g)&0xff) << 8) | \ |
| 16 | (((uint32_t)(r)&0xff) << 16) | (((uint32_t)(a)&0xff) << 24))) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 17 | #define FPDF_GetBValue(argb) ((uint8_t)(argb)) |
| 18 | #define FPDF_GetGValue(argb) ((uint8_t)(((uint16_t)(argb)) >> 8)) |
| 19 | #define FPDF_GetRValue(argb) ((uint8_t)((argb) >> 16)) |
| 20 | #define FPDF_GetAValue(argb) ((uint8_t)((argb) >> 24)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 22 | // The page object constants. |
| 23 | #define FPDF_PAGEOBJ_TEXT 1 |
| 24 | #define FPDF_PAGEOBJ_PATH 2 |
| 25 | #define FPDF_PAGEOBJ_IMAGE 3 |
| 26 | #define FPDF_PAGEOBJ_SHADING 4 |
| 27 | #define FPDF_PAGEOBJ_FORM 5 |
| 28 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 31 | #endif // __cplusplus |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 33 | // Create a new PDF document. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 35 | // Returns a handle to a new document, or NULL on failure. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument(); |
| 37 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 38 | // Create a new PDF page. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 40 | // document - handle to document. |
| 41 | // page_index - the index of the page to create. |
| 42 | // width - the page width. |
| 43 | // height - the page height. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 45 | // Returns the handle to the new page. |
| 46 | // |
| 47 | // The page should be deleted with |FPDFPage_Delete| when finished. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, |
| 49 | int page_index, |
| 50 | double width, |
| 51 | double height); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 53 | // Delete the page at |page_index|. |
| 54 | // |
| 55 | // document - handle to document. |
| 56 | // page_index - the index of the page to delete. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index); |
| 58 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 59 | // Get the rotation of |page|. |
| 60 | // |
| 61 | // page - handle to a page |
| 62 | // |
| 63 | // Returns one of the following indicating the page rotation: |
| 64 | // 0 - No rotation. |
| 65 | // 1 - Rotated 90 degrees clockwise. |
| 66 | // 2 - Rotated 180 degrees clockwise. |
| 67 | // 3 - Rotated 270 degrees clockwise. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page); |
| 69 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 70 | // Set rotation for |page|. |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 71 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 72 | // page - handle to a page. |
| 73 | // rotate - the rotation value, one of: |
| 74 | // 0 - No rotation. |
| 75 | // 1 - Rotated 90 degrees clockwise. |
| 76 | // 2 - Rotated 180 degrees clockwise. |
| 77 | // 3 - Rotated 270 degrees clockwise. |
Bo Xu | 394010d | 2014-06-12 13:41:50 -0700 | [diff] [blame] | 78 | DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate); |
| 79 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 80 | // Insert |page_obj| into |page|. |
| 81 | // |
| 82 | // page - handle to a page |
| 83 | // page_obj - handle to a page object. The |page_obj| will be automatically |
| 84 | // freed. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, |
| 86 | FPDF_PAGEOBJECT page_obj); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 88 | // Get number of page objects inside |page|. |
| 89 | // |
| 90 | // page - handle to a page. |
| 91 | // |
| 92 | // Returns the number of objects in |page|. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page); |
| 94 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 95 | // Get object in |page| at |index|. |
| 96 | // |
| 97 | // page - handle to a page. |
| 98 | // index - the index of a page object. |
| 99 | // |
| 100 | // Returns the handle to the page object, or NULL on failed. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index); |
| 102 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 103 | // Checks if |page| contains transparency. |
| 104 | // |
| 105 | // page - handle to a page. |
| 106 | // |
| 107 | // Returns TRUE if |page| contains transparency. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 108 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page); |
| 109 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 110 | // Generate the content of |page|. |
| 111 | // |
| 112 | // page - handle to a page. |
| 113 | // |
| 114 | // Returns TRUE on success. |
| 115 | // |
| 116 | // Before you save the page to a file, or reload the page, you must call |
| 117 | // |FPDFPage_GenerateContent| or any changes to |page| will be lost. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page); |
| 119 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 120 | // Checks if |pageObject| contains transparency. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 122 | // pageObject - handle to a page object. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 124 | // Returns TRUE if |pageObject| contains transparency. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | DLLEXPORT FPDF_BOOL STDCALL |
| 126 | FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 127 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 128 | // Transform |pageObject| by the given matrix. |
| 129 | // |
| 130 | // page_object - handle to a page object. |
| 131 | // a - matrix value. |
| 132 | // b - matrix value. |
| 133 | // c - matrix value. |
| 134 | // d - matrix value. |
| 135 | // e - matrix value. |
| 136 | // f - matrix value. |
| 137 | // |
| 138 | // The matrix is composed as: |
| 139 | // |a c e| |
| 140 | // |b d f| |
| 141 | // and can be used to scale, rotate, shear and translate the |page_object|. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | double a, |
| 144 | double b, |
| 145 | double c, |
| 146 | double d, |
| 147 | double e, |
| 148 | double f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 150 | // Transform all annotations in |page|. |
| 151 | // |
| 152 | // page - handle to a page. |
| 153 | // a - matrix value. |
| 154 | // b - matrix value. |
| 155 | // c - matrix value. |
| 156 | // d - matrix value. |
| 157 | // e - matrix value. |
| 158 | // f - matrix value. |
| 159 | // |
| 160 | // The matrix is composed as: |
| 161 | // |a c e| |
| 162 | // |b d f| |
| 163 | // and can be used to scale, rotate, shear and translate the |page| annotations. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | double a, |
| 166 | double b, |
| 167 | double c, |
| 168 | double d, |
| 169 | double e, |
| 170 | double f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 172 | // Create a new image object. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 173 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 174 | // document - handle to a document. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | // |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 176 | // Returns a handle to a new image object. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | DLLEXPORT FPDF_PAGEOBJECT STDCALL |
| 178 | FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 180 | // Load an image from a JPEG image file and then set it into |image_object|. |
| 181 | // |
| 182 | // pages - pointer to the start of all loaded pages, may be NULL. |
| 183 | // nCount - number of |pages|, may be 0. |
| 184 | // image_object - handle to an image object. |
| 185 | // fileAccess - file access handler which specifies the JPEG image file. |
| 186 | // |
| 187 | // Returns TRUE on success. |
| 188 | // |
| 189 | // The image object might already have an associated image, which is shared and |
| 190 | // cached by the loaded pages. In that case, we need to clear the cached image |
| 191 | // for all the loaded pages. Pass |pages| and page count (|nCount|) to this API |
| 192 | // to clear the image cache. If the image is not previously shared, or NULL is a |
| 193 | // valid |pages| value. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | DLLEXPORT FPDF_BOOL STDCALL |
| 195 | FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, |
| 196 | int nCount, |
| 197 | FPDF_PAGEOBJECT image_object, |
| 198 | FPDF_FILEACCESS* fileAccess); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 199 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 200 | // Set the transform matrix of |image_object|. |
| 201 | // |
| 202 | // image_object - handle to an image object. |
| 203 | // a - matrix value. |
| 204 | // b - matrix value. |
| 205 | // c - matrix value. |
| 206 | // d - matrix value. |
| 207 | // e - matrix value. |
| 208 | // f - matrix value. |
| 209 | // |
| 210 | // The matrix is composed as: |
| 211 | // |a c e| |
| 212 | // |b d f| |
| 213 | // and can be used to scale, rotate, shear and translate the |page| annotations. |
| 214 | // |
| 215 | // Returns TRUE on success. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 216 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | double a, |
| 218 | double b, |
| 219 | double c, |
| 220 | double d, |
| 221 | double e, |
| 222 | double f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 224 | // Set |bitmap| to |image_object|. |
| 225 | // |
| 226 | // pages - pointer to the start of all loaded pages, may be NULL. |
| 227 | // nCount - number of |pages|, may be 0. |
| 228 | // image_object - handle to an image object. |
| 229 | // bitmap - handle of the bitmap. |
| 230 | // |
| 231 | // Returns TRUE on success. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, |
| 233 | int nCount, |
| 234 | FPDF_PAGEOBJECT image_object, |
| 235 | FPDF_BITMAP bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | |
| 237 | #ifdef __cplusplus |
dsinclair | 5f597db | 2016-03-25 09:04:54 -0700 | [diff] [blame] | 238 | } // extern "C" |
| 239 | #endif // __cplusplus |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 240 | |
| 241 | #endif // PUBLIC_FPDF_EDIT_H_ |