| 1 |
|
| /* |
| 2 |
|
| * libpdfmake — PDF object constructors and operations. |
| 3 |
|
| * |
| 4 |
|
| * Constructors for all PDF primitive types: null, bool, int, real, |
| 5 |
|
| * name, string, hexstring, array, dict, ref, and stream. |
| 6 |
|
| */ |
| 7 |
|
| |
| 8 |
|
| #include "pdfmake_arena.h" |
| 9 |
|
| #include <stdlib.h> |
| 10 |
|
| #include <string.h> |
| 11 |
|
| #include <stdio.h> |
| 12 |
|
| |
| 13 |
|
| /*---------------------------------------------------------------------------- |
| 14 |
|
| * Primitive constructors (inline values) |
| 15 |
|
| *--------------------------------------------------------------------------*/ |
| 16 |
|
| |
| 17 |
182 |
| pdfmake_obj_t pdfmake_null(void) { |
| 18 |
182 |
| pdfmake_obj_t obj = {0}; |
| 19 |
182 |
| obj.kind = PDFMAKE_NULL; |
| 20 |
182 |
| return obj; |
| 21 |
|
| } |
| 22 |
|
| |
| 23 |
32 |
| pdfmake_obj_t pdfmake_bool(int value) { |
| 24 |
32 |
| pdfmake_obj_t obj = {0}; |
| 25 |
32 |
| obj.kind = PDFMAKE_BOOL; |
| 26 |
32 |
| obj.as.i = value ? 1 : 0; |
| 27 |
32 |
| return obj; |
| 28 |
|
| } |
| 29 |
|
| |
| 30 |
15341 |
| pdfmake_obj_t pdfmake_int(int64_t value) { |
| 31 |
15341 |
| pdfmake_obj_t obj = {0}; |
| 32 |
15341 |
| obj.kind = PDFMAKE_INT; |
| 33 |
15341 |
| obj.as.i = value; |
| 34 |
15341 |
| return obj; |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
7021 |
| pdfmake_obj_t pdfmake_real(double value) { |
| 38 |
7021 |
| pdfmake_obj_t obj = {0}; |
| 39 |
7021 |
| obj.kind = PDFMAKE_REAL; |
| 40 |
7021 |
| obj.as.r = value; |
| 41 |
7021 |
| return obj; |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
|
| /*---------------------------------------------------------------------------- |
| 45 |
|
| * Name constructor (interned) |
| 46 |
|
| *--------------------------------------------------------------------------*/ |
| 47 |
|
| |
| 48 |
13216 |
| pdfmake_obj_t pdfmake_name(pdfmake_arena_t *arena, const char *bytes, size_t len) { |
| 49 |
13216 |
| pdfmake_obj_t obj = {0}; |
| 50 |
13216 |
| obj.kind = PDFMAKE_NAME; |
| 51 |
|
| |
| 52 |
13216 |
▶ | if (!arena || !bytes) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!arena || !bytes) { |
13216 |
0 |
13216 |
| if (!arena || !bytes) { |
0 |
13216 |
13216 |
|
| 53 |
0 |
| obj.as.name.id = 0; |
| 54 |
0 |
| return obj; |
| 55 |
|
| } |
| 56 |
|
| |
| 57 |
|
| /* If len is 0, calculate from null-terminated string. */ |
| 58 |
13216 |
▶ | if (len == 0 && bytes[0] != '\0') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len == 0 && bytes[0] != '\0') { |
0 |
13216 |
13216 |
| if (len == 0 && bytes[0] != '\0') { |
0 |
0 |
0 |
|
| 59 |
0 |
| len = strlen(bytes); |
| 60 |
|
| } |
| 61 |
|
| |
| 62 |
13216 |
| obj.as.name.id = pdfmake_arena_intern_name(arena, bytes, len); |
| 63 |
13216 |
| return obj; |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
4437 |
| pdfmake_obj_t pdfmake_name_cstr(pdfmake_arena_t *arena, const char *cstr) { |
| 67 |
4437 |
▶ | return pdfmake_name(arena, cstr, cstr ? strlen(cstr) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| return pdfmake_name(arena, cstr, cstr ? strlen(cstr) : 0); |
4437 |
0 |
4437 |
|
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
|
| /*---------------------------------------------------------------------------- |
| 71 |
|
| * String constructors (arena-allocated) |
| 72 |
|
| *--------------------------------------------------------------------------*/ |
| 73 |
|
| |
| 74 |
3019 |
| pdfmake_obj_t pdfmake_str(pdfmake_arena_t *arena, const char *bytes, size_t len) { |
| 75 |
3019 |
| pdfmake_obj_t obj = {0}; |
| 76 |
|
| uint8_t *dup; |
| 77 |
3019 |
| obj.kind = PDFMAKE_STR; |
| 78 |
|
| |
| 79 |
3019 |
▶ | if (!arena || !bytes || len == 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!arena || !bytes || len == 0) { |
3019 |
0 |
3019 |
| if (!arena || !bytes || len == 0) { |
3019 |
0 |
3019 |
| if (!arena || !bytes || len == 0) { |
2 |
3017 |
3019 |
|
| 80 |
2 |
| obj.as.str.bytes = NULL; |
| 81 |
2 |
| obj.as.str.len = 0; |
| 82 |
2 |
| obj.as.str.hex = 0; |
| 83 |
2 |
| return obj; |
| 84 |
|
| } |
| 85 |
|
| |
| 86 |
|
| /* Copy bytes into arena with null terminator for C string compatibility. */ |
| 87 |
3017 |
| dup = pdfmake_arena_alloc(arena, len + 1); |
| 88 |
3017 |
▶ | if (!dup) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dup) { |
0 |
3017 |
3017 |
|
| 89 |
0 |
| obj.as.str.bytes = NULL; |
| 90 |
0 |
| obj.as.str.len = 0; |
| 91 |
0 |
| obj.as.str.hex = 0; |
| 92 |
0 |
| return obj; |
| 93 |
|
| } |
| 94 |
|
| |
| 95 |
3017 |
| memcpy(dup, bytes, len); |
| 96 |
3017 |
| dup[len] = '\0'; /* null-terminate for C string use */ |
| 97 |
3017 |
| obj.as.str.bytes = dup; |
| 98 |
3017 |
| obj.as.str.len = (uint32_t)len; |
| 99 |
3017 |
| obj.as.str.hex = 0; |
| 100 |
3017 |
| return obj; |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
2054 |
| pdfmake_obj_t pdfmake_str_cstr(pdfmake_arena_t *arena, const char *cstr) { |
| 104 |
2054 |
▶ | return pdfmake_str(arena, cstr, cstr ? strlen(cstr) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| return pdfmake_str(arena, cstr, cstr ? strlen(cstr) : 0); |
2054 |
0 |
2054 |
|
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
643 |
| pdfmake_obj_t pdfmake_hexstr(pdfmake_arena_t *arena, const uint8_t *bytes, size_t len) { |
| 108 |
643 |
| pdfmake_obj_t obj = pdfmake_str(arena, (const char *)bytes, len); |
| 109 |
643 |
| obj.as.str.hex = 1; |
| 110 |
643 |
| return obj; |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
|
| /*---------------------------------------------------------------------------- |
| 114 |
|
| * Reference constructor |
| 115 |
|
| *--------------------------------------------------------------------------*/ |
| 116 |
|
| |
| 117 |
5563 |
| pdfmake_obj_t pdfmake_ref(uint32_t num, uint16_t gen) { |
| 118 |
5563 |
| pdfmake_obj_t obj = {0}; |
| 119 |
5563 |
| obj.kind = PDFMAKE_REF; |
| 120 |
5563 |
| obj.as.ref.num = num; |
| 121 |
5563 |
| obj.as.ref.gen = gen; |
| 122 |
5563 |
| return obj; |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
|
| /*---------------------------------------------------------------------------- |
| 126 |
|
| * Array operations |
| 127 |
|
| *--------------------------------------------------------------------------*/ |
| 128 |
|
| |
| 129 |
|
| /* Initial array capacity. */ |
| 130 |
|
| #define ARRAY_INIT_CAP 8 |
| 131 |
|
| |
| 132 |
3080 |
| pdfmake_obj_t pdfmake_array_new(pdfmake_arena_t *arena) { |
| 133 |
3080 |
| pdfmake_obj_t obj = {0}; |
| 134 |
|
| pdfmake_array_t *arr; |
| 135 |
3080 |
| obj.kind = PDFMAKE_ARRAY; |
| 136 |
|
| |
| 137 |
3080 |
▶ | if (!arena) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arena) { |
0 |
3080 |
3080 |
|
| 138 |
0 |
| obj.as.arr = NULL; |
| 139 |
0 |
| return obj; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
3080 |
| arr = pdfmake_arena_calloc(arena, sizeof(pdfmake_array_t)); |
| 143 |
3080 |
▶ | if (!arr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arr) { |
0 |
3080 |
3080 |
|
| 144 |
0 |
| obj.as.arr = NULL; |
| 145 |
0 |
| return obj; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
3080 |
| arr->items = pdfmake_arena_alloc(arena, ARRAY_INIT_CAP * sizeof(pdfmake_obj_t)); |
| 149 |
3080 |
▶ | if (!arr->items) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arr->items) { |
0 |
3080 |
3080 |
|
| 150 |
0 |
| obj.as.arr = NULL; |
| 151 |
0 |
| return obj; |
| 152 |
|
| } |
| 153 |
|
| |
| 154 |
3080 |
| arr->len = 0; |
| 155 |
3080 |
| arr->cap = ARRAY_INIT_CAP; |
| 156 |
3080 |
| obj.as.arr = arr; |
| 157 |
3080 |
| return obj; |
| 158 |
|
| } |
| 159 |
|
| |
| 160 |
18532 |
| int pdfmake_array_push(pdfmake_arena_t *arena, pdfmake_obj_t *arr_obj, pdfmake_obj_t item) { |
| 161 |
|
| pdfmake_array_t *arr; |
| 162 |
18532 |
▶ | if (!arena || !arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!arena || !arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
18532 |
0 |
18532 |
| if (!arena || !arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
18532 |
0 |
18532 |
| if (!arena || !arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
18532 |
0 |
18532 |
| if (!arena || !arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
18532 |
18532 |
|
| 163 |
0 |
| return 0; |
| 164 |
|
| } |
| 165 |
|
| |
| 166 |
18532 |
| arr = arr_obj->as.arr; |
| 167 |
|
| |
| 168 |
|
| /* Grow if needed. */ |
| 169 |
18532 |
▶ | if (arr->len >= arr->cap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (arr->len >= arr->cap) { |
560 |
17972 |
18532 |
|
| 170 |
560 |
| size_t new_cap = arr->cap * 2; |
| 171 |
560 |
| pdfmake_obj_t *new_items = pdfmake_arena_alloc(arena, new_cap * sizeof(pdfmake_obj_t)); |
| 172 |
560 |
▶ | if (!new_items) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!new_items) return 0; |
0 |
560 |
560 |
|
| 173 |
|
| |
| 174 |
560 |
| memcpy(new_items, arr->items, arr->len * sizeof(pdfmake_obj_t)); |
| 175 |
560 |
| arr->items = new_items; |
| 176 |
560 |
| arr->cap = (uint32_t)new_cap; |
| 177 |
|
| } |
| 178 |
|
| |
| 179 |
18532 |
| arr->items[arr->len++] = item; |
| 180 |
18532 |
| return 1; |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
9020 |
| pdfmake_obj_t *pdfmake_array_get(pdfmake_obj_t *arr_obj, size_t index) { |
| 184 |
|
| pdfmake_array_t *arr; |
| 185 |
9020 |
▶ | if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
9020 |
0 |
9020 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
9020 |
0 |
9020 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
9020 |
9020 |
|
| 186 |
0 |
| return NULL; |
| 187 |
|
| } |
| 188 |
|
| |
| 189 |
9020 |
| arr = arr_obj->as.arr; |
| 190 |
9020 |
▶ | if (index >= arr->len) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (index >= arr->len) return NULL; |
1 |
9019 |
9020 |
|
| 191 |
|
| |
| 192 |
9019 |
| return &arr->items[index]; |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
0 |
| int pdfmake_array_set(pdfmake_obj_t *arr_obj, size_t index, pdfmake_obj_t item) { |
| 196 |
|
| pdfmake_array_t *arr; |
| 197 |
0 |
▶ | if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
0 |
0 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
0 |
0 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
0 |
0 |
|
| 198 |
0 |
| return 0; |
| 199 |
|
| } |
| 200 |
|
| |
| 201 |
0 |
| arr = arr_obj->as.arr; |
| 202 |
0 |
▶ | if (index >= arr->len) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (index >= arr->len) return 0; |
0 |
0 |
0 |
|
| 203 |
|
| |
| 204 |
0 |
| arr->items[index] = item; |
| 205 |
0 |
| return 1; |
| 206 |
|
| } |
| 207 |
|
| |
| 208 |
970 |
| size_t pdfmake_array_len(pdfmake_obj_t *arr_obj) { |
| 209 |
970 |
▶ | if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
970 |
0 |
970 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
970 |
0 |
970 |
| if (!arr_obj || arr_obj->kind != PDFMAKE_ARRAY || !arr_obj->as.arr) { |
0 |
970 |
970 |
|
| 210 |
0 |
| return 0; |
| 211 |
|
| } |
| 212 |
970 |
| return arr_obj->as.arr->len; |
| 213 |
|
| } |
| 214 |
|
| |
| 215 |
|
| /*---------------------------------------------------------------------------- |
| 216 |
|
| * Dict operations |
| 217 |
|
| *--------------------------------------------------------------------------*/ |
| 218 |
|
| |
| 219 |
|
| /* Initial dict capacity (must be power of 2). */ |
| 220 |
|
| #define DICT_INIT_CAP 16 |
| 221 |
|
| |
| 222 |
|
| /* Load factor threshold: grow when entries/cap > 70%. */ |
| 223 |
|
| #define DICT_LOAD_FACTOR_NUM 7 |
| 224 |
|
| #define DICT_LOAD_FACTOR_DEN 10 |
| 225 |
|
| |
| 226 |
|
| /* Find slot for key. Returns index, sets *found = 1 if key exists. */ |
| 227 |
32785 |
| static size_t dict_find_slot(pdfmake_dict_t *dict, uint32_t key, int *found) { |
| 228 |
|
| size_t mask; |
| 229 |
|
| size_t idx; |
| 230 |
|
| size_t first_tombstone; |
| 231 |
|
| size_t i; |
| 232 |
32785 |
| *found = 0; |
| 233 |
32785 |
▶ | if (!dict->entries || dict->cap == 0) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!dict->entries || dict->cap == 0) return 0; |
32785 |
0 |
32785 |
| if (!dict->entries || dict->cap == 0) return 0; |
0 |
32785 |
32785 |
|
| 234 |
|
| |
| 235 |
32785 |
| mask = dict->cap - 1; |
| 236 |
32785 |
| idx = key & mask; |
| 237 |
32785 |
| first_tombstone = (size_t)-1; |
| 238 |
|
| |
| 239 |
34348 |
▶ | for (i = 0; i < dict->cap; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dict->cap; i++) { |
34348 |
0 |
34348 |
|
| 240 |
34348 |
| pdfmake_dict_entry_t *e = &dict->entries[idx]; |
| 241 |
|
| |
| 242 |
34348 |
▶ | if (e->key == 0 && !e->deleted) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (e->key == 0 && !e->deleted) { |
27775 |
6573 |
34348 |
| if (e->key == 0 && !e->deleted) { |
27648 |
127 |
27775 |
|
| 243 |
|
| /* Empty slot. */ |
| 244 |
27648 |
▶ | if (first_tombstone != (size_t)-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (first_tombstone != (size_t)-1) { |
111 |
27537 |
27648 |
|
| 245 |
111 |
| return first_tombstone; |
| 246 |
|
| } |
| 247 |
27537 |
| return idx; |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
6700 |
▶ | if (e->deleted) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (e->deleted) { |
127 |
6573 |
6700 |
|
| 251 |
|
| /* Tombstone. */ |
| 252 |
127 |
▶ | if (first_tombstone == (size_t)-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (first_tombstone == (size_t)-1) { |
111 |
16 |
127 |
|
| 253 |
111 |
| first_tombstone = idx; |
| 254 |
|
| } |
| 255 |
6573 |
▶ | } else if (e->key == key) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (e->key == key) { |
5137 |
1436 |
6573 |
|
| 256 |
|
| /* Found existing key. */ |
| 257 |
5137 |
| *found = 1; |
| 258 |
5137 |
| return idx; |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
1563 |
| idx = (idx + 1) & mask; |
| 262 |
|
| } |
| 263 |
|
| |
| 264 |
|
| /* Table full (shouldn't happen with proper load factor). */ |
| 265 |
0 |
▶ | return first_tombstone != (size_t)-1 ? first_tombstone : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return first_tombstone != (size_t)-1 ? first_tombstone : 0; |
0 |
0 |
0 |
|
| 266 |
|
| } |
| 267 |
|
| |
| 268 |
|
| /* Grow dict hash table. */ |
| 269 |
28 |
| static int dict_grow(pdfmake_arena_t *arena, pdfmake_dict_t *dict) { |
| 270 |
28 |
| size_t new_cap = dict->cap * 2; |
| 271 |
|
| pdfmake_dict_entry_t *new_entries; |
| 272 |
|
| size_t mask; |
| 273 |
|
| size_t i; |
| 274 |
28 |
▶ | if (new_cap == 0) new_cap = DICT_INIT_CAP; |
Branch: 1 branch
| Branch | True | False | Total |
| if (new_cap == 0) new_cap = DICT_INIT_CAP; |
0 |
28 |
28 |
|
| 275 |
|
| |
| 276 |
28 |
| new_entries = pdfmake_arena_calloc(arena, new_cap * sizeof(pdfmake_dict_entry_t)); |
| 277 |
28 |
▶ | if (!new_entries) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!new_entries) return 0; |
0 |
28 |
28 |
|
| 278 |
|
| |
| 279 |
|
| /* Rehash all non-deleted entries. */ |
| 280 |
28 |
| mask = new_cap - 1; |
| 281 |
604 |
▶ | for (i = 0; i < dict->cap; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dict->cap; i++) { |
576 |
28 |
604 |
|
| 282 |
576 |
| pdfmake_dict_entry_t *e = &dict->entries[i]; |
| 283 |
576 |
▶ | if (e->key != 0 && !e->deleted) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (e->key != 0 && !e->deleted) { |
396 |
180 |
576 |
| if (e->key != 0 && !e->deleted) { |
396 |
0 |
396 |
|
| 284 |
396 |
| size_t idx = e->key & mask; |
| 285 |
398 |
▶ | while (new_entries[idx].key != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (new_entries[idx].key != 0) { |
2 |
396 |
398 |
|
| 286 |
2 |
| idx = (idx + 1) & mask; |
| 287 |
|
| } |
| 288 |
396 |
| new_entries[idx] = *e; |
| 289 |
396 |
| new_entries[idx].deleted = 0; |
| 290 |
|
| } |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
28 |
| dict->entries = new_entries; |
| 294 |
28 |
| dict->cap = (uint32_t)new_cap; |
| 295 |
28 |
| dict->tombstones = 0; |
| 296 |
28 |
| return 1; |
| 297 |
|
| } |
| 298 |
|
| |
| 299 |
8370 |
| pdfmake_obj_t pdfmake_dict_new(pdfmake_arena_t *arena) { |
| 300 |
8370 |
| pdfmake_obj_t obj = {0}; |
| 301 |
|
| pdfmake_dict_t *dict; |
| 302 |
8370 |
| obj.kind = PDFMAKE_DICT; |
| 303 |
|
| |
| 304 |
8370 |
▶ | if (!arena) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arena) { |
0 |
8370 |
8370 |
|
| 305 |
0 |
| obj.as.dict = NULL; |
| 306 |
0 |
| return obj; |
| 307 |
|
| } |
| 308 |
|
| |
| 309 |
8370 |
| dict = pdfmake_arena_calloc(arena, sizeof(pdfmake_dict_t)); |
| 310 |
8370 |
▶ | if (!dict) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dict) { |
0 |
8370 |
8370 |
|
| 311 |
0 |
| obj.as.dict = NULL; |
| 312 |
0 |
| return obj; |
| 313 |
|
| } |
| 314 |
|
| |
| 315 |
8370 |
| dict->entries = pdfmake_arena_calloc(arena, DICT_INIT_CAP * sizeof(pdfmake_dict_entry_t)); |
| 316 |
8370 |
▶ | if (!dict->entries) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dict->entries) { |
0 |
8370 |
8370 |
|
| 317 |
0 |
| obj.as.dict = NULL; |
| 318 |
0 |
| return obj; |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
8370 |
| dict->cap = DICT_INIT_CAP; |
| 322 |
8370 |
| dict->len = 0; |
| 323 |
8370 |
| dict->tombstones = 0; |
| 324 |
8370 |
| dict->next_order = 0; |
| 325 |
8370 |
| obj.as.dict = dict; |
| 326 |
8370 |
| return obj; |
| 327 |
|
| } |
| 328 |
|
| |
| 329 |
23185 |
| int pdfmake_dict_set(pdfmake_arena_t *arena, pdfmake_obj_t *dict_obj, uint32_t key, pdfmake_obj_t value) { |
| 330 |
|
| pdfmake_dict_t *dict; |
| 331 |
|
| int found; |
| 332 |
|
| size_t idx; |
| 333 |
23185 |
▶ | if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
Branch: 5 branches
| Branch | True | False | Total |
| if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
23185 |
0 |
23185 |
| if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
23185 |
0 |
23185 |
| if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
23185 |
0 |
23185 |
| if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
23185 |
0 |
23185 |
| if (!arena || !dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
0 |
23185 |
23185 |
|
| 334 |
0 |
| return 0; |
| 335 |
|
| } |
| 336 |
|
| |
| 337 |
23185 |
| dict = dict_obj->as.dict; |
| 338 |
|
| |
| 339 |
|
| /* Check load factor and grow if needed. */ |
| 340 |
23185 |
▶ | if ((dict->len + dict->tombstones + 1) * DICT_LOAD_FACTOR_DEN > dict->cap * DICT_LOAD_FACTOR_NUM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((dict->len + dict->tombstones + 1) * DICT_LOAD_FACTOR_DEN > dict->cap * DICT_LOAD_FACTOR_NUM) { |
28 |
23157 |
23185 |
|
| 341 |
28 |
▶ | if (!dict_grow(arena, dict)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dict_grow(arena, dict)) return 0; |
0 |
28 |
28 |
|
| 342 |
|
| } |
| 343 |
|
| |
| 344 |
23185 |
| idx = dict_find_slot(dict, key, &found); |
| 345 |
|
| |
| 346 |
23185 |
▶ | if (found) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) { |
227 |
22958 |
23185 |
|
| 347 |
|
| /* Update existing. */ |
| 348 |
227 |
| dict->entries[idx].value = value; |
| 349 |
|
| } else { |
| 350 |
|
| /* Insert new. */ |
| 351 |
22958 |
▶ | if (dict->entries[idx].deleted) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (dict->entries[idx].deleted) { |
51 |
22907 |
22958 |
|
| 352 |
51 |
| dict->tombstones--; |
| 353 |
|
| } |
| 354 |
22958 |
| dict->entries[idx].key = key; |
| 355 |
22958 |
| dict->entries[idx].value = value; |
| 356 |
22958 |
| dict->entries[idx].order = dict->next_order++; |
| 357 |
22958 |
| dict->entries[idx].deleted = 0; |
| 358 |
22958 |
| dict->len++; |
| 359 |
|
| } |
| 360 |
|
| |
| 361 |
23185 |
| return 1; |
| 362 |
|
| } |
| 363 |
|
| |
| 364 |
9443 |
| pdfmake_obj_t *pdfmake_dict_get(pdfmake_obj_t *dict_obj, uint32_t key) { |
| 365 |
|
| pdfmake_dict_t *dict; |
| 366 |
|
| int found; |
| 367 |
|
| size_t idx; |
| 368 |
9443 |
▶ | if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
9443 |
0 |
9443 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
9443 |
0 |
9443 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
9443 |
0 |
9443 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
0 |
9443 |
9443 |
|
| 369 |
0 |
| return NULL; |
| 370 |
|
| } |
| 371 |
|
| |
| 372 |
9443 |
| dict = dict_obj->as.dict; |
| 373 |
9443 |
| idx = dict_find_slot(dict, key, &found); |
| 374 |
|
| |
| 375 |
9443 |
▶ | if (found) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) { |
4805 |
4638 |
9443 |
|
| 376 |
4805 |
| return &dict->entries[idx].value; |
| 377 |
|
| } |
| 378 |
4638 |
| return NULL; |
| 379 |
|
| } |
| 380 |
|
| |
| 381 |
213 |
| int pdfmake_dict_has(pdfmake_obj_t *dict_obj, uint32_t key) { |
| 382 |
213 |
| return pdfmake_dict_get(dict_obj, key) != NULL; |
| 383 |
|
| } |
| 384 |
|
| |
| 385 |
157 |
| int pdfmake_dict_del(pdfmake_obj_t *dict_obj, uint32_t key) { |
| 386 |
|
| pdfmake_dict_t *dict; |
| 387 |
|
| int found; |
| 388 |
|
| size_t idx; |
| 389 |
157 |
▶ | if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
157 |
0 |
157 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
157 |
0 |
157 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
157 |
0 |
157 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict || key == 0) { |
0 |
157 |
157 |
|
| 390 |
0 |
| return 0; |
| 391 |
|
| } |
| 392 |
|
| |
| 393 |
157 |
| dict = dict_obj->as.dict; |
| 394 |
157 |
| idx = dict_find_slot(dict, key, &found); |
| 395 |
|
| |
| 396 |
157 |
▶ | if (found) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) { |
105 |
52 |
157 |
|
| 397 |
105 |
| dict->entries[idx].deleted = 1; |
| 398 |
105 |
| dict->entries[idx].key = 0; |
| 399 |
105 |
| dict->len--; |
| 400 |
105 |
| dict->tombstones++; |
| 401 |
105 |
| return 1; |
| 402 |
|
| } |
| 403 |
52 |
| return 0; |
| 404 |
|
| } |
| 405 |
|
| |
| 406 |
3 |
| size_t pdfmake_dict_len(pdfmake_obj_t *dict_obj) { |
| 407 |
3 |
▶ | if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict) { |
3 |
0 |
3 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict) { |
3 |
0 |
3 |
| if (!dict_obj || dict_obj->kind != PDFMAKE_DICT || !dict_obj->as.dict) { |
0 |
3 |
3 |
|
| 408 |
0 |
| return 0; |
| 409 |
|
| } |
| 410 |
3 |
| return dict_obj->as.dict->len; |
| 411 |
|
| } |
| 412 |
|
| |
| 413 |
|
| /* Iterator: return entries in insertion order. */ |
| 414 |
|
| typedef struct { |
| 415 |
|
| pdfmake_dict_t *dict; |
| 416 |
|
| uint32_t current_order; |
| 417 |
|
| size_t visited; |
| 418 |
|
| } pdfmake_dict_iter_state_t; |
| 419 |
|
| |
| 420 |
668 |
| void pdfmake_dict_iter_init(pdfmake_dict_iter_t *iter, pdfmake_obj_t *dict_obj) { |
| 421 |
668 |
| iter->dict_obj = dict_obj; |
| 422 |
668 |
| iter->index = 0; |
| 423 |
668 |
| iter->current_key = 0; |
| 424 |
668 |
| iter->current_value = NULL; |
| 425 |
668 |
| } |
| 426 |
|
| |
| 427 |
2562 |
| int pdfmake_dict_iter_next(pdfmake_dict_iter_t *iter) { |
| 428 |
|
| pdfmake_dict_t *dict; |
| 429 |
|
| uint32_t best_order; |
| 430 |
|
| size_t best_idx; |
| 431 |
|
| size_t i; |
| 432 |
2562 |
▶ | if (!iter || !iter->dict_obj || iter->dict_obj->kind != PDFMAKE_DICT || !iter->dict_obj->as.dict) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!iter || !iter->dict_obj || iter->dict_obj->kind != PDFMAKE_DICT || !iter->dict_obj->as.dict) { |
2562 |
0 |
2562 |
| if (!iter || !iter->dict_obj || iter->dict_obj->kind != PDFMAKE_DICT || !iter->dict_obj->as.dict) { |
2562 |
0 |
2562 |
| if (!iter || !iter->dict_obj || iter->dict_obj->kind != PDFMAKE_DICT || !iter->dict_obj->as.dict) { |
2562 |
0 |
2562 |
| if (!iter || !iter->dict_obj || iter->dict_obj->kind != PDFMAKE_DICT || !iter->dict_obj->as.dict) { |
0 |
2562 |
2562 |
|
| 433 |
0 |
| return 0; |
| 434 |
|
| } |
| 435 |
|
| |
| 436 |
2562 |
| dict = iter->dict_obj->as.dict; |
| 437 |
|
| |
| 438 |
|
| /* Find next entry with smallest order >= current position. |
| 439 |
|
| * This is O(n²) worst case but maintains insertion order. |
| 440 |
|
| * For 10k entries, consider caching sorted keys. */ |
| 441 |
|
| |
| 442 |
2562 |
| best_order = UINT32_MAX; |
| 443 |
2562 |
| best_idx = (size_t)-1; |
| 444 |
|
| |
| 445 |
43554 |
▶ | for (i = 0; i < dict->cap; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dict->cap; i++) { |
40992 |
2562 |
43554 |
|
| 446 |
40992 |
| pdfmake_dict_entry_t *e = &dict->entries[i]; |
| 447 |
40992 |
▶ | if (e->key != 0 && !e->deleted) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (e->key != 0 && !e->deleted) { |
11550 |
29442 |
40992 |
| if (e->key != 0 && !e->deleted) { |
11550 |
0 |
11550 |
|
| 448 |
11550 |
▶ | if (e->order >= iter->index && e->order < best_order) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (e->order >= iter->index && e->order < best_order) { |
5775 |
5775 |
11550 |
| if (e->order >= iter->index && e->order < best_order) { |
2375 |
3400 |
5775 |
|
| 449 |
2375 |
| best_order = e->order; |
| 450 |
2375 |
| best_idx = i; |
| 451 |
|
| } |
| 452 |
|
| } |
| 453 |
|
| } |
| 454 |
|
| |
| 455 |
2562 |
▶ | if (best_idx == (size_t)-1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (best_idx == (size_t)-1) { |
668 |
1894 |
2562 |
|
| 456 |
668 |
| return 0; |
| 457 |
|
| } |
| 458 |
|
| |
| 459 |
1894 |
| iter->current_key = dict->entries[best_idx].key; |
| 460 |
1894 |
| iter->current_value = &dict->entries[best_idx].value; |
| 461 |
1894 |
| iter->index = best_order + 1; |
| 462 |
1894 |
| return 1; |
| 463 |
|
| } |
| 464 |
|
| |
| 465 |
|
| /*---------------------------------------------------------------------------- |
| 466 |
|
| * Stream operations |
| 467 |
|
| *--------------------------------------------------------------------------*/ |
| 468 |
|
| |
| 469 |
1046 |
| pdfmake_obj_t pdfmake_stream_new(pdfmake_arena_t *arena) { |
| 470 |
1046 |
| pdfmake_obj_t obj = {0}; |
| 471 |
|
| pdfmake_stream_t *stream; |
| 472 |
|
| pdfmake_obj_t dict; |
| 473 |
1046 |
| obj.kind = PDFMAKE_STREAM; |
| 474 |
|
| |
| 475 |
1046 |
▶ | if (!arena) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arena) { |
0 |
1046 |
1046 |
|
| 476 |
0 |
| obj.as.stream = NULL; |
| 477 |
0 |
| return obj; |
| 478 |
|
| } |
| 479 |
|
| |
| 480 |
1046 |
| stream = pdfmake_arena_calloc(arena, sizeof(pdfmake_stream_t)); |
| 481 |
1046 |
▶ | if (!stream) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stream) { |
0 |
1046 |
1046 |
|
| 482 |
0 |
| obj.as.stream = NULL; |
| 483 |
0 |
| return obj; |
| 484 |
|
| } |
| 485 |
|
| |
| 486 |
|
| /* Initialize the stream's dict. */ |
| 487 |
1046 |
| dict = pdfmake_dict_new(arena); |
| 488 |
1046 |
▶ | if (dict.as.dict) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (dict.as.dict) { |
1046 |
0 |
1046 |
|
| 489 |
1046 |
| stream->dict = dict.as.dict; |
| 490 |
|
| } |
| 491 |
|
| |
| 492 |
1046 |
| stream->raw = NULL; |
| 493 |
1046 |
| stream->raw_len = 0; |
| 494 |
1046 |
| stream->filtered = 0; |
| 495 |
|
| |
| 496 |
1046 |
| obj.as.stream = stream; |
| 497 |
1046 |
| return obj; |
| 498 |
|
| } |
| 499 |
|
| |
| 500 |
994 |
| int pdfmake_stream_set_data(pdfmake_arena_t *arena, pdfmake_obj_t *stream_obj, |
| 501 |
|
| const uint8_t *data, size_t len) { |
| 502 |
|
| pdfmake_stream_t *stream; |
| 503 |
994 |
▶ | if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
994 |
0 |
994 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
994 |
0 |
994 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
994 |
0 |
994 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
0 |
994 |
994 |
|
| 504 |
0 |
| return 0; |
| 505 |
|
| } |
| 506 |
|
| |
| 507 |
994 |
| stream = stream_obj->as.stream; |
| 508 |
|
| |
| 509 |
994 |
▶ | if (data && len > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (data && len > 0) { |
994 |
0 |
994 |
| if (data && len > 0) { |
972 |
22 |
994 |
|
| 510 |
972 |
| uint8_t *dup = pdfmake_arena_memdup(arena, data, len); |
| 511 |
972 |
▶ | if (!dup) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dup) return 0; |
0 |
972 |
972 |
|
| 512 |
972 |
| stream->raw = dup; |
| 513 |
972 |
| stream->raw_len = (uint32_t)len; |
| 514 |
|
| } else { |
| 515 |
22 |
| stream->raw = NULL; |
| 516 |
22 |
| stream->raw_len = 0; |
| 517 |
|
| } |
| 518 |
|
| |
| 519 |
994 |
| return 1; |
| 520 |
|
| } |
| 521 |
|
| |
| 522 |
27 |
| pdfmake_dict_t *pdfmake_stream_dict(pdfmake_obj_t *stream_obj) { |
| 523 |
27 |
▶ | if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
27 |
0 |
27 |
| if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
27 |
0 |
27 |
| if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
0 |
27 |
27 |
|
| 524 |
0 |
| return NULL; |
| 525 |
|
| } |
| 526 |
27 |
| return stream_obj->as.stream->dict; |
| 527 |
|
| } |
| 528 |
|
| |
| 529 |
9 |
| int pdfmake_stream_set_flate(pdfmake_arena_t *arena, pdfmake_obj_t *stream_obj) { |
| 530 |
|
| pdfmake_stream_t *stream; |
| 531 |
|
| uint32_t filter_key; |
| 532 |
|
| pdfmake_obj_t filter_name; |
| 533 |
|
| pdfmake_obj_t dict_obj; |
| 534 |
9 |
▶ | if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
9 |
0 |
9 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
9 |
0 |
9 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
9 |
0 |
9 |
| if (!arena || !stream_obj || stream_obj->kind != PDFMAKE_STREAM || !stream_obj->as.stream) { |
0 |
9 |
9 |
|
| 535 |
0 |
| return 0; |
| 536 |
|
| } |
| 537 |
|
| |
| 538 |
9 |
| stream = stream_obj->as.stream; |
| 539 |
9 |
▶ | if (!stream->dict) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stream->dict) return 0; |
0 |
9 |
9 |
|
| 540 |
|
| |
| 541 |
|
| /* Set /Filter to /FlateDecode */ |
| 542 |
9 |
| filter_key = pdfmake_arena_intern_name(arena, "Filter", 6); |
| 543 |
9 |
▶ | if (filter_key == 0) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (filter_key == 0) return 0; |
0 |
9 |
9 |
|
| 544 |
|
| |
| 545 |
9 |
| filter_name = pdfmake_name_cstr(arena, "FlateDecode"); |
| 546 |
9 |
| dict_obj.kind = PDFMAKE_DICT; |
| 547 |
9 |
| dict_obj.as.dict = stream->dict; |
| 548 |
9 |
▶ | if (!pdfmake_dict_set(arena, &dict_obj, filter_key, filter_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pdfmake_dict_set(arena, &dict_obj, filter_key, filter_name)) { |
0 |
9 |
9 |
|
| 549 |
0 |
| return 0; |
| 550 |
|
| } |
| 551 |
|
| |
| 552 |
|
| /* Mark stream as needing compression (filtered=0 means raw data to encode) */ |
| 553 |
9 |
| stream->filtered = 0; |
| 554 |
9 |
| return 1; |
| 555 |
|
| } |
| 556 |
|
| |
| 557 |
|
| /*---------------------------------------------------------------------------- |
| 558 |
|
| * Type checking and accessors |
| 559 |
|
| *--------------------------------------------------------------------------*/ |
| 560 |
|
| |
| 561 |
2 |
| int pdfmake_is_null(pdfmake_obj_t *obj) { |
| 562 |
2 |
▶ | return obj && obj->kind == PDFMAKE_NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_NULL; |
2 |
0 |
2 |
| return obj && obj->kind == PDFMAKE_NULL; |
1 |
1 |
2 |
|
| 563 |
|
| } |
| 564 |
|
| |
| 565 |
2 |
| int pdfmake_is_bool(pdfmake_obj_t *obj) { |
| 566 |
2 |
▶ | return obj && obj->kind == PDFMAKE_BOOL; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_BOOL; |
2 |
0 |
2 |
| return obj && obj->kind == PDFMAKE_BOOL; |
1 |
1 |
2 |
|
| 567 |
|
| } |
| 568 |
|
| |
| 569 |
2 |
| int pdfmake_is_int(pdfmake_obj_t *obj) { |
| 570 |
2 |
▶ | return obj && obj->kind == PDFMAKE_INT; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_INT; |
2 |
0 |
2 |
| return obj && obj->kind == PDFMAKE_INT; |
1 |
1 |
2 |
|
| 571 |
|
| } |
| 572 |
|
| |
| 573 |
2 |
| int pdfmake_is_real(pdfmake_obj_t *obj) { |
| 574 |
2 |
▶ | return obj && obj->kind == PDFMAKE_REAL; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_REAL; |
2 |
0 |
2 |
| return obj && obj->kind == PDFMAKE_REAL; |
1 |
1 |
2 |
|
| 575 |
|
| } |
| 576 |
|
| |
| 577 |
3 |
| int pdfmake_is_numeric(pdfmake_obj_t *obj) { |
| 578 |
3 |
▶ | return obj && (obj->kind == PDFMAKE_INT || obj->kind == PDFMAKE_REAL); |
Branch: 3 branches
| Branch | True | False | Total |
| return obj && (obj->kind == PDFMAKE_INT || obj->kind == PDFMAKE_REAL); |
3 |
0 |
3 |
| return obj && (obj->kind == PDFMAKE_INT || obj->kind == PDFMAKE_REAL); |
2 |
1 |
3 |
| return obj && (obj->kind == PDFMAKE_INT || obj->kind == PDFMAKE_REAL); |
1 |
1 |
2 |
|
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
2 |
| int pdfmake_is_name(pdfmake_obj_t *obj) { |
| 582 |
2 |
▶ | return obj && obj->kind == PDFMAKE_NAME; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_NAME; |
2 |
0 |
2 |
| return obj && obj->kind == PDFMAKE_NAME; |
1 |
1 |
2 |
|
| 583 |
|
| } |
| 584 |
|
| |
| 585 |
3 |
| int pdfmake_is_str(pdfmake_obj_t *obj) { |
| 586 |
3 |
▶ | return obj && obj->kind == PDFMAKE_STR; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_STR; |
3 |
0 |
3 |
| return obj && obj->kind == PDFMAKE_STR; |
2 |
1 |
3 |
|
| 587 |
|
| } |
| 588 |
|
| |
| 589 |
3 |
| int pdfmake_is_array(pdfmake_obj_t *obj) { |
| 590 |
3 |
▶ | return obj && obj->kind == PDFMAKE_ARRAY; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_ARRAY; |
3 |
0 |
3 |
| return obj && obj->kind == PDFMAKE_ARRAY; |
1 |
2 |
3 |
|
| 591 |
|
| } |
| 592 |
|
| |
| 593 |
4 |
| int pdfmake_is_dict(pdfmake_obj_t *obj) { |
| 594 |
4 |
▶ | return obj && obj->kind == PDFMAKE_DICT; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_DICT; |
4 |
0 |
4 |
| return obj && obj->kind == PDFMAKE_DICT; |
1 |
3 |
4 |
|
| 595 |
|
| } |
| 596 |
|
| |
| 597 |
1 |
| int pdfmake_is_stream(pdfmake_obj_t *obj) { |
| 598 |
1 |
▶ | return obj && obj->kind == PDFMAKE_STREAM; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_STREAM; |
1 |
0 |
1 |
| return obj && obj->kind == PDFMAKE_STREAM; |
1 |
0 |
1 |
|
| 599 |
|
| } |
| 600 |
|
| |
| 601 |
1 |
| int pdfmake_is_ref(pdfmake_obj_t *obj) { |
| 602 |
1 |
▶ | return obj && obj->kind == PDFMAKE_REF; |
Branch: 2 branches
| Branch | True | False | Total |
| return obj && obj->kind == PDFMAKE_REF; |
1 |
0 |
1 |
| return obj && obj->kind == PDFMAKE_REF; |
1 |
0 |
1 |
|
| 603 |
|
| } |
| 604 |
|
| |
| 605 |
2 |
| int pdfmake_get_bool(pdfmake_obj_t *obj) { |
| 606 |
2 |
▶ | return (obj && obj->kind == PDFMAKE_BOOL) ? (int)obj->as.i : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return (obj && obj->kind == PDFMAKE_BOOL) ? (int)obj->as.i : 0; |
2 |
0 |
2 |
| return (obj && obj->kind == PDFMAKE_BOOL) ? (int)obj->as.i : 0; |
2 |
0 |
2 |
|
| 607 |
|
| } |
| 608 |
|
| |
| 609 |
7 |
| int64_t pdfmake_get_int(pdfmake_obj_t *obj) { |
| 610 |
7 |
▶ | if (!obj) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!obj) return 0; |
0 |
7 |
7 |
|
| 611 |
7 |
▶ | if (obj->kind == PDFMAKE_INT) return obj->as.i; |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj->kind == PDFMAKE_INT) return obj->as.i; |
7 |
0 |
7 |
|
| 612 |
0 |
▶ | if (obj->kind == PDFMAKE_REAL) return (int64_t)obj->as.r; |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj->kind == PDFMAKE_REAL) return (int64_t)obj->as.r; |
0 |
0 |
0 |
|
| 613 |
0 |
| return 0; |
| 614 |
|
| } |
| 615 |
|
| |
| 616 |
14 |
| double pdfmake_get_real(pdfmake_obj_t *obj) { |
| 617 |
14 |
▶ | if (!obj) return 0.0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!obj) return 0.0; |
0 |
14 |
14 |
|
| 618 |
14 |
▶ | if (obj->kind == PDFMAKE_REAL) return obj->as.r; |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj->kind == PDFMAKE_REAL) return obj->as.r; |
1 |
13 |
14 |
|
| 619 |
13 |
▶ | if (obj->kind == PDFMAKE_INT) return (double)obj->as.i; |
Branch: 1 branch
| Branch | True | False | Total |
| if (obj->kind == PDFMAKE_INT) return (double)obj->as.i; |
13 |
0 |
13 |
|
| 620 |
0 |
| return 0.0; |
| 621 |
|
| } |
| 622 |
|
| |
| 623 |
13 |
| double pdfmake_get_number(pdfmake_obj_t *obj) { |
| 624 |
13 |
| return pdfmake_get_real(obj); |
| 625 |
|
| } |
| 626 |
|
| |
| 627 |
386 |
| const char *pdfmake_get_name_bytes(pdfmake_arena_t *arena, pdfmake_obj_t *obj) { |
| 628 |
386 |
▶ | if (!arena || !obj || obj->kind != PDFMAKE_NAME) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!arena || !obj || obj->kind != PDFMAKE_NAME) return NULL; |
386 |
0 |
386 |
| if (!arena || !obj || obj->kind != PDFMAKE_NAME) return NULL; |
386 |
0 |
386 |
| if (!arena || !obj || obj->kind != PDFMAKE_NAME) return NULL; |
0 |
386 |
386 |
|
| 629 |
386 |
| return pdfmake_arena_name_bytes(arena, obj->as.name.id); |
| 630 |
|
| } |
| 631 |
|
| |
| 632 |
66 |
| const uint8_t *pdfmake_get_str_bytes(pdfmake_obj_t *obj, size_t *len_out) { |
| 633 |
66 |
▶ | if (!obj || obj->kind != PDFMAKE_STR) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!obj || obj->kind != PDFMAKE_STR) { |
66 |
0 |
66 |
| if (!obj || obj->kind != PDFMAKE_STR) { |
0 |
66 |
66 |
|
| 634 |
0 |
▶ | if (len_out) *len_out = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len_out) *len_out = 0; |
0 |
0 |
0 |
|
| 635 |
0 |
| return NULL; |
| 636 |
|
| } |
| 637 |
66 |
▶ | if (len_out) *len_out = obj->as.str.len; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len_out) *len_out = obj->as.str.len; |
66 |
0 |
66 |
|
| 638 |
66 |
| return obj->as.str.bytes; |
| 639 |
|
| } |
| 640 |
|
| |
| 641 |
0 |
| int pdfmake_str_is_hex(pdfmake_obj_t *obj) { |
| 642 |
0 |
▶ | return (obj && obj->kind == PDFMAKE_STR) ? obj->as.str.hex : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return (obj && obj->kind == PDFMAKE_STR) ? obj->as.str.hex : 0; |
0 |
0 |
0 |
| return (obj && obj->kind == PDFMAKE_STR) ? obj->as.str.hex : 0; |
0 |
0 |
0 |
|
| 643 |
|
| } |