obf 0.9.8.21 → 0.9.8.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Arial.ttf +0 -0
  3. data/lib/obf/pdf.rb +168 -88
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50eeb7069d0910bcd43413ae6926ddc8e2c3dcc73d699aba08b590eca468258e
4
- data.tar.gz: ed156dbda3e5a505a9eef60a5d1696b1619820ee1a484b5ebd8372c93be49d7f
3
+ metadata.gz: 634ef9637b8b8a49071e2bd8b51dd0e72b1a51893ef72c1c747ba25f27874001
4
+ data.tar.gz: b5d17a2f08e2894bb67f8e8fcd8f7be4c23d3a17d0326e9d06e87853f3861730
5
5
  SHA512:
6
- metadata.gz: 3a1e154445ad6827a21b41fa9968b975c2dea290441fd554ce024d234f6a3f91431cddd5a6438630b47815365d67180620631ad6982da3efd528fad6f0f62a7c
7
- data.tar.gz: 289e220cdc43bc9e49fddcf65b2ffffc19802f115563b321f0e4c420c4702b70b8106f7a6769b7810538694a2ad57bc9ec80de8a9b49366384a1f814d93fd230
6
+ metadata.gz: 5cd0d799df8d154d55bd8c2616320ff449965ab797afc54785b6d28bc44a4371d7289564596219636339b74fa3078130f9bf6579a4607f1ebb41262520b341aa
7
+ data.tar.gz: 48d255a567dee72f2eb8f13a1f635842a3bfb0ad894ce4c67413e2a97b4930d090cd383d004c3bc96e548c9af9778c463657bbbff1f03e075ce381801c409606
Binary file
@@ -53,15 +53,30 @@ module OBF::PDF
53
53
  pdf.font_families['TimesNewRoman'] = {
54
54
  normal: {font: 'TimesNewRoman', file: File.expand_path('../../TimesNewRoman.ttf', __FILE__)}
55
55
  }
56
+ pdf.font_families['Arial'] = {
57
+ normal: {font: 'Arial', file: File.expand_path('../../Arial.ttf', __FILE__)}
58
+ }
56
59
  pdf.fallback_fonts = ['TimesNewRoman', 'THFahKwangBold', 'MiedingerBook']
57
60
 
58
61
  font = opts['font'] if opts['font'] && File.exists?(opts['font'])
59
- font ||= File.expand_path('../../TimesNewRoman.ttf', __FILE__)
60
- pdf.font(font) if File.exists?(font)
62
+ if font && File.exists?(font)
63
+ pdf.font(font)
64
+ else
65
+ #pdf.font('TimesNewRoman')
66
+ end
61
67
 
62
68
  multi_render_paths = []
63
69
  if obj['boards']
64
70
  multi_render = obj['boards'].length > 20
71
+ obj['backlinks'] = {}
72
+ obj['boards'].each do |board|
73
+ board['buttons'].each do |button|
74
+ if button['load_board'] && button['load_board']['id']
75
+ obj['backlinks'][button['load_board']['id']] ||= []
76
+ obj['backlinks'][button['load_board']['id']] << board['id']
77
+ end
78
+ end
79
+ end
65
80
  obj['boards'].each_with_index do |board, idx|
66
81
  started = Time.now.to_i
67
82
  OBF::Utils.log "starting pdf of board #{idx} #{board['name'] || board['id']} at #{started}"
@@ -75,7 +90,8 @@ module OBF::PDF
75
90
  pdf = Prawn::Document.new(doc_opts)
