obf 0.9.9.1 → 0.9.9.2

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/obf/external.rb +82 -69
  3. data/lib/obf/pdf.rb +80 -77
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2516fbb23f12e3378fa47cc3c61cae145104a2c2595022db3026c26e944f4a12
4
- data.tar.gz: b5087e0ee7223306ba60ce4503b3293f3e0dfe8e3de2f206e3f31d833ed349be
3
+ metadata.gz: 49734c92d9d154f254416ecff17f6a04503b5afc2d340d3ceb7f94ec89b6f82b
4
+ data.tar.gz: bfff105ec7b48a2eeb746b8d437c3f6d245d75b499bbc4feae142548a2b43f82
5
5
  SHA512:
6
- metadata.gz: 274d446b05caab4279d2a9acb563e7322b8e57521a9c2da386daa0da50057ee4f96b5d07cb1f832b012a60add50c08db803c894fbd6a6770bcf5831b3fbf08fb
7
- data.tar.gz: 67bfaba475aaa1c882e3a0b705790f26b9fe90bd94cfeb77468f329404b20e7d1f0a78593c5181449dc6b4ccd82a06fcaec05b9767d7e5cc810bfaa8f713b45f
6
+ metadata.gz: cc6e780f1b371e4c87dbb42e039410605a27c1bc6ee8753a907badb3953a841b26f0c907ac1c530f1c2344dd4186e59d194b76fb179c6ae2bbe8516665bfbbde
7
+ data.tar.gz: dacb2ff2fdcebabbbb918ff047c241efe6c36d1d35710f0c1cfa2f9c2c16015cb39796fe984a131e7d8320dc7f221492a9b104e7917253392ea5d69f22fbf5ae
data/lib/obf/external.rb CHANGED
@@ -41,81 +41,85 @@ module OBF::External
41
41
  buttons = hash['buttons'] #board.settings['buttons']
42
42
  button_count = buttons.length
43
43
 
