Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-print/dist/measure-text.js
1126 views
1
"use strict";
2
3
Object.defineProperty(exports, "__esModule", {
4
value: true
5
});
6
exports.measureText = measureText;
7
exports.measureTextHeight = measureTextHeight;
8
9
function measureText(font, text) {
10
var x = 0;
11
12
for (var i = 0; i < text.length; i++) {
13
if (font.chars[text[i]]) {
14
var kerning = font.kernings[text[i]] && font.kernings[text[i]][text[i + 1]] ? font.kernings[text[i]][text[i + 1]] : 0;
15
x += (font.chars[text[i]].xadvance || 0) + kerning;
16
}
17
}
18
19
return x;
20
}
21
22
function measureTextHeight(font, text, maxWidth) {
23
var words = text.split(' ');
24
var line = '';
25
var textTotalHeight = font.common.lineHeight;
26
27
for (var n = 0; n < words.length; n++) {
28
var testLine = line + words[n] + ' ';
29
var testWidth = measureText(font, testLine);
30
31
if (testWidth > maxWidth && n > 0) {
32
textTotalHeight += font.common.lineHeight;
33
line = words[n] + ' ';
34
} else {
35
line = testLine;
36
}
37
}
38
39
return textTotalHeight;
40
}
41
//# sourceMappingURL=measure-text.js.map
42