(text: string, font: string)
| 25 | * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393 |
| 26 | */ |
| 27 | export function getTextWidth(text: string, font: string) { |
| 28 | // re-use canvas object for better performance |
| 29 | const canvas = getTextWidth['canvas'] || (getTextWidth['canvas'] = document.createElement('canvas')) |
| 30 | const context = canvas.getContext('2d') |
| 31 | context.font = font |
| 32 | const metrics = context.measureText(text) |
| 33 | return metrics.width |
| 34 | } |
| 35 | |
| 36 | export function getStringPreHeight(text: string, maxWidth: number) { |
| 37 | let pre: HTMLPreElement = getStringPreHeight['pre'] |
no outgoing calls
no test coverage detected