44
- buttons.each_with_index do |original_button, idx|
45
- button = {
46
- 'id' => original_button['id'],
47
- 'label' => original_button['label'],
48
- 'vocalization' => original_button['vocalization'],
49
- 'action' => original_button['action'],
50
- 'actions' => original_button['actions'],
51
- 'left' => original_button['left'],
52
- 'top' => original_button['top'],
53
- 'width' => original_button['width'],
54
- 'height' => original_button['height'],
55
- 'border_color' => OBF::Utils.fix_color(original_button['border_color'] || "#aaa", 'rgb'),
56
- 'background_color' => OBF::Utils.fix_color(original_button['background_color'] || "#fff", 'rgb')
57
- }
58
- if original_button['load_board']
59
- button['load_board'] = {
60
- 'id' => original_button['load_board']['id'],
61
- 'url' => original_button['load_board']['url'],
62
- 'data_url' => original_button['load_board']['data_url']
44
+ OBF::Utils.as_progress_percent(0.0, 0.3) do
45
+ buttons.each_with_index do |original_button, idx|
46
+ button = {
47
+ 'id' => original_button['id'],
48
+ 'label' => original_button['label'],
49
+ 'vocalization' => original_button['vocalization'],
50
+ 'action' => original_button['action'],
51
+ 'actions' => original_button['actions'],
52
+ 'left' => original_button['left'],
53
+ 'top' => original_button['top'],
54
+ 'width' => original_button['width'],
55
+ 'height' => original_button['height'],
56
+ 'border_color' => OBF::Utils.fix_color(original_button['border_color'] || "#aaa", 'rgb'),
57
+ 'background_color' => OBF::Utils.fix_color(original_button['background_color'] || "#fff", 'rgb')
63
58
  }
64
- if path_hash && path_hash['included_boards'] && path_hash['included_boards'][original_button['load_board']['id']]
65
- button['load_board']['path'] = "board_#{original_button['load_board']['id']}.obf"
59
+ if original_button['load_board']
60
+ button['load_board'] = {
61
+ 'id' => original_button['load_board']['id'],
62
+ 'url' => original_button['load_board']['url'],
63
+ 'data_url' => original_button['load_board']['data_url']
64
+ }
65
+ if path_hash && path_hash['included_boards'] && path_hash['included_boards'][original_button['load_board']['id']]
66
+ button['load_board']['path'] = "board_#{original_button['load_board']['id']}.obf"
67
+ end
66
68
  end
67
- end
68
- if original_button['translations']
69
- original_button['translations'].each do |loc, hash|
70
- next unless hash.is_a?(Hash)
71
- button['translations'] ||= {}
72
- button['translations'][loc] ||= {}
73
- button['translations'][loc]['label'] = hash['label'].to_s if hash['label']
74
- button['translations'][loc]['vocalization'] = hash['vocalization'].to_s if hash['vocalization']
75
- (hash['inflections'] || {}).each do |key, val|
76
- if key.match(/^ext_/)
77
- button['translations'][loc]['inflections'] ||= {}
78
- button['translations'][loc]['inflections'][key] = val
79
- else
80
- button['translations'][loc]['inflections'] ||= {}
81
- button['translations'][loc]['inflections'][key] = val.to_s
69
+ if original_button['translations']
70
+ original_button['translations'].each do |loc, hash|
71
+ next unless hash.is_a?(Hash)
72
+ button['translations'] ||= {}
73
+ button['translations'][loc] ||= {}
74
+ button['translations'][loc]['label'] = hash['label'].to_s if hash['label']
75
+ button['translations'][loc]['vocalization'] = hash['vocalization'].to_s if hash['vocalization']
76
+ (hash['inflections'] || {}).each do |key, val|
77
+ if key.match(/^ext_/)
78
+ button['translations'][loc]['inflections'] ||= {}
79
+ button['translations'][loc]['inflections'][key] = val
80
+ else
81
+ button['translations'][loc]['inflections'] ||= {}
82
+ button['translations'][loc]['inflections'][key] = val.to_s
83
+ end
84
+ end
85
+ hash.keys.each do |key|
86
+ button['translations'][loc][key] = hash[key] if key.to_s.match(/^ext_/)
82
87
  end
83
- end
84
- hash.keys.each do |key|
85
- button['translations'][loc][key] = hash[key] if key.to_s.match(/^ext_/)
86
88
  end
87
89
  end
88
- end
89
- if original_button['hidden']
90
- button['hidden'] = original_button['hidden']
91
- end
92
- if original_button['url']
93
- button['url'] = original_button['url']
94
- end
95
- original_button.each do|key, val|
96
- if key.match(/^ext_/)
97
- button[key] = val
90
+ if original_button['hidden']
91
+ button['hidden'] = original_button['hidden']
92
+ end
93
+ if original_button['url']
94
+ button['url'] = original_button['url']
95
+ end
96
+ original_button.each do|key, val|
97
+ if key.match(/^ext_/)
98
+ button[key] = val
99
+ end
98
100
  end
99
- end
100
101
 
101
- if original_button['image_id'] && hash['images']
102
- image = hash['images'].detect{|i| i['id'] == original_button['image_id']}
103
- if image
104
- images << image
105
- button['image_id'] = image['id']
102
+ if original_button['image_id'] && hash['images']
103
+ image = hash['images'].detect{|i| i['id'] == original_button['image_id']}
104
+ if image
105
+ images << image
106
+ button['image_id'] = image['id']
107
+ end
106
108
  end
107
- end
108
- if original_button['sound_id']
109
- sound = hash['sounds'].detect{|s| s['id'] == original_button['sound_id']}
110
- if sound
111
- sounds << sound
112
- button['sound_id'] = sound['id']
109
+ if original_button['sound_id']
110
+ sound = hash['sounds'].detect{|s| s['id'] == original_button['sound_id']}
111
+ if sound
112
+ sounds << sound
113
+ button['sound_id'] = sound['id']
114
+ end
113
115
  end
116
+ res['buttons'] << trim_empties(button)
117
+ OBF::Utils.update_current_progress(idx.to_f / button_count.to_f, "generated button #{button['id']} for #{res['id']}")
114
118
  end
115
- res['buttons'] << trim_empties(button)
116
- OBF::Utils.update_current_progress(idx.to_f / button_count.to_f)
117
119
  end
118
120
 
121
+ OBF::Utils.update_current_progress(0.35, "images for board #{res['id']}")
122
+
119
123
  # board_id 1_527892 has some svg's still, not pre-rasterized versions
120
124
  # 1_531854 convert-im6.q16: non-conforming drawing primitive definition `Helvetica''' @ error/draw.c/DrawImage/3265.
121
125
  if to_include[:images]
@@ -215,6 +219,7 @@ module OBF::External
215
219
 
216
220
  end
217
221
 
222
+ OBF::Utils.update_current_progress(0.75, "sounds for board #{res['id']}")
218
223
  if to_include[:sounds]
219
224
  sounds.each do |original_sound|
220
225
  sound = {
@@ -266,6 +271,8 @@ module OBF::External
266
271
  end
267
272
  end
268
273
 
274
+ OBF::Utils.update_current_progress(0.85, "grid for board #{res['id']}")
275
+
269
276
  res['grid'] = OBF::Utils.parse_grid(hash['grid']) # TODO: more robust parsing here
270
277
  if path_hash && path_hash['zip']
271
278
  zip_path = "board_#{res['id']}.obf"
@@ -278,6 +285,7 @@ module OBF::External
278
285
  File.open(dest_path, 'w') {|f| f.write(JSON.pretty_generate(res)) }
279
286
  end
280
287
  OBF::Utils.log(" done compressing board #{res['name'] || res['id']}")
288
+ OBF::Utils.update_current_progress(1.0, "done for board #{res['id']}")
281
289
  return dest_path
282
290
  end
283
291
 
@@ -333,6 +341,8 @@ module OBF::External
333
341
  content['images'] ||= boards.map{|b| b['images'] }.flatten.uniq
334
342
  content['sounds'] ||= boards.map{|b| b['sounds'] }.flatten.uniq
335
343
  root_board = boards[0]
344
+ incr = 1.0 / boards.length.to_f
345
+ tally = 0.0
336
346
  OBF::Utils.build_zip(dest_path) do |zipper|
337
347
  paths['zip'] = zipper
338
348
  paths['included_boards'] = {}
@@ -340,12 +350,15 @@ module OBF::External
340
350
  paths['included_boards'][b['id']] = b
341
351
  end
342
352
  boards.each do |b|
343
- b = paths['included_boards'][b['id']]
344
- if b
345
- b['images'] = content['images'] || []
346
- b['sounds'] = content['sounds'] || []
347
- to_obf(b, nil, paths, opts[:to_include])
353
+ OBF::Utils.as_progress_percent(tally, tally + incr) do
354
+ b = paths['included_boards'][b['id']]
355
+ if b
356
+ b['images'] = content['images'] || []
357
+ b['sounds'] = content['sounds'] || []
358
+ to_obf(b, nil, paths, opts[:to_include])
359
+ end
348
360
  end
361
+ tally += incr
349
362
  end
350
363
  manifest = {
351
364
  'format' => OBF::OBF::FORMAT,
@@ -424,7 +437,7 @@ module OBF::External
424
437
  end
425
438
  tmp_path = OBF::Utils.temp_path("stash")
426
439
  if opts['packet']
427
- OBF::Utils.as_progress_percent(0, 0.3) do
440
+ OBF::Utils.as_progress_percent(0.1, 0.3) do
428
441
  opts[:to_include] = {images: true}
429
442
  OBF::External.to_obz(board, tmp_path, opts)
430
443
  end
data/lib/obf/pdf.rb CHANGED
@@ -63,84 +63,84 @@ module OBF::PDF
63
63
  end
64
64
 
65
65
  def self.build_pdf(obj, dest_path, zipper, opts={})
66
- OBF::Utils.as_progress_percent(0, 1.0) do
67
- # parse obf, draw as pdf
68
- doc_opts = {
69
- :page_layout => :landscape,
70
- :page_size => [8.5*72, 11*72],
71
- :info => {
72
- :Title => obj['name']
73
- }
66
+ # parse obf, draw as pdf
67
+ doc_opts = {
68
+ :page_layout => :landscape,
69
+ :page_size => [8.5*72, 11*72],
70
+ :info => {
71
+ :Title => obj['name']
74
72
  }
75
- pdf = Prawn::Document.new(doc_opts)
76
- default_font = load_fonts(pdf, opts)
77
-
78
- multi_render_paths = []
79
- if obj['boards']
80
- multi_render = obj['boards'].length > 20 && `which gs`.length > 0
81
- obj['backlinks'] = {}
82
- if obj['pages']
83
- obj['boards'].each do |board|
84
- board['buttons'].each do |button|
85
- if button['load_board'] && button['load_board']['id']
86
- obj['backlinks'][button['load_board']['id']] ||= []
87
- obj['backlinks'][button['load_board']['id']] << obj['pages'][board['id']] if obj['pages'][board['id']]
88
- end
73
+ }
74
+ pdf = Prawn::Document.new(doc_opts)
75
+ default_font = load_fonts(pdf, opts)
76
+
77
+ multi_render_paths = []
78
+ if obj['boards']
79
+ multi_render = obj['boards'].length > 20 && `which gs`.length > 0
80
+ obj['backlinks'] = {}
81
+ if obj['pages']
82
+ obj['boards'].each do |board|
83
+ board['buttons'].each do |button|
84
+ if button['load_board'] && button['load_board']['id']
85
+ obj['backlinks'][button['load_board']['id']] ||= []
86
+ obj['backlinks'][button['load_board']['id']] << obj['pages'][board['id']] if obj['pages'][board['id']]
89
87
  end
90
88
  end
91
- OBF::Utils.log "backlinks #{obj['backlinks'].to_json}"
92
89
  end
93
- obj['boards'].each_with_index do |board, idx|
94
- started = Time.now.to_i
95
- OBF::Utils.log "starting pdf of board #{idx} #{board['name'] || board['id']} at #{started}"
96
- pre = idx.to_f / obj['boards'].length.to_f
97
- post = (idx + 1).to_f / obj['boards'].length.to_f
98
- OBF::Utils.as_progress_percent(pre, post) do
99
- # if more than 20 pages, build each page individually
100
- # and combine them afterwards
101
- if multi_render
102
- path = OBF::Utils.temp_path("stash-#{idx}.pdf")
103
- pdf = Prawn::Document.new(doc_opts)
104
- load_fonts(pdf, opts)
105
- else
106
- pdf.start_new_page unless idx == 0
107
- end
108
- build_page(pdf, board, {
109
- 'zipper' => zipper,
110
- 'pages' => obj['pages'],
111
- 'backlinks' => obj['backlinks'][board['id']] || [],
112
- 'headerless' => !!opts['headerless'],
113
- 'font' => default_font,
114
- 'links' => false,
115
- 'text_on_top' => !!opts['text_on_top'],
116
- 'transparent_background' => !!opts['transparent_background'],
117
- 'symbol_background' => opts['symbol_background'],
118
- 'text_case' => opts['text_case']
119
- })
120
- if multi_render
121
- pdf.render_file(path)
122
- multi_render_paths << path
123
- end
90
+ OBF::Utils.log "backlinks #{obj['backlinks'].to_json}"
91
+ end
92
+ incr = 1.0 / obj['boards'].length.to_f
93
+ tally = 0
94
+ obj['boards'].each_with_index do |board, idx|
95
+ started = Time.now.to_i
96
+ OBF::Utils.log "starting pdf of board #{idx} #{board['name'] || board['id']} at #{started}"
97
+ pre = idx.to_f / obj['boards'].length.to_f
98
+ post = (idx + 1).to_f / obj['boards'].length.to_f
99
+ OBF::Utils.as_progress_percent(tally, tally + incr) do
100
+ # if more than 20 pages, build each page individually
101
+ # and combine them afterwards
102
+ if multi_render
103
+ path = OBF::Utils.temp_path("stash-#{idx}.pdf")
104
+ pdf = Prawn::Document.new(doc_opts)
105
+ load_fonts(pdf, opts)
106
+ else
107
+ pdf.start_new_page unless idx == 0
108
+ end
109
+ build_page(pdf, board, {
110
+ 'zipper' => zipper,
111
+ 'pages' => obj['pages'],
112
+ 'backlinks' => obj['backlinks'][board['id']] || [],
113
+ 'headerless' => !!opts['headerless'],
114
+ 'font' => default_font,
115
+ 'links' => false,
116
+ 'text_on_top' => !!opts['text_on_top'],
117
+ 'transparent_background' => !!opts['transparent_background'],
118
+ 'symbol_background' => opts['symbol_background'],
119
+ 'text_case' => opts['text_case']
120
+ })
121
+ if multi_render
122
+ pdf.render_file(path)
123
+ multi_render_paths << path
124
124
  end
125
- OBF::Utils.log " finished pdf of board #{idx}/#{obj['boards'].length} #{Time.now.to_i - started}s"
126
125
  end
127
- else
128
- build_page(pdf, obj, {
129
- 'headerless' => !!opts['headerless'],
130
- 'font' => default_font,
131
- 'text_on_top' => !!opts['text_on_top'],
132
- 'transparent_background' => !!opts['transparent_background'],
133
- 'symbol_background' => opts['symbol_background'],
134
- 'text_case' => opts['text_case']
135
- })
126
+ tally += incr
127
+ OBF::Utils.log " finished pdf of board #{idx}/#{obj['boards'].length} #{Time.now.to_i - started}s"
136
128
  end
137
- if multi_render_paths.length > 0
138
- # `cp #{multi_render_paths[0]} #{dest_path}`
139
- `gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=#{dest_path} #{multi_render_paths.join(' ')}`
140
- else
141
- pdf.render_file(dest_path)
142
- end
143
-
129
+ else
130
+ build_page(pdf, obj, {
131
+ 'headerless' => !!opts['headerless'],
132
+ 'font' => default_font,
133
+ 'text_on_top' => !!opts['text_on_top'],
134
+ 'transparent_background' => !!opts['transparent_background'],
135
+ 'symbol_background' => opts['symbol_background'],
136
+ 'text_case' => opts['text_case']
137
+ })
138
+ end
139
+ if multi_render_paths.length > 0
140
+ # `cp #{multi_render_paths[0]} #{dest_path}`
141
+ `gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=#{dest_path} #{multi_render_paths.join(' ')}`
142
+ else
143
+ pdf.render_file(dest_path)
144
144
  end
145
145
  end
146
146
 
@@ -433,7 +433,7 @@ module OBF::PDF
433
433
  end
434
434
  end
435
435
  index = col + (row * obj['grid']['columns'])
436
- OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f)
436
+ OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f, "updated button #{button_id}")
437
437
  end
438
438
  end
439
439
  end
@@ -448,6 +448,7 @@ module OBF::PDF
448
448
  board['path'] = root
449
449
  unvisited_boards = [board]
450
450
  visited_boards = []
451
+ OBF::Utils.update_current_progress(0.2, "prepping for pdf")
451
452
  while unvisited_boards.length > 0
452
453
  board = unvisited_boards.shift
453
454
  visited_boards << board
@@ -474,11 +475,13 @@ module OBF::PDF
474
475
  pages[board['id']] = (idx + 1).to_s
475
476
  end
476
477
 
477
- build_pdf({
478
- 'name' => 'Communication Board Set',
479
- 'boards' => visited_boards,
480
- 'pages' => pages
481
- }, dest_path, zipper, opts)
478
+ OBF::Utils.as_progress_percent(0.2, 1.0) do
479
+ build_pdf({
480
+ 'name' => 'Communication Board Set',
481
+ 'boards' => visited_boards,
482
+ 'pages' => pages
483
+ }, dest_path, zipper, opts)
484
+ end
482
485
  end
483
486
  # parse obz, draw as pdf
484
487
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9.1
4
+ version: 0.9.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer