rubypost 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -1
- data/lib/draw.rb +39 -39
- data/lib/drawable.rb +198 -208
- data/lib/graph.rb +311 -311
- data/lib/label.rb +0 -0
- data/lib/objects.rb +203 -217
- data/lib/options.rb +176 -176
- data/lib/redefine_float_to_s_for_metapost.rb +20 -11
- data/lib/revert_float_to_s.rb +13 -6
- data/lib/rubypost.rb +7 -8
- data/lib/simpleplot.rb +0 -0
- data/tests/mproof.dvi +0 -0
- data/tests/mproof.log +28 -0
- data/tests/test_circle.rb +0 -0
- data/tests/test_clip.rb +0 -0
- data/tests/test_graph.rb +1 -0
- data/tests/test_label.rb +0 -0
- data/tests/test_pair.rb +0 -0
- data/tests/test_path.rb +2 -1
- data/tests/test_picture.rb +1 -0
- data/tests/test_simpleplot.rb +0 -0
- data/tests/test_square.rb +1 -0
- data/tests/testsquare.1 +36 -0
- data/tests/testsquare.2 +42 -0
- data/tests/testsquare.3 +30 -0
- data/tests/testsquare.log +6 -0
- data/tests/testsquare.mp +20 -0
- metadata +44 -50
- data/doc/created.rid +0 -1
- data/doc/fr_class_index.html +0 -87
- data/doc/fr_file_index.html +0 -37
- data/doc/fr_method_index.html +0 -203
- data/doc/index.html +0 -24
data/lib/objects.rb
CHANGED
@@ -1,217 +1,203 @@
|
|
1
|
-
module RubyPost
|
2
|
-
|
3
|
-
#base class for rubypost
|
4
|
-
class Object
|
5
|
-
#returns the string of metapost commmands
|
6
|
-
def compile
|
7
|
-
'%compile not implemented for ' + self.class.to_s
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
#stores the macros that particular drawbles need.
|
12
|
-
#This should really be a private class.
|
13
|
-
class Macros < Object
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@inputs = Hash.new
|
17
|
-
end
|
18
|
-
|
19
|
-
#uses hash to make sure we never input same thing twice
|
20
|
-
def add_input(s)
|
21
|
-
@inputs[s] = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def compile
|
25
|
-
str = String.new
|
26
|
-
@inputs.each_key do
|
27
|
-
|k| str = str + "input " + k + ";\n"
|
28
|
-
end
|
29
|
-
str
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
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
|
-
#metapost file
|
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
|
-
end
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
#
|
190
|
-
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
#if wont print anything
|
205
|
-
def compile
|
206
|
-
#@mpsize='cm' if(@mpsize==nil)
|
207
|
-
to_s + @mpsize.to_s
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
#Add the compile functionality to Ruby String class
|
212
|
-
#it just calls to_s
|
213
|
-
class String
|
214
|
-
def compile
|
215
|
-
to_s
|
216
|
-
end
|
217
|
-
end
|
1
|
+
module RubyPost
|
2
|
+
|
3
|
+
#base class for rubypost
|
4
|
+
class Object
|
5
|
+
#returns the string of metapost commmands
|
6
|
+
def compile
|
7
|
+
'%compile not implemented for ' + self.class.to_s
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#stores the macros that particular drawbles need.
|
12
|
+
#This should really be a private class.
|
13
|
+
class Macros < Object
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@inputs = Hash.new
|
17
|
+
end
|
18
|
+
|
19
|
+
#uses hash to make sure we never input same thing twice
|
20
|
+
def add_input(s)
|
21
|
+
@inputs[s] = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def compile
|
25
|
+
str = String.new
|
26
|
+
@inputs.each_key do
|
27
|
+
|k| str = str + "input " + k + ";\n"
|
28
|
+
end
|
29
|
+
str
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
#Defines all the pictures at the front of the file
|
35
|
+
class PicturePrecompiler < Object
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@pictures = Array.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_picture(s)
|
42
|
+
@pictures.push(s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def compile
|
46
|
+
str = "picture " + @@org_picture + ";\n" + @@org_picture + " := currentpicture;\n"
|
47
|
+
@pictures.each do
|
48
|
+
|p| str = str + p.precompile + "\n"
|
49
|
+
end
|
50
|
+
str
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
#module variable to be altered by drawables that
|
56
|
+
#need a particular metapost macro input.
|
57
|
+
@@picture_precompiler = PicturePrecompiler.new
|
58
|
+
|
59
|
+
#module variable to be altered by drawables that
|
60
|
+
#need a particular metapost macro input.
|
61
|
+
@@Inputs = Macros.new
|
62
|
+
|
63
|
+
#this is the origninal metapost picture that is
|
64
|
+
#what actually gets displayed. You shouldn't use
|
65
|
+
#this name for any other picture!
|
66
|
+
@@org_picture = "ORIGINAL_PICTURE"
|
67
|
+
|
68
|
+
#metapost file
|
69
|
+
#A metapost file can contain many figures.
|
70
|
+
#Notes: Filenames cannot contain underscores for view to work! <br>
|
71
|
+
#compile_to_str has a dodgy backspace handler.
|
72
|
+
class File < Object
|
73
|
+
|
74
|
+
attr_writer :fname,
|
75
|
+
#name of div viewer program to use
|
76
|
+
:dvi_viewer,
|
77
|
+
#option for metapost command line
|
78
|
+
:metapost_options
|
79
|
+
|
80
|
+
@@start_of_file = <<END_OF_STRING
|
81
|
+
prologues := 2;
|
82
|
+
END_OF_STRING
|
83
|
+
|
84
|
+
#input 'sarith' so that metapost can read exponential notation
|
85
|
+
def initialize(fname = nil)
|
86
|
+
@figures = Array.new
|
87
|
+
@fname = fname
|
88
|
+
@dvi_viewer = 'yap'
|
89
|
+
@metapost_options = '-interaction=nonstopmode'
|
90
|
+
end
|
91
|
+
|
92
|
+
#add a new figure to this mpost file
|
93
|
+
def add_figure(f)
|
94
|
+
@figures.push(f)
|
95
|
+
end
|
96
|
+
|
97
|
+
#returns the mp file as a str
|
98
|
+
def compile_to_string
|
99
|
+
str = @@start_of_file + @@Inputs.compile
|
100
|
+
#save the original metapost picture
|
101
|
+
str = str + @@picture_precompiler.compile
|
102
|
+
@figures.each_index do
|
103
|
+
|i| str = str + 'beginfig(' + (i+1).to_s + ");\n" + @figures[i].compile + "\n"
|
104
|
+
end
|
105
|
+
str = str + "end;\n"
|
106
|
+
#remove the backspaces
|
107
|
+
strback = str.gsub(/.[\b]/, '')
|
108
|
+
if (strback==nil)
|
109
|
+
return str
|
110
|
+
else
|
111
|
+
return strback
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#writes the string of metapost commands to a file named 'fname.mp'
|
116
|
+
def compile_to_file(fname=@fname)
|
117
|
+
@fname = fname
|
118
|
+
IO::File.open(fname + '.mp','w') { |f| f.puts self.compile_to_string }
|
119
|
+
end
|
120
|
+
|
121
|
+
#calls compile_to_file and writes the
|
122
|
+
#and copmiles the metapost commands if mpost is in the path
|
123
|
+
def compile(fname=@fname)
|
124
|
+
compile_to_file(fname)
|
125
|
+
system('mpost ' + @metapost_options + ' ' + fname + '.mp')
|
126
|
+
end
|
127
|
+
|
128
|
+
#default view command is view_dvi
|
129
|
+
def view
|
130
|
+
view_dvi
|
131
|
+
end
|
132
|
+
|
133
|
+
#assumes that the file has already been compiled by metapost. ie compile_to_ps
|
134
|
+
#has already been called. This assumes that the yap viewer and tex is in your path. Install
|
135
|
+
#miktex to get these by default. <p>
|
136
|
+
#Notes: Filenames cannot contain underscores for view_dvi to work. The "tex mproof" will
|
137
|
+
#not work with underscores
|
138
|
+
def view_dvi
|
139
|
+
str = 'tex mproof'
|
140
|
+
@figures.each_index { |i| str = str + ' ' + @fname + '.' + (i+1).to_s }
|
141
|
+
system(str)
|
142
|
+
system(@dvi_viewer + ' mproof.dvi')
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
#wrapper for the metapost figure
|
148
|
+
#Figures actually become the figures that will to be viewed
|
149
|
+
class Figure < Object
|
150
|
+
|
151
|
+
def initialize
|
152
|
+
@draw_commands = Array.new
|
153
|
+
end
|
154
|
+
|
155
|
+
def add_drawable(d)
|
156
|
+
@draw_commands.push(d)
|
157
|
+
end
|
158
|
+
|
159
|
+
def compile
|
160
|
+
str = String.new
|
161
|
+
@draw_commands.each do |d|
|
162
|
+
str = str + d.compile + "\n"
|
163
|
+
end
|
164
|
+
str = str + "endfig;\n"
|
165
|
+
return str
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
#end module RubyPost
|
171
|
+
end
|
172
|
+
|
173
|
+
#Add the compile functionality to Ruby Numeric. Calling
|
174
|
+
#compile will add the cm, inch, bp metapost sizes to the
|
175
|
+
#to_s
|
176
|
+
class Numeric
|
177
|
+
def cm
|
178
|
+
@mpsize = 'cm'
|
179
|
+
self
|
180
|
+
end
|
181
|
+
def inch
|
182
|
+
@mpsize = 'inch'
|
183
|
+
self
|
184
|
+
end
|
185
|
+
def bp
|
186
|
+
@mpsize = 'bp'
|
187
|
+
self
|
188
|
+
end
|
189
|
+
#A nifty thing here is that if you dont specify the size
|
190
|
+
#if wont print anything
|
191
|
+
def compile
|
192
|
+
#@mpsize='cm' if(@mpsize==nil)
|
193
|
+
to_s + @mpsize.to_s
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
#Add the compile functionality to Ruby String class
|
198
|
+
#it just calls to_s
|
199
|
+
class String
|
200
|
+
def compile
|
201
|
+
to_s
|
202
|
+
end
|
203
|
+
end
|