obf 0.9.9.1 → 0.9.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Khmer.ttf +0 -0
- data/lib/obf/external.rb +82 -69
- data/lib/obf/pdf.rb +84 -78
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0e84d8f70a1087b0875c7515fdb3eef30caae91e862bade5a2e6f6044cf43af
|
4
|
+
data.tar.gz: 8ea281959203867d563704341cf178a7c166a0a51efbc28ec42385f71ed81fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f76d3cb77c81d210261b2295a7d2aa2358bb324250d3093600bc0765971b6f67c0f04ca31de9023ceda7087d853516449eeb1716bbb4f456d05633babfefa969
|
7
|
+
data.tar.gz: 4b2389d3600ec697d8cd74aacae99ef4936bcedd0aa85a8f57d1c3215146fe82cb7138af6c7d338ae5d29db44231b8755b6a066f34a000e8f7f84ef5f68954fd
|
data/lib/Khmer.ttf
ADDED
Binary file
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
65
|
-
button['load_board']
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
344
|
-
|
345
|
-
b
|
346
|
-
|
347
|
-
|
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
@@ -50,6 +50,9 @@ module OBF::PDF
|
|
50
50
|
pdf.font_families.update('Sazanami-Hanazono-Mincho' => {
|
51
51
|
normal: File.expand_path('../../Sazanami-Hanazono-Mincho.ttf', __FILE__)
|
52
52
|
})
|
53
|
+
pdf.font_families.update('Khmer' => {
|
54
|
+
normal: File.expand_path('../../Khmer.ttf', __FILE__)
|
55
|
+
})
|
53
56
|
default_font = 'TimesNewRoman'
|
54
57
|
if opts['font'] && !opts['font'].match(/TimesNewRoman/) && File.exists?(opts['font'])
|
55
58
|
pdf.font_families.update('DocDefault' => {
|
@@ -57,90 +60,90 @@ module OBF::PDF
|
|
57
60
|
})
|
58
61
|
default_font = 'DocDefault'
|
59
62
|
end
|
60
|
-
pdf.fallback_fonts = ['TimesNewRoman', 'THFahKwangBold', 'MiedingerBook', 'Helvetica', 'Sazanami-Hanazono-Mincho']
|
63
|
+
pdf.fallback_fonts = ['TimesNewRoman', 'THFahKwangBold', 'MiedingerBook', 'Helvetica', 'Sazanami-Hanazono-Mincho', 'Khmer']
|
61
64
|
pdf.font(default_font)
|
62
65
|
default_font
|
63
66
|
end
|
64
67
|
|
65
68
|
def self.build_pdf(obj, dest_path, zipper, opts={})
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
:
|
72
|
-
:Title => obj['name']
|
73
|
-
}
|
69
|
+
# parse obf, draw as pdf
|
70
|
+
doc_opts = {
|
71
|
+
:page_layout => :landscape,
|
72
|
+
:page_size => [8.5*72, 11*72],
|
73
|
+
:info => {
|
74
|
+
:Title => obj['name']
|
74
75
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
76
|
+
}
|
77
|
+
pdf = Prawn::Document.new(doc_opts)
|
78
|
+
default_font = load_fonts(pdf, opts)
|
79
|
+
|
80
|
+
multi_render_paths = []
|
81
|
+
if obj['boards']
|
82
|
+
multi_render = obj['boards'].length > 20 && `which gs`.length > 0
|
83
|
+
obj['backlinks'] = {}
|
84
|
+
if obj['pages']
|
85
|
+
obj['boards'].each do |board|
|
86
|
+
board['buttons'].each do |button|
|
87
|
+
if button['load_board'] && button['load_board']['id']
|
88
|
+
obj['backlinks'][button['load_board']['id']] ||= []
|
89
|
+
obj['backlinks'][button['load_board']['id']] << obj['pages'][board['id']] if obj['pages'][board['id']]
|
89
90
|
end
|
90
91
|
end
|
91
|
-
OBF::Utils.log "backlinks #{obj['backlinks'].to_json}"
|
92
92
|
end
|
93
|
-
obj['
|
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
|
-
|
93
|
+
OBF::Utils.log "backlinks #{obj['backlinks'].to_json}"
|
94
|
+
end
|
95
|
+
incr = 1.0 / obj['boards'].length.to_f
|
96
|
+
tally = 0
|
97
|
+
obj['boards'].each_with_index do |board, idx|
|
98
|
+
started = Time.now.to_i
|
99
|
+
OBF::Utils.log "starting pdf of board #{idx} #{board['name'] || board['id']} at #{started}"
|
100
|
+
pre = idx.to_f / obj['boards'].length.to_f
|
101
|
+
post = (idx + 1).to_f / obj['boards'].length.to_f
|
102
|
+
OBF::Utils.as_progress_percent(tally, tally + incr) do
|
103
|
+
# if more than 20 pages, build each page individually
|
104
|
+
# and combine them afterwards
|
105
|
+
if multi_render
|
106
|
+
path = OBF::Utils.temp_path("stash-#{idx}.pdf")
|
107
|
+
pdf = Prawn::Document.new(doc_opts)
|
108
|
+
load_fonts(pdf, opts)
|
109
|
+
else
|
110
|
+
pdf.start_new_page unless idx == 0
|
111
|
+
end
|
112
|
+
build_page(pdf, board, {
|
113
|
+
'zipper' => zipper,
|
114
|
+
'pages' => obj['pages'],
|
115
|
+
'backlinks' => obj['backlinks'][board['id']] || [],
|
116
|
+
'headerless' => !!opts['headerless'],
|
117
|
+
'font' => default_font,
|
118
|
+
'links' => false,
|
119
|
+
'text_on_top' => !!opts['text_on_top'],
|
120
|
+
'transparent_background' => !!opts['transparent_background'],
|
121
|
+
'symbol_background' => opts['symbol_background'],
|
122
|
+
'text_case' => opts['text_case']
|
123
|
+
})
|
124
|
+
if multi_render
|
125
|
+
pdf.render_file(path)
|
126
|
+
multi_render_paths << path
|
124
127
|
end
|
125
|
-
OBF::Utils.log " finished pdf of board #{idx}/#{obj['boards'].length} #{Time.now.to_i - started}s"
|
126
128
|
end
|
127
|
-
|
128
|
-
|
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
|
-
})
|
136
|
-
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)
|
129
|
+
tally += incr
|
130
|
+
OBF::Utils.log " finished pdf of board #{idx}/#{obj['boards'].length} #{Time.now.to_i - started}s"
|
142
131
|
end
|
143
|
-
|
132
|
+
else
|
133
|
+
build_page(pdf, obj, {
|
134
|
+
'headerless' => !!opts['headerless'],
|
135
|
+
'font' => default_font,
|
136
|
+
'text_on_top' => !!opts['text_on_top'],
|
137
|
+
'transparent_background' => !!opts['transparent_background'],
|
138
|
+
'symbol_background' => opts['symbol_background'],
|
139
|
+
'text_case' => opts['text_case']
|
140
|
+
})
|
141
|
+
end
|
142
|
+
if multi_render_paths.length > 0
|
143
|
+
# `cp #{multi_render_paths[0]} #{dest_path}`
|
144
|
+
`gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=#{dest_path} #{multi_render_paths.join(' ')}`
|
145
|
+
else
|
146
|
+
pdf.render_file(dest_path)
|
144
147
|
end
|
145
148
|
end
|
146
149
|
|
@@ -433,7 +436,7 @@ module OBF::PDF
|
|
433
436
|
end
|
434
437
|
end
|
435
438
|
index = col + (row * obj['grid']['columns'])
|
436
|
-
OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f)
|
439
|
+
OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f, "updated button #{button_id}")
|
437
440
|
end
|
438
441
|
end
|
439
442
|
end
|
@@ -448,6 +451,7 @@ module OBF::PDF
|
|
448
451
|
board['path'] = root
|
449
452
|
unvisited_boards = [board]
|
450
453
|
visited_boards = []
|
454
|
+
OBF::Utils.update_current_progress(0.2, "prepping for pdf")
|
451
455
|
while unvisited_boards.length > 0
|
452
456
|
board = unvisited_boards.shift
|
453
457
|
visited_boards << board
|
@@ -474,11 +478,13 @@ module OBF::PDF
|
|
474
478
|
pages[board['id']] = (idx + 1).to_s
|
475
479
|
end
|
476
480
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
481
|
+
OBF::Utils.as_progress_percent(0.2, 1.0) do
|
482
|
+
build_pdf({
|
483
|
+
'name' => 'Communication Board Set',
|
484
|
+
'boards' => visited_boards,
|
485
|
+
'pages' => pages
|
486
|
+
}, dest_path, zipper, opts)
|
487
|
+
end
|
482
488
|
end
|
483
489
|
# parse obz, draw as pdf
|
484
490
|
|
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.9.
|
4
|
+
version: 0.9.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- LICENSE
|
147
147
|
- README.md
|
148
148
|
- lib/Arial.ttf
|
149
|
+
- lib/Khmer.ttf
|
149
150
|
- lib/MiedingerBook.ttf
|
150
151
|
- lib/Sazanami-Hanazono-Mincho.ttf
|
151
152
|
- lib/THFahKwangBold.ttf
|