File Coverage

xs/document.xs
Criterion Covered Total %
statement 210 269 78.0
branch 145 236 61.4
condition n/a
subroutine n/a
pod n/a
total 355 505 70.3


line stmt bran cond sub pod time code
1             MODULE = PDF::Make PACKAGE = PDF::Make::Document
2             PROTOTYPES: ENABLE
3              
4             pdfmake_doc_t *
5             new(class)
6             char *class
7             CODE:
8 335           RETVAL = pdfmake_doc_new();
9 335 50         if (!RETVAL) {
10 0           croak("PDF::Make::Document::new: failed to create document");
11             }
12             OUTPUT:
13             RETVAL
14              
15             UV
16             add(self, obj_sv)
17             pdfmake_doc_t *self
18             SV *obj_sv
19             CODE:
20             /* For now, accept simple scalars. Full object support later. */
21             pdfmake_obj_t obj;
22 22           pdfmake_arena_t *arena = pdfmake_doc_arena(self);
23              
24 22 50         if (!SvOK(obj_sv)) {
25 0           obj = pdfmake_null();
26             }
27 22 100         else if (SvIOK(obj_sv)) {
28 8           obj = pdfmake_int(SvIV(obj_sv));
29             }
30 14 100         else if (SvNOK(obj_sv)) {
31 1           obj = pdfmake_real(SvNV(obj_sv));
32             }
33 13 50         else if (SvPOK(obj_sv)) {
34             STRLEN len;
35 13           const char *str = SvPV(obj_sv, len);
36 13           obj = pdfmake_str(arena, str, len);
37             }
38             else {
39 0           croak("PDF::Make::Document::add: unsupported object type");
40             }
41              
42 22           RETVAL = pdfmake_doc_add(self, obj);
43 22 50         if (RETVAL == 0) {
44 0           croak("PDF::Make::Document::add: failed to add object");
45             }
46             OUTPUT:
47             RETVAL
48              
49             void
50             set_root(self, num, gen = 0)
51             pdfmake_doc_t *self
52             UV num
53             UV gen
54             CODE:
55 12           pdfmake_doc_set_root(self, (uint32_t)num, (uint16_t)gen);
56              
57             void
58             set_info(self, num, gen = 0)
59             pdfmake_doc_t *self
60             UV num
61             UV gen
62             CODE:
63 1           pdfmake_doc_set_info(self, (uint32_t)num, (uint16_t)gen);
64              
65             void
66             set_encryption(self, algorithm, user_passwd, owner_passwd, permissions)
67             pdfmake_doc_t *self
68             const char *algorithm
69             const char *user_passwd
70             SV *owner_passwd
71             IV permissions
72             PREINIT:
73             pdfmake_crypt_algo_t algo;
74 5           const char *owner = NULL;
75             CODE:
76 5 50         if (strEQ(algorithm, "RC4-40") || strEQ(algorithm, "rc4-40")) {
    50          
77 0           algo = PDFMAKE_CRYPT_RC4_40;
78 5 100         } else if (strEQ(algorithm, "RC4-128") || strEQ(algorithm, "rc4-128")) {
    50          
79 1           algo = PDFMAKE_CRYPT_RC4_128;
80 4 100         } else if (strEQ(algorithm, "AES-128") || strEQ(algorithm, "aes-128")) {
    50          
81 1           algo = PDFMAKE_CRYPT_AES_128;
82 3 50         } else if (strEQ(algorithm, "AES-256") || strEQ(algorithm, "aes-256")) {
    0          
83 3           algo = PDFMAKE_CRYPT_AES_256;
84             } else {
85 0           croak("PDF::Make::Document::set_encryption: unknown algorithm '%s'", algorithm);
86             }
87 5 50         if (SvOK(owner_passwd)) owner = SvPV_nolen(owner_passwd);
88 5 50         if (pdfmake_doc_set_encryption(self, algo, user_passwd, owner,
89             (int32_t)permissions) != PDFMAKE_OK) {
90 0           croak("PDF::Make::Document::set_encryption: failed");
91             }
92              
93             SV *
94             to_bytes(self)
95             pdfmake_doc_t *self
96             CODE:
97             pdfmake_buf_t buf;
98 56 50         if (pdfmake_buf_init(&buf) != PDFMAKE_OK) {
99 0           croak("PDF::Make::Document::to_bytes: buffer init failed");
100             }
101 56 50         if (pdfmake_doc_write(self, &buf) != PDFMAKE_OK) {
102 0           pdfmake_buf_free(&buf);
103 0           croak("PDF::Make::Document::to_bytes: write failed");
104             }
105 56           RETVAL = newSVpvn((char *)buf.data, buf.len);
106 56           pdfmake_buf_free(&buf);
107             OUTPUT:
108             RETVAL
109              
110             void
111             to_file(self, path)
112             pdfmake_doc_t *self
113             const char *path
114             CODE:
115             pdfmake_buf_t buf;
116 118 50         if (pdfmake_buf_init(&buf) != PDFMAKE_OK) {
117 0           croak("PDF::Make::Document::to_file: buffer init failed");
118             }
119 118 50         if (pdfmake_doc_write(self, &buf) != PDFMAKE_OK) {
120 0           pdfmake_buf_free(&buf);
121 0           croak("PDF::Make::Document::to_file: write failed");
122             }
123              
124 118           FILE *fp = fopen(path, "wb");
125 118 100         if (!fp) {
126 1           pdfmake_buf_free(&buf);
127 1           croak("PDF::Make::Document::to_file: cannot open %s", path);
128             }
129 117           size_t expected = buf.len;
130 117           size_t written = fwrite(buf.data, 1, buf.len, fp);
131 117           fclose(fp);
132 117           pdfmake_buf_free(&buf);
133              
134 117 50         if (written != expected) {
135 0           croak("PDF::Make::Document::to_file: write incomplete");
136             }
137              
138             SV *
139             title(self, ...)
140             pdfmake_doc_t *self
141             CODE:
142 116 100         if (items > 1) {
143 67           const char *val = SvPV_nolen(ST(1));
144 67 50         if (pdfmake_meta_set_title(self, val) != PDFMAKE_OK) {
145 0           croak("PDF::Make::Document::title: failed to set title");
146             }
147 67           RETVAL = ST(1);
148 67           SvREFCNT_inc(RETVAL);
149             } else {
150 49           const char *val = pdfmake_meta_get_title(self);
151 49 100         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
152             }
153             OUTPUT:
154             RETVAL
155              
156             SV *
157             author(self, ...)
158             pdfmake_doc_t *self
159             CODE:
160 61 100         if (items > 1) {
161 57           const char *val = SvPV_nolen(ST(1));
162 57 50         if (pdfmake_meta_set_author(self, val) != PDFMAKE_OK) {
163 0           croak("PDF::Make::Document::author: failed to set author");
164             }
165 57           RETVAL = ST(1);
166 57           SvREFCNT_inc(RETVAL);
167             } else {
168 4           const char *val = pdfmake_meta_get_author(self);
169 4 100         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
170             }
171             OUTPUT:
172             RETVAL
173              
174             SV *
175             subject(self, ...)
176             pdfmake_doc_t *self
177             CODE:
178 50 100         if (items > 1) {
179 47           const char *val = SvPV_nolen(ST(1));
180 47 50         if (pdfmake_meta_set_subject(self, val) != PDFMAKE_OK) {
181 0           croak("PDF::Make::Document::subject: failed to set subject");
182             }
183 47           RETVAL = ST(1);
184 47           SvREFCNT_inc(RETVAL);
185             } else {
186 3           const char *val = pdfmake_meta_get_subject(self);
187 3 100         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
188             }
189             OUTPUT:
190             RETVAL
191              
192             SV *
193             keywords(self, ...)
194             pdfmake_doc_t *self
195             CODE:
196 7 100         if (items > 1) {
197 4           const char *val = SvPV_nolen(ST(1));
198 4 50         if (pdfmake_meta_set_keywords(self, val) != PDFMAKE_OK) {
199 0           croak("PDF::Make::Document::keywords: failed to set keywords");
200             }
201 4           RETVAL = ST(1);
202 4           SvREFCNT_inc(RETVAL);
203             } else {
204 3           const char *val = pdfmake_meta_get_keywords(self);
205 3 100         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
206             }
207             OUTPUT:
208             RETVAL
209              
210             SV *
211             creator(self, ...)
212             pdfmake_doc_t *self
213             CODE:
214 6 100         if (items > 1) {
215 3           const char *val = SvPV_nolen(ST(1));
216 3 50         if (pdfmake_meta_set_creator(self, val) != PDFMAKE_OK) {
217 0           croak("PDF::Make::Document::creator: failed to set creator");
218             }
219 3           RETVAL = ST(1);
220 3           SvREFCNT_inc(RETVAL);
221             } else {
222 3           const char *val = pdfmake_meta_get_creator(self);
223 3 100         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
224             }
225             OUTPUT:
226             RETVAL
227              
228             SV *
229             producer(self, ...)
230             pdfmake_doc_t *self
231             CODE:
232 6 100         if (items > 1) {
233 4           const char *val = SvPV_nolen(ST(1));
234 4 50         if (pdfmake_meta_set_producer(self, val) != PDFMAKE_OK) {
235 0           croak("PDF::Make::Document::producer: failed to set producer");
236             }
237 4           RETVAL = ST(1);
238 4           SvREFCNT_inc(RETVAL);
239             } else {
240 2           const char *val = pdfmake_meta_get_producer(self);
241 2 50         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
242             }
243             OUTPUT:
244             RETVAL
245              
246             SV *
247             get_meta(self, key)
248             pdfmake_doc_t *self
249             const char *key
250             CODE:
251 3           const char *val = pdfmake_meta_get(self, key);
252 3 50         RETVAL = val ? newSVpv(val, 0) : &PL_sv_undef;
253             OUTPUT:
254             RETVAL
255              
256             void
257             set_meta(self, key, value)
258             pdfmake_doc_t *self
259             const char *key
260             const char *value
261             CODE:
262 3 50         if (pdfmake_meta_set(self, key, value) != PDFMAKE_OK) {
263 0           croak("PDF::Make::Document::set_meta: failed to set %s", key);
264             }
265              
266             pdfmake_page_t *
267             add_page(self, ...)
268             pdfmake_doc_t *self
269             PREINIT:
270 326           double width = PDFMAKE_PAGE_LETTER_WIDTH;
271 326           double height = PDFMAKE_PAGE_LETTER_HEIGHT;
272             CODE:
273 326 100         if (items > 1) width = SvNV(ST(1));
274 326 100         if (items > 2) height = SvNV(ST(2));
275 326           RETVAL = pdfmake_doc_add_page(self, width, height);
276 326 50         if (!RETVAL)
277 0           croak("PDF::Make::Document::add_page: failed to add page");
278             OUTPUT:
279             RETVAL
280              
281             UV
282             page_count(self)
283             pdfmake_doc_t *self
284             CODE:
285 97           RETVAL = pdfmake_doc_page_count(self);
286             OUTPUT:
287             RETVAL
288              
289             pdfmake_page_t *
290             get_page(self, idx)
291             pdfmake_doc_t *self
292             UV idx
293             CODE:
294 57           RETVAL = pdfmake_doc_get_page(self, (size_t)idx);
295 57 100         if (!RETVAL)
296 1           croak("PDF::Make::Document::get_page: invalid page index %u", (unsigned)idx);
297             OUTPUT:
298             RETVAL
299              
300             void
301             insert_page(self, idx, page)
302             pdfmake_doc_t *self
303             UV idx
304             pdfmake_page_t *page
305             CODE:
306 0           pdfmake_err_t err = pdfmake_doc_insert_page(self, (size_t)idx, page);
307 0 0         if (err != PDFMAKE_OK)
308 0           croak("PDF::Make::Document::insert_page: failed to insert page");
309              
310             void
311             remove_page(self, idx)
312             pdfmake_doc_t *self
313             UV idx
314             CODE:
315 3           pdfmake_err_t err = pdfmake_doc_remove_page(self, (size_t)idx);
316 3 100         if (err != PDFMAKE_OK)
317 1           croak("PDF::Make::Document::remove_page: failed to remove page %u", (unsigned)idx);
318              
319             void
320             move_page(self, from_idx, to_idx)
321             pdfmake_doc_t *self
322             UV from_idx
323             UV to_idx
324             CODE:
325 2           pdfmake_err_t err = pdfmake_doc_move_page(self, (size_t)from_idx, (size_t)to_idx);
326 2 100         if (err != PDFMAKE_OK)
327 1           croak("PDF::Make::Document::move_page: failed to move page %u to %u", (unsigned)from_idx, (unsigned)to_idx);
328              
329             void
330             rotate_page(self, idx, degrees)
331             pdfmake_doc_t *self
332             UV idx
333             IV degrees
334             CODE:
335             pdfmake_rotation_t rot;
336 5           switch (degrees) {
337 0           case 0: rot = PDFMAKE_ROTATE_0; break;
338 2           case 90: rot = PDFMAKE_ROTATE_90; break;
339 1           case 180: rot = PDFMAKE_ROTATE_180; break;
340 1           case 270: rot = PDFMAKE_ROTATE_270; break;
341 0           case -90: rot = PDFMAKE_ROTATE_270; break;
342 1           default:
343 1           croak("PDF::Make::Document::rotate_page: invalid rotation %d (use 0, 90, 180, 270)", (int)degrees);
344             }
345 4           pdfmake_err_t err = pdfmake_doc_rotate_page(self, (size_t)idx, rot);
346 4 50         if (err != PDFMAKE_OK)
347 0           croak("PDF::Make::Document::rotate_page: failed to rotate page %u", (unsigned)idx);
348              
349             void
350             duplicate_page(self, idx)
351             pdfmake_doc_t *self
352             UV idx
353             CODE:
354 3           pdfmake_err_t err = pdfmake_doc_duplicate_page(self, (size_t)idx);
355 3 100         if (err != PDFMAKE_OK)
356 1           croak("PDF::Make::Document::duplicate_page: failed to duplicate page %u", (unsigned)idx);
357              
358             UV
359             add_text_annot(self, x1, y1, x2, y2, contents, ...)
360             pdfmake_doc_t *self
361             double x1
362             double y1
363             double x2
364             double y2
365             const char *contents
366             PREINIT:
367 8           pdfmake_annot_icon_t icon = PDFMAKE_ANNOT_ICON_NOTE;
368 8 50         int open = 0;
369             CODE:
370 8 100         if (items > 6) {
371 7           const char *icon_str = SvPV_nolen(ST(6));
372 7 100         if (strEQ(icon_str, "Comment")) icon = PDFMAKE_ANNOT_ICON_COMMENT;
373 4 100         else if (strEQ(icon_str, "Key")) icon = PDFMAKE_ANNOT_ICON_KEY;
374 3 50         else if (strEQ(icon_str, "Help")) icon = PDFMAKE_ANNOT_ICON_HELP;
375 3 50         else if (strEQ(icon_str, "Paragraph")) icon = PDFMAKE_ANNOT_ICON_PARAGRAPH;
376 3 50         else if (strEQ(icon_str, "NewParagraph")) icon = PDFMAKE_ANNOT_ICON_NEWPARAGRAPH;
377 3 50         else if (strEQ(icon_str, "Insert")) icon = PDFMAKE_ANNOT_ICON_INSERT;
378             }
379 8 100         if (items > 7) open = SvIV(ST(7));
380            
381 8           pdfmake_rect_t rect = {x1, y1, x2, y2};
382 8           RETVAL = pdfmake_annot_text(self, rect, contents, icon, open);
383 8 50         if (RETVAL == 0)
384 0           croak("PDF::Make::Document::add_text_annot: failed to create annotation");
385             OUTPUT:
386             RETVAL
387              
388             UV
389             add_link_uri(self, x1, y1, x2, y2, uri)
390             pdfmake_doc_t *self
391             double x1
392             double y1
393             double x2
394             double y2
395             const char *uri
396             CODE:
397 5           pdfmake_rect_t rect = {x1, y1, x2, y2};
398 5           RETVAL = pdfmake_annot_link_uri(self, rect, uri);
399 5 50         if (RETVAL == 0)
400 0           croak("PDF::Make::Document::add_link_uri: failed to create annotation");
401             OUTPUT:
402             RETVAL
403              
404             UV
405             add_link_goto(self, x1, y1, x2, y2, dest_page)
406             pdfmake_doc_t *self
407             double x1
408             double y1
409             double x2
410             double y2
411             UV dest_page
412             CODE:
413 15           pdfmake_rect_t rect = {x1, y1, x2, y2};
414 15           RETVAL = pdfmake_annot_link_goto(self, rect, (size_t)dest_page);
415 15 50         if (RETVAL == 0)
416 0           croak("PDF::Make::Document::add_link_goto: failed to create annotation");
417             OUTPUT:
418             RETVAL
419              
420             UV
421             add_stamp(self, x1, y1, x2, y2, stamp_type)
422             pdfmake_doc_t *self
423             double x1
424             double y1
425             double x2
426             double y2
427             const char *stamp_type
428             PREINIT:
429 5 50         pdfmake_stamp_type_t type = PDFMAKE_STAMP_DRAFT;
430             CODE:
431 5 100         if (strEQ(stamp_type, "Approved")) type = PDFMAKE_STAMP_APPROVED;
432 4 50         else if (strEQ(stamp_type, "Experimental")) type = PDFMAKE_STAMP_EXPERIMENTAL;
433 4 50         else if (strEQ(stamp_type, "NotApproved")) type = PDFMAKE_STAMP_NOTAPPROVED;
434 4 50         else if (strEQ(stamp_type, "AsIs")) type = PDFMAKE_STAMP_ASIS;
435 4 50         else if (strEQ(stamp_type, "Expired")) type = PDFMAKE_STAMP_EXPIRED;
436 4 50         else if (strEQ(stamp_type, "NotForPublicRelease")) type = PDFMAKE_STAMP_NOTFORPUBLICRELEASE;
437 4 100         else if (strEQ(stamp_type, "Confidential")) type = PDFMAKE_STAMP_CONFIDENTIAL;
438 2 50         else if (strEQ(stamp_type, "Final")) type = PDFMAKE_STAMP_FINAL;
439 2 50         else if (strEQ(stamp_type, "Sold")) type = PDFMAKE_STAMP_SOLD;
440 2 50         else if (strEQ(stamp_type, "Departmental")) type = PDFMAKE_STAMP_DEPARTMENTAL;
441 2 50         else if (strEQ(stamp_type, "ForLegalReview")) type = PDFMAKE_STAMP_FORLEGALREVIEW;
442 2 50         else if (strEQ(stamp_type, "TopSecret")) type = PDFMAKE_STAMP_TOPSECRET;
443 2 50         else if (strEQ(stamp_type, "ForComment")) type = PDFMAKE_STAMP_FORCOMMENT;
444             /* Default is Draft */
445            
446 5           pdfmake_rect_t rect = {x1, y1, x2, y2};
447 5           RETVAL = pdfmake_annot_stamp(self, rect, type);
448 5 50         if (RETVAL == 0)
449 0           croak("PDF::Make::Document::add_stamp: failed to create annotation");
450             OUTPUT:
451             RETVAL
452              
453             ##############################################################################
454             # Outline (Bookmarks) API
455             ##############################################################################
456              
457             SV *
458             add_outline(self, title, page_index, dest_type = "Fit", left = 0, top = 0, zoom = 0)
459             pdfmake_doc_t *self
460             const char *title
461             UV page_index
462             const char *dest_type
463             double left
464             double top
465             double zoom
466             PREINIT:
467             pdfmake_dest_t dest;
468             pdfmake_outline_item_t *item;
469             SV *sv;
470             CODE:
471             /* Build destination based on type */
472 17 100         if (strEQ(dest_type, "XYZ")) {
473 1           dest = pdfmake_dest_xyz((size_t)page_index, left, top, zoom);
474             }
475 16 100         else if (strEQ(dest_type, "Fit")) {
476 15           dest = pdfmake_dest_fit((size_t)page_index);
477             }
478 1 50         else if (strEQ(dest_type, "FitH")) {
479 1           dest = pdfmake_dest_fith((size_t)page_index, top);
480             }
481 0 0         else if (strEQ(dest_type, "FitV")) {
482 0           dest = pdfmake_dest_fitv((size_t)page_index, left);
483             }
484 0 0         else if (strEQ(dest_type, "FitB")) {
485 0           dest = pdfmake_dest_fitb((size_t)page_index);
486             }
487 0 0         else if (strEQ(dest_type, "FitBH")) {
488 0           dest = pdfmake_dest_fitbh((size_t)page_index, top);
489             }
490 0 0         else if (strEQ(dest_type, "FitBV")) {
491 0           dest = pdfmake_dest_fitbv((size_t)page_index, left);
492             }
493             else {
494 0           dest = pdfmake_dest_fit((size_t)page_index);
495             }
496              
497 17           item = pdfmake_doc_add_outline_root(self, title, dest);
498 17 50         if (!item)
499 0           croak("PDF::Make::Document::add_outline: failed to create outline root");
500              
501 17           sv = newSV(0);
502 17           sv_setref_pv(sv, "PDF::Make::Outline", (void *)item);
503 17           RETVAL = sv;
504             OUTPUT:
505             RETVAL
506              
507             ##############################################################################
508             # Action API
509             ##############################################################################
510              
511             pdfmake_action_t *
512             action_goto(self, page_index, dest_type = "Fit", left = 0, top = 0, zoom = 0)
513             pdfmake_doc_t *self
514             UV page_index
515             const char *dest_type
516             double left
517             double top
518             double zoom
519             PREINIT:
520             pdfmake_dest_t dest;
521             CODE:
522             /* Build destination based on type */
523 6 100         if (strEQ(dest_type, "XYZ")) {
524 1           dest = pdfmake_dest_xyz((size_t)page_index, left, top, zoom);
525             }
526 5 100         else if (strEQ(dest_type, "Fit")) {
527 3           dest = pdfmake_dest_fit((size_t)page_index);
528             }
529 2 100         else if (strEQ(dest_type, "FitH")) {
530 1           dest = pdfmake_dest_fith((size_t)page_index, top);
531             }
532 1 50         else if (strEQ(dest_type, "FitV")) {
533 1           dest = pdfmake_dest_fitv((size_t)page_index, left);
534             }
535 0 0         else if (strEQ(dest_type, "FitB")) {
536 0           dest = pdfmake_dest_fitb((size_t)page_index);
537             }
538 0 0         else if (strEQ(dest_type, "FitBH")) {
539 0           dest = pdfmake_dest_fitbh((size_t)page_index, top);
540             }
541 0 0         else if (strEQ(dest_type, "FitBV")) {
542 0           dest = pdfmake_dest_fitbv((size_t)page_index, left);
543             }
544             else {
545 0           dest = pdfmake_dest_fit((size_t)page_index);
546             }
547            
548 6           RETVAL = pdfmake_action_goto(self, dest);
549 6 50         if (!RETVAL)
550 0           croak("PDF::Make::Document::action_goto: failed to create action");
551             OUTPUT:
552             RETVAL
553              
554             pdfmake_action_t *
555             action_uri(self, uri)
556             pdfmake_doc_t *self
557             const char *uri
558             CODE:
559 5           RETVAL = pdfmake_action_uri(self, uri);
560 5 50         if (!RETVAL)
561 0           croak("PDF::Make::Document::action_uri: failed to create action");
562             OUTPUT:
563             RETVAL
564              
565             pdfmake_action_t *
566             action_named(self, name)
567             pdfmake_doc_t *self
568             const char *name
569             CODE:
570 5           RETVAL = pdfmake_action_named_str(self, name);
571 5 50         if (!RETVAL)
572 0           croak("PDF::Make::Document::action_named: unknown named action '%s'", name);
573             OUTPUT:
574             RETVAL
575              
576             pdfmake_action_t *
577             action_javascript(self, script)
578             pdfmake_doc_t *self
579             const char *script
580             CODE:
581 2           RETVAL = pdfmake_action_javascript(self, script);
582 2 50         if (!RETVAL)
583 0           croak("PDF::Make::Document::action_javascript: failed to create action");
584             OUTPUT:
585             RETVAL
586              
587             pdfmake_action_t *
588             action_gotor(self, file, page_index, new_window = 0)
589             pdfmake_doc_t *self
590             const char *file
591             UV page_index
592             int new_window
593             PREINIT:
594             pdfmake_dest_t dest;
595             CODE:
596 5           dest = pdfmake_dest_fit((size_t)page_index);
597 5           RETVAL = pdfmake_action_gotor(self, file, dest, new_window);
598 5 50         if (!RETVAL)
599 0           croak("PDF::Make::Document::action_gotor: failed to create action");
600             OUTPUT:
601             RETVAL
602              
603             UV
604             add_link_with_action(self, x1, y1, x2, y2, action, highlight = "Invert")
605             pdfmake_doc_t *self
606             double x1
607             double y1
608             double x2
609             double y2
610             pdfmake_action_t *action
611             const char *highlight
612             PREINIT:
613             pdfmake_rect_t rect;
614             pdfmake_highlight_mode_t hl;
615             CODE:
616 9           rect.x1 = x1;
617 9           rect.y1 = y1;
618 9           rect.x2 = x2;
619 9           rect.y2 = y2;
620            
621 9 100         if (strEQ(highlight, "None")) {
622 1           hl = PDFMAKE_HIGHLIGHT_NONE;
623             }
624 8 100         else if (strEQ(highlight, "Outline")) {
625 1           hl = PDFMAKE_HIGHLIGHT_OUTLINE;
626             }
627 7 100         else if (strEQ(highlight, "Push")) {
628 1           hl = PDFMAKE_HIGHLIGHT_PUSH;
629             }
630             else {
631 6           hl = PDFMAKE_HIGHLIGHT_INVERT; /* Default */
632             }
633            
634 9           RETVAL = pdfmake_annot_link_action(self, rect, action, hl);
635 9 50         if (RETVAL == 0)
636 0           croak("PDF::Make::Document::add_link_with_action: failed to create link");
637             OUTPUT:
638             RETVAL
639              
640             UV
641             add_link_named_action(self, x1, y1, x2, y2, name, highlight = "Invert")
642             pdfmake_doc_t *self
643             double x1
644             double y1
645             double x2
646             double y2
647             const char *name
648             const char *highlight
649             PREINIT:
650             pdfmake_rect_t rect;
651             pdfmake_highlight_mode_t hl;
652             CODE:
653 6           rect.x1 = x1;
654 6           rect.y1 = y1;
655 6           rect.x2 = x2;
656 6           rect.y2 = y2;
657            
658 6 50         if (strEQ(highlight, "None")) {
659 0           hl = PDFMAKE_HIGHLIGHT_NONE;
660             }
661 6 50         else if (strEQ(highlight, "Outline")) {
662 0           hl = PDFMAKE_HIGHLIGHT_OUTLINE;
663             }
664 6 50         else if (strEQ(highlight, "Push")) {
665 0           hl = PDFMAKE_HIGHLIGHT_PUSH;
666             }
667             else {
668 6           hl = PDFMAKE_HIGHLIGHT_INVERT;
669             }
670            
671 6           RETVAL = pdfmake_annot_link_named(self, rect, name, hl);
672 6 50         if (RETVAL == 0)
673 0           croak("PDF::Make::Document::add_link_named_action: unknown named action '%s'", name);
674             OUTPUT:
675             RETVAL
676              
677             void
678             DESTROY(self)
679             pdfmake_doc_t *self
680             CODE:
681 339           pdfmake_doc_free(self);
682              
683             BOOT:
684             {
685 90           HV *stash = gv_stashpv("PDF::Make::Document", GV_ADD);
686 90 50         PDFMAKE_REGISTER_META(stash, "title", pdfmake_meta_get_title, pdfmake_meta_set_title);
    50          
687 90 50         PDFMAKE_REGISTER_META(stash, "author", pdfmake_meta_get_author, pdfmake_meta_set_author);
    50          
688 90 50         PDFMAKE_REGISTER_META(stash, "subject", pdfmake_meta_get_subject, pdfmake_meta_set_subject);
    50          
689 90 50         PDFMAKE_REGISTER_META(stash, "keywords", pdfmake_meta_get_keywords, pdfmake_meta_set_keywords);
    50          
690 90 50         PDFMAKE_REGISTER_META(stash, "creator", pdfmake_meta_get_creator, pdfmake_meta_set_creator);
    50          
691 90 50         PDFMAKE_REGISTER_META(stash, "producer", pdfmake_meta_get_producer, pdfmake_meta_set_producer);
    50          
692             }