all files / barcode/ one-dimension.js

100% Statements 288/288
99.3% Branches 426/429
100% Functions 29/29
100% Lines 285/285
11 statements, 6 functions, 9 branches Ignored     
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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439  1× 1× 1× 1× 1× 1×   1× 1× 1× 1×     1×   1× 1× 1× 1× 173×   1× 309× 309× 309×   1× 150×   150×   150× 150×   1× 31820×       31820× 3358×   31820× 1635× 1635×   31820×   1× 148× 148× 86× 86× 86×   62× 31× 31×   31× 2× 2× 33× 33× 205×     2×     29× 29× 238× 238×   29× 29× 10×   19× 5×   29×     1× 7261× 7261× 1258× 1258×   6003×   1× 1251× 873×   378× 64×     314×     1× 15732×               161×     15571×     1× 15571× 15571×                     158×     15413×     1× 15732× 15732× 64×   15668× 174×   15494× 679×     14815×   15732×   1× 1251×       188×     1063×     1× 15732× 15527× 10689× 10689×     4838×     15732× 205× 5×   200× 62×   138× 11×     127×     15732×   1× 150× 150× 150× 150× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 148× 1251× 1251× 1251× 1251× 1251× 1251× 1251× 15732× 15732× 161×   15571× 158× 158× 1×   158×   15732× 15732× 15732× 15732× 15732× 15732× 15732× 15732× 15732× 15732× 15732× 148× 148× 148×   15732× 1754×   15732× 2× 2× 2×   15732× 14136× 14136× 14136× 14136× 8329× 8329× 8329× 1539×   8329×   14136× 6003× 6003× 6003× 970×   6003× 6003× 6003× 6003× 6003× 6003×   14136× 13996×   14136×     145× 23×     122×   145× 14× 14× 14×   14× 14× 7× 7× 7× 7× 7× 7× 4×   7× 7×     7× 7× 7× 7× 4×   7× 7×     145× 145×     15732× 7005×   15732× 9731×       148×     1× 15732×     9731×     6001×     1× 13996× 3089× 2635×     454×     13996× 2207× 2027× 2027× 2027×       180×       1× 159× 133×   26× 14×     12×     1× 148× 148× 7005×     1× 39× 22× 22× 2× 2× 2× 2× 2× 2×       1× 145× 145× 29× 18× 18× 18× 18×   29× 2× 2× 2×   27× 17× 17× 17×       1× 1596×   1542× 1542× 1542×   54× 37×     1× 161× 26×   161× 161×   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", "./barcode-base", "./rendering/renderer", "./primitives/rect", "./utility/dom-util"], function (require, exports, barcode_base_1, renderer_1, rect_1, dom_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var OneDimension = (function (_super) {
        __extends(OneDimension, _super);
        function OneDimension() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        OneDimension.prototype.getInstance = function (id) {
            var barCode = document.getElementById(id);
            var barcodeRenderer = new renderer_1.BarcodeRenderer(barCode.id, this.isSvgMode);
            return barcodeRenderer;
        };
        OneDimension.prototype.getDrawableSize = function (margin, w, h) {
            var topMargin = ((this.isSvgMode ? margin.bottom : margin.bottom * 1.5)
                + (this.isSvgMode ? margin.top : margin.top * 1.5));
            var rightMargin = ((this.isSvgMode ? margin.right : margin.right * 1.5)
                + (this.isSvgMode ? margin.left : margin.left * 1.5));
            var barcodeSize = new rect_1.Rect(margin.left, margin.top, (w - rightMargin), h - topMargin);
            return barcodeSize;
        };
        OneDimension.prototype.getBaseAttributes = function (width, height, offSetX, offsetY, color, string, stringSize, visibility, fontStyle) {
            var options = {
                width: width, height: height, x: offSetX, y: offsetY, color: color, string: string,
                stringSize: stringSize, visibility: visibility, fontStyle: fontStyle
            };
            if (!this.isSvgMode) {
                options.height = options.height / 1.5;
            }
            if (string && !this.isSvgMode) {
                var scaleValue = this.margin.bottom * 1.5 - this.margin.bottom;
                options.y += scaleValue;
            }
            return options;
        };
        OneDimension.prototype.getBarLineRatio = function (code, widthValue) {
            var type = this.type;
            if (type === 'Code39' || type === 'Code32' || type === 'Code39Extension' || type === 'Code11') {
                var singlewidth = code.length * ((type === 'Code39' || type === 'Code32' || type === 'Code39Extension') ? 6 : 3);
                var doublwidth = code.length * ((type === 'Code39' || type === 'Code32' || type === 'Code39Extension') ? 3 : 2) * 2;
                return (widthValue / (doublwidth + singlewidth + code.length - 1));
            }
            else if (type === 'Code128A' || type === 'Code128B' || type === 'Code128C' || type === 'Code128') {
                var lineCount = code[0].length;
                return (widthValue / (lineCount + code.length - 1));
            }
            else if (type === 'Code93Extension') {
                var count = 0;
                for (var i = 0; i < code.length; i++) {
                    var numberOfDigits = code[parseInt(i.toString(), 10)];
                    for (var j = 0; j < numberOfDigits.length; j++) {
                        count += Number(numberOfDigits[parseInt(j.toString(), 10)]);
                    }
                }
                return widthValue / count;
            }
            else {
                var lineCount = 0;
                for (var i = 0; i < code.length; i++) {
                    var numberOfDigits = code[parseInt(i.toString(), 10)].length;
                    lineCount += numberOfDigits;
                }
                var additionalValue = void 0;
                if (type === 'Ean8' || type === 'Ean13' || type === 'UpcA') {
                    additionalValue = 2;
                }
                else if (type === 'Code93') {
                    additionalValue = -code.length + 1;
                }
                return (widthValue / (additionalValue ? ((lineCount + code.length - 1) + additionalValue) : (lineCount + code.length - 1)));
            }
        };
        OneDimension.prototype.multipleWidth = function (codeValue, k, value) {
            var number;
            if (codeValue[parseInt(k.toString(), 10)] === '1' && codeValue[k + 1] === '1') {
                number = value + 1;
                return this.multipleWidth(codeValue, k + 1, number);
            }
            return value;
        };
        OneDimension.prototype.barCodeType = function (type) {
            if (type === 'Code39' || type === 'UpcE' || type === 'Code39Extension') {
                return 'twoBars';
            }
            else if (type === 'UpcA' || type === 'Ean13' || type === 'Ean8') {
                return 'threeBars';
            }
            else {
                return 'noBars';
            }
        };
        OneDimension.prototype.checkStartValueCondition = function (j, k, numberOfDigits, barType) {
            if ((j === 1 && k === 0 && barType === 'twoBars' && this.type !== 'UpcE' ||
                (((j === 0 && k === numberOfDigits - 1) || j === 2 && k === numberOfDigits - 2)
                    && (this.type === 'Ean8' || this.type === 'Ean13')))
                || (this.type === 'UpcE' && j === 2 && k === 0)
                || (this.type !== 'UpcA' && barType === 'threeBars' && (j === 2 && k === numberOfDigits - 1))
                || this.type === 'UpcA' && ((j === 1 && k === numberOfDigits - 2)
                    || (j === 3 && k === numberOfDigits - 2))
                || (barType === 'noBars' && j === 0 && k === 0)) {
                return true;
            }
            else {
                return false;
            }
        };
        OneDimension.prototype.checkEndValueCondition = function (k, j, numberOfDigits, code, temp, doublwidth) {
            var type = this.type;
            if ((k === numberOfDigits && j === code.length - 2 && (type === 'Code39' || type === 'Code39Extension'))
                || (type === 'Code11' && j === code.length - 1 && k === numberOfDigits - 1)
                || type === 'Code93Extension' && j === code.length - 1 && k === numberOfDigits - 1
                || ((type === 'Ean8') && (j === 1 && k === numberOfDigits
                    || j === code.length - 2 && k === numberOfDigits))
                || ((this.type === 'Ean13') && ((j === 2 && k === 1) || j === code.length - 2 && k === numberOfDigits))
                || (type === 'UpcA' && (j === 3 && k === 0 || j === 5 && (!temp ? (k === 1) : ((k === (doublwidth))))))
                || (type === 'UpcE' && (j === code.length - 2 && k === 1))
                || (type === 'Code93' && j === code.length - 1 && k === numberOfDigits - 1)
                || ((type !== 'Code39' && type !== 'Code39Extension'
                    && type !== 'Ean8' && type !== 'Ean13') && j === code.length - 1 && k === numberOfDigits)) {
                return true;
            }
            else {
                return false;
            }
        };
        OneDimension.prototype.getDisplayText = function (j, textProperty) {
            var text;
            if (this.type === 'Ean8') {
                text = j === 1 ? (this.value.substring(0, 4)) : (this.value.substring(4, 8));
            }
            else if (this.type === 'Ean13') {
                text = j === 2 ? (this.value.substring(1, 7)) : (this.value.substring(7));
            }
            else if (this.type === 'UpcA') {
                text = j === 3 ? ((this.value.substring(0, 6))) : (this.value.substring(6, 12));
            }
            else {
                text = textProperty.text ? textProperty.text : this.value;
            }
            return text;
        };
        OneDimension.prototype.checkExtraHeight = function (j, type, code) {
            if (((j === 0 || j === code.length - 1) && (type === 'Code39' || type === 'Code39Extension'))
                || ((type === 'Ean8' || type === 'Ean13') && (j === 0 || j === 2 || j === code.length - 1))
                || type === 'UpcA' && (j === 1 || j === code.length - 2 || j === code.length - 4)
                || type === 'UpcE' && (j === 1 || j === code.length - 2 || j === code.length - 4)) {
                return true;
            }
            else {
                return false;
            }
        };
        OneDimension.prototype.getWidthValue = function (number, width, type) {
            if (this.type !== 'Code93Extension') {
                if (number) {
                    var dividerValue = type === 'Code32' ? 3 : 2;
                    width = number % dividerValue ? 1 : 2;
                }
                else {
                    width = 1;
                }
            }
            if (this.type === 'Code93Extension') {
                if (number && !(number % 4)) {
                    width = 4;
                }
                else if (number && !(number % 2)) {
                    width = 2;
                }
                else if (number && !(number % 3)) {
                    width = 3;
                }
                else {
                    width = 1;
                }
            }
            return width;
        };
        OneDimension.prototype.calculateBarCodeAttributes = function (code, canvas, isUpcE) {
            var temp = false;
            var canDoubleWidth;
            var barcodeSize = this.getDrawableSize(this.margin, this.width, this.height);
            if (barcodeSize.height > 0 && barcodeSize.width > 0) {
                var tempBaseAttributes = void 0;
                var options = [];
                var offsetX = barcodeSize.x;
                var ratio = this.getBarLineRatio(code, barcodeSize.width);
                ratio = this.isSvgMode ? ratio : ratio / 1.5;
                var startValue = 0;
                var endValue = void 0;
                var type = this.type;
                var position = this.displayText.position;
                var scaleValue = this.isSvgMode ? 1 : 1.5;
                var textOptions = void 0;
                var textSize = void 0;
                var textHeight = void 0;
                var textProperty = void 0;
                for (var j = 0; j < code.length; j++) {
                    var codeValue = code[parseInt(j.toString(), 10)];
                    var check = (type !== 'UpcA' && type !== 'UpcE' && type !== 'Code11' && type !== 'Code93' && type !== 'Code93Extension');
                    var barType = this.barCodeType(this.type);
                    var extraHeight = this.checkExtraHeight(j, type, code);
                    var numberOfDigits = codeValue.length;
                    temp = false;
                    for (var k = 0; check ? k <= numberOfDigits : k < numberOfDigits; k++) {
                        var renderText = false;
                        if (this.checkStartValueCondition(j, k, numberOfDigits, barType)) {
                            startValue = offsetX;
                        }
                        else if (this.checkEndValueCondition(k, j, numberOfDigits, code, temp, canDoubleWidth)) {
                            endValue = offsetX;
                            if (this.type === 'UpcA' && temp && canDoubleWidth) {
                                endValue -= canDoubleWidth * ratio;
                            }
                            renderText = true;
                        }
                        var canDrawCheck = (type === 'Code39' || type === 'Code93Extension' || type === 'Code32' || type === 'Code11' || type === 'Code39Extension');
                        var candraw = canDrawCheck ? (k % 2 ? false : true) : (codeValue[parseInt(k.toString(), 10)] === '1' ? true : false);
                        var string = codeValue.toString();
                        var number = Number(string[parseInt(k.toString(), 10)]);
                        var width = void 0;
                        width = this.getWidthValue(number, width, type);
                        width = width * ratio;
                        textProperty = this.displayText;
                        var text = this.getDisplayText(j, textProperty);
                        textOptions = this.getBaseAttributes(undefined, undefined, startValue, position === 'Bottom' ? (barcodeSize.y + barcodeSize.height) + 2 : (barcodeSize.y + textHeight) - 2, this.foreColor, isUpcE || text, textProperty.size, textProperty.visibility, textProperty.font);
                        if (!textHeight) {
                            dom_util_1.createMeasureElements();
                            textSize = dom_util_1.measureText(textOptions);
                            textHeight = (textSize.height / 2) + 2;
                        }
                        if (extraHeight) {
                            tempBaseAttributes = this.getBaseAttributes(width, position === 'Top' && barType !== 'noBars' ? (barcodeSize.height - textHeight - this.displayText.margin.top) : (barcodeSize.height), offsetX, position === 'Bottom' ? barcodeSize.y : barcodeSize.y + textHeight + this.displayText.margin.top, this.foreColor);
                        }
                        if ((type === 'Ean13') && k === 0 && j === 0 && textProperty.visibility) {
                            textOptions = this.getBaseAttributes(undefined, undefined, startValue, position === 'Bottom' ? (barcodeSize.y + barcodeSize.height) + 2 : ((barcodeSize.y + textHeight + this.displayText.margin.top) - 2) - this.displayText.margin.bottom, this.foreColor, isUpcE || text, textProperty.size, textProperty.visibility, textProperty.font);
                            textOptions.string = this.value[0];
                            this.drawText(canvas, textOptions);
                        }
                        if (!extraHeight || renderText || (type === 'UpcA' && extraHeight)) {
                            var checkCode = type === 'Code39' || type === 'Code32' || type === 'Code93Extension' || type === 'Code39Extension' || type === 'Code11';
                            var value = barcodeSize.height;
                            var barCodeHeight = (((value) - textHeight * scaleValue) > 0 ? ((value) - textHeight * scaleValue) : 0);
                            if (checkCode || type === 'Ean8' || type === 'Ean13') {
                                barCodeHeight = position === 'Top' && barType !== 'noBars' ? (barCodeHeight - textHeight) : barCodeHeight;
                                var height = extraHeight ? barcodeSize.height : barCodeHeight;
                                if (this.type !== 'Code39') {
                                    height = position === 'Top' && barType !== 'noBars' ? (height - this.displayText.margin.top) - textHeight : height;
                                }
                                tempBaseAttributes = this.getBaseAttributes(width, height, offsetX, position === 'Bottom' ? barcodeSize.y : barcodeSize.y + textHeight + this.displayText.margin.top, this.foreColor);
                            }
                            if ((!checkCode || (!renderText && !checkCode)) && (!renderText || this.type !== 'UpcE')) {
                                canDoubleWidth = this.multipleWidth((codeValue), k, 1);
                                k += canDoubleWidth - 1;
                                if (canDoubleWidth > 1) {
                                    temp = true;
                                }
                                var rectWidth = canDoubleWidth > 1 ? (canDoubleWidth * width) : width;
                                var rectHeight = (barcodeSize.height - textHeight * scaleValue);
                                var height = extraHeight ? barcodeSize.height : rectHeight;
                                height = position === 'Top' && barType !== 'noBars' ? (height - this.displayText.margin.top) - textHeight : height;
                                tempBaseAttributes = this.getBaseAttributes(rectWidth, height, offsetX, position === 'Bottom' ? barcodeSize.y : barcodeSize.y + textHeight + this.displayText.margin.top, this.foreColor);
                                offsetX = canDoubleWidth > 1 ? offsetX + (canDoubleWidth * (width)) : offsetX + (1 * (width));
                            }
                            if (renderText || !extraHeight) {
                                this.verticalTextMargin(textProperty, tempBaseAttributes, textOptions);
                            }
                            if (textProperty.visibility &&
                                ((endValue && type !== 'Ean8' && type !== 'Ean13' && type !== 'UpcA' && type !== 'UpcE')
                                    || ((type === 'Ean8' || type === 'UpcA' || type === 'UpcE' || type === 'Ean13') && renderText))) {
                                if (!textProperty.margin.left && !textProperty.margin.right && (textProperty.text || type === 'UpcA')) {
                                    this.updateOverlappedTextPosition((endValue - startValue), textOptions, textSize, startValue, textProperty, endValue);
                                }
                                else {
                                    this.getAlignmentPosition(textOptions, endValue, startValue, textSize);
                                }
                                if (type === 'UpcA') {
                                    var checkVAl = (textOptions.string === this.value.substr(0, 6)) ? true : false;
                                    textOptions.string = checkVAl ? this.value.substr(0, 1) : textOptions.string.substr(0, 5);
                                    var xPosition = checkVAl ? options[0].x / 2 : options[options.length - 1].x
                                        + textOptions.stringSize;
                                    var yPosition = 0;
                                    if (checkVAl) {
                                        var tempPosition = textOptions.x;
                                        textOptions.x = xPosition;
                                        yPosition = textOptions.y;
                                        this.drawText(canvas, textOptions);
                                        textOptions.x = tempPosition;
                                        if (!this.isSvgMode) {
                                            textOptions.y = yPosition;
                                        }
                                        textOptions.string = this.value.substr(1, 5);
                                        this.updateOverlappedTextPosition((endValue - startValue), textOptions, textSize, startValue, textProperty, endValue);
                                    }
                                    else {
                                        this.updateOverlappedTextPosition((endValue - startValue), textOptions, textSize, startValue, textProperty, endValue);
                                        yPosition = textOptions.y;
                                        this.drawText(canvas, textOptions);
                                        if (!this.isSvgMode) {
                                            textOptions.y = yPosition;
                                        }
                                        textOptions.string = this.value.substr(11, 12);
                                        textOptions.x = xPosition;
                                    }
                                }
                                this.alignDisplayText(textOptions, textProperty, startValue, endValue, textSize);
                                this.drawText(canvas, textOptions);
                            }
                        }
                        if (candraw) {
                            options.push(tempBaseAttributes);
                        }
                        if (this.canIncrementCheck(type, j, code)) {
                            offsetX += (width);
                        }
                    }
                }
                this.drawImage(canvas, options);
            }
        };
        OneDimension.prototype.canIncrementCheck = function (type, j, code) {
            if ((type === 'Code39' || type === 'Code32' || type === 'Code39Extension' || type === 'Code93Extension'
                || type === 'Code11') || (type === 'UpcE' && (j === 1 || j === code.length - 2)) ||
                ((type === 'Ean8' || type === 'Ean13') && (j === 0 || j === code.length - 1 || j === 2))) {
                return true;
            }
            else {
                return false;
            }
        };
        OneDimension.prototype.verticalTextMargin = function (textProperty, tempBaseAttributes, textOptions) {
            if (textProperty.margin.top && tempBaseAttributes.height - textProperty.margin.top > 0) {
                if (textProperty.margin.top > 0 && textProperty.position === 'Bottom') {
                    tempBaseAttributes.height -= textProperty.margin.top;
                }
                else {
                    textOptions.y += textProperty.margin.top;
                }
            }
            if (textProperty.margin.bottom && tempBaseAttributes.height - textProperty.margin.bottom > 0) {
                if (textProperty.margin.bottom > 0) {
                    textOptions.y -= textProperty.margin.bottom;
                    Eif (this.displayText.position === 'Bottom') {
                        tempBaseAttributes.height -= textProperty.margin.bottom;
                    }
                }
                else {
                    textOptions.y -= textProperty.margin.bottom;
                }
            }
        };
        OneDimension.prototype.getAlignmentPosition = function (textOptions, endValue, startValue, textSize) {
            if (this.displayText.alignment === 'Center') {
                textOptions.x += (((endValue - startValue)) / 2) - textSize.width * .5;
            }
            else if (this.displayText.alignment === 'Left') {
                textOptions.x = startValue;
            }
            else {
                textOptions.x = endValue - textSize.width;
            }
        };
        OneDimension.prototype.drawImage = function (canvas, options) {
            var barcodeRenderer = this.getInstance(canvas.id);
            for (var i = 0; i < options.length; i++) {
                barcodeRenderer.renderRectElement(canvas, options[parseInt(i.toString(), 10)]);
            }
        };
        OneDimension.prototype.updateDisplayTextSize = function (options, size, endValue, startValue, textProperty) {
            if (options.x + size.width > endValue || (options.x < startValue) && options.stringSize > 2) {
                var rightAlign = options.x < startValue && textProperty.margin.right ? true : false;
                if (options.x < startValue && textProperty.margin.right) {
                    options.stringSize -= 2;
                    var newSize = dom_util_1.measureText(options);
                    options.x += (((endValue - startValue)) / 2) - newSize.width * .5;
                    var diff = textProperty.margin.right - (endValue - (options.x + size.width));
                    options.x -= diff;
                    this.updateDisplayTextSize(options, newSize, endValue, startValue, textProperty);
                }
            }
        };
        OneDimension.prototype.alignDisplayText = function (options, textProperty, startValue, endValue, size) {
            var leftMargin = false;
            if ((textProperty.margin.left || textProperty.margin.right)) {
                if (options.x - startValue < textProperty.margin.left && textProperty.margin.left) {
                    leftMargin = true;
                    var diff = textProperty.margin.left - (options.x - startValue);
                    options.x += diff;
                    this.updateDisplayTextSize(options, size, endValue, startValue, textProperty);
                }
                if ((endValue - (options.x + size.width) < textProperty.margin.right) && textProperty.margin.right && !leftMargin) {
                    var diff = textProperty.margin.right - (endValue - (options.x + size.width));
                    options.x -= diff;
                    this.updateDisplayTextSize(options, size, endValue, startValue, textProperty);
                }
                else if ((endValue - (options.x + size.width) < textProperty.margin.right)) {
                    var newSize = dom_util_1.measureText(options);
                    this.updateOverlappedTextPosition((endValue - startValue), options, newSize, startValue, textProperty, endValue);
                    this.updateDisplayTextSize(options, newSize, endValue, startValue, textProperty);
                }
            }
        };
        OneDimension.prototype.updateOverlappedTextPosition = function (width, options, size, startValue, textProperty, endValue) {
            if ((size.width > width || textProperty) && (endValue - (options.x + size.width) <= textProperty.margin.right)
                && options.stringSize > 2) {
                options.stringSize -= !textProperty ? 2 : .2;
                var newSize = dom_util_1.measureText(options);
                this.updateOverlappedTextPosition(width, options, newSize, startValue, textProperty, endValue);
            }
            else if (!textProperty.margin.left && !textProperty.margin.right && options.stringSize > 2) {
                this.getAlignmentPosition(options, endValue, startValue, size);
            }
        };
        OneDimension.prototype.drawText = function (canvas, options) {
            if (!this.isSvgMode) {
                options.y /= 1.5;
            }
            var barcodeRenderer = this.getInstance(canvas.id);
            barcodeRenderer.renderTextElement(canvas, options);
        };
        return OneDimension;
    }(barcode_base_1.BarcodeBase));
    exports.OneDimension = OneDimension;
});