obf 0.8.3 → 0.8.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/obf/pdf.rb +71 -26
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13d72d3a1108db429d2a7298c3ba99f5c745a28f
4
- data.tar.gz: 853f4bacc4dd3f7b6d92d50fe7f01c8aedf9b0f6
3
+ metadata.gz: 5632f5b2f1f0a39e5959b450b224ceaf0156e70b
4
+ data.tar.gz: 51e0052c09a107e280d3309d38e54e7ca1f88f11
5
5
  SHA512:
6
- metadata.gz: ca8ccd678f89aeb58f302b4965b87e76f68cc52f7996560ecbe77a2b2fc917be9627d78ec055e6aead76e7955d830eec098989ae978737fffd265491da55e69d
7
- data.tar.gz: e8c10fd75ec8ed098b28f6488c3f3c7e13b305279bda8a200762d263863803203ffcf55b18dd3b6ff0380062107ba156b7b1a97358ce96fc796c3bb364f3412d
6
+ metadata.gz: dbeb5f66b6ba30025ca2212f90cac5fd46510a4875a93b511aeca856fc5329b1cb04a471add5ffafcd8984327e3fb7103d9aff0addb7ff86de72d58872df6acc
7
+ data.tar.gz: 13f8c5a2705a34e2ecf61327ff96c8c619e297cd38fcf3fb45b2f3b733a563950df29f31982e438b286c344be00c3ade07f887e9baf37f813b1c93c2e5d7201e
data/lib/obf/pdf.rb CHANGED
@@ -2,6 +2,8 @@ module OBF::PDF
2
2
  @@footer_text ||= nil
3
3
  @@footer_url ||= nil
4
4
 
5
+ RTL_SCRIPTS = %w(Arabic Hebrew Nko Kharoshthi Phoenician Syriac Thaana Tifinagh)
6
+
5
7
  def self.footer_text
6
8
  @@footer_text
7
9
  end
@@ -30,6 +32,8 @@ module OBF::PDF
30
32
  end
31
33
 
32
34
  def self.build_pdf(obj, dest_path, zipper, opts={})
