aspose.barcode 20.6.11

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/lib/Joint.js ADDED
@@ -0,0 +1,439 @@
1
+ const java = require('java');
2
+ const fs = require("fs");
3
+
4
+
5
+ function isPath(image)
6
+ {
7
+ if (image.length < 256 && image.includes("/") || image.includes("\\"))
8
+ {
9
+ if (fs.existsSync(image))
10
+ {
11
+ return true;
12
+ }
13
+ throw new joint.BarcodeException("Path " + image + " does not exist");
14
+ }
15
+ return false;
16
+ }
17
+
18
+ function convertResourceToBase64String(resource)
19
+ {
20
+ let is_path_to_image = false;
21
+ is_path_to_image = fs.existsSync(resource);
22
+
23
+ if (is_path_to_image)
24
+ {
25
+ return fs.readFileSync(resource).toString('base64');
26
+ }
27
+ else
28
+ {
29
+ return resource;
30
+ }
31
+ }
32
+
33
+ class BaseJavaClass
34
+ {
35
+ javaClass;
36
+ javaClassName;
37
+
38
+ constructor(javaClass)
39
+ {
40
+ this.javaClass = javaClass;
41
+
42
+ if (this.javaClassName == null || this.javaClassName === "")
43
+ {
44
+ this.javaClassName = this.javaClass.__signature;
45
+ }
46
+ }
47
+
48
+ init()
49
+ {
50
+ throw new BarcodeException('You have to implement the method init!');
51
+ }
52
+
53
+ /**
54
+ * @return mixed
55
+ */
56
+ getJavaClass()
57
+ {
58
+ return this.javaClass;
59
+ }
60
+
61
+ /**
62
+ * @return mixed
63
+ */
64
+ setJavaClass(javaClass)
65
+ {
66
+ this.javaClass = javaClass;
67
+ this.init();
68
+ }
69
+
70
+ getJavaClassName()
71
+ {
72
+ return this.javaClassName;
73
+ }
74
+
75
+ isNull()
76
+ {
77
+ return java_cast(this.javaClass.isNull(), "boolean");
78
+ }
79
+
80
+ printJavaClassName()
81
+ {
82
+ console.log("Java class name => '" + this.javaClassName + "'");
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Provides methods to license the component.
88
+ */
89
+ class License extends BaseJavaClass
90
+ {
91
+ static get javaClassName()
92
+ {
93
+ return "com.aspose.nodejs.barcode.license.NodejsLicense"
94
+ };
95
+
96
+ /**
97
+ * Initializes a new instance of this class.
98
+ */
99
+ constructor()
100
+ {
101
+ let javaLicense = java.import(License.javaClassName);
102
+ super(new javaLicense());
103
+ }
104
+
105
+ /**
106
+ * Licenses the component.
107
+ *
108
+ * @param licenseName Can be a full or short file name
109
+ */
110
+ setLicense(filePath)
111
+ {
112
+ try
113
+ {
114
+ let file_data = License.openFile(filePath);
115
+ this.getJavaClass().setLicenseSync(file_data);
116
+ } catch (ex)
117
+ {
118
+ throw new BarcodeException(ex);
119
+ }
120
+ }
121
+
122
+ isLicensed()
123
+ {
124
+ let is_licensed = this.getJavaClass().isLicensedSync();
125
+ return is_licensed.toString();
126
+ }
127
+
128
+ static openFile(filename)
129
+ {
130
+ let buffer = Buffer.from(fs.readFileSync(filename, 'utf8'));
131
+ let array = [];
132
+ array.push('');
133
+ for (let i = 0; i < buffer.length; i++)
134
+ {
135
+ array.push(buffer[i] + '');
136
+ }
137
+ return array;
138
+ }
139
+
140
+ init()
141
+ {
142
+ // do nothing
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Class BarcodeException
148
+ */
149
+ class BarcodeException extends Error
150
+ {
151
+ static get MAX_LINES()
152
+ {
153
+ return 4;
154
+ };
155
+
156
+ /**
157
+ * BarcodeException constructor.
158
+ * @param exc exception's instance
159
+ */
160
+ constructor(exc)
161
+ {
162
+ super();
163
+ if ((typeof exc.toString()) === 'string')
164
+ {
165
+ this.setMessage(exc.toString());
166
+ return;
167
+ }
168
+ let exc_message = "Exception occured in file:line" + nl;
169
+
170
+ this.setMessage(exc_message);
171
+ }
172
+
173
+ getDetails(exc)
174
+ {
175
+ let details = "";
176
+ if (typeof exc === 'string' || exc instanceof String)
177
+ {
178
+ return exc;
179
+ }
180
+ if (get_class(exc) != null)
181
+ {
182
+ details = "exception type : " + get_class(exc) + "\n";
183
+ }
184
+ if (method_exists(exc, "__toString"))
185
+ {
186
+ details += exc.__toString();
187
+ }
188
+ if (method_exists(exc, "getMessage"))
189
+ {
190
+ details += exc.getMessage();
191
+ }
192
+ if (method_exists(exc, "getCause"))
193
+ {
194
+ details += exc.getCause();
195
+ }
196
+ return details;
197
+ }
198
+
199
+ /**
200
+ * @param mixed message
201
+ */
202
+ setMessage(message)
203
+ {
204
+ this.message = message;
205
+ }
206
+
207
+ }
208
+
209
+ class Rectangle extends BaseJavaClass
210
+ {
211
+
212
+ static get EMPTY()
213
+ {
214
+ return new Rectangle(0, 0,0,0);
215
+ }
216
+
217
+ init()
218
+ {
219
+ // TODO: Implement init() method.
220
+ }
221
+
222
+ static get javaClassName()
223
+ {
224
+ return "java.awt.Rectangle";
225
+ }
226
+
227
+ /**
228
+ * Rectangle constructor.
229
+ * @param x
230
+ * @param y
231
+ * @param width
232
+ * @param height
233
+ */
234
+ constructor(x, y, width, height)
235
+ {
236
+ let java_class_link = java.import(Rectangle.javaClassName);
237
+ let java_class = new java_class_link(x, y, width, height);
238
+ super(java_class);
239
+ }
240
+
241
+ static construct(...args)
242
+ {
243
+ let rectangle = this.EMPTY;
244
+ rectangle.setJavaClass(args[0]);
245
+ return rectangle;
246
+ }
247
+
248
+ getX()
249
+ {
250
+ return this.getJavaClass().getXSync();
251
+ }
252
+
253
+ getY()
254
+ {
255
+ return this.getJavaClass().getYSync();
256
+ }
257
+
258
+ getLeft()
259
+ {
260
+ return this.getX();
261
+ }
262
+
263
+ getTop()
264
+ {
265
+ return this.getY();
266
+ }
267
+
268
+ getRight()
269
+ {
270
+ return this.getX() + this.getWidth();
271
+ }
272
+
273
+ getBottom()
274
+ {
275
+ return this.getY() + this.getHeight();
276
+ }
277
+
278
+ getWidth()
279
+ {
280
+ return this.getJavaClass().getWidthSync();
281
+ }
282
+
283
+ getHeight()
284
+ {
285
+ return this.getJavaClass().getHeightSync();
286
+ }
287
+
288
+ toString()
289
+ {
290
+ return this.getX() + ',' + this.getY() + ',' + this.getWidth() + ',' + this.getHeight();
291
+ }
292
+
293
+ equals(obj)
294
+ {
295
+ return this.getJavaClass().equals(obj.getJavaClass());
296
+ }
297
+
298
+ /**
299
+ * Determines if this rectangle intersects with rect.
300
+ * @param rectangle
301
+ * @returns {boolean}
302
+ */
303
+ intersectsWithInclusive(rectangle)
304
+ {
305
+ return !((this.getLeft() > rectangle.getRight()) || (this.getRight() < rectangle.getLeft()) ||
306
+ (this.getTop() > rectangle.getBottom()) || (this.getBottom() < rectangle.getTop()));
307
+ }
308
+
309
+ /**
310
+ * Intersect Shared Method
311
+ * Produces a new Rectangle by intersecting 2 existing
312
+ * Rectangles. Returns null if there is no intersection.
313
+ */
314
+ static intersect(a, b)
315
+ {
316
+ if (!a.intersectsWithInclusive(b))
317
+ {
318
+ return new Rectangle(0, 0, 0, 0);
319
+ }
320
+ return Rectangle.fromLTRB(Math.max(a.getLeft(), b.getLeft()),
321
+ Math.max(a.getTop(), b.getTop()),
322
+ Math.min(a.getRight(), b.getRight()),
323
+ Math.min(a.getBottom(), b.getBottom()));
324
+ }
325
+
326
+ /**
327
+ * FromLTRB Shared Method
328
+ * Produces a Rectangle class from left, top, right,
329
+ * and bottom coordinates.
330
+ */
331
+ static fromLTRB(left, top, right, bottom)
332
+ {
333
+ return new Rectangle(left, top, right - left, bottom - top);
334
+ }
335
+
336
+ isEmpty()
337
+ {
338
+ return (this.getWidth() <= 0) || (this.getHeight() <= 0);
339
+ }
340
+ }
341
+
342
+ class Point extends BaseJavaClass
343
+ {
344
+ static get javaClassName()
345
+ {
346
+ return "java.awt.Point";
347
+ }
348
+
349
+ /**
350
+ * Represents a Quadrangle structure with its properties left uninitialized.Value: Quadrangle
351
+ */
352
+ static get EMPTY()
353
+ {
354
+ return new Point(0, 0);
355
+ }
356
+
357
+ /**
358
+ * Rectangle constructor.
359
+ * @param x
360
+ * @param y
361
+ */
362
+ constructor(x, y)
363
+ {
364
+ let java_class_link = java.import(Point.javaClassName);
365
+ let java_class = new java_class_link(x, y);
366
+ super(java_class);
367
+ }
368
+
369
+ static construct(...args)
370
+ {
371
+ let point = Point.EMPTY;
372
+ point.setJavaClass(args[0]);
373
+ return point;
374
+ }
375
+
376
+ init()
377
+ {
378
+ // TODO: Implement init() method.
379
+ }
380
+
381
+ getX()
382
+ {
383
+ return this.getJavaClass().getXSync();
384
+ }
385
+
386
+ getY()
387
+ {
388
+ return this.getJavaClass().getYSync();
389
+ }
390
+
391
+ setX(x)
392
+ {
393
+ this.getJavaClass().xSync = x;
394
+ }
395
+
396
+ setY(y)
397
+ {
398
+ this.getJavaClass().ySync = y;
399
+ }
400
+
401
+ toString()
402
+ {
403
+ return this.getX() + ',' + this.getY();
404
+ }
405
+
406
+ equals(obj)
407
+ {
408
+ return this.getJavaClass().equals(obj.getJavaClass());
409
+ }
410
+ }
411
+
412
+ class BuildVersionInfo
413
+ {
414
+ static get javaClassName()
415
+ {
416
+ return "com.aspose.barcode.BuildVersionInfo";
417
+ }
418
+
419
+ static get javaClass()
420
+ {
421
+ let java_class_link = java.import(BuildVersionInfo.javaClassName);
422
+ return java_class_link;
423
+ }
424
+
425
+ static get product()
426
+ {
427
+ return BuildVersionInfo.javaClass.PRODUCT;
428
+ }
429
+
430
+ static get assemblyVersion()
431
+ {
432
+ return BuildVersionInfo.javaClass.ASSEMBLY_VERSION;
433
+ }
434
+
435
+ }
436
+
437
+ module.exports = {
438
+ BaseJavaClass, BarcodeException, Rectangle, Point, License, BuildVersionInfo, isPath, convertResourceToBase64String
439
+ };