tweak: Change saved char widths (#13)

* tweak: Change saved char widths

* tweak: Update json widths file name and reference

* fix: Bad reference
pull/15/head
Guillaume Martigny 2018-08-23 17:43:34 +02:00 zatwierdzone przez Amio /
rodzic da5795ac13
commit f57d5125c4
5 zmienionych plików z 8 dodań i 12 usunięć

Wyświetl plik

@ -1,11 +1,7 @@
const widthsVerdana11 = require('./widths-verdana-11.json')
const SCALE = 10 // Prevent results like 60.599999999999994
const widthsVerdana110 = require('./widths-verdana-110.json')
const calcWidth = (charWidthTable) => {
const widthTable = charWidthTable.map(w => Math.round(w * SCALE))
widthTable[64] = widthTable[64] + 6 // Slightly increase width of "@" by 0.6px
const fallbackWidth = widthTable[64] // Width as "@" for overflows
const fallbackWidth = charWidthTable[64] // Width as "@" for overflows
return (text, astral) => {
if (astral) text = [...text]
@ -15,8 +11,8 @@ const calcWidth = (charWidthTable) => {
let char = ''
while (i--) {
char = text[i]
total += widthTable[char.charCodeAt()] ||
widthTable[char.normalize('NFD').charCodeAt()] ||
total += charWidthTable[char.charCodeAt()] ||
charWidthTable[char.normalize('NFD').charCodeAt()] ||
fallbackWidth
}
return total
@ -24,5 +20,5 @@ const calcWidth = (charWidthTable) => {
}
module.exports = {
Verdana11: calcWidth(widthsVerdana11)
Verdana110: calcWidth(widthsVerdana110)
}

Wyświetl plik

@ -1,4 +1,4 @@
const calcWidth = require('./calc-text-width.js').Verdana11
const calcWidth = require('./calc-text-width.js').Verdana110
const colorPresets = require('./color-presets.js')
module.exports = ({ subject, status, color, style, emoji, icon, iconWidth = 130 }) => {

Wyświetl plik

@ -1 +0,0 @@
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.9,4.3,5,9,7,12,8,3,5,5,7,9,4,5,4,5,7,7,7,7,7,7,7,7,7,7,5,5,9,9,9,6,11,7.5,7.5,7.7,8.5,7,6.3,8.5,8.3,4.6,5,7.6,6.1,9.3,8.2,8.7,6.6,8.7,7.6,7.5,6.8,8.1,7.5,11,7.5,6.8,7.5,5,5,5,9,7,7,6.6,6.9,5.7,6.9,6.6,3.9,6.9,7,3,3.8,6.5,3,11,7,6.7,6.9,6.9,4.7,5.7,4.3,7,6.5,9,6.5,6.5,5.8,7,5,7,9]

Wyświetl plik

@ -0,0 +1 @@
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,43,50,90,70,120,80,30,50,50,70,90,40,50,40,50,70,70,70,70,70,70,70,70,70,70,50,50,90,90,90,60,116,75,75,77,85,70,63,85,83,46,50,76,61,93,82,87,66,87,76,75,68,81,75,110,75,68,75,50,50,50,90,70,70,66,69,57,69,66,39,69,70,30,38,65,30,110,70,67,69,69,47,57,43,70,65,90,65,65,58,70,50,70,90]

Wyświetl plik

@ -1,5 +1,5 @@
const tap = require('tap')
const calcWidth = require('../lib/calc-text-width.js').Verdana11
const calcWidth = require('../lib/calc-text-width.js').Verdana110
tap.test('basic functions', t => {
t.ok(typeof calcWidth === 'function', 'export calcWidth function')