obf 0.9.8.5 → 0.9.8.6

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: be39949f2f5c4c6af4bb7fd943ac2950234bee6ea9a524becabbaa4b77ec3239
4
- data.tar.gz: 8a3fc7c6b9b52bd116a1e2f141180544c3a1ccd487477c06fb6cc25eb830e288
3
+ metadata.gz: b2c866158d28930becd902f17ed56e40e9fe7c42427a669e3059cc6e5c5e94e0
4
+ data.tar.gz: 335218803680fd6cf87cd36b862811c1af6e57e29972d129a491de926aa837c8
5
5
  SHA512:
6
- metadata.gz: 6b9659266746cbca8d2d9cf09675def278e6a62d2b81532e92b8f7bad6b038a99b15b2c3936495938332bf4335d9190294fa57e42e8bc8e4942255d51e802768
7
- data.tar.gz: '081f80f5b327cf2c32e03941d35d0d8c6e93a14442ed874245852052eaeba3dc537a5350def0b36942b235433fd16c674f32ea48711f13c1f6fe90f0f63091c5'
6
+ metadata.gz: 5cefe31a7fea80ef4e80f5a1e605a169f31db0e7bf684e9aba0a93ebb06913508cef8374aa994fe77965c34dbdda364c65f6815cb4b4cad0afc990b26636fdf4
7
+ data.tar.gz: 2d6ef0cc281351d3217864f3f07b55fc72adef71d5ced8653de7201bfac061c463a0e8f5224be366872c8ddc533f2c6d5ceba7b58fd54989725a94eb13ff7dc3
data/lib/obf/c4v.rb ADDED
@@ -0,0 +1,215 @@
1
+ module OBF::C4v
2
+ def self.to_external(c4v_path)
3
+ # load the sqlite file, read the following into memory:
4
+ # - action_data
5
+ # - actions
6
+ # - button_box_cells
7
+ # - button_box_instances
8
+ # - button_boxes
9
+ # - button_set_modifiers
10
+ # - button_sets
11
+ # - button_styles
12
+ # - buttons
13
+ # - pages
14
+ # - resources
15
+ # - special_pages
16
+
17
+ # then use the munger code to convert to a hash of boards
18
+ end
19
+ end
20
+
21
+
22
+ # # buttons => id, label, message, resource_id, button_style_id
23
+ # # button_box_cells => button_box_id, resource_id (buttons), location
24
+ # # button_box_instances => page_id (pages), button_box_id
25
+ # # button_boxes => id, layout_x (cols), layout_y (rows)
26
+ # # button_styles => id, body_color, etc.
27
+ # # pages => id, resource_id, button_style_id (?)
28
+ # # actions => id, resource_id, code
29
+ # # action_data => action_id, value
30
+ # # resource => id, rid, name, type
31
+
32
+ # # buttons.resource_id == button_box_cells.resource_id (where buttons go in the layout)
33
+ # # buttons.resource_id == actions.resource_id (action for each button, code=8 is a link, code=13 is maybe an append?)
34
+ # # action_data.action_id == actions.id
35
+ # # action_data.value == resources.rid (where each button links to)
36
+ # # resources.id == pages.resource_id (page name for reference)
37
+
38
+ # # resources
39
+ # # type 7 == board
40
+ # # type 4 == button
41
+ # # type 5 == special button
42
+
43
+ # require 'json'
44
+ # require 'fileutils'
45
+ # require 'zip'
46
+ # require 'csv'
47
+
48
+ # Dir.glob('*')
49
+ # ["LAMP 84 Full"]
50
+ # Dir.glob('*').each do |dir|
51
+ # puts dir
52
+ # if dir
53
+ # refs = {}
54
+ # Dir.glob("./#{dir}/*.json").each do |json|
55
+ # puts " #{json}"
56
+ # type = json.split(/\//)[-1].split(/\./)[0]
57
+ # refs[type] = JSON.parse(File.read(json))
58
+ # end
59
+ # if refs.keys.length > 0
60
+ # root_path = "./#{dir}/output"
61
+ # FileUtils.mkdir_p root_path
62
+
63
+ # home_page_id = refs['special_pages'].detect{|p| p['name'] == 'HOME'}['page_id']
64
+ # manifest = {
65
+ # 'format' => 'open-board-0.1',
66
+ # 'root' => "boards/#{home_page_id}.obf",
67
+ # 'paths' => {
68
+ # 'boards' => {
69
+ # }
70
+ # }
71
+ # }
72
+
73
+ # home_page = refs['pages'].detect{|p| p['id'] == home_page_id }
74
+ # processed_pages = []
75
+ # pages_to_process = [home_page]
76
+ # bbis = {}
77
+ # refs['button_box_instances'].each{|bbi| bbis[bbi['page_id']] = bbi}
78
+ # rs = {}
79
+ # refs['resources'].each{|r| rs[r['id']] = r; rs[r['rid']] = r }
80
+ # btns = {}
81
+ # words = []
82
+ # refs['buttons'].each{|b| btns[b['resource_id']] = b; words << b['message'] }
83
+ # words = words.select{|w| w && w.length > 0 && w != ' '}.sort.uniq
84
+ # CSV.open(root_path + "/#{dir} words.csv", 'wb') do |csv|
85
+ # words.each{|w| csv << [w] }
86
+ # end
87
+ # File.write(root_path + "/#{dir} words.txt", words.join("\n"))
88
+ # acts = {}
89
+ # refs['actions'].each{|a| acts[a['resource_id']] ||= []; acts[a['resource_id']] << a }
90
+ # pgs = {}
91
+ # refs['pages'].each{|p| pgs[p['resource_id']] = p }
92
+ # ads = {}
93
+ # refs['action_data'].each{|d| ads[d['action_id']] ||= []; ads[d['action_id']] << d }
94
+ # cls = {}
95
+ # refs['button_box_cells'].each{|c| cls[c['button_box_id']] ||= []; cls[c['button_box_id']] << c }
96
+ # bxs = {}
97
+ # refs['button_boxes'].each{|b| bxs[b['id']] = b }
98
+ # bsts = {}
99
+ # refs['button_styles'].each{|b| bsts[b['id']] = b }
100
+ # btnsts = {}
101
+ # refs['button_sets'].each{|b| btnsts[b['resource_id']] = b }
102
+ # btnmd = {}
103
+ # refs['button_set_modifiers'].each{|b| btnmd[b['button_set_id']] = b if b['modifier'] == 0 }
104
+
105
+ # while pages_to_process.length > 0
106
+ # page = pages_to_process.shift
107
+ # manifest['paths']['boards'][page['id']] = "boards/#{page['id']}.obf"
108
+ # processed_pages.push(page['id'])
109
+ # page_name = rs[page['resource_id']]['name']
110
+ # page_name = dir if page['id'] == home_page_id
111
+ # board = {
112
+ # 'format' => 'open-board-0.1',
113
+ # 'id' => page['id'],
114
+ # 'locale' => 'en',
115
+ # 'name' => page_name,
116
+ # 'description' => "Auto-Generated",
117
+ # 'buttons' => [],
118
+ # 'grid' => {
119
+ # 'rows' => 0,
120
+ # 'columns' => 0,
121
+ # 'order' => []
122
+ # }
123
+ # }
124
+ # button_box_instance = bbis[page['id']] #refs['button_box_instances'].detect{|b| b['page_id'] == page['id'] }
125
+ # button_box_id = button_box_instance['button_box_id']
126
+ # puts " #{page_name} #{button_box_id}"
127
+ # button_box = bxs[button_box_id] #refs['button_boxes'].detect{|b| b['id'] == button_box_instance }
128
+ # columns = button_box['layout_x']
129
+ # rows = button_box['layout_y']
130
+ # board['grid']['rows'] = rows
131
+ # board['grid']['columns'] = columns
132
+ # cells = cls[button_box_id] #refs['button_box_cells'].select{|c| c['button_box_id'] == button_box_id }
133
+ # cells.each do |cell|
134
+ # # TODO: add coloring from button_styles
135
+ # col = cell['location'] % columns
136
+ # row = (cell['location'] - col) / columns
137
+ # resource_id = cell['resource_id']
138
+ # resource = rs[cell['resource_id']]
139
+ # if resource && resource['type'] == 5
140
+ # button_set = btnsts[resource_id]
141
+ # button_mod = button_set && btnmd[button_set['id']]
142
+ # button_id = button_mod && button_mod['button_id']
143
+ # button = refs['buttons'].detect{|b| b['id'] == button_id}
144
+ # resource_id = button['resource_id'] if button
145
+ # end
146
+ # cell['button'] = btns[resource_id] #refs['buttons'].detect{|b| b['resource_id'] == cell['resource_id'] }
147
+ # cell['style'] = cell['button'] && bsts[cell['button']['button_style_id']]
148
+ # label = (cell['button'] && cell['button']['label']) || rs[cell['resource_id']]['name']
149
+ # cell['actions'] = acts[cell['resource_id']] || []
150
+ # cell['actions'] += acts[resource_id] || [] #refs['actions'].select{|b| b['resource_id'] == cell['resource_id'] }
151
+ # link_id = nil
152
+ # verbose = button_box_id == 268 && row == 0 && col == 3
153
+ # cell['actions'].each do |action|
154
+ # if action && (action['code'] == 8 || action['code'] == 9 || action['code'] == 73 || (button_box_id == 268 && row == 0 && col == 2))
155
+ # action_data = ads[action['id']] #refs['action_data'].detect{|a| a['action_id'] == action['id'] }
156
+ # action['data'] = action_data
157
+ # (action_data || []).each do |ad|
158
+ # if ad && ad['value'] != '0' && ad['value'] != '1'
159
+ # action_resource = rs[ad['value']] #refs['resources'].detect{|r| r['rid'] == action_data['value'] }
160
+ # if !action_resource || action_resource['type'] != 7
161
+ # puts JSON.pretty_generate(cell)
162
+ # puts ad.to_json
163
+ # puts action_resource.to_json
164
+ # raise "wut"
165
+ # end
166
+ # puts ad['value'].to_json if !action_resource
167
+ # new_page = pgs[action_resource['id']] #refs['pages'].detect{|p| p['resource_id'] == action_resource['id'] }
168
+ # link_id = new_page['id']
169
+ # if !processed_pages.include?(new_page['id']) && !pages_to_process.detect{|p| p['id'] == new_page['id'] }
170
+ # pages_to_process.push(new_page)
171
+ # end
172
+ # end
173
+ # end
174
+ # end
175
+ # end
176
+ # puts JSON.pretty_generate(cell) if verbose
177
+ # if label && label != ''
178
+ # # puts " #{label.to_json} #{row} #{col}"
179
+ # button = {
180
+ # 'id' => cell['id'],
181
+ # 'label' => label
182
+ # }
183
+ # if cell['button'] && cell['button']['message']
184
+ # button['vocalization'] = cell['button']['message']
185
+ # end
186
+ # if link_id
187
+ # button['load_board'] = {
188
+ # 'id' => link_id,
189
+ # 'path' => "boards/#{link_id}.obf"
190
+ # }
191
+ # end
192
+ # if cell['style']
193
+ # button['background_color'] = "\##{cell['style']['body_color'].to_s(16).rjust(6, '0')}" if cell['style']['body_color']
194
+ # button['border_color'] = "\##{cell['style']['border_color'].to_s(16).rjust(6, '0')}" if cell['style']['border_coloor']
195
+ # end
196
+ # board['buttons'] << button
197
+ # board['grid']['order'][row] ||= []
198
+ # board['grid']['order'][row][col] = button['id']
199
+ # end
200
+ # end
201
+ # FileUtils.mkdir_p(root_path + "/boards")
202
+ # File.write(root_path + "/boards/#{page['id']}.obf", JSON.pretty_generate(board))
203
+ # end
204
+
205
+ # File.write(root_path + "/manifest.json", JSON.pretty_generate(manifest))
206
+ # File.unlink(root_path + "/#{dir}.obz") if File.exists?(root_path + "/#{dir}.obz")
207
+ # Zip::File.open(root_path + "/#{dir}.obz", Zip::File::CREATE) do |zipfile|
208
+ # zipfile.add("manifest.json", root_path + "/manifest.json")
209
+ # manifest['paths']['boards'].each do |id, path|
210
+ # zipfile.add(path, root_path + "/" + path)
211
+ # end
212
+ # end
213
+ # end
214
+ # end
215
+ # end
data/lib/obf/pdf.rb CHANGED
@@ -183,6 +183,29 @@ module OBF::PDF
183
183
  if obj['grid'] && obj['grid']['rows'] > 0 && obj['grid']['columns'] > 0
