File Coverage

src/pdfmake_content.c
Criterion Covered Total %
statement 446 539 82.7
branch 270 644 41.9
condition n/a
subroutine n/a
pod n/a
total 716 1183 60.5


line stmt bran cond sub pod time code
1             /*
2             * pdfmake_content.c — Content stream builder implementation.
3             *
4             * Implements all PDF content stream operators per Annex A.
5             * Each function appends the operator with its operands to a buffer.
6             */
7              
8             #include "pdfmake_content.h"
9             #include "pdfmake_writer.h"
10             #include
11             #include
12             #include
13              
14             /*----------------------------------------------------------------------------
15             * Internal helpers
16             *--------------------------------------------------------------------------*/
17              
18             /* Append a formatted number (removes trailing zeros for cleaner output). */
19 19653           static pdfmake_err_t append_number(pdfmake_buf_t *buf, double val)
20             {
21             char tmp[32];
22 19653           int len = pdfmake_format_real(tmp, val);
23 19653 50         if (len < 0) return PDFMAKE_EINVAL;
24 19653           return pdfmake_buf_append(buf, (const uint8_t *)tmp, (size_t)len);
25             }
26              
27             /* Append a name (with leading /). */
28 1251           static pdfmake_err_t append_name(pdfmake_buf_t *buf, const char *name)
29             {
30 1251 50         if (pdfmake_buf_append_byte(buf, '/') != PDFMAKE_OK) return PDFMAKE_EINVAL;
31 1251           return pdfmake_buf_append_cstr(buf, name);
32             }
33              
34             /* Append a space. */
35 22124           static PDFMAKE_INLINE pdfmake_err_t append_space(pdfmake_buf_t *buf)
36             {
37 22124           return pdfmake_buf_append_byte(buf, ' ');
38             }
39              
40             /* Append a newline. */
41 13451           static PDFMAKE_INLINE pdfmake_err_t append_newline(pdfmake_buf_t *buf)
42             {
43 13451           return pdfmake_buf_append_byte(buf, '\n');
44             }
45              
46             /* Append a simple operator (no operands). */
47 13451           static pdfmake_err_t append_op(pdfmake_buf_t *buf, const char *op)
48             {
49 13451 50         if (pdfmake_buf_append_cstr(buf, op) != PDFMAKE_OK) return PDFMAKE_EINVAL;
50 13451           return append_newline(buf);
51             }
52              
53             /* Append a PDF string (with escaping). */
54 1236           static pdfmake_err_t append_string(pdfmake_buf_t *buf,
55             const uint8_t *str, size_t len)
56             {
57             size_t i;
58 1236 50         if (pdfmake_buf_append_byte(buf, '(') != PDFMAKE_OK) return PDFMAKE_EINVAL;
59              
60 81927 100         for (i = 0; i < len; i++) {
61 80691           uint8_t ch = str[i];
62 80691           switch (ch) {
63 2           case '(':
64             case ')':
65             case '\\':
66 2 50         if (pdfmake_buf_append_byte(buf, '\\') != PDFMAKE_OK)
67 0           return PDFMAKE_EINVAL;
68 2 50         if (pdfmake_buf_append_byte(buf, ch) != PDFMAKE_OK)
69 0           return PDFMAKE_EINVAL;
70 2           break;
71 0           case '\n':
72 0 0         if (pdfmake_buf_append_cstr(buf, "\\n") != PDFMAKE_OK)
73 0           return PDFMAKE_EINVAL;
74 0           break;
75 0           case '\r':
76 0 0         if (pdfmake_buf_append_cstr(buf, "\\r") != PDFMAKE_OK)
77 0           return PDFMAKE_EINVAL;
78 0           break;
79 0           case '\t':
80 0 0         if (pdfmake_buf_append_cstr(buf, "\\t") != PDFMAKE_OK)
81 0           return PDFMAKE_EINVAL;
82 0           break;
83 80689           default:
84 80689 50         if (pdfmake_buf_append_byte(buf, ch) != PDFMAKE_OK)
85 0           return PDFMAKE_EINVAL;
86             }
87             }
88              
89 1236           return pdfmake_buf_append_byte(buf, ')');
90             }
91              
92             /*----------------------------------------------------------------------------
93             * Lifecycle
94             *--------------------------------------------------------------------------*/
95              
96 332           pdfmake_content_t *pdfmake_content_new(pdfmake_arena_t *arena)
97             {
98             pdfmake_content_t *c;
99 332 50         if (!arena) return NULL;
100              
101 332           c = malloc(sizeof(pdfmake_content_t));
102 332 50         if (!c) return NULL;
103              
104 332           c->arena = arena;
105 332 50         if (pdfmake_buf_init(&c->buf) != PDFMAKE_OK) {
106 0           free(c);
107 0           return NULL;
108             }
109              
110 332           return c;
111             }
112              
113 332           void pdfmake_content_free(pdfmake_content_t *c)
114             {
115 332 50         if (!c) return;
116 332           pdfmake_buf_free(&c->buf);
117 332           free(c);
118             }
119              
120 296           const uint8_t *pdfmake_content_data(pdfmake_content_t *c)
121             {
122 296 50         if (!c) return NULL;
123             /* Ensure null-termination for string use */
124 296 50         if (pdfmake_buf_append_byte(&c->buf, '\0') != PDFMAKE_OK)
125 0           return NULL;
126 296           c->buf.len--; /* Don't count the null in length */
127 296           return c->buf.data;
128             }
129              
130 301           size_t pdfmake_content_len(pdfmake_content_t *c)
131             {
132 301 50         return c ? c->buf.len : 0;
133             }
134              
135 41           void pdfmake_content_clear(pdfmake_content_t *c)
136             {
137 41 50         if (c) pdfmake_buf_clear(&c->buf);
138 41           }
139              
140             /*----------------------------------------------------------------------------
141             * General graphics state operators (§8.4.4)
142             *--------------------------------------------------------------------------*/
143              
144 125           pdfmake_err_t pdfmake_gs_q(pdfmake_content_t *c)
145             {
146 125 50         if (!c) return PDFMAKE_EINVAL;
147 125           return append_op(&c->buf, "q");
148             }
149              
150 125           pdfmake_err_t pdfmake_gs_Q(pdfmake_content_t *c)
151             {
152 125 50         if (!c) return PDFMAKE_EINVAL;
153 125           return append_op(&c->buf, "Q");
154             }
155              
156 23           pdfmake_err_t pdfmake_gs_cm(pdfmake_content_t *c,
157             double a, double b, double c_,
158             double d, double e, double f)
159             {
160             pdfmake_buf_t *buf;
161 23 50         if (!c) return PDFMAKE_EINVAL;
162 23           buf = &c->buf;
163              
164 23 50         if (append_number(buf, a) != PDFMAKE_OK) return PDFMAKE_EINVAL;
165 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
166 23 50         if (append_number(buf, b) != PDFMAKE_OK) return PDFMAKE_EINVAL;
167 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
168 23 50         if (append_number(buf, c_) != PDFMAKE_OK) return PDFMAKE_EINVAL;
169 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
170 23 50         if (append_number(buf, d) != PDFMAKE_OK) return PDFMAKE_EINVAL;
171 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
172 23 50         if (append_number(buf, e) != PDFMAKE_OK) return PDFMAKE_EINVAL;
173 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
174 23 50         if (append_number(buf, f) != PDFMAKE_OK) return PDFMAKE_EINVAL;
175 23 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
176 23           return append_op(buf, "cm");
177             }
178              
179 62           pdfmake_err_t pdfmake_gs_w(pdfmake_content_t *c, double width)
180             {
181             pdfmake_buf_t *buf;
182 62 50         if (!c) return PDFMAKE_EINVAL;
183 62           buf = &c->buf;
184              
185 62 50         if (append_number(buf, width) != PDFMAKE_OK) return PDFMAKE_EINVAL;
186 62 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
187 62           return append_op(buf, "w");
188             }
189              
190 18           pdfmake_err_t pdfmake_gs_J(pdfmake_content_t *c, int cap)
191             {
192             char tmp[16];
193 18 50         if (!c) return PDFMAKE_EINVAL;
194 18           snprintf(tmp, sizeof(tmp), "%d J\n", cap);
195 18           return pdfmake_buf_append_cstr(&c->buf, tmp);
196             }
197              
198 3           pdfmake_err_t pdfmake_gs_j(pdfmake_content_t *c, int join)
199             {
200             char tmp[16];
201 3 50         if (!c) return PDFMAKE_EINVAL;
202 3           snprintf(tmp, sizeof(tmp), "%d j\n", join);
203 3           return pdfmake_buf_append_cstr(&c->buf, tmp);
204             }
205              
206 3           pdfmake_err_t pdfmake_gs_M(pdfmake_content_t *c, double limit)
207             {
208             pdfmake_buf_t *buf;
209 3 50         if (!c) return PDFMAKE_EINVAL;
210 3           buf = &c->buf;
211              
212 3 50         if (append_number(buf, limit) != PDFMAKE_OK) return PDFMAKE_EINVAL;
213 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
214 3           return append_op(buf, "M");
215             }
216              
217 8           pdfmake_err_t pdfmake_gs_d(pdfmake_content_t *c,
218             const double *array, size_t count,
219             double phase)
220             {
221             pdfmake_buf_t *buf;
222             size_t i;
223 8 50         if (!c) return PDFMAKE_EINVAL;
224 8           buf = &c->buf;
225              
226 8 50         if (pdfmake_buf_append_byte(buf, '[') != PDFMAKE_OK) return PDFMAKE_EINVAL;
227 24 100         for (i = 0; i < count; i++) {
228 16 100         if (i > 0 && append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
    50          
229 16 50         if (append_number(buf, array[i]) != PDFMAKE_OK) return PDFMAKE_EINVAL;
230             }
231 8 50         if (pdfmake_buf_append_cstr(buf, "] ") != PDFMAKE_OK) return PDFMAKE_EINVAL;
232 8 50         if (append_number(buf, phase) != PDFMAKE_OK) return PDFMAKE_EINVAL;
233 8 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
234 8           return append_op(buf, "d");
235             }
236              
237 1           pdfmake_err_t pdfmake_gs_ri(pdfmake_content_t *c, const char *intent)
238             {
239             pdfmake_buf_t *buf;
240 1 50         if (!c || !intent) return PDFMAKE_EINVAL;
    50          
241 1           buf = &c->buf;
242              
243 1 50         if (append_name(buf, intent) != PDFMAKE_OK) return PDFMAKE_EINVAL;
244 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
245 1           return append_op(buf, "ri");
246             }
247              
248 1           pdfmake_err_t pdfmake_gs_i(pdfmake_content_t *c, double flatness)
249             {
250             pdfmake_buf_t *buf;
251 1 50         if (!c) return PDFMAKE_EINVAL;
252 1           buf = &c->buf;
253              
254 1 50         if (append_number(buf, flatness) != PDFMAKE_OK) return PDFMAKE_EINVAL;
255 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
256 1           return append_op(buf, "i");
257             }
258              
259 1           pdfmake_err_t pdfmake_gs_gs(pdfmake_content_t *c, const char *name)
260             {
261             pdfmake_buf_t *buf;
262 1 50         if (!c || !name) return PDFMAKE_EINVAL;
    50          
263 1           buf = &c->buf;
264              
265 1 50         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
266 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
267 1           return append_op(buf, "gs");
268             }
269              
270             /*----------------------------------------------------------------------------
271             * Path construction operators (§8.5.2)
272             *--------------------------------------------------------------------------*/
273              
274 1839           pdfmake_err_t pdfmake_path_m(pdfmake_content_t *c, double x, double y)
275             {
276             pdfmake_buf_t *buf;
277 1839 50         if (!c) return PDFMAKE_EINVAL;
278 1839           buf = &c->buf;
279              
280 1839 50         if (append_number(buf, x) != PDFMAKE_OK) return PDFMAKE_EINVAL;
281 1839 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
282 1839 50         if (append_number(buf, y) != PDFMAKE_OK) return PDFMAKE_EINVAL;
283 1839 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
284 1839           return append_op(buf, "m");
285             }
286              
287 1837           pdfmake_err_t pdfmake_path_l(pdfmake_content_t *c, double x, double y)
288             {
289             pdfmake_buf_t *buf;
290 1837 50         if (!c) return PDFMAKE_EINVAL;
291 1837           buf = &c->buf;
292              
293 1837 50         if (append_number(buf, x) != PDFMAKE_OK) return PDFMAKE_EINVAL;
294 1837 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
295 1837 50         if (append_number(buf, y) != PDFMAKE_OK) return PDFMAKE_EINVAL;
296 1837 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
297 1837           return append_op(buf, "l");
298             }
299              
300 13           pdfmake_err_t pdfmake_path_c(pdfmake_content_t *c,
301             double x1, double y1,
302             double x2, double y2,
303             double x3, double y3)
304             {
305             pdfmake_buf_t *buf;
306 13 50         if (!c) return PDFMAKE_EINVAL;
307 13           buf = &c->buf;
308              
309 13 50         if (append_number(buf, x1) != PDFMAKE_OK) return PDFMAKE_EINVAL;
310 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
311 13 50         if (append_number(buf, y1) != PDFMAKE_OK) return PDFMAKE_EINVAL;
312 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
313 13 50         if (append_number(buf, x2) != PDFMAKE_OK) return PDFMAKE_EINVAL;
314 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
315 13 50         if (append_number(buf, y2) != PDFMAKE_OK) return PDFMAKE_EINVAL;
316 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
317 13 50         if (append_number(buf, x3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
318 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
319 13 50         if (append_number(buf, y3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
320 13 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
321 13           return append_op(buf, "c");
322             }
323              
324 1           pdfmake_err_t pdfmake_path_v(pdfmake_content_t *c,
325             double x2, double y2,
326             double x3, double y3)
327             {
328             pdfmake_buf_t *buf;
329 1 50         if (!c) return PDFMAKE_EINVAL;
330 1           buf = &c->buf;
331              
332 1 50         if (append_number(buf, x2) != PDFMAKE_OK) return PDFMAKE_EINVAL;
333 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
334 1 50         if (append_number(buf, y2) != PDFMAKE_OK) return PDFMAKE_EINVAL;
335 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
336 1 50         if (append_number(buf, x3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
337 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
338 1 50         if (append_number(buf, y3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
339 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
340 1           return append_op(buf, "v");
341             }
342              
343 1           pdfmake_err_t pdfmake_path_y(pdfmake_content_t *c,
344             double x1, double y1,
345             double x3, double y3)
346             {
347             pdfmake_buf_t *buf;
348 1 50         if (!c) return PDFMAKE_EINVAL;
349 1           buf = &c->buf;
350              
351 1 50         if (append_number(buf, x1) != PDFMAKE_OK) return PDFMAKE_EINVAL;
352 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
353 1 50         if (append_number(buf, y1) != PDFMAKE_OK) return PDFMAKE_EINVAL;
354 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
355 1 50         if (append_number(buf, x3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
356 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
357 1 50         if (append_number(buf, y3) != PDFMAKE_OK) return PDFMAKE_EINVAL;
358 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
359 1           return append_op(buf, "y");
360             }
361              
362 82           pdfmake_err_t pdfmake_path_re(pdfmake_content_t *c,
363             double x, double y,
364             double width, double height)
365             {
366             pdfmake_buf_t *buf;
367 82 50         if (!c) return PDFMAKE_EINVAL;
368 82           buf = &c->buf;
369              
370 82 50         if (append_number(buf, x) != PDFMAKE_OK) return PDFMAKE_EINVAL;
371 82 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
372 82 50         if (append_number(buf, y) != PDFMAKE_OK) return PDFMAKE_EINVAL;
373 82 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
374 82 50         if (append_number(buf, width) != PDFMAKE_OK) return PDFMAKE_EINVAL;
375 82 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
376 82 50         if (append_number(buf, height) != PDFMAKE_OK) return PDFMAKE_EINVAL;
377 82 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
378 82           return append_op(buf, "re");
379             }
380              
381 2           pdfmake_err_t pdfmake_path_h(pdfmake_content_t *c)
382             {
383 2 50         if (!c) return PDFMAKE_EINVAL;
384 2           return append_op(&c->buf, "h");
385             }
386              
387             /*----------------------------------------------------------------------------
388             * Path painting operators (§8.5.3)
389             *--------------------------------------------------------------------------*/
390              
391 1870           pdfmake_err_t pdfmake_paint_S(pdfmake_content_t *c)
392             {
393 1870 50         if (!c) return PDFMAKE_EINVAL;
394 1870           return append_op(&c->buf, "S");
395             }
396              
397 2           pdfmake_err_t pdfmake_paint_s(pdfmake_content_t *c)
398             {
399 2 50         if (!c) return PDFMAKE_EINVAL;
400 2           return append_op(&c->buf, "s");
401             }
402              
403 51           pdfmake_err_t pdfmake_paint_f(pdfmake_content_t *c)
404             {
405 51 50         if (!c) return PDFMAKE_EINVAL;
406 51           return append_op(&c->buf, "f");
407             }
408              
409 1           pdfmake_err_t pdfmake_paint_f_star(pdfmake_content_t *c)
410             {
411 1 50         if (!c) return PDFMAKE_EINVAL;
412 1           return append_op(&c->buf, "f*");
413             }
414              
415 4           pdfmake_err_t pdfmake_paint_B(pdfmake_content_t *c)
416             {
417 4 50         if (!c) return PDFMAKE_EINVAL;
418 4           return append_op(&c->buf, "B");
419             }
420              
421 1           pdfmake_err_t pdfmake_paint_B_star(pdfmake_content_t *c)
422             {
423 1 50         if (!c) return PDFMAKE_EINVAL;
424 1           return append_op(&c->buf, "B*");
425             }
426              
427 1           pdfmake_err_t pdfmake_paint_b(pdfmake_content_t *c)
428             {
429 1 50         if (!c) return PDFMAKE_EINVAL;
430 1           return append_op(&c->buf, "b");
431             }
432              
433 1           pdfmake_err_t pdfmake_paint_b_star(pdfmake_content_t *c)
434             {
435 1 50         if (!c) return PDFMAKE_EINVAL;
436 1           return append_op(&c->buf, "b*");
437             }
438              
439 2           pdfmake_err_t pdfmake_paint_n(pdfmake_content_t *c)
440             {
441 2 50         if (!c) return PDFMAKE_EINVAL;
442 2           return append_op(&c->buf, "n");
443             }
444              
445             /*----------------------------------------------------------------------------
446             * Clipping operators (§8.5.4)
447             *--------------------------------------------------------------------------*/
448              
449 1           pdfmake_err_t pdfmake_clip_W(pdfmake_content_t *c)
450             {
451 1 50         if (!c) return PDFMAKE_EINVAL;
452 1           return append_op(&c->buf, "W");
453             }
454              
455 1           pdfmake_err_t pdfmake_clip_W_star(pdfmake_content_t *c)
456             {
457 1 50         if (!c) return PDFMAKE_EINVAL;
458 1           return append_op(&c->buf, "W*");
459             }
460              
461             /*----------------------------------------------------------------------------
462             * Colour operators (§8.6)
463             *--------------------------------------------------------------------------*/
464              
465 1           pdfmake_err_t pdfmake_color_CS(pdfmake_content_t *c, const char *name)
466             {
467             pdfmake_buf_t *buf;
468 1 50         if (!c || !name) return PDFMAKE_EINVAL;
    50          
469 1           buf = &c->buf;
470              
471 1 50         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
472 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
473 1           return append_op(buf, "CS");
474             }
475              
476 1           pdfmake_err_t pdfmake_color_cs(pdfmake_content_t *c, const char *name)
477             {
478             pdfmake_buf_t *buf;
479 1 50         if (!c || !name) return PDFMAKE_EINVAL;
    50          
480 1           buf = &c->buf;
481              
482 1 50         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
483 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
484 1           return append_op(buf, "cs");
485             }
486              
487 0           pdfmake_err_t pdfmake_color_SC(pdfmake_content_t *c,
488             const double *components, size_t count)
489             {
490             pdfmake_buf_t *buf;
491             size_t i;
492 0 0         if (!c || !components || count == 0) return PDFMAKE_EINVAL;
    0          
    0          
493 0           buf = &c->buf;
494              
495 0 0         for (i = 0; i < count; i++) {
496 0 0         if (append_number(buf, components[i]) != PDFMAKE_OK) return PDFMAKE_EINVAL;
497 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
498             }
499 0           return append_op(buf, "SC");
500             }
501              
502 0           pdfmake_err_t pdfmake_color_sc(pdfmake_content_t *c,
503             const double *components, size_t count)
504             {
505             pdfmake_buf_t *buf;
506             size_t i;
507 0 0         if (!c || !components || count == 0) return PDFMAKE_EINVAL;
    0          
    0          
508 0           buf = &c->buf;
509              
510 0 0         for (i = 0; i < count; i++) {
511 0 0         if (append_number(buf, components[i]) != PDFMAKE_OK) return PDFMAKE_EINVAL;
512 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
513             }
514 0           return append_op(buf, "sc");
515             }
516              
517 0           pdfmake_err_t pdfmake_color_SCN(pdfmake_content_t *c,
518             const double *components, size_t count,
519             const char *name)
520             {
521             pdfmake_buf_t *buf;
522             size_t i;
523 0 0         if (!c) return PDFMAKE_EINVAL;
524 0           buf = &c->buf;
525              
526 0 0         if (components && count > 0) {
    0          
527 0 0         for (i = 0; i < count; i++) {
528 0 0         if (append_number(buf, components[i]) != PDFMAKE_OK) return PDFMAKE_EINVAL;
529 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
530             }
531             }
532 0 0         if (name) {
533 0 0         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
534 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
535             }
536 0           return append_op(buf, "SCN");
537             }
538              
539 0           pdfmake_err_t pdfmake_color_scn(pdfmake_content_t *c,
540             const double *components, size_t count,
541             const char *name)
542             {
543             pdfmake_buf_t *buf;
544             size_t i;
545 0 0         if (!c) return PDFMAKE_EINVAL;
546 0           buf = &c->buf;
547              
548 0 0         if (components && count > 0) {
    0          
549 0 0         for (i = 0; i < count; i++) {
550 0 0         if (append_number(buf, components[i]) != PDFMAKE_OK) return PDFMAKE_EINVAL;
551 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
552             }
553             }
554 0 0         if (name) {
555 0 0         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
556 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
557             }
558 0           return append_op(buf, "scn");
559             }
560              
561 4           pdfmake_err_t pdfmake_color_G(pdfmake_content_t *c, double gray)
562             {
563             pdfmake_buf_t *buf;
564 4 50         if (!c) return PDFMAKE_EINVAL;
565 4           buf = &c->buf;
566              
567 4 50         if (append_number(buf, gray) != PDFMAKE_OK) return PDFMAKE_EINVAL;
568 4 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
569 4           return append_op(buf, "G");
570             }
571              
572 3           pdfmake_err_t pdfmake_color_g(pdfmake_content_t *c, double gray)
573             {
574             pdfmake_buf_t *buf;
575 3 50         if (!c) return PDFMAKE_EINVAL;
576 3           buf = &c->buf;
577              
578 3 50         if (append_number(buf, gray) != PDFMAKE_OK) return PDFMAKE_EINVAL;
579 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
580 3           return append_op(buf, "g");
581             }
582              
583 60           pdfmake_err_t pdfmake_color_RG(pdfmake_content_t *c,
584             double r, double g, double b)
585             {
586             pdfmake_buf_t *buf;
587 60 50         if (!c) return PDFMAKE_EINVAL;
588 60           buf = &c->buf;
589              
590 60 50         if (append_number(buf, r) != PDFMAKE_OK) return PDFMAKE_EINVAL;
591 60 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
592 60 50         if (append_number(buf, g) != PDFMAKE_OK) return PDFMAKE_EINVAL;
593 60 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
594 60 50         if (append_number(buf, b) != PDFMAKE_OK) return PDFMAKE_EINVAL;
595 60 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
596 60           return append_op(buf, "RG");
597             }
598              
599 1149           pdfmake_err_t pdfmake_color_rg(pdfmake_content_t *c,
600             double r, double g, double b)
601             {
602             pdfmake_buf_t *buf;
603 1149 50         if (!c) return PDFMAKE_EINVAL;
604 1149           buf = &c->buf;
605              
606 1149 50         if (append_number(buf, r) != PDFMAKE_OK) return PDFMAKE_EINVAL;
607 1149 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
608 1149 50         if (append_number(buf, g) != PDFMAKE_OK) return PDFMAKE_EINVAL;
609 1149 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
610 1149 50         if (append_number(buf, b) != PDFMAKE_OK) return PDFMAKE_EINVAL;
611 1149 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
612 1149           return append_op(buf, "rg");
613             }
614              
615 3           pdfmake_err_t pdfmake_color_K(pdfmake_content_t *c,
616             double c_, double m, double y, double k)
617             {
618             pdfmake_buf_t *buf;
619 3 50         if (!c) return PDFMAKE_EINVAL;
620 3           buf = &c->buf;
621              
622 3 50         if (append_number(buf, c_) != PDFMAKE_OK) return PDFMAKE_EINVAL;
623 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
624 3 50         if (append_number(buf, m) != PDFMAKE_OK) return PDFMAKE_EINVAL;
625 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
626 3 50         if (append_number(buf, y) != PDFMAKE_OK) return PDFMAKE_EINVAL;
627 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
628 3 50         if (append_number(buf, k) != PDFMAKE_OK) return PDFMAKE_EINVAL;
629 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
630 3           return append_op(buf, "K");
631             }
632              
633 3           pdfmake_err_t pdfmake_color_k(pdfmake_content_t *c,
634             double c_, double m, double y, double k)
635             {
636             pdfmake_buf_t *buf;
637 3 50         if (!c) return PDFMAKE_EINVAL;
638 3           buf = &c->buf;
639              
640 3 50         if (append_number(buf, c_) != PDFMAKE_OK) return PDFMAKE_EINVAL;
641 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
642 3 50         if (append_number(buf, m) != PDFMAKE_OK) return PDFMAKE_EINVAL;
643 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
644 3 50         if (append_number(buf, y) != PDFMAKE_OK) return PDFMAKE_EINVAL;
645 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
646 3 50         if (append_number(buf, k) != PDFMAKE_OK) return PDFMAKE_EINVAL;
647 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
648 3           return append_op(buf, "k");
649             }
650              
651             /*----------------------------------------------------------------------------
652             * Text object operators (§9.4)
653             *--------------------------------------------------------------------------*/
654              
655 1223           pdfmake_err_t pdfmake_text_BT(pdfmake_content_t *c)
656             {
657 1223 50         if (!c) return PDFMAKE_EINVAL;
658 1223           return append_op(&c->buf, "BT");
659             }
660              
661 1223           pdfmake_err_t pdfmake_text_ET(pdfmake_content_t *c)
662             {
663 1223 50         if (!c) return PDFMAKE_EINVAL;
664 1223           return append_op(&c->buf, "ET");
665             }
666              
667             /*----------------------------------------------------------------------------
668             * Text state operators (§9.3)
669             *--------------------------------------------------------------------------*/
670              
671 1           pdfmake_err_t pdfmake_text_Tc(pdfmake_content_t *c, double spacing)
672             {
673             pdfmake_buf_t *buf;
674 1 50         if (!c) return PDFMAKE_EINVAL;
675 1           buf = &c->buf;
676              
677 1 50         if (append_number(buf, spacing) != PDFMAKE_OK) return PDFMAKE_EINVAL;
678 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
679 1           return append_op(buf, "Tc");
680             }
681              
682 1           pdfmake_err_t pdfmake_text_Tw(pdfmake_content_t *c, double spacing)
683             {
684             pdfmake_buf_t *buf;
685 1 50         if (!c) return PDFMAKE_EINVAL;
686 1           buf = &c->buf;
687              
688 1 50         if (append_number(buf, spacing) != PDFMAKE_OK) return PDFMAKE_EINVAL;
689 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
690 1           return append_op(buf, "Tw");
691             }
692              
693 1           pdfmake_err_t pdfmake_text_Tz(pdfmake_content_t *c, double scale)
694             {
695             pdfmake_buf_t *buf;
696 1 50         if (!c) return PDFMAKE_EINVAL;
697 1           buf = &c->buf;
698              
699 1 50         if (append_number(buf, scale) != PDFMAKE_OK) return PDFMAKE_EINVAL;
700 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
701 1           return append_op(buf, "Tz");
702             }
703              
704 4           pdfmake_err_t pdfmake_text_TL(pdfmake_content_t *c, double leading)
705             {
706             pdfmake_buf_t *buf;
707 4 50         if (!c) return PDFMAKE_EINVAL;
708 4           buf = &c->buf;
709              
710 4 50         if (append_number(buf, leading) != PDFMAKE_OK) return PDFMAKE_EINVAL;
711 4 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
712 4           return append_op(buf, "TL");
713             }
714              
715 1212           pdfmake_err_t pdfmake_text_Tf(pdfmake_content_t *c,
716             const char *font_name, double size)
717             {
718             pdfmake_buf_t *buf;
719 1212 50         if (!c || !font_name) return PDFMAKE_EINVAL;
    50          
720 1212           buf = &c->buf;
721              
722 1212 50         if (append_name(buf, font_name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
723 1212 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
724 1212 50         if (append_number(buf, size) != PDFMAKE_OK) return PDFMAKE_EINVAL;
725 1212 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
726 1212           return append_op(buf, "Tf");
727             }
728              
729 3           pdfmake_err_t pdfmake_text_Tr(pdfmake_content_t *c, int mode)
730             {
731             char tmp[16];
732 3 50         if (!c) return PDFMAKE_EINVAL;
733 3           snprintf(tmp, sizeof(tmp), "%d Tr\n", mode);
734 3           return pdfmake_buf_append_cstr(&c->buf, tmp);
735             }
736              
737 3           pdfmake_err_t pdfmake_text_Ts(pdfmake_content_t *c, double rise)
738             {
739             pdfmake_buf_t *buf;
740 3 50         if (!c) return PDFMAKE_EINVAL;
741 3           buf = &c->buf;
742              
743 3 50         if (append_number(buf, rise) != PDFMAKE_OK) return PDFMAKE_EINVAL;
744 3 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
745 3           return append_op(buf, "Ts");
746             }
747              
748             /*----------------------------------------------------------------------------
749             * Text positioning operators (§9.4.2)
750             *--------------------------------------------------------------------------*/
751              
752 149           pdfmake_err_t pdfmake_text_Td(pdfmake_content_t *c, double tx, double ty)
753             {
754             pdfmake_buf_t *buf;
755 149 50         if (!c) return PDFMAKE_EINVAL;
756 149           buf = &c->buf;
757              
758 149 50         if (append_number(buf, tx) != PDFMAKE_OK) return PDFMAKE_EINVAL;
759 149 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
760 149 50         if (append_number(buf, ty) != PDFMAKE_OK) return PDFMAKE_EINVAL;
761 149 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
762 149           return append_op(buf, "Td");
763             }
764              
765 1           pdfmake_err_t pdfmake_text_TD(pdfmake_content_t *c, double tx, double ty)
766             {
767             pdfmake_buf_t *buf;
768 1 50         if (!c) return PDFMAKE_EINVAL;
769 1           buf = &c->buf;
770              
771 1 50         if (append_number(buf, tx) != PDFMAKE_OK) return PDFMAKE_EINVAL;
772 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
773 1 50         if (append_number(buf, ty) != PDFMAKE_OK) return PDFMAKE_EINVAL;
774 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
775 1           return append_op(buf, "TD");
776             }
777              
778 1079           pdfmake_err_t pdfmake_text_Tm(pdfmake_content_t *c,
779             double a, double b, double c_,
780             double d, double e, double f)
781             {
782             pdfmake_buf_t *buf;
783 1079 50         if (!c) return PDFMAKE_EINVAL;
784 1079           buf = &c->buf;
785              
786 1079 50         if (append_number(buf, a) != PDFMAKE_OK) return PDFMAKE_EINVAL;
787 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
788 1079 50         if (append_number(buf, b) != PDFMAKE_OK) return PDFMAKE_EINVAL;
789 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
790 1079 50         if (append_number(buf, c_) != PDFMAKE_OK) return PDFMAKE_EINVAL;
791 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
792 1079 50         if (append_number(buf, d) != PDFMAKE_OK) return PDFMAKE_EINVAL;
793 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
794 1079 50         if (append_number(buf, e) != PDFMAKE_OK) return PDFMAKE_EINVAL;
795 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
796 1079 50         if (append_number(buf, f) != PDFMAKE_OK) return PDFMAKE_EINVAL;
797 1079 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
798 1079           return append_op(buf, "Tm");
799             }
800              
801 2           pdfmake_err_t pdfmake_text_Tstar(pdfmake_content_t *c)
802             {
803 2 50         if (!c) return PDFMAKE_EINVAL;
804 2           return append_op(&c->buf, "T*");
805             }
806              
807             /*----------------------------------------------------------------------------
808             * Text showing operators (§9.4.3)
809             *--------------------------------------------------------------------------*/
810              
811 1229           pdfmake_err_t pdfmake_text_Tj(pdfmake_content_t *c,
812             const uint8_t *str, size_t len)
813             {
814             pdfmake_buf_t *buf;
815 1229 50         if (!c || !str) return PDFMAKE_EINVAL;
    50          
816 1229           buf = &c->buf;
817              
818 1229 50         if (append_string(buf, str, len) != PDFMAKE_OK) return PDFMAKE_EINVAL;
819 1229 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
820 1229           return append_op(buf, "Tj");
821             }
822              
823 0           pdfmake_err_t pdfmake_text_Tj_cstr(pdfmake_content_t *c, const char *str)
824             {
825 0 0         if (!str) return PDFMAKE_EINVAL;
826 0           return pdfmake_text_Tj(c, (const uint8_t *)str, strlen(str));
827             }
828              
829 2           pdfmake_err_t pdfmake_text_TJ(pdfmake_content_t *c, pdfmake_obj_t *array)
830             {
831             pdfmake_buf_t *buf;
832             size_t len;
833             size_t i;
834 2 50         if (!c || !array) return PDFMAKE_EINVAL;
    50          
835 2 50         if (array->kind != PDFMAKE_ARRAY) return PDFMAKE_EINVAL;
836              
837 2           buf = &c->buf;
838              
839 2 50         if (pdfmake_buf_append_byte(buf, '[') != PDFMAKE_OK) return PDFMAKE_EINVAL;
840              
841 2           len = pdfmake_array_len(array);
842 10 100         for (i = 0; i < len; i++) {
843 8           pdfmake_obj_t *elem = pdfmake_array_get(array, i);
844 8 50         if (!elem) continue;
845              
846 8 100         if (elem->kind == PDFMAKE_STR) {
847 5 50         if (append_string(buf, elem->as.str.bytes, elem->as.str.len)
848 0           != PDFMAKE_OK) return PDFMAKE_EINVAL;
849 3 50         } else if (elem->kind == PDFMAKE_INT) {
850             char tmp[32];
851 0           snprintf(tmp, sizeof(tmp), "%ld", (long)elem->as.i);
852 0 0         if (pdfmake_buf_append_cstr(buf, tmp) != PDFMAKE_OK) return PDFMAKE_EINVAL;
853 3 50         } else if (elem->kind == PDFMAKE_REAL) {
854 3 50         if (append_number(buf, elem->as.r) != PDFMAKE_OK) return PDFMAKE_EINVAL;
855             }
856             }
857              
858 2 50         if (pdfmake_buf_append_cstr(buf, "] TJ\n") != PDFMAKE_OK) return PDFMAKE_EINVAL;
859 2           return PDFMAKE_OK;
860             }
861              
862 1           pdfmake_err_t pdfmake_text_apostrophe(pdfmake_content_t *c,
863             const uint8_t *str, size_t len)
864             {
865             pdfmake_buf_t *buf;
866 1 50         if (!c || !str) return PDFMAKE_EINVAL;
    50          
867 1           buf = &c->buf;
868              
869 1 50         if (append_string(buf, str, len) != PDFMAKE_OK) return PDFMAKE_EINVAL;
870 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
871 1           return append_op(buf, "'");
872             }
873              
874 1           pdfmake_err_t pdfmake_text_quote(pdfmake_content_t *c,
875             double aw, double ac,
876             const uint8_t *str, size_t len)
877             {
878             pdfmake_buf_t *buf;
879 1 50         if (!c || !str) return PDFMAKE_EINVAL;
    50          
880 1           buf = &c->buf;
881              
882 1 50         if (append_number(buf, aw) != PDFMAKE_OK) return PDFMAKE_EINVAL;
883 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
884 1 50         if (append_number(buf, ac) != PDFMAKE_OK) return PDFMAKE_EINVAL;
885 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
886 1 50         if (append_string(buf, str, len) != PDFMAKE_OK) return PDFMAKE_EINVAL;
887 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
888 1           return append_op(buf, "\"");
889             }
890              
891             /*----------------------------------------------------------------------------
892             * XObject operator (§8.8)
893             *--------------------------------------------------------------------------*/
894              
895 19           pdfmake_err_t pdfmake_xobj_Do(pdfmake_content_t *c, const char *name)
896             {
897             pdfmake_buf_t *buf;
898 19 50         if (!c || !name) return PDFMAKE_EINVAL;
    50          
899 19           buf = &c->buf;
900              
901 19 50         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
902 19 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
903 19           return append_op(buf, "Do");
904             }
905              
906             /*----------------------------------------------------------------------------
907             * Marked content operators (§14.6)
908             *--------------------------------------------------------------------------*/
909              
910 0           pdfmake_err_t pdfmake_mc_MP(pdfmake_content_t *c, const char *tag)
911             {
912             pdfmake_buf_t *buf;
913 0 0         if (!c || !tag) return PDFMAKE_EINVAL;
    0          
914 0           buf = &c->buf;
915              
916 0 0         if (append_name(buf, tag) != PDFMAKE_OK) return PDFMAKE_EINVAL;
917 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
918 0           return append_op(buf, "MP");
919             }
920              
921 0           pdfmake_err_t pdfmake_mc_DP(pdfmake_content_t *c,
922             const char *tag, const char *props)
923             {
924             pdfmake_buf_t *buf;
925 0 0         if (!c || !tag || !props) return PDFMAKE_EINVAL;
    0          
    0          
926 0           buf = &c->buf;
927              
928 0 0         if (append_name(buf, tag) != PDFMAKE_OK) return PDFMAKE_EINVAL;
929 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
930 0 0         if (append_name(buf, props) != PDFMAKE_OK) return PDFMAKE_EINVAL;
931 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
932 0           return append_op(buf, "DP");
933             }
934              
935 1           pdfmake_err_t pdfmake_mc_BMC(pdfmake_content_t *c, const char *tag)
936             {
937             pdfmake_buf_t *buf;
938 1 50         if (!c || !tag) return PDFMAKE_EINVAL;
    50          
939 1           buf = &c->buf;
940              
941 1 50         if (append_name(buf, tag) != PDFMAKE_OK) return PDFMAKE_EINVAL;
942 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
943 1           return append_op(buf, "BMC");
944             }
945              
946 7           pdfmake_err_t pdfmake_mc_BDC(pdfmake_content_t *c,
947             const char *tag, const char *props)
948             {
949             pdfmake_buf_t *buf;
950 7 50         if (!c || !tag || !props) return PDFMAKE_EINVAL;
    50          
    50          
951 7           buf = &c->buf;
952              
953 7 50         if (append_name(buf, tag) != PDFMAKE_OK) return PDFMAKE_EINVAL;
954 7 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
955 7 50         if (append_name(buf, props) != PDFMAKE_OK) return PDFMAKE_EINVAL;
956 7 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
957 7           return append_op(buf, "BDC");
958             }
959              
960 8           pdfmake_err_t pdfmake_mc_EMC(pdfmake_content_t *c)
961             {
962 8 50         if (!c) return PDFMAKE_EINVAL;
963 8           return append_op(&c->buf, "EMC");
964             }
965              
966             /*----------------------------------------------------------------------------
967             * Shading operator (§8.7.4)
968             *--------------------------------------------------------------------------*/
969              
970 1           pdfmake_err_t pdfmake_sh(pdfmake_content_t *c, const char *name)
971             {
972             pdfmake_buf_t *buf;
973 1 50         if (!c || !name) return PDFMAKE_EINVAL;
    50          
974 1           buf = &c->buf;
975              
976 1 50         if (append_name(buf, name) != PDFMAKE_OK) return PDFMAKE_EINVAL;
977 1 50         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
978 1           return append_op(buf, "sh");
979             }
980              
981             /*----------------------------------------------------------------------------
982             * Inline image operators (§8.9.7)
983             *--------------------------------------------------------------------------*/
984              
985 0           pdfmake_err_t pdfmake_inline_BI(pdfmake_content_t *c)
986             {
987 0 0         if (!c) return PDFMAKE_EINVAL;
988 0           return append_op(&c->buf, "BI");
989             }
990              
991 0           pdfmake_err_t pdfmake_inline_key(pdfmake_content_t *c,
992             const char *key, const char *value)
993             {
994             pdfmake_buf_t *buf;
995 0 0         if (!c || !key || !value) return PDFMAKE_EINVAL;
    0          
    0          
996 0           buf = &c->buf;
997              
998 0 0         if (append_name(buf, key) != PDFMAKE_OK) return PDFMAKE_EINVAL;
999 0 0         if (append_space(buf) != PDFMAKE_OK) return PDFMAKE_EINVAL;
1000             /* Value might be a name or integer - just pass through */
1001 0 0         if (pdfmake_buf_append_cstr(buf, value) != PDFMAKE_OK) return PDFMAKE_EINVAL;
1002 0           return append_newline(buf);
1003             }
1004              
1005 0           pdfmake_err_t pdfmake_inline_ID(pdfmake_content_t *c)
1006             {
1007 0 0         if (!c) return PDFMAKE_EINVAL;
1008             /* ID followed by single space before data */
1009 0           return pdfmake_buf_append_cstr(&c->buf, "ID ");
1010             }
1011              
1012 0           pdfmake_err_t pdfmake_inline_data(pdfmake_content_t *c,
1013             const uint8_t *data, size_t len)
1014             {
1015 0 0         if (!c || !data) return PDFMAKE_EINVAL;
    0          
1016 0           return pdfmake_buf_append(&c->buf, data, len);
1017             }
1018              
1019 0           pdfmake_err_t pdfmake_inline_EI(pdfmake_content_t *c)
1020             {
1021 0 0         if (!c) return PDFMAKE_EINVAL;
1022             /* Single space before EI per spec */
1023 0           return pdfmake_buf_append_cstr(&c->buf, " EI\n");
1024             }
1025              
1026             /*----------------------------------------------------------------------------
1027             * Compatibility operators (§8.4.5)
1028             *--------------------------------------------------------------------------*/
1029              
1030 1           pdfmake_err_t pdfmake_compat_BX(pdfmake_content_t *c)
1031             {
1032 1 50         if (!c) return PDFMAKE_EINVAL;
1033 1           return append_op(&c->buf, "BX");
1034             }
1035              
1036 1           pdfmake_err_t pdfmake_compat_EX(pdfmake_content_t *c)
1037             {
1038 1 50         if (!c) return PDFMAKE_EINVAL;
1039 1           return append_op(&c->buf, "EX");
1040             }