76
91
  build_page(pdf, board, {
77
92
  'zipper' => zipper,
78
- 'pages' => obj['pages'],
93
+ 'pages' => obj['pages'],
94
+ 'backlinks' => obj['backlinks'][board['id']] || [],
79
95
  'headerless' => !!opts['headerless'],
80
96
  'font' => font,
81
97
  'links' => false,
@@ -135,6 +151,7 @@ module OBF::PDF
135
151
  default_radius = 3
136
152
  text_height = 20
137
153
  header_height = 0
154
+ page_num = 0
138
155
 
139
156
  if options['pages']
140
157
  page_num = options['pages'][obj['id']]
@@ -142,37 +159,92 @@ module OBF::PDF
142
159
  end
143
160
  # header
144
161
  if !options['headerless']
145
- header_height = 100
146
- pdf.bounding_box([0, doc_height], :width => doc_width, :height => 100) do
162
+ header_height = 80
163
+ pdf.bounding_box([0, doc_height], :width => doc_width, :height => header_height) do
164
+ pdf.font('Arial')
147
165
  pdf.line_width = 2
148
166
  pdf.font_size 16
149
-
150
167
  pdf.fill_color "eeeeee"
151
168
  pdf.stroke_color "888888"
152
- pdf.fill_and_stroke_rounded_rectangle [0, 100], 100, 100, default_radius
153
- pdf.fill_color "6D81D1"
154
- pdf.fill_and_stroke_polygon([5, 50], [35, 85], [35, 70], [95, 70], [95, 30], [35, 30], [35, 15])
155
- pdf.fill_color "ffffff"
156
- text_options = {:text => "Go Back"}
157
- text_options[:anchor] = "page1" if options['links']
158
- pdf.formatted_text_box [text_options], :at => [10, 90], :width => 80, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
169
+
170
+ include_back = options['pages'] && page_num != 1
171
+ # Go Back
172
+ if include_back
173
+ x = 110
174
+ pdf.fill_and_stroke_rounded_rectangle [x, header_height], 100, header_height, default_radius
175
+ pdf.fill_color "6D81D1"
176
+ pdf.fill_and_stroke_polygon([x + 5, 45], [x + 35, 75], [x + 35, 60], [x + 95, 60], [x + 95, 30], [x + 35, 30], [x + 35, 15])
177
+ pdf.fill_color "666666"
178
+ text_options = {:text => "Go Back"}
179
+ text_options[:anchor] = "page1" if options['links']
180
+ pdf.formatted_text_box [text_options], :at => [x + 10, header_height], :width => 80, :height => 80, :align => :center, :valign => :bottom, :overflow => :shrink_to_fit
181
+ backlinks = (obj['backlinks'] || []).length > 0 ? obj['backlinks'].join(',') : '1'
182
+ pdf.fill_color "ffffff"
183
+ pdf.formatted_text_box [{:text => backlinks}], :at => [x + 10, header_height + 5], :width => 80, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
184
+ end
185
+
186
+ # Say it Out Loud
159
187
  pdf.fill_color "ffffff"
160
- pdf.fill_and_stroke_rounded_rectangle [110, 100], (doc_width - 200 - 20), 100, default_radius
188
+ shift = include_back ? 0 : 55
189
+ offset = include_back ? 110 : 55
190
+ box_shift = include_back ? 110 : 0
191
+
192
+ pdf.fill_and_stroke_rounded_rectangle [110 + box_shift, header_height], 170 + shift + shift, header_height, default_radius
161
193
  pdf.fill_color "DDDB54"
162
194
  pdf.fill_and_stroke do
163
- pdf.move_to 160, 50
164
- pdf.line_to 190, 70
165
- pdf.curve_to [190, 30], :bounds => [[100, 130], [100, -30]]
166
- pdf.line_to 160, 50
195
+ pdf.move_to 160 + offset, 40
196
+ pdf.line_to 190 + offset, 55
197
+ pdf.curve_to [125 + offset, 40], :bounds => [[180 + offset, 80], [125 + offset, 80]]
198
+ pdf.curve_to [190 + offset, 25], :bounds => [[125 + offset, 0], [180 + offset, 0]]
199
+ pdf.line_to 160 + offset, 40
167
200
  end
168
201
  pdf.fill_color "444444"
169
- 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
202
+ pdf.text_box "Say that out loud for me", :at => [210 + offset, header_height], :width => 60, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
203
+
204
+ # Start Over
205
+ x = doc_width
170
206
  pdf.fill_color "eeeeee"
171
- pdf.fill_and_stroke_rounded_rectangle [(doc_width - 100), 100], 100, 100, default_radius
172
- pdf.fill_color "aaaaaa"
173
- 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])
174
- pdf.fill_color "ffffff"
175
- pdf.text_box "Erase", :at => [(doc_width - 100 + 10), 90], :width => 80, :height => 80, :align => :center, :valign => :center, :overflow => :shrink_to_fit
207
+ pdf.fill_and_stroke_rounded_rectangle [(doc_width - x), header_height], 100, header_height, default_radius
208
+ pdf.fill_color "5c9c6d"
209
+ pdf.stroke_color "25783b"
210
+ pdf.fill_and_stroke_polygon([doc_width - x + 50, 75], [doc_width - x + 80, 50], [doc_width - x + 80, 20], [doc_width - x + 20, 20], [doc_width - x + 20, 50])
211
+ pdf.stroke_color "888888"
212
+ pdf.fill_color "666666"
213
+ pdf.text_box "Start Over", :styles => [:bold], :at => [(doc_width - x + 10), header_height], :width => 80, :height => 80, :align => :center, :valign => :bottom, :overflow => :shrink_to_fit
214
+
215
+ # Oops
216
+ x = 210
217
+ pdf.fill_color "eeeeee"
218
+ pdf.fill_and_stroke_rounded_rectangle [(doc_width - x), header_height], 100, header_height, default_radius
219
+ pdf.fill_color "6653a6"
220
+ pdf.stroke_color "554a78"
221
+ pdf.fill_and_stroke_polygon([doc_width - x + 50 - 7, 75], [doc_width - x + 50 + 7, 75], [doc_width - x + 50 + 7, 40], [doc_width - x + 50 - 7, 40])
222
+ pdf.fill_and_stroke_polygon([doc_width - x + 50 - 7, 33], [doc_width - x + 50 + 7, 33], [doc_width - x + 50 + 7, 20], [doc_width - x + 50 - 7, 20])
223
+ pdf.stroke_color "888888"
224
+ pdf.fill_color "666666"
225
+ pdf.text_box "Oops", :at => [(doc_width - x + 10), header_height], :width => 80, :height => 80, :align => :center, :valign => :bottom, :overflow => :shrink_to_fit
226
+
227
+ # Stop
228
+ x = 320
229
+ pdf.fill_color "eeeeee"
230
+ pdf.fill_and_stroke_rounded_rectangle [(doc_width - x), header_height], 100, header_height, default_radius
231
+ pdf.fill_color "944747"
232
+ pdf.stroke_color "693636"
233
+ pdf.fill_and_stroke_polygon([doc_width - x + 39, 70], [doc_width - x + 61, 70], [doc_width - x + 75, 56], [doc_width - x + 75, 34], [doc_width - x + 61, 20], [doc_width - x + 39, 20], [doc_width - x + 25, 34], [doc_width - x + 25, 56])
234
+ pdf.stroke_color "888888"
235
+ pdf.fill_color "666666"
236
+ pdf.text_box "Stop", :at => [(doc_width - x + 10), header_height], :width => 80, :height => 80, :align => :center, :valign => :bottom, :overflow => :shrink_to_fit
237
+
238
+ # Clear
239
+ x = 100
240
+ pdf.fill_color "eeeeee"
241
+ pdf.fill_and_stroke_rounded_rectangle [(doc_width - x), header_height], 100, header_height, default_radius
242
+ pdf.stroke_color "666666"
243
+ pdf.fill_color "888888"
244
+ pdf.fill_and_stroke_polygon([doc_width - x + 10, 45], [doc_width - x + 35, 70], [doc_width - x + 90, 70], [doc_width - x + 90, 20], [doc_width - x + 35, 20])
245
+ pdf.stroke_color "888888"
246
+ pdf.fill_color "666666"
247
+ pdf.text_box "Clear", :at => [(doc_width - x + 10), header_height], :width => 80, :height => 80, :align => :center, :valign => :bottom, :overflow => :shrink_to_fit
176
248
  end