184
184
  button_height = (grid_height - (padding * (obj['grid']['rows'] - 1))) / obj['grid']['rows'].to_f
185
185
  button_width = (grid_width - (padding * (obj['grid']['columns'] - 1))) / obj['grid']['columns'].to_f
186
+
187
+ # Grab all the images per board in parallel
188
+ puts " batch-retrieving remote images"
189
+ hydra = Typhoeus::Hydra.hydra
190
+ grabs = []
191
+ obj['buttons'].each do |btn|
192
+ image = (obj['images_hash'] || {})[btn['image_id']]
193
+ if image && image['url'] && !image['data'] && !(image['path'] && optionns['zipper'])
194
+ url = image['url']
195
+ uri = url.match(/\%/) ? url : URI.escape(url)
196
+ uri = OBF::Utils.sanitize_url(uri)
197
+ req = Typhoeus::Request.new(uri, followlocation: true)
198
+ hydra.queue(req)
199
+ grabs << {url: url, req: req, image: image}
200
+ end
201
+ end
202
+ hydra.run
203
+ grabs.each do |grab|
204
+ grab[:image]['raw_data'] = grab[:req].response.body
205
+ grab[:image]['content_type'] = grab[:req].response.headers['Content-Type'] if grab[:req].response.headers['Content-Type']
206
+ end
207
+ puts " done with #{grabs.length} remote images!"
208
+
186
209
  obj['grid']['order'].each_with_index do |buttons, row|
