@reportman/engine 0.0.0-stage → 4.1.0-alpha.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.
Files changed (252) hide show
  1. package/LICENSE +373 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/data/columns.d.ts +50 -0
  4. package/dist/data/columns.d.ts.map +1 -0
  5. package/dist/data/columns.js +385 -0
  6. package/dist/data/columns.js.map +1 -0
  7. package/dist/data/databaseinfo.d.ts +41 -0
  8. package/dist/data/databaseinfo.d.ts.map +1 -0
  9. package/dist/data/databaseinfo.js +145 -0
  10. package/dist/data/databaseinfo.js.map +1 -0
  11. package/dist/data/datainfo.d.ts +82 -0
  12. package/dist/data/datainfo.d.ts.map +1 -0
  13. package/dist/data/datainfo.js +449 -0
  14. package/dist/data/datainfo.js.map +1 -0
  15. package/dist/data/errors.d.ts +8 -0
  16. package/dist/data/errors.d.ts.map +1 -0
  17. package/dist/data/errors.js +14 -0
  18. package/dist/data/errors.js.map +1 -0
  19. package/dist/data/host.d.ts +132 -0
  20. package/dist/data/host.d.ts.map +1 -0
  21. package/dist/data/host.js +108 -0
  22. package/dist/data/host.js.map +1 -0
  23. package/dist/data/op.d.ts +21 -0
  24. package/dist/data/op.d.ts.map +1 -0
  25. package/dist/data/op.js +97 -0
  26. package/dist/data/op.js.map +1 -0
  27. package/dist/data/reportdataset.d.ts +116 -0
  28. package/dist/data/reportdataset.d.ts.map +1 -0
  29. package/dist/data/reportdataset.js +396 -0
  30. package/dist/data/reportdataset.js.map +1 -0
  31. package/dist/data/transfer.d.ts +46 -0
  32. package/dist/data/transfer.d.ts.map +1 -0
  33. package/dist/data/transfer.js +100 -0
  34. package/dist/data/transfer.js.map +1 -0
  35. package/dist/data/union.d.ts +88 -0
  36. package/dist/data/union.d.ts.map +1 -0
  37. package/dist/data/union.js +733 -0
  38. package/dist/data/union.js.map +1 -0
  39. package/dist/eval/chinesetables.d.ts +5 -0
  40. package/dist/eval/chinesetables.d.ts.map +1 -0
  41. package/dist/eval/chinesetables.js +8 -0
  42. package/dist/eval/chinesetables.js.map +1 -0
  43. package/dist/eval/evaluator.d.ts +100 -0
  44. package/dist/eval/evaluator.d.ts.map +1 -0
  45. package/dist/eval/evaluator.js +667 -0
  46. package/dist/eval/evaluator.js.map +1 -0
  47. package/dist/eval/exception.d.ts +9 -0
  48. package/dist/eval/exception.d.ts.map +1 -0
  49. package/dist/eval/exception.js +15 -0
  50. package/dist/eval/exception.js.map +1 -0
  51. package/dist/eval/fields.d.ts +60 -0
  52. package/dist/eval/fields.d.ts.map +1 -0
  53. package/dist/eval/fields.js +104 -0
  54. package/dist/eval/fields.js.map +1 -0
  55. package/dist/eval/functions.d.ts +27 -0
  56. package/dist/eval/functions.d.ts.map +1 -0
  57. package/dist/eval/functions.js +810 -0
  58. package/dist/eval/functions.js.map +1 -0
  59. package/dist/eval/identifiers.d.ts +100 -0
  60. package/dist/eval/identifiers.d.ts.map +1 -0
  61. package/dist/eval/identifiers.js +195 -0
  62. package/dist/eval/identifiers.js.map +1 -0
  63. package/dist/eval/parser.d.ts +47 -0
  64. package/dist/eval/parser.d.ts.map +1 -0
  65. package/dist/eval/parser.js +336 -0
  66. package/dist/eval/parser.js.map +1 -0
  67. package/dist/index.d.ts +52 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +42 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/params/param.d.ts +92 -0
  72. package/dist/params/param.d.ts.map +1 -0
  73. package/dist/params/param.js +358 -0
  74. package/dist/params/param.js.map +1 -0
  75. package/dist/params/parameters.d.ts +87 -0
  76. package/dist/params/parameters.d.ts.map +1 -0
  77. package/dist/params/parameters.js +499 -0
  78. package/dist/params/parameters.js.map +1 -0
  79. package/dist/report/barcode/barcodeitem.d.ts +76 -0
  80. package/dist/report/barcode/barcodeitem.d.ts.map +1 -0
  81. package/dist/report/barcode/barcodeitem.js +864 -0
  82. package/dist/report/barcode/barcodeitem.js.map +1 -0
  83. package/dist/report/barcode/code128.d.ts +18 -0
  84. package/dist/report/barcode/code128.d.ts.map +1 -0
  85. package/dist/report/barcode/code128.js +187 -0
  86. package/dist/report/barcode/code128.js.map +1 -0
  87. package/dist/report/barcode/netutil.d.ts +30 -0
  88. package/dist/report/barcode/netutil.d.ts.map +1 -0
  89. package/dist/report/barcode/netutil.js +65 -0
  90. package/dist/report/barcode/netutil.js.map +1 -0
  91. package/dist/report/barcode/pdf417.d.ts +17 -0
  92. package/dist/report/barcode/pdf417.d.ts.map +1 -0
  93. package/dist/report/barcode/pdf417.js +782 -0
  94. package/dist/report/barcode/pdf417.js.map +1 -0
  95. package/dist/report/barcode/pdf417tables.d.ts +11 -0
  96. package/dist/report/barcode/pdf417tables.d.ts.map +1 -0
  97. package/dist/report/barcode/pdf417tables.js +880 -0
  98. package/dist/report/barcode/pdf417tables.js.map +1 -0
  99. package/dist/report/barcode/qrcode.d.ts +14 -0
  100. package/dist/report/barcode/qrcode.d.ts.map +1 -0
  101. package/dist/report/barcode/qrcode.js +214 -0
  102. package/dist/report/barcode/qrcode.js.map +1 -0
  103. package/dist/report/barcode/zxingwidth.d.ts +4 -0
  104. package/dist/report/barcode/zxingwidth.d.ts.map +1 -0
  105. package/dist/report/barcode/zxingwidth.js +247 -0
  106. package/dist/report/barcode/zxingwidth.js.map +1 -0
  107. package/dist/report/chart/chartidens.d.ts +70 -0
  108. package/dist/report/chart/chartidens.d.ts.map +1 -0
  109. package/dist/report/chart/chartidens.js +162 -0
  110. package/dist/report/chart/chartidens.js.map +1 -0
  111. package/dist/report/chart/chartitem.d.ts +110 -0
  112. package/dist/report/chart/chartitem.d.ts.map +1 -0
  113. package/dist/report/chart/chartitem.js +403 -0
  114. package/dist/report/chart/chartitem.js.map +1 -0
  115. package/dist/report/chart/series.d.ts +65 -0
  116. package/dist/report/chart/series.d.ts.map +1 -0
  117. package/dist/report/chart/series.js +74 -0
  118. package/dist/report/chart/series.js.map +1 -0
  119. package/dist/report/chart/vectorchart.d.ts +18 -0
  120. package/dist/report/chart/vectorchart.d.ts.map +1 -0
  121. package/dist/report/chart/vectorchart.js +356 -0
  122. package/dist/report/chart/vectorchart.js.map +1 -0
  123. package/dist/report/convert.d.ts +4 -0
  124. package/dist/report/convert.d.ts.map +1 -0
  125. package/dist/report/convert.js +162 -0
  126. package/dist/report/convert.js.map +1 -0
  127. package/dist/report/errors.d.ts +13 -0
  128. package/dist/report/errors.d.ts.map +1 -0
  129. package/dist/report/errors.js +20 -0
  130. package/dist/report/errors.js.map +1 -0
  131. package/dist/report/identifiers.d.ts +91 -0
  132. package/dist/report/identifiers.d.ts.map +1 -0
  133. package/dist/report/identifiers.js +404 -0
  134. package/dist/report/identifiers.js.map +1 -0
  135. package/dist/report/imageitem.d.ts +66 -0
  136. package/dist/report/imageitem.d.ts.map +1 -0
  137. package/dist/report/imageitem.js +190 -0
  138. package/dist/report/imageitem.js.map +1 -0
  139. package/dist/report/items.d.ts +219 -0
  140. package/dist/report/items.d.ts.map +1 -0
  141. package/dist/report/items.js +1015 -0
  142. package/dist/report/items.js.map +1 -0
  143. package/dist/report/report.d.ts +221 -0
  144. package/dist/report/report.d.ts.map +1 -0
  145. package/dist/report/report.js +1974 -0
  146. package/dist/report/report.js.map +1 -0
  147. package/dist/report/run.d.ts +87 -0
  148. package/dist/report/run.d.ts.map +1 -0
  149. package/dist/report/run.js +121 -0
  150. package/dist/report/run.js.map +1 -0
  151. package/dist/report/section.d.ts +86 -0
  152. package/dist/report/section.d.ts.map +1 -0
  153. package/dist/report/section.js +325 -0
  154. package/dist/report/section.js.map +1 -0
  155. package/dist/report/subreport.d.ts +49 -0
  156. package/dist/report/subreport.d.ts.map +1 -0
  157. package/dist/report/subreport.js +220 -0
  158. package/dist/report/subreport.js.map +1 -0
  159. package/dist/util/base64.d.ts +9 -0
  160. package/dist/util/base64.d.ts.map +1 -0
  161. package/dist/util/base64.js +60 -0
  162. package/dist/util/base64.js.map +1 -0
  163. package/dist/util/chars.d.ts +45 -0
  164. package/dist/util/chars.d.ts.map +1 -0
  165. package/dist/util/chars.js +194 -0
  166. package/dist/util/chars.js.map +1 -0
  167. package/dist/util/compositeformat.d.ts +3 -0
  168. package/dist/util/compositeformat.d.ts.map +1 -0
  169. package/dist/util/compositeformat.js +99 -0
  170. package/dist/util/compositeformat.js.map +1 -0
  171. package/dist/util/culture.d.ts +84 -0
  172. package/dist/util/culture.d.ts.map +1 -0
  173. package/dist/util/culture.js +59 -0
  174. package/dist/util/culture.js.map +1 -0
  175. package/dist/util/cultures.generated.d.ts +3 -0
  176. package/dist/util/cultures.generated.d.ts.map +1 -0
  177. package/dist/util/cultures.generated.js +1043 -0
  178. package/dist/util/cultures.generated.js.map +1 -0
  179. package/dist/util/dateformat.d.ts +21 -0
  180. package/dist/util/dateformat.d.ts.map +1 -0
  181. package/dist/util/dateformat.js +439 -0
  182. package/dist/util/dateformat.js.map +1 -0
  183. package/dist/util/dateparse.d.ts +12 -0
  184. package/dist/util/dateparse.d.ts.map +1 -0
  185. package/dist/util/dateparse.js +1212 -0
  186. package/dist/util/dateparse.js.map +1 -0
  187. package/dist/util/datetime.d.ts +70 -0
  188. package/dist/util/datetime.d.ts.map +1 -0
  189. package/dist/util/datetime.js +265 -0
  190. package/dist/util/datetime.js.map +1 -0
  191. package/dist/util/decimal.d.ts +54 -0
  192. package/dist/util/decimal.d.ts.map +1 -0
  193. package/dist/util/decimal.js +365 -0
  194. package/dist/util/decimal.js.map +1 -0
  195. package/dist/util/delphidateformat.d.ts +34 -0
  196. package/dist/util/delphidateformat.d.ts.map +1 -0
  197. package/dist/util/delphidateformat.js +247 -0
  198. package/dist/util/delphidateformat.js.map +1 -0
  199. package/dist/util/delphiformatsettings.generated.d.ts +3 -0
  200. package/dist/util/delphiformatsettings.generated.d.ts.map +1 -0
  201. package/dist/util/delphiformatsettings.generated.js +15 -0
  202. package/dist/util/delphiformatsettings.generated.js.map +1 -0
  203. package/dist/util/delphitext.d.ts +40 -0
  204. package/dist/util/delphitext.d.ts.map +1 -0
  205. package/dist/util/delphitext.js +408 -0
  206. package/dist/util/delphitext.js.map +1 -0
  207. package/dist/util/doubleutil.d.ts +30 -0
  208. package/dist/util/doubleutil.d.ts.map +1 -0
  209. package/dist/util/doubleutil.js +651 -0
  210. package/dist/util/doubleutil.js.map +1 -0
  211. package/dist/util/inflate.d.ts +7 -0
  212. package/dist/util/inflate.d.ts.map +1 -0
  213. package/dist/util/inflate.js +256 -0
  214. package/dist/util/inflate.js.map +1 -0
  215. package/dist/util/netexception.d.ts +59 -0
  216. package/dist/util/netexception.d.ts.map +1 -0
  217. package/dist/util/netexception.js +94 -0
  218. package/dist/util/netexception.js.map +1 -0
  219. package/dist/util/numberformat.d.ts +14 -0
  220. package/dist/util/numberformat.d.ts.map +1 -0
  221. package/dist/util/numberformat.js +828 -0
  222. package/dist/util/numberformat.js.map +1 -0
  223. package/dist/util/numberparse.d.ts +49 -0
  224. package/dist/util/numberparse.d.ts.map +1 -0
  225. package/dist/util/numberparse.js +568 -0
  226. package/dist/util/numberparse.js.map +1 -0
  227. package/dist/util/reportmanres.en.generated.d.ts +2 -0
  228. package/dist/util/reportmanres.en.generated.d.ts.map +1 -0
  229. package/dist/util/reportmanres.en.generated.js +2082 -0
  230. package/dist/util/reportmanres.en.generated.js.map +1 -0
  231. package/dist/util/reportmanres.es.generated.d.ts +2 -0
  232. package/dist/util/reportmanres.es.generated.d.ts.map +1 -0
  233. package/dist/util/reportmanres.es.generated.js +2082 -0
  234. package/dist/util/reportmanres.es.generated.js.map +1 -0
  235. package/dist/util/translator.d.ts +29 -0
  236. package/dist/util/translator.d.ts.map +1 -0
  237. package/dist/util/translator.js +79 -0
  238. package/dist/util/translator.js.map +1 -0
  239. package/dist/variant/coercion.d.ts +9 -0
  240. package/dist/variant/coercion.d.ts.map +1 -0
  241. package/dist/variant/coercion.js +298 -0
  242. package/dist/variant/coercion.js.map +1 -0
  243. package/dist/variant/context.d.ts +30 -0
  244. package/dist/variant/context.d.ts.map +1 -0
  245. package/dist/variant/context.js +22 -0
  246. package/dist/variant/context.js.map +1 -0
  247. package/dist/variant/variant.d.ts +193 -0
  248. package/dist/variant/variant.d.ts.map +1 -0
  249. package/dist/variant/variant.js +1235 -0
  250. package/dist/variant/variant.js.map +1 -0
  251. package/package.json +35 -4
  252. package/README.md +0 -3
