@lexmata/micropdf 0.4.0

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 (170) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +985 -0
  3. package/binding.gyp +73 -0
  4. package/dist/annot.d.ts +458 -0
  5. package/dist/annot.d.ts.map +1 -0
  6. package/dist/annot.js +697 -0
  7. package/dist/annot.js.map +1 -0
  8. package/dist/archive.d.ts +128 -0
  9. package/dist/archive.d.ts.map +1 -0
  10. package/dist/archive.js +268 -0
  11. package/dist/archive.js.map +1 -0
  12. package/dist/buffer.d.ts +572 -0
  13. package/dist/buffer.d.ts.map +1 -0
  14. package/dist/buffer.js +971 -0
  15. package/dist/buffer.js.map +1 -0
  16. package/dist/colorspace.d.ts +287 -0
  17. package/dist/colorspace.d.ts.map +1 -0
  18. package/dist/colorspace.js +542 -0
  19. package/dist/colorspace.js.map +1 -0
  20. package/dist/context.d.ts +184 -0
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/context.js +320 -0
  23. package/dist/context.js.map +1 -0
  24. package/dist/cookie.d.ts +164 -0
  25. package/dist/cookie.d.ts.map +1 -0
  26. package/dist/cookie.js +306 -0
  27. package/dist/cookie.js.map +1 -0
  28. package/dist/device.d.ts +169 -0
  29. package/dist/device.d.ts.map +1 -0
  30. package/dist/device.js +350 -0
  31. package/dist/device.js.map +1 -0
  32. package/dist/display-list.d.ts +202 -0
  33. package/dist/display-list.d.ts.map +1 -0
  34. package/dist/display-list.js +410 -0
  35. package/dist/display-list.js.map +1 -0
  36. package/dist/document.d.ts +637 -0
  37. package/dist/document.d.ts.map +1 -0
  38. package/dist/document.js +902 -0
  39. package/dist/document.js.map +1 -0
  40. package/dist/easy.d.ts +423 -0
  41. package/dist/easy.d.ts.map +1 -0
  42. package/dist/easy.js +644 -0
  43. package/dist/easy.js.map +1 -0
  44. package/dist/enhanced.d.ts +226 -0
  45. package/dist/enhanced.d.ts.map +1 -0
  46. package/dist/enhanced.js +368 -0
  47. package/dist/enhanced.js.map +1 -0
  48. package/dist/filter.d.ts +51 -0
  49. package/dist/filter.d.ts.map +1 -0
  50. package/dist/filter.js +381 -0
  51. package/dist/filter.js.map +1 -0
  52. package/dist/font.d.ts +222 -0
  53. package/dist/font.d.ts.map +1 -0
  54. package/dist/font.js +381 -0
  55. package/dist/font.js.map +1 -0
  56. package/dist/form.d.ts +214 -0
  57. package/dist/form.d.ts.map +1 -0
  58. package/dist/form.js +497 -0
  59. package/dist/form.js.map +1 -0
  60. package/dist/geometry.d.ts +469 -0
  61. package/dist/geometry.d.ts.map +1 -0
  62. package/dist/geometry.js +780 -0
  63. package/dist/geometry.js.map +1 -0
  64. package/dist/image.d.ts +172 -0
  65. package/dist/image.d.ts.map +1 -0
  66. package/dist/image.js +348 -0
  67. package/dist/image.js.map +1 -0
  68. package/dist/index.d.ts +171 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +339 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/link.d.ts +168 -0
  73. package/dist/link.d.ts.map +1 -0
  74. package/dist/link.js +343 -0
  75. package/dist/link.js.map +1 -0
  76. package/dist/micropdf.d.ts +40 -0
  77. package/dist/micropdf.d.ts.map +1 -0
  78. package/dist/micropdf.js +45 -0
  79. package/dist/micropdf.js.map +1 -0
  80. package/dist/nanopdf.d.ts +40 -0
  81. package/dist/nanopdf.d.ts.map +1 -0
  82. package/dist/nanopdf.js +45 -0
  83. package/dist/nanopdf.js.map +1 -0
  84. package/dist/native.d.ts +242 -0
  85. package/dist/native.d.ts.map +1 -0
  86. package/dist/native.js +509 -0
  87. package/dist/native.js.map +1 -0
  88. package/dist/output.d.ts +166 -0
  89. package/dist/output.d.ts.map +1 -0
  90. package/dist/output.js +365 -0
  91. package/dist/output.js.map +1 -0
  92. package/dist/path.d.ts +420 -0
  93. package/dist/path.d.ts.map +1 -0
  94. package/dist/path.js +687 -0
  95. package/dist/path.js.map +1 -0
  96. package/dist/pdf/object.d.ts +489 -0
  97. package/dist/pdf/object.d.ts.map +1 -0
  98. package/dist/pdf/object.js +1045 -0
  99. package/dist/pdf/object.js.map +1 -0
  100. package/dist/pixmap.d.ts +315 -0
  101. package/dist/pixmap.d.ts.map +1 -0
  102. package/dist/pixmap.js +590 -0
  103. package/dist/pixmap.js.map +1 -0
  104. package/dist/profiler.d.ts +159 -0
  105. package/dist/profiler.d.ts.map +1 -0
  106. package/dist/profiler.js +380 -0
  107. package/dist/profiler.js.map +1 -0
  108. package/dist/render-options.d.ts +227 -0
  109. package/dist/render-options.d.ts.map +1 -0
  110. package/dist/render-options.js +130 -0
  111. package/dist/render-options.js.map +1 -0
  112. package/dist/resource-tracking.d.ts +332 -0
  113. package/dist/resource-tracking.d.ts.map +1 -0
  114. package/dist/resource-tracking.js +653 -0
  115. package/dist/resource-tracking.js.map +1 -0
  116. package/dist/simple.d.ts +276 -0
  117. package/dist/simple.d.ts.map +1 -0
  118. package/dist/simple.js +343 -0
  119. package/dist/simple.js.map +1 -0
  120. package/dist/stext.d.ts +290 -0
  121. package/dist/stext.d.ts.map +1 -0
  122. package/dist/stext.js +312 -0
  123. package/dist/stext.js.map +1 -0
  124. package/dist/stream.d.ts +174 -0
  125. package/dist/stream.d.ts.map +1 -0
  126. package/dist/stream.js +476 -0
  127. package/dist/stream.js.map +1 -0
  128. package/dist/text.d.ts +337 -0
  129. package/dist/text.d.ts.map +1 -0
  130. package/dist/text.js +454 -0
  131. package/dist/text.js.map +1 -0
  132. package/dist/typed-arrays.d.ts +127 -0
  133. package/dist/typed-arrays.d.ts.map +1 -0
  134. package/dist/typed-arrays.js +410 -0
  135. package/dist/typed-arrays.js.map +1 -0
  136. package/dist/types.d.ts +358 -0
  137. package/dist/types.d.ts.map +1 -0
  138. package/dist/types.js +216 -0
  139. package/dist/types.js.map +1 -0
  140. package/native/annot.cc +557 -0
  141. package/native/buffer.cc +204 -0
  142. package/native/colorspace.cc +166 -0
  143. package/native/context.cc +84 -0
  144. package/native/cookie.cc +179 -0
  145. package/native/device.cc +179 -0
  146. package/native/display_list.cc +179 -0
  147. package/native/document.cc +268 -0
  148. package/native/enhanced.cc +70 -0
  149. package/native/font.cc +282 -0
  150. package/native/form.cc +523 -0
  151. package/native/geometry.cc +255 -0
  152. package/native/image.cc +216 -0
  153. package/native/include/micropdf/enhanced.h +38 -0
  154. package/native/include/micropdf/types.h +36 -0
  155. package/native/include/micropdf.h +106 -0
  156. package/native/include/mupdf-ffi.h +39 -0
  157. package/native/include/mupdf.h +11 -0
  158. package/native/include/mupdf_minimal.h +381 -0
  159. package/native/lib/linux-x64/libmicropdf.a +0 -0
  160. package/native/link.cc +234 -0
  161. package/native/micropdf.cc +71 -0
  162. package/native/output.cc +229 -0
  163. package/native/page.cc +572 -0
  164. package/native/path.cc +259 -0
  165. package/native/pixmap.cc +240 -0
  166. package/native/stext.cc +610 -0
  167. package/native/stream.cc +239 -0
  168. package/package.json +120 -0
  169. package/scripts/build-from-rust.js +97 -0
  170. package/scripts/install.js +184 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Minimal MuPDF C Header
