@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.
- package/LICENSE +191 -0
- package/README.md +985 -0
- package/binding.gyp +73 -0
- package/dist/annot.d.ts +458 -0
- package/dist/annot.d.ts.map +1 -0
- package/dist/annot.js +697 -0
- package/dist/annot.js.map +1 -0
- package/dist/archive.d.ts +128 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +268 -0
- package/dist/archive.js.map +1 -0
- package/dist/buffer.d.ts +572 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +971 -0
- package/dist/buffer.js.map +1 -0
- package/dist/colorspace.d.ts +287 -0
- package/dist/colorspace.d.ts.map +1 -0
- package/dist/colorspace.js +542 -0
- package/dist/colorspace.js.map +1 -0
- package/dist/context.d.ts +184 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +320 -0
- package/dist/context.js.map +1 -0
- package/dist/cookie.d.ts +164 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +306 -0
- package/dist/cookie.js.map +1 -0
- package/dist/device.d.ts +169 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +350 -0
- package/dist/device.js.map +1 -0
- package/dist/display-list.d.ts +202 -0
- package/dist/display-list.d.ts.map +1 -0
- package/dist/display-list.js +410 -0
- package/dist/display-list.js.map +1 -0
- package/dist/document.d.ts +637 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +902 -0
- package/dist/document.js.map +1 -0
- package/dist/easy.d.ts +423 -0
- package/dist/easy.d.ts.map +1 -0
- package/dist/easy.js +644 -0
- package/dist/easy.js.map +1 -0
- package/dist/enhanced.d.ts +226 -0
- package/dist/enhanced.d.ts.map +1 -0
- package/dist/enhanced.js +368 -0
- package/dist/enhanced.js.map +1 -0
- package/dist/filter.d.ts +51 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +381 -0
- package/dist/filter.js.map +1 -0
- package/dist/font.d.ts +222 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +381 -0
- package/dist/font.js.map +1 -0
- package/dist/form.d.ts +214 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +497 -0
- package/dist/form.js.map +1 -0
- package/dist/geometry.d.ts +469 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +780 -0
- package/dist/geometry.js.map +1 -0
- package/dist/image.d.ts +172 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +348 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +339 -0
- package/dist/index.js.map +1 -0
- package/dist/link.d.ts +168 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +343 -0
- package/dist/link.js.map +1 -0
- package/dist/micropdf.d.ts +40 -0
- package/dist/micropdf.d.ts.map +1 -0
- package/dist/micropdf.js +45 -0
- package/dist/micropdf.js.map +1 -0
- package/dist/nanopdf.d.ts +40 -0
- package/dist/nanopdf.d.ts.map +1 -0
- package/dist/nanopdf.js +45 -0
- package/dist/nanopdf.js.map +1 -0
- package/dist/native.d.ts +242 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +509 -0
- package/dist/native.js.map +1 -0
- package/dist/output.d.ts +166 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +365 -0
- package/dist/output.js.map +1 -0
- package/dist/path.d.ts +420 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +687 -0
- package/dist/path.js.map +1 -0
- package/dist/pdf/object.d.ts +489 -0
- package/dist/pdf/object.d.ts.map +1 -0
- package/dist/pdf/object.js +1045 -0
- package/dist/pdf/object.js.map +1 -0
- package/dist/pixmap.d.ts +315 -0
- package/dist/pixmap.d.ts.map +1 -0
- package/dist/pixmap.js +590 -0
- package/dist/pixmap.js.map +1 -0
- package/dist/profiler.d.ts +159 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +380 -0
- package/dist/profiler.js.map +1 -0
- package/dist/render-options.d.ts +227 -0
- package/dist/render-options.d.ts.map +1 -0
- package/dist/render-options.js +130 -0
- package/dist/render-options.js.map +1 -0
- package/dist/resource-tracking.d.ts +332 -0
- package/dist/resource-tracking.d.ts.map +1 -0
- package/dist/resource-tracking.js +653 -0
- package/dist/resource-tracking.js.map +1 -0
- package/dist/simple.d.ts +276 -0
- package/dist/simple.d.ts.map +1 -0
- package/dist/simple.js +343 -0
- package/dist/simple.js.map +1 -0
- package/dist/stext.d.ts +290 -0
- package/dist/stext.d.ts.map +1 -0
- package/dist/stext.js +312 -0
- package/dist/stext.js.map +1 -0
- package/dist/stream.d.ts +174 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +476 -0
- package/dist/stream.js.map +1 -0
- package/dist/text.d.ts +337 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +454 -0
- package/dist/text.js.map +1 -0
- package/dist/typed-arrays.d.ts +127 -0
- package/dist/typed-arrays.d.ts.map +1 -0
- package/dist/typed-arrays.js +410 -0
- package/dist/typed-arrays.js.map +1 -0
- package/dist/types.d.ts +358 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +216 -0
- package/dist/types.js.map +1 -0
- package/native/annot.cc +557 -0
- package/native/buffer.cc +204 -0
- package/native/colorspace.cc +166 -0
- package/native/context.cc +84 -0
- package/native/cookie.cc +179 -0
- package/native/device.cc +179 -0
- package/native/display_list.cc +179 -0
- package/native/document.cc +268 -0
- package/native/enhanced.cc +70 -0
- package/native/font.cc +282 -0
- package/native/form.cc +523 -0
- package/native/geometry.cc +255 -0
- package/native/image.cc +216 -0
- package/native/include/micropdf/enhanced.h +38 -0
- package/native/include/micropdf/types.h +36 -0
- package/native/include/micropdf.h +106 -0
- package/native/include/mupdf-ffi.h +39 -0
- package/native/include/mupdf.h +11 -0
- package/native/include/mupdf_minimal.h +381 -0
- package/native/lib/linux-x64/libmicropdf.a +0 -0
- package/native/link.cc +234 -0
- package/native/micropdf.cc +71 -0
- package/native/output.cc +229 -0
- package/native/page.cc +572 -0
- package/native/path.cc +259 -0
- package/native/pixmap.cc +240 -0
- package/native/stext.cc +610 -0
- package/native/stream.cc +239 -0
- package/package.json +120 -0
- package/scripts/build-from-rust.js +97 -0
- package/scripts/install.js +184 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF Geometry Bindings
|
|
3
|
+
*
|
|
4
|
+
* Node.js bindings for MicroPDF geometry operations.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <napi.h>
|
|
8
|
+
#include "include/micropdf.h"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a Point object from micropdf_point_t
|
|
12
|
+
*/
|
|
13
|
+
Napi::Object PointToObject(Napi::Env env, micropdf_point_t p) {
|
|
14
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
15
|
+
obj.Set("x", Napi::Number::New(env, p.x));
|
|
16
|
+
obj.Set("y", Napi::Number::New(env, p.y));
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create micropdf_point_t from a JS object
|
|
22
|
+
*/
|
|
23
|
+
micropdf_point_t ObjectToPoint(Napi::Object obj) {
|
|
24
|
+
micropdf_point_t p;
|
|
25
|
+
p.x = obj.Get("x").As<Napi::Number>().FloatValue();
|
|
26
|
+
p.y = obj.Get("y").As<Napi::Number>().FloatValue();
|
|
27
|
+
return p;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a Rect object from micropdf_rect_t
|
|
32
|
+
*/
|
|
33
|
+
Napi::Object RectToObject(Napi::Env env, micropdf_rect_t r) {
|
|
34
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
35
|
+
obj.Set("x0", Napi::Number::New(env, r.x0));
|
|
36
|
+
obj.Set("y0", Napi::Number::New(env, r.y0));
|
|
37
|
+
obj.Set("x1", Napi::Number::New(env, r.x1));
|
|
38
|
+
obj.Set("y1", Napi::Number::New(env, r.y1));
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create micropdf_rect_t from a JS object
|
|
44
|
+
*/
|
|
45
|
+
micropdf_rect_t ObjectToRect(Napi::Object obj) {
|
|
46
|
+
micropdf_rect_t r;
|
|
47
|
+
r.x0 = obj.Get("x0").As<Napi::Number>().FloatValue();
|
|
48
|
+
r.y0 = obj.Get("y0").As<Napi::Number>().FloatValue();
|
|
49
|
+
r.x1 = obj.Get("x1").As<Napi::Number>().FloatValue();
|
|
50
|
+
r.y1 = obj.Get("y1").As<Napi::Number>().FloatValue();
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Create a Matrix object from micropdf_matrix_t
|
|
56
|
+
*/
|
|
57
|
+
Napi::Object MatrixToObject(Napi::Env env, micropdf_matrix_t m) {
|
|
58
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
59
|
+
obj.Set("a", Napi::Number::New(env, m.a));
|
|
60
|
+
obj.Set("b", Napi::Number::New(env, m.b));
|
|
61
|
+
obj.Set("c", Napi::Number::New(env, m.c));
|
|
62
|
+
obj.Set("d", Napi::Number::New(env, m.d));
|
|
63
|
+
obj.Set("e", Napi::Number::New(env, m.e));
|
|
64
|
+
obj.Set("f", Napi::Number::New(env, m.f));
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create micropdf_matrix_t from a JS object
|
|
70
|
+
*/
|
|
71
|
+
micropdf_matrix_t ObjectToMatrix(Napi::Object obj) {
|
|
72
|
+
micropdf_matrix_t m;
|
|
73
|
+
m.a = obj.Get("a").As<Napi::Number>().FloatValue();
|
|
74
|
+
m.b = obj.Get("b").As<Napi::Number>().FloatValue();
|
|
75
|
+
m.c = obj.Get("c").As<Napi::Number>().FloatValue();
|
|
76
|
+
m.d = obj.Get("d").As<Napi::Number>().FloatValue();
|
|
77
|
+
m.e = obj.Get("e").As<Napi::Number>().FloatValue();
|
|
78
|
+
m.f = obj.Get("f").As<Napi::Number>().FloatValue();
|
|
79
|
+
return m;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Point functions
|
|
83
|
+
Napi::Value CreatePoint(const Napi::CallbackInfo& info) {
|
|
84
|
+
Napi::Env env = info.Env();
|
|
85
|
+
|
|
86
|
+
float x = 0, y = 0;
|
|
87
|
+
if (info.Length() >= 2) {
|
|
88
|
+
x = info[0].As<Napi::Number>().FloatValue();
|
|
89
|
+
y = info[1].As<Napi::Number>().FloatValue();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
micropdf_point_t p = {x, y};
|
|
93
|
+
return PointToObject(env, p);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Napi::Value TransformPoint(const Napi::CallbackInfo& info) {
|
|
97
|
+
Napi::Env env = info.Env();
|
|
98
|
+
|
|
99
|
+
if (info.Length() < 2 || !info[0].IsObject() || !info[1].IsObject()) {
|
|
100
|
+
Napi::TypeError::New(env, "Expected (point, matrix)").ThrowAsJavaScriptException();
|
|
101
|
+
return env.Undefined();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
micropdf_point_t p = ObjectToPoint(info[0].As<Napi::Object>());
|
|
105
|
+
micropdf_matrix_t m = ObjectToMatrix(info[1].As<Napi::Object>());
|
|
106
|
+
micropdf_point_t result = micropdf_point_transform(p, m);
|
|
107
|
+
|
|
108
|
+
return PointToObject(env, result);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Rect functions
|
|
112
|
+
Napi::Value CreateRect(const Napi::CallbackInfo& info) {
|
|
113
|
+
Napi::Env env = info.Env();
|
|
114
|
+
|
|
115
|
+
float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
|
116
|
+
if (info.Length() >= 4) {
|
|
117
|
+
x0 = info[0].As<Napi::Number>().FloatValue();
|
|
118
|
+
y0 = info[1].As<Napi::Number>().FloatValue();
|
|
119
|
+
x1 = info[2].As<Napi::Number>().FloatValue();
|
|
120
|
+
y1 = info[3].As<Napi::Number>().FloatValue();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
micropdf_rect_t r = {x0, y0, x1, y1};
|
|
124
|
+
return RectToObject(env, r);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Napi::Value RectEmpty(const Napi::CallbackInfo& info) {
|
|
128
|
+
Napi::Env env = info.Env();
|
|
129
|
+
return RectToObject(env, micropdf_rect_empty());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Napi::Value RectUnit(const Napi::CallbackInfo& info) {
|
|
133
|
+
Napi::Env env = info.Env();
|
|
134
|
+
return RectToObject(env, micropdf_rect_unit());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
Napi::Value IsRectEmpty(const Napi::CallbackInfo& info) {
|
|
138
|
+
Napi::Env env = info.Env();
|
|
139
|
+
|
|
140
|
+
if (info.Length() < 1 || !info[0].IsObject()) {
|
|
141
|
+
Napi::TypeError::New(env, "Expected rect object").ThrowAsJavaScriptException();
|
|
142
|
+
return env.Undefined();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
micropdf_rect_t r = ObjectToRect(info[0].As<Napi::Object>());
|
|
146
|
+
return Napi::Boolean::New(env, micropdf_rect_is_empty(r) != 0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Napi::Value RectUnion(const Napi::CallbackInfo& info) {
|
|
150
|
+
Napi::Env env = info.Env();
|
|
151
|
+
|
|
152
|
+
if (info.Length() < 2 || !info[0].IsObject() || !info[1].IsObject()) {
|
|
153
|
+
Napi::TypeError::New(env, "Expected (rect, rect)").ThrowAsJavaScriptException();
|
|
154
|
+
return env.Undefined();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
micropdf_rect_t a = ObjectToRect(info[0].As<Napi::Object>());
|
|
158
|
+
micropdf_rect_t b = ObjectToRect(info[1].As<Napi::Object>());
|
|
159
|
+
|
|
160
|
+
return RectToObject(env, micropdf_rect_union(a, b));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Napi::Value RectIntersect(const Napi::CallbackInfo& info) {
|
|
164
|
+
Napi::Env env = info.Env();
|
|
165
|
+
|
|
166
|
+
if (info.Length() < 2 || !info[0].IsObject() || !info[1].IsObject()) {
|
|
167
|
+
Napi::TypeError::New(env, "Expected (rect, rect)").ThrowAsJavaScriptException();
|
|
168
|
+
return env.Undefined();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
micropdf_rect_t a = ObjectToRect(info[0].As<Napi::Object>());
|
|
172
|
+
micropdf_rect_t b = ObjectToRect(info[1].As<Napi::Object>());
|
|
173
|
+
|
|
174
|
+
return RectToObject(env, micropdf_rect_intersect(a, b));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Matrix functions
|
|
178
|
+
Napi::Value MatrixIdentity(const Napi::CallbackInfo& info) {
|
|
179
|
+
Napi::Env env = info.Env();
|
|
180
|
+
return MatrixToObject(env, micropdf_matrix_identity());
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Napi::Value MatrixTranslate(const Napi::CallbackInfo& info) {
|
|
184
|
+
Napi::Env env = info.Env();
|
|
185
|
+
|
|
186
|
+
float tx = 0, ty = 0;
|
|
187
|
+
if (info.Length() >= 2) {
|
|
188
|
+
tx = info[0].As<Napi::Number>().FloatValue();
|
|
189
|
+
ty = info[1].As<Napi::Number>().FloatValue();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return MatrixToObject(env, micropdf_matrix_translate(tx, ty));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
Napi::Value MatrixScale(const Napi::CallbackInfo& info) {
|
|
196
|
+
Napi::Env env = info.Env();
|
|
197
|
+
|
|
198
|
+
float sx = 1, sy = 1;
|
|
199
|
+
if (info.Length() >= 2) {
|
|
200
|
+
sx = info[0].As<Napi::Number>().FloatValue();
|
|
201
|
+
sy = info[1].As<Napi::Number>().FloatValue();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return MatrixToObject(env, micropdf_matrix_scale(sx, sy));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
Napi::Value MatrixRotate(const Napi::CallbackInfo& info) {
|
|
208
|
+
Napi::Env env = info.Env();
|
|
209
|
+
|
|
210
|
+
float degrees = 0;
|
|
211
|
+
if (info.Length() >= 1) {
|
|
212
|
+
degrees = info[0].As<Napi::Number>().FloatValue();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return MatrixToObject(env, micropdf_matrix_rotate(degrees));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
Napi::Value MatrixConcat(const Napi::CallbackInfo& info) {
|
|
219
|
+
Napi::Env env = info.Env();
|
|
220
|
+
|
|
221
|
+
if (info.Length() < 2 || !info[0].IsObject() || !info[1].IsObject()) {
|
|
222
|
+
Napi::TypeError::New(env, "Expected (matrix, matrix)").ThrowAsJavaScriptException();
|
|
223
|
+
return env.Undefined();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
micropdf_matrix_t a = ObjectToMatrix(info[0].As<Napi::Object>());
|
|
227
|
+
micropdf_matrix_t b = ObjectToMatrix(info[1].As<Napi::Object>());
|
|
228
|
+
|
|
229
|
+
return MatrixToObject(env, micropdf_matrix_concat(a, b));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Export initialization function
|
|
233
|
+
Napi::Object InitGeometry(Napi::Env env, Napi::Object exports) {
|
|
234
|
+
// Point
|
|
235
|
+
exports.Set("createPoint", Napi::Function::New(env, CreatePoint));
|
|
236
|
+
exports.Set("transformPoint", Napi::Function::New(env, TransformPoint));
|
|
237
|
+
|
|
238
|
+
// Rect
|
|
239
|
+
exports.Set("createRect", Napi::Function::New(env, CreateRect));
|
|
240
|
+
exports.Set("rectEmpty", Napi::Function::New(env, RectEmpty));
|
|
241
|
+
exports.Set("rectUnit", Napi::Function::New(env, RectUnit));
|
|
242
|
+
exports.Set("isRectEmpty", Napi::Function::New(env, IsRectEmpty));
|
|
243
|
+
exports.Set("rectUnion", Napi::Function::New(env, RectUnion));
|
|
244
|
+
exports.Set("rectIntersect", Napi::Function::New(env, RectIntersect));
|
|
245
|
+
|
|
246
|
+
// Matrix
|
|
247
|
+
exports.Set("matrixIdentity", Napi::Function::New(env, MatrixIdentity));
|
|
248
|
+
exports.Set("matrixTranslate", Napi::Function::New(env, MatrixTranslate));
|
|
249
|
+
exports.Set("matrixScale", Napi::Function::New(env, MatrixScale));
|
|
250
|
+
exports.Set("matrixRotate", Napi::Function::New(env, MatrixRotate));
|
|
251
|
+
exports.Set("matrixConcat", Napi::Function::New(env, MatrixConcat));
|
|
252
|
+
|
|
253
|
+
return exports;
|
|
254
|
+
}
|
|
255
|
+
|
package/native/image.cc
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF Image Bindings
|
|
3
|
+
*
|
|
4
|
+
* N-API bindings for image operations.
|
|
5
|
+
* Images represent raster graphics with various formats and compression.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include <napi.h>
|
|
9
|
+
#include "include/mupdf_minimal.h"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Load image from file
|
|
13
|
+
*
|
|
14
|
+
* @param ctx - Context handle
|
|
15
|
+
* @param filename - Path to image file
|
|
16
|
+
* @returns Image handle
|
|
17
|
+
*/
|
|
18
|
+
Napi::BigInt NewImageFromFile(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, filename")
|
|
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
|
+
std::string filename = info[1].As<Napi::String>().Utf8Value();
|
|
30
|
+
|
|
31
|
+
uint64_t image_handle = fz_new_image_from_file(ctx_handle, filename.c_str());
|
|
32
|
+
|
|
33
|
+
return Napi::BigInt::New(env, image_handle);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Load image from buffer
|
|
38
|
+
*
|
|
39
|
+
* @param ctx - Context handle
|
|
40
|
+
* @param data - Buffer containing image data
|
|
41
|
+
* @returns Image handle
|
|
42
|
+
*/
|
|
43
|
+
Napi::BigInt NewImageFromBuffer(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, data")
|
|
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
|
+
Napi::Buffer<uint8_t> buffer = info[1].As<Napi::Buffer<uint8_t>>();
|
|
55
|
+
|
|
56
|
+
uint64_t image_handle = fz_new_image_from_buffer_data(
|
|
57
|
+
ctx_handle,
|
|
58
|
+
buffer.Data(),
|
|
59
|
+
buffer.Length()
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return Napi::BigInt::New(env, image_handle);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Drop image handle
|
|
67
|
+
*
|
|
68
|
+
* @param ctx - Context handle
|
|
69
|
+
* @param image - Image handle
|
|
70
|
+
*/
|
|
71
|
+
Napi::Value DropImage(const Napi::CallbackInfo& info) {
|
|
72
|
+
Napi::Env env = info.Env();
|
|
73
|
+
|
|
74
|
+
if (info.Length() < 2) {
|
|
75
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, image")
|
|
76
|
+
.ThrowAsJavaScriptException();
|
|
77
|
+
return env.Undefined();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bool lossless;
|
|
81
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
82
|
+
uint64_t image_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
83
|
+
|
|
84
|
+
fz_drop_image(ctx_handle, image_handle);
|
|
85
|
+
|
|
86
|
+
return env.Undefined();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get image width
|
|
91
|
+
*
|
|
92
|
+
* @param ctx - Context handle
|
|
93
|
+
* @param image - Image handle
|
|
94
|
+
* @returns Width in pixels
|
|
95
|
+
*/
|
|
96
|
+
Napi::Number ImageWidth(const Napi::CallbackInfo& info) {
|
|
97
|
+
Napi::Env env = info.Env();
|
|
98
|
+
|
|
99
|
+
if (info.Length() < 2) {
|
|
100
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, image")
|
|
101
|
+
.ThrowAsJavaScriptException();
|
|
102
|
+
return Napi::Number::New(env, 0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
bool lossless;
|
|
106
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
107
|
+
uint64_t image_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
108
|
+
|
|
109
|
+
int32_t width = fz_image_width(ctx_handle, image_handle);
|
|
110
|
+
|
|
111
|
+
return Napi::Number::New(env, width);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get image height
|
|
116
|
+
*
|
|
117
|
+
* @param ctx - Context handle
|
|
118
|
+
* @param image - Image handle
|
|
119
|
+
* @returns Height in pixels
|
|
120
|
+
*/
|
|
121
|
+
Napi::Number ImageHeight(const Napi::CallbackInfo& info) {
|
|
122
|
+
Napi::Env env = info.Env();
|
|
123
|
+
|
|
124
|
+
if (info.Length() < 2) {
|
|
125
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, image")
|
|
126
|
+
.ThrowAsJavaScriptException();
|
|
127
|
+
return Napi::Number::New(env, 0);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
bool lossless;
|
|
131
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
132
|
+
uint64_t image_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
133
|
+
|
|
134
|
+
int32_t height = fz_image_height(ctx_handle, image_handle);
|
|
135
|
+
|
|
136
|
+
return Napi::Number::New(env, height);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get image colorspace
|
|
141
|
+
*
|
|
142
|
+
* @param ctx - Context handle
|
|
143
|
+
* @param image - Image handle
|
|
144
|
+
* @returns Colorspace handle
|
|
145
|
+
*/
|
|
146
|
+
Napi::BigInt ImageColorspace(const Napi::CallbackInfo& info) {
|
|
147
|
+
Napi::Env env = info.Env();
|
|
148
|
+
|
|
149
|
+
if (info.Length() < 2) {
|
|
150
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, image")
|
|
151
|
+
.ThrowAsJavaScriptException();
|
|
152
|
+
return Napi::BigInt::New(env, static_cast<uint64_t>(0));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
bool lossless;
|
|
156
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
157
|
+
uint64_t image_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
158
|
+
|
|
159
|
+
uint64_t cs_handle = fz_image_colorspace(ctx_handle, image_handle);
|
|
160
|
+
|
|
161
|
+
return Napi::BigInt::New(env, cs_handle);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Convert image to pixmap
|
|
166
|
+
*
|
|
167
|
+
* @param ctx - Context handle
|
|
168
|
+
* @param image - Image handle
|
|
169
|
+
* @returns Object {pixmap: BigInt, width: Number, height: Number}
|
|
170
|
+
*/
|
|
171
|
+
Napi::Object GetPixmapFromImage(const Napi::CallbackInfo& info) {
|
|
172
|
+
Napi::Env env = info.Env();
|
|
173
|
+
Napi::Object result = Napi::Object::New(env);
|
|
174
|
+
|
|
175
|
+
if (info.Length() < 2) {
|
|
176
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, image")
|
|
177
|
+
.ThrowAsJavaScriptException();
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
bool lossless;
|
|
182
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
183
|
+
uint64_t image_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
184
|
+
|
|
185
|
+
int32_t w = 0, h = 0;
|
|
186
|
+
uint64_t pixmap_handle = fz_get_pixmap_from_image(
|
|
187
|
+
ctx_handle,
|
|
188
|
+
image_handle,
|
|
189
|
+
nullptr,
|
|
190
|
+
nullptr,
|
|
191
|
+
&w,
|
|
192
|
+
&h
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
result.Set("pixmap", Napi::BigInt::New(env, pixmap_handle));
|
|
196
|
+
result.Set("width", Napi::Number::New(env, w));
|
|
197
|
+
result.Set("height", Napi::Number::New(env, h));
|
|
198
|
+
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Initialize Image module exports
|
|
204
|
+
*/
|
|
205
|
+
Napi::Object InitImage(Napi::Env env, Napi::Object exports) {
|
|
206
|
+
exports.Set("newImageFromFile", Napi::Function::New(env, NewImageFromFile));
|
|
207
|
+
exports.Set("newImageFromBuffer", Napi::Function::New(env, NewImageFromBuffer));
|
|
208
|
+
exports.Set("dropImage", Napi::Function::New(env, DropImage));
|
|
209
|
+
exports.Set("imageWidth", Napi::Function::New(env, ImageWidth));
|
|
210
|
+
exports.Set("imageHeight", Napi::Function::New(env, ImageHeight));
|
|
211
|
+
exports.Set("imageColorspace", Napi::Function::New(env, ImageColorspace));
|
|
212
|
+
exports.Set("getPixmapFromImage", Napi::Function::New(env, GetPixmapFromImage));
|
|
213
|
+
|
|
214
|
+
return exports;
|
|
215
|
+
}
|
|
216
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// MicroPDF - Enhanced/Extended Functions
|
|
2
|
+
// Auto-generated from Rust FFI - DO NOT EDIT MANUALLY
|
|
3
|
+
// Module: enhanced
|
|
4
|
+
//
|
|
5
|
+
// These are MicroPDF-specific extensions beyond MuPDF compatibility.
|
|
6
|
+
// All functions are prefixed with mp_* to distinguish from MuPDF functions.
|
|
7
|
+
|
|
8
|
+
#ifndef MICROPDF_ENHANCED_H
|
|
9
|
+
#define MICROPDF_ENHANCED_H
|
|
10
|
+
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stddef.h>
|
|
13
|
+
#include <stdbool.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Enhanced Functions (10 total)
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
int32_t mp_add_blank_page(int32_t _ctx, int32_t _doc, float width, float height);
|
|
24
|
+
int32_t mp_add_watermark(int32_t _ctx, const char * input_path, const char * output_path, const char * text, float _x, float _y, float font_size, float opacity);
|
|
25
|
+
int32_t mp_draw_circle(int32_t _ctx, int32_t _page, float _x, float _y, float radius, float r, float g, float b, float alpha, int32_t _fill);
|
|
26
|
+
int32_t mp_draw_line(int32_t _ctx, int32_t _page, float _x0, float _y0, float _x1, float _y1, float r, float g, float b, float alpha, float line_width);
|
|
27
|
+
int32_t mp_draw_rectangle(int32_t _ctx, int32_t _page, float _x, float _y, float width, float height, float r, float g, float b, float alpha, int32_t _fill);
|
|
28
|
+
int32_t mp_linearize_pdf(int32_t _ctx, const char * input_path, const char * output_path);
|
|
29
|
+
int32_t mp_merge_pdfs(int32_t _ctx, const char * const * paths, int32_t count, const char * output_path);
|
|
30
|
+
int32_t mp_optimize_pdf(int32_t _ctx, const char * path);
|
|
31
|
+
int32_t mp_split_pdf(int32_t _ctx, const char * input_path, const char * output_dir);
|
|
32
|
+
int32_t mp_write_pdf(int32_t _ctx, int32_t _doc, const char * _path);
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif /* MICROPDF_ENHANCED_H */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Type aliases for C/C++ compatibility with Rust-generated headers
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MICROPDF_TYPES_H
|
|
8
|
+
#define MICROPDF_TYPES_H
|
|
9
|
+
|
|
10
|
+
#include <stdint.h>
|
|
11
|
+
#include <stddef.h>
|
|
12
|
+
#include <stdbool.h>
|
|
13
|
+
|
|
14
|
+
#ifdef __cplusplus
|
|
15
|
+
extern "C" {
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
// Rust type aliases for C/C++
|
|
19
|
+
typedef int8_t i8;
|
|
20
|
+
typedef int16_t i16;
|
|
21
|
+
typedef int32_t i32;
|
|
22
|
+
typedef int64_t i64;
|
|
23
|
+
typedef uint8_t u8;
|
|
24
|
+
typedef uint16_t u16;
|
|
25
|
+
typedef uint32_t u32;
|
|
26
|
+
typedef uint64_t u64;
|
|
27
|
+
typedef size_t usize;
|
|
28
|
+
typedef float f32;
|
|
29
|
+
typedef double f64;
|
|
30
|
+
|
|
31
|
+
#ifdef __cplusplus
|
|
32
|
+
}
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#endif /* MICROPDF_TYPES_H */
|
|
36
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF - Fast, lightweight PDF library
|
|
3
|
+
*
|
|
4
|
+
* This is a comprehensive C FFI header for the MicroPDF Rust library.
|
|
5
|
+
* All functions are prefixed with fz_ or pdf_ for compatibility with MuPDF.
|
|
6
|
+
*
|
|
7
|
+
* This header includes all auto-generated module headers with complete
|
|
8
|
+
* function declarations for all 660+ FFI functions.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* #include <micropdf.h>
|
|
12
|
+
*
|
|
13
|
+
* For MuPDF drop-in compatibility:
|
|
14
|
+
* #include <mupdf.h>
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef MICROPDF_H
|
|
18
|
+
#define MICROPDF_H
|
|
19
|
+
|
|
20
|
+
#include <stdint.h>
|
|
21
|
+
#include <stddef.h>
|
|
22
|
+
#include <stdbool.h>
|
|
23
|
+
|
|
24
|
+
#ifdef __cplusplus
|
|
25
|
+
extern "C" {
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Type Definitions - Opaque handles for resource management
|
|
30
|
+
// ============================================================================
|
|
31
|
+
|
|
32
|
+
typedef int32_t fz_context;
|
|
33
|
+
typedef int32_t fz_document;
|
|
34
|
+
typedef int32_t fz_page;
|
|
35
|
+
typedef int32_t fz_device;
|
|
36
|
+
typedef int32_t fz_pixmap;
|
|
37
|
+
typedef int32_t fz_buffer;
|
|
38
|
+
typedef int32_t fz_stream;
|
|
39
|
+
typedef int32_t fz_output;
|
|
40
|
+
typedef int32_t fz_colorspace;
|
|
41
|
+
typedef int32_t fz_font;
|
|
42
|
+
typedef int32_t fz_image;
|
|
43
|
+
typedef int32_t fz_path;
|
|
44
|
+
typedef int32_t fz_text;
|
|
45
|
+
typedef int32_t fz_cookie;
|
|
46
|
+
typedef int32_t fz_display_list;
|
|
47
|
+
typedef int32_t fz_link;
|
|
48
|
+
typedef int32_t fz_archive;
|
|
49
|
+
typedef int32_t pdf_obj;
|
|
50
|
+
typedef int32_t pdf_annot;
|
|
51
|
+
typedef int32_t pdf_form_field;
|
|
52
|
+
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Geometry types (used by many modules)
|
|
55
|
+
// ============================================================================
|
|
56
|
+
|
|
57
|
+
typedef struct {
|
|
58
|
+
float x, y;
|
|
59
|
+
} fz_point;
|
|
60
|
+
|
|
61
|
+
typedef struct {
|
|
62
|
+
float x0, y0;
|
|
63
|
+
float x1, y1;
|
|
64
|
+
} fz_rect;
|
|
65
|
+
|
|
66
|
+
typedef struct {
|
|
67
|
+
int x0, y0;
|
|
68
|
+
int x1, y1;
|
|
69
|
+
} fz_irect;
|
|
70
|
+
|
|
71
|
+
typedef struct {
|
|
72
|
+
float a, b, c, d, e, f;
|
|
73
|
+
} fz_matrix;
|
|
74
|
+
|
|
75
|
+
typedef struct {
|
|
76
|
+
fz_point ul, ur, ll, lr;
|
|
77
|
+
} fz_quad;
|
|
78
|
+
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Common type aliases
|
|
81
|
+
// ============================================================================
|
|
82
|
+
|
|
83
|
+
typedef int32_t PdfObjHandle;
|
|
84
|
+
typedef int32_t Handle;
|
|
85
|
+
|
|
86
|
+
// ============================================================================
|
|
87
|
+
// Function Declarations
|
|
88
|
+
// ============================================================================
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* All function declarations are auto-generated from Rust FFI source.
|
|
92
|
+
* See individual module headers in mupdf/fitz/ and mupdf/pdf/ for details.
|
|
93
|
+
*
|
|
94
|
+
* Total: 660+ functions covering:
|
|
95
|
+
* - Core fitz functions (geometry, buffers, streams, devices, etc.)
|
|
96
|
+
* - PDF-specific functions (annotations, forms, objects, etc.)
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
// For complete function declarations, include the comprehensive header:
|
|
100
|
+
#include "mupdf.h"
|
|
101
|
+
|
|
102
|
+
#ifdef __cplusplus
|
|
103
|
+
}
|
|
104
|
+
#endif
|
|
105
|
+
|
|
106
|
+
#endif /* MICROPDF_H */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MuPDF FFI Compatibility Header
|
|
3
|
+
*
|
|
4
|
+
* This header provides 100% MuPDF-compatible FFI bindings.
|
|
5
|
+
* Include this for drop-in compatibility with MuPDF-based applications.
|
|
6
|
+
*
|
|
7
|
+
* All 660+ fz_* and pdf_* functions are available through this header.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* #include <mupdf-ffi.h>
|
|
11
|
+
*
|
|
12
|
+
* Or for complete MuPDF compatibility:
|
|
13
|
+
* #include <mupdf.h>
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#ifndef MUPDF_FFI_H
|
|
17
|
+
#define MUPDF_FFI_H
|
|
18
|
+
|
|
19
|
+
#include "micropdf.h"
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* All MuPDF-compatible functions are available through micropdf.h
|
|
23
|
+
*
|
|
24
|
+
* Function categories:
|
|
25
|
+
* - Context management (fz_new_context, fz_drop_context, etc.)
|
|
26
|
+
* - Document operations (fz_open_document, fz_load_page, etc.)
|
|
27
|
+
* - Geometry operations (fz_concat, fz_transform_rect, etc.)
|
|
28
|
+
* - Buffer operations (fz_new_buffer, fz_append_data, etc.)
|
|
29
|
+
* - Device operations (fz_new_bbox_device, fz_fill_path, etc.)
|
|
30
|
+
* - Image operations (fz_new_image_from_pixmap, fz_decode_image, etc.)
|
|
31
|
+
* - Text operations (fz_new_text, fz_show_string, etc.)
|
|
32
|
+
* - PDF object operations (pdf_new_dict, pdf_dict_get, etc.)
|
|
33
|
+
* - PDF annotation operations (pdf_create_annot, pdf_set_annot_contents, etc.)
|
|
34
|
+
* - PDF form operations (pdf_next_widget, pdf_set_field_value, etc.)
|
|
35
|
+
*
|
|
36
|
+
* Total coverage: 660+ functions
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#endif /* MUPDF_FFI_H */
|