| 1 |
|
| MODULE = PDF::Make PACKAGE = PDF::Make::Markup::Style |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # Attributes, values and inheritance. Every decision - which properties exist, |
| 6 |
|
| # which tags accept them, how a value is read, what inherits - lives in |
| 7 |
|
| # src/pdfmake_markup_style.c. What is here is the SV walking needed to get |
| 8 |
|
| # bytes in and values out, and nothing else. |
| 9 |
|
| |
| 10 |
|
| # Coerce one value. Croaks with the reason, which the caller decorates with a |
| 11 |
|
| # position when it has one. |
| 12 |
|
| double |
| 13 |
|
| length_pt(class, value, node = NULL, what = NULL) |
| 14 |
|
| SV *class |
| 15 |
|
| SV *value |
| 16 |
|
| SV *node |
| 17 |
|
| SV *what |
| 18 |
|
| ALIAS: |
| 19 |
|
| number = 1 |
| 20 |
|
| CODE: |
| 21 |
|
| { |
| 22 |
|
| STRLEN len; |
| 23 |
|
| const char *v; |
| 24 |
|
| char err[PDFMAKE_STYLE_ERR_LEN]; |
| 25 |
9 |
| double out = 0; |
| 26 |
|
| int ok; |
| 27 |
|
| |
| 28 |
|
| PERL_UNUSED_VAR(class); |
| 29 |
9 |
| v = pdfmake_markup_sv_bytes(aTHX_ value, &len); |
| 30 |
0 |
| ok = ix ? pdfmake_style_number(v, len, &out, err, sizeof(err)) |
| 31 |
9 |
▶ | : pdfmake_style_length(v, len, &out, err, sizeof(err)); |
Branch: 1 branch
| Branch | True | False | Total |
| : pdfmake_style_length(v, len, &out, err, sizeof(err)); |
0 |
9 |
9 |
|
| 32 |
9 |
▶ | if (!ok) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) |
5 |
4 |
9 |
|
| 33 |
5 |
| pdfmake_markup_croak_at(aTHX_ node, what, err); |
| 34 |
4 |
▶ | RETVAL = out; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = out; |
0 |
4 |
4 |
|
| 35 |
|
| } |
| 36 |
|
| OUTPUT: |
| 37 |
|
| RETVAL |
| 38 |
|
| |
| 39 |
|
| SV * |
| 40 |
|
| colour(class, value, node = NULL, what = NULL) |
| 41 |
|
| SV *class |
| 42 |
|
| SV *value |
| 43 |
|
| SV *node |
| 44 |
|
| SV *what |
| 45 |
|
| CODE: |
| 46 |
|
| { |
| 47 |
|
| STRLEN len; |
| 48 |
|
| const char *v; |
| 49 |
|
| char err[PDFMAKE_STYLE_ERR_LEN]; |
| 50 |
|
| char out[8]; |
| 51 |
|
| |
| 52 |
|
| PERL_UNUSED_VAR(class); |
| 53 |
11 |
| v = pdfmake_markup_sv_bytes(aTHX_ value, &len); |
| 54 |
11 |
▶ | if (!pdfmake_style_colour(v, len, out, err, sizeof(err))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pdfmake_style_colour(v, len, out, err, sizeof(err))) |
6 |
5 |
11 |
|
| 55 |
6 |
| pdfmake_markup_croak_at(aTHX_ node, what, err); |
| 56 |
5 |
| RETVAL = newSVpv(out, 0); |
| 57 |
|
| } |
| 58 |
|
| OUTPUT: |
| 59 |
|
| RETVAL |
| 60 |
|
| |
| 61 |
|
| IV |
| 62 |
|
| boolean(class, value, node = NULL, what = NULL) |
| 63 |
|
| SV *class |
| 64 |
|
| SV *value |
| 65 |
|
| SV *node |
| 66 |
|
| SV *what |
| 67 |
|
| CODE: |
| 68 |
|
| { |
| 69 |
|
| STRLEN len; |
| 70 |
|
| const char *v; |
| 71 |
|
| char err[PDFMAKE_STYLE_ERR_LEN]; |
| 72 |
16 |
| int out = 0; |
| 73 |
|
| |
| 74 |
|
| PERL_UNUSED_VAR(class); |
| 75 |
16 |
| v = pdfmake_markup_sv_bytes(aTHX_ value, &len); |
| 76 |
16 |
▶ | if (!pdfmake_style_bool(v, len, &out, err, sizeof(err))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pdfmake_style_bool(v, len, &out, err, sizeof(err))) |
4 |
12 |
16 |
|
| 77 |
4 |
| pdfmake_markup_croak_at(aTHX_ node, what, err); |
| 78 |
12 |
▶ | RETVAL = out; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = out; |
10 |
2 |
12 |
|
| 79 |
|
| } |
| 80 |
|
| OUTPUT: |
| 81 |
|
| RETVAL |
| 82 |
|
| |
| 83 |
|
| # One element's own attributes, validated and coerced. |
| 84 |
|
| SV * |
| 85 |
|
| attrs(class, node) |
| 86 |
|
| SV *class |
| 87 |
|
| SV *node |
| 88 |
|
| CODE: |
| 89 |
|
| PERL_UNUSED_VAR(class); |
| 90 |
218 |
| RETVAL = pdfmake_markup_style_attrs_sv(aTHX_ node); |
| 91 |
|
| OUTPUT: |
| 92 |
|
| RETVAL |
| 93 |
|
| |
| 94 |
|
| # A <style> declaration list for one tag. |
| 95 |
|
| SV * |
| 96 |
|
| declarations(class, string, node, tag) |
| 97 |
|
| SV *class |
| 98 |
|
| SV *string |
| 99 |
|
| SV *node |
| 100 |
|
| SV *tag |
| 101 |
|
| CODE: |
| 102 |
|
| PERL_UNUSED_VAR(class); |
| 103 |
10 |
| RETVAL = pdfmake_markup_style_decls_sv(aTHX_ string, node, tag); |
| 104 |
|
| OUTPUT: |
| 105 |
|
| RETVAL |
| 106 |
|
| |
| 107 |
|
| # Parent's inheritable properties, with own on top. |
| 108 |
|
| SV * |
| 109 |
|
| inherit(class, parent, own) |
| 110 |
|
| SV *class |
| 111 |
|
| SV *parent |
| 112 |
|
| SV *own |
| 113 |
|
| CODE: |
| 114 |
|
| PERL_UNUSED_VAR(class); |
| 115 |
198 |
| RETVAL = pdfmake_markup_style_inherit_sv(aTHX_ parent, own); |
| 116 |
|
| OUTPUT: |
| 117 |
|
| RETVAL |
| 118 |
|
| |
| 119 |
|
| # The font-shaped part of a style, named the way Builder::Font wants it. |
| 120 |
|
| SV * |
| 121 |
|
| font_args(class, style) |
| 122 |
|
| SV *class |
| 123 |
|
| SV *style |
| 124 |
|
| CODE: |
| 125 |
|
| PERL_UNUSED_VAR(class); |
| 126 |
179 |
| RETVAL = pdfmake_markup_style_font_sv(aTHX_ style); |
| 127 |
|
| OUTPUT: |
| 128 |
|
| RETVAL |
| 129 |
|
| |
| 130 |
|
| # The tables themselves, so documentation and tests read what the engine uses. |
| 131 |
|
| SV * |
| 132 |
|
| properties(class) |
| 133 |
|
| SV *class |
| 134 |
|
| CODE: |
| 135 |
|
| { |
| 136 |
1 |
| HV *out = newHV(); |
| 137 |
|
| int p; |
| 138 |
|
| PERL_UNUSED_VAR(class); |
| 139 |
29 |
▶ | for (p = 1; p < PDFMAKE_P_MAX; p++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = 1; p < PDFMAKE_P_MAX; p++) { |
28 |
1 |
29 |
|
| 140 |
28 |
| const char *name = pdfmake_style_prop_name((pdfmake_prop_t)p); |
| 141 |
|
| HV *spec; |
| 142 |
28 |
▶ | if (!name) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!name) continue; |
0 |
28 |
28 |
|
| 143 |
28 |
| spec = newHV(); |
| 144 |
28 |
| (void)hv_stores(spec, "inherit", |
| 145 |
|
| newSViv(pdfmake_style_inherits((pdfmake_prop_t)p))); |
| 146 |
28 |
| (void)hv_store(out, name, (I32)strlen(name), |
| 147 |
|
| newRV_noinc((SV *)spec), 0); |
| 148 |
|
| } |
| 149 |
1 |
| RETVAL = newRV_noinc((SV *)out); |
| 150 |
|
| } |
| 151 |
|
| OUTPUT: |
| 152 |
|
| RETVAL |
| 153 |
|
| |
| 154 |
|
| SV * |
| 155 |
|
| allowed(class, tag) |
| 156 |
|
| SV *class |
| 157 |
|
| SV *tag |
| 158 |
|
| CODE: |
| 159 |
|
| { |
| 160 |
|
| STRLEN len; |
| 161 |
|
| const char *name; |
| 162 |
|
| pdfmake_markup_tag_t t; |
| 163 |
|
| AV *out; |
| 164 |
|
| const char *list, *p; |
| 165 |
|
| |
| 166 |
|
| PERL_UNUSED_VAR(class); |
| 167 |
54 |
| name = pdfmake_markup_sv_bytes(aTHX_ tag, &len); |
| 168 |
54 |
| t = pdfmake_markup_tag_id(name, len); |
| 169 |
54 |
▶ | if (t == PDFMAKE_MK_INVALID) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == PDFMAKE_MK_INVALID) XSRETURN_UNDEF; |
0 |
54 |
54 |
|
| 170 |
|
| |
| 171 |
54 |
| out = newAV(); |
| 172 |
54 |
| list = pdfmake_style_tag_allowed(t); |
| 173 |
54 |
▶ | if (strcmp(list, "(none)") != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(list, "(none)") != 0) { |
50 |
4 |
54 |
|
| 174 |
452 |
▶ | for (p = list; *p; ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = list; *p; ) { |
452 |
0 |
452 |
|
| 175 |
452 |
| const char *e = strstr(p, ", "); |
| 176 |
452 |
▶ | size_t l = e ? (size_t)(e - p) : strlen(p); |
Branch: 1 branch
| Branch | True | False | Total |
| size_t l = e ? (size_t)(e - p) : strlen(p); |
402 |
50 |
452 |
|
| 177 |
452 |
| av_push(out, newSVpvn(p, l)); |
| 178 |
452 |
▶ | if (!e) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) break; |
50 |
402 |
452 |
|
| 179 |
402 |
| p = e + 2; |
| 180 |
|
| } |
| 181 |
|
| } |
| 182 |
54 |
| RETVAL = newRV_noinc((SV *)out); |
| 183 |
|
| } |
| 184 |
|
| OUTPUT: |
| 185 |
|
| RETVAL |
| 186 |
|
| |
| 187 |
|
| SV * |
| 188 |
|
| colours(class) |
| 189 |
|
| SV *class |
| 190 |
|
| CODE: |
| 191 |
|
| { |
| 192 |
|
| static const char *NAMES[] = { |
| 193 |
|
| "aqua","black","blue","fuchsia","gray","green","grey","lime", |
| 194 |
|
| "maroon","navy","olive","purple","red","silver","teal","white", |
| 195 |
|
| "yellow", NULL |
| 196 |
|
| }; |
| 197 |
0 |
| HV *out = newHV(); |
| 198 |
|
| int i; |
| 199 |
|
| PERL_UNUSED_VAR(class); |
| 200 |
0 |
▶ | for (i = 0; NAMES[i]; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; NAMES[i]; i++) { |
0 |
0 |
0 |
|
| 201 |
|
| char hex[8]; |
| 202 |
|
| char err[PDFMAKE_STYLE_ERR_LEN]; |
| 203 |
0 |
▶ | if (!pdfmake_style_colour(NAMES[i], strlen(NAMES[i]), hex, |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pdfmake_style_colour(NAMES[i], strlen(NAMES[i]), hex, |
0 |
0 |
0 |
|
| 204 |
|
| err, sizeof(err))) |
| 205 |
0 |
| continue; |
| 206 |
0 |
| (void)hv_store(out, NAMES[i], (I32)strlen(NAMES[i]), |
| 207 |
|
| newSVpv(hex, 0), 0); |
| 208 |
|
| } |
| 209 |
0 |
| RETVAL = newRV_noinc((SV *)out); |
| 210 |
|
| } |
| 211 |
|
| OUTPUT: |
| 212 |
|
| RETVAL |