3
+ *
4
+ * Clean C-compatible declarations for only the functions we need.
5
+ * This bypasses the auto-generated headers that contain Rust syntax.
6
+ */
7
+
8
+ #ifndef MUPDF_MINIMAL_H
9
+ #define MUPDF_MINIMAL_H
10
+
11
+ #include "micropdf/types.h"
12
+
13
+ #ifdef __cplusplus
14
+ extern "C" {
15
+ #endif
16
+
17
+ // ============================================================================
18
+ // Geometry Types
19
+ // ============================================================================
20
+
21
+ typedef struct {
22
+ float x, y;
23
+ } fz_point;
24
+
25
+ typedef struct {
26
+ float x0, y0, x1, y1;
27
+ } fz_rect;
28
+
29
+ typedef struct {
30
+ int x0, y0, x1, y1;
31
+ } fz_irect;
32
+
33
+ typedef struct {
34
+ float a, b, c, d, e, f;
35
+ } fz_matrix;
36
+
37
+ typedef struct {
38
+ fz_point ul, ur, ll, lr;
39
+ } fz_quad;
40
+
41
+ // ============================================================================
42
+ // Opaque Handle Types (all represented as int32_t in FFI)
43
+ // ============================================================================
44
+
45
+ typedef int32_t fz_context;
46
+ typedef int32_t fz_document;
47
+ typedef int32_t fz_page;
48
+ // fz_pixmap is defined later with specific functions
49
+ typedef int32_t fz_buffer;
50
+ typedef int32_t fz_stext_page;
51
+ typedef int32_t fz_link;
52
+ typedef int32_t fz_archive;
53
+
54
+ // Forward declarations for types defined later with specific functions
55
+ typedef uint64_t fz_colorspace;
56
+ typedef uint64_t fz_device;
57
+ typedef uint64_t fz_font;
58
+ typedef uint64_t fz_stream;
59
+ typedef uint64_t fz_output;
60
+
61
+ // ============================================================================
62
+ // Context Functions
63
+ // ============================================================================
64
+
65
+ #define FZ_STORE_DEFAULT 256 * 1024 * 1024 // 256 MB
66
+
67
+ fz_context fz_new_context(const void* alloc, const void* locks, size_t max_store);
68
+ void fz_drop_context(fz_context ctx);
69
+ fz_context fz_clone_context(fz_context ctx);
70
+
71
+ // ============================================================================
72
+ // Document Functions
73
+ // ============================================================================
74
+
75
+ fz_document fz_open_document(fz_context ctx, const char* filename);
76
+ fz_document fz_open_document_with_buffer(fz_context ctx, const char* magic, const unsigned char* data, size_t len);
77
+ void fz_drop_document(fz_context ctx, fz_document doc);
78
+ int fz_count_pages(fz_context ctx, fz_document doc);
79
+ int fz_needs_password(fz_context ctx, fz_document doc);
80
+ int fz_authenticate_password(fz_context ctx, fz_document doc, const char* password);
81
+ int fz_has_permission(fz_context ctx, fz_document doc, int permission);
82
+ int fz_lookup_metadata(fz_context ctx, fz_document doc, const char* key, char* buf, int size);
83
+
84
+ // PDF-specific document functions
85
+ void pdf_save_document(fz_context ctx, fz_document doc, const char* filename, const void* opts);
86
+ int pdf_lookup_named_dest(fz_context ctx, fz_document doc, const char* name);
87
+
88
+ // ============================================================================
89
+ // Page Functions
90
+ // ============================================================================
91
+
92
+ fz_page fz_load_page(fz_context ctx, fz_document doc, int number);
93
+ void fz_drop_page(fz_context ctx, fz_page page);
94
+ fz_rect fz_bound_page(fz_context ctx, fz_page page);
95
+
96
+ // ============================================================================
97
+ // Matrix Functions
98
+ // ============================================================================
99
+
100
+ fz_matrix fz_identity();
101
+ fz_matrix fz_scale(float sx, float sy);
102
+ fz_matrix fz_translate(float tx, float ty);
103
+ fz_matrix fz_rotate(float degrees);
104
+ fz_matrix fz_concat(fz_matrix a, fz_matrix b);
105
+
106
+ // ============================================================================
107
+ // Buffer Functions
108
+ // ============================================================================
109
+
110
+ // fz_new_buffer_from_pixmap_as_png is declared after fz_pixmap typedef
111
+ void fz_drop_buffer(fz_context ctx, fz_buffer buf);
112
+ size_t fz_buffer_storage(fz_context ctx, fz_buffer buf, const unsigned char** data);
113
+ const unsigned char* fz_buffer_data(fz_context ctx, fz_buffer buf, size_t* len);
114
+
115
+ // ============================================================================
116
+ // Text Extraction Functions
117
+ // ============================================================================
118
+
119
+ fz_stext_page fz_new_stext_page_from_page(fz_context ctx, fz_page page, const void* options);
120
+ void fz_drop_stext_page(fz_context ctx, fz_stext_page stext);
121
+ fz_buffer fz_new_buffer_from_stext_page(fz_context ctx, fz_stext_page stext);
122
+ fz_rect fz_bound_stext_page(fz_context ctx, fz_stext_page stext);
123
+
124
+ // ============================================================================
125
+ // Search Functions
126
+ // ============================================================================
127
+
128
+ int fz_search_stext_page(fz_context ctx, fz_stext_page stext, const char* needle, int* mark, fz_quad* hit_bbox, int hit_max);
129
+
130
+ // ============================================================================
131
+ // Archive Functions
132
+ // ============================================================================
133
+
134
+ fz_archive fz_open_archive(fz_context ctx, const char* path);
135
+ fz_archive fz_open_archive_with_buffer(fz_context ctx, fz_buffer buffer);
136
+ void fz_drop_archive(fz_context ctx, fz_archive arch);
137
+
138
+ // ============================================================================
139
+ // Annotation Functions
140
+ // ============================================================================
141
+
142
+ typedef int32_t pdf_annot;
143
+
144
+ pdf_annot pdf_create_annot(fz_context ctx, fz_page page, int type);
145
+ void pdf_delete_annot(fz_context ctx, fz_page page, pdf_annot annot);
146
+ void pdf_drop_annot(fz_context ctx, pdf_annot annot);
147
+
148
+ int pdf_annot_type(fz_context ctx, pdf_annot annot);
149
+ fz_rect pdf_annot_rect(fz_context ctx, pdf_annot annot);
150
+ void pdf_set_annot_rect(fz_context ctx, pdf_annot annot, fz_rect rect);
151
+
152
+ unsigned int pdf_annot_flags(fz_context ctx, pdf_annot annot);
153
+ void pdf_set_annot_flags(fz_context ctx, pdf_annot annot, unsigned int flags);
154
+
155
+ void pdf_annot_contents(fz_context ctx, pdf_annot annot, char* buf, int size);
156
+ void pdf_set_annot_contents(fz_context ctx, pdf_annot annot, const char* text);
157
+
158
+ void pdf_annot_author(fz_context ctx, pdf_annot annot, char* buf, int size);
159
+ void pdf_set_annot_author(fz_context ctx, pdf_annot annot, const char* author);
160
+
161
+ float pdf_annot_opacity(fz_context ctx, pdf_annot annot);
162
+ void pdf_set_annot_opacity(fz_context ctx, pdf_annot annot, float opacity);
163
+
164
+ int pdf_annot_has_dirty(fz_context ctx, pdf_annot annot);
165
+ void pdf_annot_clear_dirty(fz_context ctx, pdf_annot annot);
166
+ int pdf_update_annot(fz_context ctx, pdf_annot annot);
167
+
168
+ pdf_annot pdf_clone_annot(fz_context ctx, pdf_annot annot);
169
+ int pdf_annot_is_valid(fz_context ctx, pdf_annot annot);
170
+
171
+ // ============================================================================
172
+ // Display List Functions
173
+ // ============================================================================
174
+
175
+ typedef uint64_t fz_display_list_handle;
176
+
177
+ fz_display_list_handle fz_new_display_list(fz_context ctx, fz_rect rect);
178
+ void fz_drop_display_list(fz_context ctx, fz_display_list_handle list);
179
+ fz_rect fz_bound_display_list(fz_context ctx, fz_display_list_handle list);
180
+ void fz_run_display_list(fz_context ctx, fz_display_list_handle list, fz_device device, fz_matrix matrix, fz_rect rect);
181
+ fz_display_list_handle fz_new_display_list_from_page(fz_context ctx, fz_page page);
182
+
183
+ // ============================================================================
184
+ // Colorspace Functions
185
+ // ============================================================================
186
+
187
+ typedef uint64_t fz_colorspace_handle;
188
+
189
+ uint64_t fz_device_gray(fz_context ctx);
190
+ uint64_t fz_device_rgb(fz_context ctx);
191
+ uint64_t fz_device_bgr(fz_context ctx);
192
+ uint64_t fz_device_cmyk(fz_context ctx);
193
+ int fz_colorspace_n(fz_context ctx, fz_colorspace_handle cs);
194
+ const char* fz_colorspace_name(fz_context ctx, fz_colorspace_handle cs);
195
+
196
+ // ============================================================================
197
+ // Font Functions
198
+ // ============================================================================
199
+
200
+ typedef uint64_t fz_font;
201
+
202
+ fz_font fz_new_font(fz_context ctx, const char* name, int is_bold, int is_italic, uint64_t font_file);
203
+ fz_font fz_new_font_from_file(fz_context ctx, const char* name, const char* path, int index, int use_glyph_bbox);
204
+ fz_font fz_new_font_from_memory(fz_context ctx, const char* name, const unsigned char* data, int len, int index, int use_glyph_bbox);
205
+ void fz_drop_font(fz_context ctx, fz_font font);
206
+ void fz_font_name(fz_context ctx, fz_font font, char* buf, int size);
207
+ int fz_font_is_bold(fz_context ctx, fz_font font);
208
+ int fz_font_is_italic(fz_context ctx, fz_font font);
209
+ int fz_encode_character(fz_context ctx, fz_font font, int unicode);
210
+ float fz_advance_glyph(fz_context ctx, fz_font font, int glyph, int wmode);
211
+
212
+ // ============================================================================
213
+ // Stream Functions
214
+ // ============================================================================
215
+
216
+ fz_stream fz_open_file(fz_context ctx, const char* filename);
217
+ fz_stream fz_open_memory(fz_context ctx, const unsigned char* data, size_t len);
218
+ void fz_drop_stream(fz_context ctx, fz_stream stm);
219
+ size_t fz_read(fz_context ctx, fz_stream stm, unsigned char* data, size_t len);
220
+ int fz_read_byte(fz_context ctx, fz_stream stm);
221
+ int fz_is_eof(fz_context ctx, fz_stream stm);
222
+ void fz_seek(fz_context ctx, fz_stream stm, int64_t offset, int whence);
223
+ int64_t fz_tell(fz_context ctx, fz_stream stm);
224
+
225
+ // ============================================================================
226
+ // Output Functions
227
+ // ============================================================================
228
+
229
+ fz_output fz_new_output_with_path(fz_context ctx, const char* filename, int append);
230
+ fz_output fz_new_output_with_buffer(fz_context ctx, uint64_t buf);
231
+ void fz_drop_output(fz_context ctx, fz_output out);
232
+ void fz_write_data(fz_context ctx, fz_output out, const void* data, size_t size);
233
+ void fz_write_string(fz_context ctx, fz_output out, const char* s);
234
+ void fz_write_byte(fz_context ctx, fz_output out, unsigned char byte);
235
+ void fz_close_output(fz_context ctx, fz_output out);
236
+ int64_t fz_tell_output(fz_context ctx, fz_output out);
237
+
238
+ // ============================================================================
239
+ // Image Functions
240
+ // ============================================================================
241
+
242
+ typedef uint64_t fz_image;
243
+
244
+ fz_image fz_new_image_from_file(fz_context ctx, const char* filename);
245
+ fz_image fz_new_image_from_buffer_data(fz_context ctx, const uint8_t* data, size_t len);
246
+ void fz_drop_image(fz_context ctx, fz_image image);
247
+ int fz_image_width(fz_context ctx, fz_image image);
248
+ int fz_image_height(fz_context ctx, fz_image image);
249
+ uint64_t fz_image_colorspace(fz_context ctx, fz_image image);
250
+ // fz_get_pixmap_from_image is declared after fz_pixmap typedef
251
+
252
+ // ============================================================================
253
+ // Pixmap Functions
254
+ // ============================================================================
255
+
256
+ typedef uint64_t fz_pixmap;
257
+
258
+ // Legacy page-to-pixmap function (compatibility)
259
+ fz_pixmap fz_new_pixmap_from_page(fz_context ctx, fz_page page, fz_matrix ctm, fz_colorspace cs, int alpha);
260
+
261
+ // Core pixmap functions
262
+ fz_pixmap fz_new_pixmap(fz_context ctx, uint64_t colorspace, int w, int h, int alpha);
263
+ void fz_drop_pixmap(fz_context ctx, fz_pixmap pixmap);
264
+ int fz_pixmap_width(fz_context ctx, fz_pixmap pixmap);
265
+ int fz_pixmap_height(fz_context ctx, fz_pixmap pixmap);
266
+ void fz_pixmap_samples(fz_context ctx, fz_pixmap pixmap, uint8_t** data, size_t* size);
267
+ unsigned char* fz_pixmap_samples_old(fz_context ctx, fz_pixmap pix);
268
+ size_t fz_pixmap_stride(fz_context ctx, fz_pixmap pixmap);
269
+ int fz_pixmap_components(fz_context ctx, fz_pixmap pixmap);
270
+ void fz_clear_pixmap(fz_context ctx, fz_pixmap pixmap, int value);
271
+
272
+ // Pixmap-to-buffer conversion
273
+ fz_buffer fz_new_buffer_from_pixmap_as_png(fz_context ctx, fz_pixmap pix, int color_params);
274
+
275
+ // Image-to-pixmap conversion (needs fz_image and fz_pixmap defined)
276
+ fz_pixmap fz_get_pixmap_from_image(fz_context ctx, fz_image image, const fz_irect* subarea, fz_matrix* ctm, int* w, int* h);
277
+
278
+ // ============================================================================
279
+ // Path Functions
280
+ // ============================================================================
281
+
282
+ typedef uint64_t fz_path_handle;
283
+ typedef uint64_t fz_stroke_handle;
284
+
285
+ fz_path_handle fz_new_path(fz_context ctx);
286
+ void fz_drop_path(fz_context ctx, fz_path_handle path);
287
+ void fz_moveto(fz_context ctx, fz_path_handle path, float x, float y);
288
+ void fz_lineto(fz_context ctx, fz_path_handle path, float x, float y);
289
+ void fz_curveto(fz_context ctx, fz_path_handle path, float x1, float y1, float x2, float y2, float x3, float y3);
290
+ void fz_closepath(fz_context ctx, fz_path_handle path);
291
+ void fz_rectto(fz_context ctx, fz_path_handle path, float x, float y, float w, float h);
292
+ fz_rect fz_bound_path(fz_context ctx, fz_path_handle path, fz_stroke_handle stroke);
293
+
294
+ // ============================================================================
295
+ // Device Functions
296
+ // ============================================================================
297
+
298
+ typedef uint64_t fz_device_handle;
299
+
300
+ fz_device_handle fz_new_draw_device(fz_context ctx, fz_pixmap pixmap);
301
+ fz_device_handle fz_new_list_device(fz_context ctx, fz_display_list_handle list);
302
+ void fz_drop_device(fz_context ctx, fz_device_handle device);
303
+ void fz_close_device(fz_context ctx, fz_device_handle device);
304
+ void fz_begin_page(fz_context ctx, fz_device_handle device, fz_rect rect);
305
+ void fz_end_page(fz_context ctx, fz_device_handle device);
306
+
307
+ // ============================================================================
308
+ // Cookie Functions
309
+ // ============================================================================
310
+
311
+ typedef uint64_t fz_cookie_handle;
312
+
313
+ fz_cookie_handle fz_new_cookie(fz_context ctx);
314
+ void fz_drop_cookie(fz_context ctx, fz_cookie_handle cookie);
315
+ void fz_abort_cookie(fz_context ctx, fz_cookie_handle cookie);
316
+ void fz_cookie_progress(fz_context ctx, fz_cookie_handle cookie, int* progress, int* progress_max, int* errors);
317
+ int fz_cookie_is_aborted(fz_context ctx, fz_cookie_handle cookie);
318
+ void fz_reset_cookie(fz_context ctx, fz_cookie_handle cookie);
319
+
320
+ // ============================================================================
321
+ // Link Functions
322
+ // ============================================================================
323
+
324
+ typedef uint64_t fz_link_handle;
325
+
326
+ fz_link_handle fz_load_links(fz_context ctx, fz_page page);
327
+ fz_link_handle fz_next_link(fz_context ctx, fz_link_handle link);
328
+ void fz_drop_link(fz_context ctx, fz_link_handle link);
329
+ fz_rect fz_link_rect(fz_context ctx, fz_link_handle link);
330
+ void fz_link_uri(fz_context ctx, fz_link_handle link, char* buf, int size);
331
+ int fz_link_is_external(fz_context ctx, fz_link_handle link);
332
+ int fz_resolve_link_page(fz_context ctx, fz_document doc, fz_link_handle link);
333
+ int fz_link_is_valid(fz_context ctx, fz_link_handle link);
334
+
335
+ // ============================================================================
336
+ // Form Widget Functions
337
+ // ============================================================================
338
+
339
+ typedef uint64_t pdf_widget;
340
+
341
+ // Widget navigation
342
+ pdf_widget pdf_first_widget(fz_context ctx, fz_page page);
343
+ pdf_widget pdf_next_widget(fz_context ctx, pdf_widget widget);
344
+ void pdf_drop_widget(fz_context ctx, pdf_widget widget);
345
+
346
+ // Widget properties
347
+ int pdf_widget_type(fz_context ctx, pdf_widget widget);
348
+ void pdf_widget_name(fz_context ctx, pdf_widget widget, char* buf, int size);
349
+ fz_rect pdf_widget_rect(fz_context ctx, pdf_widget widget);
350
+
351
+ // Widget values
352
+ void pdf_widget_value(fz_context ctx, pdf_widget widget, char* buf, int size);
353
+ int pdf_set_widget_value(fz_context ctx, pdf_widget widget, const char* value);
354
+
355
+ // Widget state
356
+ int pdf_widget_is_readonly(fz_context ctx, pdf_widget widget);
357
+ int pdf_widget_is_required(fz_context ctx, pdf_widget widget);
358
+ int pdf_widget_is_valid(fz_context ctx, pdf_widget widget);
359
+
360
+ // Text field specific
361
+ int pdf_widget_text_format(fz_context ctx, pdf_widget widget);
362
+ int pdf_widget_max_len(fz_context ctx, pdf_widget widget);
363
+ int pdf_widget_is_multiline(fz_context ctx, pdf_widget widget);
364
+
365
+ // Checkbox/radio specific
366
+ int pdf_widget_is_checked(fz_context ctx, pdf_widget widget);
367
+ void pdf_set_widget_checked(fz_context ctx, pdf_widget widget, int checked);
368
+
369
+ // Choice field specific
370
+ int pdf_widget_option_count(fz_context ctx, pdf_widget widget);
371
+ void pdf_widget_option(fz_context ctx, pdf_widget widget, int index, char* buf, int size);
372
+
373
+ // Widget updates
374
+ int pdf_update_widget(fz_context ctx, pdf_widget widget);
375
+
376
+ #ifdef __cplusplus
377
+ }
378
+ #endif
379
+
380
+ #endif /* MUPDF_MINIMAL_H */
381
+
package/native/link.cc ADDED
@@ -0,0 +1,234 @@
1
+ /**
2
+ * MicroPDF Link Bindings
3
+ *
4
+ * N-API bindings for PDF link/hyperlink operations.
5
+ * Links provide navigation within and between PDF documents.
6
+ */
7
+
8
+ #include <napi.h>
9
+ #include "include/mupdf_minimal.h"
10
+
11
+ /**
12
+ * Get first link on page
13
+ *
14
+ * @param ctx - Context handle
15
+ * @param page - Page handle
16
+ * @returns Link handle (or 0 if none)
17
+ */
18
+ Napi::BigInt LoadPageLinks(const Napi::CallbackInfo& info) {
19
+ Napi::Env env = info.Env();
20
+
21
+ if (info.Length() < 2) {
22
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, page")
23
+ .ThrowAsJavaScriptException();
24
+ return Napi::BigInt::New(env, static_cast<uint64_t>(0));
25
+ }
26
+
27
+ bool lossless;
28
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
29
+ uint64_t page_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
30
+
31
+ uint64_t link_handle = fz_load_links(ctx_handle, page_handle);
32
+
33
+ return Napi::BigInt::New(env, link_handle);
34
+ }
35
+
36
+ /**
37
+ * Get next link in list
38
+ *
39
+ * @param ctx - Context handle
40
+ * @param link - Current link handle
41
+ * @returns Next link handle (or 0 if none)
42
+ */
43
+ Napi::BigInt GetNextLink(const Napi::CallbackInfo& info) {
44
+ Napi::Env env = info.Env();
45
+
46
+ if (info.Length() < 2) {
47
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
48
+ .ThrowAsJavaScriptException();
49
+ return Napi::BigInt::New(env, static_cast<uint64_t>(0));
50
+ }
51
+
52
+ bool lossless;
53
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
54
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
55
+
56
+ uint64_t next_handle = fz_next_link(ctx_handle, link_handle);
57
+
58
+ return Napi::BigInt::New(env, next_handle);
59
+ }
60
+
61
+ /**
62
+ * Drop link handle
63
+ *
64
+ * @param ctx - Context handle
65
+ * @param link - Link handle
66
+ */
67
+ Napi::Value DropLink(const Napi::CallbackInfo& info) {
68
+ Napi::Env env = info.Env();
69
+
70
+ if (info.Length() < 2) {
71
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
72
+ .ThrowAsJavaScriptException();
73
+ return env.Undefined();
74
+ }
75
+
76
+ bool lossless;
77
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
78
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
79
+
80
+ fz_drop_link(ctx_handle, link_handle);
81
+
82
+ return env.Undefined();
83
+ }
84
+
85
+ /**
86
+ * Get link rectangle
87
+ *
88
+ * @param ctx - Context handle
89
+ * @param link - Link handle
90
+ * @returns Rectangle {x0, y0, x1, y1}
91
+ */
92
+ Napi::Object GetLinkRect(const Napi::CallbackInfo& info) {
93
+ Napi::Env env = info.Env();
94
+ Napi::Object rect = Napi::Object::New(env);
95
+
96
+ if (info.Length() < 2) {
97
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
98
+ .ThrowAsJavaScriptException();
99
+ return rect;
100
+ }
101
+
102
+ bool lossless;
103
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
104
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
105
+
106
+ fz_rect link_rect = fz_link_rect(ctx_handle, link_handle);
107
+
108
+ rect.Set("x0", Napi::Number::New(env, link_rect.x0));
109
+ rect.Set("y0", Napi::Number::New(env, link_rect.y0));
110
+ rect.Set("x1", Napi::Number::New(env, link_rect.x1));
111
+ rect.Set("y1", Napi::Number::New(env, link_rect.y1));
112
+
113
+ return rect;
114
+ }
115
+
116
+ /**
117
+ * Get link URI
118
+ *
119
+ * @param ctx - Context handle
120
+ * @param link - Link handle
121
+ * @returns URI string (or empty if internal)
122
+ */
123
+ Napi::String GetLinkURI(const Napi::CallbackInfo& info) {
124
+ Napi::Env env = info.Env();
125
+
126
+ if (info.Length() < 2) {
127
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
128
+ .ThrowAsJavaScriptException();
129
+ return Napi::String::New(env, "");
130
+ }
131
+
132
+ bool lossless;
133
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
134
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
135
+
136
+ char buffer[2048];
137
+ fz_link_uri(ctx_handle, link_handle, buffer, sizeof(buffer));
138
+
139
+ return Napi::String::New(env, buffer);
140
+ }
141
+
142
+ /**
143
+ * Check if link is external
144
+ *
145
+ * @param ctx - Context handle
146
+ * @param link - Link handle
147
+ * @returns Boolean
148
+ */
149
+ Napi::Boolean IsLinkExternal(const Napi::CallbackInfo& info) {
150
+ Napi::Env env = info.Env();
151
+
152
+ if (info.Length() < 2) {
153
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
154
+ .ThrowAsJavaScriptException();
155
+ return Napi::Boolean::New(env, false);
156
+ }
157
+
158
+ bool lossless;
159
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
160
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
161
+
162
+ int32_t is_external = fz_link_is_external(ctx_handle, link_handle);
163
+
164
+ return Napi::Boolean::New(env, is_external != 0);
165
+ }
166
+
167
+ /**
168
+ * Resolve link destination page
169
+ *
170
+ * @param ctx - Context handle
171
+ * @param doc - Document handle
172
+ * @param link - Link handle
173
+ * @returns Page number (-1 if external)
174
+ */
175
+ Napi::Number ResolveLinkPage(const Napi::CallbackInfo& info) {
176
+ Napi::Env env = info.Env();
177
+
178
+ if (info.Length() < 3) {
179
+ Napi::TypeError::New(env, "Expected 3 arguments: ctx, doc, link")
180
+ .ThrowAsJavaScriptException();
181
+ return Napi::Number::New(env, -1);
182
+ }
183
+
184
+ bool lossless;
185
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
186
+ uint64_t doc_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
187
+ uint64_t link_handle = info[2].As<Napi::BigInt>().Uint64Value(&lossless);
188
+
189
+ int32_t page_num = fz_resolve_link_page(ctx_handle, doc_handle, link_handle);
190
+
191
+ return Napi::Number::New(env, page_num);
192
+ }
193
+
194
+ /**
195
+ * Check if link is valid
196
+ *
197
+ * @param ctx - Context handle
198
+ * @param link - Link handle
199
+ * @returns Boolean
200
+ */
201
+ Napi::Boolean IsLinkValid(const Napi::CallbackInfo& info) {
202
+ Napi::Env env = info.Env();
203
+
204
+ if (info.Length() < 2) {
205
+ Napi::TypeError::New(env, "Expected 2 arguments: ctx, link")
206
+ .ThrowAsJavaScriptException();
207
+ return Napi::Boolean::New(env, false);
208
+ }
209
+
210
+ bool lossless;
211
+ uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
212
+ uint64_t link_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
213
+
214
+ int32_t is_valid = fz_link_is_valid(ctx_handle, link_handle);
215
+
216
+ return Napi::Boolean::New(env, is_valid != 0);
217
+ }
218
+
219
+ /**
220
+ * Initialize Link module exports
221
+ */
222
+ Napi::Object InitLink(Napi::Env env, Napi::Object exports) {
223
+ exports.Set("loadPageLinks", Napi::Function::New(env, LoadPageLinks));
224
+ exports.Set("getNextLink", Napi::Function::New(env, GetNextLink));
225
+ exports.Set("dropLink", Napi::Function::New(env, DropLink));
226
+ exports.Set("getLinkRect", Napi::Function::New(env, GetLinkRect));
227
+ exports.Set("getLinkURI", Napi::Function::New(env, GetLinkURI));
228
+ exports.Set("isLinkExternal", Napi::Function::New(env, IsLinkExternal));
229
+ exports.Set("resolveLinkPage", Napi::Function::New(env, ResolveLinkPage));
230
+ exports.Set("isLinkValid", Napi::Function::New(env, IsLinkValid));
231
+
232
+ return exports;
233
+ }
234
+
@@ -0,0 +1,71 @@
1
+ /**
2
+ * MicroPDF Node.js Native Addon
3
+ *
4
+ * Main entry point for the native addon that binds the MicroPDF Rust library
5
+ * to Node.js via N-API.
6
+ */
7
+
8
+ #include <napi.h>
9
+ #include "include/mupdf_minimal.h"
10
+
11
+ // Forward declarations from other source files
12
+ Napi::Object InitContext(Napi::Env env, Napi::Object exports);
13
+ Napi::Object InitDocument(Napi::Env env, Napi::Object exports);
14
+ Napi::Object InitPage(Napi::Env env, Napi::Object exports);
15
+ Napi::Object InitSText(Napi::Env env, Napi::Object exports);
16
+ Napi::Object InitAnnotation(Napi::Env env, Napi::Object exports);
17
+ Napi::Object InitForm(Napi::Env env, Napi::Object exports);
18
+ Napi::Object InitDisplayList(Napi::Env env, Napi::Object exports);
19
+ Napi::Object InitLink(Napi::Env env, Napi::Object exports);
20
+ Napi::Object InitCookie(Napi::Env env, Napi::Object exports);
21
+ Napi::Object InitDevice(Napi::Env env, Napi::Object exports);
22
+ Napi::Object InitPath(Napi::Env env, Napi::Object exports);
23
+ Napi::Object InitPixmap(Napi::Env env, Napi::Object exports);
24
+ Napi::Object InitImage(Napi::Env env, Napi::Object exports);
25
+ Napi::Object InitColorspace(Napi::Env env, Napi::Object exports);
26
+ Napi::Object InitFont(Napi::Env env, Napi::Object exports);
27
+ Napi::Object InitStream(Napi::Env env, Napi::Object exports);
28
+ Napi::Object InitOutput(Napi::Env env, Napi::Object exports);
29
+ Napi::Object InitEnhanced(Napi::Env env, Napi::Object exports);
30
+
31
+ /**
32
+ * Get the MicroPDF library version
33
+ */
34
+ Napi::String GetVersion(const Napi::CallbackInfo& info) {
35
+ Napi::Env env = info.Env();
36
+ // Return version from package.json
37
+ return Napi::String::New(env, "0.1.0");
38
+ }
39
+
40
+ /**
41
+ * Initialize the native addon
42
+ */
43
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
44
+ // Add version function
45
+ exports.Set("getVersion", Napi::Function::New(env, GetVersion));
46
+
47
+ // Initialize sub-modules
48
+ InitContext(env, exports);
49
+ InitDocument(env, exports);
50
+ InitPage(env, exports);
51
+ InitSText(env, exports);
52
+ InitAnnotation(env, exports);
53
+ InitForm(env, exports);
54
+ InitDisplayList(env, exports);
55
+ InitLink(env, exports);
56
+ InitCookie(env, exports);
57
+ InitDevice(env, exports);
58
+ InitPath(env, exports);
59
+ InitPixmap(env, exports);
60
+ InitImage(env, exports);
61
+ InitColorspace(env, exports);
62
+ InitFont(env, exports);
63
+ InitStream(env, exports);
64
+ InitOutput(env, exports);
65
+ InitEnhanced(env, exports);
66
+
67
+ return exports;
68
+ }
69
+
70
+ NODE_API_MODULE(micropdf, Init)
71
+