This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (53 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
const fs = require('fs')
const { selectedRanges, shortListOfRanges } = require('./code-point-ranges')
const Measurer = require('./measurer')
const { format, formatRange } = require('./format')
const { compact } = require('./compact')
const { eachCharOfRanges } = require('./range')
async function computeWidthsOfRanges(ranges, { verbose = true } = {}) {
const measurer = new Measurer()
await measurer.init()
let collected = []
for (const [lower, upper] of ranges) {
if (verbose) {
console.log(`Computing widths for ${formatRange(lower, upper)}`)
}
const widths = await measurer.widthOfRange([lower, upper])
const compacted = compact(widths, lower)
collected = collected.concat(compacted)
}
measurer.destroy()
return collected
}
async function computeKerning(ranges, { verbose = true } = {}) {
const measurer = new Measurer()
await measurer.init()
const eachChar = eachCharOfRanges(ranges)
const collected = []
for (const second of eachChar) {
console.log(format(second))
for (const first of eachChar) {
const kerningAdjustment = await measurer.kerningAdjustmentFor(
first,
second
)
if (kerningAdjustment) {
collected.push([first, second, kerningAdjustment])
if (verbose) {
console.log(`${format(first)} ${format(second)} ${kerningAdjustment}`)
}
}
}
}
measurer.destroy()
return collected
}
async function main() {
const widths = await computeWidthsOfRanges(selectedRanges)
// const widths = await computeWidthsOfRanges(shortListOfRanges)
fs.writeFileSync('widths.json', JSON.stringify(widths))
const kerning = await computeKerning(shortListOfRanges)
fs.writeFileSync('kerning.json', JSON.stringify(kerning))
}
;(async () => main())()