35
+ character_classes = RTL_SCRIPTS.map{ |script| "\\p{#{script}}" }.join
36
+ rtl_regex = /[#{character_classes}]/
33
37
  OBF::Utils.as_progress_percent(0, 1.0) do
34
38
  # parse obf, draw as pdf
35
39
  pdf = Prawn::Document.new(
@@ -49,11 +53,23 @@ module OBF::PDF
49
53
  post = (idx + 1).to_f / obj['boards'].length.to_f
50
54
  OBF::Utils.as_progress_percent(pre, post) do
51
55
  pdf.start_new_page unless idx == 0
52
- build_page(pdf, board, {'zipper' => zipper, 'pages' => obj['pages'], 'headerless' => !!opts['headerless'], 'text_on_top' => !!opts['text_on_top'], 'transparent_background' => !!opts['transparent_background']})
56
+ build_page(pdf, board, {
57
+ 'zipper' => zipper,
58
+ 'pages' => obj['pages'],
59
+ 'headerless' => !!opts['headerless'],
60
+ 'text_on_top' => !!opts['text_on_top'],
61
+ 'transparent_background' => !!opts['transparent_background'],
62
+ 'text_case' => opts['text_case']
63
+ })
53
64
  end
54
65
  end
55
66
  else
56
- build_page(pdf, obj, {'headerless' => !!opts['headerless'], 'text_on_top' => !!opts['text_on_top'], 'transparent_background' => !!opts['transparent_background']})
67
+ build_page(pdf, obj, {
68
+ 'headerless' => !!opts['headerless'],
69
+ 'text_on_top' => !!opts['text_on_top'],
70
+ 'transparent_background' => !!opts['transparent_background'],
71
+ 'text_case' => opts['text_case']
72
+ })
57
73
  end
58
74
 
59
75
  pdf.render_file(dest_path)
@@ -133,35 +149,64 @@ module OBF::PDF
133
149
  pdf.stroke_color border
134
150
  pdf.fill_and_stroke_rounded_rectangle [0, button_height], button_width, button_height, default_radius
135
151
  vertical = options['text_on_top'] ? button_height - text_height : button_height - 5
136
- pdf.bounding_box([5, vertical], :width => button_width - 10, :height => button_height - text_height - 5) do
137
- image = (obj['images_hash'] || {})[button['image_id']]
138
- if image
139
- bg = 'white'
140
- if options['transparent_background']
141
- bg = "\##{fill}"
152
+
153
+ text = (button['label'] || button['vocalization']).to_s
154
+ direction = text.match(rtl_regex) ? :rtl : :ltr
155
+ if opts['text_case'] == 'upper'
156
+ text = text.upcase
157
+ elsif opts['text_case'] == 'lower'
158
+ text = text.downcase
159
+ end
160
+ pdf.text_box text, :at => [0, vertical], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
161
+ if opts['text_only']
162
+ # render text
163
+ pdf.fill_color "000000"
164
+ text = (button['label'] || button['vocalization']).to_s
165
+ if opts['text_case'] == 'upper'
166
+ text = text.upcase
167
+ elsif opts['text_case'] == 'lower'
168
+ text = text.downcase
169
+ end
170
+ pdf.text_box text, :at => [0, 0], :width => button_width, :height => button_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit, :direction => direction
171
+ else
172
+ # render image
173
+ pdf.bounding_box([5, vertical], :width => button_width - 10, :height => button_height - text_height - 5) do
174
+ image = (obj['images_hash'] || {})[button['image_id']]
175
+ if image
176
+ bg = 'white'
177
+ if options['transparent_background']
178
+ bg = "\##{fill}"
179
+ end
180
+ image_local_path = image && OBF::Utils.save_image(image, options['zipper'], bg)
181
+ if image_local_path && File.exist?(image_local_path)
182
+ pdf.image image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center
183
+ File.unlink image_local_path
184
+ end
142
185
  end
143
- image_local_path = image && OBF::Utils.save_image(image, options['zipper'], bg)
144
- if image_local_path && File.exist?(image_local_path)
145
- pdf.image image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center
146
- File.unlink image_local_path
186
+ end
187
+ if options['pages'] && button['load_board']
188
+ page = options['pages'][button['load_board']['id']]
189
+ if page
190
+ page_vertical = options['text_on_top'] ? 5 + text_height : button_height - 5
191
+ pdf.fill_color "ffffff"
192
+ pdf.stroke_color "eeeeee"
193
+ pdf.fill_and_stroke_rounded_rectangle [button_width - 25, page_vertical], 20, text_height, 5
194
+ pdf.fill_color "000000"
195
+ pdf.formatted_text_box [{:text => page, :anchor => "page#{page}"}], :at => [button_width - 25, page_vertical], :width => 20, :height => text_height, :align => :center, :valign => :center
147
196
  end
148
197
  end
149
- end
150
- if options['pages'] && button['load_board']
151
- page = options['pages'][button['load_board']['id']]
152
- if page
153
- page_vertical = options['text_on_top'] ? 5 + text_height : button_height - 5
154
- pdf.fill_color "ffffff"
155
- pdf.stroke_color "eeeeee"
156
- pdf.fill_and_stroke_rounded_rectangle [button_width - 25, page_vertical], 20, text_height, 5
157
- pdf.fill_color "000000"
158
- pdf.formatted_text_box [{:text => page, :anchor => "page#{page}"}], :at => [button_width - 25, page_vertical], :width => 20, :height => text_height, :align => :center, :valign => :center
198
+
199
+ # render text
200
+ pdf.fill_color "000000"
201
+ vertical = options['text_on_top'] ? button_height : text_height
202
+ text = (button['label'] || button['vocalization']).to_s
203
+ if opts['text_case'] == 'upper'
204
+ text = text.upcase
205
+ elsif opts['text_case'] == 'lower'
206
+ text = text.downcase
159
207
  end
208
+ pdf.text_box text, :at => [0, vertical], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit
160
209
  end
161
-
162
- pdf.fill_color "000000"
163
- vertical = options['text_on_top'] ? button_height : text_height
164
- pdf.text_box (button['label'] || button['vocalization']).to_s, :at => [0, vertical], :width => button_width, :height => text_height, :align => :center, :valign => :center, :overflow => :shrink_to_fit
165
210
  end
166
211
  index = col + (row * obj['grid']['columns'])
167
212
  OBF::Utils.update_current_progress(index.to_f / (obj['grid']['rows'] * obj['grid']['columns']).to_f)
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.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-21 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json