/
texfontnamesake.coffee
105 lines (93 loc) · 3.67 KB
/
texfontnamesake.coffee
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict'
############################################################################################################
CND = require 'cnd'
rpr = CND.rpr
badge = 'FONTMIRROR/TEXFONTNAMESAKE'
log = CND.get_logger 'plain', badge
debug = CND.get_logger 'debug', badge
info = CND.get_logger 'info', badge
warn = CND.get_logger 'warn', badge
alert = CND.get_logger 'alert', badge
help = CND.get_logger 'help', badge
urge = CND.get_logger 'urge', badge
whisper = CND.get_logger 'whisper', badge
echo = CND.echo.bind CND
#...........................................................................................................
types = require './types'
{ isa
validate
type_of
defaults
Failure } = types
#-----------------------------------------------------------------------------------------------------------
@partitioner = 'ː'
@latindigitnames =
0: 'zero'
1: 'one'
2: 'two'
3: 'three'
4: 'four'
5: 'five'
6: 'six'
7: 'seven'
8: 'eight'
9: 'nine'
#-----------------------------------------------------------------------------------------------------------
@escape = ( text ) ->
### See https://github.com/latex3/unicode-data; thx to https://tex.stackexchange.com/a/514731/128255 ###
validate.nonempty_text text
R = text
### replace Latin digits by partitioner plus name: ###
R = R.replace ///[0-9]///gu, ( $0 ) => @partitioner + @latindigitnames[ $0 ]
### insert partitioner between sequences of lower and upper case (aB -> aːB) ###
R = R.replace ///(\p{Ll})(\p{Lu})///gu, ( _, $1, $2 ) => $1 + @partitioner + $2
### replace each code point that is not a Unicode 'Letter' or 'Mark' with partitioner: ###
R = R.replace ///[^\p{Letter}\p{Mark}]///gu, @partitioner
### turn the result into lower case: ###
return R.toLowerCase()
############################################################################################################
if require.main is module then do =>
texts = [
'辛亥革命'
'一二三'
'¥ÄÖå'
' 、。〃〄々〇〈〉'
'、。〃〄々〇〈〉'
# ''
'Ⅶ'
'µ¶ƐⅦⓇⓈ'
'书法家超明体.ttf'
'Aleo-Bold.otf'
'Aleo-BoldItalic.otf'
'unifont_upper-12.1.03.ttf'
'Sun-ExtB.ttf'
'SUN-EXTB.TTF'
'legalnameₘ'
]
PATH = require 'path'
fontfile_extensions = 'otf|ttf|woff|woff2|ttc'
home = '/home/flow/jzr/benchmarks/assets/fontmirror/fonts'
pattern = PATH.join home, "/**/*.+(#{fontfile_extensions})"
paths = ( require 'glob' ).sync pattern
seen = {}
for path in paths
name = PATH.basename path
fontnick = @escape name
cache = seen[ fontnick ] ?= []
if cache.length isnt 0
names = cache.join ' | '
warn '^89973^', "seen: {fontnick} {names}"
else
whisper '^89973^', ( CND.lime rpr fontnick ), ( CND.white rpr name )
cache.push name
for fontnick, cache of seen
continue if cache.length is 1
names = cache.join ' | '
debug '^4446^', fontnick, names
# debug seen
# for text in texts
# debug '^89973^', ( CND.lime rpr text ), ( CND.white rpr @escape text )
# for cid in [ 0x1ff .. 0x4ff ]
# glyph = String.fromCodePoint cid
# continue unless ( glyph.match ///^[\p{Letter}\p{Mark}]$///gu )?
# debug '^3473^', ( cid.toString 16 ), ( rpr glyph )