include/pdfmake_meta.h

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 24 / 24 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/pdfmake_internal.h ↑ Summary include/pdfmake_tokenizer.h »
1 /*
2 * pdfmake_meta.h — Document Information Dictionary (§14.3.3).
3 *
4 * Provides functions to set and get standard metadata fields like
5 * Title, Author, Subject, Keywords, Creator, Producer, CreationDate,
6 * ModDate, and Trapped.
7 *
8 * PDF date format (§7.9.4): D:YYYYMMDDHHmmSSOHH'mm'
9 * - YYYY = year, MM = month (01-12), DD = day (01-31)
10 * - HH = hour (00-23), mm = minute (00-59), SS = second (00-59)
11 * - O = timezone relation (+, -, Z)
12 * - HH'mm' = timezone offset hours and minutes
13 */
14  
15 #ifndef PDFMAKE_META_H
16 #define PDFMAKE_META_H
17  
18 #include "pdfmake_types.h"
19 #include "pdfmake_doc.h"
20 #include <time.h>
21  
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25  
26 /*----------------------------------------------------------------------------
27 * Standard metadata keys (§14.3.3)
28 *--------------------------------------------------------------------------*/
29  
30 #define PDFMAKE_META_TITLE "Title"
31 #define PDFMAKE_META_AUTHOR "Author"
32 #define PDFMAKE_META_SUBJECT "Subject"
33 #define PDFMAKE_META_KEYWORDS "Keywords"
34 #define PDFMAKE_META_CREATOR "Creator"
35 #define PDFMAKE_META_PRODUCER "Producer"
36 #define PDFMAKE_META_CREATION_DATE "CreationDate"
37 #define PDFMAKE_META_MOD_DATE "ModDate"
38 #define PDFMAKE_META_TRAPPED "Trapped"
39  
40 /*----------------------------------------------------------------------------
41 * PDF date formatting (§7.9.4)
42 *--------------------------------------------------------------------------*/
43  
44 /*
45 * Format a time_t as a PDF date string: D:YYYYMMDDHHmmSSOHH'mm'
46 * Uses local timezone. Buffer must be at least 24 bytes.
47 * Returns pointer to buf on success, NULL on error.
48 */
49 char *pdfmake_format_date(time_t t, char *buf, size_t buflen);
50  
51 /*
52 * Format a time_t as a PDF date string in UTC: D:YYYYMMDDHHMMSSZ
53 * Buffer must be at least 18 bytes.
54 * Returns pointer to buf on success, NULL on error.
55 */
56 char *pdfmake_format_date_utc(time_t t, char *buf, size_t buflen);
57  
58 /*----------------------------------------------------------------------------
59 * Generic metadata set/get
60 *--------------------------------------------------------------------------*/
61  
62 /*
63 * Set a metadata field on the document's /Info dictionary.
64 * Creates the /Info dictionary if it doesn't exist.
65 * Key should be one of the standard keys (Title, Author, etc.).
66 * Value is a string; dates should use pdfmake_format_date().
67 * Returns PDFMAKE_OK on success.
68 */
69 pdfmake_err_t pdfmake_meta_set(pdfmake_doc_t *doc, const char *key, const char *value);
70  
71 /*
72 * Get a metadata field from the document's /Info dictionary.
73 * Returns the string value, or NULL if not set or key not found.
74 * The returned string is owned by the document and must not be freed.
75 */
76 const char *pdfmake_meta_get(pdfmake_doc_t *doc, const char *key);
77  
78 /*----------------------------------------------------------------------------
79 * Convenience setters (string fields)
80 *--------------------------------------------------------------------------*/
81  
82 67 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_title(pdfmake_doc_t *doc, const char *v) {
83 67 return pdfmake_meta_set(doc, PDFMAKE_META_TITLE, v);
84 }
85  
86 57 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_author(pdfmake_doc_t *doc, const char *v) {
87 57 return pdfmake_meta_set(doc, PDFMAKE_META_AUTHOR, v);
88 }
89  
90 47 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_subject(pdfmake_doc_t *doc, const char *v) {
91 47 return pdfmake_meta_set(doc, PDFMAKE_META_SUBJECT, v);
92 }
93  
94 4 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_keywords(pdfmake_doc_t *doc, const char *v) {
95 4 return pdfmake_meta_set(doc, PDFMAKE_META_KEYWORDS, v);
96 }
97  
98 3 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_creator(pdfmake_doc_t *doc, const char *v) {
99 3 return pdfmake_meta_set(doc, PDFMAKE_META_CREATOR, v);
100 }
101  
102 4 static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_producer(pdfmake_doc_t *doc, const char *v) {
103 4 return pdfmake_meta_set(doc, PDFMAKE_META_PRODUCER, v);
104 }
105  
106 /*----------------------------------------------------------------------------
107 * Convenience setters (date fields)
108 *--------------------------------------------------------------------------*/
109  
110 /*
111 * Set CreationDate from a time_t value.
112 * Formats as PDF date string with local timezone.
113 */
114 pdfmake_err_t pdfmake_meta_set_creation_date(pdfmake_doc_t *doc, time_t t);
115  
116 /*
117 * Set ModDate from a time_t value.
118 * Formats as PDF date string with local timezone.
119 */
120 pdfmake_err_t pdfmake_meta_set_mod_date(pdfmake_doc_t *doc, time_t t);
121  
122 /*----------------------------------------------------------------------------
123 * Convenience getters
124 *--------------------------------------------------------------------------*/
125  
126 49 static PDFMAKE_INLINE const char *pdfmake_meta_get_title(pdfmake_doc_t *doc) {
127 49 return pdfmake_meta_get(doc, PDFMAKE_META_TITLE);
128 }
129  
130 4 static PDFMAKE_INLINE const char *pdfmake_meta_get_author(pdfmake_doc_t *doc) {
131 4 return pdfmake_meta_get(doc, PDFMAKE_META_AUTHOR);
132 }
133  
134 3 static PDFMAKE_INLINE const char *pdfmake_meta_get_subject(pdfmake_doc_t *doc) {
135 3 return pdfmake_meta_get(doc, PDFMAKE_META_SUBJECT);
136 }
137  
138 3 static PDFMAKE_INLINE const char *pdfmake_meta_get_keywords(pdfmake_doc_t *doc) {
139 3 return pdfmake_meta_get(doc, PDFMAKE_META_KEYWORDS);
140 }
141  
142 3 static PDFMAKE_INLINE const char *pdfmake_meta_get_creator(pdfmake_doc_t *doc) {
143 3 return pdfmake_meta_get(doc, PDFMAKE_META_CREATOR);
144 }
145  
146 2 static PDFMAKE_INLINE const char *pdfmake_meta_get_producer(pdfmake_doc_t *doc) {
147 2 return pdfmake_meta_get(doc, PDFMAKE_META_PRODUCER);
148 }
149  
150 static PDFMAKE_INLINE const char *pdfmake_meta_get_creation_date(pdfmake_doc_t *doc) {
151 return pdfmake_meta_get(doc, PDFMAKE_META_CREATION_DATE);
152 }
153  
154 static PDFMAKE_INLINE const char *pdfmake_meta_get_mod_date(pdfmake_doc_t *doc) {
155 return pdfmake_meta_get(doc, PDFMAKE_META_MOD_DATE);
156 }
157  
158 /*----------------------------------------------------------------------------
159 * Trapped field (name value, not string)
160 *--------------------------------------------------------------------------*/
161  
162 typedef enum {
163 PDFMAKE_TRAPPED_UNKNOWN = 0,
164 PDFMAKE_TRAPPED_TRUE = 1,
165 PDFMAKE_TRAPPED_FALSE = 2
166 } pdfmake_trapped_t;
167  
168 pdfmake_err_t pdfmake_meta_set_trapped(pdfmake_doc_t *doc, pdfmake_trapped_t trapped);
169 pdfmake_trapped_t pdfmake_meta_get_trapped(pdfmake_doc_t *doc);
170  
171 /*----------------------------------------------------------------------------
172 * Auto-metadata (called during write)
173 *--------------------------------------------------------------------------*/
174  
175 /*
176 * Set Producer to "PDF-Make/VERSION" if not already set.
177 * Set CreationDate to current time if not already set.
178 * Set ModDate to current time.
179 * Called automatically by pdfmake_doc_write().
180 */
181 void pdfmake_meta_auto_fill(pdfmake_doc_t *doc);
182  
183 /*
184 * Resolve SOURCE_DATE_EPOCH. Returns 1 and writes the epoch to *out when the
185 * variable holds a valid non-negative integer, 0 otherwise. Callers fall back
186 * to time(NULL). Used by the metadata auto-fill and by /ID generation so that
187 * a render is byte-reproducible when the variable is set.
188 */
189 int pdfmake_source_date(time_t *out);
190  
191 /*
192 * Override how SOURCE_DATE_EPOCH is resolved.
193 *
194 * The engine is plain C and reads it with getenv(). That is the process
195 * environment, which is not where an embedding host necessarily keeps the
196 * variable: under PERL_IMPLICIT_SYS (every Strawberry perl) the interpreter
197 * has its own environment table, so a perl that sets SOURCE_DATE_EPOCH leaves
198 * the C runtime's getenv() returning NULL and every timestamp falls back to
199 * the wall clock.
200 *
201 * The hook returns 1 and writes the epoch when it resolves one, 0 otherwise;
202 * it is consulted before getenv(). Pass NULL to go back to getenv() alone.
203 */
204 typedef int (*pdfmake_source_date_hook_t)(time_t *out);
205 void pdfmake_set_source_date_hook(pdfmake_source_date_hook_t hook);
206  
207 #ifdef __cplusplus
208 }
209 #endif
210  
211 #endif /* PDFMAKE_META_H */
« include/pdfmake_internal.h ↑ Summary include/pdfmake_tokenizer.h »