@@ -0,0 +1,864 @@
1
+ // Port of the runtime part of Reportman.Reporting.BarcodeItem (BarcodeItem.cs) and of
2
+ // BaseReport.BarcodeOp: the text of the item encoded with its symbology and drawn into the
3
+ // metafile, each bar (or dark QR module) a filled rectangle; a rotation turns the corners of
4
+ // each bar and draws the rectangle that bounds them.
5
+ //
6
+ // C# parity: the item draws no human-readable text, MSI, PostNet and Codabar draw nothing (their
7
+ // encoders are empty in C#) and the item has no GetExtension of its own (PrintPosItem's).
8
+ import { BarcodeItem as BarcodeModel, BarcodeType } from '@reportman/lib';
9
+ import { BrushType, MetaBarcodeEcc, MetaBarcodeSymbology, MetaObjectBarcode, MetaObjectDraw, MetaObjectType, PenType, ShapeType, } from '@reportman/metafile';
10
+ import { substringNet, trimNet } from '../../util/chars.js';
11
+ import { messageOf, NamedException } from '../../util/netexception.js';
12
+ import { NumberStyles, parseInt32 } from '../../util/numberparse.js';
13
+ import { ParamType, Variant } from '../../variant/variant.js';
14
+ import { NotSupportedYetError } from '../../data/errors.js';
15
+ import { ReportException } from '../errors.js';
16
+ import { PrintPosItem } from '../items.js';
17
+ import { CODE128_PATTERNS, CODE128_START_A, CODE128_START_B, CODE128_START_C, CODE128_STOP, encodeCode128 } from './code128.js';
18
+ import { castInt32, charAt, convertToInt16, convertToInt32, i32, idiv, indexOutOfRange, mathRound } from './netutil.js';
19
+ import { draw2DBarcode } from './pdf417.js';
20
+ import { qrMatrix } from './qrcode.js';
21
+ import { zxingLinearModules } from './zxingwidth.js';
22
+ // ---------------------------------------------------------------------------------------------
23
+ // Tables
24
+ /** A [rows, columns] table of characters (a C# char[,]) with the .NET bounds checks. */
25
+ function cell(table, row, column) {
26
+ if (row < 0 || row >= table.length)
27
+ throw indexOutOfRange();
28
+ const r = table[row];
29
+ if (column < 0 || column >= r.length)
30
+ throw indexOutOfRange();
31
+ return r.charAt(column);
32
+ }
33
+ const PARITY_EAN13 = ['AAAAAA', 'AABABB', 'AABBAB', 'AABBBA', 'ABAABB', 'ABBAAB', 'ABBBAA', 'ABABAB', 'ABABBA', 'ABBABA'];
34
+ // Pattern for Barcode EAN A: L1 S1 L2 S2
35
+ const EAN_A = ['2605', '1615', '1516', '0805', '0526', '0625', '0508', '0706', '0607', '2506'];
36
+ // Pattern for Barcode EAN B: L1 S1 L2 S2
37
+ const EAN_B = ['0517', '0616', '1606', '0535', '1705', '0715', '3505', '1525', '2515', '1507'];
38
+ // Pattern for Barcode EAN C: S1 L1 S2 L2
39
+ const EAN_C = ['7150', '6160', '6061', '5350', '5071', '5170', '5053', '5251', '5152', '7051'];
40
+ // Pattern for Barcode 2 of 5
41
+ const TABLE_2_5 = ['00110', '10001', '01001', '11000', '00101', '10100', '01100', '00011', '10010', '01010'];
42
+ const TABLE_39 = [
43
+ ['0', '505160605', 0], ['1', '605150506', 1], ['2', '506150506', 2], ['3', '606150505', 3],
44
+ ['4', '505160506', 4], ['5', '605160505', 5], ['6', '506160505', 6], ['7', '505150606', 7],
45
+ ['8', '605150605', 8], ['9', '506150605', 9], ['A', '605051506', 10], ['B', '506051506', 11],
46
+ ['C', '606051505', 12], ['D', '505061506', 13], ['E', '605061505', 14], ['F', '506061505', 15],
47
+ ['G', '505051606', 16], ['H', '605051605', 17], ['I', '506051605', 18], ['J', '505061605', 19],
48
+ ['K', '605050516', 20], ['L', '506050516', 21], ['M', '606050515', 22], ['N', '505060516', 23],
49
+ ['O', '605060515', 24], ['P', '506060515', 25], ['Q', '505050616', 26], ['R', '605050615', 27],
50
+ ['S', '506050615', 28], ['T', '505060615', 29], ['U', '615050506', 30], ['V', '516050506', 31],
51
+ ['W', '616050505', 32], ['X', '515060506', 33], ['Y', '615060505', 34], ['Z', '516060505', 35],
52
+ ['-', '515050606', 36], ['.', '615050605', 37], [' ', '516050605', 38], ['*', '515060605', 0],
53
+ ['$', '515151505', 39], ['/', '515150515', 40], ['+', '515051515', 41], ['%', '505151515', 42],
54
+ ].map(([c, data, chk]) => ({ c, data, chk }));
55
+ const CODE39X = [
56
+ '%U', '$A', '$B', '$C', '$D', '$E', '$F', '$G', '$H', '$I', '$J', '$K', '$L', '$M', '$N', '$O',
57
+ '$P', '$Q', '$R', '$S', '$T', '$U', '$V', '$W', '$X', '$Y', '$Z', '%A', '%B', '%C', '%D', '%E',
58
+ ' ', '/A', '/B', '/C', '/D', '/E', '/F', '/G', '/H', '/I', '/J', '/K', '/L', '/M', '/N', '/O',
59
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '/Z', '%F', '%G', '%H', '%I', '%J',
60
+ '%V', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
61
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '%K', '%L', '%M', '%N', '%O',
62
+ '%W', '+A', '+B', '+C', '+D', '+E', '+F', '+G', '+H', '+I', '+J', '+K', '+L', '+M', '+N', '+O',
63
+ '+P', '+Q', '+R', '+S', '+T', '+U', '+V', '+W', '+X', '+Y', '+Z', '%P', '%Q', '%R', '%S', '%T',
64
+ ];
65
+ const TABLE_93 = [
66
+ ['0', '131112'], ['1', '111213'], ['2', '111312'], ['3', '111411'], ['4', '121113'], ['5', '121212'],
67
+ ['6', '121311'], ['7', '111114'], ['8', '131211'], ['9', '141111'], ['A', '211113'], ['B', '211212'],
68
+ ['C', '211311'], ['D', '221112'], ['E', '221211'], ['F', '231111'], ['G', '112113'], ['H', '112212'],
69
+ ['I', '112311'], ['J', '122112'], ['K', '132111'], ['L', '111123'], ['M', '111222'], ['N', '111321'],
70
+ ['O', '121122'], ['P', '131121'], ['Q', '212112'], ['R', '212211'], ['S', '211122'], ['T', '211221'],
71
+ ['U', '221121'], ['V', '222111'], ['W', '112122'], ['X', '112221'], ['Y', '122121'], ['Z', '123111'],
72
+ ['-', '121131'], ['.', '311112'], [' ', '311211'], ['$', '321111'], ['/', '112131'], ['+', '113121'],
73
+ ['%', '211131'],
74
+ // only used for Extended Code 93
75
+ ['[', '121221'], [']', '312111'], ['{', '311121'], ['}', '122211'],
76
+ ];
77
+ const CODE93X = [
78
+ ']U', '[A', '[B', '[C', '[D', '[E', '[F', '[G', '[H', '[I', '[J', '[K', '[L', '[M', '[N', '[O',
79
+ '[P', '[Q', '[R', '[S', '[T', '[U', '[V', '[W', '[X', '[Y', '[Z', ']A', ']B', ']C', ']D', ']E',
80
+ ' ', '{A', '{B', '{C', '{D', '{E', '{F', '{G', '{H', '{I', '{J', '{K', '{L', '{M', '{N', '{O',
81
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '{Z', ']F', ']G', ']H', ']I', ']J',
82
+ ']V', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
83
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ']K', ']L', ']M', ']N', ']O',
84
+ ']W', '}A', '}B', '}C', '}D', '}E', '}F', '}G', '}H', '}I', '}J', '}K', '}L', '}M', '}N', '}O',
85
+ '}P', '}Q', '}R', '}S', '}T', '}U', '}V', '}W', '}X', '}Y', '}Z', ']P', ']Q', ']R', ']S', ']T',
86
+ ];
87
+ /** The line types of DoLines: half is a black line with 2/5 height (used for PostNet). */
88
+ var LineType;
89
+ (function (LineType) {
90
+ LineType[LineType["White"] = 0] = "White";
91
+ LineType[LineType["Black"] = 1] = "Black";
92
+ LineType[LineType["Half"] = 2] = "Half";
93
+ })(LineType || (LineType = {}));
94
+ // ---------------------------------------------------------------------------------------------
95
+ // The item
96
+ /**
97
+ * EccToMeta: the item's error correction level as the metafile vocabulary (2 = L, 3 = M, 4 = Q,
98
+ * 5 = H; anything else, the -1 automatic default included, is L).
99
+ */
100
+ export function eccToMeta(eccLevel) {
101
+ switch (eccLevel) {
102
+ case 3:
103
+ return MetaBarcodeEcc.M;
104
+ case 4:
105
+ return MetaBarcodeEcc.Q;
106
+ case 5:
107
+ return MetaBarcodeEcc.H;
108
+ default:
109
+ return MetaBarcodeEcc.L;
110
+ }
111
+ }
112
+ /**
113
+ * NativeSymbology: the device symbology of a barcode type, or Unknown for the ones no receipt
114
+ * printer draws natively (MSI, PostNet, industrial and matrix 2 of 5).
115
+ */
116
+ export function nativeSymbology(type) {
117
+ switch (type) {
118
+ case BarcodeType.CodeQR:
119
+ return MetaBarcodeSymbology.QR;
120
+ case BarcodeType.CodePDF417:
121
+ return MetaBarcodeSymbology.PDF417;
122
+ case BarcodeType.Code128:
123
+ case BarcodeType.Code128A:
124
+ case BarcodeType.Code128B:
125
+ case BarcodeType.Code128C:
126
+ return MetaBarcodeSymbology.Code128;
127
+ case BarcodeType.CodeEAN13:
128
+ return MetaBarcodeSymbology.EAN13;
129
+ case BarcodeType.CodeEAN8:
130
+ return MetaBarcodeSymbology.EAN8;
131
+ case BarcodeType.Code39:
132
+ case BarcodeType.Code39Extended:
133
+ return MetaBarcodeSymbology.Code39;
134
+ case BarcodeType.Code93:
135
+ case BarcodeType.Code93Extended:
136
+ return MetaBarcodeSymbology.Code93;
137
+ case BarcodeType.Code_2_5_interleaved:
138
+ return MetaBarcodeSymbology.ITF;
139
+ case BarcodeType.CodeCodabar:
140
+ return MetaBarcodeSymbology.Codabar;
141
+ default:
142
+ return MetaBarcodeSymbology.Unknown;
143
+ }
144
+ }
145
+ function translate2D(a, b) {
146
+ return { x: i32(a.x + b.x), y: i32(a.y + b.y) };
147
+ }
148
+ function rotate2D(p, alpha) {
149
+ const sinus = Math.sin(alpha);
150
+ const cosinus = Math.cos(alpha);
151
+ const x = convertToInt32(mathRound(p.x * cosinus + p.y * sinus));
152
+ const y = convertToInt32(mathRound(-p.x * sinus + p.y * cosinus));
153
+ return { x, y };
154
+ }
155
+ /**
156
+ * The rectangle a, b, c, d of a bar or module, rotated around the origin (its bounds) or moved
157
+ * to it; returns the top left and bottom right corners.
158
+ */
159
+ function placeRectangle(a, b, c, d, origin, rotation) {
160
+ if (rotation !== 0) {
161
+ const alpha = ((rotation / 10) * Math.PI) / 180.0;
162
+ a = translate2D(rotate2D(a, alpha), origin);
163
+ b = translate2D(rotate2D(b, alpha), origin);
164
+ c = translate2D(rotate2D(c, alpha), origin);
165
+ d = translate2D(rotate2D(d, alpha), origin);
166
+ const left = Math.min(Math.min(a.x, b.x), Math.min(c.x, d.x));
167
+ const top = Math.min(Math.min(a.y, b.y), Math.min(c.y, d.y));
168
+ const right = Math.max(Math.max(a.x, b.x), Math.max(c.x, d.x));
169
+ const bottom = Math.max(Math.max(a.y, b.y), Math.max(c.y, d.y));
170
+ return [
171
+ { x: left, y: top },
172
+ { x: right, y: bottom },
173
+ ];
174
+ }
175
+ return [translate2D(a, origin), translate2D(c, origin)];
176
+ }
177
+ /** A filled rectangle (PenType.Clear) from the corner a to the corner c. */
178
+ function filledRectangle(metafile, a, c, penWidth, penColor, brushColor) {
179
+ const metaobj = new MetaObjectDraw();
180
+ metaobj.metaType = MetaObjectType.Draw;
181
+ metaobj.top = a.y;
182
+ metaobj.left = a.x;
183
+ metaobj.width = i32(c.x - a.x);
184
+ metaobj.height = i32(c.y - a.y);
185
+ metaobj.drawStyle = ShapeType.Rectangle;
186
+ metaobj.brushStyle = BrushType.Solid;
187
+ metaobj.penStyle = PenType.Clear;
188
+ metaobj.penWidth = penWidth;
189
+ metaobj.penColor = penColor;
190
+ metaobj.brushColor = brushColor;
191
+ metafile.pages.get(metafile.currentPage).objects.push(metaobj);
192
+ }
193
+ /** BarcodeItem: an expression drawn as a barcode. */
194
+ export class BarcodeItem extends PrintPosItem {
195
+ modules = [0, 1, 2, 3];
196
+ fUpdated = false;
197
+ fValue = Variant.null;
198
+ expression;
199
+ modul;
200
+ ratio;
201
+ barType;
202
+ checksum;
203
+ displayFormat;
204
+ /** In tenths of a degree. */
205
+ rotation;
206
+ bColor;
207
+ backColor;
208
+ transparent;
209
+ numColumns;
210
+ numRows;
211
+ /** PDF417: -1 Auto, 0 to 8 the level. QR: 3 M, 4 Q, 5 H, any other value L. */
212
+ eccLevel;
213
+ truncated;
214
+ /** The text last evaluated and encoded. */
215
+ currentText = '';
216
+ constructor(report, model) {
217
+ super(report, model);
218
+ this.expression = model.expression;
219
+ this.modul = model.modul;
220
+ this.ratio = model.ratio;
221
+ this.barType = model.barType;
222
+ this.checksum = model.checksum;
223
+ this.displayFormat = model.displayFormat;
224
+ this.rotation = model.rotation;
225
+ this.bColor = model.bColor;
226
+ this.backColor = model.backColor;
227
+ this.transparent = model.transparent;
228
+ this.numColumns = model.numColumns;
229
+ this.numRows = model.numRows;
230
+ this.eccLevel = model.eccLevel;
231
+ this.truncated = model.truncated;
232
+ }
233
+ evaluate() {
234
+ if (this.fUpdated)
235
+ return;
236
+ try {
237
+ this.fValue = this.report.evaluator.evaluateText(this.expression);
238
+ this.fUpdated = true;
239
+ }
240
+ catch (e) {
241
+ throw new ReportException(messageOf(e) + ':Barcode', this.name, 'Expression');
242
+ }
243
+ }
244
+ subReportChanged(newstate, newgroup) {
245
+ super.subReportChanged(newstate, newgroup);
246
+ this.fUpdated = false;
247
+ }
248
+ getText() {
249
+ const expre = trimNet(this.expression);
250
+ if (expre.length === 0)
251
+ return '';
252
+ try {
253
+ this.evaluate();
254
+ return this.fValue.toFormatString(this.report.evaluator.context, this.displayFormat, ParamType.Unknown, true);
255
+ }
256
+ catch (e) {
257
+ // C# parity: an error of Evaluate is wrapped twice (":Barcode:Barcode")
258
+ throw new ReportException(messageOf(e) + ':Barcode', this.name, 'Expression');
259
+ }
260
+ }
261
+ doPrint(adriver, aposx, aposy, newwidth, newheight, metafile, maxExtent, partialPrint) {
262
+ super.doPrint(adriver, aposx, aposy, newwidth, newheight, metafile, maxExtent, partialPrint);
263
+ this.currentText = this.getText();
264
+ try {
265
+ if (this.barType === BarcodeType.CodeQR) {
266
+ this.printQr(adriver, aposx, aposy, metafile);
267
+ }
268
+ else {
269
+ // The same door as the QR: a driver that draws this symbology by itself gets the barcode
270
+ // object; the rest get the bars.
271
+ const simbologia = nativeSymbology(this.barType);
272
+ if (simbologia !== MetaBarcodeSymbology.Unknown && adriver.supportsNativeBarcode(simbologia) && this.emitNativeBarcode(simbologia, aposx, aposy, metafile))
273
+ return;
274
+ const data = this.calculateBarcode();
275
+ // draw the barcode
276
+ this.doLines(data, aposx, aposy, metafile);
277
+ }
278
+ }
279
+ catch (e) {
280
+ if (e instanceof NotSupportedYetError)
281
+ throw e;
282
+ throw new ReportException(messageOf(e) + ':' + this.report.translator.translateStr(573), this.name, 'Barcode');
283
+ }
284
+ }
285
+ /**
286
+ * EmitNativeBarcode: a linear barcode or PDF417 as a native object (for a receipt printer). The
287
+ * module count is the one ZXing.Net gives C# (zxingLinearModules), so the driver sizes the module
288
+ * to the box; where ZXing refuses the text (an EAN of another length, an ITF with an odd count)
289
+ * nothing is emitted and the bars are drawn as always. The module count of PDF417 comes from the
290
+ * PDF417 encoder of ZXing, not ported (the engine draws PDF417 with the encoder of Delphi): a
291
+ * device that draws PDF417 by itself is not supported yet.
292
+ */
293
+ emitNativeBarcode(simbologia, aposx, aposy, metafile) {
294
+ // C# parity: an empty text is drawn as bars
295
+ const text = this.currentText;
296
+ if (text.length === 0)
297
+ return false;
298
+ if (simbologia === MetaBarcodeSymbology.PDF417)
299
+ throw new NotSupportedYetError('PDF417 barcodes drawn by the device itself (the item ' + this.name + ')');
300
+ const modules = zxingLinearModules(simbologia, text);
301
+ if (modules === null)
302
+ return false;
303
+ const page = metafile.pages.get(metafile.currentPage);
304
+ const nativo = new MetaObjectBarcode();
305
+ nativo.metaType = MetaObjectType.Barcode;
306
+ nativo.left = aposx;
307
+ nativo.top = aposy;
308
+ nativo.width = this.width;
309
+ nativo.height = this.height;
310
+ nativo.textP = page.addString(text);
311
+ nativo.textS = text.length;
312
+ nativo.symbology = simbologia;
313
+ nativo.ecc = MetaBarcodeEcc.L;
314
+ nativo.modules = modules;
315
+ nativo.rows = 0;
316
+ // Code 128: the code set the item asked (A, B, C), 0 for the automatic one
317
+ nativo.columns =
318
+ simbologia === MetaBarcodeSymbology.Code128
319
+ ? this.barType === BarcodeType.Code128A
320
+ ? 1
321
+ : this.barType === BarcodeType.Code128B
322
+ ? 2
323
+ : this.barType === BarcodeType.Code128C
324
+ ? 3
325
+ : 0
326
+ : 0;
327
+ nativo.flags = 0;
328
+ page.objects.push(nativo);
329
+ return true;
330
+ }
331
+ printQr(adriver, aposx, aposy, metafile) {
332
+ const qrResult = qrMatrix(this.currentText, this.eccLevel);
333
+ const barcodeHeight = qrResult.height;
334
+ const barcodeWidth = qrResult.width;
335
+ const page = metafile.pages.get(metafile.currentPage);
336
+ // The driver that draws the QR by itself gets the barcode, not its modules; Modules counts what
337
+ // ZXing returned (the symbol plus its quiet zone), the grid the modules below spread over.
338
+ if (adriver.supportsNativeBarcode(MetaBarcodeSymbology.QR)) {
339
+ const nativo = new MetaObjectBarcode();
340
+ nativo.metaType = MetaObjectType.Barcode;
341
+ nativo.left = aposx;
342
+ nativo.top = aposy;
343
+ nativo.width = this.width;
344
+ nativo.height = this.height;
345
+ nativo.textP = page.addString(this.currentText);
346
+ nativo.textS = this.currentText.length;
347
+ nativo.symbology = MetaBarcodeSymbology.QR;
348
+ nativo.ecc = eccToMeta(this.eccLevel);
349
+ nativo.modules = barcodeWidth;
350
+ nativo.rows = barcodeHeight;
351
+ page.objects.push(nativo);
352
+ return;
353
+ }
354
+ let squareWidth = idiv(this.width, barcodeWidth);
355
+ let squareHeight = idiv(this.height, barcodeHeight);
356
+ // Center barcode in rectangle
357
+ if (squareWidth > squareHeight) {
358
+ const dif = squareWidth - squareHeight;
359
+ aposx = i32(aposx + idiv(Math.imul(dif, barcodeWidth), 2));
360
+ squareWidth = squareHeight;
361
+ }
362
+ else {
363
+ const dif = squareHeight - squareWidth;
364
+ aposy = i32(aposy + idiv(Math.imul(dif, barcodeHeight), 2));
365
+ squareHeight = squareWidth;
366
+ }
367
+ const origin = {
368
+ x: i32(aposx + idiv(Math.imul(squareWidth, barcodeWidth), 2)),
369
+ y: i32(aposy + idiv(Math.imul(squareHeight, barcodeHeight), 2)),
370
+ };
371
+ // The quiet background goes down once, as a single rectangle; only the dark modules follow
372
+ if (!this.transparent) {
373
+ const fondo = new MetaObjectDraw();
374
+ fondo.metaType = MetaObjectType.Draw;
375
+ fondo.left = aposx;
376
+ fondo.top = aposy;
377
+ fondo.width = Math.imul(squareWidth, barcodeWidth);
378
+ fondo.height = Math.imul(squareHeight, barcodeHeight);
379
+ fondo.drawStyle = ShapeType.Rectangle;
380
+ fondo.brushStyle = BrushType.Solid;
381
+ fondo.penStyle = PenType.Clear;
382
+ fondo.penWidth = 0;
383
+ fondo.penColor = this.backColor;
384
+ fondo.brushColor = this.backColor;
385
+ page.objects.push(fondo);
386
+ }
387
+ for (let rowIndex = 0; rowIndex < barcodeHeight; rowIndex++) {
388
+ for (let column = 0; column < barcodeWidth; column++) {
389
+ const xadd = i32(Math.imul(squareWidth, column) - idiv(Math.imul(squareWidth, barcodeWidth), 2));
390
+ const yadd = i32(Math.imul(squareHeight, rowIndex) - idiv(Math.imul(squareHeight, barcodeHeight), 2));
391
+ // a, b, c, d builds the rectangle we want to draw
392
+ const [a, c] = placeRectangle({ x: xadd, y: yadd }, { x: xadd, y: i32(yadd + squareHeight) }, { x: i32(xadd + squareWidth), y: i32(yadd + squareHeight) }, { x: i32(xadd + squareWidth), y: yadd }, origin, this.rotation);
393
+ // Only the dark modules are painted, filled and not stroked
394
+ if (qrResult.get(column, rowIndex))
395
+ filledRectangle(metafile, a, c, 0, this.bColor, this.bColor);
396
+ }
397
+ // C# parity: aposy moves down a row, and nothing reads it
398
+ aposy = i32(aposy + squareHeight);
399
+ }
400
+ }
401
+ /** CalculateBarcode: the bar and space widths of the text ('0'-'3' spaces, '5'-'8' bars). */
402
+ calculateBarcode() {
403
+ let data = '';
404
+ if (this.barType === BarcodeType.CodePDF417)
405
+ return this.currentText;
406
+ // Calculate the with of lines
407
+ this.makeModules();
408
+ switch (this.barType) {
409
+ case BarcodeType.Code_2_5_interleaved:
410
+ data = this.code25Interleaved();
411
+ break;
412
+ case BarcodeType.Code_2_5_industrial:
413
+ data = this.code25Industrial();
414
+ break;
415
+ case BarcodeType.Code_2_5_matrix:
416
+ data = this.code25Matrix();
417
+ break;
418
+ case BarcodeType.Code39:
419
+ data = this.code39();
420
+ break;
421
+ case BarcodeType.Code39Extended:
422
+ data = this.code39Extended();
423
+ break;
424
+ case BarcodeType.Code128A:
425
+ case BarcodeType.Code128B:
426
+ case BarcodeType.Code128C:
427
+ case BarcodeType.Code128:
428
+ data = this.code128();
429
+ break;
430
+ case BarcodeType.Code93:
431
+ data = this.code93();
432
+ break;
433
+ case BarcodeType.Code93Extended:
434
+ data = this.code93Extended();
435
+ break;
436
+ case BarcodeType.CodeMSI:
437
+ case BarcodeType.CodePostNet:
438
+ case BarcodeType.CodeCodabar:
439
+ // C# parity: Code_MSI, Code_PostNet and Code_Codabar return an empty pattern
440
+ data = '';
441
+ break;
442
+ case BarcodeType.CodeEAN8:
443
+ data = this.codeEAN8();
444
+ break;
445
+ case BarcodeType.CodeEAN13:
446
+ data = this.codeEAN13();
447
+ break;
448
+ }
449
+ return data;
450
+ }
451
+ makeModules() {
452
+ switch (this.barType) {
453
+ case BarcodeType.Code_2_5_interleaved:
454
+ case BarcodeType.Code_2_5_industrial:
455
+ case BarcodeType.Code39:
456
+ case BarcodeType.Code39Extended:
457
+ case BarcodeType.CodeEAN8:
458
+ case BarcodeType.CodeEAN13:
459
+ if (this.ratio < 2.0)
460
+ this.ratio = 2.0;
461
+ if (this.ratio > 3.0)
462
+ this.ratio = 3.0;
463
+ break;
464
+ case BarcodeType.Code_2_5_matrix:
465
+ if (this.ratio < 2.25)
466
+ this.ratio = 2.25;
467
+ if (this.ratio > 3.25)
468
+ this.ratio = 3.25;
469
+ break;
470
+ }
471
+ const m = this.modules;
472
+ m[0] = this.modul;
473
+ m[1] = castInt32(mathRound(this.modul * this.ratio));
474
+ m[2] = idiv(Math.imul(m[1], 3), 2);
475
+ m[3] = Math.imul(m[1], 2);
476
+ // Code 128 bars and spaces are 1, 2, 3 or 4 modules: the Ratio does not apply
477
+ if (this.barType === BarcodeType.Code128 ||
478
+ this.barType === BarcodeType.Code128A ||
479
+ this.barType === BarcodeType.Code128B ||
480
+ this.barType === BarcodeType.Code128C) {
481
+ m[1] = Math.imul(this.modul, 2);
482
+ m[2] = Math.imul(this.modul, 3);
483
+ m[3] = Math.imul(this.modul, 4);
484
+ }
485
+ }
486
+ /** GetEAN: the text with its last digit replaced by the EAN check digit. */
487
+ getEAN(nr) {
488
+ let sum = 0;
489
+ const tmp = substringNet(nr, 0, nr.length - 1);
490
+ let fak = tmp.length;
491
+ const nfi = this.report.evaluator.context.culture.number;
492
+ for (let i = 0; i < tmp.length; i++) {
493
+ const digit = parseInt32(tmp.charAt(i), NumberStyles.Integer, nfi);
494
+ if (fak % 2 === 0)
495
+ sum = i32(sum + digit * 1);
496
+ else
497
+ sum = i32(sum + Math.imul(digit, 3));
498
+ fak--;
499
+ }
500
+ if (sum % 10 === 0)
501
+ return tmp + '0';
502
+ return tmp + String(10 - (sum % 10));
503
+ }
504
+ code128() {
505
+ const values = encodeCode128(this.currentText, this.barType);
506
+ if (values.length === 0)
507
+ return '';
508
+ let achecksum = values[0];
509
+ for (let i = 1; i < values.length; i++)
510
+ achecksum = i32(achecksum + Math.imul(values[i], i));
511
+ achecksum = achecksum % 103;
512
+ let aresult = '';
513
+ for (const v of values) {
514
+ if (v === 103)
515
+ aresult += doConvert(CODE128_START_A);
516
+ else if (v === 104)
517
+ aresult += doConvert(CODE128_START_B);
518
+ else if (v === 105)
519
+ aresult += doConvert(CODE128_START_C);
520
+ else
521
+ aresult += doConvert(patternAt(v));
522
+ }
523
+ aresult += doConvert(patternAt(achecksum));
524
+ aresult += doConvert(CODE128_STOP);
525
+ return aresult;
526
+ }
527
+ codeEAN13() {
528
+ let tmp;
529
+ let retresult = '';
530
+ if (this.checksum) {
531
+ tmp = '0000000000000' + this.currentText;
532
+ tmp = this.getEAN(substringNet(tmp, tmp.length - 12, 12) + '0');
533
+ }
534
+ else
535
+ tmp = this.currentText;
536
+ // Startcode
537
+ let result = '505';
538
+ // Avoid to process a code that is shorter to 13 characters
539
+ if (tmp.length >= 13) {
540
+ const lk = charAt(tmp, 0) - 48;
541
+ tmp = substringNet(tmp, 1, 12);
542
+ for (let i = 0; i < 6; i++) {
543
+ const index = charAt(tmp, i) - 48;
544
+ switch (cell(PARITY_EAN13, lk, i)) {
545
+ case 'A':
546
+ for (let j = 0; j < 4; j++)
547
+ result += cell(EAN_A, index, j);
548
+ break;
549
+ case 'B':
550
+ for (let j = 0; j < 4; j++)
551
+ result += cell(EAN_B, index, j);
552
+ break;
553
+ case 'C':
554
+ for (let j = 0; j < 4; j++)
555
+ result += cell(EAN_C, index, j);
556
+ break;
557
+ }
558
+ }
559
+ result += '05050';
560
+ for (let i = 6; i < 12; i++)
561
+ for (let j = 0; j < 4; j++) {
562
+ const index = charAt(tmp, i) - 48;
563
+ result += cell(EAN_C, index, j);
564
+ }
565
+ // Stopcode
566
+ result += '505';
567
+ retresult = result;
568
+ }
569
+ return retresult;
570
+ }
571
+ codeEAN8() {
572
+ let tmp;
573
+ let retResult = '';
574
+ if (this.checksum) {
575
+ tmp = '00000000' + this.currentText;
576
+ tmp = this.getEAN(substringNet(tmp, tmp.length - 7, 7) + '0');
577
+ }
578
+ else
579
+ tmp = this.currentText;
580
+ // Startcode
581
+ let result = '505';
582
+ // Check to avoid the processing of code shorter than 8 characters
583
+ if (tmp.length >= 8) {
584
+ for (let i = 0; i < 4; i++)
585
+ for (let j = 0; j < 4; j++) {
586
+ const index = charAt(tmp, i) - 48;
587
+ result += cell(EAN_A, index, j);
588
+ }
589
+ result += '05050';
590
+ for (let i = 4; i < 8; i++)
591
+ for (let j = 0; j < 4; j++) {
592
+ const index = charAt(tmp, i) - 48;
593
+ result += cell(EAN_C, index, j);
594
+ }
595
+ // Stopcode
596
+ result += '505';
597
+ retResult = result;
598
+ }
599
+ return retResult;
600
+ }
601
+ code25Interleaved() {
602
+ const ftext = this.currentText;
603
+ let result = '5050'; // Startcode
604
+ for (let i = 0; i < Math.trunc(ftext.length / 2); i++)
605
+ for (let j = 0; j < 5; j++) {
606
+ let index = charAt(ftext, i * 2) - 48;
607
+ result += cell(TABLE_2_5, index, j) === '1' ? '6' : '5';
608
+ index = charAt(ftext, i * 2 + 1) - 48;
609
+ result += cell(TABLE_2_5, index, j) === '1' ? '1' : '0';
610
+ }
611
+ result += '605'; // Stopcode
612
+ return result;
613
+ }
614
+ code25Industrial() {
615
+ const ftext = this.currentText;
616
+ let result = '606050'; // Startcode
617
+ for (let i = 0; i < ftext.length; i++)
618
+ for (let j = 0; j < 5; j++) {
619
+ const index = charAt(ftext, i) - 48;
620
+ result += cell(TABLE_2_5, index, j) === '1' ? '60' : '50';
621
+ }
622
+ result += '605060'; // Stopcode
623
+ return result;
624
+ }
625
+ code25Matrix() {
626
+ const ftext = this.currentText;
627
+ let result = '705050'; // Startcode
628
+ for (let i = 0; i < ftext.length; i++) {
629
+ for (let j = 0; j < 5; j++) {
630
+ // C# parity: the digit read is the one at i * 2 + 1, past the end of any text of one
631
+ // character or more (IndexOutOfRangeException)
632
+ const index = charAt(ftext, i * 2 + 1) - 48;
633
+ let c = cell(TABLE_2_5, index, j) === '1' ? 49 : 48;
634
+ if (j % 2 !== 0)
635
+ c = c + 5;
636
+ result += String.fromCharCode(c);
637
+ }
638
+ result += '0';
639
+ }
640
+ result += '70505'; // Stopcode
641
+ return result;
642
+ }
643
+ code39() {
644
+ let checksum = 0;
645
+ const star = findCode39IDX('*');
646
+ // Startcode
647
+ let result = TABLE_39[star].data + '0';
648
+ const ftext = this.currentText;
649
+ for (let i = 0; i < ftext.length; i++) {
650
+ const idx = findCode39IDX(ftext.charAt(i));
651
+ if (idx >= 0) {
652
+ result += TABLE_39[idx].data + '0';
653
+ checksum = i32(checksum + TABLE_39[idx].chk);
654
+ }
655
+ }
656
+ // Calculate Checksum Data
657
+ if (this.checksum) {
658
+ checksum = checksum % 43;
659
+ for (let i = 0; i < 44; i++)
660
+ if (checksum === TABLE_39[i].chk) {
661
+ // C# parity: with the check character the symbol has no stop character
662
+ result += TABLE_39[i].data + '0';
663
+ return result;
664
+ }
665
+ }
666
+ result += TABLE_39[star].data;
667
+ return result;
668
+ }
669
+ code39Extended() {
670
+ const save = this.currentText;
671
+ let ftext = '';
672
+ for (let i = 0; i < save.length; i++) {
673
+ const c = save.charCodeAt(i);
674
+ if (c <= 127)
675
+ ftext += CODE39X[c];
676
+ }
677
+ this.currentText = ftext;
678
+ try {
679
+ return this.code39();
680
+ }
681
+ finally {
682
+ this.currentText = save;
683
+ }
684
+ }
685
+ code93() {
686
+ const ftext = this.currentText;
687
+ let result = doConvert('111141'); // Startcode
688
+ for (let i = 0; i < ftext.length; i++) {
689
+ const idx = findCode93(ftext.charAt(i));
690
+ if (idx < 0)
691
+ throw new NamedException('Code93 bad Data: ' + ftext, ftext);
692
+ result += doConvert(TABLE_93[idx][1]);
693
+ }
694
+ let checkC = 0;
695
+ let checkK = 0;
696
+ let weightC = 1;
697
+ let weightK = 2;
698
+ for (let i = ftext.length - 1; i >= 0; i--) {
699
+ const idx = findCode93(ftext.charAt(i));
700
+ checkC = i32(checkC + Math.imul(idx, weightC));
701
+ checkK = i32(checkK + Math.imul(idx, weightK));
702
+ weightC++;
703
+ if (weightC > 20)
704
+ weightC = 1;
705
+ weightK++;
706
+ // C# parity: the K weight never restarts (the weight of C is reset instead)
707
+ if (weightK > 15)
708
+ weightC = 1;
709
+ }
710
+ checkK = i32(checkK + checkC);
711
+ checkC = checkC % 47;
712
+ checkK = checkK % 47;
713
+ result += doConvert(TABLE_93[checkC][1]) + doConvert(TABLE_93[checkK][1]);
714
+ result += doConvert('1111411'); // Stopcode
715
+ return result;
716
+ }
717
+ code93Extended() {
718
+ const save = this.currentText;
719
+ let ftext = '';
720
+ for (let i = 0; i < save.length; i++) {
721
+ const c = save.charCodeAt(i);
722
+ if (c <= 127)
723
+ ftext += CODE93X[c];
724
+ }
725
+ this.currentText = ftext;
726
+ try {
727
+ return this.code93();
728
+ }
729
+ finally {
730
+ this.currentText = save;
731
+ }
732
+ }
733
+ /** DoLines: draws the bars of the pattern (or the PDF417 symbol) at Left, Top. */
734
+ doLines(data, left, top, metafile) {
735
+ if (this.barType === BarcodeType.CodePDF417) {
736
+ draw2DBarcode(this.currentText, this.eccLevel, this.numRows, this.numColumns, this.truncated, this.modul, left, top, this.height, metafile, this.bColor, this.rotation, this.report.evaluator.context.culture.number);
737
+ return;
738
+ }
739
+ let xadd = 0;
740
+ const origin = { x: left, y: top };
741
+ const penWidth = 0;
742
+ const m = this.modules;
743
+ for (let i = 0; i < data.length; i++) {
744
+ let awidth;
745
+ let lt;
746
+ switch (data.charAt(i)) {
747
+ case '0':
748
+ awidth = m[0];
749
+ lt = LineType.White;
750
+ break;
751
+ case '1':
752
+ awidth = m[1];
753
+ lt = LineType.White;
754
+ break;
755
+ case '2':
756
+ awidth = m[2];
757
+ lt = LineType.White;
758
+ break;
759
+ case '3':
760
+ awidth = m[3];
761
+ lt = LineType.White;
762
+ break;
763
+ case '5':
764
+ awidth = m[0];
765
+ lt = LineType.Black;
766
+ break;
767
+ case '6':
768
+ awidth = m[1];
769
+ lt = LineType.Black;
770
+ break;
771
+ case '7':
772
+ awidth = m[2];
773
+ lt = LineType.Black;
774
+ break;
775
+ case '8':
776
+ awidth = m[3];
777
+ lt = LineType.Black;
778
+ break;
779
+ case 'A':
780
+ awidth = m[0];
781
+ lt = LineType.Half;
782
+ break;
783
+ case 'B':
784
+ awidth = m[1];
785
+ lt = LineType.Half;
786
+ break;
787
+ case 'C':
788
+ awidth = m[2];
789
+ lt = LineType.Half;
790
+ break;
791
+ case 'D':
792
+ awidth = m[3];
793
+ lt = LineType.Half;
794
+ break;
795
+ default:
796
+ throw new NamedException(this.report.translator.translateStr(582) + ':' + data, data);
797
+ }
798
+ const penColor = lt === LineType.Black || lt === LineType.Half ? this.bColor : 0xffffff;
799
+ if (lt !== LineType.White || (lt === LineType.White && !this.transparent)) {
800
+ const brushColor = penColor;
801
+ const aheight = lt === LineType.Half ? idiv(Math.imul(this.printHeight, 2), 5) : this.printHeight;
802
+ // a, b, c, d builds the rectangle we want to draw
803
+ const [a, c] = placeRectangle({ x: xadd, y: 0 }, { x: xadd, y: aheight }, { x: i32(xadd + awidth), y: aheight }, { x: i32(xadd + awidth), y: 0 }, origin, this.rotation);
804
+ filledRectangle(metafile, a, c, penWidth, penColor, brushColor);
805
+ }
806
+ xadd = i32(xadd + awidth);
807
+ }
808
+ }
809
+ }
810
+ function findCode39IDX(z) {
811
+ for (let i = 0; i < 44; i++)
812
+ if (TABLE_39[i].c === z)
813
+ return i;
814
+ return -1;
815
+ }
816
+ function findCode93(c) {
817
+ for (let i = 0; i < 47; i++)
818
+ if (TABLE_93[i][0] === c)
819
+ return i;
820
+ return -1;
821
+ }
822
+ /** Code128.table[v].data with the .NET bounds check. */
823
+ function patternAt(v) {
824
+ if (v < 0 || v >= CODE128_PATTERNS.length)
825
+ throw indexOutOfRange();
826
+ return CODE128_PATTERNS[v];
827
+ }
828
+ /**
829
+ * DoConvert: a pattern of widths ('321') in the internal representation ('715'): the even
830
+ * positions are bars (5 to 8), the odd ones spaces (0 to 3).
831
+ */
832
+ function doConvert(s) {
833
+ let t = '';
834
+ for (let i = 0; i < s.length; i++) {
835
+ let v = s.charCodeAt(i) - 1;
836
+ if (i % 2 === 0)
837
+ v = v + 5;
838
+ t += String.fromCharCode(v & 0xffff);
839
+ }
840
+ return t;
841
+ }
842
+ /**
843
+ * BaseReport.BarcodeOp (the BARCODEOP function): a barcode of the value of an expression drawn
844
+ * in the current page. A QR draws nothing (CalculateBarcode has no QR pattern).
845
+ */
846
+ export function barcodeOp(report, left, top, width, height, expression, displayFormat, barType, modul, ratio, rotation, calcChecksum, brushColor) {
847
+ const barcode = new BarcodeItem(report, new BarcodeModel());
848
+ barcode.width = width;
849
+ barcode.height = height;
850
+ barcode.barType = barType;
851
+ barcode.modul = modul;
852
+ barcode.ratio = ratio;
853
+ barcode.rotation = convertToInt16(rotation * 10);
854
+ barcode.checksum = calcChecksum;
855
+ const fValue = report.evaluator.evaluateText(expression);
856
+ barcode.currentText = fValue.toFormatString(report.evaluator.context, displayFormat, ParamType.Unknown, true);
857
+ const data = barcode.calculateBarcode();
858
+ // Draws Barcode
859
+ barcode.printHeight = height;
860
+ barcode.bColor = brushColor;
861
+ barcode.doLines(data, left, top, report.metaFile);
862
+ return true;
863
+ }
864
+ //# sourceMappingURL=barcodeitem.js.map