1 //========================================================================
5 // Copyright 2000-2005 Emmanuel Lesueur
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
26 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
30 const int annotInvisible
= 1 << 0;
31 const int annotHidden
= 1 << 1;
32 const int annotPrint
= 1 << 2;
33 const int annotNoZoom
= 1 << 3;
34 const int annotNoRotate
= 1 << 4;
35 const int annotNoView
= 1 << 5;
36 const int annotReadOnly
= 1 << 6;
75 enum AnnotAppearance
{
85 AnnotState(): setFlags(0), clrFlags(0), additionalAction(NULL
) {}
88 // Import from an FDF dictionary.
92 AnnotState(const AnnotState
&);
93 AnnotState
& operator = (const AnnotState
&);
98 Object appearanceState
;
99 AdditionalAction
*additionalAction
;
107 Annot(XRef
*, Object
*);
112 // Check annotation type.
113 virtual AnnotKind
getKind() { return annotUnknown
; }
115 // Get the annotation description string.
116 virtual char *getDescr() { return NULL
; }
118 // Was the Annot created successfully?
119 GBool
isOk() { return ok
; }
121 // Get annotation box.
122 void getRect(double *xa1
, double *ya1
, double *xa2
, double *ya2
)
123 { *xa1
= x1
; *ya1
= y1
; *xa2
= x2
; *ya2
= y2
; }
125 // Check if point is inside the link rectangle.
126 //GBool inRect(double x, double y)
127 // { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
129 // Is the annotation invisible?
130 GBool
isInvisible() { return flags
& annotInvisible
; }
132 // Is the annotation hidden?
133 GBool
isHidden() { return flags
& annotHidden
; }
135 // Is the annotation read-only?
136 GBool
isReadOnly() { return flags
& annotReadOnly
; }
138 // Get the highlight mode.
139 AnnotHighlight
getHighlightMode() { return highlightMode
; }
141 // Get the annotation appearance.
142 Object
*getAppearance(XRef
*xref
, AnnotAppearance a
, Object
*obj
);
143 Object
*getAppearance(XRef
*xref
, Object
*obj
) {
144 return getAppearance(xref
, curAppearance
, obj
);
146 Dict
*getAppearanceDict() {
147 return appearance
[appearanceNormal
].isDict() ?
148 appearance
[appearanceNormal
].getDict() : NULL
;
151 // Get the annotation border.
152 Object
*getBorder(Object
*obj
) { return border
.copy(obj
); }
154 // Get the appearance state.
155 char *getAppearanceState();
157 // Get the additional action.
158 AdditionalAction
*getAdditionalAction() { return additionalAction
; }
160 // Set the additional action.
161 //void setAdditionalAction(AdditionalAction *);
164 void addAdditionalAction(ActionTrigger
, Action
*);
166 // Set the appearance state.
167 GBool
setAppearance(AnnotAppearance a
) {
168 if (curAppearance
== a
)
173 void setAppearance(AnnotAppearance a
, Object
*);
175 // Set the appearance state.
176 void setAppearanceState(char *);
178 // Change the hidden flag.
179 void hide(GBool f
) { if (f
) flags
|= annotHidden
; else flags
&= ~annotHidden
; }
181 // Check if an annotation has a specific appearance
182 GBool
hasAppearance(AnnotAppearance
);
184 // Build an appearance stream.
185 Object
*makeAppearanceStream(GString
*, Object
*);
187 // Remove the border.
188 void noBorder() { border
.free(); border
.initNull(); }
190 // Get the annotation title.
191 GString
*getTitle() { return title
; }
193 // Save the annotation state.
194 void saveState(AnnotState
*);
196 // Restore the annotation state.
197 void restoreState(AnnotState
*);
201 double x1
, y1
; // lower left corner
202 double x2
, y2
; // upper right corner
203 GfxColor
*color
; // annotation color
204 GString
*title
; // annotation title
206 AnnotHighlight highlightMode
; // highlight mode
207 Object appearance
[3]; // appearances
208 Object appearanceState
;
210 AnnotAppearance curAppearance
;// current appearance
211 AdditionalAction
*additionalAction
;
214 GBool ok
; // is link valid?
218 //------------------------------------------------------------------------
220 //------------------------------------------------------------------------
222 class RawTextAnnot
: public Annot
{
226 RawTextAnnot(XRef
*, Object
*);
229 virtual ~RawTextAnnot();
232 virtual AnnotKind
getKind() { return annotUnknown
; }
233 GString
*getContents() { return contents
; }
240 //------------------------------------------------------------------------
242 //------------------------------------------------------------------------
244 class TextAnnot
: public RawTextAnnot
{
248 TextAnnot(XRef
*, Object
*);
251 virtual AnnotKind
getKind() { return annotText
; }
255 //------------------------------------------------------------------------
257 //------------------------------------------------------------------------
259 class LineAnnot
: public RawTextAnnot
{
263 LineAnnot(XRef
*, Object
*);
266 virtual AnnotKind
getKind() { return annotLine
; }
270 //------------------------------------------------------------------------
272 //------------------------------------------------------------------------
274 class SquareAnnot
: public RawTextAnnot
{
278 SquareAnnot(XRef
*, Object
*);
281 virtual AnnotKind
getKind() { return annotSquare
; }
285 //------------------------------------------------------------------------
287 //------------------------------------------------------------------------
289 class CircleAnnot
: public RawTextAnnot
{
293 CircleAnnot(XRef
*, Object
*);
296 virtual AnnotKind
getKind() { return annotCircle
; }
300 //------------------------------------------------------------------------
302 //------------------------------------------------------------------------
304 class LinkAnnot
: public Annot
{
308 LinkAnnot(XRef
*, Object
*);
311 virtual ~LinkAnnot();
314 virtual AnnotKind
getKind() { return annotLink
; }
316 // Get the description string.
317 virtual char *getDescr() { return action
? action
->getDescr() : NULL
; }
320 Action
*getAction() { return action
; }
327 //------------------------------------------------------------------------
329 //------------------------------------------------------------------------
331 class WidgetAnnot
: public Annot
{
334 WidgetAnnot(XRef
*, Object
*, Field
*);
337 virtual ~WidgetAnnot();
340 virtual AnnotKind
getKind() { return annotWidget
; }
347 //------------------------------------------------------------------------
349 //------------------------------------------------------------------------
354 // Read the array of annotations.
355 Annots(XRef
*xref
, Object
*annots
, AcroForm
*form
);
360 // Iterate through list of links.
361 int getNumAnnots() { return numAnnots
; }
362 Annot
*getAnnot(int i
) { return annots
[i
]; }
364 // If point <x>,<y> is on an annotation, return it,
366 Annot
*find(double x
, double y
);
368 // Return true if <x>,<y> is on an annotation.
369 GBool
onAnnot(double x
, double y
);