2019-10-03 04:08:16 +00:00
|
|
|
// import widthsVerdana110 from './widths-verdana-110.json'
|
|
|
|
// @ts-ignore
|
2022-04-30 08:10:24 +00:00
|
|
|
const widthsVerdana110: number[] = require('./widths-verdana-110.json')
|
2018-08-22 07:15:55 +00:00
|
|
|
|
2022-04-30 08:10:24 +00:00
|
|
|
const calcWidth = (charWidthTable: number[]) => {
|
2018-08-23 15:43:34 +00:00
|
|
|
const fallbackWidth = charWidthTable[64] // Width as "@" for overflows
|
2018-07-18 16:35:09 +00:00
|
|
|
|
2018-08-24 02:57:05 +00:00
|
|
|
return ([...text]) => {
|
2018-07-18 05:59:40 +00:00
|
|
|
let total = 0
|
2018-08-24 02:52:42 +00:00
|
|
|
let charWidth = 0
|
2018-07-18 05:59:40 +00:00
|
|
|
let i = text.length
|
|
|
|
while (i--) {
|
2018-08-24 02:52:42 +00:00
|
|
|
charWidth = charWidthTable[text[i].charCodeAt()]
|
|
|
|
total += charWidth === undefined ? fallbackWidth : charWidth
|
2018-06-22 15:49:01 +00:00
|
|
|
}
|
2018-08-22 07:15:55 +00:00
|
|
|
return total
|
2018-05-30 02:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 04:08:16 +00:00
|
|
|
export const Verdana110 = calcWidth(widthsVerdana110)
|