Path: blob/master/node_modules/@jimp/plugin-print/dist/measure-text.js
1126 views
"use strict";12Object.defineProperty(exports, "__esModule", {3value: true4});5exports.measureText = measureText;6exports.measureTextHeight = measureTextHeight;78function measureText(font, text) {9var x = 0;1011for (var i = 0; i < text.length; i++) {12if (font.chars[text[i]]) {13var kerning = font.kernings[text[i]] && font.kernings[text[i]][text[i + 1]] ? font.kernings[text[i]][text[i + 1]] : 0;14x += (font.chars[text[i]].xadvance || 0) + kerning;15}16}1718return x;19}2021function measureTextHeight(font, text, maxWidth) {22var words = text.split(' ');23var line = '';24var textTotalHeight = font.common.lineHeight;2526for (var n = 0; n < words.length; n++) {27var testLine = line + words[n] + ' ';28var testWidth = measureText(font, testLine);2930if (testWidth > maxWidth && n > 0) {31textTotalHeight += font.common.lineHeight;32line = words[n] + ' ';33} else {34line = testLine;35}36}3738return textTotalHeight;39}40//# sourceMappingURL=measure-text.js.map4142