blob: 9e349bdd5ef1a6fa484943b220a9e93c2db601b8 [file] [log] [blame]
Jane Liu4fd9a472017-06-01 18:56:09 -04001// 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
16extern "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 Liu20eafda2017-06-07 10:33:24 -040048typedef enum FPDFANNOT_COLORTYPE {
49 FPDFANNOT_COLORTYPE_Color = 0,
50 FPDFANNOT_COLORTYPE_InteriorColor
51} FPDFANNOT_COLORTYPE;
52
53typedef 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 Liu8ce58f52017-06-29 13:40:22 -040065// Returns true if this subtype supported.
Jane Liu20eafda2017-06-07 10:33:24 -040066DLLEXPORT FPDF_BOOL STDCALL
67FPDFAnnot_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 Liu20eafda2017-06-07 10:33:24 -040074//
Jane Liud60e9ad2017-06-26 11:28:36 -040075// Returns a handle to the new annotation object, or NULL on failure.
76DLLEXPORT FPDF_ANNOTATION STDCALL
77FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype);
Jane Liu20eafda2017-06-07 10:33:24 -040078
Jane Liu4fd9a472017-06-01 18:56:09 -040079// Get the number of annotations in |page|.
80//
81// page - handle to a page.
82//
83// Returns the number of annotations in |page|.
84DLLEXPORT 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 Liu4fd9a472017-06-01 18:56:09 -040090//
Jane Liud60e9ad2017-06-26 11:28:36 -040091// Returns a handle to the annotation object, or NULL on failure.
92DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index);
Jane Liu4fd9a472017-06-01 18:56:09 -040093
Jane Liue10509a2017-06-20 16:47:41 -040094// 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.
99DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot);
100
Jane Liu8ce58f52017-06-29 13:40:22 -0400101// 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.
107DLLEXPORT FPDF_BOOL STDCALL FPDFPage_RemoveAnnot(FPDF_PAGE page, int index);
108
Jane Liu4fd9a472017-06-01 18:56:09 -0400109// Get the subtype of an annotation.
110//
111// annot - handle to an annotation.
112//
113// Returns the annotation subtype.
114DLLEXPORT FPDF_ANNOTATION_SUBTYPE STDCALL
115FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot);
116
Jane Liu06462752017-06-27 16:41:14 -0400117// 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 Liu20eafda2017-06-07 10:33:24 -0400120//
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 Liu8ce58f52017-06-29 13:40:22 -0400126// Returns true if successful.
Jane Liu20eafda2017-06-07 10:33:24 -0400127DLLEXPORT 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 Liu4fd9a472017-06-01 18:56:09 -0400133
134// Get the color of an annotation. If no color is specified, default to yellow
Jane Liu06462752017-06-27 16:41:14 -0400135// 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 Liu4fd9a472017-06-01 18:56:09 -0400138//
Jane Liu20eafda2017-06-07 10:33:24 -0400139// annot - handle to an annotation.
140// type - type of the color requested.
Jane Liu4fd9a472017-06-01 18:56:09 -0400141// R, G, B - buffer to hold the RGB value of the color. Ranges from 0 to 255.
Jane Liu20eafda2017-06-07 10:33:24 -0400142// A - buffer to hold the opacity. Ranges from 0 to 255.
Jane Liu4fd9a472017-06-01 18:56:09 -0400143//
Jane Liu8ce58f52017-06-29 13:40:22 -0400144// Returns true if successful.
Jane Liu4fd9a472017-06-01 18:56:09 -0400145DLLEXPORT 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 Liu20eafda2017-06-07 10:33:24 -0400155// 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 Liu4fd9a472017-06-01 18:56:09 -0400158//
159// annot - handle to an annotation.
160//
161// Returns true if the annotation is of a type that has quadpoints, false
162// otherwise.
163DLLEXPORT FPDF_BOOL STDCALL
164FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot);
165
Jane Liu06462752017-06-27 16:41:14 -0400166// 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 Liu20eafda2017-06-07 10:33:24 -0400169//
170// annot - handle to an annotation.
171// quadPoints - the quadpoints to be set.
172//
Jane Liu8ce58f52017-06-29 13:40:22 -0400173// Returns true if successful.
Jane Liu20eafda2017-06-07 10:33:24 -0400174DLLEXPORT FPDF_BOOL STDCALL
Jane Liu06462752017-06-27 16:41:14 -0400175FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot,
176 const FS_QUADPOINTSF* quadPoints);
Jane Liu20eafda2017-06-07 10:33:24 -0400177
Jane Liu06462752017-06-27 16:41:14 -0400178// 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 Liu4fd9a472017-06-01 18:56:09 -0400181//
Jane Liu20eafda2017-06-07 10:33:24 -0400182// annot - handle to an annotation.
Jane Liu4fd9a472017-06-01 18:56:09 -0400183//
Jane Liud60e9ad2017-06-26 11:28:36 -0400184// Returns a quadpoints object, or an empty set of quadpoints on failure.
185DLLEXPORT FS_QUADPOINTSF STDCALL
186FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot);
Jane Liu4fd9a472017-06-01 18:56:09 -0400187
Jane Liu06462752017-06-27 16:41:14 -0400188// 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 Liu20eafda2017-06-07 10:33:24 -0400191//
192// annot - handle to an annotation.
193// rect - the annotation rectangle to be set.
194//
Jane Liu8ce58f52017-06-29 13:40:22 -0400195// Returns true if successful.
Jane Liu20eafda2017-06-07 10:33:24 -0400196DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot,
Jane Liu06462752017-06-27 16:41:14 -0400197 const FS_RECTF* rect);
Jane Liu20eafda2017-06-07 10:33:24 -0400198
Jane Liu06462752017-06-27 16:41:14 -0400199// 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 Liu4fd9a472017-06-01 18:56:09 -0400202//
203// annot - handle to an annotation.
Jane Liu4fd9a472017-06-01 18:56:09 -0400204//
Jane Liud60e9ad2017-06-26 11:28:36 -0400205// Returns a rectangle object, or an empty rectangle on failure.
206DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot);
Jane Liu4fd9a472017-06-01 18:56:09 -0400207
Jane Liu20eafda2017-06-07 10:33:24 -0400208// 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 Liu8ce58f52017-06-29 13:40:22 -0400214// Returns true if successful.
Jane Liu20eafda2017-06-07 10:33:24 -0400215DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetText(FPDF_ANNOTATION annot,
216 FPDFANNOT_TEXTTYPE type,
217 FPDF_WIDESTRING text);
Jane Liu4fd9a472017-06-01 18:56:09 -0400218
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 Liu20eafda2017-06-07 10:33:24 -0400223// type - type of the text requested.
Jane Liu4fd9a472017-06-01 18:56:09 -0400224// 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 Liu4fd9a472017-06-01 18:56:09 -0400228DLLEXPORT unsigned long STDCALL FPDFAnnot_GetText(FPDF_ANNOTATION annot,
229 FPDFANNOT_TEXTTYPE type,
Jane Liu262cf462017-06-09 11:36:37 -0400230 void* buffer,
Jane Liu4fd9a472017-06-01 18:56:09 -0400231 unsigned long buflen);
232
233#ifdef __cplusplus
234} // extern "C"
235#endif // __cplusplus
236
237#endif // PUBLIC_FPDF_ANNOT_H_