-
Notifications
You must be signed in to change notification settings - Fork 1
/
spencerian_guidelines.rb
executable file
·130 lines (120 loc) · 3.46 KB
/
spencerian_guidelines.rb
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
#!/usr/bin/env ruby
require 'prawn'
require 'prawn/measurement_extensions'
class Prawn::Document
MAIN_LINE_COLOR = "000000"
LIGHT_LINE_COLOR = "aaaaaa"
SLANT_LINE_COLOR = "aaaaff"
JOIN_LINE_COLOR = "ffaaaa"
def spencerian_stave (x_height, page_width, cursor, main_slant)
separation = 15
slant = (main_slant/180.0)*Math::PI
join_slant = ((main_slant-22)/180.0)*Math::PI
stroke_color MAIN_LINE_COLOR
stroke do
horizontal_line 0, page_width, :at => cursor
horizontal_line 0, page_width, :at => (cursor + x_height)
end
stroke_color LIGHT_LINE_COLOR
stroke do
horizontal_line 0, page_width, :at => (cursor + 3*x_height)
horizontal_line 0, page_width, :at => (cursor - 2*x_height)
end
stroke do
stroke_color SLANT_LINE_COLOR
horizontal_line 0, page_width, :at => (cursor + 2*x_height)
horizontal_line 0, page_width, :at => (cursor - x_height)
end
slant_lines = (page_width / separation.mm).to_i
y2 = cursor + 3*x_height
slant_lines.times do |i|
x1 = (separation*i).mm
y1 = cursor - 2*x_height
x2 = x1 + (5*x_height / Math::tan(slant))
stroke do
line [x1,y1], [x2,y2]
end
end
stroke_color JOIN_LINE_COLOR
join_slant_lines = (page_width / separation.mm).to_i
y2 = cursor + 3*x_height
join_slant_lines.times do |i|
x1 = (separation*i).mm + (2*x_height / Math::tan(slant))
y1 = cursor
x2 = x1 + (3*x_height / Math::tan(join_slant))
stroke do
line [x1,y1], [x2,y2]
end
end
end
def copperplate_stave (x_height, page_width, cursor, main_slant)
slant = (main_slant/180.0)*Math::PI
separation = x_height / (2 * Math::tan(slant))
stroke_color MAIN_LINE_COLOR
stroke do
horizontal_line 0, page_width, :at => cursor
horizontal_line 0, page_width, :at => (cursor + x_height)
end
stroke_color LIGHT_LINE_COLOR
stroke do
horizontal_line 0, page_width, :at => (cursor + 2.5*x_height)
horizontal_line 0, page_width, :at => (cursor - 1.5*x_height)
end
stroke do
stroke_color SLANT_LINE_COLOR
horizontal_line 0, page_width, :at => (cursor + 1.75*x_height)
horizontal_line 0, page_width, :at => (cursor - 0.75*x_height)
end
slant_lines = (page_width / separation.mm).to_i - 1
y2 = cursor + 2.5*x_height
slant_lines.times do |i|
x1 = (separation*i).mm
y1 = cursor - 1.5*x_height
x2 = x1 + (4*x_height / Math::tan(slant))
stroke do
line [x1,y1], [x2,y2]
end
end
end
end
def do_page(page_height, page_width, x_height, slant, style)
page_height = page_height.mm
page_width = page_width.mm
x_height = x_height.mm
case style
when :spencerian
title = "Spencerian"
multiplier = 5.5
when :copperplate
title = "Copperplate"
multiplier = 4.5
else
exit(-1)
end
Prawn::Document.generate("#{title}_#{x_height/1.mm}mm_#{slant} degrees.pdf",{:page_size=>"A4"}) do
font_size(9)
text "#{title} #{x_height/1.mm}mm, #{slant} degrees"
self.line_width = 0.1.mm
move_down 2.cm
stave_height = multiplier * x_height
total_staves = ((page_height - 2.cm) / stave_height).to_i - 1
total_staves.times do |i|
case style
when :spencerian then spencerian_stave(x_height, page_width, i*stave_height, slant)
when :copperplate then copperplate_stave(x_height, page_width, i*stave_height, slant)
end
move_down stave_height
end
end
end
argstyle = ARGV[0]
x_height = ARGV[1]
slant = ARGV[2]
style = case argstyle
when "c" then :copperplate
when "s" then :spencerian
else nil
end
exit unless style
puts x_height.to_f
do_page 290, 185, x_height.to_f, slant.to_f, style