blob: acec6c0d301ee9c4f78edc5345679bc463c75476 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -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.
Tom Sepez9857e202015-05-13 17:09:26 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez9857e202015-05-13 17:09:26 -07007#ifndef PUBLIC_FPDF_EDIT_H_
8#define PUBLIC_FPDF_EDIT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepezbfa9a822015-06-09 13:24:12 -070010#include <stdint.h>
11
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012#include "fpdfview.h"
13
dan sinclair61b2fc72016-03-23 19:21:44 -040014#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 Weber9d8ec5a2015-08-04 13:00:21 -070017#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-Malek3f3b45c2014-05-23 17:28:10 -070021
dsinclair5f597db2016-03-25 09:04:54 -070022// 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-Malek3f3b45c2014-05-23 17:28:10 -070029#ifdef __cplusplus
30extern "C" {
dsinclair5f597db2016-03-25 09:04:54 -070031#endif // __cplusplus
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
dsinclair5f597db2016-03-25 09:04:54 -070033// Create a new PDF document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034//
dsinclair5f597db2016-03-25 09:04:54 -070035// Returns a handle to a new document, or NULL on failure.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument();
37
dsinclair5f597db2016-03-25 09:04:54 -070038// Create a new PDF page.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039//
dsinclair5f597db2016-03-25 09:04:54 -070040// 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-Malek3f3b45c2014-05-23 17:28:10 -070044//
dsinclair5f597db2016-03-25 09:04:54 -070045// Returns the handle to the new page.
46//
47// The page should be deleted with |FPDFPage_Delete| when finished.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
49 int page_index,
50 double width,
51 double height);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
dsinclair5f597db2016-03-25 09:04:54 -070053// 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-Malek3f3b45c2014-05-23 17:28:10 -070057DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index);
58
dsinclair5f597db2016-03-25 09:04:54 -070059// 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-Malek3f3b45c2014-05-23 17:28:10 -070068DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page);
69
dsinclair5f597db2016-03-25 09:04:54 -070070// Set rotation for |page|.
Tom Sepez9857e202015-05-13 17:09:26 -070071//
dsinclair5f597db2016-03-25 09:04:54 -070072// 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 Xu394010d2014-06-12 13:41:50 -070078DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate);
79
dsinclair5f597db2016-03-25 09:04:54 -070080// 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 Weber9d8ec5a2015-08-04 13:00:21 -070085DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
86 FPDF_PAGEOBJECT page_obj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
dsinclair5f597db2016-03-25 09:04:54 -070088// 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-Malek3f3b45c2014-05-23 17:28:10 -070093DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page);
94
dsinclair5f597db2016-03-25 09:04:54 -070095// 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-Malek3f3b45c2014-05-23 17:28:10 -0700101DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index);
102
dsinclair5f597db2016-03-25 09:04:54 -0700103// Checks if |page| contains transparency.
104//
105// page - handle to a page.
106//
107// Returns TRUE if |page| contains transparency.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page);
109
dsinclair5f597db2016-03-25 09:04:54 -0700110// 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-Malek3f3b45c2014-05-23 17:28:10 -0700118DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page);
119
dsinclair5f597db2016-03-25 09:04:54 -0700120// Checks if |pageObject| contains transparency.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121//
dsinclair5f597db2016-03-25 09:04:54 -0700122// pageObject - handle to a page object.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123//
dsinclair5f597db2016-03-25 09:04:54 -0700124// Returns TRUE if |pageObject| contains transparency.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125DLLEXPORT FPDF_BOOL STDCALL
126FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127
dsinclair5f597db2016-03-25 09:04:54 -0700128// 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-Malek3f3b45c2014-05-23 17:28:10 -0700142DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 double a,
144 double b,
145 double c,
146 double d,
147 double e,
148 double f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149
dsinclair5f597db2016-03-25 09:04:54 -0700150// 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-Malek3f3b45c2014-05-23 17:28:10 -0700164DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 double a,
166 double b,
167 double c,
168 double d,
169 double e,
170 double f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
dsinclair5f597db2016-03-25 09:04:54 -0700172// Create a new image object.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173//
dsinclair5f597db2016-03-25 09:04:54 -0700174// document - handle to a document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175//
dsinclair5f597db2016-03-25 09:04:54 -0700176// Returns a handle to a new image object.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177DLLEXPORT FPDF_PAGEOBJECT STDCALL
178FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
dsinclair5f597db2016-03-25 09:04:54 -0700180// 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 Weber9d8ec5a2015-08-04 13:00:21 -0700194DLLEXPORT FPDF_BOOL STDCALL
195FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
196 int nCount,
197 FPDF_PAGEOBJECT image_object,
198 FPDF_FILEACCESS* fileAccess);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
dsinclair5f597db2016-03-25 09:04:54 -0700200// 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-Malek3f3b45c2014-05-23 17:28:10 -0700216DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 double a,
218 double b,
219 double c,
220 double d,
221 double e,
222 double f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223
dsinclair5f597db2016-03-25 09:04:54 -0700224// 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 Weber9d8ec5a2015-08-04 13:00:21 -0700232DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
233 int nCount,
234 FPDF_PAGEOBJECT image_object,
235 FPDF_BITMAP bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236
237#ifdef __cplusplus
dsinclair5f597db2016-03-25 09:04:54 -0700238} // extern "C"
239#endif // __cplusplus
Tom Sepez9857e202015-05-13 17:09:26 -0700240
241#endif // PUBLIC_FPDF_EDIT_H_