all files / graphics/fonts/ pdf-true-type-font.js

67.01% Statements 65/97
54.35% Branches 25/46
77.78% Functions 14/18
65.96% Lines 62/94
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                          20× 20×         20×   20× 20× 20× 20×                                                   10× 10× 10×                                                          
/* 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", "./unicode-true-type-font", "./pdf-font", "./enum", "./../../document/pdf-document", "./../enum", "./rtl-renderer"], function (require, exports, unicode_true_type_font_1, pdf_font_1, enum_1, pdf_document_1, enum_2, rtl_renderer_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfTrueTypeFont = (function (_super) {
        __extends(PdfTrueTypeFont, _super);
        function PdfTrueTypeFont(base64String, size, style) {
            var _this = _super.call(this, size) || this;
            _this.isEmbedFont = false;
            _this.isUnicode = true;
            Iif (style !== undefined) {
                _this.createFontInternal(base64String, style);
            }
            else {
                _this.createFontInternal(base64String, enum_1.PdfFontStyle.Regular);
            }
            return _this;
        }
        PdfTrueTypeFont.prototype.equalsToFont = function (font) {
            var result = false;
            return result;
        };
        PdfTrueTypeFont.prototype.getLineWidth = function (line, format) {
            var width = 0;
            Iif (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_2.PdfTextDirection.None) {
                var returnValue = this.getUnicodeLineWidth(line, width, format);
                width = returnValue.width;
            }
            else {
                width = this.fontInternal.getLineWidth(line);
            }
            var size = this.metrics.getSize(format);
            width *= (pdf_font_1.PdfFont.charSizeMultiplier * size);
            width = this.applyFormatSettings(line, format, width);
            return width;
        };
        PdfTrueTypeFont.prototype.getCharWidth = function (charCode, format) {
            var codeWidth = this.fontInternal.getCharWidth(charCode);
            var size = this.metrics.getSize(format);
            codeWidth *= (0.001 * size);
            return codeWidth;
        };
        PdfTrueTypeFont.prototype.createFontInternal = function (base64String, style) {
            this.fontInternal = new unicode_true_type_font_1.UnicodeTrueTypeFont(base64String, this.size);
            this.calculateStyle(style);
            this.initializeInternals();
        };
        PdfTrueTypeFont.prototype.calculateStyle = function (style) {
            var iStyle = this.fontInternal.ttfMetrics.macStyle;
            Iif ((style & enum_1.PdfFontStyle.Underline) !== 0) {
                iStyle |= enum_1.PdfFontStyle.Underline;
            }
            Iif ((style & enum_1.PdfFontStyle.Strikeout) !== 0) {
                iStyle |= enum_1.PdfFontStyle.Strikeout;
            }
            this.setStyle(iStyle);
        };
        PdfTrueTypeFont.prototype.initializeInternals = function () {
            var equalFont = null;
            Eif (pdf_document_1.PdfDocument.enableCache) {
                equalFont = pdf_document_1.PdfDocument.cache.search(this);
            }
            var internals = null;
            Iif (equalFont !== null && equalFont !== undefined) {
                internals = equalFont.getInternals();
                var metrics = equalFont.metrics;
                metrics = metrics.clone();
                metrics.size = this.size;
                this.metrics = metrics;
                this.fontInternal = equalFont.fontInternal;
            }
            else {
                Eif (equalFont == null) {
                    Eif (this.fontInternal instanceof unicode_true_type_font_1.UnicodeTrueTypeFont) {
                        this.fontInternal.isEmbed = this.isEmbedFont;
                    }
                    this.fontInternal.createInternals();
                    internals = this.fontInternal.getInternals();
                    this.metrics = this.fontInternal.metrics;
                }
            }
            this.metrics.isUnicodeFont = true;
            this.setInternals(internals);
        };
        PdfTrueTypeFont.prototype.setSymbols = function (text) {
            var internalFont = this.fontInternal;
            Eif (internalFont != null) {
                internalFont.setSymbols(text);
            }
        };
        Object.defineProperty(PdfTrueTypeFont.prototype, "Unicode", {
            get: function () {
                return this.isUnicode;
            },
            enumerable: true,
            configurable: true
        });
        PdfTrueTypeFont.prototype.getUnicodeLineWidth = function (line, width, format) {
            width = 0;
            var glyphIndices = null;
            var rtlRender = new rtl_renderer_1.RtlRenderer();
            var result = rtlRender.getGlyphIndex(line, this, (format.textDirection === enum_2.PdfTextDirection.RightToLeft) ? true : false, glyphIndices, true);
            var resultGlyph = result.success;
            glyphIndices = result.glyphs;
            if (resultGlyph && glyphIndices !== null) {
                var ttfReader = this.fontInternal.ttfReader;
                for (var i = 0, len = glyphIndices.length; i < len; i++) {
                    var glyphIndex = glyphIndices[i];
                    var glyph = ttfReader.getGlyph(glyphIndex);
                    if (glyph !== null && typeof glyph !== 'undefined') {
                        width += glyph.width;
                    }
                }
            }
            return { success: resultGlyph, width: width };
        };
        return PdfTrueTypeFont;
    }(pdf_font_1.PdfFont));
    exports.PdfTrueTypeFont = PdfTrueTypeFont;
});