Version 1.4.0
This commit is contained in:
@@ -9,7 +9,7 @@ module.exports = {
|
||||
* @param {string} font the font
|
||||
*/
|
||||
applyText(canvas, text, defaultFontSize, width, font){
|
||||
const ctx = canvas.getContext("2d");
|
||||
const ctx = canvas.getContext(`2d`);
|
||||
do {
|
||||
ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
||||
} while (ctx.measureText(text).width > width);
|
||||
@@ -19,10 +19,10 @@ module.exports = {
|
||||
wrapText(ctx, text, maxWidth) {
|
||||
return new Promise(resolve => {
|
||||
if (ctx.measureText(text).width < maxWidth) return resolve([text]);
|
||||
if (ctx.measureText('W').width > maxWidth) return resolve(null);
|
||||
const words = text.split(' ');
|
||||
if (ctx.measureText(`W`).width > maxWidth) return resolve(null);
|
||||
const words = text.split(` `);
|
||||
const lines = [];
|
||||
let line = '';
|
||||
let line = ``;
|
||||
while (words.length > 0) {
|
||||
let split = false;
|
||||
while (ctx.measureText(words[0]).width >= maxWidth) {
|
||||
@@ -41,11 +41,11 @@ module.exports = {
|
||||
}
|
||||
else {
|
||||
lines.push(line.trim());
|
||||
line = '';
|
||||
line = ``;
|
||||
}
|
||||
if (words.length === 0) lines.push(line.trim());
|
||||
}
|
||||
return resolve(lines);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user