obf 0.9.8.21 → 0.9.8.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/Arial.ttf +0 -0
- data/lib/obf/pdf.rb +168 -88
- 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: 634ef9637b8b8a49071e2bd8b51dd0e72b1a51893ef72c1c747ba25f27874001
|
4
|
+
data.tar.gz: b5d17a2f08e2894bb67f8e8fcd8f7be4c23d3a17d0326e9d06e87853f3861730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cd0d799df8d154d55bd8c2616320ff449965ab797afc54785b6d28bc44a4371d7289564596219636339b74fa3078130f9bf6579a4607f1ebb41262520b341aa
|
7
|
+
data.tar.gz: 48d255a567dee72f2eb8f13a1f635842a3bfb0ad894ce4c67413e2a97b4930d090cd383d004c3bc96e548c9af9778c463657bbbff1f03e075ce381801c409606
|
data/lib/Arial.ttf
ADDED
Binary file
|
data/lib/obf/pdf.rb
CHANGED
@@ -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
|
60
|
-
|
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 =
|
146
|
-
pdf.bounding_box([0, doc_height], :width => doc_width, :height =>
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
-
|
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,
|
164
|
-
pdf.line_to 190,
|
165
|
-
pdf.curve_to [
|
166
|
-
pdf.
|
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
|
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 -
|
172
|
-
pdf.fill_color "
|
173
|
-
pdf.
|
174
|
-
pdf.
|
175
|
-
pdf.
|
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
|
-
|
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
|
-
|
344
|
+
if !blank_button
|
345
|
+
vertical = options['text_on_top'] ? button_height - text_height : button_height - 5
|
272
346
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
bg = '
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
File.
|
309
|
-
|
310
|
-
|
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
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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 "
|
343
|
-
if OBF::PDF.footer_text
|
344
|
-
text = OBF::PDF.footer_text
|
345
|
-
|
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.
|
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-
|
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
|