| 1 |
|
| MODULE = PDF::Make PACKAGE = PDF::Make::Redaction |
| 2 |
|
| PROTOTYPES: ENABLE |
| 3 |
|
| |
| 4 |
|
| void |
| 5 |
|
| mark(class, page, ...) |
| 6 |
|
| char *class |
| 7 |
|
| pdfmake_page_t *page |
| 8 |
|
| PREINIT: |
| 9 |
22 |
| double x0 = 0, y0 = 0, x1 = 0, y1 = 0; |
| 10 |
|
| pdfmake_redact_opts_t opts; |
| 11 |
|
| pdfmake_redact_t *r; |
| 12 |
|
| int i; |
| 13 |
|
| CODE: |
| 14 |
|
| PERL_UNUSED_VAR(class); |
| 15 |
22 |
| memset(&opts, 0, sizeof(opts)); |
| 16 |
22 |
| opts.overlay_font_size = 10; |
| 17 |
|
| |
| 18 |
77 |
▶ | for (i = 2; i < items - 1; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i < items - 1; i += 2) { |
55 |
22 |
77 |
|
| 19 |
55 |
| const char *key = SvPV_nolen(ST(i)); |
| 20 |
55 |
| SV *val = ST(i + 1); |
| 21 |
55 |
▶ | if (strEQ(key, "x0")) x0 = SvNV(val); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(key, "x0")) x0 = SvNV(val); |
1 |
54 |
55 |
|
| 22 |
54 |
▶ | else if (strEQ(key, "y0")) y0 = SvNV(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "y0")) y0 = SvNV(val); |
1 |
53 |
54 |
|
| 23 |
53 |
▶ | else if (strEQ(key, "x1")) x1 = SvNV(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "x1")) x1 = SvNV(val); |
1 |
52 |
53 |
|
| 24 |
52 |
▶ | else if (strEQ(key, "y1")) y1 = SvNV(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "y1")) y1 = SvNV(val); |
1 |
51 |
52 |
|
| 25 |
72 |
▶ | else if (strEQ(key, "rect") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (strEQ(key, "rect") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
21 |
30 |
51 |
| else if (strEQ(key, "rect") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
21 |
0 |
21 |
| else if (strEQ(key, "rect") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
21 |
0 |
21 |
|
| 26 |
21 |
| AV *av = (AV *)SvRV(val); |
| 27 |
|
| SV **e; |
| 28 |
21 |
▶ | if ((e = av_fetch(av, 0, 0))) x0 = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 0, 0))) x0 = SvNV(*e); |
21 |
0 |
21 |
|
| 29 |
21 |
▶ | if ((e = av_fetch(av, 1, 0))) y0 = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 1, 0))) y0 = SvNV(*e); |
21 |
0 |
21 |
|
| 30 |
21 |
▶ | if ((e = av_fetch(av, 2, 0))) x1 = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 2, 0))) x1 = SvNV(*e); |
21 |
0 |
21 |
|
| 31 |
21 |
▶ | if ((e = av_fetch(av, 3, 0))) y1 = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 3, 0))) y1 = SvNV(*e); |
21 |
0 |
21 |
|
| 32 |
|
| } |
| 33 |
42 |
▶ | else if (strEQ(key, "overlay_color") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (strEQ(key, "overlay_color") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
12 |
18 |
30 |
| else if (strEQ(key, "overlay_color") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
12 |
0 |
12 |
| else if (strEQ(key, "overlay_color") && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) { |
12 |
0 |
12 |
|
| 34 |
12 |
| AV *av = (AV *)SvRV(val); |
| 35 |
|
| SV **e; |
| 36 |
12 |
▶ | if ((e = av_fetch(av, 0, 0))) opts.overlay_color[0] = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 0, 0))) opts.overlay_color[0] = SvNV(*e); |
12 |
0 |
12 |
|
| 37 |
12 |
▶ | if ((e = av_fetch(av, 1, 0))) opts.overlay_color[1] = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 1, 0))) opts.overlay_color[1] = SvNV(*e); |
12 |
0 |
12 |
|
| 38 |
12 |
▶ | if ((e = av_fetch(av, 2, 0))) opts.overlay_color[2] = SvNV(*e); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((e = av_fetch(av, 2, 0))) opts.overlay_color[2] = SvNV(*e); |
12 |
0 |
12 |
|
| 39 |
|
| } |
| 40 |
35 |
▶ | else if (strEQ(key, "overlay_text")) opts.overlay_text = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "overlay_text")) opts.overlay_text = SvPV_nolen(val); |
17 |
1 |
18 |
|
| 41 |
1 |
▶ | else if (strEQ(key, "overlay_font_size")) opts.overlay_font_size = SvNV(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "overlay_font_size")) opts.overlay_font_size = SvNV(val); |
1 |
0 |
1 |
|
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
22 |
| r = pdfmake_page_mark_redaction(page, x0, y0, x1, y1, &opts); |
| 45 |
22 |
▶ | if (!r) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) |
0 |
22 |
22 |
|
| 46 |
0 |
| croak("PDF::Make::Redaction: mark failed"); |
| 47 |
|
| |
| 48 |
|
| void |
| 49 |
|
| apply_page(class, page) |
| 50 |
|
| char *class |
| 51 |
|
| pdfmake_page_t *page |
| 52 |
|
| CODE: |
| 53 |
|
| PERL_UNUSED_VAR(class); |
| 54 |
0 |
▶ | if (pdfmake_page_apply_redactions(page) != PDFMAKE_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdfmake_page_apply_redactions(page) != PDFMAKE_OK) |
0 |
0 |
0 |
|
| 55 |
0 |
| croak("PDF::Make::Redaction: apply failed"); |
| 56 |
|
| |
| 57 |
|
| void |
| 58 |
|
| apply_doc(class, doc) |
| 59 |
|
| char *class |
| 60 |
|
| pdfmake_doc_t *doc |
| 61 |
|
| CODE: |
| 62 |
|
| PERL_UNUSED_VAR(class); |
| 63 |
0 |
▶ | if (pdfmake_doc_apply_redactions(doc) != PDFMAKE_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdfmake_doc_apply_redactions(doc) != PDFMAKE_OK) |
0 |
0 |
0 |
|
| 64 |
0 |
| croak("PDF::Make::Redaction: apply failed"); |
| 65 |
|
| |
| 66 |
|
| void |
| 67 |
|
| sanitize(class, doc) |
| 68 |
|
| char *class |
| 69 |
|
| pdfmake_doc_t *doc |
| 70 |
|
| CODE: |
| 71 |
|
| PERL_UNUSED_VAR(class); |
| 72 |
5 |
▶ | if (pdfmake_doc_sanitize_metadata(doc) != PDFMAKE_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdfmake_doc_sanitize_metadata(doc) != PDFMAKE_OK) |
0 |
5 |
5 |
|
| 73 |
0 |
| croak("PDF::Make::Redaction: sanitize failed"); |
| 74 |
|
| |
| 75 |
|
| UV |
| 76 |
|
| count(class, page) |
| 77 |
|
| char *class |
| 78 |
|
| pdfmake_page_t *page |
| 79 |
|
| CODE: |
| 80 |
|
| PERL_UNUSED_VAR(class); |
| 81 |
9 |
| RETVAL = pdfmake_page_redaction_count(page); |
| 82 |
|
| OUTPUT: |
| 83 |
|
| RETVAL |
| 84 |
|
| |
| 85 |
|
| SV * |
| 86 |
|
| rewrite_stream(class, content_sv, rects_sv) |
| 87 |
|
| char *class |
| 88 |
|
| SV *content_sv |
| 89 |
|
| SV *rects_sv |
| 90 |
|
| PREINIT: |
| 91 |
|
| STRLEN in_len; |
| 92 |
|
| const uint8_t *in_bytes; |
| 93 |
|
| AV *rects_av; |
| 94 |
|
| SSize_t n_rects; |
| 95 |
1 |
▶ | pdfmake_redact_t *rects = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| pdfmake_redact_t *rects = NULL; |
1 |
0 |
1 |
|
| 96 |
|
| pdfmake_buf_t out; |
| 97 |
|
| pdfmake_err_t err; |
| 98 |
|
| CODE: |
| 99 |
|
| PERL_UNUSED_VAR(class); |
| 100 |
1 |
| in_bytes = (const uint8_t *)SvPVbyte(content_sv, in_len); |
| 101 |
|
| |
| 102 |
1 |
▶ | if (!SvROK(rects_sv) || SvTYPE(SvRV(rects_sv)) != SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(rects_sv) || SvTYPE(SvRV(rects_sv)) != SVt_PVAV) { |
1 |
0 |
1 |
| if (!SvROK(rects_sv) || SvTYPE(SvRV(rects_sv)) != SVt_PVAV) { |
0 |
1 |
1 |
|
| 103 |
0 |
| croak("PDF::Make::Redaction::rewrite_stream: rects must be an arrayref"); |
| 104 |
|
| } |
| 105 |
1 |
| rects_av = (AV *)SvRV(rects_sv); |
| 106 |
1 |
| n_rects = av_len(rects_av) + 1; |
| 107 |
|
| |
| 108 |
1 |
▶ | if (n_rects > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n_rects > 0) { |
1 |
0 |
1 |
|
| 109 |
1 |
| rects = (pdfmake_redact_t *)calloc((size_t)n_rects, sizeof(*rects)); |
| 110 |
1 |
▶ | if (!rects) croak("PDF::Make::Redaction::rewrite_stream: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rects) croak("PDF::Make::Redaction::rewrite_stream: out of memory"); |
0 |
1 |
1 |
|
| 111 |
3 |
▶ | for (SSize_t i = 0; i < n_rects; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < n_rects; i++) { |
2 |
1 |
3 |
|
| 112 |
2 |
| SV **e = av_fetch(rects_av, i, 0); |
| 113 |
2 |
▶ | if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVAV) { |
2 |
0 |
2 |
| if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVAV) { |
2 |
0 |
2 |
| if (!e || !SvROK(*e) || SvTYPE(SvRV(*e)) != SVt_PVAV) { |
0 |
2 |
2 |
|
| 114 |
0 |
| free(rects); |
| 115 |
0 |
| croak("PDF::Make::Redaction::rewrite_stream: rect %ld not an arrayref", (long)i); |
| 116 |
|
| } |
| 117 |
2 |
| AV *rav = (AV *)SvRV(*e); |
| 118 |
|
| SV **v; |
| 119 |
2 |
▶ | if ((v = av_fetch(rav, 0, 0))) rects[i].rect[0] = SvNV(*v); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = av_fetch(rav, 0, 0))) rects[i].rect[0] = SvNV(*v); |
2 |
0 |
2 |
|
| 120 |
2 |
▶ | if ((v = av_fetch(rav, 1, 0))) rects[i].rect[1] = SvNV(*v); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = av_fetch(rav, 1, 0))) rects[i].rect[1] = SvNV(*v); |
2 |
0 |
2 |
|
| 121 |
2 |
▶ | if ((v = av_fetch(rav, 2, 0))) rects[i].rect[2] = SvNV(*v); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = av_fetch(rav, 2, 0))) rects[i].rect[2] = SvNV(*v); |
2 |
0 |
2 |
|
| 122 |
2 |
▶ | if ((v = av_fetch(rav, 3, 0))) rects[i].rect[3] = SvNV(*v); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v = av_fetch(rav, 3, 0))) rects[i].rect[3] = SvNV(*v); |
2 |
0 |
2 |
|
| 123 |
|
| } |
| 124 |
|
| } |
| 125 |
|
| |
| 126 |
1 |
▶ | if (pdfmake_buf_init(&out) != PDFMAKE_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdfmake_buf_init(&out) != PDFMAKE_OK) { |
0 |
1 |
1 |
|
| 127 |
0 |
| free(rects); |
| 128 |
0 |
| croak("PDF::Make::Redaction::rewrite_stream: buf init failed"); |
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
1 |
| err = pdfmake_redact_rewrite_stream( |
| 132 |
|
| in_bytes, (size_t)in_len, rects, (size_t)n_rects, &out); |
| 133 |
1 |
| free(rects); |
| 134 |
1 |
▶ | if (err != PDFMAKE_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (err != PDFMAKE_OK) { |
0 |
1 |
1 |
|
| 135 |
0 |
| pdfmake_buf_free(&out); |
| 136 |
0 |
| croak("PDF::Make::Redaction::rewrite_stream: rewrite failed"); |
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
1 |
| RETVAL = newSVpvn((const char *)out.data, out.len); |
| 140 |
1 |
| pdfmake_buf_free(&out); |
| 141 |
|
| OUTPUT: |
| 142 |
|
| RETVAL |