177
249
  end
178
250
 
@@ -219,7 +291,7 @@ module OBF::PDF
219
291
  end
220
292
  end
221
293
  blocks << block if block
222
- OBF::Utils.log(" final block #{block.to_json}")
294
+ # OBF::Utils.log(" final block #{block.to_json}")
223
295
  blocks.each_with_index do |block, idx|
224
296
  threads = []
225
297
  OBF::Utils.log(" block #{idx}")
@@ -253,82 +325,89 @@ module OBF::PDF
253
325
  obj['grid']['order'].each_with_index do |buttons, row|
254
326
  buttons.each_with_index do |button_id, col|
255
327
  button = obj['buttons'].detect{|b| b['id'] == button_id }
256
- next if !button || button['hidden'] == true
328
+ blank_button = (!button || button['hidden'] == true)
329
+ next if options['skip_blank'] && blank_button
257
330
  x = (padding * col) + (col * button_width)
258
331
  y = text_height + padding - (padding * row) + grid_height - (row * button_height)
259
332
  pdf.bounding_box([x, y], :width => button_width, :height => button_height) do
260
333
  fill = "ffffff"
261
334
  border = "eeeeee"
262
- if button['background_color']
335
+ if !blank_button && button['background_color']
263
336
  fill = OBF::Utils.fix_color(button['background_color'], 'hex')
