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/lib/options.rb CHANGED
@@ -1,177 +1,177 @@
1
-
2
- module RubyPost
3
-
4
- #return the string s wrapped in btex etex
5
- def latex(s)
6
- 'btex ' + s + ' etex'
7
- end
8
-
9
- #options for rubypost drawables. These wrap metapose commands
10
- #such as 'withpen', 'scaled' and etc
11
- class Option < Object
12
- end
13
-
14
- #Can insert pure metapost option commands here.
15
- class CustomOption < Option
16
- def initialize
17
- @command = String.new
18
- end
19
-
20
- def initialize(c=Sting.new)
21
- @command = c
22
- end
23
-
24
- def compile
25
- @command.compile
26
- end
27
-
28
- end
29
-
30
- #wrapper for the metapost withcolor command
31
- #Except colour is now spelt correctly.
32
- class Colour < Option
33
-
34
- attr :r
35
- attr :g
36
- attr :b
37
-
38
- def initialize(r=0,g=0,b=0)
39
- @r = r
40
- @g = g
41
- @b = b
42
- end
43
-
44
- def compile
45
- 'withcolor' + '(' + @r.to_s + ',' + @g.to_s + ',' + @b.to_s + ')'
46
- end
47
-
48
- end
49
-
50
- #incorrectly spelt Colour alias
51
- class Color < Colour
52
- end
53
-
54
-
55
- #wraps the metapost withpen command
56
- class Pen < Option
57
-
58
- attr_writer :pen_type, :scale
59
-
60
- def initialize(pt='pencircle', scale = 1)
61
- @pen_type = pt
62
- @scale = scale
63
- end
64
-
65
- def compile
66
- 'withpen ' + @pen_type + ' scaled ' + @scale.compile
67
- end
68
-
69
- end
70
-
71
- #base class for options related to paths
72
- class PathOption < Option
73
- end
74
-
75
- #dased path
76
- #there are a plethora of dashing options. Only implemented
77
- #evenly at present.
78
- class Dashed < PathOption
79
-
80
- def initialize(t='evenly')
81
- @type = t
82
- end
83
-
84
- #evenly dashed line
85
- def evenly
86
- @type = 'evenly'
87
- self
88
- end
89
-
90
- #dahed line with dots inbetween dashes
91
- def withdots
92
- @type = 'withdots'
93
- self
94
- end
95
-
96
- #set the type with the metapost command s.
97
- def type(s)
98
- @type = s
99
- self
100
- end
101
-
102
- def compile
103
- 'dashed ' + @type
104
- end
105
-
106
- end
107
-
108
- #Wrapped the scaled metapost command.
109
- #Resizes the drawable.
110
- class Scale < Option
111
-
112
- attr_writer :scale
113
-
114
- def initialize(scale=1)
115
- @scale = scale
116
- end
117
-
118
- def compile
119
- 'scaled ' + @scale.compile
120
- end
121
-
122
- end
123
-
124
- #Scale alias
125
- class Scaled < Scale
126
- end
127
-
128
- #Wraps the rotated metapost command
129
- class Rotate < Option
130
-
131
- attr_writer :degrees
132
-
133
- def initialize(degrees=0)
134
- @degrees = degrees
135
- end
136
-
137
- #set the angle in radiians
138
- def radians=(rads)
139
- @degrees = 180.0*rads/Math::PI
140
- self
141
- end
142
-
143
- def compile
144
- 'rotated ' + @degrees.to_s
145
- end
146
-
147
- end
148
-
149
- #Rotate alias
150
- class Rotated < Rotate
151
- end
152
-
153
- #Wraps the metapose shifted command. <br>
154
- #The translation @t is specifed by a Pair
155
- class Translate < Option
156
-
157
- attr_writer :t
158
-
159
- def initialize(p=Pair.new)
160
- @t = p
161
- end
162
-
163
- def compile
164
- 'shifted ' + @t.compile
165
- end
166
-
167
- end
168
-
169
- #Translate alias
170
- class Shifted < Translate
171
- end
172
-
173
- #Translate alias
174
- class Shift < Translate
175
- end
176
-
1
+
2
+ module RubyPost
3
+
4
+ #return the string s wrapped in btex etex
5
+ def latex(s)
6
+ 'btex ' + s + ' etex'
7
+ end
8
+
9
+ #options for rubypost drawables. These wrap metapose commands
10
+ #such as 'withpen', 'scaled' and etc
11
+ class Option < Object
12
+ end
13
+
14
+ #Can insert pure metapost option commands here.
15
+ class CustomOption < Option
16
+ def initialize
17
+ @command = String.new
18
+ end
19
+
20
+ def initialize(c=Sting.new)
21
+ @command = c
22
+ end
23
+
24
+ def compile
25
+ @command.compile
26
+ end
27
+
28
+ end
29
+
30
+ #wrapper for the metapost withcolor command
31
+ #Except colour is now spelt correctly.
32
+ class Colour < Option
33
+
34
+ attr :r
35
+ attr :g
36
+ attr :b
37
+
38
+ def initialize(r=0,g=0,b=0)
39
+ @r = r
40
+ @g = g
41
+ @b = b
42
+ end
43
+
44
+ def compile
45
+ 'withcolor' + '(' + @r.to_s + ',' + @g.to_s + ',' + @b.to_s + ')'
46
+ end
47
+
48
+ end
49
+
50
+ #incorrectly spelt Colour alias
51
+ class Color < Colour
52
+ end
53
+
54
+
55
+ #wraps the metapost withpen command
56
+ class Pen < Option
57
+
58
+ attr_writer :pen_type, :scale
59
+
60
+ def initialize(pt='pencircle', scale = 1)
61
+ @pen_type = pt
62
+ @scale = scale
63
+ end
64
+
65
+ def compile
66
+ 'withpen ' + @pen_type + ' scaled ' + @scale.compile
67
+ end
68
+
69
+ end
70
+
71
+ #base class for options related to paths
72
+ class PathOption < Option
73
+ end
74
+
75
+ #dased path
76
+ #there are a plethora of dashing options. Only implemented
77
+ #evenly at present.
78
+ class Dashed < PathOption
79
+
80
+ def initialize(t='evenly')
81
+ @type = t
82
+ end
83
+
84
+ #evenly dashed line
85
+ def evenly
86
+ @type = 'evenly'
87
+ self
88
+ end
89
+
90
+ #dahed line with dots inbetween dashes
91
+ def withdots
92
+ @type = 'withdots'
93
+ self
94
+ end
95
+
96
+ #set the type with the metapost command s.
97
+ def type(s)
98
+ @type = s
99
+ self
100
+ end
101
+
102
+ def compile
103
+ 'dashed ' + @type
104
+ end
105
+
106
+ end
107
+
108
+ #Wrapped the scaled metapost command.
109
+ #Resizes the drawable.
110
+ class Scale < Option
111
+
112
+ attr_writer :scale
113
+
114
+ def initialize(scale=1)
115
+ @scale = scale
116
+ end
117
+
118
+ def compile
119
+ 'scaled ' + @scale.compile
120
+ end
121
+
122
+ end
123
+
124
+ #Scale alias
125
+ class Scaled < Scale
126
+ end
127
+
128
+ #Wraps the rotated metapost command
129
+ class Rotate < Option
130
+
131
+ attr_writer :degrees
132
+
133
+ def initialize(degrees=0)
134
+ @degrees = degrees
135
+ end
136
+
137
+ #set the angle in radiians
138
+ def radians=(rads)
139
+ @degrees = 180.0*rads/Math::PI
140
+ self
141
+ end
142
+
143
+ def compile
144
+ 'rotated ' + @degrees.to_s
145
+ end
146
+
147
+ end
148
+
149
+ #Rotate alias
150
+ class Rotated < Rotate
151
+ end
152
+
153
+ #Wraps the metapose shifted command. <br>
154
+ #The translation @t is specifed by a Pair
155
+ class Translate < Option
156
+
157
+ attr_writer :t
158
+
159
+ def initialize(p=Pair.new)
160
+ @t = p
161
+ end
162
+
163
+ def compile
164
+ 'shifted ' + @t.compile
165
+ end
166
+
167
+ end
168
+
169
+ #Translate alias
170
+ class Shifted < Translate
171
+ end
172
+
173
+ #Translate alias
174
+ class Shift < Translate
175
+ end
176
+
177
177
  end
