page_print 0.1.1-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +247 -0
  4. data/ext/page_print/extconf.rb +48 -0
  5. data/ext/page_print/page_print.c +851 -0
  6. data/lib/page_print/page_print.so +0 -0
  7. data/lib/page_print/rails_resource_fetcher.rb +138 -0
  8. data/lib/page_print/railtie.rb +15 -0
  9. data/lib/page_print/vendor/x86_64-linux/include/plutobook/plutobook.h +1101 -0
  10. data/lib/page_print/vendor/x86_64-linux/include/plutobook/plutobook.hpp +1361 -0
  11. data/lib/page_print/vendor/x86_64-linux/lib/libX11.so.6 +0 -0
  12. data/lib/page_print/vendor/x86_64-linux/lib/libXau.so.6 +0 -0
  13. data/lib/page_print/vendor/x86_64-linux/lib/libXdmcp.so.6 +0 -0
  14. data/lib/page_print/vendor/x86_64-linux/lib/libXext.so.6 +0 -0
  15. data/lib/page_print/vendor/x86_64-linux/lib/libXrender.so.1 +0 -0
  16. data/lib/page_print/vendor/x86_64-linux/lib/libbrotlicommon.so.1 +0 -0
  17. data/lib/page_print/vendor/x86_64-linux/lib/libbrotlidec.so.1 +0 -0
  18. data/lib/page_print/vendor/x86_64-linux/lib/libbsd.so.0 +0 -0
  19. data/lib/page_print/vendor/x86_64-linux/lib/libbz2.so.1.0 +0 -0
  20. data/lib/page_print/vendor/x86_64-linux/lib/libcairo.so.2 +0 -0
  21. data/lib/page_print/vendor/x86_64-linux/lib/libcrypt.so.1 +0 -0
  22. data/lib/page_print/vendor/x86_64-linux/lib/libexpat.so.1 +0 -0
  23. data/lib/page_print/vendor/x86_64-linux/lib/libfontconfig.so.1 +0 -0
  24. data/lib/page_print/vendor/x86_64-linux/lib/libfreetype.so.6 +0 -0
  25. data/lib/page_print/vendor/x86_64-linux/lib/libglib-2.0.so.0 +0 -0
  26. data/lib/page_print/vendor/x86_64-linux/lib/libgmp.so.10 +0 -0
  27. data/lib/page_print/vendor/x86_64-linux/lib/libgraphite2.so.3 +0 -0
  28. data/lib/page_print/vendor/x86_64-linux/lib/libharfbuzz.so.0 +0 -0
  29. data/lib/page_print/vendor/x86_64-linux/lib/libicudata.so.74 +0 -0
  30. data/lib/page_print/vendor/x86_64-linux/lib/libicui18n.so.74 +0 -0
  31. data/lib/page_print/vendor/x86_64-linux/lib/libicuuc.so.74 +0 -0
  32. data/lib/page_print/vendor/x86_64-linux/lib/libmd.so.0 +0 -0
  33. data/lib/page_print/vendor/x86_64-linux/lib/libpcre2-8.so.0 +0 -0
  34. data/lib/page_print/vendor/x86_64-linux/lib/libpixman-1.so.0 +0 -0
  35. data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so +0 -0
  36. data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so.0 +0 -0
  37. data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so.0.17.0 +0 -0
  38. data/lib/page_print/vendor/x86_64-linux/lib/libpng16.so.16 +0 -0
  39. data/lib/page_print/vendor/x86_64-linux/lib/libruby.so.3.4 +0 -0
  40. data/lib/page_print/vendor/x86_64-linux/lib/libxcb-render.so.0 +0 -0
  41. data/lib/page_print/vendor/x86_64-linux/lib/libxcb-shm.so.0 +0 -0
  42. data/lib/page_print/vendor/x86_64-linux/lib/libxcb.so.1 +0 -0
  43. data/lib/page_print/vendor/x86_64-linux/lib/libz.so.1 +0 -0
  44. data/lib/page_print/vendor/x86_64-linux/lib/pkgconfig/plutobook.pc +10 -0
  45. data/lib/page_print/version.rb +3 -0
  46. data/lib/page_print.rb +28 -0
  47. metadata +89 -0
