1 /*
2  * << Haru Free PDF Library >> -- hpdf_annotation.c
3  *
4  * URL: http://libharu.org
5  *
6  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7  * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8  *
9  * Permission to use, copy, modify, distribute and sell this software
10  * and its documentation for any purpose is hereby granted without fee,
11  * provided that the above copyright notice appear in all copies and
12  * that both that copyright notice and this permission notice appear
13  * in supporting documentation.
14  * It is provided "as is" without express or implied warranty.
15  *
16  */
17 
18 #include "hpdf_conf.h"
19 #include "hpdf_utils.h"
20 #include "hpdf_info.h"
21 #include "hpdf_annotation.h"
22 #include "hpdf.h"
23 
24 static const char * const HPDF_ANNOT_TYPE_NAMES[] = {
25                                         "Text",
26                                         "Link",
27                                         "Sound",
28                                         "FreeText",
29                                         "Stamp",
30                                         "Square",
31                                         "Circle",
32                                         "StrikeOut",
33                                         "Highlight",
34                                         "Underline",
35                                         "Ink",
36                                         "FileAttachment",
37                                         "Popup",
38                                         "3D",
39                                         "Squiggly",
40 										"Line",
41 										"Projection"
42 										"Widget"
43                                         };
44 
45 static const char * const HPDF_ANNOT_ICON_NAMES_NAMES[] = {
46                                         "Comment",
47                                         "Key",
48                                         "Note",
49                                         "Help",
50                                         "NewParagraph",
51                                         "Paragraph",
52                                         "Insert"
53                                         };
54 
55 static const char * const HPDF_ANNOT_INTENT_NAMES[] = {
56                                         "FreeTextCallout",
57                                         "FreeTextTypeWriter",
58                                         "LineArrow",
59                                         "LineDimension",
60                                         "PolygonCloud",
61                                         "PolyLineDimension",
62                                         "PolygonDimension"
63                                         };
64 
65 static const char * const HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[] = {
66                                         "None",
67                                         "Square",
68                                         "Circle",
69                                         "Diamond",
70                                         "OpenArrow",
71                                         "ClosedArrow",
72                                         "Butt",
73                                         "ROpenArrow",
74                                         "RClosedArrow",
75                                         "Slash"
76                                         };
77 
78 static const char * const HPDF_LINE_ANNOT_CAP_POSITION_NAMES[] = {
79                                         "Inline",
80                                         "Top"
81                                         };
82 
83 static const char * const HPDF_STAMP_ANNOT_NAME_NAMES[] = {
84                                         "Approved",
85                                         "Experimental",
86                                         "NotApproved",
87                                         "AsIs",
88                                         "Expired",
89                                         "NotForPublicRelease",
90                                         "Confidential",
91                                         "Final",
92                                         "Sold",
93                                         "Departmental",
94                                         "ForComment",
95                                         "TopSecret",
96                                         "Draft",
97                                         "ForPublicRelease"
98                                         };
99 
100 static HPDF_BOOL
101 CheckSubType (HPDF_Annotation  annot,
102               HPDF_AnnotType  type);
103 
104 
105 /*----------------------------------------------------------------------------*/
106 /*------ HPDF_Annotation -----------------------------------------------------*/
107 
108 
109 HPDF_Annotation
HPDF_Annotation_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_AnnotType type,HPDF_Rect rect)110 HPDF_Annotation_New  (HPDF_MMgr       mmgr,
111                       HPDF_Xref       xref,
112                       HPDF_AnnotType  type,
113                       HPDF_Rect       rect)
114 {
115     HPDF_Annotation annot;
116     HPDF_Array array;
117     HPDF_STATUS ret = HPDF_OK;
118     HPDF_REAL tmp;
119 
120     HPDF_PTRACE((" HPDF_Annotation_New\n"));
121 
122     annot = HPDF_Dict_New (mmgr);
123     if (!annot)
124         return NULL;
125 
126     if (HPDF_Xref_Add (xref, annot) != HPDF_OK)
127         return NULL;
128 
129     array = HPDF_Array_New (mmgr);
130     if (!array)
131         return NULL;
132 
133     if (HPDF_Dict_Add (annot, "Rect", array) != HPDF_OK)
134         return NULL;
135 
136     if (rect.top < rect.bottom) {
137         tmp = rect.top;
138         rect.top = rect.bottom;
139         rect.bottom = tmp;
140     }
141 
142     ret += HPDF_Array_AddReal (array, rect.left);
143     ret += HPDF_Array_AddReal (array, rect.bottom);
144     ret += HPDF_Array_AddReal (array, rect.right);
145     ret += HPDF_Array_AddReal (array, rect.top);
146 
147     ret += HPDF_Dict_AddName (annot, "Type", "Annot");
148     ret += HPDF_Dict_AddName (annot, "Subtype",
149                     HPDF_ANNOT_TYPE_NAMES[(HPDF_INT)type]);
150 
151     if (ret != HPDF_OK)
152         return NULL;
153 
154     annot->header.obj_class |= HPDF_OSUBCLASS_ANNOTATION;
155 
156     return annot;
157 }
158 
159 
160 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annotation_SetBorderStyle(HPDF_Annotation annot,HPDF_BSSubtype subtype,HPDF_REAL width,HPDF_UINT16 dash_on,HPDF_UINT16 dash_off,HPDF_UINT16 dash_phase)161 HPDF_Annotation_SetBorderStyle  (HPDF_Annotation  annot,
162                                  HPDF_BSSubtype   subtype,
163                                  HPDF_REAL        width,
164                                  HPDF_UINT16      dash_on,
165                                  HPDF_UINT16      dash_off,
166                                  HPDF_UINT16      dash_phase)
167 {
168     HPDF_Dict bs;
169     HPDF_Array dash;
170     HPDF_STATUS ret;
171 
172     HPDF_PTRACE((" HPDF_Annotation_SetBoderStyle\n"));
173 
174     bs = HPDF_Dict_New (annot->mmgr);
175     if (!bs)
176         return HPDF_Error_GetCode (annot->error);
177 
178     if ((ret = HPDF_Dict_Add (annot, "BS", bs)) != HPDF_OK)
179         return ret;
180 
181     if (subtype == HPDF_BS_DASHED) {
182         dash = HPDF_Array_New (annot->mmgr);
183         if (!dash)
184             return HPDF_Error_GetCode (annot->error);
185 
186         if ((ret = HPDF_Dict_Add (bs, "D", dash)) != HPDF_OK)
187             return ret;
188 
189         ret += HPDF_Dict_AddName (bs, "Type", "Border");
190         ret += HPDF_Array_AddReal (dash, dash_on);
191         ret += HPDF_Array_AddReal (dash, dash_off);
192 
193         if (dash_phase  != 0)
194             ret += HPDF_Array_AddReal (dash, dash_off);
195     }
196 
197     switch (subtype) {
198         case HPDF_BS_SOLID:
199             ret += HPDF_Dict_AddName (bs, "S", "S");
200             break;
201         case HPDF_BS_DASHED:
202             ret += HPDF_Dict_AddName (bs, "S", "D");
203             break;
204         case HPDF_BS_BEVELED:
205             ret += HPDF_Dict_AddName (bs, "S", "B");
206             break;
207         case HPDF_BS_INSET:
208             ret += HPDF_Dict_AddName (bs, "S", "I");
209             break;
210         case HPDF_BS_UNDERLINED:
211             ret += HPDF_Dict_AddName (bs, "S", "U");
212             break;
213         default:
214             return  HPDF_SetError (annot->error, HPDF_ANNOT_INVALID_BORDER_STYLE, 0);
215     }
216 
217     if (width != HPDF_BS_DEF_WIDTH)
218         ret += HPDF_Dict_AddReal (bs, "W", width);
219 
220     if (ret != HPDF_OK)
221         return HPDF_Error_GetCode (annot->error);
222 
223     return HPDF_OK;
224 }
225 
226 HPDF_Annotation
HPDF_WidgetAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect)227 HPDF_WidgetAnnot_New (HPDF_MMgr         mmgr,
228                      HPDF_Xref         xref,
229                      HPDF_Rect         rect)
230 {
231     HPDF_Annotation annot;
232 
233     HPDF_PTRACE((" HPDF_WidgetAnnot_New\n"));
234 
235     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_WIDGET, rect);
236     if (!annot)
237         return NULL;
238 
239     return annot;
240 }
241 
242 HPDF_Annotation
HPDF_LinkAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,HPDF_Destination dst)243 HPDF_LinkAnnot_New  (HPDF_MMgr         mmgr,
244                      HPDF_Xref         xref,
245                      HPDF_Rect         rect,
246                      HPDF_Destination  dst)
247 {
248     HPDF_Annotation annot;
249 
250     HPDF_PTRACE((" HPDF_LinkAnnot_New\n"));
251 
252     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_LINK, rect);
253     if (!annot)
254         return NULL;
255 
256     if (dst)
257     {
258     if (HPDF_Dict_Add (annot, "Dest", dst) != HPDF_OK)
259         return NULL;
260     }
261 
262     return annot;
263 }
264 
265 
266 HPDF_Annotation
HPDF_URILinkAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,const char * uri)267 HPDF_URILinkAnnot_New  (HPDF_MMgr          mmgr,
268                         HPDF_Xref          xref,
269                         HPDF_Rect          rect,
270                         const char   *uri)
271 {
272     HPDF_Annotation annot;
273     HPDF_Dict action;
274     HPDF_STATUS ret;
275 
276     HPDF_PTRACE((" HPDF_URILinkAnnot_New\n"));
277 
278     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_LINK, rect);
279     if (!annot)
280         return NULL;
281 
282     /* create action dictionary */
283     action = HPDF_Dict_New (mmgr);
284     if (!action)
285         return NULL;
286 
287     ret = HPDF_Dict_Add (annot, "A", action);
288     if (ret != HPDF_OK)
289         return NULL;
290 
291     ret += HPDF_Dict_AddName (action, "Type", "Action");
292     ret += HPDF_Dict_AddName (action, "S", "URI");
293     ret += HPDF_Dict_Add (action, "URI", HPDF_String_New (mmgr, uri, NULL));
294 
295     if (ret != HPDF_OK)
296         return NULL;
297 
298     return annot;
299 }
300 
301 HPDF_EXPORT(HPDF_STATUS)
HPDF_LinkAnnot_SetJavaScript(HPDF_Annotation annot,HPDF_JavaScript javascript)302 HPDF_LinkAnnot_SetJavaScript(HPDF_Annotation annot, HPDF_JavaScript javascript)
303 {
304    HPDF_Dict action;
305    HPDF_STATUS ret;
306 
307    HPDF_PTRACE((" HPDF_LinkAnnot_SetJavaScript\n"));
308 
309     if (!CheckSubType (annot, HPDF_ANNOT_LINK))
310         return HPDF_INVALID_ANNOTATION;
311 
312     /* create action dictionary */
313    action = HPDF_Dict_New (annot->mmgr);
314    if (!action)
315         return HPDF_CheckError ( annot->error);
316 
317     ret = HPDF_Dict_Add (annot, "A", action);
318     if (ret != HPDF_OK)
319         return HPDF_CheckError (annot->error);
320 
321 	ret += HPDF_Dict_Add (action, "JS", javascript);
322     ret += HPDF_Dict_AddName (action, "S", "JavaScript");
323 
324     if (ret != HPDF_OK)
325         return HPDF_CheckError (annot->error);
326 
327     return HPDF_OK;
328 }
329 
330 HPDF_EXPORT(HPDF_STATUS)
HPDF_LinkAnnot_SetBorderStyle(HPDF_Annotation annot,HPDF_REAL width,HPDF_UINT16 dash_on,HPDF_UINT16 dash_off)331 HPDF_LinkAnnot_SetBorderStyle  (HPDF_Annotation  annot,
332                                 HPDF_REAL        width,
333                                 HPDF_UINT16      dash_on,
334                                 HPDF_UINT16      dash_off)
335 {
336     HPDF_Array array;
337     HPDF_STATUS ret;
338 
339     HPDF_PTRACE((" HPDF_LinkAnnot_SetBorderStyle\n"));
340 
341     if (!CheckSubType (annot, HPDF_ANNOT_LINK))
342         return HPDF_INVALID_ANNOTATION;
343 
344     if (width < 0)
345         return HPDF_RaiseError (annot->error, HPDF_INVALID_PARAMETER, 0);
346 
347     array = HPDF_Array_New (annot->mmgr);
348     if (!array)
349         return HPDF_CheckError (annot->error);
350 
351     if ((ret = HPDF_Dict_Add (annot, "Border", array)) != HPDF_OK)
352         return HPDF_CheckError (annot->error);
353 
354     ret += HPDF_Array_AddNumber (array, 0);
355     ret += HPDF_Array_AddNumber (array, 0);
356     ret += HPDF_Array_AddReal (array, width);
357 
358     if (ret != HPDF_OK)
359         return HPDF_CheckError (annot->error);
360 
361     if (dash_on && dash_off) {
362         HPDF_Array dash = HPDF_Array_New (annot->mmgr);
363         if (!dash)
364             return HPDF_CheckError (annot->error);
365 
366         if ((ret = HPDF_Array_Add (array, dash)) != HPDF_OK)
367             return HPDF_CheckError (annot->error);
368 
369         ret += HPDF_Array_AddNumber (dash, dash_on);
370         ret += HPDF_Array_AddNumber (dash, dash_off);
371 
372         if (ret != HPDF_OK)
373            return HPDF_CheckError (annot->error);
374     }
375 
376     return HPDF_OK;
377 }
378 
379 HPDF_EXPORT(HPDF_STATUS)
HPDF_LinkAnnot_SetHighlightMode(HPDF_Annotation annot,HPDF_AnnotHighlightMode mode)380 HPDF_LinkAnnot_SetHighlightMode  (HPDF_Annotation           annot,
381                                   HPDF_AnnotHighlightMode  mode)
382 {
383     HPDF_STATUS ret;
384 
385     HPDF_PTRACE((" HPDF_LinkAnnot_SetHighlightMode\n"));
386 
387     if (!CheckSubType (annot, HPDF_ANNOT_LINK))
388         return HPDF_INVALID_ANNOTATION;
389 
390     switch (mode) {
391         case HPDF_ANNOT_NO_HIGHTLIGHT:
392             ret = HPDF_Dict_AddName (annot, "H", "N");
393             break;
394         case HPDF_ANNOT_INVERT_BORDER:
395             ret = HPDF_Dict_AddName (annot, "H", "O");
396             break;
397         case HPDF_ANNOT_DOWN_APPEARANCE:
398             ret = HPDF_Dict_AddName (annot, "H", "P");
399             break;
400         default:  /* HPDF_ANNOT_INVERT_BOX */
401             /* default value */
402             HPDF_Dict_RemoveElement (annot, "H");
403             ret = HPDF_OK;
404     }
405 
406     if (ret != HPDF_OK)
407         return HPDF_CheckError (annot->error);
408 
409     return ret;
410 }
411 
412 
413 HPDF_Annotation
HPDF_3DAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,HPDF_BOOL tb,HPDF_BOOL np,HPDF_U3D u3d,HPDF_Image ap)414 HPDF_3DAnnot_New    (HPDF_MMgr        mmgr,
415                      HPDF_Xref        xref,
416                      HPDF_Rect        rect,
417                      HPDF_BOOL        tb,
418                      HPDF_BOOL        np,
419                      HPDF_U3D         u3d,
420                      HPDF_Image       ap)
421 {
422     HPDF_Annotation annot;
423     HPDF_Dict action, appearance, stream;
424     HPDF_STATUS ret;
425 
426     HPDF_PTRACE((" HPDF_3DAnnot_New\n"));
427 
428     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_3D, rect);
429     if (!annot) {
430         return NULL;
431     }
432 
433     // include the flags
434     HPDF_Dict_AddNumber (annot, "F", 68);
435     //Bit 3:Print If set, print the annotation when the page is printed.
436     //Bit 7:If set, do not allow the annotation to interact with the user.
437     //      The annotation may be displayed or printed (depending on the settings of the NoView and Print flags)
438     //      but should not respond to mouse clicks or change its appearance in response to mouse motions.
439 
440     HPDF_Dict_Add(annot, "Contents", HPDF_String_New (mmgr, "3D Model", NULL));
441 
442     action = HPDF_Dict_New (mmgr);
443     if (!action) {
444         return NULL;
445     }
446 
447     ret = HPDF_Dict_Add (annot, "3DA", action);
448     if (ret != HPDF_OK) {
449         return NULL;
450     }
451 
452     // enable visibility on page open
453     ret += HPDF_Dict_AddName (action, "A", "PO");
454 
455     // enable visibility of ToolBar
456     ret += HPDF_Dict_AddBoolean(action, "TB", tb);
457 
458     // enable visibility of Navigation Panel
459     ret += HPDF_Dict_AddBoolean(action, "NP", np);
460 
461     // Set behavior of Annotation on Disabling
462     ret += HPDF_Dict_AddName(action, "DIS", "U");
463 
464     // Set behavior of Annotation upon activation
465     ret += HPDF_Dict_AddName(action, "AIS", "L");
466 
467     if (ret != HPDF_OK) {
468         return NULL;
469     }
470 
471     if (HPDF_Dict_Add (annot, "3DD", u3d) != HPDF_OK) {
472         return NULL;
473     }
474 
475     appearance = HPDF_Dict_New (mmgr);
476     if (!appearance) {
477         return NULL;
478     }
479 
480     ret = HPDF_Dict_Add (annot, "AP", appearance);
481     if (ret != HPDF_OK) {
482         return NULL;
483     }
484 
485     if (ap) {
486       if (HPDF_Dict_Add (appearance, "N", ap) != HPDF_OK)
487         return NULL;
488     }
489     else{
490     stream = HPDF_Dict_New (mmgr);
491     if (!stream) {
492         return NULL;
493     }
494     ret = HPDF_Dict_Add (appearance, "N", stream);
495     }
496 
497     if (ret != HPDF_OK) {
498         return NULL;
499     }
500 
501     return annot;
502 }
503 
504 HPDF_Annotation
HPDF_MarkupAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,const char * text,HPDF_Encoder encoder,HPDF_AnnotType subtype)505 HPDF_MarkupAnnot_New (HPDF_MMgr      mmgr,
506                      HPDF_Xref       xref,
507                      HPDF_Rect       rect,
508                      const char     *text,
509                      HPDF_Encoder    encoder,
510                      HPDF_AnnotType  subtype)
511 {
512     HPDF_Annotation annot;
513     HPDF_String s;
514 
515     HPDF_PTRACE((" HPDF_MarkupAnnot_New\n"));
516 
517     annot = HPDF_Annotation_New (mmgr, xref, subtype, rect);
518     if (!annot)
519         return NULL;
520 
521     s = HPDF_String_New (mmgr, text, encoder);
522     if (!s)
523         return NULL;
524 
525     if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
526         return NULL;
527 
528     return annot;
529 }
530 
531 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetRGBColor(HPDF_Annotation annot,HPDF_RGBColor color)532 HPDF_Annot_SetRGBColor (HPDF_Annotation annot, HPDF_RGBColor color)
533 {
534     HPDF_Array cArray;
535     HPDF_STATUS ret = HPDF_OK;
536 
537     HPDF_PTRACE((" HPDF_Annot_SetRGBColor\n"));
538 
539     cArray = HPDF_Array_New ( annot->mmgr);
540     if (!cArray)
541         return HPDF_Error_GetCode ( annot->error);
542 
543     ret += HPDF_Dict_Add (annot, "C", cArray);
544     ret += HPDF_Array_AddReal (cArray, color.r);
545     ret += HPDF_Array_AddReal (cArray, color.g);
546     ret += HPDF_Array_AddReal (cArray, color.b);
547 
548     if (ret != HPDF_OK)
549        return HPDF_Error_GetCode (annot->error);
550 
551     return HPDF_OK;
552 }
553 
554 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetCMYKColor(HPDF_Annotation annot,HPDF_CMYKColor color)555 HPDF_Annot_SetCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color)
556 {
557     HPDF_Array cArray;
558     HPDF_STATUS ret = HPDF_OK;
559 
560     HPDF_PTRACE((" HPDF_Annot_SetCMYKColor\n"));
561 
562     cArray = HPDF_Array_New (annot->mmgr);
563     if (!cArray)
564         return HPDF_Error_GetCode (annot->error);
565 
566     ret += HPDF_Dict_Add (annot, "C", cArray);
567     ret += HPDF_Array_AddReal (cArray, color.c);
568     ret += HPDF_Array_AddReal (cArray, color.m);
569     ret += HPDF_Array_AddReal (cArray, color.y);
570     ret += HPDF_Array_AddReal (cArray, color.k);
571 
572     if (ret != HPDF_OK)
573         return HPDF_Error_GetCode (annot->error);
574 
575     return HPDF_OK;
576 }
577 
578 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetGrayColor(HPDF_Annotation annot,HPDF_REAL color)579 HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color)
580 {
581     HPDF_Array cArray;
582     HPDF_STATUS ret = HPDF_OK;
583 
584     HPDF_PTRACE((" HPDF_Annot_SetGrayColor\n"));
585 
586     cArray = HPDF_Array_New (annot->mmgr);
587     if (!cArray)
588         return HPDF_Error_GetCode ( annot->error);
589 
590     ret += HPDF_Dict_Add (annot, "C", cArray);
591     ret += HPDF_Array_AddReal ( cArray, color);
592 
593     if (ret != HPDF_OK)
594         return HPDF_Error_GetCode ( annot->error);
595 
596     return HPDF_OK;
597 }
598 
599 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetNoColor(HPDF_Annotation annot)600 HPDF_Annot_SetNoColor (HPDF_Annotation annot)
601 {
602     HPDF_Array cArray;
603     HPDF_STATUS ret = HPDF_OK;
604 
605     HPDF_PTRACE((" HPDF_Annot_SetNoColor\n"));
606 
607     cArray = HPDF_Array_New (annot->mmgr);
608     if (!cArray)
609         return HPDF_Error_GetCode ( annot->error);
610 
611     ret = HPDF_Dict_Add (annot, "C", cArray);
612 
613     return ret;
614 }
615 
616 HPDF_EXPORT(HPDF_STATUS)
HPDF_TextAnnot_SetIcon(HPDF_Annotation annot,HPDF_AnnotIcon icon)617 HPDF_TextAnnot_SetIcon  (HPDF_Annotation  annot,
618                          HPDF_AnnotIcon   icon)
619 {
620     HPDF_PTRACE((" HPDF_TextAnnot_SetIcon\n"));
621 
622     if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES))
623         return HPDF_INVALID_ANNOTATION;
624 
625     if (icon >= HPDF_ANNOT_ICON_EOF)
626         return HPDF_RaiseError (annot->error, HPDF_ANNOT_INVALID_ICON,
627                 (HPDF_STATUS)icon);
628 
629     if (HPDF_Dict_AddName (annot, "Name",
630         HPDF_ANNOT_ICON_NAMES_NAMES[(HPDF_INT)icon]) != HPDF_OK)
631         return HPDF_CheckError (annot->error);
632 
633     return HPDF_OK;
634 }
635 
636 
637 HPDF_EXPORT(HPDF_STATUS)
HPDF_TextAnnot_SetOpened(HPDF_Annotation annot,HPDF_BOOL opened)638 HPDF_TextAnnot_SetOpened  (HPDF_Annotation  annot,
639                            HPDF_BOOL        opened)
640 {
641     HPDF_Boolean b;
642 
643     HPDF_PTRACE((" HPDF_TextAnnot_SetOpend\n"));
644 
645     if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES))
646         return HPDF_INVALID_ANNOTATION;
647 
648     b = HPDF_Boolean_New (annot->mmgr, opened);
649     if (!b)
650         return HPDF_CheckError (annot->error);
651 
652     return  HPDF_Dict_Add (annot, "Open", b);
653 }
654 
655 HPDF_EXPORT(HPDF_STATUS)
HPDF_PopupAnnot_SetOpened(HPDF_Annotation annot,HPDF_BOOL opened)656 HPDF_PopupAnnot_SetOpened (HPDF_Annotation  annot,
657                            HPDF_BOOL        opened)
658 {
659     HPDF_Boolean b;
660 
661     HPDF_PTRACE((" HPDF_TextAnnot_SetOpend\n"));
662 
663     if (!CheckSubType (annot, HPDF_ANNOT_POPUP))
664         return HPDF_INVALID_ANNOTATION;
665 
666     b = HPDF_Boolean_New (annot->mmgr, opened);
667     if (!b)
668         return HPDF_CheckError (annot->error);
669 
670     return  HPDF_Dict_Add (annot, "Open", b);
671 }
672 
673 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTitle(HPDF_Annotation annot,const char * name)674 HPDF_MarkupAnnot_SetTitle (HPDF_Annotation   annot, const char* name)
675 {
676     HPDF_PTRACE((" HPDF_MarkupAnnot_SetTitle\n"));
677 
678     return HPDF_Dict_Add( annot, "T", HPDF_String_New( annot->mmgr, name, NULL));
679 }
680 
681 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetSubject(HPDF_Annotation annot,const char * name)682 HPDF_MarkupAnnot_SetSubject (HPDF_Annotation   annot, const char* name)
683 {
684     HPDF_PTRACE((" HPDF_MarkupAnnot_SetSubject\n"));
685 
686     return HPDF_Dict_Add( annot, "Subj", HPDF_String_New( annot->mmgr, name, NULL));
687 }
688 
689 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCreationDate(HPDF_Annotation annot,HPDF_Date value)690 HPDF_MarkupAnnot_SetCreationDate (HPDF_Annotation   annot, HPDF_Date value)
691 {
692     HPDF_PTRACE((" HPDF_MarkupAnnot_SetCreationDate\n"));
693 
694     return HPDF_Info_SetInfoDateAttr( annot, HPDF_INFO_CREATION_DATE, value);
695 }
696 
697 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTransparency(HPDF_Annotation annot,HPDF_REAL value)698 HPDF_MarkupAnnot_SetTransparency (HPDF_Annotation   annot, HPDF_REAL value)
699 {
700     HPDF_PTRACE((" HPDF_MarkupAnnot_SetTransparency\n"));
701 
702     return HPDF_Dict_AddReal( annot, "CA", value);
703 }
704 
705 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetIntent(HPDF_Annotation annot,HPDF_AnnotIntent intent)706 HPDF_MarkupAnnot_SetIntent  (HPDF_Annotation  annot,
707                              HPDF_AnnotIntent  intent)
708 {
709     HPDF_PTRACE((" HPDF_MarkupAnnot_SetIntent\n"));
710 
711     if (HPDF_Dict_AddName (annot, "IT",
712         HPDF_ANNOT_INTENT_NAMES[(HPDF_INT)intent]) != HPDF_OK)
713         return HPDF_CheckError (annot->error);
714 
715     return HPDF_OK;
716 }
717 
718 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetPopup(HPDF_Annotation annot,HPDF_Annotation popup)719 HPDF_MarkupAnnot_SetPopup (HPDF_Annotation  annot,
720                            HPDF_Annotation  popup)
721 {
722     HPDF_PTRACE((" HPDF_MarkupAnnot_SetPopup\n"));
723 
724     return HPDF_Dict_Add( annot, "Popup", popup);
725 }
726 
727 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorRGBColor(HPDF_Annotation annot,HPDF_RGBColor color)728 HPDF_MarkupAnnot_SetInteriorRGBColor (HPDF_Annotation  annot, HPDF_RGBColor color)/* IC with RGB entry */
729 {
730     HPDF_Array cArray;
731     HPDF_STATUS ret = HPDF_OK;
732 
733     HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorRGBColor\n"));
734 
735     cArray = HPDF_Array_New ( annot->mmgr);
736     if (!cArray)
737         return HPDF_Error_GetCode ( annot->error);
738 
739     ret += HPDF_Dict_Add (annot, "IC", cArray);
740     ret += HPDF_Array_AddReal (cArray, color.r);
741     ret += HPDF_Array_AddReal (cArray, color.g);
742     ret += HPDF_Array_AddReal (cArray, color.b);
743 
744     if (ret != HPDF_OK)
745         return HPDF_Error_GetCode (annot->error);
746 
747     return HPDF_OK;
748 }
749 
750 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorCMYKColor(HPDF_Annotation annot,HPDF_CMYKColor color)751 HPDF_MarkupAnnot_SetInteriorCMYKColor (HPDF_Annotation  annot, HPDF_CMYKColor color)/* IC with CMYK entry */
752 {
753     HPDF_Array cArray;
754     HPDF_STATUS ret = HPDF_OK;
755 
756     HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorCMYKColor\n"));
757 
758     cArray = HPDF_Array_New ( annot->mmgr);
759     if (!cArray)
760         return HPDF_Error_GetCode ( annot->error);
761 
762     ret += HPDF_Dict_Add (annot, "IC", cArray);
763     ret += HPDF_Array_AddReal (cArray, color.c);
764     ret += HPDF_Array_AddReal (cArray, color.m);
765     ret += HPDF_Array_AddReal (cArray, color.y);
766     ret += HPDF_Array_AddReal (cArray, color.k);
767 
768     if (ret != HPDF_OK)
769        return HPDF_Error_GetCode (annot->error);
770 
771     return HPDF_OK;
772 }
773 
774 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorGrayColor(HPDF_Annotation annot,HPDF_REAL color)775 HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation  annot, HPDF_REAL color)/* IC with Gray entry */
776 {
777     HPDF_Array cArray;
778     HPDF_STATUS ret = HPDF_OK;
779 
780     HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorGrayColor\n"));
781 
782     cArray = HPDF_Array_New ( annot->mmgr);
783     if (!cArray)
784         return HPDF_Error_GetCode ( annot->error);
785 
786     ret += HPDF_Dict_Add (annot, "IC", cArray);
787     ret += HPDF_Array_AddReal (cArray, color);
788 
789     if (ret != HPDF_OK)
790         return HPDF_Error_GetCode ( annot->error);
791 
792     return HPDF_OK;
793 }
794 
795 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorTransparent(HPDF_Annotation annot)796 HPDF_MarkupAnnot_SetInteriorTransparent (HPDF_Annotation  annot) /* IC with No Color entry */
797 {
798     HPDF_Array cArray;
799     HPDF_STATUS ret = HPDF_OK;
800 
801     HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorTransparent\n"));
802 
803     cArray = HPDF_Array_New ( annot->mmgr);
804     if (!cArray)
805         return HPDF_Error_GetCode ( annot->error);
806 
807     ret = HPDF_Dict_Add (annot, "IC", cArray);
808 
809     return ret;
810 }
811 
812 HPDF_BOOL
HPDF_Annotation_Validate(HPDF_Annotation annot)813 HPDF_Annotation_Validate (HPDF_Annotation  annot)
814 {
815     HPDF_PTRACE((" HPDF_Annotation_Validate\n"));
816 
817     if (!annot)
818         return HPDF_FALSE;
819 
820     if (annot->header.obj_class !=
821                 (HPDF_OSUBCLASS_ANNOTATION | HPDF_OCLASS_DICT))
822         return HPDF_FALSE;
823 
824     return HPDF_TRUE;
825 }
826 
827 static HPDF_BOOL
CheckSubType(HPDF_Annotation annot,HPDF_AnnotType type)828 CheckSubType (HPDF_Annotation  annot,
829               HPDF_AnnotType  type)
830 {
831     HPDF_Name subtype;
832 
833     HPDF_PTRACE((" HPDF_Annotation_CheckSubType\n"));
834 
835     if (!HPDF_Annotation_Validate (annot))
836         return HPDF_FALSE;
837 
838     subtype = HPDF_Dict_GetItem (annot, "Subtype", HPDF_OCLASS_NAME);
839 
840     if (!subtype || HPDF_StrCmp (subtype->value,
841                 HPDF_ANNOT_TYPE_NAMES[(HPDF_INT)type]) != 0) {
842         HPDF_RaiseError (annot->error, HPDF_INVALID_ANNOTATION, 0);
843         return HPDF_FALSE;
844     }
845 
846     return HPDF_TRUE;
847 }
848 
849 HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_Set3DView(HPDF_MMgr mmgr,HPDF_Annotation annot,HPDF_Annotation annot3d,HPDF_Dict view3d)850 HPDF_Annot_Set3DView ( HPDF_MMgr mmgr,
851                      HPDF_Annotation    annot,
852                      HPDF_Annotation    annot3d,
853                      HPDF_Dict            view3d)
854 {
855     HPDF_Proxy proxyView3d;
856     HPDF_Dict exData = HPDF_Dict_New( mmgr);
857     HPDF_STATUS retS = HPDF_OK;
858 
859     retS += HPDF_Dict_AddName( exData, "Type", "ExData");
860     retS += HPDF_Dict_AddName( exData, "Subtype", "Markup3D");
861     retS += HPDF_Dict_Add( exData, "3DA", annot3d);
862 
863     proxyView3d = HPDF_Proxy_New( mmgr, view3d);
864 
865     retS += HPDF_Dict_Add( exData, "3DV", proxyView3d);
866     retS += HPDF_Dict_Add( annot, "ExData", exData);
867     return retS;
868 }
869 
870 
871 HPDF_Annotation
HPDF_PopupAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,HPDF_Annotation parent)872 HPDF_PopupAnnot_New (HPDF_MMgr         mmgr,
873                      HPDF_Xref         xref,
874                      HPDF_Rect         rect,
875                      HPDF_Annotation   parent)
876 {
877     HPDF_Annotation annot;
878 
879     HPDF_PTRACE((" HPDF_PopupAnnot_New\n"));
880 
881     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_POPUP, rect);
882     if (!annot)
883         return NULL;
884 
885     if (HPDF_Dict_Add (annot, "Parent", parent) != HPDF_OK)
886         return NULL;
887 
888     return annot;
889 }
890 
891 HPDF_Annotation
HPDF_StampAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,HPDF_StampAnnotName name,const char * text,HPDF_Encoder encoder)892 HPDF_StampAnnot_New (HPDF_MMgr         mmgr,
893                      HPDF_Xref         xref,
894                      HPDF_Rect         rect,
895                      HPDF_StampAnnotName name,
896                      const char*       text,
897                      HPDF_Encoder       encoder)
898 {
899     HPDF_Annotation annot;
900     HPDF_String s;
901     HPDF_PTRACE((" HPDF_StampAnnot_New\n"));
902 
903     annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_STAMP, rect);
904     if (!annot)
905         return NULL;
906 
907     if (HPDF_Dict_AddName ( annot, "Name", HPDF_STAMP_ANNOT_NAME_NAMES[name]) != HPDF_OK)
908         return NULL;
909 
910     s = HPDF_String_New (mmgr, text, encoder);
911     if (!s)
912         return NULL;
913 
914     if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
915         return NULL;
916 
917     return annot;
918 }
919 
920 HPDF_Annotation
HPDF_ProjectionAnnot_New(HPDF_MMgr mmgr,HPDF_Xref xref,HPDF_Rect rect,const char * text,HPDF_Encoder encoder)921 HPDF_ProjectionAnnot_New(HPDF_MMgr         mmgr,
922 						 HPDF_Xref         xref,
923 						 HPDF_Rect         rect,
924 						 const char*       text,
925 						 HPDF_Encoder       encoder)
926 {
927 	HPDF_Annotation annot;
928 	HPDF_String s;
929 	HPDF_PTRACE((" HPDF_StampAnnot_New\n"));
930 
931 	annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_PROJECTION, rect);
932 	if (!annot)
933 		return NULL;
934 
935 	s = HPDF_String_New (mmgr, text, encoder);
936 	if (!s)
937 		return NULL;
938 
939 	if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
940 		return NULL;
941 
942 	return annot;
943 }
944 
945 
946 HPDF_EXPORT(HPDF_STATUS)
HPDF_TextMarkupAnnot_SetQuadPoints(HPDF_Annotation annot,HPDF_Point lb,HPDF_Point rb,HPDF_Point lt,HPDF_Point rt)947 HPDF_TextMarkupAnnot_SetQuadPoints ( HPDF_Annotation annot, HPDF_Point lb, HPDF_Point rb, HPDF_Point lt, HPDF_Point rt) /* l-left, r-right, b-bottom, t-top positions */
948 {
949     HPDF_Array quadPoints;
950     HPDF_STATUS ret = HPDF_OK;
951 
952     HPDF_PTRACE((" HPDF_TextMarkupAnnot_SetQuadPoints\n"));
953 
954     quadPoints = HPDF_Array_New ( annot->mmgr);
955     if ( !quadPoints)
956         return HPDF_Error_GetCode ( annot->error);
957 
958     if ((ret = HPDF_Dict_Add ( annot, "QuadPoints", quadPoints)) != HPDF_OK)
959         return ret;
960 
961     ret += HPDF_Array_AddReal (quadPoints, lb.x);
962     ret += HPDF_Array_AddReal (quadPoints, lb.y);
963     ret += HPDF_Array_AddReal (quadPoints, rb.x);
964     ret += HPDF_Array_AddReal (quadPoints, rb.y);
965     ret += HPDF_Array_AddReal (quadPoints, lt.x);
966     ret += HPDF_Array_AddReal (quadPoints, lt.y);
967     ret += HPDF_Array_AddReal (quadPoints, rt.x);
968     ret += HPDF_Array_AddReal (quadPoints, rt.y);
969 
970     if (ret != HPDF_OK)
971        return HPDF_Error_GetCode (quadPoints->error);
972 
973     return HPDF_OK;
974 }
975 
976 HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetLineEndingStyle(HPDF_Annotation annot,HPDF_LineAnnotEndingStyle startStyle,HPDF_LineAnnotEndingStyle endStyle)977 HPDF_FreeTextAnnot_SetLineEndingStyle (HPDF_Annotation annot, HPDF_LineAnnotEndingStyle startStyle, HPDF_LineAnnotEndingStyle endStyle)
978 {
979     HPDF_Array lineEndStyles;
980     HPDF_STATUS ret = HPDF_OK;
981 
982     HPDF_PTRACE((" HPDF_FreeTextAnnot_SetLineEndingStyle\n"));
983 
984     lineEndStyles = HPDF_Array_New ( annot->mmgr);
985     if ( !lineEndStyles)
986         return HPDF_Error_GetCode ( annot->error);
987 
988     if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK)
989         return ret;
990 
991     ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]);
992     ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]);
993 
994     if (ret != HPDF_OK)
995        return HPDF_Error_GetCode (lineEndStyles->error);
996 
997     return HPDF_OK;
998 }
999 
1000 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetRectDiff(HPDF_Annotation annot,HPDF_Rect rect)1001 HPDF_MarkupAnnot_SetRectDiff (HPDF_Annotation  annot, HPDF_Rect  rect) /* RD entry : this is the difference between Rect and the text annotation rectangle */
1002 {
1003     HPDF_Array array;
1004     HPDF_STATUS ret = HPDF_OK;
1005     HPDF_REAL tmp;
1006 
1007     HPDF_PTRACE((" HPDF_MarkupAnnot_SetRectDiff\n"));
1008 
1009     array = HPDF_Array_New ( annot->mmgr);
1010     if ( !array)
1011         return HPDF_Error_GetCode ( annot->error);
1012 
1013     if ((ret = HPDF_Dict_Add ( annot, "RD", array)) != HPDF_OK)
1014         return ret;
1015 
1016     if (rect.top < rect.bottom) {
1017         tmp = rect.top;
1018         rect.top = rect.bottom;
1019         rect.bottom = tmp;
1020     }
1021 
1022     ret += HPDF_Array_AddReal (array, rect.left);
1023     ret += HPDF_Array_AddReal (array, rect.bottom);
1024     ret += HPDF_Array_AddReal (array, rect.right);
1025     ret += HPDF_Array_AddReal (array, rect.top);
1026 
1027     if (ret != HPDF_OK)
1028        return HPDF_Error_GetCode (array->error);
1029 
1030     return HPDF_OK;
1031 }
1032 
1033 HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetDefaultStyle(HPDF_Annotation annot,const char * style)1034 HPDF_FreeTextAnnot_SetDefaultStyle (HPDF_Annotation  annot,
1035                                     const char* style)
1036 {
1037     HPDF_String s;
1038     HPDF_STATUS ret = HPDF_OK;
1039 
1040     HPDF_PTRACE((" HPDF_FreeTextAnnot_SetDefaultStyle\n"));
1041 
1042     s = HPDF_String_New ( annot->mmgr, style, NULL);
1043     if ( !s)
1044         return HPDF_Error_GetCode ( annot->error);
1045 
1046     ret = HPDF_Dict_Add ( annot, "DS", s);
1047 
1048     return ret;
1049 }
1050 
1051 HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set3PointCalloutLine(HPDF_Annotation annot,HPDF_Point startPoint,HPDF_Point kneePoint,HPDF_Point endPoint)1052 HPDF_FreeTextAnnot_Set3PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point kneePoint, HPDF_Point endPoint) /* Callout line will be in default user space */
1053 {
1054     HPDF_Array clPoints;
1055     HPDF_STATUS ret = HPDF_OK;
1056 
1057     HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n"));
1058 
1059     clPoints = HPDF_Array_New ( annot->mmgr);
1060     if ( !clPoints)
1061         return HPDF_Error_GetCode ( annot->error);
1062 
1063     if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK)
1064         return ret;
1065 
1066     ret += HPDF_Array_AddReal (clPoints, startPoint.x);
1067     ret += HPDF_Array_AddReal (clPoints, startPoint.y);
1068     ret += HPDF_Array_AddReal (clPoints, kneePoint.x);
1069     ret += HPDF_Array_AddReal (clPoints, kneePoint.y);
1070     ret += HPDF_Array_AddReal (clPoints, endPoint.x);
1071     ret += HPDF_Array_AddReal (clPoints, endPoint.y);
1072 
1073     if (ret != HPDF_OK)
1074        return HPDF_Error_GetCode (clPoints->error);
1075 
1076     return HPDF_OK;
1077 }
1078 
1079 HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set2PointCalloutLine(HPDF_Annotation annot,HPDF_Point startPoint,HPDF_Point endPoint)1080 HPDF_FreeTextAnnot_Set2PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point endPoint) /* Callout line will be in default user space */
1081 {
1082     HPDF_Array clPoints;
1083     HPDF_STATUS ret = HPDF_OK;
1084 
1085     HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n"));
1086 
1087     clPoints = HPDF_Array_New ( annot->mmgr);
1088     if ( !clPoints)
1089         return HPDF_Error_GetCode ( annot->error);
1090 
1091     if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK)
1092         return ret;
1093 
1094     ret += HPDF_Array_AddReal (clPoints, startPoint.x);
1095     ret += HPDF_Array_AddReal (clPoints, startPoint.y);
1096     ret += HPDF_Array_AddReal (clPoints, endPoint.x);
1097     ret += HPDF_Array_AddReal (clPoints, endPoint.y);
1098 
1099     if (ret != HPDF_OK)
1100        return HPDF_Error_GetCode (clPoints->error);
1101 
1102     return HPDF_OK;
1103 }
1104 
1105 HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCloudEffect(HPDF_Annotation annot,HPDF_INT cloudIntensity)1106 HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation  annot, HPDF_INT cloudIntensity) /* BE entry */
1107 {
1108     HPDF_Dict borderEffect;
1109     HPDF_STATUS ret = HPDF_OK;
1110 
1111     HPDF_PTRACE((" HPDF_MarkupAnnot_SetCloudEffect\n"));
1112 
1113     borderEffect = HPDF_Dict_New ( annot->mmgr);
1114     if (!borderEffect)
1115         return HPDF_Error_GetCode ( annot->error);
1116 
1117     ret += HPDF_Dict_Add ( annot, "BE", borderEffect);
1118     ret += HPDF_Dict_AddName ( borderEffect, "S", "C");
1119     ret += HPDF_Dict_AddNumber ( borderEffect, "I", cloudIntensity);
1120 
1121     if (ret != HPDF_OK)
1122         return HPDF_Error_GetCode (annot->error);
1123 
1124     return HPDF_OK;
1125 }
1126 
1127 HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetPosition(HPDF_Annotation annot,HPDF_Point startPoint,HPDF_LineAnnotEndingStyle startStyle,HPDF_Point endPoint,HPDF_LineAnnotEndingStyle endStyle)1128 HPDF_LineAnnot_SetPosition (HPDF_Annotation annot,
1129                             HPDF_Point startPoint, HPDF_LineAnnotEndingStyle startStyle,
1130                             HPDF_Point endPoint, HPDF_LineAnnotEndingStyle endStyle)
1131 {
1132     HPDF_Array lineEndPoints;
1133     HPDF_Array lineEndStyles;
1134     HPDF_STATUS ret = HPDF_OK;
1135 
1136     HPDF_PTRACE((" HPDF_LineAnnot_SetPosition\n"));
1137 
1138     lineEndPoints = HPDF_Array_New ( annot->mmgr);
1139     if ( !lineEndPoints)
1140         return HPDF_Error_GetCode ( annot->error);
1141 
1142     if ((ret = HPDF_Dict_Add ( annot, "L", lineEndPoints)) != HPDF_OK)
1143         return ret;
1144 
1145     ret += HPDF_Array_AddReal (lineEndPoints, startPoint.x);
1146     ret += HPDF_Array_AddReal (lineEndPoints, startPoint.y);
1147     ret += HPDF_Array_AddReal (lineEndPoints, endPoint.x);
1148     ret += HPDF_Array_AddReal (lineEndPoints, endPoint.y);
1149 
1150     if (ret != HPDF_OK)
1151        return HPDF_Error_GetCode ( lineEndPoints->error);
1152 
1153     lineEndStyles = HPDF_Array_New ( annot->mmgr);
1154     if ( !lineEndStyles)
1155         return HPDF_Error_GetCode ( annot->error);
1156 
1157     if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK)
1158         return ret;
1159 
1160     ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]);
1161     ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]);
1162 
1163     if (ret != HPDF_OK)
1164        return HPDF_Error_GetCode ( lineEndStyles->error);
1165 
1166     return HPDF_OK;
1167 }
1168 
1169 HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetLeader(HPDF_Annotation annot,HPDF_INT leaderLen,HPDF_INT leaderExtLen,HPDF_INT leaderOffsetLen)1170 HPDF_LineAnnot_SetLeader (HPDF_Annotation annot, HPDF_INT leaderLen, HPDF_INT leaderExtLen, HPDF_INT leaderOffsetLen)
1171 {
1172     HPDF_STATUS ret = HPDF_OK;
1173 
1174     HPDF_PTRACE((" HPDF_LineAnnot_SetLeader\n"));
1175 
1176     ret += HPDF_Dict_AddNumber ( annot, "LL", leaderLen);
1177     ret += HPDF_Dict_AddNumber ( annot, "LLE", leaderExtLen);
1178     ret += HPDF_Dict_AddNumber ( annot, "LLO", leaderOffsetLen);
1179 
1180     if (ret != HPDF_OK)
1181        return HPDF_Error_GetCode ( annot->error);
1182 
1183     return HPDF_OK;
1184 }
1185 
1186 HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetCaption(HPDF_Annotation annot,HPDF_BOOL showCaption,HPDF_LineAnnotCapPosition position,HPDF_INT horzOffset,HPDF_INT vertOffset)1187 HPDF_LineAnnot_SetCaption (HPDF_Annotation annot, HPDF_BOOL showCaption, HPDF_LineAnnotCapPosition position, HPDF_INT horzOffset, HPDF_INT vertOffset)
1188 {
1189     HPDF_STATUS ret = HPDF_OK;
1190     HPDF_Array capOffset;
1191     HPDF_PTRACE((" HPDF_LineAnnot_SetCaption\n"));
1192 
1193     ret += HPDF_Dict_AddBoolean ( annot, "Cap", showCaption);
1194     ret += HPDF_Dict_AddName( annot, "CP", HPDF_LINE_ANNOT_CAP_POSITION_NAMES[(HPDF_INT)position]);
1195 
1196     if (ret != HPDF_OK)
1197        return HPDF_Error_GetCode ( annot->error);
1198 
1199     capOffset = HPDF_Array_New ( annot->mmgr);
1200     if ( !capOffset)
1201         return HPDF_Error_GetCode ( annot->error);
1202 
1203     if ((ret = HPDF_Dict_Add ( annot, "CO", capOffset)) != HPDF_OK)
1204         return ret;
1205 
1206     ret += HPDF_Array_AddNumber (capOffset, horzOffset);
1207     ret += HPDF_Array_AddNumber (capOffset, vertOffset);
1208 
1209     if (ret != HPDF_OK)
1210        return HPDF_Error_GetCode (capOffset->error);
1211 
1212     return HPDF_OK;
1213 }
1214 
1215 
1216 
1217 HPDF_EXPORT(HPDF_STATUS)
HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot,HPDF_ExData exdata)1218 HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot, HPDF_ExData exdata)
1219 {
1220 	HPDF_STATUS ret = HPDF_OK;
1221 
1222 	ret = HPDF_Dict_Add(annot, "ExData", exdata);
1223 
1224 	return ret;
1225 }
1226