33
33
import { bwipp_auspost , bwipp_azteccode , bwipp_azteccodecompact , bwipp_aztecrune , bwipp_bc412 , bwipp_channelcode , bwipp_codablockf , bwipp_code11 , bwipp_code128 , bwipp_code16k , bwipp_code2of5 , bwipp_code32 , bwipp_code39 , bwipp_code39ext , bwipp_code49 , bwipp_code93 , bwipp_code93ext , bwipp_codeone , bwipp_coop2of5 , bwipp_daft , bwipp_databarexpanded , bwipp_databarexpandedcomposite , bwipp_databarexpandedstacked , bwipp_databarexpandedstackedcomposite , bwipp_databarlimited , bwipp_databarlimitedcomposite , bwipp_databaromni , bwipp_databaromnicomposite , bwipp_databarstacked , bwipp_databarstackedcomposite , bwipp_databarstackedomni , bwipp_databarstackedomnicomposite , bwipp_databartruncated , bwipp_databartruncatedcomposite , bwipp_datalogic2of5 , bwipp_datamatrix , bwipp_datamatrixrectangular , bwipp_datamatrixrectangularextension , bwipp_dotcode , bwipp_ean13 , bwipp_ean13composite , bwipp_ean14 , bwipp_ean2 , bwipp_ean5 , bwipp_ean8 , bwipp_ean8composite , bwipp_flattermarken , bwipp_gs1_128 , bwipp_gs1_128composite , bwipp_gs1_cc , bwipp_gs1datamatrix , bwipp_gs1datamatrixrectangular , bwipp_gs1dldatamatrix , bwipp_gs1dlqrcode , bwipp_gs1dotcode , bwipp_gs1northamericancoupon , bwipp_gs1qrcode , bwipp_hanxin , bwipp_hibcazteccode , bwipp_hibccodablockf , bwipp_hibccode128 , bwipp_hibccode39 , bwipp_hibcdatamatrix , bwipp_hibcdatamatrixrectangular , bwipp_hibcmicropdf417 , bwipp_hibcpdf417 , bwipp_hibcqrcode , bwipp_iata2of5 , bwipp_identcode , bwipp_industrial2of5 , bwipp_interleaved2of5 , bwipp_isbn , bwipp_ismn , bwipp_issn , bwipp_itf14 , bwipp_jabcode , bwipp_japanpost , bwipp_kix , bwipp_leitcode , bwipp_mailmark , bwipp_mands , bwipp_matrix2of5 , bwipp_maxicode , bwipp_micropdf417 , bwipp_microqrcode , bwipp_msi , bwipp_onecode , bwipp_pdf417 , bwipp_pdf417compact , bwipp_pharmacode , bwipp_pharmacode2 , bwipp_planet , bwipp_plessey , bwipp_posicode , bwipp_postnet , bwipp_pzn , bwipp_qrcode , bwipp_rationalizedCodabar , bwipp_raw , bwipp_rectangularmicroqrcode , bwipp_royalmail , bwipp_sscc18 , bwipp_swissqrcode , bwipp_symbol , bwipp_telepen , bwipp_telepennumeric , bwipp_ultracode , bwipp_upca , bwipp_upcacomposite , bwipp_upce , bwipp_upcecomposite , bwipp_lookup , bwipp_encode , BWIPP_VERSION } from './bwipp.mjs' ;
34
34
35
35
// exports.js
36
- const BWIPJS_VERSION = '4.3.0 (2024-03-12 )' ;
36
+ const BWIPJS_VERSION = '4.3.1 (2024-03-16 )' ;
37
37
38
38
39
39
// bwipjs.toSVG(options)
@@ -338,7 +338,7 @@ BWIPJS.prototype.restore = function() {
338
338
// coordinates corresponding to the current point according to the current
339
339
// value of the CTM. Thus, if a current point is set and then the CTM is
340
340
// changed, the coordinates returned by currentpoint will be different
341
- // from those that were originally specified for the point.
341
+ // from those that were originally specified for the point.
342
342
BWIPJS . prototype . currpos = function ( ) {
343
343
return { x :( this . g_posx - this . g_tdx ) / this . g_tsx ,
344
344
y :( this . g_posy - this . g_tdy ) / this . g_tsy
@@ -392,7 +392,7 @@ BWIPJS.prototype.setcolor = function(s) {
392
392
return ;
393
393
}
394
394
if ( ! / ^ (?: # ? [ 0 - 9 a - f A - F ] { 3 } (?: [ 0 - 9 a - f A - F ] { 3 } ) ? | [ 0 - 9 a - f A - F ] { 8 } ) $ / . test ( s ) ) {
395
- throw new Error ( 'bwip-js: invalid color: ' + s ) ;
395
+ throw new Error ( 'bwip-js: invalid color: ' + s ) ;
396
396
}
397
397
if ( s [ 0 ] == '#' ) {
398
398
s = s . substr ( 1 ) ;
@@ -836,9 +836,9 @@ BWIPJS.prototype.maxicode = function(pix) {
836
836
y *= tsy * 3 ;
837
837
y += tsy * 2 - h / 2 ;
838
838
y = y | 0 ;
839
-
839
+
840
840
// Build bottom up so the drawing is top-down.
841
- var pts = [ [ x - 0.5 , y -- ] ] ;
841
+ var pts = [ [ x - 0.5 , y -- ] ] ;
842
842
y -= qh - 1 ;
843
843
pts . push ( [ x - 1 - w2 , y -- ] ) ;
844
844
y -= vh ;
@@ -1117,7 +1117,7 @@ function DrawingBuiltin() {
1117
1117
1118
1118
// Polygons are used to draw the connected regions in a 2d barcode.
1119
1119
// These will always be unstroked, filled, orthogonal shapes.
1120
- //
1120
+ //
1121
1121
// You will see a series of polygon() calls, followed by a fill().
1122
1122
polygon : function ( pts ) {
1123
1123
var npts = pts . length ;
@@ -1410,7 +1410,7 @@ function DrawingBuiltin() {
1410
1410
for ( var y = left . min , max = left . length - 1 ; y <= max ; y ++ ) {
1411
1411
addPoint ( left [ y ] , y ) ;
1412
1412
}
1413
- // The points we calculated are "inside". The fill algorithm excludes
1413
+ // The points we calculated are "inside". The fill algorithm excludes
1414
1414
// right edges, so +1 on each x.
1415
1415
for ( var y = right . min , max = right . length - 1 ; y <= max ; y ++ ) {
1416
1416
addPoint ( right [ y ] + 1 , y ) ;
@@ -1448,7 +1448,7 @@ function DrawingBuiltin() {
1448
1448
for ( var n = 0 , npts = pts . length ; n < npts ; n ++ ) {
1449
1449
var xn = pts [ n ] ;
1450
1450
if ( xn > x ) {
1451
- return ! wn ;
1451
+ return ! wn ;
1452
1452
} else if ( xn == x ) {
1453
1453
return wn ;
1454
1454
}
@@ -1524,15 +1524,19 @@ function DrawingSVG() {
1524
1524
var width = 0 ;
1525
1525
var ascent = 0 ;
1526
1526
var descent = 0 ;
1527
- for ( var i = 0 ; i < str . length ; i ++ ) {
1527
+ for ( var i = 0 , l = str . length ; i < l ; i ++ ) {
1528
1528
var ch = str . charCodeAt ( i ) ;
1529
- var glyph = FontLib . getpaths ( fontid , ch , fwidth , fheight ) ;
1529
+ var glyph = FontLib . getglyph ( fontid , ch , fwidth , fheight ) ;
1530
1530
if ( ! glyph ) {
1531
1531
continue ;
1532
1532
}
1533
- ascent = Math . max ( ascent , glyph . ascent ) ;
1534
- descent = Math . max ( descent , - glyph . descent ) ;
1535
- width += glyph . advance ;
1533
+ ascent = Math . max ( ascent , glyph . top ) ;
1534
+ descent = Math . max ( descent , glyph . height - glyph . top ) ;
1535
+ if ( i == l - 1 ) {
1536
+ width += glyph . left + glyph . width ;
1537
+ } else {
1538
+ width += glyph . advance ;
1539
+ }
1536
1540
}
1537
1541
return { width, ascent, descent } ;
1538
1542
} ,
@@ -1592,6 +1596,12 @@ function DrawingSVG() {
1592
1596
y1 += 0.5 ;
1593
1597
}
1594
1598
}
1599
+ // The svg path does not include the start pixel, but the bwip-js drawing does.
1600
+ if ( x0 == x1 ) {
1601
+ y0 ++ ;
1602
+ } else if ( y0 == y1 ) {
1603
+ x0 ++ ;
1604
+ }
1595
1605
1596
1606
// Group together all lines of the same width and emit as single paths.
1597
1607
// Dramatically reduces resulting text size.
@@ -1720,7 +1730,9 @@ function DrawingSVG() {
1720
1730
// Close the shape
1721
1731
path += 'Z' ;
1722
1732
}
1723
- x += glyph . advance + dx ;
1733
+ // getglyph() provides slightly different metrics than getpaths(). Keep
1734
+ // it consistent with the built-in drawing.
1735
+ x += FontLib . getglyph ( fontid , ch , fwidth , fheight ) . advance + dx ;
1724
1736
}
1725
1737
if ( path ) {
1726
1738
svg += '<path d="' + path + '" fill="#' + rgb + '" />\n' ;
@@ -1837,7 +1849,7 @@ var FontLib = (function() {
1837
1849
}
1838
1850
1839
1851
// In the cache?
1840
- var cachekey = '' + fontid + 'c' + charcode + 'w' + width + 'h' + height ;
1852
+ var cachekey = '' + fontid + 'c' + charcode + 'w' + width + 'h' + height ;
1841
1853
var glyph = glyphcache [ cachekey ] ;
1842
1854
if ( glyph ) {
1843
1855
// Unthread from the MRU
@@ -1850,7 +1862,7 @@ var FontLib = (function() {
1850
1862
glyph . next = sntl . next ;
1851
1863
glyph . prev = sntl ;
1852
1864
sntl . next = glyph ;
1853
-
1865
+
1854
1866
return glyph ;
1855
1867
}
1856
1868
@@ -1859,7 +1871,7 @@ var FontLib = (function() {
1859
1871
height * font . bwipjs_multy / 100 ) ||
1860
1872
STBTT . GetGlyph ( font , 0 , width * font . bwipjs_multx / 100 ,
1861
1873
height * font . bwipjs_multy / 100 ) ;
1862
-
1874
+
1863
1875
glyph . bytes = glyph . pixels ;
1864
1876
glyph . cachekey = cachekey ;
1865
1877
glyph . offset = 0 ;
@@ -1928,7 +1940,6 @@ var FontLib = (function() {
1928
1940
function LoadFont ( ) {
1929
1941
return FontLib . loadFont . apply ( FontLib , Array . prototype . slice . call ( arguments ) ) ;
1930
1942
}
1931
-
1932
1943
// bwip-js/stb_trutype.js
1933
1944
//
1934
1945
// JavaScript implementation of stb_truetype.h @ https://github.com/nothings/stb.
@@ -3876,7 +3887,7 @@ function toUint8Array(data) {
3876
3887
}
3877
3888
throw new ReferenceError ( "data must be a binary or base64 encoded string or Uint8Array" ) ;
3878
3889
}
3879
- toUint8Array . b64map = ( function ( ) {
3890
+ toUint8Array . b64map = ( function ( ) {
3880
3891
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ;
3881
3892
var map = { } ;
3882
3893
for ( var i = 0 ; i < 64 ; i ++ ) {
0 commit comments