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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef PUBLIC_FPDF_EDIT_H_ 8 #define PUBLIC_FPDF_EDIT_H_ 9 10 #include <stdint.h> 11 12 // NOLINTNEXTLINE(build/include) 13 #include "fpdfview.h" 14 15 #define FPDF_ARGB(a, r, g, b) \ 16 ((uint32_t)(((uint32_t)(b)&0xff) | (((uint32_t)(g)&0xff) << 8) | \ 17 (((uint32_t)(r)&0xff) << 16) | (((uint32_t)(a)&0xff) << 24))) 18 #define FPDF_GetBValue(argb) ((uint8_t)(argb)) 19 #define FPDF_GetGValue(argb) ((uint8_t)(((uint16_t)(argb)) >> 8)) 20 #define FPDF_GetRValue(argb) ((uint8_t)((argb) >> 16)) 21 #define FPDF_GetAValue(argb) ((uint8_t)((argb) >> 24)) 22 23 // The page object constants. 24 #define FPDF_PAGEOBJ_TEXT 1 25 #define FPDF_PAGEOBJ_PATH 2 26 #define FPDF_PAGEOBJ_IMAGE 3 27 #define FPDF_PAGEOBJ_SHADING 4 28 #define FPDF_PAGEOBJ_FORM 5 29 30 #define FPDF_FILLMODE_ALTERNATE 1 31 #define FPDF_FILLMODE_WINDING 2 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif // __cplusplus 36 37 // Create a new PDF document. 38 // 39 // Returns a handle to a new document, or NULL on failure. 40 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument(); 41 42 // Create a new PDF page. 43 // 44 // document - handle to document. 45 // page_index - suggested index of the page to create. If it is larger than 46 // document's current last index(L), the created page index is 47 // the next available index -- L+1. 48 // width - the page width. 49 // height - the page height. 50 // 51 // Returns the handle to the new page. 52 // 53 // The page should be closed with CPDF_ClosePage() when finished as 54 // with any other page in the document. 55 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, 56 int page_index, 57 double width, 58 double height); 59 60 // Delete the page at |page_index|. 61 // 62 // document - handle to document. 63 // page_index - the index of the page to delete. 64 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index); 65 66 // Get the rotation of |page|. 67 // 68 // page - handle to a page 69 // 70 // Returns one of the following indicating the page rotation: 71 // 0 - No rotation. 72 // 1 - Rotated 90 degrees clockwise. 73 // 2 - Rotated 180 degrees clockwise. 74 // 3 - Rotated 270 degrees clockwise. 75 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page); 76 77 // Set rotation for |page|. 78 // 79 // page - handle to a page. 80 // rotate - the rotation value, one of: 81 // 0 - No rotation. 82 // 1 - Rotated 90 degrees clockwise. 83 // 2 - Rotated 180 degrees clockwise. 84 // 3 - Rotated 270 degrees clockwise. 85 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate); 86 87 // Insert |page_obj| into |page|. 88 // 89 // page - handle to a page 90 // page_obj - handle to a page object. The |page_obj| will be automatically 91 // freed. 92 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, 93 FPDF_PAGEOBJECT page_obj); 94 95 // Get number of page objects inside |page|. 96 // 97 // page - handle to a page. 98 // 99 // Returns the number of objects in |page|. 100 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page); 101 102 // Get object in |page| at |index|. 103 // 104 // page - handle to a page. 105 // index - the index of a page object. 106 // 107 // Returns the handle to the page object, or NULL on failed. 108 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index); 109 110 // Checks if |page| contains transparency. 111 // 112 // page - handle to a page. 113 // 114 // Returns TRUE if |page| contains transparency. 115 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page); 116 117 // Generate the content of |page|. 118 // 119 // page - handle to a page. 120 // 121 // Returns TRUE on success. 122 // 123 // Before you save the page to a file, or reload the page, you must call 124 // |FPDFPage_GenerateContent| or any changes to |page| will be lost. 125 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page); 126 127 // Checks if |pageObject| contains transparency. 128 // 129 // pageObject - handle to a page object. 130 // 131 // Returns TRUE if |pageObject| contains transparency. 132 DLLEXPORT FPDF_BOOL STDCALL 133 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject); 134 135 // Transform |pageObject| by the given matrix. 136 // 137 // page_object - handle to a page object. 138 // a - matrix value. 139 // b - matrix value. 140 // c - matrix value. 141 // d - matrix value. 142 // e - matrix value. 143 // f - matrix value. 144 // 145 // The matrix is composed as: 146 // |a c e| 147 // |b d f| 148 // and can be used to scale, rotate, shear and translate the |page_object|. 149 DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, 150 double a, 151 double b, 152 double c, 153 double d, 154 double e, 155 double f); 156 157 // Transform all annotations in |page|. 158 // 159 // page - handle to a page. 160 // a - matrix value. 161 // b - matrix value. 162 // c - matrix value. 163 // d - matrix value. 164 // e - matrix value. 165 // f - matrix value. 166 // 167 // The matrix is composed as: 168 // |a c e| 169 // |b d f| 170 // and can be used to scale, rotate, shear and translate the |page| annotations. 171 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, 172 double a, 173 double b, 174 double c, 175 double d, 176 double e, 177 double f); 178 179 // Create a new image object. 180 // 181 // document - handle to a document. 182 // 183 // Returns a handle to a new image object. 184 DLLEXPORT FPDF_PAGEOBJECT STDCALL 185 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document); 186 187 // Load an image from a JPEG image file and then set it into |image_object|. 188 // 189 // pages - pointer to the start of all loaded pages, may be NULL. 190 // nCount - number of |pages|, may be 0. 191 // image_object - handle to an image object. 192 // fileAccess - file access handler which specifies the JPEG image file. 193 // 194 // Returns TRUE on success. 195 // 196 // The image object might already have an associated image, which is shared and 197 // cached by the loaded pages. In that case, we need to clear the cached image 198 // for all the loaded pages. Pass |pages| and page count (|nCount|) to this API 199 // to clear the image cache. If the image is not previously shared, or NULL is a 200 // valid |pages| value. 201 DLLEXPORT FPDF_BOOL STDCALL 202 FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, 203 int nCount, 204 FPDF_PAGEOBJECT image_object, 205 FPDF_FILEACCESS* fileAccess); 206 207 // Load an image from a JPEG image file and then set it into |image_object|. 208 // 209 // pages - pointer to the start of all loaded pages, may be NULL. 210 // nCount - number of |pages|, may be 0. 211 // image_object - handle to an image object. 212 // fileAccess - file access handler which specifies the JPEG image file. 213 // 214 // Returns TRUE on success. 215 // 216 // The image object might already have an associated image, which is shared and 217 // cached by the loaded pages. In that case, we need to clear the cached image 218 // for all the loaded pages. Pass |pages| and page count (|nCount|) to this API 219 // to clear the image cache. If the image is not previously shared, or NULL is a 220 // valid |pages| value. This function loads the JPEG image inline, so the image 221 // content is copied to the file. This allows |fileAccess| and its associated 222 // data to be deleted after this function returns. 223 DLLEXPORT FPDF_BOOL STDCALL 224 FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages, 225 int nCount, 226 FPDF_PAGEOBJECT image_object, 227 FPDF_FILEACCESS* fileAccess); 228 229 // Set the transform matrix of |image_object|. 230 // 231 // image_object - handle to an image object. 232 // a - matrix value. 233 // b - matrix value. 234 // c - matrix value. 235 // d - matrix value. 236 // e - matrix value. 237 // f - matrix value. 238 // 239 // The matrix is composed as: 240 // |a c e| 241 // |b d f| 242 // and can be used to scale, rotate, shear and translate the |page| annotations. 243 // 244 // Returns TRUE on success. 245 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, 246 double a, 247 double b, 248 double c, 249 double d, 250 double e, 251 double f); 252 253 // Set |bitmap| to |image_object|. 254 // 255 // pages - pointer to the start of all loaded pages, may be NULL. 256 // nCount - number of |pages|, may be 0. 257 // image_object - handle to an image object. 258 // bitmap - handle of the bitmap. 259 // 260 // Returns TRUE on success. 261 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, 262 int nCount, 263 FPDF_PAGEOBJECT image_object, 264 FPDF_BITMAP bitmap); 265 266 // Create a new path object at an initial position. 267 // 268 // x - initial horizontal position. 269 // y - initial vertical position. 270 // 271 // Returns a handle to a new path object. 272 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewPath(float x, float y); 273 274 // Create a closed path consisting of a rectangle. 275 // 276 // x - horizontal position for the left boundary of the rectangle. 277 // y - vertical position for the bottom boundary of the rectangle. 278 // w - width of the rectangle. 279 // h - height of the rectangle. 280 // 281 // Returns a handle to the new path object. 282 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x, 283 float y, 284 float w, 285 float h); 286 287 // Set the stroke RGBA of a path. Range of values: 0 - 255. 288 // 289 // path - the handle to the path object. 290 // R - the red component for the path stroke color. 291 // G - the green component for the path stroke color. 292 // B - the blue component for the path stroke color. 293 // A - the stroke alpha for the path. 294 // 295 // Returns TRUE on success. 296 DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, 297 unsigned int R, 298 unsigned int G, 299 unsigned int B, 300 unsigned int A); 301 302 // Set the stroke width of a path. 303 // 304 // path - the handle to the path object. 305 // width - the width of the stroke. 306 // 307 // Returns TRUE on success 308 DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width); 309 310 // Set the fill RGBA of a path. Range of values: 0 - 255. 311 // 312 // path - the handle to the path object. 313 // R - the red component for the path fill color. 314 // G - the green component for the path fill color. 315 // B - the blue component for the path fill color. 316 // A - the fill alpha for the path. 317 // 318 // Returns TRUE on success. 319 DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, 320 unsigned int R, 321 unsigned int G, 322 unsigned int B, 323 unsigned int A); 324 325 // Move a path's current point. 326 // 327 // path - the handle to the path object. 328 // x - the horizontal position of the new current point. 329 // y - the vertical position of the new current point. 330 // 331 // Note that no line will be created between the previous current point and the 332 // new one. 333 // 334 // Returns TRUE on success 335 DLLEXPORT FPDF_BOOL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y); 336 337 // Add a line between the current point and a new point in the path. 338 // 339 // path - the handle to the path object. 340 // x - the horizontal position of the new point. 341 // y - the vertical position of the new point. 342 // 343 // The path's current point is changed to (x, y). 344 // 345 // Returns TRUE on success 346 DLLEXPORT FPDF_BOOL FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y); 347 348 // Add a cubic Bezier curve to the given path, starting at the current point. 349 // 350 // path - the handle to the path object. 351 // x1 - the horizontal position of the first Bezier control point. 352 // y1 - the vertical position of the first Bezier control point. 353 // x2 - the horizontal position of the second Bezier control point. 354 // y2 - the vertical position of the second Bezier control point. 355 // x3 - the horizontal position of the ending point of the Bezier curve. 356 // y3 - the vertical position of the ending point of the Bezier curve. 357 // 358 // Returns TRUE on success 359 DLLEXPORT FPDF_BOOL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, 360 float x1, 361 float y1, 362 float x2, 363 float y2, 364 float x3, 365 float y3); 366 367 // Close the current subpath of a given path. 368 // 369 // path - the handle to the path object. 370 // 371 // This will add a line between the current point and the initial point of the 372 // subpath, thus terminating the current subpath. 373 // 374 // Returns TRUE on success 375 DLLEXPORT FPDF_BOOL FPDFPath_Close(FPDF_PAGEOBJECT path); 376 377 // Set the drawing mode of a path. 378 // 379 // path - the handle to the path object. 380 // fillmode - the filling mode to be set: 0 for no fill, 1 for alternate, 2 for 381 // winding. 382 // stroke - a boolean specifying if the path should be stroked or not. 383 // 384 // Returns TRUE on success 385 DLLEXPORT FPDF_BOOL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, 386 int fillmode, 387 FPDF_BOOL stroke); 388 389 // Create a new text object using one of the standard PDF fonts. 390 // 391 // document - handle to the document. 392 // font - string containing the font name, without spaces. 393 // font_size - the font size for the new text object. 394 // 395 // Returns a handle to a new text object, or NULL on failure 396 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewTextObj(FPDF_DOCUMENT document, 397 FPDF_BYTESTRING font, 398 float font_size); 399 400 // Set the text for a textobject. If it had text, it will be replaced. 401 // 402 // text_object - handle to the text object. 403 // text - string containing the text to be added. 404 // 405 // Returns TRUE on success 406 DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetText(FPDF_PAGEOBJECT text_object, 407 FPDF_BYTESTRING text); 408 409 // Returns a type 1 font object loaded from a stream of data. The font is loaded 410 // into the document. The caller does not need to free the returned object. 411 // 412 // document - handle to the document. 413 // data - the stream of data, which will be copied by the font object. 414 // size - size of the stream, in bytes. 415 // 416 // Returns NULL on failure 417 DLLEXPORT FPDF_FONT STDCALL FPDFText_LoadType1Font(FPDF_DOCUMENT document, 418 const uint8_t* data, 419 uint32_t size); 420 421 #ifdef __cplusplus 422 } // extern "C" 423 #endif // __cplusplus 424 425 #endif // PUBLIC_FPDF_EDIT_H_ 426