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
|
# File 'lib/obf/pdf.rb', line 61
def self.build_page(pdf, obj, options)
OBF::Utils.as_progress_percent(0, 1.0) do
doc_width = 11*72 - 72
doc_height = 8.5*72 - 72
default_radius = 3
text_height = 20
pdf.bounding_box([0, doc_height], :width => doc_width, :height => 100) do
if options['pages']
page_num = options['pages'][obj['id']]
pdf.add_dest("page#{page_num}", pdf.dest_fit)
end
pdf.line_width = 2
pdf.font_size 16
pdf.fill_color "eeeeee"
pdf.stroke_color "888888"
pdf.fill_and_stroke_rounded_rectangle [0, 100], 100, 100, default_radius
pdf.fill_color "6D81D1"
pdf.fill_and_stroke_polygon([5, 50], [35, 85], [35, 70], [95, 70], [95, 30], [35, 30], [35, 15])
pdf.fill_color "ffffff"
pdf.text_box "Go Back", :at => [10, 90], :width => 80, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
pdf.fill_color "ffffff"
pdf.fill_and_stroke_rounded_rectangle [110, 100], (doc_width - 200 - 20), 100, default_radius
pdf.fill_color "DDDB54"
pdf.fill_and_stroke do
pdf.move_to 160, 50
pdf.line_to 190, 70
pdf.curve_to [190, 30], :bounds => [[100, 130], [100, -30]]
pdf.line_to 160, 50
end
pdf.fill_color "444444"
pdf.text_box "Say that sentence out loud for me", :at => [210, 90], :width => (doc_width - 200 - 120), :height => 80, :align => :left, :valign => :center, :overflow => :shrink_to_fit
pdf.fill_color "eeeeee"
pdf.fill_and_stroke_rounded_rectangle [(doc_width - 100), 100], 100, 100, default_radius
pdf.fill_color "aaaaaa"
pdf.fill_and_stroke_polygon([doc_width - 100 + 5, 50], [doc_width - 100 + 35, 85], [doc_width - 100 + 95, 85], [doc_width - 100 + 95, 15], [doc_width - 100 + 35, 15])
pdf.fill_color "ffffff"
pdf.text_box "Erase", :at => [(doc_width - 100 + 10), 90], :width => 80, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
end
pdf.font_size 12
padding = 10
grid_height = doc_height - 100 - text_height - (padding * 2)
grid_width = doc_width
if obj['grid'] && obj['grid']['rows'] > 0 && obj['grid']['columns'] > 0
button_height = (grid_height - (padding * (obj['grid']['rows'] - 1))) / obj['grid']['rows'].to_f
button_width = (grid_width - (padding * (obj['grid']['columns'] - 1))) / obj['grid']['columns'].to_f
obj['grid']['order'].each_with_index do |buttons, row|
buttons.each_with_index do |button_id, col|
button = obj['buttons'].detect{|b| b['id'] == button_id }
next unless button
x = (padding * col) + (col * button_width)
y = text_height + padding - (padding * row) + grid_height - (row * button_height)
pdf.bounding_box([x, y], :width => button_width, :height => button_height) do
fill = "ffffff"
border = "eeeeee"
if button['background_color']
fill = OBF::Utils.fix_color(button['background_color'], 'hex')
end
if button['border_color']
border = OBF::Utils.fix_color(button['border_color'], 'hex')
end
pdf.fill_color fill
pdf.stroke_color border
pdf.fill_and_stroke_rounded_rectangle [0, button_height], button_width, button_height, default_radius
pdf.bounding_box([5, button_height - 5], :width => button_width - 10, :height => button_height - text_height - 5) do
image = (obj['images_hash'] || {})[button['image_id']]
if image
image_local_path = image && OBF::Utils.save_image(image, options['zipper'])
if image_local_path && File.exist?(image_local_path)
pdf.image image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center
File.unlink image_local_path
end
end
end
if options['pages'] && button['load_board']
page = options['pages'][button['load_board']['id']]
pdf.fill_color "ffffff"
pdf.stroke_color "eeeeee"
pdf.fill_and_stroke_rounded_rectangle [button_width - 25, button_height - 5], 20, text_height, 5
pdf.fill_color "000000"
pdf.formatted_text_box [{:text => page, :anchor => "page#{page}"}], :at => [button_width - 25, button_height - 5], :width => 20, :height => text_height, :align => :center, :valign => :center
end
pdf.fill_color "000000"
pdf.text_box (button['label'] || button['vocalization']).to_s, :at => [0, text_height], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit
end
index = col + (row * obj['grid']['columns'])
OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f)
end
end
end
pdf.fill_color "aaaaaa"
if OBF::PDF.
text = OBF::PDF.
pdf.formatted_text_box [{:text => text, :link => OBF::PDF.}], :at => [doc_width - 300, text_height], :width => 200, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
end
pdf.fill_color "000000"
if options['pages']
pdf.text_box options['pages'][obj['id']], :at => [doc_width - 100, text_height], :width => 100, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
end
end
end
|