(s: string)
| 85 | |
| 86 | // Gets the width of a string of text. Multiply by font size to get pixel width. |
| 87 | export function getTextWidth(s: string) { |
| 88 | let longestWord = ''; |
| 89 | for (let segment of s.split(/\s+/)) { |
| 90 | if (segment.length > longestWord.length) { |
| 91 | longestWord = segment; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | let width = 0; |
| 96 | for (let c of longestWord) { |
| 97 | let w = letters[c]; |
| 98 | if (w != null) { |
| 99 | width += w; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return width; |
| 104 | } |