forked from sunaku/tamzen-font
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
88 lines (75 loc) · 2.83 KB
/
Rakefile
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
require 'tempfile'
require 'rake/clean'
task :default => :screenshots
CLOBBER.include 'fonts.dir', '*.bdf'
CLEAN.include '*.png'
#-----------------------------------------------------------------------------
# index
#-----------------------------------------------------------------------------
file 'fonts.dir' => [:tamzen, :powerline] do
sh 'mkfontdir'
sh 'xset', '+fp', Dir.pwd
sh 'xset', 'fp', 'rehash'
end
#-----------------------------------------------------------------------------
# fonts
#-----------------------------------------------------------------------------
desc 'Build Tamzen fonts.'
task :tamzen => 'Tamzen.rb' do
ruby 'Tamzen.rb' # this will generate Tamzen[0-9]*.bdf files
end
desc 'Build Tamzen fonts for Powerline.'
task :powerline => [:tamzen, 'bitmap-font-patcher'] do
FileList['Tamzen[0-9]*.bdf'].each do |src|
IO.popen('python bitmap-font-patcher/fontpatcher.py', 'w+') do |patcher|
rename = [/Tamzen/, '\&ForPowerline']
patcher.write File.read(src).gsub(*rename).gsub('ISO8859', 'ISO10646')
patcher.close_write
File.write src.sub(*rename), patcher.read
end
end
end
file 'bitmap-font-patcher' do
sh 'hg', 'clone', 'https://bitbucket.org/ZyX_I/bitmap-font-patcher'
end
#-----------------------------------------------------------------------------
# screenshots
#-----------------------------------------------------------------------------
desc 'Build font preview screenshots.'
task :screenshots => 'fonts.dir' do
FileList['*.bdf'].ext('png').each do |png|
Rake::Task[png].invoke
end
end
rule '.png' => ['.bdf', 'fonts.dir'] do |t|
# translate the BDF font filename into its full X11 font name
@bdf_to_x11 ||= Hash[File.readlines('fonts.dir').map(&:split)]
# assemble sample text for rendering
lines = [
'ABCDEFGHIJKLMNOPQRSTUVWXYZ 12345',
'abcdefghijklmnopqrstuvwxyz 67890',
'{}[]()<>$*-+=/#_%^@\\&|~?\'"`!,.;:',
#
# visit the following URL for Unicode code points of powerline symbols
# https://powerline.readthedocs.org/en/latest/fontpatching.html#glyph-table
#
"Illegal1i = oO0 \uE0A0 \uE0A1 \uE0A2 \uE0B0 \uE0B1 \uE0B2 \uE0B3"
]
width = lines.first.length
lines.unshift t.source.center(width)
# store sample text in a file because it's the easiest way to render
sample_text_file = Tempfile.open('screenshot')
sample_text_file.write lines.join(?\n)
sample_text_file.close
# render sample text using the source font to the destination image
sh 'xterm',
'-fg', 'black',
'-bg', 'white',
'-font', @bdf_to_x11[t.source],
'-geometry', "#{lines.first.length}x#{lines.length}",
'-e', [
'tput civis', # hide the cursor
"cat #{sample_text_file.path.inspect}", # show sample text
"import -window $WINDOWID #{t.name.inspect}", # take a screenshot
].join(' && ')
end