264
337
  end
265
- if button['border_color']
338
+ if !blank_button && button['border_color']
266
339
  border = OBF::Utils.fix_color(button['border_color'], 'hex')
267
340
  end
268
341
  pdf.fill_color fill
269
342
  pdf.stroke_color border
270
343
  pdf.fill_and_stroke_rounded_rectangle [0, button_height], button_width, button_height, default_radius
271
- vertical = options['text_on_top'] ? button_height - text_height : button_height - 5
344
+ if !blank_button
345
+ vertical = options['text_on_top'] ? button_height - text_height : button_height - 5
272
346
 
273
- text = (button['label'] || button['vocalization']).to_s
274
- font = options['font']
275
- # Nepali text isn't working as a fallback for some reason, it says "bad font family"
276
- if text.match(Regexp.new("[" + NEPALI_ALPHABET + "]"))
277
- font = File.expand_path('../../MiedingerBook.ttf', __FILE__)
278
- end
279
- pdf.font(font) if font && File.exists?(font)
280
- direction = text.match(rtl_regex) ? :rtl : :ltr
281
- if options['text_case'] == 'upper'
282
- text = text.upcase
283
- elsif options['text_case'] == 'lower'
284
- text = text.downcase
285
- end
286
- text_color = OBF::Utils.fix_color(fill, 'contrast')
287
-
288
- if options['text_only']
289
- # render text
290
- pdf.fill_color text_color
291
- pdf.text_box text, :at => [0, 0], :width => button_width, :height => button_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
292
- else
293
- # render image
294
- pdf.bounding_box([5, vertical], :width => button_width - 10, :height => button_height - text_height - 5) do
295
- image = (obj['images_hash'] || {})[button['image_id']]
296
- if image
297
- bg = 'white'
298
- if options['transparent_background'] || options['symbol_background'] == 'transparent'
299
- bg = "\##{fill}"
300
- elsif options['symbol_background'] == 'black'
301
- bg = 'black'
302
- end
303
- image['threadable'] = false
304
- image_local_path = image['local_path'] if image && image['local_path'] && File.exist?(image['local_path'])
305
- image_local_path ||= image && OBF::Utils.save_image(image, options['zipper'], bg)
306
- if image_local_path && File.exist?(image_local_path)
307
- pdf.image(image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center) rescue nil
308
- File.unlink image_local_path
309
- else
310
- OBF::Utils.log(" missing image #{image['id']} #{image_local_path}")
347
+ text = (button['label'] || button['vocalization']).to_s
348
+ font = options['font']
349
+ # Nepali text isn't working as a fallback for some reason, it says "bad font family"
350
+ if text.match(Regexp.new("[" + NEPALI_ALPHABET + "]"))
351
+ font = File.expand_path('../../MiedingerBook.ttf', __FILE__)
352
+ end
353
+ if font && File.exists?(font)
354
+ pdf.font(font)
355
+ else
356
+ pdf.font('TimesNewRoman')
357
+ end
358
+ direction = text.match(rtl_regex) ? :rtl : :ltr
359
+ if options['text_case'] == 'upper'
360
+ text = text.upcase
361
+ elsif options['text_case'] == 'lower'
362
+ text = text.downcase
363
+ end
364
+ text_color = OBF::Utils.fix_color(fill, 'contrast')
365
+
366
+ if options['text_only']
367
+ # render text
368
+ pdf.fill_color text_color
369
+ pdf.text_box text, :at => [0, 0], :width => button_width, :height => button_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
370
+ else
371
+ # render image
372
+ pdf.bounding_box([5, vertical], :width => button_width - 10, :height => button_height - text_height - 5) do
373
+ image = (obj['images_hash'] || {})[button['image_id']]
374
+ if image
375
+ bg = 'white'
376
+ if options['transparent_background'] || options['symbol_background'] == 'transparent'
377
+ bg = "\##{fill}"
378
+ elsif options['symbol_background'] == 'black'
379
+ bg = 'black'
380
+ end
381
+ image['threadable'] = false
382
+ image_local_path = image['local_path'] if image && image['local_path'] && File.exist?(image['local_path'])
383
+ image_local_path ||= image && OBF::Utils.save_image(image, options['zipper'], bg)
384
+ if image_local_path && File.exist?(image_local_path)
385
+ pdf.image(image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center) rescue nil
386
+ File.unlink image_local_path
387
+ else
388
+ OBF::Utils.log(" missing image #{image['id']} #{image_local_path}")
389
+ end
311
390
  end
