Home | History | Annotate | Download | only in public
      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 #include "fpdfview.h"
     13 
     14 // Define all types used in the SDK. Note they can be simply regarded as opaque
     15 // pointers
     16 // or long integer numbers.
     17 
     18 #define FPDF_ARGB(a, r, g, b)                                     \
     19   ((((uint32_t)(((uint8_t)(b) | ((FX_WORD)((uint8_t)(g)) << 8)) | \
     20                 (((FX_DWORD)(uint8_t)(r)) << 16)))) |             \
     21    (((FX_DWORD)(uint8_t)(a)) << 24))
     22 #define FPDF_GetBValue(argb) ((uint8_t)(argb))
     23 #define FPDF_GetGValue(argb) ((uint8_t)(((uint16_t)(argb)) >> 8))
     24 #define FPDF_GetRValue(argb) ((uint8_t)((argb) >> 16))
     25 #define FPDF_GetAValue(argb) ((uint8_t)((argb) >> 24))
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 //////////////////////////////////////////////////////////////////////
     32 //
     33 // Document functions
     34 //
     35 //////////////////////////////////////////////////////////////////////
     36 
     37 // Function: FPDF_CreateNewDocument
     38 //          Create a new PDF document.
     39 // Parameters:
     40 //          None.
     41 // Return value:
     42 //          A handle to a document. If failed, NULL is returned.
     43 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument();
     44 
     45 //////////////////////////////////////////////////////////////////////
     46 //
     47 // Page functions
     48 //
     49 //////////////////////////////////////////////////////////////////////
     50 
     51 // Function: FPDFPage_New
     52 //          Construct an empty page.
     53 // Parameters:
     54 //          document    -   Handle to document. Returned by FPDF_LoadDocument
     55 //          and FPDF_CreateNewDocument.
     56 //          page_index  -   The index of a page.
     57 //          width       -   The page width.
     58 //          height      -   The page height.
     59 // Return value:
     60 //          The handle to the page.
     61 // Comments:
     62 //          Loaded page can be deleted by FPDFPage_Delete.
     63 DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
     64                                          int page_index,
     65                                          double width,
     66                                          double height);
     67 
     68 // Function: FPDFPage_Delete
     69 //          Delete a PDF page.
     70 // Parameters:
     71 //          document    -   Handle to document. Returned by FPDF_LoadDocument
     72 //          and FPDF_CreateNewDocument.
     73 //          page_index  -   The index of a page.
     74 // Return value:
     75 //          None.
     76 DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index);
     77 
     78 // Function: FPDFPage_GetRotation
     79 //          Get the page rotation. One of following values will be returned:
     80 //          0(0), 1(90), 2(180), 3(270).
     81 // Parameters:
     82 //          page        -   Handle to a page. Returned by FPDFPage_New or
     83 //          FPDF_LoadPage.
     84 // Return value:
     85 //          The PDF page rotation.
     86 // Comment:
     87 //          The PDF page rotation is rotated clockwise.
     88 DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page);
     89 
     90 // Function: FPDFPage_SetRotation
     91 //          Set page rotation. One of following values will be set: 0(0), 1(90),
     92 //          2(180), 3(270).
     93 // Parameters:
     94 //          page        -   Handle to a page. Returned by FPDFPage_New or
     95 //          FPDF_LoadPage.
     96 //          rotate      -   The value of the PDF page rotation.
     97 // Return value:
     98 //          None.
     99 // Comment:
    100 //          The PDF page rotation is rotated clockwise.
    101 //
    102 DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate);
    103 
    104 // Function: FPDFPage_InsertObject
    105 //          Insert an object to the page. The page object is automatically
    106 //          freed.
    107 // Parameters:
    108 //          page        -   Handle to a page. Returned by FPDFPage_New or
    109 //          FPDF_LoadPage.
    110 //          page_obj    -   Handle to a page object. Returned by
    111 //          FPDFPageObj_NewTextObj,FPDFPageObj_NewTextObjEx and
    112 //                          FPDFPageObj_NewPathObj.
    113 // Return value:
    114 //          None.
    115 DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page,
    116                                              FPDF_PAGEOBJECT page_obj);
    117 
    118 // Function: FPDFPage_CountObject
    119 //          Get number of page objects inside the page.
    120 // Parameters:
    121 //          page        -   Handle to a page. Returned by FPDFPage_New or
    122 //          FPDF_LoadPage.
    123 // Return value:
    124 //          The number of the page object.
    125 DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page);
    126 
    127 // Function: FPDFPage_GetObject
    128 //          Get page object by index.
    129 // Parameters:
    130 //          page        -   Handle to a page. Returned by FPDFPage_New or
    131 //          FPDF_LoadPage.
    132 //          index       -   The index of a page object.
    133 // Return value:
    134 //          The handle of the page object. Null for failed.
    135 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index);
    136 
    137 // Function: FPDFPage_HasTransparency
    138 //          Check that whether the content of specified PDF page contains
    139 //          transparency.
    140 // Parameters:
    141 //          page        -   Handle to a page. Returned by FPDFPage_New or
    142 //          FPDF_LoadPage.
    143 // Return value:
    144 //          TRUE means that the PDF page does contains transparency.
    145 //          Otherwise, returns FALSE.
    146 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page);
    147 
    148 // Function: FPDFPage_GenerateContent
    149 //          Generate PDF Page content.
    150 // Parameters:
    151 //          page        -   Handle to a page. Returned by FPDFPage_New or
    152 //          FPDF_LoadPage.
    153 // Return value:
    154 //          True if successful, false otherwise.
    155 // Comment:
    156 //          Before you save the page to a file, or reload the page, you must
    157 //          call the FPDFPage_GenerateContent function.
    158 //          Or the changed information will be lost.
    159 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page);
    160 
    161 //////////////////////////////////////////////////////////////////////
    162 //
    163 // Page Object functions
    164 //
    165 //////////////////////////////////////////////////////////////////////
    166 
    167 // Function: FPDFPageObj_HasTransparency
    168 //          Check that whether the specified PDF page object contains
    169 //          transparency.
    170 // Parameters:
    171 //          pageObject  -   Handle to a page object.
    172 // Return value:
    173 //          TRUE means that the PDF page object does contains transparency.
    174 //          Otherwise, returns FALSE.
    175 DLLEXPORT FPDF_BOOL STDCALL
    176 FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject);
    177 
    178 // Function: FPDFPageObj_Transform
    179 //          Transform (scale, rotate, shear, move) page object.
    180 // Parameters:
    181 //          page_object -   Handle to a page object. Returned by
    182 //          FPDFPageObj_NewImageObj.
    183 //          a           -   The coefficient "a" of the matrix.
    184 //          b           -   The coefficient "b" of the matrix.
    185 //          c           -   The coefficient "c" of the matrix.
    186 //          d           -   The coefficient "d" of the matrix.
    187 //          e           -   The coefficient "e" of the matrix.
    188 //          f           -   The coefficient "f" of the matrix.
    189 // Return value:
    190 //          None.
    191 DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object,
    192                                              double a,
    193                                              double b,
    194                                              double c,
    195                                              double d,
    196                                              double e,
    197                                              double f);
    198 
    199 // Function: FPDFPage_TransformAnnots
    200 //          Transform (scale, rotate, shear, move) all annots in a page.
    201 // Parameters:
    202 //          page        -   Handle to a page.
    203 //          a           -   The coefficient "a" of the matrix.
    204 //          b           -   The coefficient "b" of the matrix.
    205 //          c           -   The coefficient "c" of the matrix.
    206 //          d           -   The coefficient "d" of the matrix.
    207 //          e           -   The coefficient "e" of the matrix.
    208 //          f           -   The coefficient "f" of the matrix.
    209 // Return value:
    210 //          None.
    211 DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
    212                                                 double a,
    213                                                 double b,
    214                                                 double c,
    215                                                 double d,
    216                                                 double e,
    217                                                 double f);
    218 
    219 // The page object constants.
    220 #define FPDF_PAGEOBJ_TEXT 1
    221 #define FPDF_PAGEOBJ_PATH 2
    222 #define FPDF_PAGEOBJ_IMAGE 3
    223 #define FPDF_PAGEOBJ_SHADING 4
    224 #define FPDF_PAGEOBJ_FORM 5
    225 
    226 //////////////////////////////////////////////////////////////////////
    227 //
    228 // Image functions
    229 //
    230 //////////////////////////////////////////////////////////////////////
    231 
    232 // Function: FPDFPageObj_NewImgeObj
    233 //          Create a new Image Object.
    234 // Parameters:
    235 //          document        -   Handle to document. Returned by
    236 //          FPDF_LoadDocument or FPDF_CreateNewDocument function.
    237 // Return Value:
    238 //          Handle of image object.
    239 DLLEXPORT FPDF_PAGEOBJECT STDCALL
    240 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document);
    241 
    242 // Function: FPDFImageObj_LoadJpegFile
    243 //          Load Image from a JPEG image file and then set it to an image
    244 //          object.
    245 // Parameters:
    246 //          pages           -   Pointers to the start of all loaded pages, could
    247 //          be NULL.
    248 //          nCount          -   Number of pages, could be 0.
    249 //          image_object    -   Handle of image object returned by
    250 //          FPDFPageObj_NewImgeObj.
    251 //          fileAccess      -   The custom file access handler, which specifies
    252 //          the JPEG image file.
    253 //  Return Value:
    254 //          TRUE if successful, FALSE otherwise.
    255 //  Note:
    256 //          The image object might already has an associated image, which is
    257 //          shared and cached by the loaded pages, In this case, we need to
    258 //          clear the cache of image for all the loaded pages.
    259 //          Pass pages and count to this API to clear the image cache.
    260 DLLEXPORT FPDF_BOOL STDCALL
    261 FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
    262                           int nCount,
    263                           FPDF_PAGEOBJECT image_object,
    264                           FPDF_FILEACCESS* fileAccess);
    265 
    266 // Function: FPDFImageObj_SetMatrix
    267 //          Set the matrix of an image object.
    268 // Parameters:
    269 //          image_object    -   Handle of image object returned by
    270 //          FPDFPageObj_NewImgeObj.
    271 //          a               -   The coefficient "a" of the matrix.
    272 //          b               -   The coefficient "b" of the matrix.
    273 //          c               -   The coefficient "c" of the matrix.
    274 //          d               -   The coefficient "d" of the matrix.
    275 //          e               -   The coefficient "e" of the matrix.
    276 //          f               -   The coefficient "f" of the matrix.
    277 // Return value:
    278 //          TRUE if successful, FALSE otherwise.
    279 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
    280                                                    double a,
    281                                                    double b,
    282                                                    double c,
    283                                                    double d,
    284                                                    double e,
    285                                                    double f);
    286 
    287 // Function: FPDFImageObj_SetBitmap
    288 //          Set the bitmap to an image object.
    289 // Parameters:
    290 //          pages           -   Pointer's to the start of all loaded pages.
    291 //          nCount          -   Number of pages.
    292 //          image_object    -   Handle of image object returned by
    293 //          FPDFPageObj_NewImgeObj.
    294 //          bitmap          -   The handle of the bitmap which you want to set
    295 //          it to the image object.
    296 // Return value:
    297 //          TRUE if successful, FALSE otherwise.
    298 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
    299                                                    int nCount,
    300                                                    FPDF_PAGEOBJECT image_object,
    301                                                    FPDF_BITMAP bitmap);
    302 
    303 #ifdef __cplusplus
    304 }
    305 #endif
    306 
    307 #endif  // PUBLIC_FPDF_EDIT_H_
    308