function newTextSizeEstimator(measureCharWidth, baseTextSize) {
baseTextSize = baseTextSize || measureCharWidth.size;
const table = buildTextWidthEstimatorTable(measureCharWidth);
const estimate = newTableBasedCharWidthEstimator(table);
return _newTextSizeEstimator(estimate, baseTextSize);
function _newTextSizeEstimator(measureCharWidth, baseTextSize) {
const index = {};
return (str, size = baseTextSize) => {
let width = str.split("").reduce((w, ch) => {
let width = index[ch];
if (!width) {
width = index[ch] = measureCharWidth(ch);
}
return width + w;
}, 0);
if (size !== baseTextSize) {
width *= size / baseTextSize;
}
return [width, size];
};
}
}