Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 1 | // Copyright 2017 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_ANNOT_H_ |
| 8 | #define PUBLIC_FPDF_ANNOT_H_ |
| 9 | |
| 10 | // NOLINTNEXTLINE(build/include) |
| 11 | #include "fpdfview.h" |
| 12 | |
| 13 | #include "public/fpdf_doc.h" |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif // __cplusplus |
| 18 | |
| 19 | #define FPDF_ANNOT_UNKNOWN 0 |
| 20 | #define FPDF_ANNOT_TEXT 1 |
| 21 | #define FPDF_ANNOT_LINK 2 |
| 22 | #define FPDF_ANNOT_FREETEXT 3 |
| 23 | #define FPDF_ANNOT_LINE 4 |
| 24 | #define FPDF_ANNOT_SQUARE 5 |
| 25 | #define FPDF_ANNOT_CIRCLE 6 |
| 26 | #define FPDF_ANNOT_POLYGON 7 |
| 27 | #define FPDF_ANNOT_POLYLINE 8 |
| 28 | #define FPDF_ANNOT_HIGHLIGHT 9 |
| 29 | #define FPDF_ANNOT_UNDERLINE 10 |
| 30 | #define FPDF_ANNOT_SQUIGGLY 11 |
| 31 | #define FPDF_ANNOT_STRIKEOUT 12 |
| 32 | #define FPDF_ANNOT_STAMP 13 |
| 33 | #define FPDF_ANNOT_CARET 14 |
| 34 | #define FPDF_ANNOT_INK 15 |
| 35 | #define FPDF_ANNOT_POPUP 16 |
| 36 | #define FPDF_ANNOT_FILEATTACHMENT 17 |
| 37 | #define FPDF_ANNOT_SOUND 18 |
| 38 | #define FPDF_ANNOT_MOVIE 19 |
| 39 | #define FPDF_ANNOT_WIDGET 20 |
| 40 | #define FPDF_ANNOT_SCREEN 21 |
| 41 | #define FPDF_ANNOT_PRINTERMARK 22 |
| 42 | #define FPDF_ANNOT_TRAPNET 23 |
| 43 | #define FPDF_ANNOT_WATERMARK 24 |
| 44 | #define FPDF_ANNOT_THREED 25 |
| 45 | #define FPDF_ANNOT_RICHMEDIA 26 |
| 46 | #define FPDF_ANNOT_XFAWIDGET 27 |
| 47 | |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 48 | typedef enum FPDFANNOT_COLORTYPE { |
| 49 | FPDFANNOT_COLORTYPE_Color = 0, |
| 50 | FPDFANNOT_COLORTYPE_InteriorColor |
| 51 | } FPDFANNOT_COLORTYPE; |
| 52 | |
| 53 | typedef enum FPDFANNOT_TEXTTYPE { |
| 54 | FPDFANNOT_TEXTTYPE_Contents = 0, |
| 55 | FPDFANNOT_TEXTTYPE_Author |
| 56 | } FPDFANNOT_TEXTTYPE; |
| 57 | |
| 58 | // Check if an annotation subtype is currently supported for creating and |
| 59 | // displaying. The supported subtypes must be consistent with the ones supported |
| 60 | // by AP generation - see the list of calls to CPVT_GenerateAP::Generate*AP() in |
| 61 | // CPDF_Annot::GenerateAPIfNeeded(). |
| 62 | // |
| 63 | // subtype - the subtype to be checked. |
| 64 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 65 | // Returns true if this subtype supported. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 66 | DLLEXPORT FPDF_BOOL STDCALL |
| 67 | FPDFAnnot_IsSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype); |
| 68 | |
| 69 | // Create an annotation in |page| of the subtype |subtype|. If the specified |
| 70 | // subtype is illegal or unsupported, then a new annotation will not be created. |
| 71 | // |
| 72 | // page - handle to a page. |
| 73 | // subtype - the subtype of the new annotation. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 74 | // |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 75 | // Returns a handle to the new annotation object, or NULL on failure. |
| 76 | DLLEXPORT FPDF_ANNOTATION STDCALL |
| 77 | FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 78 | |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 79 | // Get the number of annotations in |page|. |
| 80 | // |
| 81 | // page - handle to a page. |
| 82 | // |
| 83 | // Returns the number of annotations in |page|. |
| 84 | DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page); |
| 85 | |
| 86 | // Get annotation in |page| at |index|. |
| 87 | // |
| 88 | // page - handle to a page. |
| 89 | // index - the index of the annotation. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 90 | // |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 91 | // Returns a handle to the annotation object, or NULL on failure. |
| 92 | DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 93 | |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 94 | // Close an annotation. Must be called when the annotation returned by |
| 95 | // FPDFPage_CreateAnnot() or FPDFPage_GetAnnot() is no longer needed. This |
| 96 | // function does not remove the annotation from the document. |
| 97 | // |
| 98 | // annot - handle to an annotation. |
| 99 | DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot); |
| 100 | |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 101 | // Remove the annotation in |page| at |index|. |
| 102 | // |
| 103 | // page - handle to a page. |
| 104 | // index - the index of the annotation. |
| 105 | // |
| 106 | // Returns true if successful. |
| 107 | DLLEXPORT FPDF_BOOL STDCALL FPDFPage_RemoveAnnot(FPDF_PAGE page, int index); |
| 108 | |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 109 | // Get the subtype of an annotation. |
| 110 | // |
| 111 | // annot - handle to an annotation. |
| 112 | // |
| 113 | // Returns the annotation subtype. |
| 114 | DLLEXPORT FPDF_ANNOTATION_SUBTYPE STDCALL |
| 115 | FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot); |
| 116 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 117 | // Set the color of an annotation. Fails when called on annotations with |
| 118 | // appearance streams already defined; instead use |
| 119 | // FPDFPath_Set{Stroke|Fill}Color(). |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 120 | // |
| 121 | // annot - handle to an annotation. |
| 122 | // type - type of the color to be set. |
| 123 | // R, G, B - buffer to hold the RGB value of the color. Ranges from 0 to 255. |
| 124 | // A - buffer to hold the opacity. Ranges from 0 to 255. |
| 125 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 126 | // Returns true if successful. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 127 | DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetColor(FPDF_ANNOTATION annot, |
| 128 | FPDFANNOT_COLORTYPE type, |
| 129 | unsigned int R, |
| 130 | unsigned int G, |
| 131 | unsigned int B, |
| 132 | unsigned int A); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 133 | |
| 134 | // Get the color of an annotation. If no color is specified, default to yellow |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 135 | // for highlight annotation, black for all else. Fails when called on |
| 136 | // annotations with appearance streams already defined; instead use |
| 137 | // FPDFPath_Get{Stroke|Fill}Color(). |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 138 | // |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 139 | // annot - handle to an annotation. |
| 140 | // type - type of the color requested. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 141 | // R, G, B - buffer to hold the RGB value of the color. Ranges from 0 to 255. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 142 | // A - buffer to hold the opacity. Ranges from 0 to 255. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 143 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 144 | // Returns true if successful. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 145 | DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetColor(FPDF_ANNOTATION annot, |
| 146 | FPDFANNOT_COLORTYPE type, |
| 147 | unsigned int* R, |
| 148 | unsigned int* G, |
| 149 | unsigned int* B, |
| 150 | unsigned int* A); |
| 151 | |
| 152 | // Check if the annotation is of a type that has attachment points |
| 153 | // (i.e. quadpoints). Quadpoints are the vertices of the rectange that |
| 154 | // encompasses the texts affected by the annotation. They provide the |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 155 | // coordinates in the page where the annotation is attached. Only text markup |
| 156 | // annotations (i.e. highlight, strikeout, squiggly, and underline) and link |
| 157 | // annotations have quadpoints. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 158 | // |
| 159 | // annot - handle to an annotation. |
| 160 | // |
| 161 | // Returns true if the annotation is of a type that has quadpoints, false |
| 162 | // otherwise. |
| 163 | DLLEXPORT FPDF_BOOL STDCALL |
| 164 | FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot); |
| 165 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 166 | // Set the attachment points (i.e. quadpoints) of an annotation. If the |
| 167 | // annotation's appearance stream is defined and this annotation is of a type |
| 168 | // with quadpoints, then update the bounding box too. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 169 | // |
| 170 | // annot - handle to an annotation. |
| 171 | // quadPoints - the quadpoints to be set. |
| 172 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 173 | // Returns true if successful. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 174 | DLLEXPORT FPDF_BOOL STDCALL |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 175 | FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, |
| 176 | const FS_QUADPOINTSF* quadPoints); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 177 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 178 | // Get the attachment points (i.e. quadpoints) of an annotation. If the |
| 179 | // annotation's appearance stream is defined and this annotation is of a type |
| 180 | // with quadpoints, then return the bounding box it specifies instead. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 181 | // |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 182 | // annot - handle to an annotation. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 183 | // |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 184 | // Returns a quadpoints object, or an empty set of quadpoints on failure. |
| 185 | DLLEXPORT FS_QUADPOINTSF STDCALL |
| 186 | FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 187 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 188 | // Set the annotation rectangle defining the location of the annotation. If the |
| 189 | // annotation's appearance stream is defined and this annotation is of a type |
| 190 | // without quadpoints, then update the bounding box too. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 191 | // |
| 192 | // annot - handle to an annotation. |
| 193 | // rect - the annotation rectangle to be set. |
| 194 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 195 | // Returns true if successful. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 196 | DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 197 | const FS_RECTF* rect); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 198 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 199 | // Get the annotation rectangle defining the location of the annotation. If the |
| 200 | // annotation's appearance stream is defined and this annotation is of a type |
| 201 | // without quadpoints, then return the bounding box it specifies instead. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 202 | // |
| 203 | // annot - handle to an annotation. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 204 | // |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 205 | // Returns a rectangle object, or an empty rectangle on failure. |
| 206 | DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 207 | |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 208 | // Set the contents of an annotation. |
| 209 | // |
| 210 | // annot - handle to an annotation. |
| 211 | // type - type of the text to be set. |
| 212 | // text - the text to be set. |
| 213 | // |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 214 | // Returns true if successful. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 215 | DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetText(FPDF_ANNOTATION annot, |
| 216 | FPDFANNOT_TEXTTYPE type, |
| 217 | FPDF_WIDESTRING text); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 218 | |
| 219 | // Get the contents of an annotation. |buffer| is only modified if |buflen| |
| 220 | // is longer than the length of contents. |
| 221 | // |
| 222 | // annot - handle to an annotation. |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 223 | // type - type of the text requested. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 224 | // buffer - buffer for holding the contents string, encoded in UTF16-LE. |
| 225 | // buflen - length of the buffer. |
| 226 | // |
| 227 | // Returns the length of the contents. |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 228 | DLLEXPORT unsigned long STDCALL FPDFAnnot_GetText(FPDF_ANNOTATION annot, |
| 229 | FPDFANNOT_TEXTTYPE type, |
Jane Liu | 262cf46 | 2017-06-09 11:36:37 -0400 | [diff] [blame] | 230 | void* buffer, |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 231 | unsigned long buflen); |
| 232 | |
| 233 | #ifdef __cplusplus |
| 234 | } // extern "C" |
| 235 | #endif // __cplusplus |
| 236 | |
| 237 | #endif // PUBLIC_FPDF_ANNOT_H_ |