Move measureTextWidths to render/canvas

This commit is contained in:
ahocevar
2018-11-13 17:32:27 +01:00
committed by Guillaume Beraudo
parent 3170355b07
commit 3d203f990e
3 changed files with 21 additions and 42 deletions

View File

@@ -324,6 +324,25 @@ export function measureTextWidth(font, text) {
}
/**
* @param {string} font Font to use for measuring.
* @param {Array<string>} lines Lines to measure.
* @param {Array<number>} widths Array will be populated with the widths of
* each line.
* @return {number} Width of the whole text.
*/
export function measureTextWidths(font, lines, widths) {
const numLines = lines.length;
let width = 0;
for (let i = 0; i < numLines; ++i) {
const currentWidth = measureTextWidth(font, lines[i]);
width = Math.max(width, currentWidth);
widths.push(currentWidth);
}
return width;
}
/**
* @param {CanvasRenderingContext2D} context Context.
* @param {number} rotation Rotation.