obf 0.9.8.37 → 0.9.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e9c05fbc1eb76aca00e0b2bda343ed7d2309ef8350d494eee7c07b1806013e4
4
- data.tar.gz: 0b13491784c9dae969e7cf9344f7c5d171b63ab6251a37d57ce0261ae78106da
3
+ metadata.gz: 49734c92d9d154f254416ecff17f6a04503b5afc2d340d3ceb7f94ec89b6f82b
4
+ data.tar.gz: bfff105ec7b48a2eeb746b8d437c3f6d245d75b499bbc4feae142548a2b43f82
5
5
  SHA512:
6
- metadata.gz: 9459a448663ae43c120ed92d1d223efa5402895665919df8ba2d1ac2c8a52276724f6b4157a71f6c1abe7fafa26029118467a1646f1f0ea2083320dc5c8fcc45
7
- data.tar.gz: 8847fd9594814bb7789178f89584811f63c4726982307a1e4ff432cb9537e9a2beff69c684d4218a04d398116128bab6efc7e87eadc07f24a0a6d09f64aedffa
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]
@@ -149,6 +153,8 @@ module OBF::External
149
153
  'width' => original_image['width'],
150
154
  'height' => original_image['height'],
151
155
  'license' => OBF::Utils.parse_license(original_image['license']),
156
+ 'protected' => original_image['protected'],
157
+ 'protected_source' => original_image['protected_source'],
152
158
  'url' => original_image['url'],
153
159
  'data' => original_image['data'],
154
160
  'data_url' => original_image['data_url'],
@@ -172,7 +178,7 @@ module OBF::External
172
178
  image['height'] ||= path_hash['images'][image['id']]['height']
173
179
  else
174
180
  image_fetch = OBF::Utils.image_raw(image['data'] || image['url'])
175
- if image_fetch
181
+ if image_fetch && image_fetch['data']
176
182
  if !image['content_type'] || !image['width'] || !image['height']
177
183
  attrs = OBF::Utils.image_attrs(image_fetch['data'])
178
184
  image['content_type'] ||= image_fetch['content_type'] || attrs['content_type']
@@ -202,6 +208,8 @@ module OBF::External
202
208
  'width' => original_image['width'],
203
209
  'height' => original_image['height'],
204
210
  'license' => OBF::Utils.parse_license(original_image['license']),
211
+ 'protected' => original_image['protected'],
212
+ 'protected_source' => original_image['protected_source'],
205
213
  'url' => original_image['url'],
206
214
  'data_url' => original_image['data_url'],
207
215
  'content_type' => original_image['content_type']
@@ -211,12 +219,15 @@ module OBF::External
211
219
 
212
220
  end
213
221
 
222
+ OBF::Utils.update_current_progress(0.75, "sounds for board #{res['id']}")
214
223
  if to_include[:sounds]
215
224
  sounds.each do |original_sound|
216
225
  sound = {
217
226
  'id' => original_sound['id'],
218
227
  'duration' => original_sound['duration'],
219
228
  'license' => OBF::Utils.parse_license(original_sound['license']),
229
+ 'protected' => original_sound['protected'],
230
+ 'protected_source' => original_sound['protected_source'],
220
231
  'url' => original_sound['url'],
221
232
  'data' => original_sound['data'],
222
233
  'data_url' => original_sound['data_url'],
@@ -250,6 +261,8 @@ module OBF::External
250
261
  'id' => original_sound['id'],
251
262
  'duration' => original_sound['duration'],
252
263
  'license' => OBF::Utils.parse_license(original_sound['license']),
264
+ 'protected' => original_sound['protected'],
265
+ 'protected_source' => original_sound['protected_source'],
253
266
  'url' => original_sound['url'],
254
267
  'data_url' => original_sound['data_url'],
255
268
  'content_type' => original_sound['content_type']
@@ -258,6 +271,8 @@ module OBF::External
258
271
  end
259
272
  end
260
273
 
274
+ OBF::Utils.update_current_progress(0.85, "grid for board #{res['id']}")
275
+
261
276
  res['grid'] = OBF::Utils.parse_grid(hash['grid']) # TODO: more robust parsing here
262
277
  if path_hash && path_hash['zip']
263
278
  zip_path = "board_#{res['id']}.obf"
@@ -270,6 +285,7 @@ module OBF::External
270
285
  File.open(dest_path, 'w') {|f| f.write(JSON.pretty_generate(res)) }
271
286
  end
272
287
  OBF::Utils.log(" done compressing board #{res['name'] || res['id']}")
288
+ OBF::Utils.update_current_progress(1.0, "done for board #{res['id']}")
273
289
  return dest_path
274
290
  end
275
291
 
@@ -325,6 +341,8 @@ module OBF::External
325
341
  content['images'] ||= boards.map{|b| b['images'] }.flatten.uniq
326
342
  content['sounds'] ||= boards.map{|b| b['sounds'] }.flatten.uniq
327
343
  root_board = boards[0]
344
+ incr = 1.0 / boards.length.to_f
345
+ tally = 0.0
328
346
  OBF::Utils.build_zip(dest_path) do |zipper|
329
347
  paths['zip'] = zipper
330
348
  paths['included_boards'] = {}
@@ -332,12 +350,15 @@ module OBF::External
332
350
  paths['included_boards'][b['id']] = b
333
351
  end
334
352
  boards.each do |b|
335
- b = paths['included_boards'][b['id']]
336
- if b
337
- b['images'] = content['images'] || []
338
- b['sounds'] = content['sounds'] || []
339
- 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
340
360
  end
361
+ tally += incr
341
362
  end
342
363
  manifest = {
343
364
  'format' => OBF::OBF::FORMAT,
@@ -416,7 +437,7 @@ module OBF::External
416
437
  end
417
438
  tmp_path = OBF::Utils.temp_path("stash")
418
439
  if opts['packet']
419
- OBF::Utils.as_progress_percent(0, 0.3) do
440
+ OBF::Utils.as_progress_percent(0.1, 0.3) do
420
441
  opts[:to_include] = {images: true}
421
442
  OBF::External.to_obz(board, tmp_path, opts)
422
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
 
data/lib/obf/utils.rb CHANGED
@@ -153,7 +153,7 @@ module OBF::Utils
153
153
  image['content_type'] ||= attrs['content_type']
154
154
  end
155
155
  end
156
- return nil unless image
156
+ return nil unless image && image['data']
157
157
  str = "data:" + image['content_type']
158
158
  str += ";base64," + Base64.strict_encode64(image['data'])
159
159
  str
@@ -377,7 +377,7 @@ module OBF::Utils
377
377
 
378
378
  def self.image_attrs(path, extension='')
379
379
  res = {}
380
- if path.match(/^data:/)
380
+ if path && path.match(/^data:/)
381
381
  res['content_type'] = path.split(/;/)[0].split(/:/)[1]
382
382
  raw = Base64.strict_decode64(path.split(/\,/, 2)[1])
383
383
  file = Tempfile.new(['file', extension])
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.37
4
+ version: 0.9.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -184,8 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.7.6
187
+ rubygems_version: 3.0.9
189
188
  signing_key:
190
189
  specification_version: 4
191
190
  summary: Open Board Format