@@ -1,11 +1,20 @@
1
-
2
- #metapost cannot handle expoential notation for float
3
- #strings. This redefines the Float#to_s so that it is
4
- #compatible with metapost.
5
- class Float
6
- alias_method :orig_to_s, :to_s
7
- def to_s
8
- roundedfloat = (10000.0*self).round/10000.0
9
- sprintf("%.#{5}f", roundedfloat)
10
- end
11
- end
1
+
2
+ #metapost cannot handle expoential notation for float
3
+ #strings. This redefines the Float#to_s so that it is
4
+ #compatible with metapost.
5
+ class Float
6
+ alias_method :orig_to_s, :to_s
7
+ def to_s
8
+ sprintf("%.#{5}f", self)
9
+ end
10
+ end
11
+
12
+ #metapost cannot handle the way ruby prints Rational.
13
+ #This redefines the Rational#to_s so that it is
14
+ #compatible with metapost.
15
+ class Rational
16
+ alias_method :orig_to_s, :to_s
17
+ def to_s
18
+ sprintf("%.#{5}f", self.to_f)
19
+ end
20
+ end
@@ -1,6 +1,13 @@
1
- #puts Float#to_s back to it's original state
2
- class Float
3
- def to_s
4
- orig_to_s
5
- end
6
- end
1
+ #puts Float#to_s back to it's original state
2
+ class Float
3
+ def to_s
4
+ orig_to_s
5
+ end
6
+ end
7
+
8
+ #puts Rational#to_s back to it's original state
9
+ class Rational
10
+ def to_s
11
+ orig_to_s
12
+ end
13
+ end
data/lib/rubypost.rb CHANGED
@@ -1,8 +1,7 @@
1
- #load the rest of rubypost
2
- require 'objects'
3
- require 'drawable'
4
- require 'draw'
5
- require 'options'
6
- require 'label'
7
- require 'graph'
8
- require 'simpleplot'
1
+ #load the rest of rubypost
2
+ require 'objects'
3
+ require 'drawable'
4
+ require 'draw'
5
+ require 'options'
6
+ require 'label'
7
+ require 'graph'
data/lib/simpleplot.rb CHANGED
File without changes
data/tests/mproof.dvi ADDED
Binary file
data/tests/mproof.log ADDED
@@ -0,0 +1,28 @@
1
+ This is TeX, Version 3.1415926 (TeX Live 2013/Debian) (format=tex 2014.1.26) 26 APR 2014 07:41
2
+ **mproof testsquare.1 testsquare.2
3
+ (/usr/share/texlive/texmf-dist/tex/generic/metapost/mproof.tex
4
+ (/usr/share/texlive/texmf-dist/tex/generic/epsf/epsf.tex
5
+ This is `epsf.tex' v2.7.4 <14 February 2011>
6
+ \epsffilein=\read0
7
+ \epsfframemargin=\dimen16
8
+ \epsfframethickness=\dimen17
9
+ \epsfrsize=\dimen18
10
+ \epsftmp=\dimen19
11
+ \epsftsize=\dimen20
12
+ \epsfxsize=\dimen21
13
+ \epsfysize=\dimen22
14
+ \pspoints=\dimen23
15
+ )
16
+ \m=\count26
17
+ \n=\count27
18
+ )
19
+ (testsquare.1
20
+ testsquare.1: BoundingBox: llx = -142 lly = -142 urx = 142 ury = 142
21
+ testsquare.1: scaled width = 285.0617pt scaled height = 285.0617pt
22
+ )
23
+ (testsquare.2
24
+ testsquare.2: BoundingBox: llx = -100 lly = -100 urx = 100 ury = 100
25
+ testsquare.2: scaled width = 200.74768pt scaled height = 200.74768pt
26
+ )
27
+ [1]
28
+ Output written on mproof.dvi (1 page, 520 bytes).
data/tests/test_circle.rb CHANGED
File without changes
data/tests/test_clip.rb CHANGED
File without changes
data/tests/test_graph.rb CHANGED
@@ -34,4 +34,5 @@ gd.add_label(GraphLabel.new(latex("data label"), 5).right)
34
34
  puts file.compile_to_string
35
35
  file.compile('testgraph')
36
36
 
37
+ file.dvi_viewer = 'evince'
37
38
  file.view
data/tests/test_label.rb CHANGED
File without changes
data/tests/test_pair.rb CHANGED
File without changes
data/tests/test_path.rb CHANGED
@@ -4,7 +4,8 @@ require '../lib/objects'
4
4
  require '../lib/drawable'
5
5
  require '../lib/draw'
6
6
  require '../lib/options'
7
- #require '../lib/graph'
7
+ require '../lib/label'
8
+ require '../lib/graph'
8
9
 
9
10
  include RubyPost
10
11
 
@@ -4,6 +4,7 @@ require '../lib/objects'
4
4
  require '../lib/drawable'
5
5
  require '../lib/draw'
6
6
  require '../lib/options'
7
+ require '../lib/label'
7
8
  require '../lib/graph'
8
9
 
9
10
  include RubyPost
File without changes
data/tests/test_square.rb CHANGED
@@ -4,6 +4,7 @@ require '../lib/objects'
4
4
  require '../lib/drawable'
5
5
  require '../lib/draw'
6
6
  require '../lib/options'
7
+ require '../lib/label'
7
8
  require '../lib/graph'
8
9
 
9
10
  include RubyPost
@@ -0,0 +1,36 @@
1
+ %!PS-Adobe-3.0 EPSF-3.0
2
+ %%BoundingBox: -142 -142 142 142
3
+ %%HiResBoundingBox: -141.73225 -141.73225 141.73225 141.73225
4
+ %%Creator: MetaPost 1.803
5
+ %%CreationDate: 2014.04.26:0741
6
+ %%Pages: 1
7
+ %%DocumentResources: procset mpost-minimal
8
+ %%DocumentSuppliedResources: procset mpost-minimal
9
+ %%EndComments
10
+ %%BeginProlog
11
+ %%BeginResource: procset mpost-minimal
12
+ /bd{bind def}bind def/fshow {exch findfont exch scalefont setfont show}bd
13
+ /fcp{findfont dup length dict begin{1 index/FID ne{def}{pop pop}ifelse}forall}bd
14
+ /fmc{FontMatrix dup length array copy dup dup}bd/fmd{/FontMatrix exch def}bd
15
+ /Amul{4 -1 roll exch mul 1000 div}bd/ExtendFont{fmc 0 get Amul 0 exch put fmd}bd
16
+ /ScaleFont{dup fmc 0 get Amul 0 exch put dup dup 3 get Amul 3 exch put fmd}bd
17
+ /SlantFont{fmc 2 get dup 0 eq{pop 1}if Amul FontMatrix 0 get mul 2 exch put fmd}bd
18
+ %%EndResource
19
+ %%EndProlog
20
+ %%BeginSetup
21
+ %%EndSetup
22
+ %%Page: 1 1
23
+ 0.8 0.8 0.8 setrgbcolor
24
+ newpath -141.73225 -141.73225 moveto
25
+ -141.73225 -47.24553 -141.73225 47.24553 -141.73225 141.73225 curveto
26
+ -47.24553 141.73225 47.24553 141.73225 141.73225 141.73225 curveto
27
+ 141.73225 47.24553 141.73225 -47.24553 141.73225 -141.73225 curveto
28
+ 47.24553 -141.73225 -47.24553 -141.73225 -141.73225 -141.73225 curveto closepath fill
29
+ 0 0 0 setrgbcolor
30
+ newpath -42.51968 -42.51968 moveto
31
+ -42.51968 42.51968 lineto
32
+ 42.51968 42.51968 lineto
33
+ 42.51968 -42.51968 lineto
34
+ closepath fill
35
+ showpage
36
+ %%EOF
@@ -0,0 +1,42 @@
1
+ %!PS-Adobe-3.0 EPSF-3.0
2
+ %%BoundingBox: -100 -100 100 100
3
+ %%HiResBoundingBox: -99.21259 -99.21259 99.21259 99.21259
4
+ %%Creator: MetaPost 1.803
5
+ %%CreationDate: 2014.04.26:0741
6
+ %%Pages: 1
7
+ %%DocumentResources: procset mpost-minimal
8
+ %%DocumentSuppliedResources: procset mpost-minimal
9
+ %%EndComments
10
+ %%BeginProlog
11
+ %%BeginResource: procset mpost-minimal
12
+ /bd{bind def}bind def/fshow {exch findfont exch scalefont setfont show}bd
13
+ /fcp{findfont dup length dict begin{1 index/FID ne{def}{pop pop}ifelse}forall}bd
14
+ /fmc{FontMatrix dup length array copy dup dup}bd/fmd{/FontMatrix exch def}bd
15
+ /Amul{4 -1 roll exch mul 1000 div}bd/ExtendFont{fmc 0 get Amul 0 exch put fmd}bd
16
+ /ScaleFont{dup fmc 0 get Amul 0 exch put dup dup 3 get Amul 3 exch put fmd}bd
17
+ /SlantFont{fmc 2 get dup 0 eq{pop 1}if Amul FontMatrix 0 get mul 2 exch put fmd}bd
18
+ %%EndResource
19
+ %%EndProlog
20
+ %%BeginSetup
21
+ %%EndSetup
22
+ %%Page: 1 1
23
+ gsave newpath -99.21259 -99.21259 moveto
24
+ -99.21259 -33.07187 -99.21259 33.07187 -99.21259 99.21259 curveto
25
+ -33.07187 99.21259 33.07187 99.21259 99.21259 99.21259 curveto
26
+ 99.21259 33.07187 99.21259 -33.07187 99.21259 -99.21259 curveto
27
+ 33.07187 -99.21259 -33.07187 -99.21259 -99.21259 -99.21259 curveto closepath clip
28
+ 0.8 0.8 0.8 setrgbcolor
29
+ newpath -141.73225 -141.73225 moveto
30
+ -141.73225 -47.24553 -141.73225 47.24553 -141.73225 141.73225 curveto
31
+ -47.24553 141.73225 47.24553 141.73225 141.73225 141.73225 curveto
32
+ 141.73225 47.24553 141.73225 -47.24553 141.73225 -141.73225 curveto
33
+ 47.24553 -141.73225 -47.24553 -141.73225 -141.73225 -141.73225 curveto closepath fill
34
+ 0 0 0 setrgbcolor
35
+ newpath -42.51968 -42.51968 moveto
36
+ -42.51968 42.51968 lineto
37
+ 42.51968 42.51968 lineto
38
+ 42.51968 -42.51968 lineto
39
+ closepath fill
40
+ grestore
41
+ showpage
42
+ %%EOF
@@ -0,0 +1,30 @@
1
+ %!PS-Adobe-3.0 EPSF-3.0
2
+ %%BoundingBox: -15 -15 15 15
3
+ %%HiResBoundingBox: -14.17323 -14.17323 14.17323 14.17323
4
+ %%Creator: MetaPost 1.803
5
+ %%CreationDate: 2014.04.26:0740
6
+ %%Pages: 1
7
+ %%DocumentResources: procset mpost-minimal
8
+ %%DocumentSuppliedResources: procset mpost-minimal
9
+ %%EndComments
10
+ %%BeginProlog
11
+ %%BeginResource: procset mpost-minimal
12
+ /bd{bind def}bind def/fshow {exch findfont exch scalefont setfont show}bd
13
+ /fcp{findfont dup length dict begin{1 index/FID ne{def}{pop pop}ifelse}forall}bd
14
+ /fmc{FontMatrix dup length array copy dup dup}bd/fmd{/FontMatrix exch def}bd
15
+ /Amul{4 -1 roll exch mul 1000 div}bd/ExtendFont{fmc 0 get Amul 0 exch put fmd}bd
16
+ /ScaleFont{dup fmc 0 get Amul 0 exch put dup dup 3 get Amul 3 exch put fmd}bd
17
+ /SlantFont{fmc 2 get dup 0 eq{pop 1}if Amul FontMatrix 0 get mul 2 exch put fmd}bd
18
+ %%EndResource
19
+ %%EndProlog
20
+ %%BeginSetup
21
+ %%EndSetup
22
+ %%Page: 1 1
23
+ 0 1 0 setrgbcolor
24
+ newpath -14.17323 -14.17323 moveto
25
+ -14.17323 14.17323 lineto
26
+ 14.17323 14.17323 lineto
27
+ 14.17323 -14.17323 lineto
28
+ closepath fill
29
+ showpage
30
+ %%EOF
@@ -0,0 +1,6 @@
1
+ This is MetaPost, version 1.803 (kpathsea version 6.1.1) 26 APR 2014 07:41
2
+ **testsquare.mp
3
+ (mpost.mp (/usr/share/texlive/texmf-dist/metapost/base/plain.mp
4
+ Preloading the plain mem file, version 1.004) ) (./testsquare.mp [1] [2] )
5
+ 2 output files written: testsquare.1 .. testsquare.2
6
+
@@ -0,0 +1,20 @@
1
+ prologues := 2;
2
+ picture ORIGINAL_PICTURE;
3
+ ORIGINAL_PICTURE := currentpicture;
4
+ beginfig(1);
5
+ fill ((-0.5, -0.5)--(-0.5, 0.5)--(0.5, 0.5)--(0.5, -0.5)--cycle) scaled 10cm withcolor(0.8,0.8,0.8);
6
+
7
+ fill ((-0.5, -0.5)--(-0.5, 0.5)--(0.5, 0.5)--(0.5, -0.5)--cycle) scaled 3cm withcolor(0,0,0);
8
+
9
+ endfig;
10
+
11
+ beginfig(2);
12
+ fill ((-0.5, -0.5)--(-0.5, 0.5)--(0.5, 0.5)--(0.5, -0.5)--cycle) scaled 10cm withcolor(0.8,0.8,0.8);
13
+
14
+ fill ((-0.5, -0.5)--(-0.5, 0.5)--(0.5, 0.5)--(0.5, -0.5)--cycle) scaled 3cm withcolor(0,0,0);
15
+
16
+ clip currentpicture to ((-0.5, -0.5)--(-0.5, 0.5)--(0.5, 0.5)--(0.5, -0.5)--cycle) scaled 7cm;
17
+
18
+ endfig;
19
+
20
+ end;