UNPKG

principles-ui-components

Version:

Supporting UI controller for Tizen TV web application, which developed base on React Framework.

18 lines (14 loc) 465 B
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();