aspose.barcode 24.3.0 → 24.5.1

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.
@@ -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-24.3.jar";
7
+ const jar_name_ = "/aspose-barcode-nodejs-24.5.jar";
8
8
  const jar_path_ = __dirname + jar_name_;
9
9
  const fs = require("fs");
10
10
 
@@ -1841,6 +1841,15 @@ class MaxiCodeStructuredCodetext extends MaxiCodeCodetext
1841
1841
  return this.getJavaClass().getPostalCodeSync();
1842
1842
  }
1843
1843
 
1844
+ /**
1845
+ * Identifies the postal code. Must be 9 digits in mode 2 or
1846
+ * 6 alphanumeric symbols in mode 3.
1847
+ */
1848
+ setPostalCode(value)
1849
+ {
1850
+ this.getJavaClass().setPostalCodeSync(value);
1851
+ }
1852
+
1844
1853
  /**
1845
1854
  * Identifies 3 digit country code.
1846
1855
  */
package/lib/Generation.js CHANGED
@@ -859,7 +859,7 @@ class BaseGenerationParameters extends joint.BaseJavaClass
859
859
  */
860
860
  setAutoSizeMode(value)
861
861
  {
862
- this.getJavaClass().setAutoSizeModeSync(value + "");
862
+ this.getJavaClass().setAutoSizeModeSync(value);
863
863
  }
864
864
 
865
865
 
package/lib/Joint.js CHANGED
@@ -1,5 +1,7 @@
1
1
  const java = require('java');
2
2
  const fs = require("fs");
3
+ const URL = require('url');
4
+ const https = require('https');
3
5
 
4
6
 
5
7
  function isPath(image)
@@ -15,19 +17,93 @@ function isPath(image)
15
17
  return false;
16
18
  }
17
19
 