@@ -0,0 +1,1101 @@
1
+ /*
2
+ * Copyright (c) 2022-2026 Samuel Ugochukwu <sammycageagle@gmail.com>
3
+ *
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
+ */
8
+
9
+ #ifndef PLUTOBOOK_H
10
+ #define PLUTOBOOK_H
11
+
12
+ #include <stdbool.h>
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ #if !defined(PLUTOBOOK_BUILD_STATIC) && (defined(_WIN32) || defined(__CYGWIN__))
19
+ #define PLUTOBOOK_EXPORT __declspec(dllexport)
20
+ #define PLUTOBOOK_IMPORT __declspec(dllimport)
21
+ #elif defined(__GNUC__) && (__GNUC__ >= 4)
22
+ #define PLUTOBOOK_EXPORT __attribute__((__visibility__("default")))
23
+ #define PLUTOBOOK_IMPORT
24
+ #else
25
+ #define PLUTOBOOK_EXPORT
26
+ #define PLUTOBOOK_IMPORT
27
+ #endif
28
+
29
+ #ifdef PLUTOBOOK_BUILD
30
+ #define PLUTOBOOK_API PLUTOBOOK_EXPORT
31
+ #else
32
+ #define PLUTOBOOK_API PLUTOBOOK_IMPORT
33
+ #endif
34
+
35
+ #if defined(__GNUC__) && (__GNUC__ > 2)
36
+ #define PLUTOBOOK_PRINTF_FORMAT(fmt_index, va_index) __attribute__((format(printf, fmt_index, va_index)))
37
+ #else
38
+ #define PLUTOBOOK_PRINTF_FORMAT(fmt_index, va_index)
39
+ #endif
40
+
41
+ #define PLUTOBOOK_VERSION_MAJOR 0
42
+ #define PLUTOBOOK_VERSION_MINOR 17
43
+ #define PLUTOBOOK_VERSION_MICRO 0
44
+
45
+ #define PLUTOBOOK_VERSION_ENCODE(major, minor, micro) (((major) * 10000) + ((minor) * 100) + ((micro) * 1))
46
+ #define PLUTOBOOK_VERSION PLUTOBOOK_VERSION_ENCODE(PLUTOBOOK_VERSION_MAJOR, PLUTOBOOK_VERSION_MINOR, PLUTOBOOK_VERSION_MICRO)
47
+
48
+ #define PLUTOBOOK_VERSION_XSTRINGIZE(major, minor, micro) #major"."#minor"."#micro
49
+ #define PLUTOBOOK_VERSION_STRINGIZE(major, minor, micro) PLUTOBOOK_VERSION_XSTRINGIZE(major, minor, micro)
50
+ #define PLUTOBOOK_VERSION_STRING PLUTOBOOK_VERSION_STRINGIZE(PLUTOBOOK_VERSION_MAJOR, PLUTOBOOK_VERSION_MINOR, PLUTOBOOK_VERSION_MICRO)
51
+
52
+ /**
53
+ * @brief Returns the version of the plutobook library encoded in a single integer.
54
+ *
55
+ * This function retrieves the version of the plutobook library and encodes it into a single integer.
56
+ * The version number is represented in a format suitable for comparison.
57
+ *
58
+ * @return The version of the plutobook library encoded in a single integer.
59
+ */
60
+ PLUTOBOOK_API int plutobook_version(void);
61
+
62
+ /**
63
+ * @brief Returns the version of the plutobook library as a human-readable string in the format "X.Y.Z".
64
+ *
65
+ * This function retrieves the version of the plutobook library and returns it as a human-readable string
66
+ * in the format "X.Y.Z", where X represents the major version, Y represents the minor version, and Z represents
67
+ * the patch version.
68
+ *
69
+ * @return A pointer to a string containing the version of the plutobook library in the format "X.Y.Z".
70
+ */
71
+ PLUTOBOOK_API const char* plutobook_version_string(void);
72
+
73
+ /**
74
+ * @brief Returns a string containing the build metadata of the plutobook library.
75
+ * @return A pointer to a string containing the build metadata of the plutobook library.
76
+ */
77
+ PLUTOBOOK_API const char* plutobook_build_info(void);
78
+
79
+ /**
80
+ * This macro defines an index that is guaranteed to exceed the valid page count.
81
+ * It is typically utilized as a sentinel value to represent an unbounded or maximum value, indicating
82
+ * that there is no limit or that the maximum possible value is intended.
83
+ */
84
+ #define PLUTOBOOK_MAX_PAGE_COUNT 0xFFFFFFFFU
85
+
86
+ /**
87
+ * This macro defines an index that is guaranteed to be below the valid page count.
88
+ * It is typically utilized as a sentinel value to represent an unbounded or minimum value, indicating
89
+ * that there is no lower limit or that the minimum possible value is intended.
90
+ */
91
+ #define PLUTOBOOK_MIN_PAGE_COUNT 0x00000000U
92
+
93
+ /**
94
+ * Defines conversion factors for various units to points (pt) and vice versa.
95
+ * These conversion factors allow easy conversion between different units and points.
96
+ *
97
+ * Example Usage:
98
+ * - To convert 12 inches to points: 12 * PLUTOBOOK_UNITS_IN
99
+ * - To convert 12 points to inches: 12 / PLUTOBOOK_UNITS_IN
100
+ */
101
+ #define PLUTOBOOK_UNITS_PT 1.f
102
+ #define PLUTOBOOK_UNITS_PC 12.f
103
+ #define PLUTOBOOK_UNITS_IN 72.f
104
+ #define PLUTOBOOK_UNITS_CM (72.f / 2.54f)
105
+ #define PLUTOBOOK_UNITS_MM (72.f / 25.4f)
106
+ #define PLUTOBOOK_UNITS_PX (72.f / 96.0f)
107
+
108
+ #ifdef __cplusplus
109
+ #define PLUTOBOOK_MAKE_STRUCT(type, ...) type{__VA_ARGS__}
110
+ #else
111
+ #define PLUTOBOOK_MAKE_STRUCT(type, ...) (type){__VA_ARGS__}
112
+ #endif
113
+
114
+ /**
115
+ * @brief Defines the dimensions of a page in points (1/72 inch).
116
+ */
117
+ typedef struct _plutobook_page_size {
118
+ float width; /**< Page width in points */
119
+ float height; /**< Page height in points */
120
+ } plutobook_page_size_t;
121
+
122
+ #define PLUTOBOOK_MAKE_PAGE_SIZE(width, height) PLUTOBOOK_MAKE_STRUCT(plutobook_page_size_t, width, height)
123
+
124
+ /**
125
+ * @brief Predefined macros for common paper sizes.
126
+ */
127
+ #define PLUTOBOOK_PAGE_SIZE_NAMED(name) PLUTOBOOK_MAKE_PAGE_SIZE(PLUTOBOOK_PAGE_WIDTH_##name, PLUTOBOOK_PAGE_HEIGHT_##name)
128
+
129
+ #define PLUTOBOOK_PAGE_WIDTH_NONE 0.f
130
+ #define PLUTOBOOK_PAGE_HEIGHT_NONE 0.f
131
+ #define PLUTOBOOK_PAGE_SIZE_NONE PLUTOBOOK_PAGE_SIZE_NAMED(NONE)
132
+
133
+ #define PLUTOBOOK_PAGE_WIDTH_A3 (297 * PLUTOBOOK_UNITS_MM)
134
+ #define PLUTOBOOK_PAGE_HEIGHT_A3 (420 * PLUTOBOOK_UNITS_MM)
135
+ #define PLUTOBOOK_PAGE_SIZE_A3 PLUTOBOOK_PAGE_SIZE_NAMED(A3)
136
+
137
+ #define PLUTOBOOK_PAGE_WIDTH_A4 (210 * PLUTOBOOK_UNITS_MM)
138
+ #define PLUTOBOOK_PAGE_HEIGHT_A4 (297 * PLUTOBOOK_UNITS_MM)
139
+ #define PLUTOBOOK_PAGE_SIZE_A4 PLUTOBOOK_PAGE_SIZE_NAMED(A4)
140
+
141
+ #define PLUTOBOOK_PAGE_WIDTH_A5 (148 * PLUTOBOOK_UNITS_MM)
142
+ #define PLUTOBOOK_PAGE_HEIGHT_A5 (210 * PLUTOBOOK_UNITS_MM)
143
+ #define PLUTOBOOK_PAGE_SIZE_A5 PLUTOBOOK_PAGE_SIZE_NAMED(A5)
144
+
145
+ #define PLUTOBOOK_PAGE_WIDTH_B4 (250 * PLUTOBOOK_UNITS_MM)
146
+ #define PLUTOBOOK_PAGE_HEIGHT_B4 (353 * PLUTOBOOK_UNITS_MM)
147
+ #define PLUTOBOOK_PAGE_SIZE_B4 PLUTOBOOK_PAGE_SIZE_NAMED(B4)
148
+
149
+ #define PLUTOBOOK_PAGE_WIDTH_B5 (176 * PLUTOBOOK_UNITS_MM)
150
+ #define PLUTOBOOK_PAGE_HEIGHT_B5 (250 * PLUTOBOOK_UNITS_MM)
151
+ #define PLUTOBOOK_PAGE_SIZE_B5 PLUTOBOOK_PAGE_SIZE_NAMED(B5)
152
+
153
+ #define PLUTOBOOK_PAGE_WIDTH_LETTER (8.5f * PLUTOBOOK_UNITS_IN)
154
+ #define PLUTOBOOK_PAGE_HEIGHT_LETTER (11 * PLUTOBOOK_UNITS_IN)
155
+ #define PLUTOBOOK_PAGE_SIZE_LETTER PLUTOBOOK_PAGE_SIZE_NAMED(LETTER)
156
+
157
+ #define PLUTOBOOK_PAGE_WIDTH_LEGAL (8.5f * PLUTOBOOK_UNITS_IN)
158
+ #define PLUTOBOOK_PAGE_HEIGHT_LEGAL (14 * PLUTOBOOK_UNITS_IN)
159
+ #define PLUTOBOOK_PAGE_SIZE_LEGAL PLUTOBOOK_PAGE_SIZE_NAMED(LEGAL)
160
+
161
+ #define PLUTOBOOK_PAGE_WIDTH_LEDGER (11 * PLUTOBOOK_UNITS_IN)
162
+ #define PLUTOBOOK_PAGE_HEIGHT_LEDGER (17 * PLUTOBOOK_UNITS_IN)
163
+ #define PLUTOBOOK_PAGE_SIZE_LEDGER PLUTOBOOK_PAGE_SIZE_NAMED(LEDGER)
164
+
165
+ /**
166
+ * @brief Defines the margins of a page in points (1/72 inch).
167
+ */
168
+ typedef struct _plutobook_page_margins {
169
+ float top; /**< Top margin in points */
170
+ float right; /**< Right margin in points */
171
+ float bottom; /**< Bottom margin in points */
172
+ float left; /**< Left margin in points */
173
+ } plutobook_page_margins_t;
174
+
175
+ #define PLUTOBOOK_MAKE_PAGE_MARGINS(top, right, bottom, left) PLUTOBOOK_MAKE_STRUCT(plutobook_page_margins_t, top, right, bottom, left)
176
+
177
+ /**
178
+ * @brief Predefined macros for common margin settings.
179
+ */
180
+ #define PLUTOBOOK_PAGE_MARGINS_NONE PLUTOBOOK_MAKE_PAGE_MARGINS(0, 0, 0, 0)
181
+ #define PLUTOBOOK_PAGE_MARGINS_NORMAL PLUTOBOOK_MAKE_PAGE_MARGINS(72, 72, 72, 72)
182
+ #define PLUTOBOOK_PAGE_MARGINS_NARROW PLUTOBOOK_MAKE_PAGE_MARGINS(36, 36, 36, 36)
183
+ #define PLUTOBOOK_PAGE_MARGINS_MODERATE PLUTOBOOK_MAKE_PAGE_MARGINS(72, 54, 72, 54)
184
+ #define PLUTOBOOK_PAGE_MARGINS_WIDE PLUTOBOOK_MAKE_PAGE_MARGINS(72, 144, 72, 144)
185
+
186
+ /**
187
+ * @brief Defines status codes that indicate the result of a stream operation.
188
+ */
189
+ typedef enum _plutobook_stream_status {
190
+ PLUTOBOOK_STREAM_STATUS_SUCCESS = 0,
191
+ PLUTOBOOK_STREAM_STATUS_READ_ERROR = 10,
192
+ PLUTOBOOK_STREAM_STATUS_WRITE_ERROR = 11,
193
+ } plutobook_stream_status_t;
194
+
195
+ /**
196
+ * @brief This type represents a function called when writing data to an output stream.
197
+ *
198
+ * @param closure user-defined closure for the callback.
199
+ * @param data buffer containing the data to write.
200
+ * @param length the number of bytes to write.
201
+ * @return `PLUTOBOOK_STREAM_STATUS_SUCCESS` on success, or `PLUTOBOOK_STREAM_STATUS_WRITE_ERROR` on failure.
202
+ */
203
+ typedef plutobook_stream_status_t (*plutobook_stream_write_callback_t)(void* closure, const char* data, unsigned int length);
204
+
205
+ typedef struct _cairo_surface cairo_surface_t;
206
+ typedef struct _cairo cairo_t;
207
+
208
+ /**
209
+ * @brief Represents a 2D drawing interface for creating and manipulating graphical content.
210
+ */
211
+ typedef struct _plutobook_canvas plutobook_canvas_t;
212
+
213
+ /**
214
+ * @brief Destroys the canvas and frees its associated resources.
215
+ *
216
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
217
+ */
218
+ PLUTOBOOK_API void plutobook_canvas_destroy(plutobook_canvas_t* canvas);
219
+
220
+ /**
221
+ * @brief Flushes any pending drawing operations on the canvas.
222
+ *
223
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
224
+ */
225
+ PLUTOBOOK_API void plutobook_canvas_flush(plutobook_canvas_t* canvas);
226
+
227
+ /**
228
+ * @brief Finishes all drawing operations and performs cleanup on the canvas.
229
+ *
230
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
231
+ */
232
+ PLUTOBOOK_API void plutobook_canvas_finish(plutobook_canvas_t* canvas);
233
+
234
+ /**
235
+ * @brief Translates the canvas by a given offset, moving its origin.
236
+ *
237
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
238
+ * @param tx The horizontal translation offset.
239
+ * @param ty The vertical translation offset.
240
+ */
241
+ PLUTOBOOK_API void plutobook_canvas_translate(plutobook_canvas_t* canvas, float tx, float ty);
242
+
243
+ /**
244
+ * @brief Scales the canvas by the specified factors in the horizontal and vertical directions.
245
+ *
246
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
247
+ * @param sx The scaling factor in the horizontal direction.
248
+ * @param sy The scaling factor in the vertical direction.
249
+ */
250
+ PLUTOBOOK_API void plutobook_canvas_scale(plutobook_canvas_t* canvas, float sx, float sy);
251
+
252
+ /**
253
+ * @brief Rotates the canvas around the current origin by the specified angle.
254
+ *
255
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
256
+ * @param angle The rotation angle in radians.
257
+ */
258
+ PLUTOBOOK_API void plutobook_canvas_rotate(plutobook_canvas_t* canvas, float angle);
259
+
260
+ /**
261
+ * @brief Multiplies the current transformation matrix with the specified matrix.
262
+ *
263
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
264
+ * @param a The horizontal scaling factor.
265
+ * @param b The horizontal skewing factor.
266
+ * @param c The vertical skewing factor.
267
+ * @param d The vertical scaling factor.
268
+ * @param e The horizontal translation offset.
269
+ * @param f The vertical translation offset.
270
+ */
271
+ PLUTOBOOK_API void plutobook_canvas_transform(plutobook_canvas_t* canvas, float a, float b, float c, float d, float e, float f);
272
+
273
+ /**
274
+ * @brief Resets the transformation matrix to the specified matrix.
275
+ *
276
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
277
+ * @param a The horizontal scaling factor.
278
+ * @param b The horizontal skewing factor.
279
+ * @param c The vertical skewing factor.
280
+ * @param d The vertical scaling factor.
281
+ * @param e The horizontal translation offset.
282
+ * @param f The vertical translation offset.
283
+ */
284
+ PLUTOBOOK_API void plutobook_canvas_set_matrix(plutobook_canvas_t* canvas, float a, float b, float c, float d, float e, float f);
285
+
286
+ /**
287
+ * @brief Resets the current transformation matrix to the identity matrix.
288
+ *
289
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
290
+ */
291
+ PLUTOBOOK_API void plutobook_canvas_reset_matrix(plutobook_canvas_t* canvas);
292
+
293
+ /**
294
+ * @brief Intersects the current clip region with the specified rectangle.
295
+ *
296
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
297
+ * @param x The x-coordinate of the rectangle’s top-left corner.
298
+ * @param y The y-coordinate of the rectangle’s top-left corner.
299
+ * @param width The width of the rectangle.
300
+ * @param height The height of the rectangle.
301
+ */
302
+ PLUTOBOOK_API void plutobook_canvas_clip_rect(plutobook_canvas_t* canvas, float x, float y, float width, float height);
303
+
304
+ /**
305
+ * @brief Clears the canvas surface with the specified color.
306
+ *
307
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
308
+ * @param red The red component of the color, in the range [0, 1].
309
+ * @param green The green component of the color, in the range [0, 1].
310
+ * @param blue The blue component of the color, in the range [0, 1].
311
+ * @param alpha The alpha (transparency) component of the color, in the range [0, 1].
312
+ */
313
+ PLUTOBOOK_API void plutobook_canvas_clear_surface(plutobook_canvas_t* canvas, float red, float green, float blue, float alpha);
314
+
315
+ /**
316
+ * @brief Saves the current state of the canvas.
317
+ *
318
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
319
+ */
320
+ PLUTOBOOK_API void plutobook_canvas_save_state(plutobook_canvas_t* canvas);
321
+
322
+ /**
323
+ * @brief Restores the most recently saved state of the canvas.
324
+ *
325
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
326
+ */
327
+ PLUTOBOOK_API void plutobook_canvas_restore_state(plutobook_canvas_t* canvas);
328
+
329
+ /**
330
+ * @brief Gets the underlying cairo surface associated with the canvas.
331
+ *
332
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
333
+ * @return A pointer to the underlying `cairo_surface_t` object.
334
+ */
335
+ PLUTOBOOK_API cairo_surface_t* plutobook_canvas_get_surface(const plutobook_canvas_t* canvas);
336
+
337
+ /**
338
+ * @brief Gets the underlying cairo context associated with the canvas.
339
+ *
340
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
341
+ * @return A pointer to the underlying `cairo_t` object.
342
+ */
343
+ PLUTOBOOK_API cairo_t* plutobook_canvas_get_context(const plutobook_canvas_t* canvas);
344
+
345
+ /**
346
+ * @brief Defines different memory formats for image data.
347
+ */
348
+ typedef enum _plutobook_image_format {
349
+ PLUTOBOOK_IMAGE_FORMAT_INVALID = -1,
350
+ PLUTOBOOK_IMAGE_FORMAT_ARGB32 = 0,
351
+ PLUTOBOOK_IMAGE_FORMAT_RGB24 = 1,
352
+ PLUTOBOOK_IMAGE_FORMAT_A8 = 2,
353
+ PLUTOBOOK_IMAGE_FORMAT_A1 = 3
354
+ } plutobook_image_format_t;
355
+
356
+ /**
357
+ * @brief Creates a new canvas for drawing to image data with the specified dimensions and format.
358
+ *
359
+ * @param width The width of the image in pixels.
360
+ * @param height The height of the image in pixels.
361
+ * @param format The image format used for the canvas.
362
+ * @return A pointer to a newly created `plutobook_canvas_t` object, or `NULL` on failure.
363
+ */
364
+ PLUTOBOOK_API plutobook_canvas_t* plutobook_image_canvas_create(int width, int height, plutobook_image_format_t format);
365
+
366
+ /**
367
+ * @brief Creates a new canvas for drawing to existing image data.
368
+ *
369
+ * @param data A pointer to the raw image data.
370
+ * @param width The width of the image in pixels.
371
+ * @param height The height of the image in pixels.
372
+ * @param stride The number of bytes in one row of the image, including padding.
373
+ * @param format The image format used for the canvas.
374
+ * @return A pointer to a newly created `plutobook_canvas_t` object, or `NULL` on failure.
375
+ */
376
+ PLUTOBOOK_API plutobook_canvas_t* plutobook_image_canvas_create_for_data(
377
+ unsigned char* data, int width, int height, int stride, plutobook_image_format_t format);
378
+
379
+ /**
380
+ * @brief Retrieves the image data from the canvas.
381
+ *
382
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
383
+ * @return A pointer to the image data.
384
+ */
385
+ PLUTOBOOK_API unsigned char* plutobook_image_canvas_get_data(const plutobook_canvas_t* canvas);
386
+
387
+ /**
388
+ * @brief Retrieves the format of the image data on the canvas.
389
+ *
390
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
391
+ * @return The image format of the canvas.
392
+ */
393
+ PLUTOBOOK_API plutobook_image_format_t plutobook_image_canvas_get_format(const plutobook_canvas_t* canvas);
394
+
395
+ /**
396
+ * @brief Retrieves the width of the image data on the canvas.
397
+ *
398
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
399
+ * @return The width of the canvas image in pixels.
400
+ */
401
+ PLUTOBOOK_API int plutobook_image_canvas_get_width(const plutobook_canvas_t* canvas);
402
+
403
+ /**
404
+ * @brief Retrieves the height of the image data on the canvas.
405
+ *
406
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
407
+ * @return The height of the canvas image in pixels.
408
+ */
409
+ PLUTOBOOK_API int plutobook_image_canvas_get_height(const plutobook_canvas_t* canvas);
410
+
411
+ /**
412
+ * @brief Retrieves the stride (the number of bytes per row) of the image data on the canvas.
413
+ *
414
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
415
+ * @return The stride of the canvas image in bytes.
416
+ */
417
+ PLUTOBOOK_API int plutobook_image_canvas_get_stride(const plutobook_canvas_t* canvas);
418
+
419
+ /**
420
+ * @brief Writes the image data from the canvas to a PNG file.
421
+ *
422
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
423
+ * @param filename The path to the file where the PNG image will be saved.
424
+ * @return `true` on success, or `false` on failure.
425
+ */
426
+ PLUTOBOOK_API bool plutobook_image_canvas_write_to_png(const plutobook_canvas_t* canvas, const char* filename);
427
+
428
+ /**
429
+ * @brief Writes the image data from the canvas to a PNG stream using a custom write callback.
430
+ *
431
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
432
+ * @param callback The callback function for writing the image data to a stream.
433
+ * @param closure A user-defined closure passed to the callback.
434
+ * @return `true` on success, or `false` on failure.
435
+ */
436
+ PLUTOBOOK_API bool plutobook_image_canvas_write_to_png_stream(const plutobook_canvas_t* canvas,
437
+ plutobook_stream_write_callback_t callback, void* closure);
438
+
439
+ /**
440
+ * @brief Defines different metadata fields for a PDF document.
441
+ */
442
+ typedef enum _plutobook_pdf_metadata {
443
+ PLUTOBOOK_PDF_METADATA_TITLE,
444
+ PLUTOBOOK_PDF_METADATA_AUTHOR,
445
+ PLUTOBOOK_PDF_METADATA_SUBJECT,
446
+ PLUTOBOOK_PDF_METADATA_KEYWORDS,
447
+ PLUTOBOOK_PDF_METADATA_CREATOR,
448
+ PLUTOBOOK_PDF_METADATA_CREATION_DATE,
449
+ PLUTOBOOK_PDF_METADATA_MODIFICATION_DATE
450
+ } plutobook_pdf_metadata_t;
451
+
452
+ /**
453
+ * @brief Creates a new canvas for generating a PDF file.
454
+ *
455
+ * @param filename A path to the output PDF file.
456
+ * @param size The page size for the PDF.
457
+ * @return A pointer to a newly created `plutobook_canvas_t` object, or `NULL` on failure.
458
+ */
459
+ PLUTOBOOK_API plutobook_canvas_t* plutobook_pdf_canvas_create(const char* filename, plutobook_page_size_t size);
460
+
461
+ /**
462
+ * @brief Creates a new canvas for generating a PDF and writes it to a stream.
463
+ *
464
+ * @param callback A callback function to write the data to a stream.
465
+ * @param closure A user-defined pointer passed to the callback function.
466
+ * @param size The page size for the PDF.
467
+ * @return A pointer to a newly created `plutobook_canvas_t` object, or `NULL` on failure.
468
+ */
469
+ PLUTOBOOK_API plutobook_canvas_t* plutobook_pdf_canvas_create_for_stream(
470
+ plutobook_stream_write_callback_t callback, void* closure, plutobook_page_size_t size);
471
+
472
+ /**
473
+ * @brief Sets the metadata of the PDF document.
474
+ *
475
+ * The `PDF_METADATA_CREATION_DATE` and `PDF_METADATA_MODIFICATION_DATE` values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss.
476
+ * An optional timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended. All other metadata values can be any string.
477
+ *
478
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
479
+ * @param metadata The metadata type to set.
480
+ * @param value The value of the metadata field.
481
+ */
482
+ PLUTOBOOK_API void plutobook_pdf_canvas_set_metadata(plutobook_canvas_t* canvas, plutobook_pdf_metadata_t metadata, const char* value);
483
+
484
+ /**
485
+ * @brief Sets the size of the PDF page.
486
+ *
487
+ * This function should only be called before any drawing operations are performed on the current page.
488
+ * The simplest way to do this is by calling this function immediately after creating the canvas or
489
+ * immediately after completing a page with `plutobook_pdf_canvas_show_page`.
490
+ *
491
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
492
+ * @param size The desired size of the PDF page.
493
+ */
494
+ PLUTOBOOK_API void plutobook_pdf_canvas_set_size(plutobook_canvas_t* canvas, plutobook_page_size_t size);
495
+
496
+ /**
497
+ * @brief Finalizes the current page and prepares the canvas for a new page.
498
+ *
499
+ * @param canvas A pointer to a `plutobook_canvas_t` object.
500
+ */
501
+ PLUTOBOOK_API void plutobook_pdf_canvas_show_page(plutobook_canvas_t* canvas);
502
+
503
+ /**
504
+ * @brief A callback function type for resource data destruction.
505
+ *
506
+ * @param data A pointer to the resource data to be destroyed.
507
+ */
508
+ typedef void (*plutobook_resource_destroy_callback_t)(void* data);
509
+
510
+ /**
511
+ * @brief A structure representing the resource data.
512
+ */
513
+ typedef struct _plutobook_resource_data plutobook_resource_data_t;
514
+
515
+ /**
516
+ * @brief Creates a new `plutobook_resource_data_t` object by copying the provided content.
517
+ *
518
+ * @param content The content of the resource.
519
+ * @param content_length The length of the content in bytes.
520
+ * @param mime_type The MIME type of the content.
521
+ * @param text_encoding The text encoding used for the content.
522
+ * @return A pointer to a newly created `plutobook_resource_data_t` object, or `NULL` on failure.
523
+ */
524
+ PLUTOBOOK_API plutobook_resource_data_t* plutobook_resource_data_create(const char* content, unsigned int content_length,
525
+ const char* mime_type, const char* text_encoding);
526
+
527
+ /**
528
+ * @brief Creates a new `plutobook_resource_data_t` object using the provided content "as is", and uses the
529
+ * `destroy_callback` to free the resource when it's no longer needed.
530
+ *
531
+ * @param content The content of the resource.
532
+ * @param content_length The length of the content in bytes.
533
+ * @param mime_type The MIME type of the content.
534
+ * @param text_encoding The text encoding used for the content.
535
+ * @param destroy_callback A callback function that will be called to free the resource when it's no longer needed.
536
+ * @param closure A user-defined pointer that will be passed to the `destroy_callback` when called.
537
+ * @return A pointer to a newly created `plutobook_resource_data_t` object, or `NULL` on failure.
538
+ */
539
+ PLUTOBOOK_API plutobook_resource_data_t* plutobook_resource_data_create_without_copy(const char* content, unsigned int content_length,
540
+ const char* mime_type, const char* text_encoding, plutobook_resource_destroy_callback_t destroy_callback, void* closure);
541
+
542
+ /**
543
+ * @brief Increases the reference count of a resource data object.
544
+ *
545
+ * This function returns a reference to the given `plutobook_resource_data_t` object, incrementing its reference count.
546
+ * This is useful for managing the lifetime of resource data objects in a reference-counted system.
547
+ *
548
+ * @param resource A pointer to the `plutobook_resource_data_t` object to reference.
549
+ * @return A pointer to the referenced `plutobook_resource_data_t` object.
550
+ */
551
+ PLUTOBOOK_API plutobook_resource_data_t* plutobook_resource_data_reference(plutobook_resource_data_t* resource);
552
+
553
+ /**
554
+ * @brief Destroys a resource data object and frees its associated memory.
555
+ *
556
+ * This function decreases the reference count of the `plutobook_resource_data_t` object, and if the reference count
557
+ * drops to zero, the resource is destroyed and its memory is freed.
558
+ *
559
+ * @param resource A pointer to the `plutobook_resource_data_t` object to destroy.
560
+ */
561
+ PLUTOBOOK_API void plutobook_resource_data_destroy(plutobook_resource_data_t* resource);
562
+
563
+ /**
564
+ * @brief Gets the current reference count of a resource data object.
565
+ *
566
+ * This function returns the number of references to the `plutobook_resource_data_t` object, helping manage the
567
+ * object's lifetime and determine if it can be safely destroyed.
568
+ *
569
+ * @param resource A pointer to the `plutobook_resource_data_t` object.
570
+ * @return The current reference count of the `plutobook_resource_data_t` object.
571
+ */
572
+ PLUTOBOOK_API unsigned int plutobook_resource_data_get_reference_count(const plutobook_resource_data_t* resource);
573
+
574
+ /**
575
+ * @brief Retrieves the content of the resource.
576
+ * @param resource A pointer to a `plutobook_resource_data_t` object.
577
+ * @return The content of the resource.
578
+ */
579
+ PLUTOBOOK_API const char* plutobook_resource_data_get_content(const plutobook_resource_data_t* resource);
580
+
581
+ /**
582
+ * @brief Retrieves the length of the resource content.
583
+ * @param resource A pointer to a `plutobook_resource_data_t` object.
584
+ * @return The length of the resource content in bytes.
585
+ */
586
+ PLUTOBOOK_API unsigned int plutobook_resource_data_get_content_length(const plutobook_resource_data_t* resource);
587
+
588
+ /**
589
+ * @brief Retrieves the MIME type of the resource content.
590
+ * @param resource A pointer to a `plutobook_resource_data_t` object.
591
+ * @return The MIME type of the resource content.
592
+ */
593
+ PLUTOBOOK_API const char* plutobook_resource_data_get_mime_type(const plutobook_resource_data_t* resource);
594
+
595
+ /**
596
+ * @brief Retrieves the text encoding used for the resource content.
597
+ * @param resource A pointer to a `plutobook_resource_data_t` object.
598
+ * @return The text encoding used for the resource content.
599
+ */
600
+ PLUTOBOOK_API const char* plutobook_resource_data_get_text_encoding(const plutobook_resource_data_t* resource);
601
+
602
+ /**
603
+ * @brief Defines a callback type for fetching resource data from a URL.
604
+ *
605
+ * The callback should return a pointer to a `plutobook_resource_data_t` object, which contains the
606
+ * content fetched from the given URL.
607
+ *
608
+ * @param closure A user-defined pointer that will be passed to the callback (can be used for custom state or data).
609
+ * @param url The URL of the resource to fetch.
610
+ * @return A pointer to a `plutobook_resource_data_t` object containing the fetched resource, or `NULL` if an error occurs.
611
+ */
612
+ typedef plutobook_resource_data_t* (*plutobook_resource_fetch_callback_t)(void* closure, const char* url);
613
+
614
+ /**
615
+ * @brief Fetches resource data from a given URL using the default resource fetcher.
616
+ *
617
+ * This function uses a predefined mechanism to fetch resource data from the specified URL and return
618
+ * it as a `plutobook_resource_data_t` object.
619
+ *
620
+ * @param url The URL of the resource to fetch.
621
+ * @return A pointer to a `plutobook_resource_data_t` object containing the fetched content, or `NULL`
622
+ * if the fetch operation fails.
623
+ */
624
+ PLUTOBOOK_API plutobook_resource_data_t* plutobook_fetch_url(const char* url);
625
+
626
+ /**
627
+ * @brief Sets the path to a file containing trusted CA certificates.
628
+ *
629
+ * If not set, no custom CA file is used.
630
+ *
631
+ * @param path Path to the CA certificate bundle file.
632
+ */
633
+ PLUTOBOOK_API void plutobook_set_ssl_cainfo(const char* path);
634
+
635
+ /**
636
+ * @brief Sets the path to a directory containing trusted CA certificates.
637
+ *
638
+ * If not set, no custom CA path is used.
639
+ *
640
+ * @param path Path to the directory with CA certificates.
641
+ */
642
+ PLUTOBOOK_API void plutobook_set_ssl_capath(const char* path);
643
+
644
+ /**
645
+ * @brief Enables or disables SSL peer certificate verification.
646
+ *
647
+ * If not set, verification is enabled by default.
648
+ *
649
+ * @param verify Set to true to verify the peer, false to disable verification.
650
+ */
651
+ PLUTOBOOK_API void plutobook_set_ssl_verify_peer(bool verify);
652
+
653
+ /**
654
+ * @brief Enables or disables SSL host name verification.
655
+ *
656
+ * If not set, verification is enabled by default.
657
+ *
658
+ * @param verify Set to true to verify the host, false to disable verification.
659
+ */
660
+ PLUTOBOOK_API void plutobook_set_ssl_verify_host(bool verify);
661
+
662
+ /**
663
+ * @brief Enables or disables automatic following of HTTP redirects.
664
+ *
665
+ * If not set, following redirects is enabled by default.
666
+ *
667
+ * @param follow Set to true to follow redirects, false to disable.
668
+ */
669
+ PLUTOBOOK_API void plutobook_set_http_follow_redirects(bool follow);
670
+
671
+ /**
672
+ * @brief Sets the maximum number of redirects to follow.
673
+ *
674
+ * If not set, the default maximum is 30.
675
+ *
676
+ * @param amount The maximum number of redirects.
677
+ */
678
+ PLUTOBOOK_API void plutobook_set_http_max_redirects(int amount);
679
+
680
+ /**
681
+ * @brief Sets the maximum time allowed for an HTTP request.
682
+ *
683
+ * If not set, the default timeout is 300 seconds.
684
+ *
685
+ * @param timeout Timeout duration in seconds.
686
+ */
687
+ PLUTOBOOK_API void plutobook_set_http_timeout(int timeout);
688
+
689
+ /**
690
+ * @brief Defines the different media types used for CSS @media queries.
691
+ */
692
+ typedef enum _plutobook_media_type {
693
+ PLUTOBOOK_MEDIA_TYPE_PRINT,
694
+ PLUTOBOOK_MEDIA_TYPE_SCREEN
695
+ } plutobook_media_type_t;
696
+
697
+ /**
698
+ * @brief Represents a plutobook document.
699
+ */
700
+ typedef struct _plutobook plutobook_t;
701
+
702
+ /**
703
+ * @brief Creates a new `plutobook_t` object with the specified page size, margins, and media type.
704
+ *
705
+ * @param size The initial page size.
706
+ * @param margins The initial page margins.
707
+ * @param media The media type used for media queries.
708
+ * @return A pointer to the newly created `plutobook_t` object, or `NULL` on failure.
709
+ */
710
+ PLUTOBOOK_API plutobook_t* plutobook_create(plutobook_page_size_t size, plutobook_page_margins_t margins, plutobook_media_type_t media);
711
+
712
+ /**
713
+ * @brief Destroys a `plutobook_t` object and frees all associated resources.
714
+ *
715
+ * @param book A pointer to the `plutobook_t` object to destroy.
716
+ */
717
+ PLUTOBOOK_API void plutobook_destroy(plutobook_t* book);
718
+
719
+ /**
720
+ * @brief Clears the content of the document.
721
+ *
722
+ * @param book A pointer to a `plutobook_t` object.
723
+ */
724
+ PLUTOBOOK_API void plutobook_clear_content(plutobook_t* book);
725
+
726
+ /**
727
+ * @brief Sets the metadata of the PDF document.
728
+ *
729
+ * The `PDF_METADATA_CREATION_DATE` and `PDF_METADATA_MODIFICATION_DATE` values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss.
730
+ * An optional timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended. All other metadata values can be any string.
731
+ *
732
+ * @param book A pointer to a `plutobook_t` object.
733
+ * @param metadata The metadata type to set.
734
+ * @param value The value of the metadata field.
735
+ */
736
+ PLUTOBOOK_API void plutobook_set_metadata(plutobook_t* book, plutobook_pdf_metadata_t metadata, const char* value);
737
+
738
+ /**
739
+ * @brief Gets the value of the specified metadata.
740
+ *
741
+ * @param book A pointer to a `plutobook_t` object.
742
+ * @param metadata The type of metadata to get.
743
+ * @return The value of the specified metadata.
744
+ */
745
+ PLUTOBOOK_API const char* plutobook_get_metadata(const plutobook_t* book, plutobook_pdf_metadata_t metadata);
746
+
747
+ /**
748
+ * @brief Returns the width of the viewport.
749
+ *
750
+ * @param book A pointer to a `plutobook_t` object.
751
+ * @return The width of the viewport in pixels.
752
+ */
753
+ PLUTOBOOK_API float plutobook_get_viewport_width(const plutobook_t* book);
754
+
755
+ /**
756
+ * @brief Returns the height of the viewport.
757
+ *
758
+ * @param book A pointer to a `plutobook_t` object.
759
+ * @return The height of the viewport in pixels.
760
+ */
761
+ PLUTOBOOK_API float plutobook_get_viewport_height(const plutobook_t* book);
762
+
763
+ /**
764
+ * @brief Returns the width of the document.
765
+ *
766
+ * @param book A pointer to a `plutobook_t` object.
767
+ * @return The width of the document in pixels.
768
+ */
769
+ PLUTOBOOK_API float plutobook_get_document_width(const plutobook_t* book);
770
+
771
+ /**
772
+ * @brief Returns the height of the document.
773
+ *
774
+ * @param book A pointer to a `plutobook_t` object.
775
+ * @return The height of the document in pixels.
776
+ */
777
+ PLUTOBOOK_API float plutobook_get_document_height(const plutobook_t* book);
778
+
779
+ /**
780
+ * @brief Returns the initial page size.
781
+ *
782
+ * @param book A pointer to a `plutobook_t` object.
783
+ * @return The initial page size.
784
+ */
785
+ PLUTOBOOK_API plutobook_page_size_t plutobook_get_page_size(const plutobook_t* book);
786
+
787
+ /**
788
+ * @brief Returns the initial page margins.
789
+ *
790
+ * @param book A pointer to a `plutobook_t` object.
791
+ * @return The initial page margins.
792
+ */
793
+ PLUTOBOOK_API plutobook_page_margins_t plutobook_get_page_margins(const plutobook_t* book);
794
+
795
+ /**
796
+ * @brief Returns the media type used for media queries.
797
+ *
798
+ * @param book A pointer to a `plutobook_t` object.
799
+ * @return The media type used for media queries.
800
+ */
801
+ PLUTOBOOK_API plutobook_media_type_t plutobook_get_media_type(const plutobook_t* book);
802
+
803
+ /**
804
+ * @brief Returns the number of pages in the document.
805
+ *
806
+ * @param book A pointer to a `plutobook_t` object.
807
+ * @return The number of pages in the document.
808
+ */
809
+ PLUTOBOOK_API unsigned int plutobook_get_page_count(const plutobook_t* book);
810
+
811
+ /**
812
+ * @brief Returns the page size at the specified index.
813
+ *
814
+ * @param book A pointer to a `plutobook_t` object.
815
+ * @param index The index of the page.
816
+ * @return The size of the page at the specified index.
817
+ */
818
+ PLUTOBOOK_API plutobook_page_size_t plutobook_get_page_size_at(const plutobook_t* book, unsigned int index);
819
+
820
+ /**
821
+ * @brief Loads the document from the specified URL.
822
+ *
823
+ * @param book A pointer to a `plutobook_t` object.
824
+ * @param url The URL to load the document from.
825
+ * @param user_style An optional user-defined style to apply.
826
+ * @param user_script An optional user-defined script to run after the document has loaded.
827
+ * @return `true` on success, or `false` on failure.
828
+ */
829
+ PLUTOBOOK_API bool plutobook_load_url(plutobook_t* book, const char* url, const char* user_style, const char* user_script);
830
+
831
+ /**
832
+ * @brief Loads the document from the specified data.
833
+ *
834
+ * @param book A pointer to a `plutobook_t` object.
835
+ * @param data The data to load the document from.
836
+ * @param length The length of the data in bytes.
837
+ * @param mime_type The MIME type of the data.
838
+ * @param text_encoding The text encoding of the data.
839
+ * @param user_style An optional user-defined style to apply.
840
+ * @param user_script An optional user-defined script to run after the document has loaded.
841
+ * @param base_url The base URL for resolving relative URLs.
842
+ * @return `true` on success, or `false` on failure.
843
+ */
844
+ PLUTOBOOK_API bool plutobook_load_data(plutobook_t* book, const char* data, unsigned int length,
845
+ const char* mime_type, const char* text_encoding, const char* user_style, const char* user_script, const char* base_url);
846
+
847
+ /**
848
+ * @brief Loads the document from the specified image data.
849
+ *
850
+ * @param book A pointer to a `plutobook_t` object.
851
+ * @param data The image data to load the document from.
852
+ * @param length The length of the image data in bytes.
853
+ * @param mime_type The MIME type of the image data.
854
+ * @param text_encoding The text encoding of the image data.
855
+ * @param user_style An optional user-defined style to apply.
856
+ * @param user_script An optional user-defined script to run after the document has loaded.
857
+ * @param base_url The base URL for resolving relative URLs.
858
+ * @return `true` on success, or `false` on failure.
859
+ */
860
+ PLUTOBOOK_API bool plutobook_load_image(plutobook_t* book, const char* data, unsigned int length,
861
+ const char* mime_type, const char* text_encoding, const char* user_style, const char* user_script, const char* base_url);
862
+
863
+ /**
864
+ * @brief Loads the document from the specified XML data.
865
+ *
866
+ * @param book A pointer to a `plutobook_t` object.
867
+ * @param data The XML data to load the document from, encoded in UTF-8.
868
+ * @param length The length of the XML data in bytes, or `-1` if null-terminated.
869
+ * @param user_style An optional user-defined style to apply.
870
+ * @param user_script An optional user-defined script to run after the document has loaded.
871
+ * @param base_url The base URL for resolving relative URLs.
872
+ * @return `true` on success, or `false` on failure.
873
+ */
874
+ PLUTOBOOK_API bool plutobook_load_xml(plutobook_t* book, const char* data, int length,
875
+ const char* user_style, const char* user_script, const char* base_url);
876
+
877
+ /**
878
+ * @brief Loads the document from the specified HTML data.
879
+ *
880
+ * @param book A pointer to a `plutobook_t` object.
881
+ * @param data The HTML data to load the document from, encoded in UTF-8.
882
+ * @param length The length of the HTML data in bytes, or `-1` if null-terminated.
883
+ * @param user_style An optional user-defined style to apply.
884
+ * @param user_script An optional user-defined script to run after the document has loaded.
885
+ * @param base_url The base URL for resolving relative URLs.
886
+ * @return `true` on success, or `false` on failure.
887
+ */
888
+ PLUTOBOOK_API bool plutobook_load_html(plutobook_t* book, const char* data, int length,
889
+ const char* user_style, const char* user_script, const char* base_url);
890
+
891
+ /**
892
+ * @brief Renders the specified page to the given canvas.
893
+ *
894
+ * @param book A pointer to a `plutobook_t` object.
895
+ * @param canvas The canvas to render the page on.
896
+ * @param page_index The index of the page to render.
897
+ */
898
+ PLUTOBOOK_API void plutobook_render_page(const plutobook_t* book, plutobook_canvas_t* canvas, unsigned int page_index);
899
+
900
+ /**
901
+ * @brief Renders the specified page to the given cairo context.
902
+ *
903
+ * @param book A pointer to a `plutobook_t` object.
904
+ * @param context The cairo context to render the page on.
905
+ * @param page_index The index of the page to render.
906
+ */
907
+ PLUTOBOOK_API void plutobook_render_page_cairo(const plutobook_t* book, cairo_t* context, unsigned int page_index);
908
+
909
+ /**
910
+ * @brief Renders the entire document to the given canvas.
911
+ *
912
+ * @param book A pointer to a `plutobook_t` object.
913
+ * @param canvas The canvas to render the entire document on.
914
+ */
915
+ PLUTOBOOK_API void plutobook_render_document(const plutobook_t* book, plutobook_canvas_t* canvas);
916
+
917
+ /**
918
+ * @brief Renders the entire document to the given cairo context.
919
+ *
920
+ * @param book A pointer to a `plutobook_t` object.
921
+ * @param canvas The cairo context to render the entire document on.
922
+ */
923
+ PLUTOBOOK_API void plutobook_render_document_cairo(const plutobook_t* book, cairo_t* context);
924
+
925
+ /**
926
+ * @brief Renders a specific rectangular portion of the document to the given canvas.
927
+ *
928
+ * @param book A pointer to a `plutobook_t` object.
929
+ * @param canvas The canvas to render the document portion on.
930
+ * @param x The x-coordinate of the top-left corner of the rectangle.
931
+ * @param y The y-coordinate of the top-left corner of the rectangle.
932
+ * @param width The width of the rectangle to render.
933
+ * @param height The height of the rectangle to render.
934
+ */
935
+ PLUTOBOOK_API void plutobook_render_document_rect(const plutobook_t* book, plutobook_canvas_t* canvas,
936
+ float x, float y, float width, float height);
937
+
938
+ /**
939
+ * @brief Renders a specific rectangular portion of the document to the given cairo context.
940
+ *
941
+ * @param book A pointer to a `plutobook_t` object.
942
+ * @param canvas The cairo context to render the document portion on.
943
+ * @param x The x-coordinate of the top-left corner of the rectangle.
944
+ * @param y The y-coordinate of the top-left corner of the rectangle.
945
+ * @param width The width of the rectangle to render.
946
+ * @param height The height of the rectangle to render.
947
+ */
948
+ PLUTOBOOK_API void plutobook_render_document_rect_cairo(const plutobook_t* book, cairo_t* context,
949
+ float x, float y, float width, float height);
950
+
951
+ /**
952
+ * @brief Writes the entire document to a PDF file.
953
+ *
954
+ * @param book A pointer to a `plutobook_t` object.
955
+ * @param filename The file path where the PDF document will be written.
956
+ * @return `true` on success, or `false` on failure.
957
+ */
958
+ PLUTOBOOK_API bool plutobook_write_to_pdf(const plutobook_t* book, const char* filename);
959
+
960
+ /**
961
+ * @brief Writes a range of pages from the document to a PDF file.
962
+ *
963
+ * @param book A pointer to a `plutobook_t` object.
964
+ * @param filename The file path where the PDF document will be written.
965
+ * @param page_start The first page in the range to be written (inclusive).
966
+ * @param page_end The last page in the range to be written (inclusive).
967
+ * @param page_step The increment used to advance through the pages in the range.
968
+ * @return `true` on success, or `false` on failure.
969
+ */
970
+ PLUTOBOOK_API bool plutobook_write_to_pdf_range(const plutobook_t* book, const char* filename,
971
+ unsigned int page_start, unsigned int page_end, int page_step);
972
+
973
+ /**
974
+ * @brief Writes the entire document to a PDF stream using a callback function.
975
+ *
976
+ * @param book A pointer to a `plutobook_t` object.
977
+ * @param callback A callback function used for writing the PDF stream.
978
+ * @param closure A user-defined pointer passed to the callback function for additional data.
979
+ * @return `true` on success, or `false` on failure.
980
+ */
981
+ PLUTOBOOK_API bool plutobook_write_to_pdf_stream(const plutobook_t* book, plutobook_stream_write_callback_t callback, void* closure);
982
+
983
+ /**
984
+ * @brief Writes a specified range of pages from the document to a PDF stream using a callback function.
985
+ *
986
+ * @param book A pointer to a `plutobook_t` object.
987
+ * @param callback A callback function used for writing the PDF stream.
988
+ * @param closure A user-defined pointer passed to the callback function for additional data.
989
+ * @param page_start The first page in the range to be written (inclusive).
990
+ * @param page_end The last page in the range to be written (inclusive).
991
+ * @param page_step The increment used to advance through the pages in the range.
992
+ * @return `true` on success, or `false` on failure.
993
+ */
994
+ PLUTOBOOK_API bool plutobook_write_to_pdf_stream_range(const plutobook_t* book,
995
+ plutobook_stream_write_callback_t callback, void* closure, unsigned int page_start, unsigned int page_end, int page_step);
996
+
997
+ /**
998
+ * @brief Writes the entire document to a PNG image file.
999
+ *
1000
+ * @param book A pointer to a `plutobook_t` object.
1001
+ * @param filename The file path where the PNG image will be written.
1002
+ * @param width The desired width in pixels, or -1 to auto-scale based on the document size.
1003
+ * @param height The desired height in pixels, or -1 to auto-scale based on the document size.
1004
+ * @return `true` on success, or `false` on failure.
1005
+ */
1006
+ PLUTOBOOK_API bool plutobook_write_to_png(const plutobook_t* book, const char* filename, int width, int height);
1007
+
1008
+ /**
1009
+ * @brief Writes the entire document to a PNG image stream using a callback function.
1010
+ *
1011
+ * @param book A pointer to a `plutobook_t` object.
1012
+ * @param callback A callback function to handle the image data stream.
1013
+ * @param closure A pointer to user-defined data to pass to the callback function.
1014
+ * @param width The desired width in pixels, or -1 to auto-scale based on the document size.
1015
+ * @param height The desired height in pixels, or -1 to auto-scale based on the document size.
1016
+ * @return `true` on success, or `false` on failure.
1017
+ */
1018
+ PLUTOBOOK_API bool plutobook_write_to_png_stream(const plutobook_t* book,
1019
+ plutobook_stream_write_callback_t callback, void* closure, int width, int height);
1020
+
1021
+ /**
1022
+ * @brief Sets a custom resource fetcher callback for the document.
1023
+ *
1024
+ * @param book A pointer to a `plutobook_t` object.
1025
+ * @param callback A function pointer to the custom resource fetch callback.
1026
+ * @param closure A pointer to user-defined data to pass to the callback function.
1027
+ */
1028
+ PLUTOBOOK_API void plutobook_set_custom_resource_fetcher(plutobook_t* book,
1029
+ plutobook_resource_fetch_callback_t callback, void* closure);
1030
+
1031
+ /**
1032
+ * @brief Gets the custom resource fetcher callback set for the document.
1033
+ *
1034
+ * @param book A pointer to a `plutobook_t` object.
1035
+ * @return A function pointer to the custom resource fetch callback, or `NULL` if no callback is set.
1036
+ */
1037
+ PLUTOBOOK_API plutobook_resource_fetch_callback_t plutobook_get_custom_resource_fetcher_callback(const plutobook_t* book);
1038
+
1039
+ /**
1040
+ * @brief Gets the user-defined closure data passed to the custom resource fetcher callback.
1041
+ *
1042
+ * @param book A pointer to a `plutobook_t` object.
1043
+ * @return A pointer to the closure data, or `NULL` if no closure is set.
1044
+ */
1045
+ PLUTOBOOK_API void* plutobook_get_custom_resource_fetcher_closure(const plutobook_t* book);
1046
+
1047
+ /**
1048
+ * @brief Sets the error message for the current thread.
1049
+ *
1050
+ * It replaces any previously set error message for the current thread.
1051
+ *
1052
+ * @param format A `printf`-style format string specifying the error message.
1053
+ * @param ... Arguments corresponding to the format string.
1054
+ */
1055
+ PLUTOBOOK_API void plutobook_set_error_message(const char* format, ...) PLUTOBOOK_PRINTF_FORMAT(1, 2);
1056
+
1057
+ /**
1058
+ * @brief Retrieves the last error message that occurred on the current thread.
1059
+ *
1060
+ * This function returns a message describing the most recent error that occurred
1061
+ * in the current thread as set by `plutobook_set_error_message()`. If multiple errors
1062
+ * occur before this function is called, only the most recent message is returned.
1063
+ *
1064
+ * @note This function does not indicate whether an error has occurred.
1065
+ * You must check the return values of PlutoBook API functions to determine if an
1066
+ * operation failed. Do not rely solely on `plutobook_get_error_message()` to detect errors.
1067
+ *
1068
+ * @note PlutoBook does not clear the error message on successful API calls. It is your
1069
+ * responsibility to check return values and determine when to clear or ignore the message.
1070
+ *
1071
+ * @note Error messages are stored in thread-local storage. An error message set in one thread
1072
+ * will not interfere with messages or behavior in another thread.
1073
+ *
1074
+ * @return A pointer to the current error message string.
1075
+ */
1076
+ PLUTOBOOK_API const char* plutobook_get_error_message(void);
1077
+
1078
+ /**
1079
+ * @brief @brief Clears any previously set error message for the current thread.
1080
+ */
1081
+ PLUTOBOOK_API void plutobook_clear_error_message(void);
1082
+
1083
+ /**
1084
+ * @brief Sets the `FONTCONFIG_PATH` environment variable for the current process.
1085
+ *
1086
+ * This function specifies the directory that Fontconfig should use to locate
1087
+ * its configuration files.
1088
+ *
1089
+ * @param path A null-terminated string specifying the directory containing Fontconfig
1090
+ * configuration files.
1091
+ *
1092
+ * @note This function must be called before creating any `plutobook_t` instance
1093
+ * to ensure that Fontconfig uses the specified configuration path.
1094
+ */
1095
+ PLUTOBOOK_API void plutobook_set_fontconfig_path(const char* path);
1096
+
1097
+ #ifdef __cplusplus
1098
+ }
1099
+ #endif
1100
+
1101
+ #endif // PLUTOBOOK_H