aspose.barcode 25.9.0 → 25.11.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/lib/AsposeBarcode.js
CHANGED
|
@@ -4,7 +4,7 @@ const joint_ = require('./Joint');
|
|
|
4
4
|
const complexbarcode_ = require("./ComplexBarcode");
|
|
5
5
|
const generation_ = require("./Generation");
|
|
6
6
|
const recognition_ = require("./Recognition");
|
|
7
|
-
const jar_name_ = "/aspose-barcode-nodejs-25.
|
|
7
|
+
const jar_name_ = "/aspose-barcode-nodejs-25.11.jar";
|
|
8
8
|
const jar_path_ = __dirname + jar_name_;
|
|
9
9
|
const fs = require("fs");
|
|
10
10
|
|
package/lib/Generation.js
CHANGED
|
@@ -95,7 +95,7 @@ class BarcodeGenerator extends joint.BaseJavaClass
|
|
|
95
95
|
generateBarCodeImage(format)
|
|
96
96
|
{
|
|
97
97
|
try {
|
|
98
|
-
let base64Image = this.getJavaClass().
|
|
98
|
+
let base64Image = Buffer.from(this.getJavaClass().generateBarCodeImageBytesSync(format)).toString('base64');
|
|
99
99
|
return (base64Image);
|
|
100
100
|
} catch (e) {
|
|
101
101
|
throw new joint.BarcodeException(e)
|
package/lib/Joint.js
CHANGED
|
@@ -2,6 +2,7 @@ const java = require('java');
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const URL = require('url');
|
|
4
4
|
const https = require('https');
|
|
5
|
+
const {Buffer} = require("buffer");
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
function isPath(image)
|
|
@@ -41,7 +42,7 @@ function isBase64(str)
|
|
|
41
42
|
|
|
42
43
|
function convertImageResourceToBase64(imageResource)
|
|
43
44
|
{
|
|
44
|
-
if(imageResource === null)
|
|
45
|
+
if(imageResource === undefined || imageResource === null)
|
|
45
46
|
{
|
|
46
47
|
return null;
|
|
47
48
|
}
|
|
@@ -56,54 +57,90 @@ function convertImageResourceToBase64(imageResource)
|
|
|
56
57
|
throw new BarcodeException("Image is not available or this resouce is not supported!");
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
function
|
|
60
|
+
function convertResourceToInputStream(imageResource)
|
|
60
61
|
{
|
|
61
|
-
if
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
else
|
|
66
|
-
{
|
|
67
|
-
if(!Array.isArray(decodeTypes))
|
|
68
|
-
decodeTypes = [decodeTypes];
|
|
62
|
+
if(imageResource === undefined || imageResource === null)
|
|
63
|
+
return null;
|
|
64
|
+
let base64Image = convertImageResourceToBase64(imageResource);
|
|
65
|
+
const buf = Buffer.from(base64Image, 'base64');
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const jsByteArray = Array.from(buf);
|
|
68
|
+
const jByteArray = java.newArray('byte', jsByteArray);
|
|
69
|
+
|
|
70
|
+
const JByteArrayInputStream = java.import('java.io.ByteArrayInputStream');
|
|
71
|
+
return new JByteArrayInputStream(jByteArray);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function convertToDecodeTypeJava(decode_types)
|
|
75
|
+
{
|
|
76
|
+
if (decode_types === undefined || decode_types === null)
|
|
77
|
+
return null;
|
|
78
|
+
if(Array.isArray(decode_types) !== true)
|
|
79
|
+
decode_types = [decode_types]
|
|
80
|
+
const JBaseDecodeType = java.import('com.aspose.barcode.barcoderecognition.BaseDecodeType');
|
|
81
|
+
const JDecodeType = java.import('com.aspose.barcode.barcoderecognition.DecodeType');
|
|
82
|
+
// 1) Fetch all supported individual decode types from Java
|
|
83
|
+
// Expecting BaseDecodeType[] with getTypeIndex()
|
|
84
|
+
const all_supported = JDecodeType.getAllSupportedTypesArraySync();
|
|
85
|
+
|
|
86
|
+
// 2) Build a lookup: typeIndex (short/int) -> BaseDecodeType instance
|
|
87
|
+
const dict = new Map();
|
|
88
|
+
for (let i = 0; i < all_supported.length; i++) {
|
|
89
|
+
const idx = all_supported[i].getTypeIndexSync();
|
|
90
|
+
dict.set(idx, all_supported[i]);
|
|
74
91
|
}
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
|
|
93
|
+
// 3) Special grouped constants, keyed by the same numeric codes as in Python
|
|
94
|
+
const specials = new Map([
|
|
95
|
+
[97, JDecodeType.TYPES_1DSync ? JDecodeType.TYPES_1DSync() : JDecodeType.TYPES_1D], // TYPES_1D
|
|
96
|
+
[98, JDecodeType.TYPES_2DSync ? JDecodeType.TYPES_2DSync() : JDecodeType.TYPES_2D], // TYPES_2D
|
|
97
|
+
[95, JDecodeType.POSTAL_TYPESSync ? JDecodeType.POSTAL_TYPESSync() : JDecodeType.POSTAL_TYPES],
|
|
98
|
+
[96, JDecodeType.MOST_COMMON_TYPESSync ? JDecodeType.MOST_COMMON_TYPESSync() : JDecodeType.MOST_COMMON_TYPES],
|
|
99
|
+
[99, JDecodeType.ALL_SUPPORTED_TYPESSync ? JDecodeType.ALL_SUPPORTED_TYPESSync() : JDecodeType.ALL_SUPPORTED_TYPES],
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
// 4) Resolve requested items into Java BaseDecodeType instances
|
|
103
|
+
let resolved = [];
|
|
104
|
+
for (let i = 0; i < decode_types.length; i++) {
|
|
105
|
+
const item = decode_types[i];
|
|
106
|
+
const idx = typeof item === 'number' ? item : item?.value;
|
|
107
|
+
|
|
108
|
+
if (dict.has(idx)) {
|
|
109
|
+
resolved.push(dict.get(idx));
|
|
110
|
+
} else if (specials.has(idx)) {
|
|
111
|
+
resolved.push(specials.get(idx));
|
|
112
|
+
} else {
|
|
113
|
+
throw new Error('Unknown decode type');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return java.newArray('com.aspose.barcode.barcoderecognition.BaseDecodeType', resolved);
|
|
77
117
|
}
|
|
78
118
|
|
|
79
|
-
function
|
|
119
|
+
function convertAreasToJavaAreas(areas) // TODO move to Joint
|
|
80
120
|
{
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
const JavaRectangleClassName = 'java.awt.Rectangle'
|
|
122
|
+
const JavaRectangle = java.import(JavaRectangleClassName);
|
|
123
|
+
let javaAreas = null;
|
|
124
|
+
if (areas !== undefined && areas != null)
|
|
83
125
|
{
|
|
84
|
-
|
|
85
|
-
if(Array.isArray(areas))
|
|
126
|
+
javaAreas = [];
|
|
127
|
+
if(!Array.isArray(areas))
|
|
86
128
|
{
|
|
87
|
-
|
|
129
|
+
areas = [areas];
|
|
130
|
+
}
|
|
131
|
+
if (!areas.every(area => area === null))
|
|
132
|
+
{
|
|
133
|
+
for (let i = 0; i < areas.length; i++)
|
|
88
134
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw new BarcodeException('All elements of areas should be instances of Rectangle class');
|
|
94
|
-
stringFormattedAreas.push(area.toString());
|
|
95
|
-
}
|
|
135
|
+
let area = areas[i];
|
|
136
|
+
if (area === null || !(area instanceof Rectangle))
|
|
137
|
+
throw new BarcodeException('All elements of areas should be instances of Rectangle class');
|
|
138
|
+
javaAreas.push(new JavaRectangle(area.getX(), area.getY(), area.getWidth(), area.getHeight()));
|
|
96
139
|
}
|
|
97
|
-
}
|
|
98
|
-
else
|
|
99
|
-
{
|
|
100
|
-
if (!(areas instanceof Rectangle))
|
|
101
|
-
throw new BarcodeException('All elements of areas should be instances of Rectangle class');
|
|
102
|
-
stringFormattedAreas.push(areas.toString());
|
|
103
140
|
}
|
|
104
|
-
|
|
141
|
+
return java.newArray(JavaRectangleClassName, javaAreas);
|
|
105
142
|
}
|
|
106
|
-
return
|
|
143
|
+
return null;
|
|
107
144
|
}
|
|
108
145
|
|
|
109
146
|
class BaseJavaClass
|
|
@@ -548,5 +585,5 @@ class BuildVersionInfo
|
|
|
548
585
|
|
|
549
586
|
module.exports = {
|
|
550
587
|
BaseJavaClass, BarcodeException, Rectangle, Point, License, BuildVersionInfo, isPath, convertImageResourceToBase64,
|
|
551
|
-
|
|
588
|
+
convertToDecodeTypeJava, convertAreasToJavaAreas, convertResourceToInputStream
|
|
552
589
|
};
|
package/lib/Recognition.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require("fs");
|
|
|
2
2
|
const java = require('java');
|
|
3
3
|
const joint = require("./Joint");
|
|
4
4
|
const {Rectangle} = require("./Joint");
|
|
5
|
+
const {Buffer} = require("buffer");
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes.
|
|
@@ -30,21 +31,20 @@ class BarCodeReader extends joint.BaseJavaClass
|
|
|
30
31
|
/**
|
|
31
32
|
* Initializes a new instance of the BarCodeReader<br>
|
|
32
33
|
* @param image encoded as base64 string or path to image
|
|
33
|
-
* @param
|
|
34
|
+
* @param areas array of object by type Rectangle
|
|
34
35
|
* @param decodeTypes the array of objects by DecodeType
|
|
35
36
|
*/
|
|
36
37
|
constructor(image, areas, decodeTypes)
|
|
37
38
|
{
|
|
38
39
|
try
|
|
39
40
|
{
|
|
40
|
-
let
|
|
41
|
-
let
|
|
41
|
+
let javaInputStream = joint.convertResourceToInputStream(image);
|
|
42
|
+
let javaAreas = joint.convertAreasToJavaAreas(areas);
|
|
43
|
+
let decodeTypesArray = joint.convertToDecodeTypeJava(decodeTypes);
|
|
42
44
|
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let java_class = new java_class_link(base64Image, stringFormattedAreas, decodeTypesArray);
|
|
47
|
-
super(java_class);
|
|
45
|
+
let JavaBarCodeReaderClass = new java.import(BarCodeReader.javaClassName);
|
|
46
|
+
let javaBarCodeReader = javaAreas === null ? ((javaInputStream === null && decodeTypesArray === null) ? new JavaBarCodeReaderClass() : new JavaBarCodeReaderClass(javaInputStream, decodeTypesArray)) : new JavaBarCodeReaderClass(javaInputStream, javaAreas, decodeTypesArray);
|
|
47
|
+
super(javaBarCodeReader);
|
|
48
48
|
this.init()
|
|
49
49
|
}
|
|
50
50
|
catch (e)
|
|
@@ -354,9 +354,9 @@ class BarCodeReader extends joint.BaseJavaClass
|
|
|
354
354
|
*/
|
|
355
355
|
setBarCodeImage(imageResource, ...areas)
|
|
356
356
|
{
|
|
357
|
-
let
|
|
358
|
-
let
|
|
359
|
-
this.getJavaClass().setBarCodeImageSync(
|
|
357
|
+
let javaInputStream = joint.convertResourceToInputStream(imageResource);
|
|
358
|
+
let javaAreas = joint.convertAreasToJavaAreas(areas);
|
|
359
|
+
this.getJavaClass().setBarCodeImageSync(javaInputStream, javaAreas);
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
/**
|
|
@@ -378,12 +378,8 @@ class BarCodeReader extends joint.BaseJavaClass
|
|
|
378
378
|
*/
|
|
379
379
|
setBarCodeReadType(...types)
|
|
380
380
|
{
|
|
381
|
-
let
|
|
382
|
-
|
|
383
|
-
{
|
|
384
|
-
javaReadTypes.push(types[i]);
|
|
385
|
-
}
|
|
386
|
-
this.getJavaClass().setBarCodeReadTypeSync(javaReadTypes);
|
|
381
|
+
let decodeTypesArray = joint.convertToDecodeTypeJava(types);
|
|
382
|
+
this.getJavaClass().setBarCodeReadTypeSync(decodeTypesArray);
|
|
387
383
|
}
|
|
388
384
|
|
|
389
385
|
/**
|
|
@@ -1227,8 +1223,8 @@ class BarCodeResult extends joint.BaseJavaClass
|
|
|
1227
1223
|
*/
|
|
1228
1224
|
getCodeBytes()
|
|
1229
1225
|
{
|
|
1230
|
-
let
|
|
1231
|
-
return
|
|
1226
|
+
let javaArray = this.getJavaClass().getCodeBytesSync();
|
|
1227
|
+
return Array.from(javaArray);
|
|
1232
1228
|
}
|
|
1233
1229
|
|
|
1234
1230
|
/**
|
|
Binary file
|