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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +247 -0
- data/ext/page_print/extconf.rb +48 -0
- data/ext/page_print/page_print.c +851 -0
- data/lib/page_print/page_print.so +0 -0
- data/lib/page_print/rails_resource_fetcher.rb +138 -0
- data/lib/page_print/railtie.rb +15 -0
- data/lib/page_print/vendor/x86_64-linux/include/plutobook/plutobook.h +1101 -0
- data/lib/page_print/vendor/x86_64-linux/include/plutobook/plutobook.hpp +1361 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libX11.so.6 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libXau.so.6 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libXdmcp.so.6 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libXext.so.6 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libXrender.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libbrotlicommon.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libbrotlidec.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libbsd.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libbz2.so.1.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libcairo.so.2 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libcrypt.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libexpat.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libfontconfig.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libfreetype.so.6 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libglib-2.0.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libgmp.so.10 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libgraphite2.so.3 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libharfbuzz.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libicudata.so.74 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libicui18n.so.74 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libicuuc.so.74 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libmd.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libpcre2-8.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libpixman-1.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libplutobook.so.0.17.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libpng16.so.16 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libruby.so.3.4 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libxcb-render.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libxcb-shm.so.0 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libxcb.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/libz.so.1 +0 -0
- data/lib/page_print/vendor/x86_64-linux/lib/pkgconfig/plutobook.pc +10 -0
- data/lib/page_print/version.rb +3 -0
- data/lib/page_print.rb +28 -0
- metadata +89 -0
|
@@ -0,0 +1,1361 @@
|
|
|
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_HPP
|
|
10
|
+
#define PLUTOBOOK_HPP
|
|
11
|
+
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
#include <cstddef>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
#include "plutobook.h"
|
|
18
|
+
|
|
19
|
+
namespace plutobook {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This constant defines an index that is guaranteed to be greater than any valid page count.
|
|
23
|
+
* It is typically used as a sentinel value to represent an unbounded upper limit or the
|
|
24
|
+
* maximum possible value, indicating that no specific upper bound is set.
|
|
25
|
+
*/
|
|
26
|
+
constexpr uint32_t kMaxPageCount = PLUTOBOOK_MAX_PAGE_COUNT;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This constant defines an index that is guaranteed to be less than any valid page count.
|
|
30
|
+
* It is typically used as a sentinel value to represent an unbounded lower limit or the
|
|
31
|
+
* minimum possible value, indicating that no specific lower bound is set.
|
|
32
|
+
*/
|
|
33
|
+
constexpr uint32_t kMinPageCount = PLUTOBOOK_MIN_PAGE_COUNT;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @brief The PageSize class represents the dimensions of a page in points (1/72 inch).
|
|
37
|
+
*/
|
|
38
|
+
class PageSize {
|
|
39
|
+
public:
|
|
40
|
+
/**
|
|
41
|
+
* @brief Constructs a PageSize object with width and height set to 0.
|
|
42
|
+
*/
|
|
43
|
+
constexpr PageSize() = default;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @brief Constructs a PageSize object from a `plutobook_page_size_t` object.
|
|
47
|
+
*
|
|
48
|
+
* @param size A `plutobook_page_size_t` object.
|
|
49
|
+
*/
|
|
50
|
+
constexpr PageSize(plutobook_page_size_t size) : PageSize(size.width, size.height) {}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @brief Constructs a PageSize object with the same width and height.
|
|
54
|
+
*
|
|
55
|
+
* @param size The value to set for both width and height in points.
|
|
56
|
+
*/
|
|
57
|
+
constexpr explicit PageSize(float size) : PageSize(size, size) {}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @brief Constructs a PageSize object with the specified width and height.
|
|
61
|
+
*
|
|
62
|
+
* @param width The width of the page in points.
|
|
63
|
+
* @param height The height of the page in points.
|
|
64
|
+
*/
|
|
65
|
+
constexpr PageSize(float width, float height) : m_width(width), m_height(height) {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @brief Sets the width of the page.
|
|
69
|
+
*
|
|
70
|
+
* @param width The width of the page in points.
|
|
71
|
+
*/
|
|
72
|
+
constexpr void setWidth(float width) { m_width = width; }
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @brief Sets the height of the page.
|
|
76
|
+
*
|
|
77
|
+
* @param height The height of the page in points.
|
|
78
|
+
*/
|
|
79
|
+
constexpr void setHeight(float height) { m_height = height; }
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @brief Gets the width of the page.
|
|
83
|
+
*
|
|
84
|
+
* @return The width of the page in points.
|
|
85
|
+
*/
|
|
86
|
+
constexpr float width() const { return m_width; }
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @brief Gets the height of the page.
|
|
90
|
+
*
|
|
91
|
+
* @return The height of the page in points.
|
|
92
|
+
*/
|
|
93
|
+
constexpr float height() const { return m_height; }
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @brief Returns the page size in landscape orientation.
|
|
97
|
+
*
|
|
98
|
+
* @return A `PageSize` object in landscape orientation.
|
|
99
|
+
*/
|
|
100
|
+
constexpr PageSize landscape() const;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @brief Returns the page size in portrait orientation.
|
|
104
|
+
*
|
|
105
|
+
* @return A `PageSize` object in portrait orientation.
|
|
106
|
+
*/
|
|
107
|
+
constexpr PageSize portrait() const;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @brief Converts the `PageSize` object to a `plutobook_page_size_t` object.
|
|
111
|
+
*
|
|
112
|
+
* @return A `plutobook_page_size_t` object with the same width and height values.
|
|
113
|
+
*/
|
|
114
|
+
constexpr operator plutobook_page_size_t() const { return PLUTOBOOK_MAKE_PAGE_SIZE(m_width, m_height); }
|
|
115
|
+
|
|
116
|
+
static const PageSize A3; ///< Represents the A3 page size (297 x 420 mm).
|
|
117
|
+
static const PageSize A4; ///< Represents the A4 page size (210 x 297 mm).
|
|
118
|
+
static const PageSize A5; ///< Represents the A5 page size (148 x 210 mm).
|
|
119
|
+
static const PageSize B4; ///< Represents the B4 page size (250 x 353 mm).
|
|
120
|
+
static const PageSize B5; ///< Represents the B5 page size (176 x 250 mm).
|
|
121
|
+
static const PageSize Letter; ///< Represents the Letter page size (8.5 x 11 inches).
|
|
122
|
+
static const PageSize Legal; ///< Represents the Legal page size (8.5 x 14 inches).
|
|
123
|
+
static const PageSize Ledger; ///< Represents the Ledger page size (11 x 17 inches).
|
|
124
|
+
|
|
125
|
+
private:
|
|
126
|
+
float m_width{0};
|
|
127
|
+
float m_height{0};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
constexpr PageSize PageSize::landscape() const
|
|
131
|
+
{
|
|
132
|
+
if(m_width < m_height)
|
|
133
|
+
return PageSize(m_height, m_width);
|
|
134
|
+
return PageSize(m_width, m_height);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
constexpr PageSize PageSize::portrait() const
|
|
138
|
+
{
|
|
139
|
+
if(m_width > m_height)
|
|
140
|
+
return PageSize(m_height, m_width);
|
|
141
|
+
return PageSize(m_width, m_height);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
inline const PageSize PageSize::A3 = PLUTOBOOK_PAGE_SIZE_A3;
|
|
145
|
+
inline const PageSize PageSize::A4 = PLUTOBOOK_PAGE_SIZE_A4;
|
|
146
|
+
inline const PageSize PageSize::A5 = PLUTOBOOK_PAGE_SIZE_A5;
|
|
147
|
+
inline const PageSize PageSize::B4 = PLUTOBOOK_PAGE_SIZE_B4;
|
|
148
|
+
inline const PageSize PageSize::B5 = PLUTOBOOK_PAGE_SIZE_B5;
|
|
149
|
+
inline const PageSize PageSize::Letter = PLUTOBOOK_PAGE_SIZE_LETTER;
|
|
150
|
+
inline const PageSize PageSize::Legal = PLUTOBOOK_PAGE_SIZE_LEGAL;
|
|
151
|
+
inline const PageSize PageSize::Ledger = PLUTOBOOK_PAGE_SIZE_LEDGER;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @brief The PageMargins class represents the margins of a page in points (1/72 inch).
|
|
155
|
+
*/
|
|
156
|
+
class PageMargins {
|
|
157
|
+
public:
|
|
158
|
+
/**
|
|
159
|
+
* @brief Constructs a PageMargins object with all margins set to 0.
|
|
160
|
+
*/
|
|
161
|
+
constexpr PageMargins() = default;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @brief Constructs a PageMargins object from a `plutobook_page_margins_t` object.
|
|
165
|
+
*
|
|
166
|
+
* @param margins A `plutobook_page_margins_t` object.
|
|
167
|
+
*/
|
|
168
|
+
constexpr PageMargins(plutobook_page_margins_t margins)
|
|
169
|
+
: PageMargins(margins.top, margins.right, margins.bottom, margins.left)
|
|
170
|
+
{}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @brief Constructs a PageMargins object with the same margin on all sides.
|
|
174
|
+
*
|
|
175
|
+
* @param margin The margin value to apply to all four sides in points.
|
|
176
|
+
*/
|
|
177
|
+
constexpr explicit PageMargins(float margin)
|
|
178
|
+
: PageMargins(margin, margin, margin, margin)
|
|
179
|
+
{}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @brief Constructs a PageMargins object with vertical and horizontal margins.
|
|
183
|
+
*
|
|
184
|
+
* @param vertical The margin for the top and bottom sides, in points.
|
|
185
|
+
* @param horizontal The margin for the left and right sides, in points.
|
|
186
|
+
*/
|
|
187
|
+
constexpr PageMargins(float vertical, float horizontal)
|
|
188
|
+
: PageMargins(vertical, horizontal, vertical, horizontal)
|
|
189
|
+
{}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @brief Constructs a PageMargins object with vertical and horizontal margins.
|
|
193
|
+
*
|
|
194
|
+
* @param top The top margin in points.
|
|
195
|
+
* @param horizontal The margin for the left and right sides, in points.
|
|
196
|
+
* @param bottom The bottom margin in points.
|
|
197
|
+
*/
|
|
198
|
+
constexpr PageMargins(float top, float horizontal, float bottom)
|
|
199
|
+
: PageMargins(top, horizontal, bottom, horizontal)
|
|
200
|
+
{}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @brief Constructs a PageMargins object with specific margins for each side.
|
|
204
|
+
*
|
|
205
|
+
* @param top The margin for the top side, in points.
|
|
206
|
+
* @param right The margin for the right side, in points.
|
|
207
|
+
* @param bottom The margin for the bottom side, in points.
|
|
208
|
+
* @param left The margin for the left side, in points.
|
|
209
|
+
*/
|
|
210
|
+
constexpr PageMargins(float top, float right, float bottom, float left)
|
|
211
|
+
: m_top(top), m_right(right), m_bottom(bottom), m_left(left)
|
|
212
|
+
{}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @brief Sets the top margin.
|
|
216
|
+
*
|
|
217
|
+
* @param top The margin value for the top side, in points.
|
|
218
|
+
*/
|
|
219
|
+
constexpr void setTop(float top) { m_top = top; }
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @brief Sets the right margin.
|
|
223
|
+
*
|
|
224
|
+
* @param right The margin value for the right side, in points.
|
|
225
|
+
*/
|
|
226
|
+
constexpr void setRight(float right) { m_right = right; }
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @brief Sets the bottom margin.
|
|
230
|
+
*
|
|
231
|
+
* @param bottom The margin value for the bottom side, in points.
|
|
232
|
+
*/
|
|
233
|
+
constexpr void setBottom(float bottom) { m_bottom = bottom; }
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @brief Sets the left margin.
|
|
237
|
+
*
|
|
238
|
+
* @param left The margin value for the left side, in points.
|
|
239
|
+
*/
|
|
240
|
+
constexpr void setLeft(float left) { m_left = left; }
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @brief Gets the top margin.
|
|
244
|
+
*
|
|
245
|
+
* @return The margin value for the top side, in points.
|
|
246
|
+
*/
|
|
247
|
+
constexpr float top() const { return m_top; }
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @brief Gets the right margin.
|
|
251
|
+
*
|
|
252
|
+
* @return The margin value for the right side, in points.
|
|
253
|
+
*/
|
|
254
|
+
constexpr float right() const { return m_right; }
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @brief Gets the bottom margin.
|
|
258
|
+
*
|
|
259
|
+
* @return The margin value for the bottom side, in points.
|
|
260
|
+
*/
|
|
261
|
+
constexpr float bottom() const { return m_bottom; }
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @brief Gets the left margin.
|
|
265
|
+
*
|
|
266
|
+
* @return The margin value for the left side, in points.
|
|
267
|
+
*/
|
|
268
|
+
constexpr float left() const { return m_left; }
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @brief Converts the `PageMargins` object to a `plutobook_page_margins_t` object.
|
|
272
|
+
*
|
|
273
|
+
* @return A `plutobook_page_margins_t` object with the same margin values.
|
|
274
|
+
*/
|
|
275
|
+
constexpr operator plutobook_page_margins_t() const {
|
|
276
|
+
return PLUTOBOOK_MAKE_PAGE_MARGINS(m_top, m_right, m_bottom, m_left);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @brief Represents page margins with zero dimensions on all sides.
|
|
281
|
+
*
|
|
282
|
+
* - Top: 0 points
|
|
283
|
+
* - Right: 0 points
|
|
284
|
+
* - Bottom: 0 points
|
|
285
|
+
* - Left: 0 points
|
|
286
|
+
*/
|
|
287
|
+
static const PageMargins None;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @brief Represents normal page margins (72 points or 1 inch on all sides).
|
|
291
|
+
*
|
|
292
|
+
* - Top: 72 points (1 inch)
|
|
293
|
+
* - Right: 72 points (1 inch)
|
|
294
|
+
* - Bottom: 72 points (1 inch)
|
|
295
|
+
* - Left: 72 points (1 inch)
|
|
296
|
+
*/
|
|
297
|
+
static const PageMargins Normal;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @brief Represents narrow page margins (36 points or 0.5 inches on all sides).
|
|
301
|
+
*
|
|
302
|
+
* - Top: 36 points (0.5 inches)
|
|
303
|
+
* - Right: 36 points (0.5 inches)
|
|
304
|
+
* - Bottom: 36 points (0.5 inches)
|
|
305
|
+
* - Left: 36 points (0.5 inches)
|
|
306
|
+
*/
|
|
307
|
+
static const PageMargins Narrow;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @brief Represents moderate page margins.
|
|
311
|
+
*
|
|
312
|
+
* - Top: 72 points (1 inch)
|
|
313
|
+
* - Right: 54 points (0.75 inches)
|
|
314
|
+
* - Bottom: 72 points (1 inch)
|
|
315
|
+
* - Left: 54 points (0.75 inches)
|
|
316
|
+
*/
|
|
317
|
+
static const PageMargins Moderate;
|
|
318
|
+
|
|
319
|
+
private:
|
|
320
|
+
float m_top{0};
|
|
321
|
+
float m_right{0};
|
|
322
|
+
float m_bottom{0};
|
|
323
|
+
float m_left{0};
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
inline const PageMargins PageMargins::None = PLUTOBOOK_PAGE_MARGINS_NONE;
|
|
327
|
+
inline const PageMargins PageMargins::Normal = PLUTOBOOK_PAGE_MARGINS_NORMAL;
|
|
328
|
+
inline const PageMargins PageMargins::Narrow = PLUTOBOOK_PAGE_MARGINS_NARROW;
|
|
329
|
+
inline const PageMargins PageMargins::Moderate = PLUTOBOOK_PAGE_MARGINS_MODERATE;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Defines conversion factors for various units to points (pt) and vice versa.
|
|
333
|
+
* These conversion factors allow easy conversion between different units and points.
|
|
334
|
+
*
|
|
335
|
+
* Example Usage:
|
|
336
|
+
* - To convert 12 inches to points: 12 * units::in
|
|
337
|
+
* - To convert 12 points to inches: 12 / units::in
|
|
338
|
+
*/
|
|
339
|
+
namespace units {
|
|
340
|
+
|
|
341
|
+
constexpr float pt = PLUTOBOOK_UNITS_PT;
|
|
342
|
+
constexpr float pc = PLUTOBOOK_UNITS_PC;
|
|
343
|
+
constexpr float in = PLUTOBOOK_UNITS_IN;
|
|
344
|
+
constexpr float cm = PLUTOBOOK_UNITS_CM;
|
|
345
|
+
constexpr float mm = PLUTOBOOK_UNITS_MM;
|
|
346
|
+
constexpr float px = PLUTOBOOK_UNITS_PX;
|
|
347
|
+
|
|
348
|
+
} // units
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @brief The ResourceData class represents a piece of fetched data (resource).
|
|
352
|
+
*/
|
|
353
|
+
class PLUTOBOOK_API ResourceData {
|
|
354
|
+
public:
|
|
355
|
+
/**
|
|
356
|
+
* @brief Constructs a ResourceData object by initializing the underlying resource with a null pointer.
|
|
357
|
+
*/
|
|
358
|
+
ResourceData() : m_data(nullptr) {}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @brief Constructs a `ResourceData` object by adopting a bare pointer to the resource without
|
|
362
|
+
* modifying the reference count.
|
|
363
|
+
*
|
|
364
|
+
* @param data A bare pointer to a `plutobook_resource_data_t` object.
|
|
365
|
+
*/
|
|
366
|
+
explicit ResourceData(plutobook_resource_data_t* data) : m_data(data) {}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @brief Constructs a ResourceData object by copying the provided content.
|
|
370
|
+
*
|
|
371
|
+
* @param content The content of the resource.
|
|
372
|
+
* @param contentLength The length of the content in bytes.
|
|
373
|
+
* @param mimeType The MIME type of the content.
|
|
374
|
+
* @param textEncoding The text encoding used for the content.
|
|
375
|
+
*/
|
|
376
|
+
ResourceData(const char* content, size_t contentLength, const std::string& mimeType, const std::string& textEncoding);
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* @brief Constructs a ResourceData object using the provided content "as is", and uses the
|
|
380
|
+
* provided callback to clean up the resource when it is no longer needed.
|
|
381
|
+
*
|
|
382
|
+
* This method does not copy the content. It takes ownership and ensures cleanup via the
|
|
383
|
+
* specified callback.
|
|
384
|
+
*
|
|
385
|
+
* @param content The content of the resource.
|
|
386
|
+
* @param contentLength The length of the content in bytes.
|
|
387
|
+
* @param mimeType The MIME type of the content.
|
|
388
|
+
* @param textEncoding The text encoding used for the content.
|
|
389
|
+
* @param destroyCallback A callback function that is called when the resource is destroyed.
|
|
390
|
+
* @param closure A pointer to user-defined data that is passed to the destroy callback.
|
|
391
|
+
*/
|
|
392
|
+
ResourceData(const char* content, size_t contentLength, const std::string& mimeType, const std::string& textEncoding,
|
|
393
|
+
plutobook_resource_destroy_callback_t destroyCallback, void* closure);
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @brief Constructs a ResourceData object by transferring ownership from another
|
|
397
|
+
* `ResourceData` object.
|
|
398
|
+
*
|
|
399
|
+
* The move constructor releases the underlying resource from the provided `ResourceData`
|
|
400
|
+
* object and takes ownership of it, effectively leaving the original object in a null
|
|
401
|
+
* state.
|
|
402
|
+
*
|
|
403
|
+
* @param resource A `ResourceData` object.
|
|
404
|
+
*/
|
|
405
|
+
ResourceData(ResourceData&& resource) : m_data(resource.release()) {}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @brief Constructs a ResourceData object by sharing the underlying resource.
|
|
409
|
+
*
|
|
410
|
+
* This constructor shares the underlying resource from the provided `ResourceData` object
|
|
411
|
+
* by incrementing its reference count, allowing multiple `ResourceData` objects to share ownership.
|
|
412
|
+
*
|
|
413
|
+
* @param resource A `ResourceData` object to share the resource from.
|
|
414
|
+
*/
|
|
415
|
+
ResourceData(const ResourceData& resource);
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @brief Destroys the `ResourceData` object by decreasing the reference count of the underlying resource.
|
|
419
|
+
*
|
|
420
|
+
* When the `ResourceData` object is destroyed, it decreases the reference count of the underlying
|
|
421
|
+
* resource. If the reference count reaches zero, the resource is released and its memory is freed.
|
|
422
|
+
*/
|
|
423
|
+
~ResourceData();
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* @brief Copy assignment operator that shares ownership of the underlying resource.
|
|
427
|
+
*
|
|
428
|
+
* This operator performs a deep copy of the underlying resource by sharing ownership with the `resource`
|
|
429
|
+
* object. The reference count of the underlying resource is incremented to reflect the new ownership.
|
|
430
|
+
*
|
|
431
|
+
* @param resource A `ResourceData` object to copy the resource from.
|
|
432
|
+
* @return A reference to the current `ResourceData` object after the assignment.
|
|
433
|
+
*/
|
|
434
|
+
ResourceData& operator=(const ResourceData& resource);
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* @brief Move assignment operator that transfers ownership of the underlying resource.
|
|
438
|
+
* This operator releases the underlying resource from the `resource` object and takes ownership of it,
|
|
439
|
+
* leaving the original object in a null state.
|
|
440
|
+
*
|
|
441
|
+
* @param resource A `ResourceData` object to move the resource from.
|
|
442
|
+
* @return A reference to the current `ResourceData` object after the assignment.
|
|
443
|
+
*/
|
|
444
|
+
ResourceData& operator=(ResourceData&& resource);
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @brief Swaps the underlying resources of two `ResourceData` objects.
|
|
448
|
+
*
|
|
449
|
+
* This function swaps the resource data between the current object and the provided `resource` object.
|
|
450
|
+
* After the swap, both objects will share their respective resources.
|
|
451
|
+
*
|
|
452
|
+
* @param resource The `ResourceData` object to swap with.
|
|
453
|
+
*/
|
|
454
|
+
void swap(ResourceData& resource);
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @brief Retrieves the content of the resource.
|
|
458
|
+
* @return A pointer to the content of the resource.
|
|
459
|
+
*/
|
|
460
|
+
const char* content() const;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @brief Retrieves the length of the resource content.
|
|
464
|
+
* @return The length of the resource content in bytes.
|
|
465
|
+
*/
|
|
466
|
+
size_t contentLength() const;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @brief Retrieves the MIME type of the resource content.
|
|
470
|
+
* @return The MIME type of the resource content.
|
|
471
|
+
*/
|
|
472
|
+
std::string_view mimeType() const;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @brief Retrieves the text encoding used for the resource content.
|
|
476
|
+
* @return The text encoding used for the resource content.
|
|
477
|
+
*/
|
|
478
|
+
std::string_view textEncoding() const;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* @brief Releases the underlying resource and transfers ownership.
|
|
482
|
+
* @return A pointer to the underlying `plutobook_resource_data_t` object, which is now owned by the caller.
|
|
483
|
+
*/
|
|
484
|
+
plutobook_resource_data_t* release();
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @brief Retrieves the underlying resource.
|
|
488
|
+
* @return A pointer to the underlying `plutobook_resource_data_t` resource.
|
|
489
|
+
*/
|
|
490
|
+
plutobook_resource_data_t* get() const { return m_data; }
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @brief Checks if the resource is null.
|
|
494
|
+
*
|
|
495
|
+
* This function checks if the resource data is null (i.e., not initialized or invalid).
|
|
496
|
+
*
|
|
497
|
+
* @return `true` if the resource is null, otherwise `false`.
|
|
498
|
+
*/
|
|
499
|
+
bool isNull() const { return m_data == nullptr; }
|
|
500
|
+
|
|
501
|
+
private:
|
|
502
|
+
plutobook_resource_data_t* m_data;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @brief The ResourceFetcher class is an abstract base class for fetching resources from a URL.
|
|
507
|
+
*/
|
|
508
|
+
class PLUTOBOOK_API ResourceFetcher {
|
|
509
|
+
public:
|
|
510
|
+
/**
|
|
511
|
+
* @brief Destructor
|
|
512
|
+
*/
|
|
513
|
+
virtual ~ResourceFetcher() = default;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @brief Fetches a resource from the specified URL.
|
|
517
|
+
* @param url The URL of the resource to fetch.
|
|
518
|
+
* @return A `ResourceData` object containing the fetched resource, or a null `ResourceData` if an error occurs.
|
|
519
|
+
*/
|
|
520
|
+
virtual ResourceData fetchUrl(const std::string& url) = 0;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @brief The DefaultResourceFetcher class provides a default implementation of ResourceFetcher.
|
|
525
|
+
*/
|
|
526
|
+
class PLUTOBOOK_API DefaultResourceFetcher final : public ResourceFetcher {
|
|
527
|
+
public:
|
|
528
|
+
/**
|
|
529
|
+
* @brief Destroys the DefaultResourceFetcher instance.
|
|
530
|
+
*/
|
|
531
|
+
~DefaultResourceFetcher() final;
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* @brief Sets the path to a file containing trusted CA certificates.
|
|
535
|
+
*
|
|
536
|
+
* If not set, no custom CA file is used.
|
|
537
|
+
*
|
|
538
|
+
* @param path Path to the CA certificate bundle file.
|
|
539
|
+
*/
|
|
540
|
+
void setCAInfo(std::string path) { m_caInfo = std::move(path); }
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* @brief Sets the path to a directory containing trusted CA certificates.
|
|
544
|
+
*
|
|
545
|
+
* If not set, no custom CA path is used.
|
|
546
|
+
*
|
|
547
|
+
* @param path Path to the directory with CA certificates.
|
|
548
|
+
*/
|
|
549
|
+
void setCAPath(std::string path) { m_caPath = std::move(path); }
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* @brief Enables or disables SSL peer certificate verification.
|
|
553
|
+
*
|
|
554
|
+
* If not set, verification is enabled by default.
|
|
555
|
+
*
|
|
556
|
+
* @param verify Set to true to verify the peer, false to disable verification.
|
|
557
|
+
*/
|
|
558
|
+
void setVerifyPeer(bool verify) { m_verifyPeer = verify; }
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* @brief Enables or disables SSL host name verification.
|
|
562
|
+
*
|
|
563
|
+
* If not set, verification is enabled by default.
|
|
564
|
+
*
|
|
565
|
+
* @param verify Set to true to verify the host, false to disable verification.
|
|
566
|
+
*/
|
|
567
|
+
void setVerifyHost(bool verify) { m_verifyHost = verify; }
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* @brief Enables or disables automatic following of HTTP redirects.
|
|
571
|
+
*
|
|
572
|
+
* If not set, following redirects is enabled by default.
|
|
573
|
+
*
|
|
574
|
+
* @param follow Set to true to follow redirects, false to disable.
|
|
575
|
+
*/
|
|
576
|
+
void setFollowRedirects(bool follow) { m_followRedirects = follow; }
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @brief Sets the maximum number of redirects to follow.
|
|
580
|
+
*
|
|
581
|
+
* If not set, the default maximum is 30.
|
|
582
|
+
*
|
|
583
|
+
* @param amount The maximum number of redirects.
|
|
584
|
+
*/
|
|
585
|
+
void setMaxRedirects(int amount) { m_maxRedirects = amount; }
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* @brief Sets the maximum time allowed for a request.
|
|
589
|
+
*
|
|
590
|
+
* If not set, the default timeout is 300 seconds.
|
|
591
|
+
*
|
|
592
|
+
* @param timeout Timeout duration in seconds.
|
|
593
|
+
*/
|
|
594
|
+
void setTimeout(int timeout) { m_timeout = timeout; }
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* @brief Fetches the resource at the specified URL.
|
|
598
|
+
*
|
|
599
|
+
* @param url The resource URL to fetch.
|
|
600
|
+
* @return The fetched resource data.
|
|
601
|
+
*/
|
|
602
|
+
ResourceData fetchUrl(const std::string& url) final;
|
|
603
|
+
|
|
604
|
+
private:
|
|
605
|
+
DefaultResourceFetcher();
|
|
606
|
+
|
|
607
|
+
std::string m_caInfo;
|
|
608
|
+
std::string m_caPath;
|
|
609
|
+
|
|
610
|
+
bool m_verifyPeer = true;
|
|
611
|
+
bool m_verifyHost = true;
|
|
612
|
+
|
|
613
|
+
bool m_followRedirects = true;
|
|
614
|
+
int m_maxRedirects = 30;
|
|
615
|
+
int m_timeout = 300;
|
|
616
|
+
|
|
617
|
+
friend DefaultResourceFetcher* defaultResourceFetcher();
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* @brief Returns a singleton instance of DefaultResourceFetcher.
|
|
622
|
+
* @return A pointer to the singleton DefaultResourceFetcher instance.
|
|
623
|
+
*/
|
|
624
|
+
DefaultResourceFetcher* defaultResourceFetcher();
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* @brief The OutputStream is an abstract base class for writing data to an output stream.
|
|
628
|
+
*/
|
|
629
|
+
class PLUTOBOOK_API OutputStream {
|
|
630
|
+
public:
|
|
631
|
+
/**
|
|
632
|
+
* @brief Destructor
|
|
633
|
+
*/
|
|
634
|
+
virtual ~OutputStream() = default;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* @brief Writes data to the output stream.
|
|
638
|
+
* @param data A pointer to the buffer containing the data to be written.
|
|
639
|
+
* @param length The length of the data to be written, in bytes.
|
|
640
|
+
* @return true if the data was written successfully, false otherwise.
|
|
641
|
+
*/
|
|
642
|
+
virtual bool write(const char* data, size_t length) = 0;
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* @brief The Canvas class provides a basic interface for manipulating a 2D drawing surface.
|
|
647
|
+
*/
|
|
648
|
+
class PLUTOBOOK_API Canvas {
|
|
649
|
+
public:
|
|
650
|
+
/**
|
|
651
|
+
* @brief Destructor
|
|
652
|
+
*/
|
|
653
|
+
virtual ~Canvas();
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* @brief Flushes any pending drawing operations.
|
|
657
|
+
*/
|
|
658
|
+
void flush();
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* @brief Finishes all drawing operations and cleans up the canvas.
|
|
662
|
+
*/
|
|
663
|
+
void finish();
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* @brief Translates the origin of the coordinate system.
|
|
667
|
+
* @param tx The horizontal translation distance.
|
|
668
|
+
* @param ty The vertical translation distance.
|
|
669
|
+
*/
|
|
670
|
+
void translate(float tx, float ty);
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* @brief Scales the coordinate system.
|
|
674
|
+
* @param sx The horizontal scaling factor.
|
|
675
|
+
* @param sy The vertical scaling factor.
|
|
676
|
+
*/
|
|
677
|
+
void scale(float sx, float sy);
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* @brief Rotates the coordinate system.
|
|
681
|
+
* @param angle The rotation angle in radians.
|
|
682
|
+
*/
|
|
683
|
+
void rotate(float angle);
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* @brief Multiplies the current transformation matrix with the specified matrix.
|
|
687
|
+
* @param a The horizontal scaling factor.
|
|
688
|
+
* @param b The horizontal skewing factor.
|
|
689
|
+
* @param c The vertical skewing factor.
|
|
690
|
+
* @param d The vertical scaling factor.
|
|
691
|
+
* @param e The horizontal translation distance.
|
|
692
|
+
* @param f The vertical translation distance.
|
|
693
|
+
*/
|
|
694
|
+
void transform(float a, float b, float c, float d, float e, float f);
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* @brief Resets the current transformation to the identity matrix.
|
|
698
|
+
* @param a The horizontal scaling factor.
|
|
699
|
+
* @param b The horizontal skewing factor.
|
|
700
|
+
* @param c The vertical skewing factor.
|
|
701
|
+
* @param d The vertical scaling factor.
|
|
702
|
+
* @param e The horizontal translation distance.
|
|
703
|
+
* @param f The vertical translation distance.
|
|
704
|
+
*/
|
|
705
|
+
void setMatrix(float a, float b, float c, float d, float e, float f);
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* @brief Resets the transformation matrix to the identity matrix.
|
|
709
|
+
*/
|
|
710
|
+
void resetMatrix();
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* @brief Intersects the current clip with the specified rectangle.
|
|
714
|
+
* @param x The x-coordinate of the top-left corner of the rectangle.
|
|
715
|
+
* @param y The y-coordinate of the top-left corner of the rectangle.
|
|
716
|
+
* @param width width The width of the rectangle.
|
|
717
|
+
* @param height height The height of the rectangle.
|
|
718
|
+
*/
|
|
719
|
+
void clipRect(float x, float y, float width, float height);
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* @brief Clears the canvas surface with the specified color.
|
|
723
|
+
* @param red The red component of the color.
|
|
724
|
+
* @param green The green component of the color.
|
|
725
|
+
* @param blue The blue component of the color.
|
|
726
|
+
* @param alpha The alpha component of the color.
|
|
727
|
+
*/
|
|
728
|
+
void clearSurface(float red, float green, float blue, float alpha);
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* @brief Saves the current drawing state.
|
|
732
|
+
*/
|
|
733
|
+
void saveState();
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* @brief Restores the most recently saved drawing state.
|
|
737
|
+
*/
|
|
738
|
+
void restoreState();
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* @brief Gets the underlying cairo surface associated with the canvas.
|
|
742
|
+
* @return A pointer to the underlying `cairo_surface_t` object.
|
|
743
|
+
*/
|
|
744
|
+
cairo_surface_t* surface() const;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* @brief Gets the underlying cairo context associated with the canvas.
|
|
748
|
+
* @return A pointer to the underlying `cairo_t` object.
|
|
749
|
+
*/
|
|
750
|
+
cairo_t* context() const;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* @brief Gets the underlying canvas.
|
|
754
|
+
* @return A pointer to the underlying `plutobook_canvas_t` object.
|
|
755
|
+
*/
|
|
756
|
+
plutobook_canvas_t* canvas() const { return m_canvas; }
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* @brief Checks if the canvas is null.
|
|
760
|
+
* @return `true` if the canvas is null, otherwise `false`.
|
|
761
|
+
*/
|
|
762
|
+
bool isNull() const { return m_canvas == nullptr; }
|
|
763
|
+
|
|
764
|
+
protected:
|
|
765
|
+
Canvas(const Canvas&) = delete;
|
|
766
|
+
Canvas& operator=(const Canvas&) = delete;
|
|
767
|
+
Canvas(plutobook_canvas_t* canvas) : m_canvas(canvas) {}
|
|
768
|
+
plutobook_canvas_t* m_canvas;
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* @brief Defines different memory formats for image data.
|
|
773
|
+
*/
|
|
774
|
+
enum class ImageFormat {
|
|
775
|
+
Invalid = PLUTOBOOK_IMAGE_FORMAT_INVALID,
|
|
776
|
+
ARGB32 = PLUTOBOOK_IMAGE_FORMAT_ARGB32,
|
|
777
|
+
RGB24 = PLUTOBOOK_IMAGE_FORMAT_RGB24,
|
|
778
|
+
A8 = PLUTOBOOK_IMAGE_FORMAT_A8,
|
|
779
|
+
A1 = PLUTOBOOK_IMAGE_FORMAT_A1
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
class PLUTOBOOK_API ImageCanvas final : public Canvas {
|
|
783
|
+
public:
|
|
784
|
+
/**
|
|
785
|
+
* @brief Constructs an ImageCanvas with the specified width, height, and optional image format.
|
|
786
|
+
* @param width The width of the canvas.
|
|
787
|
+
* @param height The height of the canvas.
|
|
788
|
+
* @param format The format of the image
|
|
789
|
+
*/
|
|
790
|
+
ImageCanvas(int width, int height, ImageFormat format = ImageFormat::ARGB32);
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* @brief Constructs an ImageCanvas with the provided image data, width, height, stride, and optional image format.
|
|
794
|
+
* @param data A pointer to the image data.
|
|
795
|
+
* @param width The width of the image data.
|
|
796
|
+
* @param height The height of the image data.
|
|
797
|
+
* @param stride The stride of the image data.
|
|
798
|
+
* @param format The format of the image data
|
|
799
|
+
*/
|
|
800
|
+
ImageCanvas(uint8_t* data, int width, int height, int stride, ImageFormat format = ImageFormat::ARGB32);
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* @brief Retrieves a pointer to the image data.
|
|
804
|
+
* @return A pointer to the image data.
|
|
805
|
+
*/
|
|
806
|
+
uint8_t* data() const;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* @brief Retrieves the width of the canvas.
|
|
810
|
+
* @return The width of the canvas.
|
|
811
|
+
*/
|
|
812
|
+
int width() const;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* @brief Retrieves the height of the canvas.
|
|
816
|
+
* @return The height of the canvas.
|
|
817
|
+
*/
|
|
818
|
+
int height() const;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* @brief Retrieves the stride of the image data.
|
|
822
|
+
* @return The stride of the image data.
|
|
823
|
+
*/
|
|
824
|
+
int stride() const;
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @brief Retrieves the format of the image data.
|
|
828
|
+
* @return The format of the image data.
|
|
829
|
+
*/
|
|
830
|
+
ImageFormat format() const;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* @brief Writes the image data to a PNG file.
|
|
834
|
+
* @param filename The name of the PNG file to write to.
|
|
835
|
+
* @return true if the image was successfully written to the file, false otherwise.
|
|
836
|
+
*/
|
|
837
|
+
bool writeToPng(const std::string& filename) const;
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* @brief Writes the image data to an output stream in PNG format.
|
|
841
|
+
* @param output The output stream to write to.
|
|
842
|
+
* @return true if the image was successfully written to the output stream, false otherwise.
|
|
843
|
+
*/
|
|
844
|
+
bool writeToPng(OutputStream& output) const;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* @brief Writes the image data to a PNG file using a custom write callback.
|
|
848
|
+
* @param callback The callback function for writing data
|
|
849
|
+
* @param closure A pointer to user-defined data to be passed to the callback.
|
|
850
|
+
* @return true if the image was successfully written using the callback, false otherwise.
|
|
851
|
+
*/
|
|
852
|
+
bool writeToPng(plutobook_stream_write_callback_t callback, void* closure) const;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* @brief The PDFCanvas class represents a canvas for creating PDF documents.
|
|
857
|
+
*/
|
|
858
|
+
class PLUTOBOOK_API PDFCanvas final : public Canvas {
|
|
859
|
+
public:
|
|
860
|
+
/**
|
|
861
|
+
* @brief Constructs a PDFCanvas that writes to a PDF file with the specified filename and page size.
|
|
862
|
+
* @param filename The name of the PDF file to create.
|
|
863
|
+
* @param pageSize The size of the pages in the PDF.
|
|
864
|
+
*/
|
|
865
|
+
PDFCanvas(const std::string& filename, const PageSize& pageSize);
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @brief Constructs a PDFCanvas that writes to an output stream with the specified page size.
|
|
869
|
+
* @param output The output stream to write the PDF to.
|
|
870
|
+
* @param pageSize The size of the pages in the PDF.
|
|
871
|
+
*/
|
|
872
|
+
PDFCanvas(OutputStream& output, const PageSize& pageSize);
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* @brief Constructs a PDFCanvas that uses a custom write callback and closure with the specified page size.
|
|
876
|
+
* @param callback The callback function for writing PDF data.
|
|
877
|
+
* @param closure A pointer to user-defined data to be passed to the callback.
|
|
878
|
+
* @param pageSize The size of the pages in the PDF.
|
|
879
|
+
*/
|
|
880
|
+
PDFCanvas(plutobook_stream_write_callback_t callback, void* closure, const PageSize& pageSize);
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* @brief Sets the title of the PDF document.
|
|
884
|
+
* @param title The title of the PDF document.
|
|
885
|
+
*/
|
|
886
|
+
void setTitle(const std::string& title);
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* @brief Sets the author of the PDF document.
|
|
890
|
+
* @param author The author of the PDF document.
|
|
891
|
+
*/
|
|
892
|
+
void setAuthor(const std::string& author);
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* @brief Sets the subject of the PDF document.
|
|
896
|
+
* @param subject The subject of the PDF document.
|
|
897
|
+
*/
|
|
898
|
+
void setSubject(const std::string& subject);
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* @brief Sets the keywords associated with the PDF document.
|
|
902
|
+
* @param keywords The keywords associated with the PDF document.
|
|
903
|
+
*/
|
|
904
|
+
void setKeywords(const std::string& keywords);
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* @brief Sets the creator of the PDF document.
|
|
908
|
+
* @param creator The creator of the PDF document.
|
|
909
|
+
*/
|
|
910
|
+
void setCreator(const std::string& creator);
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* @brief Sets the creation date of the PDF document.
|
|
914
|
+
*
|
|
915
|
+
* The date must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss, with an optional timezone "[+/-]hh:mm" or "Z" for UTC.
|
|
916
|
+
*
|
|
917
|
+
* @param creationDate The creation date of the PDF document.
|
|
918
|
+
*/
|
|
919
|
+
void setCreationDate(const std::string& creationDate);
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* @brief Sets the modification date of the PDF document.
|
|
923
|
+
*
|
|
924
|
+
* The date must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss, with an optional timezone "[+/-]hh:mm" or "Z" for UTC.
|
|
925
|
+
*
|
|
926
|
+
* @param modificationDate The modification date of the PDF document.
|
|
927
|
+
*/
|
|
928
|
+
void setModificationDate(const std::string& modificationDate);
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* @brief Sets the page size of the PDF document.
|
|
932
|
+
* @param pageSize The page size of the PDF document.
|
|
933
|
+
*/
|
|
934
|
+
void setPageSize(const PageSize& pageSize);
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* @brief Signals the end of a page and starts a new page.
|
|
938
|
+
*/
|
|
939
|
+
void showPage();
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
class Heap;
|
|
943
|
+
class Document;
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* @brief Defines the different media types used for CSS @media queries.
|
|
947
|
+
*/
|
|
948
|
+
enum class MediaType {
|
|
949
|
+
Print = PLUTOBOOK_MEDIA_TYPE_PRINT,
|
|
950
|
+
Screen = PLUTOBOOK_MEDIA_TYPE_SCREEN
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
class PLUTOBOOK_API Book {
|
|
954
|
+
public:
|
|
955
|
+
/**
|
|
956
|
+
* @brief Constructs a Book object with the given page size, margins, and media type.
|
|
957
|
+
*
|
|
958
|
+
* @param size The initial page size.
|
|
959
|
+
* @param margins The initial page margins.
|
|
960
|
+
* @param media The media type used for media queries.
|
|
961
|
+
*/
|
|
962
|
+
Book(const PageSize& size, const PageMargins& margins = PageMargins::Normal, MediaType media = MediaType::Print);
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* @brief Destructor
|
|
966
|
+
*/
|
|
967
|
+
~Book();
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* @brief Sets the title of the document.
|
|
971
|
+
* @param title The title of the document.
|
|
972
|
+
*/
|
|
973
|
+
void setTitle(std::string title) { m_title = std::move(title); }
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* @brief Gets the title of the document.
|
|
977
|
+
* @return The title of the document.
|
|
978
|
+
*/
|
|
979
|
+
const std::string& title() const { return m_title; }
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* @brief Sets the author of the document.
|
|
983
|
+
* @param author The author of the document.
|
|
984
|
+
*/
|
|
985
|
+
void setAuthor(std::string author) { m_author = std::move(author); }
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* @brief Gets the author of the document.
|
|
989
|
+
* @return The author of the document.
|
|
990
|
+
*/
|
|
991
|
+
const std::string& author() const { return m_author; }
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* @brief Sets the subject of the document.
|
|
995
|
+
* @param subject The subject of the document.
|
|
996
|
+
*/
|
|
997
|
+
void setSubject(std::string subject) { m_subject = std::move(subject); }
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* @brief Gets the subject of the document.
|
|
1001
|
+
* @return The subject of the document.
|
|
1002
|
+
*/
|
|
1003
|
+
const std::string& subject() const { return m_subject; }
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* @brief Sets the keywords associated with the document.
|
|
1007
|
+
* @param keywords The keywords associated with the document.
|
|
1008
|
+
*/
|
|
1009
|
+
void setKeywords(std::string keywords) { m_keywords = std::move(keywords); }
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* @brief Gets the keywords associated with the document.
|
|
1013
|
+
* @return The keywords associated with the document.
|
|
1014
|
+
*/
|
|
1015
|
+
const std::string& keywords() const { return m_keywords; }
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* @brief Sets the creator of the document.
|
|
1019
|
+
* @param creator The creator of the document.
|
|
1020
|
+
*/
|
|
1021
|
+
void setCreator(std::string creator) { m_creator = std::move(creator); }
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* @brief Gets the creator of the document.
|
|
1025
|
+
* @return The creator of the document.
|
|
1026
|
+
*/
|
|
1027
|
+
const std::string& creator() const { return m_creator; }
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* @brief Sets the creation date of the document.
|
|
1031
|
+
*
|
|
1032
|
+
* The date must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss, with an optional timezone "[+/-]hh:mm" or "Z" for UTC.
|
|
1033
|
+
*
|
|
1034
|
+
* @param creationDate The creation date of the document.
|
|
1035
|
+
*/
|
|
1036
|
+
void setCreationDate(std::string creationDate) { m_creationDate = std::move(creationDate); }
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* @brief Gets the creation date of the document.
|
|
1040
|
+
* @return The creation date of the document.
|
|
1041
|
+
*/
|
|
1042
|
+
const std::string& creationDate() const { return m_creationDate; }
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* @brief Sets the modification date of the document.
|
|
1046
|
+
*
|
|
1047
|
+
* The date must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss, with an optional timezone "[+/-]hh:mm" or "Z" for UTC.
|
|
1048
|
+
*
|
|
1049
|
+
* @param modificationDate The modification date of the document.
|
|
1050
|
+
*/
|
|
1051
|
+
void setModificationDate(std::string modificationDate) { m_modificationDate = std::move(modificationDate); }
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* @brief Gets the modification date of the document.
|
|
1055
|
+
* @return The modification date of the document.
|
|
1056
|
+
*/
|
|
1057
|
+
const std::string& modificationDate() const { return m_modificationDate; }
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* @brief Returns the width of the viewport.
|
|
1061
|
+
* @return The width of the viewport in pixels.
|
|
1062
|
+
*/
|
|
1063
|
+
float viewportWidth() const;
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* @brief Returns the height of the viewport.
|
|
1067
|
+
* @return The height of the viewport in pixels.
|
|
1068
|
+
*/
|
|
1069
|
+
float viewportHeight() const;
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* @brief Returns the width of the document.
|
|
1073
|
+
* @return The width of the document in pixels.
|
|
1074
|
+
*/
|
|
1075
|
+
float documentWidth() const;
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* @brief Returns the height of the document.
|
|
1079
|
+
* @return The height of the document in pixels.
|
|
1080
|
+
*/
|
|
1081
|
+
float documentHeight() const;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* @brief Returns the initial page size.
|
|
1085
|
+
* @return The initial page size.
|
|
1086
|
+
*/
|
|
1087
|
+
const PageSize& pageSize() const { return m_pageSize; }
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* @brief Returns the initial page margins.
|
|
1091
|
+
* @return The initial page margins.
|
|
1092
|
+
*/
|
|
1093
|
+
const PageMargins& pageMargins() const { return m_pageMargins; }
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* @brief Returns the media type used for media queries.
|
|
1097
|
+
* @return The media type used for media queries.
|
|
1098
|
+
*/
|
|
1099
|
+
MediaType mediaType() const { return m_mediaType; }
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* @brief Returns the number of pages in the document.
|
|
1103
|
+
* @return The number of pages in the document.
|
|
1104
|
+
*/
|
|
1105
|
+
uint32_t pageCount() const;
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* @brief Returns the page size at the specified index.
|
|
1109
|
+
* @param pageIndex The index of the page.
|
|
1110
|
+
* @return The size of the page at the specified index.
|
|
1111
|
+
*/
|
|
1112
|
+
PageSize pageSizeAt(uint32_t pageIndex) const;
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* @brief Loads the document from the specified URL.
|
|
1116
|
+
* @param url The URL to load the document from.
|
|
1117
|
+
* @param userStyle An optional user-defined style to apply.
|
|
1118
|
+
* @param userScript An optional user-defined script to run after the document has loaded.
|
|
1119
|
+
* @return `true` on success, or `false` on failure.
|
|
1120
|
+
*/
|
|
1121
|
+
bool loadUrl(std::string_view url, std::string_view userStyle = {}, std::string_view userScript = {});
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* @brief Loads the document from the specified data.
|
|
1125
|
+
* @param data The data to load the document from.
|
|
1126
|
+
* @param length The length of the data in bytes.
|
|
1127
|
+
* @param mimeType The MIME type of the data.
|
|
1128
|
+
* @param textEncoding The text encoding of the data.
|
|
1129
|
+
* @param userStyle An optional user-defined style to apply.
|
|
1130
|
+
* @param userScript An optional user-defined script to run after the document has loaded.
|
|
1131
|
+
* @param baseUrl The base URL for resolving relative URLs.
|
|
1132
|
+
* @return `true` on success, or `false` on failure.
|
|
1133
|
+
*/
|
|
1134
|
+
bool loadData(const char* data, size_t length, std::string_view mimeType = {}, std::string_view textEncoding = {},
|
|
1135
|
+
std::string_view userStyle = {}, std::string_view userScript = {}, std::string_view baseUrl = {});
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* @brief Loads the document from the specified image data.
|
|
1139
|
+
* @param data The image data to load the document from.
|
|
1140
|
+
* @param length The length of the image data in bytes.
|
|
1141
|
+
* @param mimeType The MIME type of the image data.
|
|
1142
|
+
* @param textEncoding The text encoding of the image data.
|
|
1143
|
+
* @param userStyle An optional user-defined style to apply.
|
|
1144
|
+
* @param userScript An optional user-defined script to run after the document has loaded.
|
|
1145
|
+
* @param baseUrl The base URL for resolving relative URLs.
|
|
1146
|
+
* @return `true` on success, or `false` on failure.
|
|
1147
|
+
*/
|
|
1148
|
+
bool loadImage(const char* data, size_t length, std::string_view mimeType = {}, std::string_view textEncoding = {},
|
|
1149
|
+
std::string_view userStyle = {}, std::string_view userScript = {}, std::string_view baseUrl = {});
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* @brief Loads the document from the specified XML data.
|
|
1153
|
+
* @param content The XML data to load the document from, encoded in UTF-8.
|
|
1154
|
+
* @param userStyle An optional user-defined style to apply.
|
|
1155
|
+
* @param userScript An optional user-defined script to run after the document has loaded.
|
|
1156
|
+
* @param baseUrl The base URL for resolving relative URLs.
|
|
1157
|
+
* @return `true` on success, or `false` on failure.
|
|
1158
|
+
*/
|
|
1159
|
+
bool loadXml(std::string_view content, std::string_view userStyle = {},
|
|
1160
|
+
std::string_view userScript = {}, std::string_view baseUrl = {});
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* @brief Loads the document from the specified HTML data.
|
|
1164
|
+
* @param content The HTML data to load the document from, encoded in UTF-8.
|
|
1165
|
+
* @param userStyle An optional user-defined style to apply.
|
|
1166
|
+
* @param userScript An optional user-defined script to run after the document has loaded.
|
|
1167
|
+
* @param baseUrl The base URL for resolving relative URLs.
|
|
1168
|
+
* @return `true` on success, or `false` on failure.
|
|
1169
|
+
*/
|
|
1170
|
+
bool loadHtml(std::string_view content, std::string_view userStyle = {},
|
|
1171
|
+
std::string_view userScript = {}, std::string_view baseUrl = {});
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* @brief Clears the content of the document.
|
|
1175
|
+
*/
|
|
1176
|
+
void clearContent();
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* @brief Renders the specified page to the given canvas.
|
|
1180
|
+
* @param canvas The canvas to render the page on.
|
|
1181
|
+
* @param pageIndex The index of the page to render.
|
|
1182
|
+
*/
|
|
1183
|
+
void renderPage(Canvas& canvas, uint32_t pageIndex) const;
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* @brief Renders the specified page to the given canvas.
|
|
1187
|
+
* @param canvas The canvas to render the page on.
|
|
1188
|
+
* @param pageIndex The index of the page to render.
|
|
1189
|
+
*/
|
|
1190
|
+
void renderPage(plutobook_canvas_t* canvas, uint32_t pageIndex) const;
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* @brief Renders the specified page to the given canvas.
|
|
1194
|
+
* @param canvas The canvas to render the page on.
|
|
1195
|
+
* @param pageIndex The index of the page to render.
|
|
1196
|
+
*/
|
|
1197
|
+
void renderPage(cairo_t* canvas, uint32_t pageIndex) const;
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* @brief Renders the entire document to the given canvas.
|
|
1201
|
+
* @param canvas The canvas to render the entire document on.
|
|
1202
|
+
*/
|
|
1203
|
+
void renderDocument(Canvas& canvas) const;
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* @brief Renders a specific rectangular portion of the document to the given canvas.
|
|
1207
|
+
* @param canvas The canvas to render the document portion on.
|
|
1208
|
+
* @param x The x-coordinate of the top-left corner of the rectangle.
|
|
1209
|
+
* @param y The y-coordinate of the top-left corner of the rectangle.
|
|
1210
|
+
* @param width The width of the rectangle to render.
|
|
1211
|
+
* @param height The height of the rectangle to render.
|
|
1212
|
+
*/
|
|
1213
|
+
void renderDocument(Canvas& canvas, float x, float y, float width, float height) const;
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* @brief Renders the entire document to the given canvas.
|
|
1217
|
+
* @param canvas The canvas to render the entire document on.
|
|
1218
|
+
*/
|
|
1219
|
+
void renderDocument(plutobook_canvas_t* canvas) const;
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* @brief Renders a specific rectangular portion of the document to the given canvas.
|
|
1223
|
+
* @param canvas The canvas to render the document portion on.
|
|
1224
|
+
* @param x The x-coordinate of the top-left corner of the rectangle.
|
|
1225
|
+
* @param y The y-coordinate of the top-left corner of the rectangle.
|
|
1226
|
+
* @param width The width of the rectangle to render.
|
|
1227
|
+
* @param height The height of the rectangle to render.
|
|
1228
|
+
*/
|
|
1229
|
+
void renderDocument(plutobook_canvas_t* canvas, float x, float y, float width, float height) const;
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* @brief Renders the entire document to the given canvas.
|
|
1233
|
+
* @param canvas The canvas to render the entire document on.
|
|
1234
|
+
*/
|
|
1235
|
+
void renderDocument(cairo_t* canvas) const;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* @brief Renders a specific rectangular portion of the document to the given canvas.
|
|
1239
|
+
* @param canvas The canvas to render the document portion on.
|
|
1240
|
+
* @param x The x-coordinate of the top-left corner of the rectangle.
|
|
1241
|
+
* @param y The y-coordinate of the top-left corner of the rectangle.
|
|
1242
|
+
* @param width The width of the rectangle to render.
|
|
1243
|
+
* @param height The height of the rectangle to render.
|
|
1244
|
+
*/
|
|
1245
|
+
void renderDocument(cairo_t* canvas, float x, float y, float width, float height) const;
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* @brief Writes a range of pages from the document to a PDF file.
|
|
1249
|
+
* @param filename The file path where the PDF document will be written.
|
|
1250
|
+
* @param pageStart The first page in the range to be written (inclusive).
|
|
1251
|
+
* @param pageEnd The last page in the range to be written (inclusive).
|
|
1252
|
+
* @param pageStep The increment used to advance through pages in the range.
|
|
1253
|
+
* @return `true` on success, or `false` on failure.
|
|
1254
|
+
*/
|
|
1255
|
+
bool writeToPdf(const std::string& filename, uint32_t pageStart = kMinPageCount,
|
|
1256
|
+
uint32_t pageEnd = kMaxPageCount, int pageStep = 1) const;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* @brief Writes the entire document to a PDF stream using a callback function.
|
|
1260
|
+
* @param output The output stream where the PDF document will be written.
|
|
1261
|
+
* @param pageStart The first page in the range to be written (inclusive).
|
|
1262
|
+
* @param pageEnd The last page in the range to be written (inclusive).
|
|
1263
|
+
* @param pageStep The increment used to advance through pages in the range.
|
|
1264
|
+
* @return `true` on success, or `false` on failure.
|
|
1265
|
+
*/
|
|
1266
|
+
bool writeToPdf(OutputStream& output, uint32_t pageStart = kMinPageCount,
|
|
1267
|
+
uint32_t pageEnd = kMaxPageCount, int pageStep = 1) const;
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* @brief Writes the entire document to a PDF stream using a callback function.
|
|
1271
|
+
* @param callback A callback function used for writing the PDF stream.
|
|
1272
|
+
* @param closure A user-defined pointer passed to the callback function for additional data.
|
|
1273
|
+
* @param pageStart The first page in the range to be written (inclusive).
|
|
1274
|
+
* @param pageEnd The last page in the range to be written (inclusive).
|
|
1275
|
+
* @param pageStep The increment used to advance through pages in the range.
|
|
1276
|
+
* @return `true` on success, or `false` on failure.
|
|
1277
|
+
*/
|
|
1278
|
+
bool writeToPdf(plutobook_stream_write_callback_t callback, void* closure,
|
|
1279
|
+
uint32_t pageStart = kMinPageCount, uint32_t pageEnd = kMaxPageCount, int pageStep = 1) const;
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* @brief Writes the entire document to a PNG image file.
|
|
1283
|
+
* @param filename The file path where the PNG image will be written.
|
|
1284
|
+
* @param width The desired width in pixels, or -1 to auto-scale based on the document size.
|
|
1285
|
+
* @param height The desired height in pixels, or -1 to auto-scale based on the document size.
|
|
1286
|
+
* @return `true` on success, or `false` on failure.
|
|
1287
|
+
*/
|
|
1288
|
+
bool writeToPng(const std::string& filename, int width = -1, int height = -1) const;
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* @brief Writes the entire document to a PNG image stream.
|
|
1292
|
+
* @param output The output stream where the PNG image will be written.
|
|
1293
|
+
* @param width The desired width in pixels, or -1 to auto-scale based on the document size.
|
|
1294
|
+
* @param height The desired height in pixels, or -1 to auto-scale based on the document size.
|
|
1295
|
+
* @return `true` on success, or `false` on failure.
|
|
1296
|
+
*/
|
|
1297
|
+
bool writeToPng(OutputStream& output, int width = -1, int height = -1) const;
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* @brief Writes the entire document to a PNG image stream using a callback function.
|
|
1301
|
+
* @param callback A callback function to handle the image data stream.
|
|
1302
|
+
* @param closure A pointer to user-defined data to pass to the callback function.
|
|
1303
|
+
* @param width The desired width in pixels, or -1 to auto-scale based on the document size.
|
|
1304
|
+
* @param height The desired height in pixels, or -1 to auto-scale based on the document size.
|
|
1305
|
+
* @return `true` on success, or `false` on failure.
|
|
1306
|
+
*/
|
|
1307
|
+
bool writeToPng(plutobook_stream_write_callback_t callback, void* closure, int width = -1, int height = -1) const;
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* @brief Sets a custom resource fetcher to be used for fetching external resources.
|
|
1311
|
+
*
|
|
1312
|
+
* @param fetcher A pointer to a `ResourceFetcher` object. Pass `nullptr` to clear the custom fetcher.
|
|
1313
|
+
*/
|
|
1314
|
+
void setCustomResourceFetcher(ResourceFetcher* fetcher) { m_customResourceFetcher = fetcher; }
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* @brief Retrieves the currently set custom resource fetcher.
|
|
1318
|
+
*
|
|
1319
|
+
* @return A pointer to the `ResourceFetcher` instance, or `nullptr` if none is set.
|
|
1320
|
+
*/
|
|
1321
|
+
ResourceFetcher* customResourceFetcher() const { return m_customResourceFetcher; }
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* @internal
|
|
1325
|
+
*/
|
|
1326
|
+
Heap* heap() const { return m_heap.get(); }
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* @internal
|
|
1330
|
+
*/
|
|
1331
|
+
Document* document() const { return m_document.get(); }
|
|
1332
|
+
|
|
1333
|
+
private:
|
|
1334
|
+
Document* buildIfNeeded() const;
|
|
1335
|
+
Document* layoutIfNeeded() const;
|
|
1336
|
+
Document* paginateIfNeeded() const;
|
|
1337
|
+
|
|
1338
|
+
PageSize m_pageSize;
|
|
1339
|
+
PageMargins m_pageMargins;
|
|
1340
|
+
MediaType m_mediaType;
|
|
1341
|
+
|
|
1342
|
+
mutable bool m_needsBuild{true};
|
|
1343
|
+
mutable bool m_needsLayout{true};
|
|
1344
|
+
mutable bool m_needsPagination{true};
|
|
1345
|
+
|
|
1346
|
+
std::string m_title;
|
|
1347
|
+
std::string m_author;
|
|
1348
|
+
std::string m_subject;
|
|
1349
|
+
std::string m_keywords;
|
|
1350
|
+
std::string m_creator;
|
|
1351
|
+
std::string m_creationDate;
|
|
1352
|
+
std::string m_modificationDate;
|
|
1353
|
+
|
|
1354
|
+
ResourceFetcher* m_customResourceFetcher{nullptr};
|
|
1355
|
+
std::unique_ptr<Heap> m_heap;
|
|
1356
|
+
std::unique_ptr<Document> m_document;
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
} // namespace plutobook
|
|
1360
|
+
|
|
1361
|
+
#endif // PLUTOBOOK_HPP
|