187
210
  buttons.each_with_index do |button_id, col|
188
211
  button = obj['buttons'].detect{|b| b['id'] == button_id }
data/lib/obf/utils.rb CHANGED
@@ -40,6 +40,8 @@ module OBF::Utils
40
40
  end
41
41
 
42
42
  def self.identify_file(path)
43
+ # TODO: .c4v files are sqlite databases that can be converted
44
+ # based on your munger.rb code (text-only)
43
45
  name = File.basename(path) rescue nil
44
46
  if name.match(/\.obf$/)
45
47
  return :obf
@@ -135,6 +137,8 @@ module OBF::Utils
135
137
  if !image['content_type']
136
138
  image['content_type'] = image['data'].split(/;/)[0].split(/:/)[1]
137
139
  end
140
+ elsif image['raw_data']
141
+ # already processed
138
142
  elsif image['path'] && zipper
139
143
  image['raw_data'] = zipper.read(image['path'])
140
144
  if !image['content_type']
@@ -142,7 +146,9 @@ module OBF::Utils
142
146
  image['content_type'] = types[0] && types[0].to_s
143
147
  end
144
148
  elsif image['url']
149
+ puts " retrieving #{image['url']}"
145
150
  url_data = get_url(image['url'])
151
+ puts " done!"
146
152
  image['raw_data'] = url_data['data']
147
153
  image['content_type'] = url_data['content_type']
148
154
  elsif image['symbol']
@@ -178,14 +184,17 @@ module OBF::Utils
178
184
  size = 400
179
185
  path = file.path
180
186
  if image['content_type'] && image['content_type'].match(/svg/)
187
+ puts " convert -background \"#{background}\" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg"
181
188
  `convert -background "#{background}" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg`
182
189
  # `rsvg-convert -w #{size} -h #{size} -a #{file.path} > #{file.path}.png`
183
190
  path = "#{file.path}.jpg"
184
191
  else
192
+ puts " convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg"
185
193
  `convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg`
186
194
  path = "#{path}.jpg"
187
195
  end
188
196
 
197
+ puts " finished image"
189
198
  path
190
199
  end
191
200
  end
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.8.5
4
+ version: 0.9.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
@@ -150,6 +150,7 @@ files:
150
150
  - lib/TimesNewRoman.ttf
151
151
  - lib/obf.rb
152
152
  - lib/obf/avz.rb
153
+ - lib/obf/c4v.rb
153
154
  - lib/obf/external.rb
154
155
  - lib/obf/obf.rb
155
156
  - lib/obf/obz.rb