All files / UI_Component/common CommonAPI.js

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18        314x 314x 314x   314x 1x 1x     314x        
 
class CommonAPI {
 
    getTextWidth(textData, textSize, fontType) {
        const data = textData;
        const elem = document.createElement('CANVAS');
        const ctx = elem.getContext('2d');
        let textMetrics;
        if (ctx !== null) {
            ctx.font = `${textSize}px ${fontType}`;
            textMetrics = Math.ceil(ctx.measureText(data).width);
        }
 
        return textMetrics;
    }
}
export default new CommonAPI();