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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#!/usr/bin/env ruby
#--
# Last Change: Tue May 16 21:01:40 2006
#++
=begin rdoc
= rfont -- An example font installer
rfont uses the RFI Library for installing a family of fonts.
== Command line parameters
Usage: rfont [options] vendor/fontname FILE1 FILE2 ...
-c, --copy-fonts Also copy the font outlines
-d, --directory DIR Set base directory to DIR
--dry-run dry run, don't create any files
-m, --list-plugin list available macro support methods
-p ENCFILE read/download ENCFILE for the PostScript encoding
-s, --style STYLE Style of the font, eg. sans, roman, typewriter
--tds Put files in a TDS compliant directory hierarchy
-t ENCFILE read ENCFILE for the encoding of the vf file
multiple encodings can be given (seperated by ',')
-T ENCFILE equivalent to -p ENCFILE -t ENCFILE
-u, --use-plugin PLUGIN use plugin files PLUGIN, multiple files seperated by ','
-v, --no-vf Do not create virtual fonts for reencoding
--verbose Print more then needed on stdout
--help print this message and exit.
--version print version number and exit.
== Example usage
This is the command line I used to install the Bitstream variant of the font 'Syntax' (from the Corel Draw CD)
./rfont bitstream/syntax ../corel/hum531*afm -t ec,ts1 -p 8r -d ~/rfitexmf/ -u latex -s sans --verbose --tds -c
It works, but the <tt>.fd</tt>-file is not perfect yet.
---
Author:: Patrick Gundlach <patrick@gundla.ch>
License:: Copyright (c) 2005 Patrick Gundlach.
Released under the terms of the GNU General Public License
=end
# :enddoc:
require 'optparse'
require 'ostruct'
require 'fileutils'
require 'rfil/fontcollection'
include RFIL
options=OpenStruct.new
optionswritevf=true
fc=RFI::FontCollection.new
ret= ARGV.options { |opts|
opts.banner = "Usage: #{File.basename($0)} [options] vendor/fontname FILE1 FILE2 ..."
opts.on("-c", "--copy-fonts", "Also copy the font outlines") {
options.copyfonts=true
}
opts.on("-d DIR", "--directory", "Set base directory to DIR") { |d|
fc.set_dirs(d)
}
opts.on("--dry-run", "dry run, don't create any files") {
fc.options[:dryrun]=true
options.dryrun=true
}
opts.on("-m", "--list-plugin", "list available plugins") {
puts "The following plugins are known:"
puts fc.plugins
exit 0;
}
opts.on("-p ENCFILE", String,
"read/download ENCFILE for the PostScript encoding") {|e|
fc.mapenc = e
}
opts.on("-s STYLE", "--style", String, "Style of the font, eg. sans, roman, typewriter") { |s|
fc.style=s.to_sym
}
opts.on("--tds", "Put files in a TDS compliant directory hierarchy") {
options.tds=true
}
opts.on("-t ENCFILE",Array, "read ENCFILE for the encoding of the vf file",
"multiple encodings can be given (seperated by ',')") {|e|
fc.texenc = e
}
opts.on("-T ENCFILE",String,"equivalent to -p ENCFILE -t ENCFILE") {|e|
fc.mapenc = e
fc.texenc = e
}
opts.on("-u PLUGIN","--use-plugin",Array, "use plugin PLUGIN, multiple files seperated by ','") { |m|
options.plugin=m
}
opts.on("-v", "--no-vf", "Do not create virtual fonts for reencoding") {
fc.write_vf=false
}
opts.on("--verbose","Print more then needed on stdout") {
options.verbose=true
fc.options[:verbose]=true
}
opts.on_tail("--help","print this message and exit.") { puts opts; exit 0 }
opts.on_tail("--version","print version number and exit.") {
puts "#{File.basename($0)}: Version 0.1"
exit 0
}
opts.parse!
}
unless ret
puts "See --help for usage information"
exit(-1)
end
vendor_fontname=ARGV.shift
if vendor_fontname
options.vendor,options.fontname=vendor_fontname.split('/')
end
if options.vendor==nil or options.fontname==nil
puts "You must name vendor and fontname this way: vendor/fontname"
puts "See --help for usage information"
exit(-1)
end
fc.name=options.fontname
fc.vendor=options.vendor
fc.set_dirs(:tds=>true) if options.tds
fonts=[]
maplines=""
fontoutlinedir=File.dirname(ARGV[0])
ARGV.each { |fontname|
# puts "reading font #{File.basename(fontname)}"
f=RFI::Font.new(fc)
f.load_variant(fontname)
fonts.push f
}
fc.fonts.each { |font|
puts "Processing font #{font.defaultfm.fontname}"
font.guess_weight_variant
font.apply_ligkern_instructions(RFI::STDLIGKERN)
font.write_files(:dryrun=>options.dryrun==true,
:verbose=>false, :mapfile=>false
)
maplines << font.maplines.to_s
}
if options.copyfonts
fc.fonts.each { |font|
font.find_used_fonts.each {|varnumber|
fontmetric=font.variants[varnumber]
destdir=font.get_dir(fontmetric.outlinetype)
sourcefile=File.join(fontoutlinedir,fontmetric.fontfilename)
destfile=File.join(destdir,fontmetric.fontfilename)
puts "Copying #{sourcefile} to #{destfile}" if options.verbose
fc.ensure_dir(destdir)
unless options.dryrun
FileUtils.cp(sourcefile,destfile)
end
}
}
end
mapdir=fc.get_dir(:map)
mapfile=File.join(mapdir,options.fontname)
puts "Writing mapfile #{mapfile}" if options.verbose
unless fc.options[:dryrun]
fc.ensure_dir(mapdir)
File.open(mapfile + ".map", "w") { |f|
f << maplines
}
end
if options.plugin
options.plugin.each { |m| fc.run_plugin(m.to_sym) }
end
|