18
- function convertResourceToBase64String(resource)
20
+
21
+ function isValidURL(str) {
22
+ try {
23
+ new URL(str);
24
+ return true;
25
+ } catch (err) {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ function isBase64(str)
19
31
  {
20
- let is_path_to_image = false;
21
- is_path_to_image = fs.existsSync(resource);
32
+ try
33
+ {
34
+ return (Buffer.from(str, 'base64').toString('base64')) === str;
35
+ }
36
+ catch (err)
37
+ {
38
+ return false;
39
+ }
40
+ }
22
41
 
23
- if (is_path_to_image)
42
+ function convertImageResourceToBase64(imageResource)
43
+ {
44
+ if(imageResource === null)
45
+ {
46
+ return null;
47
+ }
48
+ else if ((typeof imageResource === 'string') && (isBase64(imageResource)))
49
+ {
50
+ return imageResource;
51
+ }
52
+ else if (fs.existsSync(imageResource))
24
53
  {
25
- return fs.readFileSync(resource).toString('base64');
54
+ return fs.readFileSync(imageResource).toString('base64');
55
+ }
56
+ throw new BarcodeException("Image is not available or this resouce is not supported!");
57
+ }
58
+
59
+ function convertDecodeTypeToFormattedDecodeType(decodeTypes)
60
+ {
61
+ if (decodeTypes === undefined || decodeTypes == null)
62
+ {
63
+ return [DecodeType.ALL_SUPPORTED_TYPES];
64
+ }
65
+ else
66
+ {
67
+ if(!Array.isArray(decodeTypes))
68
+ decodeTypes = [decodeTypes];
69
+
70
+ for (let i = 0; i < decodeTypes.length; i++)
71
+ {
72
+ if(!Number.isInteger(decodeTypes[i]))
73
+ throw new Error("Unsuported decodeType format");
74
+ }
75
+ return decodeTypes;
76
+ }
77
+ }
78
+
79
+ function convertAreasToStringFormattedAreas(areas) // TODO move to Joint
80
+ {
81
+ let stringFormattedAreas = null;
82
+ if (areas != null)
83
+ {
84
+ stringFormattedAreas = [];
85
+ if(Array.isArray(areas))
86
+ {
87
+ if(!areas.every(area => area === null))
88
+ {
89
+ for(let i = 0; i < areas.length; i++)
90
+ {
91
+ let area = areas[i];
92
+ if (area === null || !(area instanceof Rectangle))
93
+ throw new BarcodeException('All elements of areas should be instances of Rectangle class');
94
+ stringFormattedAreas.push(area.toString());
95
+ }
96
+ }
26
97
  }
27
98
  else
28
99
  {
29
- return resource;
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
+ }
104
+ stringFormattedAreas = stringFormattedAreas.length > 0 ? stringFormattedAreas : null
30
105
  }
106
+ return stringFormattedAreas;
31
107
  }
32
108
 
33
109
  class BaseJavaClass
@@ -484,5 +560,6 @@ class BuildVersionInfo
484
560
  }
485
561
 
486
562
  module.exports = {
487
- BaseJavaClass, BarcodeException, Rectangle, Point, License, BuildVersionInfo, isPath, convertResourceToBase64String
563
+ BaseJavaClass, BarcodeException, Rectangle, Point, License, BuildVersionInfo, isPath, convertImageResourceToBase64,
564
+ convertDecodeTypeToFormattedDecodeType, convertAreasToStringFormattedAreas
488
565
  };
@@ -31,55 +31,21 @@ class BarCodeReader extends joint.BaseJavaClass
31
31
  * @param rectangles array of object by type Rectangle
32
32
  * @param decodeTypes the array of objects by DecodeType
33
33
  */
34
- constructor(image, rectangles, decodeTypes)
34
+ constructor(image, areas, decodeTypes)
35
35
  {
36
- if (image != null)
37
- {
38
- if (joint.isPath(image))
39
- {
40
- image = joint.convertResourceToBase64String(image);
41
- }
42
- }
43
- if (rectangles != null)
44
- {
45
- if (!Array.isArray(rectangles))
46
- {
47
- rectangles = [rectangles];
48
- }
49
- for (let i = 0; i < rectangles.length; i++)
50
- {
51
- if(!(rectangles[i] instanceof Rectangle))
52
- throw new Error("Invalid arguments");
53
- rectangles[i] = rectangles[i].toString();
54
- }
55
- }
56
- if (decodeTypes === undefined || decodeTypes == null)
57
- {
58
- decodeTypes = DecodeType.ALL_SUPPORTED_TYPES
59
- }
60
- if (!Array.isArray(decodeTypes))
61
- {
62
- decodeTypes = [decodeTypes];
63
- }
64
- for (let i = 0; i < decodeTypes.length; i++)
65
- {
66
- decodeTypes[i] = decodeTypes[i] + "";
67
- }
68
36
  try
69
37
  {
38
+ let stringFormattedAreas = joint.convertAreasToStringFormattedAreas(areas);
39
+ let decodeTypesArray = joint.convertDecodeTypeToFormattedDecodeType(decodeTypes);
40
+
41
+ let base64Image = joint.convertImageResourceToBase64(image);
42
+
70
43
  let java_class_link = new java.import(BarCodeReader.javaClassName);
71
- let java_class = null;
72
- if (image == null && rectangles == null && image == null)
73
- {
74
- java_class = new java_class_link();
75
- }
76
- else
77
- {
78
- java_class = new java_class_link(image, rectangles, decodeTypes);
79
- }
44
+ let java_class = new java_class_link(base64Image, stringFormattedAreas, decodeTypesArray);
80
45
  super(java_class);
81
46
  this.init()
82
- } catch (e)
47
+ }
48
+ catch (e)
83
49
  {
84
50
  console.error("Invalid arguments");
85
51
  throw e;
@@ -142,7 +108,7 @@ class BarCodeReader extends joint.BaseJavaClass
142
108
  init()
143
109
  {
144
110
  this.qualitySettings = new QualitySettings(this.getJavaClass().getQualitySettingsSync());
145
- this.barcodeSettings = BarcodeSettings.construct(this.getJavaClass().getBarcodeSettingsSync());
111
+ this.barcodeSettings = new BarcodeSettings(this.getJavaClass().getBarcodeSettingsSync());
146
112
  }
147
113
 
148
114
  /**
@@ -359,38 +325,15 @@ class BarCodeReader extends joint.BaseJavaClass
359
325
  * console.log("BarCode Type: " + result.getCodeTypeName());
360
326
  * console.log("BarCode CodeText: " + result.getCodeText());
361
327
  * });
362
- * @param value The bitmap image for recognition.
328
+ * @param imageResource The image for recognition.
363
329
  * @param areas areas list for recognition
364
330
  * @throws BarcodeException
365
331
  */
366
- setBarCodeImage(image, ...areas)
332
+ setBarCodeImage(imageResource, ...areas)
367
333
  {
368
- image = joint.convertResourceToBase64String(image);
369
- let stringAreas = [];
370
- let isAllRectanglesNotNull = false;
371
- if (!(areas == null) && areas.length > 0)
372
- {
373
- for (let i = 0; i < areas.length; i++)
374
- {
375
- if (!(areas[i] == null))
376
- {
377
- isAllRectanglesNotNull |= true;
378
- stringAreas[i] = areas[i].toString();
379
- }
380
- }
381
- if (!isAllRectanglesNotNull)
382
- {
383
- stringAreas = [];
384
- }
385
- }
386
- if (stringAreas.length == 0)
387
- {
388
- this.getJavaClass().setBarCodeImageSync(image);
389
- }
390
- else
391
- {
392
- this.getJavaClass().setBarCodeImageSync(image, stringAreas);
393
- }
334
+ let base64Image = joint.convertImageResourceToBase64(imageResource);
335
+ let stringFormattedAreas = joint.convertAreasToStringFormattedAreas(areas);
336
+ this.getJavaClass().setBarCodeImageSync(base64Image, stringFormattedAreas);
394
337
  }
395
338
 
396
339
  /**
@@ -423,7 +366,14 @@ class BarCodeReader extends joint.BaseJavaClass
423
366
  */
424
367
  getBarCodeDecodeType()
425
368
  {
426
- return this.getJavaClass().getBarCodeDecodeTypeSync();
369
+ let barcodeTypesArray = [];
370
+ let javaDecodeTypes = this.getJavaClass().getBarCodeDecodeTypeSync();
371
+ for(let i = 0; i < javaDecodeTypes.sizeSync(); i++)
372
+ {
373
+ barcodeTypesArray.push(javaDecodeTypes.getSync(i));
374
+ }
375
+
376
+ return barcodeTypesArray;
427
377
  }
428
378
 
429
379
  /**
@@ -1077,7 +1027,7 @@ class Code128ExtendedParameters extends joint.BaseJavaClass
1077
1027
  let code128DataPortions = [];
1078
1028
  for (let i = 0; i < code128DataPortionsValues.length; i++)
1079
1029
  {
1080
- code128DataPortions[i] = Code128DataPortion.construct(code128DataPortionsValues[i]);
1030
+ code128DataPortions.push(new Code128DataPortion(code128DataPortionsValues[i]));
1081
1031
  }
1082
1032
  return code128DataPortions;
1083
1033
  }
@@ -1592,33 +1542,17 @@ class BarCodeExtendedParameters extends joint.BaseJavaClass
1592
1542
  class QualitySettings extends joint.BaseJavaClass
1593
1543
  {
1594
1544
 
1595
- static get javaClassName()
1545
+ constructor($javaClass)
1596
1546
  {
1597
- return "com.aspose.mw.barcode.recognition.MwQualitySettings";
1598
- }
1599
-
1600
- constructor(qualitySettings)
1601
- {
1602
- super(QualitySettings.initQualitySettings(qualitySettings));
1603
- if (qualitySettings instanceof QualitySettings)
1604
- {
1605
- this.applyAll(qualitySettings);
1606
- }
1547
+ super($javaClass);
1607
1548
  this.init();
1608
1549
  }
1609
1550
 
1610
- static initQualitySettings(qualitySettings)
1551
+ static initQualitySettings()
1611
1552
  {
1612
1553
  let javaClassName = "com.aspose.mw.barcode.recognition.MwQualitySettings";
1613
- if (qualitySettings instanceof QualitySettings || (qualitySettings === null))
1614
- {
1615
- let QualitySettings = java.import(javaClassName);
1616
- return new QualitySettings();
1617
- }
1618
- else
1619
- {
1620
- return qualitySettings;
1621
- }
1554
+ let QualitySettings = java.import(javaClassName);
1555
+ return QualitySettings;
1622
1556
  }
1623
1557
 
1624
1558
  init()
@@ -1633,7 +1567,7 @@ class QualitySettings extends joint.BaseJavaClass
1633
1567
  */
1634
1568
  static getHighPerformance()
1635
1569
  {
1636
- let JavaQualitySettings = java.import(QualitySettings.javaClassName);
1570
+ let JavaQualitySettings = QualitySettings.initQualitySettings();
1637
1571
  return new QualitySettings(JavaQualitySettings.getHighPerformanceSync());
1638
1572
  }
1639
1573
 
@@ -1647,48 +1581,45 @@ class QualitySettings extends joint.BaseJavaClass
1647
1581
  */
1648
1582
  static getNormalQuality()
1649
1583
  {
1650
- let JavaQualitySettings = java.import(QualitySettings.javaClassName);
1584
+ let JavaQualitySettings = QualitySettings.initQualitySettings();
1651
1585
  return new QualitySettings(JavaQualitySettings.getNormalQualitySync());
1652
1586
  }
1653
1587
 
1654
1588
  /**
1655
- * HighQualityDetection recognition quality preset. Same as NormalQuality but with high quality DetectorSettings
1589
+ * HighQuality recognition quality preset. This preset is developed for low quality barcodes.
1656
1590
  *
1657
1591
  * @example
1658
1592
  * let reader = new BarCodeReader("test.png");
1659
- * reader.setQualitySettings(QualitySettings.getHighQualityDetection()); *
1593
+ * reader.setQualitySettings(QualitySettings.getHighQuality());
1660
1594
  */
1661
- static getHighQualityDetection()
1595
+ static getHighQuality()
1662
1596
  {
1663
- let JavaQualitySettings = java.import(QualitySettings.javaClassName);
1664
- return new QualitySettings(JavaQualitySettings.getHighQualityDetectionSync());
1597
+ let JavaQualitySettings = QualitySettings.initQualitySettings();
1598
+ return new QualitySettings(JavaQualitySettings.getHighQualitySync());
1665
1599
  }
1666
1600
 
1667
1601
  /**
1668
- * MaxQualityDetection recognition quality preset. Same as NormalQuality but with highest quality DetectorSettings.<br>
1669
- * Allows to detect diagonal and damaged barcodes.
1602
+ * <p>
1603
+ * MaxQuality recognition quality preset. This preset is developed to recognize all possible barcodes, even incorrect barcodes.
1604
+ * </p><p><hr><blockquote><pre>
1605
+ * This sample shows how to use MaxQuality mode
1606
+ * <pre>
1670
1607
  *
1671
- * @example
1672
- * let reader = new BarCodeReader("test.png");
1673
- * reader.setQualitySettings(QualitySettings.getMaxQualityDetection());
1674
- */
1675
- static getMaxQualityDetection()
1676
- {
1677
- let JavaQualitySettings = java.import(QualitySettings.javaClassName);
1678
- return new QualitySettings(JavaQualitySettings.getMaxQualityDetectionSync());
1679
- }
1680
-
1681
- /**
1682
- * HighQuality recognition quality preset. This preset is developed for low quality barcodes.
1608
+ * $reader = new BarCodeReader("test.png"null, null, DecodeType::CODE_39_EXTENDED, DecodeType::CODE_128);
1609
+ * {
1610
+ * $reader->setQualitySettings(QualitySettings::getMaxQuality());
1611
+ * foreach($reader->readBarCodes() as $result)
1612
+ * echo ($result->getCodeText());
1613
+ * }
1614
+ * </pre>
1615
+ * </pre></blockquote></hr></p>Value:
1616
+ * MaxQuality recognition quality preset.
1683
1617
  *
1684
- * @example
1685
- * let reader = new BarCodeReader("test.png");
1686
- * reader.setQualitySettings(QualitySettings.getHighQuality());
1687
1618
  */
1688
- static getHighQuality()
1619
+ static getMaxQuality()
1689
1620
  {
1690
- let JavaQualitySettings = java.import(QualitySettings.javaClassName);
1691
- return new QualitySettings(JavaQualitySettings.getHighQualitySync());
1621
+ let JavaQualitySettings = QualitySettings.initQualitySettings();
1622
+ return new QualitySettings(JavaQualitySettings.getMaxQualitySync());
1692
1623
  }
1693
1624
 
1694
1625
  /**
@@ -1819,23 +1750,6 @@ class QualitySettings extends joint.BaseJavaClass
1819
1750
  {
1820
1751
  this.getJavaClass().setAllowIncorrectBarcodesSync(value);
1821
1752
  }
1822
-
1823
- /**
1824
- * <p>
1825
- * Function apply all values from Src setting to Dst
1826
- * </p>
1827
- * @param Src source settings
1828
- */
1829
- applyAll(Src)
1830
- {
1831
- this.setXDimension(Src.getXDimension());
1832
- this.setMinimalXDimension(Src.getMinimalXDimension());
1833
- this.setBarcodeQuality(Src.getBarcodeQuality());
1834
- this.setDeconvolution(Src.getDeconvolution());
1835
- this.setInverseImage(Src.getInverseImage());
1836
- this.setComplexBackground(Src.getComplexBackground());
1837
- this.setAllowIncorrectBarcodes(Src.getAllowIncorrectBarcodes());
1838
- }
1839
1753
  }
1840
1754
 
1841
1755
  /**
@@ -1843,30 +1757,17 @@ class QualitySettings extends joint.BaseJavaClass
1843
1757
  */
1844
1758
  class Code128DataPortion extends joint.BaseJavaClass
1845
1759
  {
1846
- static get javaClassName()
1847
- {
1848
- return "com.aspose.mw.barcode.recognition.MwCode128DataPortion";
1849
- }
1850
-
1851
1760
  /**
1852
1761
  * Creates a new instance of the {@code Code128DataPortion} class with start code symbol and decoded codetext.
1853
- *
1854
- * @param code128SubType A start encoding symbol
1855
- * @param data A partial codetext
1856
1762
  */
1857
- constructor(code128SubType, data)
1763
+ constructor(javaclass)
1858
1764
  {
1859
- let java_link = java.import(Code128DataPortion.javaClassName);
1860
- let code128DataPortion = new java_link(code128SubType + "", data);
1861
- super(code128DataPortion);
1862
- this.init();
1765
+ super(javaclass);
1766
+ this.init()
1863
1767
  }
1864
1768
 
1865
- static construct(javaClass)
1769
+ init()
1866
1770
  {
1867
- let code128DataPortion = new Code128DataPortion(0, "");
1868
- code128DataPortion.setJavaClass(javaClass);
1869
- return code128DataPortion;
1870
1771
  }
1871
1772
 
1872
1773
  /**
@@ -1879,16 +1780,6 @@ class Code128DataPortion extends joint.BaseJavaClass
1879
1780
  return this.getJavaClass().getDataSync();
1880
1781
  }
1881
1782
 
1882
- /**
1883
- * Gets the part of code text related to subtype.
1884
- *
1885
- * @return The part of code text related to subtype
1886
- */
1887
- setData(value)
1888
- {
1889
- this.getJavaClass().setDataSync(value);
1890
- }
1891
-
1892
1783
  /**
1893
1784
  * Gets the type of Code128 subset
1894
1785
  *
@@ -1899,20 +1790,6 @@ class Code128DataPortion extends joint.BaseJavaClass
1899
1790
  return this.getJavaClass().getCode128SubTypeSync();
1900
1791
  }
1901
1792
 
1902
- /**
1903
- * Sets the type of Code128 subset
1904
- *
1905
- * @return The type of Code128 subset
1906
- */
1907
- setCode128SubType(value)
1908
- {
1909
- this.getJavaClass().setCode128SubTypeSync(value);
1910
- }
1911
-
1912
- init()
1913
- {
1914
- }
1915
-
1916
1793
  /**
1917
1794
  * Returns a human-readable string representation of this {@code Code128DataPortion}.
1918
1795
  * @return A string that represents this {@code Code128DataPortion}.
@@ -1984,37 +1861,18 @@ class DataBarExtendedParameters extends joint.BaseJavaClass
1984
1861
  */
1985
1862
  class AustraliaPostSettings extends joint.BaseJavaClass
1986
1863
  {
1987
- static get javaClassName()
1988
- {
1989
- return "com.aspose.mw.barcode.recognition.MwAustraliaPostSettings";
1990
- }
1991
-
1992
- init()
1993
- {
1994
- }
1995
1864
 
1996
1865
  /**
1997
1866
  * AustraliaPostSettings constructor
1998
1867
  */
1999
- constructor(settings)
1868
+ constructor(javaclass)
2000
1869
  {
2001
- if (settings != null)
2002
- {
2003
- super(settings.getJavaClass());
2004
- }
2005
- else
2006
- {
2007
- let java_link = java.import(AustraliaPostSettings.javaClassName);
2008
- let australiaPostSettings = new java_link();
2009
- super(australiaPostSettings);
2010
- }
1870
+ super(javaclass);
1871
+ this.init()
2011
1872
  }
2012
1873
 
2013
- static construct(javaClass)
1874
+ init()
2014
1875
  {
2015
- let australiaPostSettings = new AustraliaPostSettings(null);
2016
- australiaPostSettings.setJavaClass(javaClass);
2017
- return australiaPostSettings;
2018
1876
  }
2019
1877
 
2020
1878
  /**
@@ -2091,46 +1949,21 @@ class AustraliaPostSettings extends joint.BaseJavaClass
2091
1949
  */
2092
1950
  class BarcodeSettings extends joint.BaseJavaClass
2093
1951
  {
2094
-
2095
1952
  _australiaPost;
2096
1953
 
2097
- static get javaClassName()
2098
- {
2099
- return "com.aspose.mw.barcode.recognition.MwBarcodeSettings";
2100
- }
2101
-
2102
- /**
2103
- * BarcodeSettings copy constructor
2104
- * @param settings The source of the data
2105
- */
2106
- constructor(settings)
2107
- {
2108
- if (settings != null)
2109
- {
2110
- super(settings.getJavaClass());
2111
- }
2112
- else
2113
- {
2114
- let java_link = java.import(BarcodeSettings.javaClassName);
2115
- let barcodeSettings = new java_link();
2116
- super(barcodeSettings);
2117
- }
2118
- }
2119
-
2120
1954
  /**
2121
1955
  * BarcodeSettings copy constructor
2122
1956
  * @param settings The source of the data
2123
1957
  */
2124
- static construct(javaClass)
1958
+ constructor(javaclass)
2125
1959
  {
2126
- let barcodeSettings = new BarcodeSettings(null);
2127
- barcodeSettings.setJavaClass(javaClass);
2128
- return barcodeSettings;
1960
+ super(javaclass);
1961
+ this.init()
2129
1962
  }
2130
1963
 
2131
1964
  init()
2132
1965
  {
2133
- this._australiaPost = AustraliaPostSettings.construct(this.getJavaClass().getAustraliaPostSync());
1966
+ this._australiaPost = new AustraliaPostSettings(this.getJavaClass().getAustraliaPostSync());
2134
1967
  }
2135
1968
 
2136
1969
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aspose.barcode",
3
- "version": "24.3.0",
3
+ "version": "24.5.1",
4
4
  "description": "barcode generation and recognition component",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"