Move measureTextWidths to render/canvas
This commit is contained in:
committed by
Guillaume Beraudo
parent
3170355b07
commit
3d203f990e
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user