312
391
  end
313
- end
314
- if options['pages'] && button['load_board']
315
- page = options['pages'][button['load_board']['id']]
316
- if page
317
- page_vertical = options['text_on_top'] ? -2 + text_height : button_height + 2
318
- pdf.fill_color "ffffff"
319
- pdf.stroke_color "eeeeee"
320
- pdf.fill_and_stroke_rounded_rectangle [button_width - 18, page_vertical], 20, text_height, 5
321
- pdf.fill_color text_color
322
- text_options = {:text => page}
323
- text_options[:anchor] = "page#{page}" if options['links']
324
- pdf.formatted_text_box [text_options], :at => [button_width - 18, page_vertical], :width => 20, :height => text_height, :align => :center, :valign => :center
392
+ if options['pages'] && button['load_board']
393
+ page = options['pages'][button['load_board']['id']]
394
+ if page
395
+ page_vertical = options['text_on_top'] ? -2 + text_height : button_height + 2
396
+ pdf.fill_color "ffffff"
397
+ pdf.stroke_color "eeeeee"
398
+ pdf.fill_and_stroke_rounded_rectangle [button_width - 18, page_vertical], 20, text_height, 5
399
+ pdf.fill_color text_color
400
+ text_options = {:text => page}
401
+ text_options[:anchor] = "page#{page}" if options['links']
402
+ pdf.formatted_text_box [text_options], :at => [button_width - 18, page_vertical], :width => 20, :height => text_height, :align => :center, :valign => :center
403
+ end
325
404
  end
405
+
406
+ # render text
407
+ pdf.fill_color text_color
408
+ vertical = options['text_on_top'] ? button_height : text_height
409
+ pdf.text_box text, :at => [0, vertical], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
326
410
  end
327
-
328
- # render text
329
- pdf.fill_color text_color
330
- vertical = options['text_on_top'] ? button_height : text_height
331
- pdf.text_box text, :at => [0, vertical], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
332
411
  end
333
412
  pdf.font(options['font']) if options['font'] && File.exists?(options['font'])
334
413
  end
@@ -339,10 +418,11 @@ module OBF::PDF
339
418
  end
340
419
 
341
420
  # footer
342
- pdf.fill_color "aaaaaa"
343
- if OBF::PDF.footer_text
344
- text = OBF::PDF.footer_text
345
- pdf.formatted_text_box [{:text => text, :link => OBF::PDF.footer_url}], :at => [doc_width - 300, text_height], :width => 200, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
421
+ pdf.fill_color "bbbbbb"
422
+ if OBF::PDF.footer_text || obj['name']
423
+ text = [obj['name'], OBF::PDF.footer_text].compact.join(', ')
424
+ offset = options['pages'] ? 400 : 300
425
+ pdf.formatted_text_box [{:text => text, :link => OBF::PDF.footer_url}], :at => [doc_width - offset, text_height], :width => 300, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
346
426
  end
347
427
  pdf.fill_color "000000"
348
428
  if options['pages']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.21
4
+ version: 0.9.8.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2020-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -145,6 +145,7 @@ extra_rdoc_files:
145
145
  files:
146
146
  - LICENSE
147
147
  - README.md
148
+ - lib/Arial.ttf
148
149
  - lib/MiedingerBook.ttf
149
150
  - lib/THFahKwangBold.ttf
150
151
  - lib/TimesNewRoman.ttf