StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics
https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
'use strict'
|
|
|
|
|
|
module.exports = kerning
|
|
|
|
|
|
var canvas = kerning.canvas = document.createElement('canvas')
|
|
var ctx = canvas.getContext('2d')
|
|
var asciiPairs = createPairs([32, 126])
|
|
|
|
kerning.createPairs = createPairs
|
|
kerning.ascii = asciiPairs
|
|
|
|
|
|
function kerning (family, o) {
|
|
if (Array.isArray(family)) family = family.join(', ')
|
|
|
|
var table = {}, pairs, fs = 16, threshold = .05
|
|
|
|
if (o) {
|
|
if (o.length === 2 && typeof o[0] === 'number') {
|
|
pairs = createPairs(o)
|
|
}
|
|
else if (Array.isArray(o)) {
|
|
pairs = o
|
|
}
|
|
else {
|
|
if (o.o) pairs = createPairs(o.o)
|
|
else if (o.pairs) pairs = o.pairs
|
|
|
|
if (o.fontSize) fs = o.fontSize
|
|
if (o.threshold != null) threshold = o.threshold
|
|
}
|
|
}
|
|
|
|
if (!pairs) pairs = asciiPairs
|
|
|
|
ctx.font = fs + 'px ' + family
|
|
|
|
for (var i = 0; i < pairs.length; i++) {
|
|
var pair = pairs[i]
|
|
var width = ctx.measureText(pair[0]).width + ctx.measureText(pair[1]).width
|
|
var kerningWidth = ctx.measureText(pair).width
|
|
if (Math.abs(width - kerningWidth) > fs * threshold) {
|
|
var emWidth = (kerningWidth - width) / fs
|
|
table[pair] = emWidth * 1000
|
|
}
|
|
}
|
|
|
|
return table
|
|
}
|
|
|
|
|
|
function createPairs (range) {
|
|
var pairs = []
|
|
|
|
for (var i = range[0]; i <= range[1]; i++) {
|
|
var leftChar = String.fromCharCode(i)
|
|
for (var j = range[0]; j < range[1]; j++) {
|
|
var rightChar = String.fromCharCode(j)
|
|
var pair = leftChar + rightChar
|
|
|
|
pairs.push(pair)
|
|
}
|
|
}
|
|
|
|
return pairs
|
|
}
|
|
|