| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 29× 1× 24× 24× 7× 17× 17× 17× 17× 17× 4× 4× 4× 4× 17× 17× 1× 16× 16× 1× 19× 19× 19× 19× 19× 610× 610× 518× 92× 19× 9× 10× 1× 17× 17× 1× 16× 16× 48× 16× 16× 16× 16× 16× 16× 16× 1× 16× 16× 1× 32× 32× 24× 8× 8× 8× 8× 24× 24× 24× 24× 24× 4× 4× 2× 2× 2× 2× 24× 8× 8× 24× 24× 198× 198× 8× 8× 8× 32× 8× 1012× 8× 8× 8× 24× 16× 24× 24× 16× 16× 8× 1× 24× 24× 224× 224× 224× 120× 24× 24× 24× 24× 2512× 2512× 2512× 2512× 5704× 2512× 24× 1× 24× 24× 76× 76× 76× 42× 24× 24× 24× 24× 920× 920× 920× 920× 2018× 920× 24× 1× 2018× 24× 24× 42× 42× 42× 630× 630× 314× 316× 24× 24× 24× 1× 26× 26× 26× 30× 26× 14× 26× 1× 16× 16× 16× 48× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 16× 48× 48× 48× 48× 48× 5722× 5722× 1256× 4466× 1256× 1256× 48× 16× 16× 1256× 16× 16× 16× 16× 1× 16× 1× 8× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "../one-dimension", "../rendering/renderer", "../utility/dom-util", "../../gs1/gs1-parser", "../../gs1/gs1-databar-encoder"], function (require, exports, one_dimension_1, renderer_1, dom_util_1, gs1_parser_1, gs1_databar_encoder_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var EXPANDED_ROW_HEIGHT = 34; var EXPANDED_SEPARATOR_HEIGHT = 1; var EXPANDED_MAX_SEGMENTS = 22; var EXPANDED_MAX_ROWS = 11; var EXPANDED_MAX_DIGITS = 74; var EXPANDED_MAX_LETTERS = 41; var GS1DataBarExpanded = (function (_super) { __extends(GS1DataBarExpanded, _super); function GS1DataBarExpanded() { return _super !== null && _super.apply(this, arguments) || this; } GS1DataBarExpanded.prototype.validateInput = function (char) { var parsed = gs1_parser_1.parseGs1(char); if (!parsed.ok) { return this.message(parsed.error); } var gs1 = parsed; Iif (!this.withinCapacity(gs1)) { return this.message('DataBarDataTooLong'); } var encoded = gs1_databar_encoder_1.encodeExpandedDataBar(gs1, this.databarVariant === 'ExpandedStacked' ? this.segmentsPerRow : undefined); Iif (typeof encoded === 'string') { return this.message(encoded); } if (this.databarVariant === 'ExpandedStacked') { var segmentsPerRow = this.segmentsPerRow; Iif (!segmentsPerRow || segmentsPerRow < 2 || segmentsPerRow > 20 || segmentsPerRow % 2 !== 0) { return this.message('DataBarInvalidSegmentsPerRow'); } var rowCount = Math.ceil(encoded.segments.length / segmentsPerRow); Iif (rowCount > EXPANDED_MAX_ROWS) { return this.message('DataBarDataTooLong'); } } var sizeError = this.validateSize(encoded); if (sizeError) { return sizeError; } this.encoded = encoded; return undefined; }; GS1DataBarExpanded.prototype.withinCapacity = function (gs1) { var data = gs1.encodingData; var digits = 0; var letters = 0; var index; for (index = 0; index < data.length; index++) { var charCode = data.charCodeAt(index); if (charCode >= 48 && charCode <= 57) { digits++; } else { letters++; } } if (letters === 0) { return digits <= EXPANDED_MAX_DIGITS && data.length <= EXPANDED_MAX_SEGMENTS * 12; } return letters <= EXPANDED_MAX_LETTERS && data.length <= EXPANDED_MAX_SEGMENTS * 12; }; GS1DataBarExpanded.prototype.validateSize = function (encoded) { var barcodeSize = this.getDrawableSize(this.margin, this.width, this.height); if (barcodeSize.width <= 0 || barcodeSize.height <= 0) { return this.message('InsufficientSize'); } var rows = this.buildRows(encoded); var moduleCount = rows[0].pixels.length; var totalModules = rows.reduce(function (sum, row) { return sum + row.height; }, 0); var textOptions = { width: undefined, height: undefined, x: 0, y: 0, color: this.foreColor, string: this.displayText.text ? this.displayText.text : encoded.humanReadableText, stringSize: this.displayText.size, visibility: this.displayText.visibility, fontStyle: this.displayText.font }; dom_util_1.createMeasureElements(); var textSize = dom_util_1.measureText(textOptions); var scaleValue = this.isSvgMode ? 1 : 1.5; var barHeight = barcodeSize.height - (textSize.height / 2 + 2) * scaleValue; Iif (barcodeSize.width / (moduleCount * scaleValue) < 1 || barHeight / (totalModules * scaleValue) < 1) { return this.message('InsufficientSize'); } return undefined; }; GS1DataBarExpanded.prototype.draw = function (canvas) { var rows = this.buildRows(this.encoded); this.drawRows(canvas, rows); }; GS1DataBarExpanded.prototype.buildRows = function (encoded) { var segments = encoded.segments; if (this.databarVariant !== 'ExpandedStacked') { return [{ pixels: this.linearPixels(segments), height: EXPANDED_ROW_HEIGHT }]; } var perRow = this.segmentsPerRow; var symbolRows = []; var start; for (start = 0; start < segments.length; start += perRow) { var rowIndex = symbolRows.length; var rowSegments = segments.slice(start, start + perRow); var pixels = this.rowPixels(rowSegments, perRow % 4 !== 0 && rowIndex % 2 === 1); var separator = this.separatorRow(pixels); if (perRow % 4 === 0 && rowIndex % 2 === 1) { var partialRow = pixels.length < symbolRows[0].pixels.length; if (partialRow && this.finderPositions(pixels.length).length % 2 === 1) { pixels.unshift(0); separator.unshift(0); } else { pixels.reverse(); separator.reverse(); } } symbolRows.push({ pixels: pixels, separator: separator }); } var moduleCount = symbolRows[0].pixels.length; for (var _i = 0, symbolRows_1 = symbolRows; _i < symbolRows_1.length; _i++) { var row = symbolRows_1[_i]; while (row.pixels.length < moduleCount) { row.pixels.push(0); row.separator.push(0); } } var middleSeparator = []; var moduleIndex; for (moduleIndex = 0; moduleIndex < 4; moduleIndex++) { middleSeparator.push(0); } for (moduleIndex = 4; moduleIndex < moduleCount - 4; moduleIndex++) { middleSeparator.push(moduleIndex % 2 === 1 ? 1 : 0); } middleSeparator.push(0, 0, 0, 0); var rows = []; symbolRows.forEach(function (row, rowIndex) { if (rowIndex > 0) { rows.push({ pixels: row.separator, height: EXPANDED_SEPARATOR_HEIGHT }); } rows.push({ pixels: row.pixels, height: EXPANDED_ROW_HEIGHT }); if (rowIndex < symbolRows.length - 1) { rows.push({ pixels: row.separator, height: EXPANDED_SEPARATOR_HEIGHT }); rows.push({ pixels: middleSeparator, height: EXPANDED_SEPARATOR_HEIGHT }); } }); return rows; }; GS1DataBarExpanded.prototype.linearPixels = function (segments) { var runs = [0, 1, 1]; for (var _i = 0, segments_1 = segments; _i < segments_1.length; _i++) { var segment = segments_1[_i]; runs.push.apply(runs, segment.dataWidths); if (segment.finderWidths) { runs.push.apply(runs, segment.finderWidths); } } runs.push(1, 1); var pixels = []; var runIndex = 0; for (var _a = 0, runs_1 = runs; _a < runs_1.length; _a++) { var run = runs_1[_a]; var color = runIndex % 2 === 0 ? 1 : 0; var count = void 0; for (count = 0; count < run; count++) { pixels.push(color); } runIndex++; } return pixels; }; GS1DataBarExpanded.prototype.rowPixels = function (segments, leadingPlaceholder) { var runs = leadingPlaceholder ? [0, 1, 1] : [1, 1]; for (var _i = 0, segments_2 = segments; _i < segments_2.length; _i++) { var segment = segments_2[_i]; runs.push.apply(runs, segment.dataWidths); if (segment.finderWidths) { runs.push.apply(runs, segment.finderWidths); } } runs.push(1, 1); var pixels = []; var runIndex = 0; for (var _a = 0, runs_2 = runs; _a < runs_2.length; _a++) { var run = runs_2[_a]; var color = leadingPlaceholder ? (runIndex % 2 === 0 ? 1 : 0) : (runIndex % 2 === 0 ? 0 : 1); var count = void 0; for (count = 0; count < run; count++) { pixels.push(color); } runIndex++; } return pixels; }; GS1DataBarExpanded.prototype.separatorRow = function (above) { var separator = above.map(function (pixel) { return 1 - pixel; }); var finderPositions = this.finderPositions(above.length); for (var _i = 0, finderPositions_1 = finderPositions; _i < finderPositions_1.length; _i++) { var finderStart = finderPositions_1[_i]; var index = void 0; for (index = finderStart; index <= finderStart + 14; index++) { var pixel = above.slice(index, index + 1)[0]; if (pixel === 0 && index > 0) { separator.fill(1, index - 1, index); } else { separator.fill(0, index, index + 1); } } } separator.fill(0, 0, 4); separator.fill(0, separator.length - 4); return separator; }; GS1DataBarExpanded.prototype.finderPositions = function (rowLength) { var positions = []; var position; for (position = 19; position <= rowLength - 13; position += 98) { positions.push(position); } for (position = 68; position <= rowLength - 13; position += 98) { positions.push(position); } return positions; }; GS1DataBarExpanded.prototype.drawRows = function (canvas, rows) { var barcodeSize = this.getDrawableSize(this.margin, this.width, this.height); Iif (barcodeSize.height <= 0 || barcodeSize.width <= 0) { return; } var moduleCount = rows[0].pixels.length; var totalHeight = rows.reduce(function (sum, row) { return sum + row.height; }, 0); var textOptions = { width: undefined, height: undefined, x: 0, y: 0, color: this.foreColor, string: this.displayText.text ? this.displayText.text : this.encoded.humanReadableText, stringSize: this.displayText.size, visibility: this.displayText.visibility, fontStyle: this.displayText.font }; dom_util_1.createMeasureElements(); var textSize = dom_util_1.measureText(textOptions); var textHeight = (textSize.height / 2) + 2; var scaleValue = this.isSvgMode ? 1 : 1.5; var barHeight = barcodeSize.height - textHeight * scaleValue; Iif (barHeight <= 0) { return; } var moduleWidth = barcodeSize.width / (moduleCount * scaleValue); Iif (moduleWidth < 1) { return; } var rowHeightScale = (barHeight / scaleValue) / totalHeight; var position = this.displayText.position; var barTop = position === 'Top' ? barcodeSize.y + textHeight + this.displayText.margin.top : barcodeSize.y; var options = []; var offsetY = barTop; var index; for (index = 0; index < rows.length; index++) { var row = rows[parseInt(index.toString(), 10)]; var height = row.height * rowHeightScale; var moduleIndex = void 0; var runStart = -1; for (moduleIndex = 0; moduleIndex <= row.pixels.length; moduleIndex++) { var isBar = moduleIndex < row.pixels.length && row.pixels[parseInt(moduleIndex.toString(), 10)] === 1; if (isBar && runStart === -1) { runStart = moduleIndex; } else if (!isBar && runStart !== -1) { options.push({ x: barcodeSize.x + runStart * moduleWidth, y: offsetY, width: (moduleIndex - runStart) * moduleWidth, height: height, color: this.foreColor }); runStart = -1; } } offsetY += height; } var renderer = new renderer_1.BarcodeRenderer(canvas.id, this.isSvgMode); for (index = 0; index < options.length; index++) { renderer.renderRectElement(canvas, options[parseInt(index.toString(), 10)]); } Eif (this.displayText.visibility) { textOptions.x = barcodeSize.x + (barcodeSize.width - textSize.width) / 2; textOptions.y = position === 'Bottom' ? (barcodeSize.y + barcodeSize.height) + 2 : (barcodeSize.y + textHeight) - 2; if (!this.isSvgMode) { textOptions.y /= 1.5; } renderer.renderTextElement(canvas, textOptions); } }; GS1DataBarExpanded.prototype.message = function (key) { return this.locale ? (this.locale.getConstant(key) || key) : key; }; return GS1DataBarExpanded; }(one_dimension_1.OneDimension)); exports.GS1DataBarExpanded = GS1DataBarExpanded; }); |