@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
package/native/path.cc
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF Path Bindings
|
|
3
|
+
*
|
|
4
|
+
* N-API bindings for path operations.
|
|
5
|
+
* Paths represent vector graphics for stroking and filling.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include <napi.h>
|
|
9
|
+
#include "include/mupdf_minimal.h"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a new empty path
|
|
13
|
+
*
|
|
14
|
+
* @param ctx - Context handle
|
|
15
|
+
* @returns Path handle
|
|
16
|
+
*/
|
|
17
|
+
Napi::BigInt NewPath(const Napi::CallbackInfo& info) {
|
|
18
|
+
Napi::Env env = info.Env();
|
|
19
|
+
|
|
20
|
+
if (info.Length() < 1) {
|
|
21
|
+
Napi::TypeError::New(env, "Expected 1 argument: ctx")
|
|
22
|
+
.ThrowAsJavaScriptException();
|
|
23
|
+
return Napi::BigInt::New(env, static_cast<uint64_t>(0));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
bool lossless;
|
|
27
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
28
|
+
|
|
29
|
+
uint64_t path_handle = fz_new_path(ctx_handle);
|
|
30
|
+
|
|
31
|
+
return Napi::BigInt::New(env, path_handle);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Drop path handle
|
|
36
|
+
*
|
|
37
|
+
* @param ctx - Context handle
|
|
38
|
+
* @param path - Path handle
|
|
39
|
+
*/
|
|
40
|
+
Napi::Value DropPath(const Napi::CallbackInfo& info) {
|
|
41
|
+
Napi::Env env = info.Env();
|
|
42
|
+
|
|
43
|
+
if (info.Length() < 2) {
|
|
44
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, path")
|
|
45
|
+
.ThrowAsJavaScriptException();
|
|
46
|
+
return env.Undefined();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
bool lossless;
|
|
50
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
51
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
52
|
+
|
|
53
|
+
fz_drop_path(ctx_handle, path_handle);
|
|
54
|
+
|
|
55
|
+
return env.Undefined();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Move to a point (start new subpath)
|
|
60
|
+
*
|
|
61
|
+
* @param ctx - Context handle
|
|
62
|
+
* @param path - Path handle
|
|
63
|
+
* @param x - X coordinate
|
|
64
|
+
* @param y - Y coordinate
|
|
65
|
+
*/
|
|
66
|
+
Napi::Value PathMoveTo(const Napi::CallbackInfo& info) {
|
|
67
|
+
Napi::Env env = info.Env();
|
|
68
|
+
|
|
69
|
+
if (info.Length() < 4) {
|
|
70
|
+
Napi::TypeError::New(env, "Expected 4 arguments: ctx, path, x, y")
|
|
71
|
+
.ThrowAsJavaScriptException();
|
|
72
|
+
return env.Undefined();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
bool lossless;
|
|
76
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
77
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
78
|
+
float x = info[2].As<Napi::Number>().FloatValue();
|
|
79
|
+
float y = info[3].As<Napi::Number>().FloatValue();
|
|
80
|
+
|
|
81
|
+
fz_moveto(ctx_handle, path_handle, x, y);
|
|
82
|
+
|
|
83
|
+
return env.Undefined();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Line to a point
|
|
88
|
+
*
|
|
89
|
+
* @param ctx - Context handle
|
|
90
|
+
* @param path - Path handle
|
|
91
|
+
* @param x - X coordinate
|
|
92
|
+
* @param y - Y coordinate
|
|
93
|
+
*/
|
|
94
|
+
Napi::Value PathLineTo(const Napi::CallbackInfo& info) {
|
|
95
|
+
Napi::Env env = info.Env();
|
|
96
|
+
|
|
97
|
+
if (info.Length() < 4) {
|
|
98
|
+
Napi::TypeError::New(env, "Expected 4 arguments: ctx, path, x, y")
|
|
99
|
+
.ThrowAsJavaScriptException();
|
|
100
|
+
return env.Undefined();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
bool lossless;
|
|
104
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
105
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
106
|
+
float x = info[2].As<Napi::Number>().FloatValue();
|
|
107
|
+
float y = info[3].As<Napi::Number>().FloatValue();
|
|
108
|
+
|
|
109
|
+
fz_lineto(ctx_handle, path_handle, x, y);
|
|
110
|
+
|
|
111
|
+
return env.Undefined();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Cubic Bezier curve to a point
|
|
116
|
+
*
|
|
117
|
+
* @param ctx - Context handle
|
|
118
|
+
* @param path - Path handle
|
|
119
|
+
* @param x1 - Control point 1 X
|
|
120
|
+
* @param y1 - Control point 1 Y
|
|
121
|
+
* @param x2 - Control point 2 X
|
|
122
|
+
* @param y2 - Control point 2 Y
|
|
123
|
+
* @param x3 - End point X
|
|
124
|
+
* @param y3 - End point Y
|
|
125
|
+
*/
|
|
126
|
+
Napi::Value PathCurveTo(const Napi::CallbackInfo& info) {
|
|
127
|
+
Napi::Env env = info.Env();
|
|
128
|
+
|
|
129
|
+
if (info.Length() < 8) {
|
|
130
|
+
Napi::TypeError::New(env, "Expected 8 arguments: ctx, path, x1, y1, x2, y2, x3, y3")
|
|
131
|
+
.ThrowAsJavaScriptException();
|
|
132
|
+
return env.Undefined();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
bool lossless;
|
|
136
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
137
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
138
|
+
float x1 = info[2].As<Napi::Number>().FloatValue();
|
|
139
|
+
float y1 = info[3].As<Napi::Number>().FloatValue();
|
|
140
|
+
float x2 = info[4].As<Napi::Number>().FloatValue();
|
|
141
|
+
float y2 = info[5].As<Napi::Number>().FloatValue();
|
|
142
|
+
float x3 = info[6].As<Napi::Number>().FloatValue();
|
|
143
|
+
float y3 = info[7].As<Napi::Number>().FloatValue();
|
|
144
|
+
|
|
145
|
+
fz_curveto(ctx_handle, path_handle, x1, y1, x2, y2, x3, y3);
|
|
146
|
+
|
|
147
|
+
return env.Undefined();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Close the current subpath
|
|
152
|
+
*
|
|
153
|
+
* @param ctx - Context handle
|
|
154
|
+
* @param path - Path handle
|
|
155
|
+
*/
|
|
156
|
+
Napi::Value PathClosePath(const Napi::CallbackInfo& info) {
|
|
157
|
+
Napi::Env env = info.Env();
|
|
158
|
+
|
|
159
|
+
if (info.Length() < 2) {
|
|
160
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, path")
|
|
161
|
+
.ThrowAsJavaScriptException();
|
|
162
|
+
return env.Undefined();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
bool lossless;
|
|
166
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
167
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
168
|
+
|
|
169
|
+
fz_closepath(ctx_handle, path_handle);
|
|
170
|
+
|
|
171
|
+
return env.Undefined();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Add rectangle to path
|
|
176
|
+
*
|
|
177
|
+
* @param ctx - Context handle
|
|
178
|
+
* @param path - Path handle
|
|
179
|
+
* @param x - X coordinate
|
|
180
|
+
* @param y - Y coordinate
|
|
181
|
+
* @param w - Width
|
|
182
|
+
* @param h - Height
|
|
183
|
+
*/
|
|
184
|
+
Napi::Value PathRect(const Napi::CallbackInfo& info) {
|
|
185
|
+
Napi::Env env = info.Env();
|
|
186
|
+
|
|
187
|
+
if (info.Length() < 6) {
|
|
188
|
+
Napi::TypeError::New(env, "Expected 6 arguments: ctx, path, x, y, w, h")
|
|
189
|
+
.ThrowAsJavaScriptException();
|
|
190
|
+
return env.Undefined();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
bool lossless;
|
|
194
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
195
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
196
|
+
float x = info[2].As<Napi::Number>().FloatValue();
|
|
197
|
+
float y = info[3].As<Napi::Number>().FloatValue();
|
|
198
|
+
float w = info[4].As<Napi::Number>().FloatValue();
|
|
199
|
+
float h = info[5].As<Napi::Number>().FloatValue();
|
|
200
|
+
|
|
201
|
+
fz_rectto(ctx_handle, path_handle, x, y, w, h);
|
|
202
|
+
|
|
203
|
+
return env.Undefined();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get path bounding box
|
|
208
|
+
*
|
|
209
|
+
* @param ctx - Context handle
|
|
210
|
+
* @param path - Path handle
|
|
211
|
+
* @param stroke - Optional stroke state handle
|
|
212
|
+
* @param ctm - Optional transform matrix
|
|
213
|
+
* @returns Rectangle {x0, y0, x1, y1}
|
|
214
|
+
*/
|
|
215
|
+
Napi::Object PathBoundPath(const Napi::CallbackInfo& info) {
|
|
216
|
+
Napi::Env env = info.Env();
|
|
217
|
+
Napi::Object result = Napi::Object::New(env);
|
|
218
|
+
|
|
219
|
+
if (info.Length() < 2) {
|
|
220
|
+
Napi::TypeError::New(env, "Expected at least 2 arguments: ctx, path")
|
|
221
|
+
.ThrowAsJavaScriptException();
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
bool lossless;
|
|
226
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
227
|
+
uint64_t path_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
228
|
+
|
|
229
|
+
uint64_t stroke_handle = 0;
|
|
230
|
+
if (info.Length() > 2 && !info[2].IsNull() && !info[2].IsUndefined()) {
|
|
231
|
+
stroke_handle = info[2].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fz_rect rect = fz_bound_path(ctx_handle, path_handle, stroke_handle);
|
|
235
|
+
|
|
236
|
+
result.Set("x0", Napi::Number::New(env, rect.x0));
|
|
237
|
+
result.Set("y0", Napi::Number::New(env, rect.y0));
|
|
238
|
+
result.Set("x1", Napi::Number::New(env, rect.x1));
|
|
239
|
+
result.Set("y1", Napi::Number::New(env, rect.y1));
|
|
240
|
+
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Initialize Path module exports
|
|
246
|
+
*/
|
|
247
|
+
Napi::Object InitPath(Napi::Env env, Napi::Object exports) {
|
|
248
|
+
exports.Set("newPath", Napi::Function::New(env, NewPath));
|
|
249
|
+
exports.Set("dropPath", Napi::Function::New(env, DropPath));
|
|
250
|
+
exports.Set("pathMoveTo", Napi::Function::New(env, PathMoveTo));
|
|
251
|
+
exports.Set("pathLineTo", Napi::Function::New(env, PathLineTo));
|
|
252
|
+
exports.Set("pathCurveTo", Napi::Function::New(env, PathCurveTo));
|
|
253
|
+
exports.Set("pathClosePath", Napi::Function::New(env, PathClosePath));
|
|
254
|
+
exports.Set("pathRect", Napi::Function::New(env, PathRect));
|
|
255
|
+
exports.Set("pathBoundPath", Napi::Function::New(env, PathBoundPath));
|
|
256
|
+
|
|
257
|
+
return exports;
|
|
258
|
+
}
|
|
259
|
+
|
package/native/pixmap.cc
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MicroPDF Pixmap Bindings
|
|
3
|
+
*
|
|
4
|
+
* N-API bindings for pixmap operations.
|
|
5
|
+
* Pixmaps are pixel buffers for rendering output.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include <napi.h>
|
|
9
|
+
#include "include/mupdf_minimal.h"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a new pixmap
|
|
13
|
+
*
|
|
14
|
+
* @param ctx - Context handle
|
|
15
|
+
* @param colorspace - Colorspace handle (or 0 for alpha-only)
|
|
16
|
+
* @param w - Width in pixels
|
|
17
|
+
* @param h - Height in pixels
|
|
18
|
+
* @param alpha - Include alpha channel
|
|
19
|
+
* @returns Pixmap handle
|
|
20
|
+
*/
|
|
21
|
+
Napi::BigInt NewPixmap(const Napi::CallbackInfo& info) {
|
|
22
|
+
Napi::Env env = info.Env();
|
|
23
|
+
|
|
24
|
+
if (info.Length() < 5) {
|
|
25
|
+
Napi::TypeError::New(env, "Expected 5 arguments: ctx, colorspace, w, h, alpha")
|
|
26
|
+
.ThrowAsJavaScriptException();
|
|
27
|
+
return Napi::BigInt::New(env, static_cast<uint64_t>(0));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
bool lossless;
|
|
31
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
32
|
+
uint64_t cs_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
33
|
+
int32_t w = info[2].As<Napi::Number>().Int32Value();
|
|
34
|
+
int32_t h = info[3].As<Napi::Number>().Int32Value();
|
|
35
|
+
int32_t alpha = info[4].As<Napi::Boolean>().Value() ? 1 : 0;
|
|
36
|
+
|
|
37
|
+
uint64_t pixmap_handle = fz_new_pixmap(ctx_handle, cs_handle, w, h, alpha);
|
|
38
|
+
|
|
39
|
+
return Napi::BigInt::New(env, pixmap_handle);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Drop pixmap handle
|
|
44
|
+
*
|
|
45
|
+
* @param ctx - Context handle
|
|
46
|
+
* @param pixmap - Pixmap handle
|
|
47
|
+
*/
|
|
48
|
+
Napi::Value DropPixmap(const Napi::CallbackInfo& info) {
|
|
49
|
+
Napi::Env env = info.Env();
|
|
50
|
+
|
|
51
|
+
if (info.Length() < 2) {
|
|
52
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, pixmap")
|
|
53
|
+
.ThrowAsJavaScriptException();
|
|
54
|
+
return env.Undefined();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
bool lossless;
|
|
58
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
59
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
60
|
+
|
|
61
|
+
fz_drop_pixmap(ctx_handle, pixmap_handle);
|
|
62
|
+
|
|
63
|
+
return env.Undefined();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get pixmap width
|
|
68
|
+
*
|
|
69
|
+
* @param ctx - Context handle
|
|
70
|
+
* @param pixmap - Pixmap handle
|
|
71
|
+
* @returns Width in pixels
|
|
72
|
+
*/
|
|
73
|
+
Napi::Number PixmapWidth(const Napi::CallbackInfo& info) {
|
|
74
|
+
Napi::Env env = info.Env();
|
|
75
|
+
|
|
76
|
+
if (info.Length() < 2) {
|
|
77
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, pixmap")
|
|
78
|
+
.ThrowAsJavaScriptException();
|
|
79
|
+
return Napi::Number::New(env, 0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
bool lossless;
|
|
83
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
84
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
85
|
+
|
|
86
|
+
int32_t width = fz_pixmap_width(ctx_handle, pixmap_handle);
|
|
87
|
+
|
|
88
|
+
return Napi::Number::New(env, width);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get pixmap height
|
|
93
|
+
*
|
|
94
|
+
* @param ctx - Context handle
|
|
95
|
+
* @param pixmap - Pixmap handle
|
|
96
|
+
* @returns Height in pixels
|
|
97
|
+
*/
|
|
98
|
+
Napi::Number PixmapHeight(const Napi::CallbackInfo& info) {
|
|
99
|
+
Napi::Env env = info.Env();
|
|
100
|
+
|
|
101
|
+
if (info.Length() < 2) {
|
|
102
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, pixmap")
|
|
103
|
+
.ThrowAsJavaScriptException();
|
|
104
|
+
return Napi::Number::New(env, 0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
bool lossless;
|
|
108
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
109
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
110
|
+
|
|
111
|
+
int32_t height = fz_pixmap_height(ctx_handle, pixmap_handle);
|
|
112
|
+
|
|
113
|
+
return Napi::Number::New(env, height);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get pixmap samples (pixel data)
|
|
118
|
+
*
|
|
119
|
+
* @param ctx - Context handle
|
|
120
|
+
* @param pixmap - Pixmap handle
|
|
121
|
+
* @returns Buffer containing pixel data
|
|
122
|
+
*/
|
|
123
|
+
Napi::Buffer<uint8_t> PixmapSamples(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, pixmap")
|
|
128
|
+
.ThrowAsJavaScriptException();
|
|
129
|
+
return Napi::Buffer<uint8_t>::New(env, 0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
bool lossless;
|
|
133
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
134
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
135
|
+
|
|
136
|
+
uint8_t* data = nullptr;
|
|
137
|
+
size_t size = 0;
|
|
138
|
+
|
|
139
|
+
fz_pixmap_samples(ctx_handle, pixmap_handle, &data, &size);
|
|
140
|
+
|
|
141
|
+
if (data && size > 0) {
|
|
142
|
+
// Create a copy of the data for Node.js
|
|
143
|
+
return Napi::Buffer<uint8_t>::Copy(env, data, size);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return Napi::Buffer<uint8_t>::New(env, 0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get pixmap stride (bytes per row)
|
|
151
|
+
*
|
|
152
|
+
* @param ctx - Context handle
|
|
153
|
+
* @param pixmap - Pixmap handle
|
|
154
|
+
* @returns Stride in bytes
|
|
155
|
+
*/
|
|
156
|
+
Napi::Number PixmapStride(const Napi::CallbackInfo& info) {
|
|
157
|
+
Napi::Env env = info.Env();
|
|
158
|
+
|
|
159
|
+
if (info.Length() < 2) {
|
|
160
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, pixmap")
|
|
161
|
+
.ThrowAsJavaScriptException();
|
|
162
|
+
return Napi::Number::New(env, 0);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
bool lossless;
|
|
166
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
167
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
168
|
+
|
|
169
|
+
size_t stride = fz_pixmap_stride(ctx_handle, pixmap_handle);
|
|
170
|
+
|
|
171
|
+
return Napi::Number::New(env, static_cast<double>(stride));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get number of components (including alpha)
|
|
176
|
+
*
|
|
177
|
+
* @param ctx - Context handle
|
|
178
|
+
* @param pixmap - Pixmap handle
|
|
179
|
+
* @returns Number of components
|
|
180
|
+
*/
|
|
181
|
+
Napi::Number PixmapComponents(const Napi::CallbackInfo& info) {
|
|
182
|
+
Napi::Env env = info.Env();
|
|
183
|
+
|
|
184
|
+
if (info.Length() < 2) {
|
|
185
|
+
Napi::TypeError::New(env, "Expected 2 arguments: ctx, pixmap")
|
|
186
|
+
.ThrowAsJavaScriptException();
|
|
187
|
+
return Napi::Number::New(env, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
bool lossless;
|
|
191
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
192
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
193
|
+
|
|
194
|
+
int32_t n = fz_pixmap_components(ctx_handle, pixmap_handle);
|
|
195
|
+
|
|
196
|
+
return Napi::Number::New(env, n);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Clear pixmap to a color
|
|
201
|
+
*
|
|
202
|
+
* @param ctx - Context handle
|
|
203
|
+
* @param pixmap - Pixmap handle
|
|
204
|
+
* @param value - Clear value (0-255)
|
|
205
|
+
*/
|
|
206
|
+
Napi::Value ClearPixmap(const Napi::CallbackInfo& info) {
|
|
207
|
+
Napi::Env env = info.Env();
|
|
208
|
+
|
|
209
|
+
if (info.Length() < 3) {
|
|
210
|
+
Napi::TypeError::New(env, "Expected 3 arguments: ctx, pixmap, value")
|
|
211
|
+
.ThrowAsJavaScriptException();
|
|
212
|
+
return env.Undefined();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
bool lossless;
|
|
216
|
+
uint64_t ctx_handle = info[0].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
217
|
+
uint64_t pixmap_handle = info[1].As<Napi::BigInt>().Uint64Value(&lossless);
|
|
218
|
+
int32_t value = info[2].As<Napi::Number>().Int32Value();
|
|
219
|
+
|
|
220
|
+
fz_clear_pixmap(ctx_handle, pixmap_handle, value);
|
|
221
|
+
|
|
222
|
+
return env.Undefined();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Initialize Pixmap module exports
|
|
227
|
+
*/
|
|
228
|
+
Napi::Object InitPixmap(Napi::Env env, Napi::Object exports) {
|
|
229
|
+
exports.Set("newPixmap", Napi::Function::New(env, NewPixmap));
|
|
230
|
+
exports.Set("dropPixmap", Napi::Function::New(env, DropPixmap));
|
|
231
|
+
exports.Set("pixmapWidth", Napi::Function::New(env, PixmapWidth));
|
|
232
|
+
exports.Set("pixmapHeight", Napi::Function::New(env, PixmapHeight));
|
|
233
|
+
exports.Set("pixmapSamples", Napi::Function::New(env, PixmapSamples));
|
|
234
|
+
exports.Set("pixmapStride", Napi::Function::New(env, PixmapStride));
|
|
235
|
+
exports.Set("pixmapComponents", Napi::Function::New(env, PixmapComponents));
|
|
236
|
+
exports.Set("clearPixmap", Napi::Function::New(env, ClearPixmap));
|
|
237
|
+
|
|
238
|
+
return exports;
|
|
239
|
+
}
|
|
240
|
+
|