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
|
#--
# helper.rb Last Change: Fri Jul 1 14:29:09 2005
#++
# Helper module for Font and FontCollection.
# Here we define methods that are used in Font and FontCollection.
require 'fileutils'
require 'rfil/tex/kpathsea'
module RFIL # :nodoc:
class RFI
module Helper
include TeX
def set_encarray(enc,where) #:nodoc:
if enc.instance_of?(ENC)
where.push(enc)
else
enc.each { |e|
if e.instance_of?(String)
e = e.chomp(".enc") + ".enc"
f=@kpse.open_file(e,"enc")
where.push(ENC.new(f))
f.close
elsif e.instance_of?(ENC)
where.push(e)
end
}
end
end
def set_mapenc(enc) # :nodoc:
@mapenc=enc
# nil/:none is perfectly valid
return if enc==nil or enc==:none
if enc.instance_of?(ENC)
@mapenc = enc
else
enc.find { |e|
if e.instance_of?(String)
e = e.chomp(".enc") + ".enc"
@kpse.open_file(e,"enc") { |f|
@mapenc = ENC.new(f)
}
elsif e.instance_of?(ENC)
@mapenc = e
end
}
end
end
# call-seq:
# set_dirs(string)
# set_dirs(hash)
#
# Set the base dir of all font related files. Acts only as a storage
# for the information. The automatic font installation method in
# Font#write_files uses this information. When a _string_ is passed,
# use this as the base dir for all files, when a hash is given, the
# keys must be one of <tt>:afm</tt>, <tt>:tfm</tt>,
# <tt>:vf</tt>,<tt>:map</tt>, <tt>:pfb</tt>, <tt>:tt</tt>, <tt>:tds</tt>.
def set_dirs(arg)
# tds needs testing! set vendor/fonname before/after set_dirs
types=[:afm, :tfm, :vpl, :vf, :pl, :map, :type1,:truetype, :fd, :typescript]
if arg.instance_of? String
@basedir=arg
types.each { |sym|
@dirs[sym]=arg
}
elsif arg.instance_of? Hash
if arg[:base]
@basedir=arg[:base]
end
if arg[:tds]==true
suffix = if @vendor and @name
File.join(@vendor,@name)
else
""
end
types.each { |t|
subdir= case t
when :afm
File.join("fonts/afm",suffix)
when :tfm
File.join("fonts/tfm",suffix)
when :vpl
File.join("fonts/source/vpl",suffix)
when :vf
File.join("fonts/vf",suffix)
when :pl
File.join("fonts/source/pl",suffix)
when :map
"fonts/map/dvips"
when :type1
File.join("fonts/type1",suffix)
when :truetype
File.join("fonts/truetype",suffix)
when :fd
File.join("tex/latex",suffix)
when :typescript
File.join("tex/context",suffix)
else
raise "unknown type"
end
@dirs[t] = File.join(@basedir,subdir)
}
else
arg.each { |key,value|
@dirs[key] = value
}
end
end
end
def ensure_dir(dirname) # :nodoc:
if File.exists?(dirname)
if File.directory?(dirname)
# nothing to do
else
# exists, but not dir
raise "File exists, but is not a directory: #{dirname}"
end
else
# file does not exist, we can create a directory (hopefully)
puts "Creating directory hierarchy #{dirname}" if @options[:verbose]
unless @options[:dryrun]
FileUtils.mkdir_p(dirname)
end
end
end #ensure_dir
end # helper
# options is a hash, but with lookup to a fontcollection
class Options # :nodoc:
def initialize(fontcollection)
@fc=fontcollection
@options={}
end
def [](idx)
if @options[idx]
return @options[idx]
end
if @fc
@fc.options[idx]
else
nil
end
end
def []=(idx,obj)
@options[idx]=obj
end
end
end # RFI
end
|