-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchbestfont.tcl
63 lines (60 loc) · 1.65 KB
/
searchbestfont.tcl
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
#! /usr/bin/env tclsh
#version 20240310-1130
package require struct::set
#Linux, fc-list
#https://linux.die.net/man/1/fc-list
proc searchFont {list} {
if {$::tcl_platform(platform) == "unix" } {
if {[catch {exec which fc-list} result]} {
puts "fc-list not install."
return
}
} else {
puts "no unix"
return
}
set langs $list
foreach lang $langs {
set command "fc-list :lang=$lang | grep -i '\.ttf'"
if {[catch {exec sh -c $command} result]} {
puts "lang: $lang: no Fonts found"
set uniqueFonts($lang) [list]
} else {
set lines [split $result "\n"]
set fontsForLang {}
foreach line $lines {
lappend fontsForLang $line
}
set uniqueFonts($lang) [list]
set uniqueFonts($lang) [lsort -unique $fontsForLang]
}
}
set commonFonts {}
set first 1
foreach lang $langs {
if {$first} {
set commonFonts $uniqueFonts($lang)
set first 0
} else {
set commonFonts [::struct::set intersect $commonFonts $uniqueFonts($lang)]
}
}
#proc to identify the best normal font
proc findBestRegularFont {fonts} {
foreach font $fonts {
if {[string match *":style=Regular"* $font] ||
[string match *":style=Normal"* $font] ||
[string match *":style=Book"* $font] ||
![string match *":style=Bold"* $font] && ![string match *":style=Italic"* $font]} {
return $font
}
}
return ""
}
set bestRegularFont [findBestRegularFont $commonFonts]
return [list $bestRegularFont $commonFonts]
}
set bestFont [lindex [searchFont [list en el pl pt es ru vi]] 0]
puts $bestFont
set sFont [searchFont [list zh]]
puts $sFont