prawn 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +2 -0
  6. data/Rakefile +10 -3
  7. data/lib/prawn.rb +9 -3
  8. data/lib/prawn/document.rb +40 -18
  9. data/lib/prawn/document/bounding_box.rb +9 -4
  10. data/lib/prawn/document/column_box.rb +2 -0
  11. data/lib/prawn/document/internals.rb +6 -4
  12. data/lib/prawn/document/span.rb +2 -0
  13. data/lib/prawn/encoding.rb +4 -1
  14. data/lib/prawn/errors.rb +2 -0
  15. data/lib/prawn/font.rb +34 -17
  16. data/lib/prawn/font_metric_cache.rb +8 -3
  17. data/lib/prawn/{font → fonts}/afm.rb +14 -7
  18. data/lib/prawn/{font → fonts}/dfont.rb +3 -1
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/{font → fonts}/ttc.rb +3 -1
  21. data/lib/prawn/{font → fonts}/ttf.rb +23 -12
  22. data/lib/prawn/graphics.rb +24 -26
  23. data/lib/prawn/graphics/blend_mode.rb +2 -0
  24. data/lib/prawn/graphics/cap_style.rb +2 -0
  25. data/lib/prawn/graphics/color.rb +8 -3
  26. data/lib/prawn/graphics/dash.rb +3 -1
  27. data/lib/prawn/graphics/join_style.rb +2 -0
  28. data/lib/prawn/graphics/patterns.rb +7 -2
  29. data/lib/prawn/graphics/transformation.rb +5 -1
  30. data/lib/prawn/graphics/transparency.rb +2 -0
  31. data/lib/prawn/grid.rb +39 -38
  32. data/lib/prawn/image_handler.rb +2 -0
  33. data/lib/prawn/images.rb +21 -19
  34. data/lib/prawn/images/image.rb +2 -0
  35. data/lib/prawn/images/jpg.rb +2 -0
  36. data/lib/prawn/images/png.rb +9 -9
  37. data/lib/prawn/measurement_extensions.rb +2 -0
  38. data/lib/prawn/measurements.rb +5 -0
  39. data/lib/prawn/outline.rb +2 -0
  40. data/lib/prawn/repeater.rb +2 -0
  41. data/lib/prawn/security.rb +26 -24
  42. data/lib/prawn/security/arcfour.rb +2 -0
  43. data/lib/prawn/soft_mask.rb +3 -1
  44. data/lib/prawn/stamp.rb +4 -1
  45. data/lib/prawn/text.rb +14 -12
  46. data/lib/prawn/text/box.rb +3 -1
  47. data/lib/prawn/text/formatted.rb +2 -0
  48. data/lib/prawn/text/formatted/arranger.rb +12 -12
  49. data/lib/prawn/text/formatted/box.rb +23 -13
  50. data/lib/prawn/text/formatted/fragment.rb +2 -0
  51. data/lib/prawn/text/formatted/line_wrap.rb +10 -8
  52. data/lib/prawn/text/formatted/parser.rb +8 -10
  53. data/lib/prawn/text/formatted/wrap.rb +4 -2
  54. data/lib/prawn/transformation_stack.rb +5 -2
  55. data/lib/prawn/utilities.rb +2 -2
  56. data/lib/prawn/version.rb +3 -1
  57. data/lib/prawn/view.rb +15 -7
  58. data/manual/basic_concepts/adding_pages.rb +2 -0
  59. data/manual/basic_concepts/basic_concepts.rb +4 -2
  60. data/manual/basic_concepts/creation.rb +2 -0
  61. data/manual/basic_concepts/cursor.rb +2 -0
  62. data/manual/basic_concepts/measurement.rb +3 -1
  63. data/manual/basic_concepts/origin.rb +2 -0
  64. data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
  65. data/manual/basic_concepts/view.rb +2 -0
  66. data/manual/bounding_box/bounding_box.rb +4 -2
  67. data/manual/bounding_box/bounds.rb +6 -4
  68. data/manual/bounding_box/canvas.rb +2 -0
  69. data/manual/bounding_box/creation.rb +2 -0
  70. data/manual/bounding_box/indentation.rb +2 -0
  71. data/manual/bounding_box/nesting.rb +2 -0
  72. data/manual/bounding_box/russian_boxes.rb +6 -4
  73. data/manual/bounding_box/stretchy.rb +2 -0
  74. data/manual/contents.rb +2 -0
  75. data/manual/cover.rb +10 -7
  76. data/manual/document_and_page_options/background.rb +2 -0
  77. data/manual/document_and_page_options/document_and_page_options.rb +4 -2
  78. data/manual/document_and_page_options/metadata.rb +2 -0
  79. data/manual/document_and_page_options/page_margins.rb +2 -0
  80. data/manual/document_and_page_options/page_size.rb +2 -0
  81. data/manual/document_and_page_options/print_scaling.rb +2 -0
  82. data/manual/example_helper.rb +5 -2
  83. data/manual/graphics/blend_mode.rb +6 -4
  84. data/manual/graphics/circle_and_ellipse.rb +2 -0
  85. data/manual/graphics/color.rb +2 -0
  86. data/manual/graphics/common_lines.rb +2 -0
  87. data/manual/graphics/fill_and_stroke.rb +2 -0
  88. data/manual/graphics/fill_rules.rb +2 -0
  89. data/manual/graphics/gradients.rb +2 -0
  90. data/manual/graphics/graphics.rb +4 -2
  91. data/manual/graphics/helper.rb +2 -0
  92. data/manual/graphics/line_width.rb +3 -0
  93. data/manual/graphics/lines_and_curves.rb +2 -0
  94. data/manual/graphics/polygon.rb +2 -0
  95. data/manual/graphics/rectangle.rb +2 -0
  96. data/manual/graphics/rotate.rb +2 -0
  97. data/manual/graphics/scale.rb +2 -0
  98. data/manual/graphics/soft_masks.rb +2 -0
  99. data/manual/graphics/stroke_cap.rb +3 -1
  100. data/manual/graphics/stroke_dash.rb +2 -0
  101. data/manual/graphics/stroke_join.rb +3 -1
  102. data/manual/graphics/translate.rb +2 -0
  103. data/manual/graphics/transparency.rb +2 -0
  104. data/manual/how_to_read_this_manual.rb +2 -0
  105. data/manual/images/absolute_position.rb +2 -0
  106. data/manual/images/fit.rb +2 -0
  107. data/manual/images/horizontal.rb +3 -1
  108. data/manual/images/images.rb +4 -2
  109. data/manual/images/plain_image.rb +2 -0
  110. data/manual/images/scale.rb +2 -0
  111. data/manual/images/vertical.rb +3 -1
  112. data/manual/images/width_and_height.rb +2 -0
  113. data/manual/layout/boxes.rb +2 -0
  114. data/manual/layout/content.rb +2 -0
  115. data/manual/layout/layout.rb +4 -2
  116. data/manual/layout/simple_grid.rb +2 -0
  117. data/manual/outline/add_subsection_to.rb +2 -0
  118. data/manual/outline/insert_section_after.rb +2 -0
  119. data/manual/outline/outline.rb +4 -2
  120. data/manual/outline/sections_and_pages.rb +2 -0
  121. data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
  122. data/manual/repeatable_content/page_numbering.rb +2 -0
  123. data/manual/repeatable_content/repeatable_content.rb +4 -2
  124. data/manual/repeatable_content/repeater.rb +2 -0
  125. data/manual/repeatable_content/stamp.rb +2 -0
  126. data/manual/security/encryption.rb +2 -0
  127. data/manual/security/permissions.rb +2 -0
  128. data/manual/security/security.rb +4 -2
  129. data/manual/table.rb +2 -0
  130. data/manual/text/alignment.rb +2 -0
  131. data/manual/text/color.rb +2 -0
  132. data/manual/text/column_box.rb +4 -2
  133. data/manual/text/fallback_fonts.rb +4 -2
  134. data/manual/text/font.rb +2 -0
  135. data/manual/text/font_size.rb +2 -0
  136. data/manual/text/font_style.rb +4 -2
  137. data/manual/text/formatted_callbacks.rb +2 -0
  138. data/manual/text/formatted_text.rb +3 -1
  139. data/manual/text/free_flowing_text.rb +2 -0
  140. data/manual/text/inline.rb +2 -0
  141. data/manual/text/kerning_and_character_spacing.rb +2 -0
  142. data/manual/text/leading.rb +2 -0
  143. data/manual/text/line_wrapping.rb +4 -1
  144. data/manual/text/paragraph_indentation.rb +2 -0
  145. data/manual/text/positioned_text.rb +2 -0
  146. data/manual/text/registering_families.rb +4 -2
  147. data/manual/text/rendering_and_color.rb +2 -0
  148. data/manual/text/right_to_left_text.rb +2 -0
  149. data/manual/text/rotation.rb +3 -1
  150. data/manual/text/single_usage.rb +2 -0
  151. data/manual/text/text.rb +4 -3
  152. data/manual/text/text_box_excess.rb +2 -0
  153. data/manual/text/text_box_extensions.rb +2 -0
  154. data/manual/text/text_box_overflow.rb +3 -1
  155. data/manual/text/utf8.rb +3 -1
  156. data/manual/text/win_ansi_charset.rb +6 -3
  157. data/prawn.gemspec +14 -11
  158. data/spec/extensions/encoding_helpers.rb +4 -2
  159. data/spec/prawn/document/bounding_box_spec.rb +8 -8
  160. data/spec/prawn/document/column_box_spec.rb +2 -0
  161. data/spec/prawn/document/security_spec.rb +12 -9
  162. data/spec/prawn/document_annotations_spec.rb +2 -0
  163. data/spec/prawn/document_destinations_spec.rb +2 -0
  164. data/spec/prawn/document_grid_spec.rb +3 -0
  165. data/spec/prawn/document_reference_spec.rb +2 -0
  166. data/spec/prawn/document_span_spec.rb +2 -0
  167. data/spec/prawn/document_spec.rb +59 -14
  168. data/spec/prawn/font_metric_cache_spec.rb +2 -0
  169. data/spec/prawn/font_spec.rb +45 -16
  170. data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
  171. data/spec/prawn/graphics/transparency_spec.rb +2 -0
  172. data/spec/prawn/graphics_spec.rb +40 -20
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
  174. data/spec/prawn/image_handler_spec.rb +2 -0
  175. data/spec/prawn/images/jpg_spec.rb +2 -0
  176. data/spec/prawn/images/png_spec.rb +2 -0
  177. data/spec/prawn/images_spec.rb +56 -2
  178. data/spec/prawn/measurements_extensions_spec.rb +2 -0
  179. data/spec/prawn/outline_spec.rb +6 -2
  180. data/spec/prawn/repeater_spec.rb +6 -4
  181. data/spec/prawn/soft_mask_spec.rb +2 -0
  182. data/spec/prawn/stamp_spec.rb +11 -7
  183. data/spec/prawn/text/box_spec.rb +26 -27
  184. data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
  185. data/spec/prawn/text/formatted/box_spec.rb +78 -57
  186. data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
  188. data/spec/prawn/text/formatted/parser_spec.rb +32 -2
  189. data/spec/prawn/text_draw_text_spec.rb +5 -3
  190. data/spec/prawn/text_rendering_mode_spec.rb +7 -1
  191. data/spec/prawn/text_spacing_spec.rb +6 -4
  192. data/spec/prawn/text_spec.rb +9 -7
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
  194. data/spec/prawn/transformation_stack_spec.rb +2 -0
  195. data/spec/prawn/view_spec.rb +18 -0
  196. data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
  197. data/spec/spec_helper.rb +9 -10
  198. metadata +86 -73
  199. metadata.gz.sig +4 -2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Graphics do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::ImageHandler do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Spec'ing the PNG class. Not complete yet - still needs to check the
2
4
  # contents of palette and transparency to ensure they're correct.
3
5
  # Need to find files that have these sections first.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Spec'ing the PNG class. Not complete yet - still needs to check the
2
4
  # contents of palette and transparency to ensure they're correct.
3
5
  # Need to find files that have these sections first.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'set'
3
5
  require 'pathname'
@@ -41,12 +43,63 @@ describe Prawn::Images do
41
43
  expect(info.height).to eq(453)
42
44
  end
43
45
 
46
+ it 'does not close passed-in IO objects' do
47
+ file = File.open(filename, 'rb')
48
+ _info = pdf.image(file)
49
+
50
+ expect(file).to_not be_closed
51
+ end
52
+
44
53
  it 'accepts Pathname objects' do
45
54
  info = pdf.image(Pathname.new(filename))
46
55
  expect(info.height).to eq(453)
47
56
  end
48
57
 
49
- context 'setting the length of the bytestream' do
58
+ describe 'closes opened files again after getting Pathnames', issue: 975 do
59
+ describe 'spec with File message spy' do
60
+ let(:not_filename) { 'non-existent filename' }
61
+ let(:pathname_double) { instance_double('Pathname', file?: true) }
62
+
63
+ before do
64
+ file_content = File.new(filename, 'rb').read
65
+ allow(Pathname).to receive(:new).with(not_filename) { pathname_double }
66
+ allow(pathname_double).to receive(:binread) { file_content }
67
+ end
68
+
69
+ it 'uses only binread, which closes opened files' do
70
+ # this implicitly tests that a file handle is closed again
71
+ # because only stubbed binread can be called on not_filename
72
+ _info = pdf.image(not_filename)
73
+ expect(pathname_double).to have_received(:binread)
74
+ end
75
+ end
76
+
77
+ system_has_lsof = system('lsof -v > /dev/null 2>&1')
78
+ system_has_grep = system('grep --version > /dev/null 2>&1')
79
+ if system_has_lsof && system_has_grep
80
+ it 'closes opened files, spec with lsof' do
81
+ gc_was_disabled = GC.disable # GC of File would close the file
82
+ open_before = `lsof -c ruby | grep "#{filename}"`
83
+ _info = pdf.image(Pathname.new(filename))
84
+ open_after = `lsof -c ruby | grep "#{filename}"`
85
+ GC.enable unless gc_was_disabled
86
+ expect(open_after).to eq(open_before)
87
+ end
88
+ end
89
+
90
+ if RUBY_PLATFORM != 'java'
91
+ it 'closes opened files, spec with ObjectSpace' do
92
+ gc_was_disabled = GC.disable # GC of File would close the file
93
+ open_before = ObjectSpace.each_object(File).count { |f| !f.closed? }
94
+ _info = pdf.image(Pathname.new(filename))
95
+ open_after = ObjectSpace.each_object(File).count { |f| !f.closed? }
96
+ GC.enable unless gc_was_disabled
97
+ expect(open_after).to eq(open_before)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe 'setting the length of the bytestream' do
50
103
  it 'correctlies work with images from Pathname objects' do
51
104
  pdf.image(Pathname.new(filename))
52
105
  expect(pdf).to have_parseable_xobjects
@@ -111,7 +164,7 @@ describe Prawn::Images do
111
164
  end[:Kids]
112
165
  expect(pages.size).to eq(1)
113
166
  expect(Set.new(hash[pages[0]][:Resources][:XObject].keys)).to eq(
114
- Set.new([:I1, :I2])
167
+ Set.new(%i[I1 I2])
115
168
  )
116
169
  end
117
170
 
@@ -137,6 +190,7 @@ describe Prawn::Images do
137
190
  expect(info.scaled_width).to eq(604)
138
191
  expect(info.scaled_height).to eq(453)
139
192
  end
193
+
140
194
  it 'moves text position' do
141
195
  y = pdf.y
142
196
  pdf.image filename, fit: [100, 400]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'prawn/measurement_extensions'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Outline do
@@ -42,6 +44,7 @@ describe Prawn::Outline do
42
44
  it 'stores all outline titles as UTF-16' do
43
45
  hash.each_value do |obj|
44
46
  next unless obj.is_a?(Hash) && obj[:Title]
47
+
45
48
  title = obj[:Title].dup
46
49
  title.force_encoding(Encoding::UTF_16LE)
47
50
  expect(title.valid_encoding?).to eq(true)
@@ -157,7 +160,7 @@ describe Prawn::Outline do
157
160
  end
158
161
 
159
162
  describe '#outline.add_subsection_to' do
160
- context 'positioned last' do
163
+ context 'when positioned last' do
161
164
  before do
162
165
  pdf.start_new_page
163
166
  pdf.text 'Page 3. An added subsection '
@@ -203,7 +206,7 @@ describe Prawn::Outline do
203
206
  end
204
207
  end
205
208
 
206
- context 'positioned first' do
209
+ context 'when positioned first' do
207
210
  before do
208
211
  pdf.start_new_page
209
212
  pdf.text 'Page 3. An added subsection '
@@ -395,6 +398,7 @@ describe Prawn::Outline do
395
398
  def find_by_title(title)
396
399
  hash.values.find do |obj|
397
400
  next unless obj.is_a?(Hash) && obj[:Title]
401
+
398
402
  title_codepoints = obj[:Title].unpack('n*')
399
403
  title_codepoints.shift
400
404
  utf8_title = title_codepoints.pack('U*')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Repeater do
@@ -128,11 +130,11 @@ describe Prawn::Repeater do
128
130
  doc
129
131
  end
130
132
 
131
- def repeater(*args, &b)
132
- Prawn::Repeater.new(*args, &b)
133
+ def repeater(*args, &block)
134
+ Prawn::Repeater.new(*args, &block)
133
135
  end
134
136
 
135
- context 'graphic state' do
137
+ describe 'graphic state' do
136
138
  let(:pdf) { create_pdf }
137
139
 
138
140
  it 'does not alter the graphic state stack color space' do
@@ -144,7 +146,7 @@ describe Prawn::Repeater do
144
146
  .to eq(starting_color_space)
145
147
  end
146
148
 
147
- context 'dynamic repeaters' do
149
+ context 'with dynamic repeaters' do
148
150
  it 'preserves the graphic state at creation time' do
149
151
  pdf.repeat :all, dynamic: true do
150
152
  pdf.text "fill_color: #{pdf.graphic_state.fill_color}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::SoftMask do
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Stamp do
4
6
  describe 'create_stamp before any page is added' do
5
7
  let(:pdf) { Prawn::Document.new(skip_page_creation: true) }
8
+
6
9
  it 'works with the font class' do
7
10
  # If anything goes wrong, Prawn::Errors::NotOnPage will be raised
8
11
  pdf.create_stamp('my_stamp') do
@@ -35,16 +38,16 @@ describe Prawn::Stamp do
35
38
  describe 'Document with a stamp' do
36
39
  let(:pdf) { create_pdf }
37
40
 
38
- it 'should raise_error NameTaken error when attempt to create stamp ' \
39
- 'with same name as an existing stamp' do
41
+ it 'raises NameTaken error when attempt to create stamp with '\
42
+ 'same name as an existing stamp' do
40
43
  pdf.create_stamp('MyStamp')
41
44
  expect do
42
45
  pdf.create_stamp('MyStamp')
43
46
  end.to raise_error(Prawn::Errors::NameTaken)
44
47
  end
45
48
 
46
- it 'should raise_error InvalidName error when attempt to create ' \
47
- 'stamp with a blank name' do
49
+ it 'raises InvalidName error when attempt to create stamp with '\
50
+ 'a blank name' do
48
51
  expect do
49
52
  pdf.create_stamp('')
50
53
  end.to raise_error(Prawn::Errors::InvalidName)
@@ -92,7 +95,8 @@ describe Prawn::Stamp do
92
95
  objects = output.split('endobj')
93
96
 
94
97
  objects.each do |obj|
95
- next unless obj =~ %r{/Type /Page$}
98
+ next unless %r{/Type /Page$}.match?(obj)
99
+
96
100
  # The page object must contain the annotation reference
97
101
  # to render a clickable link
98
102
  expect(obj).to match(%r{^/Annots \[\d \d .\]$})
@@ -112,9 +116,9 @@ describe Prawn::Stamp do
112
116
  output = pdf.render
113
117
  objects = output.split('endobj')
114
118
  objects.each do |object|
115
- if object =~ %r{/Type /Page$}
119
+ if %r{/Type /Page$}.match?(object)
116
120
  expect(object).to_not match(%r{/ExtGState})
117
- elsif object =~ %r{/Type /XObject$}
121
+ elsif %r{/Type /XObject$}.match?(object)
118
122
  expect(object).to match(%r{/ExtGState})
119
123
  end
120
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Text::Box do
@@ -56,8 +58,8 @@ describe Prawn::Text::Box do
56
58
  expect(text.strings[1]).to eq("I'm fine, thank you.")
57
59
  end
58
60
 
59
- it 'should only require enough space for the descender and the ascender ' \
60
- 'when determining whether a line can fit' do
61
+ it 'only requires enough space for the descender and the ascender '\
62
+ 'when determining whether a line can fit' do
61
63
  text = 'Oh hai text rect'
62
64
  options = {
63
65
  document: pdf,
@@ -110,8 +112,7 @@ describe Prawn::Text::Box do
110
112
  end
111
113
 
112
114
  describe '#line_gap' do
113
- it 'should == the line gap of the font when using a single ' \
114
- 'font and font size' do
115
+ it '==S the line gap of the font when using a single font and font size' do
115
116
  string = "Hello world, how are you?\nI'm fine, thank you."
116
117
  text_box = described_class.new(string, document: pdf)
117
118
  text_box.render
@@ -140,8 +141,8 @@ describe Prawn::Text::Box do
140
141
  end
141
142
 
142
143
  describe '#height without leading' do
143
- it 'should == the sum of the height of each line, ' \
144
- 'not including the space below the last line' do
144
+ it 'is the sum of the height of each line, not including the space below '\
145
+ 'the last line' do
145
146
  text = "Oh hai text rect.\nOh hai text rect."
146
147
  options = { document: pdf }
147
148
  text_box = described_class.new(text, options)
@@ -152,8 +153,8 @@ describe Prawn::Text::Box do
152
153
  end
153
154
 
154
155
  describe '#height with leading' do
155
- it 'should == the sum of the height of each line plus leading, ' \
156
- 'but not including the space below the last line' do
156
+ it 'is the sum of the height of each line plus leading, but not including '\
157
+ 'the space below the last line' do
157
158
  text = "Oh hai text rect.\nOh hai text rect."
158
159
  leading = 12
159
160
  options = { document: pdf, leading: leading }
@@ -327,7 +328,7 @@ describe Prawn::Text::Box do
327
328
  }
328
329
  end
329
330
 
330
- context ':rotate_around option of :center' do
331
+ context 'with :rotate_around option of :center' do
331
332
  it 'draws content to the page rotated about the center of the text' do
332
333
  options[:rotate_around] = :center
333
334
  text_box = described_class.new(text, options)
@@ -356,7 +357,7 @@ describe Prawn::Text::Box do
356
357
  end
357
358
  end
358
359
 
359
- context ':rotate_around option of :upper_left' do
360
+ context 'with :rotate_around option of :upper_left' do
360
361
  it 'draws content to the page rotated about the upper left corner of '\
361
362
  'the text' do
362
363
  options[:rotate_around] = :upper_left
@@ -384,7 +385,7 @@ describe Prawn::Text::Box do
384
385
  end
385
386
  end
386
387
 
387
- context 'default :rotate_around' do
388
+ context 'with default :rotate_around' do
388
389
  it 'draws content to the page rotated about the upper left corner of '\
389
390
  'the text' do
390
391
  text_box = described_class.new(text, options)
@@ -411,7 +412,7 @@ describe Prawn::Text::Box do
411
412
  end
412
413
  end
413
414
 
414
- context ':rotate_around option of :upper_right' do
415
+ context 'with :rotate_around option of :upper_right' do
415
416
  it 'draws content to the page rotated about the upper right corner of '\
416
417
  'the text' do
417
418
  options[:rotate_around] = :upper_right
@@ -441,7 +442,7 @@ describe Prawn::Text::Box do
441
442
  end
442
443
  end
443
444
 
444
- context ':rotate_around option of :lower_right' do
445
+ context 'with :rotate_around option of :lower_right' do
445
446
  it 'draws content to the page rotated about the lower right corner of '\
446
447
  'the text' do
447
448
  options[:rotate_around] = :lower_right
@@ -471,7 +472,7 @@ describe Prawn::Text::Box do
471
472
  end
472
473
  end
473
474
 
474
- context ':rotate_around option of :lower_left' do
475
+ context 'with :rotate_around option of :lower_left' do
475
476
  it 'draws content to the page rotated about the lower left corner of '\
476
477
  'the text' do
477
478
  options[:rotate_around] = :lower_left
@@ -521,8 +522,8 @@ describe Prawn::Text::Box do
521
522
  end
522
523
  end
523
524
 
524
- it 'should use the parent-box bottom if in a stretchy bbox and ' \
525
- 'overflow is :expand, even with an explicit height' do
525
+ it 'uses the parent-box bottom if in a stretchy bbox and overflow is '\
526
+ ':expand, even with an explicit height' do
526
527
  pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.width) do
527
528
  target_height = pdf.y - pdf.bounds.bottom
528
529
  text = "Oh hai\n" * 60
@@ -663,7 +664,7 @@ describe Prawn::Text::Box do
663
664
  end
664
665
  end
665
666
 
666
- context 'printing UTF-8 string with higher bit characters' do
667
+ context 'when printing UTF-8 string with higher bit characters' do
667
668
  let(:text) { '©' }
668
669
 
669
670
  let(:text_box) do
@@ -714,7 +715,7 @@ describe Prawn::Text::Box do
714
715
  }
715
716
  end
716
717
 
717
- context 'truncated overflow' do
718
+ context 'when truncated overflow' do
718
719
  let(:text_box) do
719
720
  described_class.new(text, options.merge(overflow: :truncate))
720
721
  end
@@ -756,7 +757,7 @@ describe Prawn::Text::Box do
756
757
  end
757
758
  end
758
759
 
759
- context 'truncated with text and size taken from the manual' do
760
+ context 'when truncated with text and size taken from the manual' do
760
761
  it 'returns the right text' do
761
762
  text = 'This is the beginning of the text. It will be cut somewhere ' \
762
763
  'and the rest of the text will procede to be rendered this time by '\
@@ -775,7 +776,7 @@ describe Prawn::Text::Box do
775
776
  end
776
777
  end
777
778
 
778
- context 'expand overflow' do
779
+ context 'when expand overflow' do
779
780
  let(:text_box) do
780
781
  described_class.new(text, options.merge(overflow: :expand))
781
782
  end
@@ -799,7 +800,7 @@ describe Prawn::Text::Box do
799
800
  end
800
801
  end
801
802
 
802
- context 'shrink_to_fit overflow' do
803
+ context 'when shrink_to_fit overflow' do
803
804
  let(:text_box) do
804
805
  described_class.new(
805
806
  text,
@@ -818,9 +819,7 @@ describe Prawn::Text::Box do
818
819
  it 'render returns an empty string because no text remains unprinted' do
819
820
  expect(text_box.render).to eq('')
820
821
  end
821
- end
822
822
 
823
- context 'shrink_to_fit overflow' do
824
823
  it 'does not drop below the minimum font size' do
825
824
  options[:overflow] = :shrink_to_fit
826
825
  options[:min_font_size] = 10.1
@@ -1018,7 +1017,7 @@ describe Prawn::Text::Box do
1018
1017
  expect(text_box.text).to eq(expect)
1019
1018
  end
1020
1019
 
1021
- it 'wraps lines comprised of a single word of the bounds when '\
1020
+ it 'wraps lines comprised of a single non-alpha word of the bounds when '\
1022
1021
  'wrapping text' do
1023
1022
  text = '©' * 30
1024
1023
 
@@ -1031,8 +1030,8 @@ describe Prawn::Text::Box do
1031
1030
 
1032
1031
  text_box.render
1033
1032
 
1034
- expected = '©' * 25 + "\n" + '©' * 5
1035
- pdf.font.normalize_encoding!(expected)
1033
+ expected = +'©' * 25 + "\n" + '©' * 5
1034
+ expected = pdf.font.normalize_encoding(expected)
1036
1035
  expected = expected.force_encoding(Encoding::UTF_8)
1037
1036
  expect(text_box.text).to eq(expected)
1038
1037
  end
@@ -1104,7 +1103,7 @@ describe Prawn::Text::Box do
1104
1103
  end
1105
1104
 
1106
1105
  def reduce_precision(float)
1107
- (format '%.5f', float).to_f
1106
+ float.round(5)
1108
1107
  end
1109
1108
 
1110
1109
  def first_line(str)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Text::Formatted::Arranger do
@@ -9,7 +11,7 @@ describe Prawn::Text::Formatted::Arranger do
9
11
  array = [
10
12
  { text: 'hello ' },
11
13
  { text: 'world how ', styles: [:bold] },
12
- { text: 'are', styles: [:bold, :italic] },
14
+ { text: 'are', styles: %i[bold italic] },
13
15
  { text: ' you?' }
14
16
  ]
15
17
 
@@ -18,7 +20,7 @@ describe Prawn::Text::Formatted::Arranger do
18
20
  expect(arranger.unconsumed[0]).to eq(text: 'hello ')
19
21
  expect(arranger.unconsumed[1]).to eq(text: 'world how ', styles: [:bold])
20
22
  expect(arranger.unconsumed[2])
21
- .to eq(text: 'are', styles: [:bold, :italic])
23
+ .to eq(text: 'are', styles: %i[bold italic])
22
24
  expect(arranger.unconsumed[3]).to eq(text: ' you?')
23
25
  end
24
26
 
@@ -65,7 +67,7 @@ describe Prawn::Text::Formatted::Arranger do
65
67
  [
66
68
  { text: 'hello ' },
67
69
  { text: 'world how ', styles: [:bold] },
68
- { text: 'are', styles: [:bold, :italic] },
70
+ { text: 'are', styles: %i[bold italic] },
69
71
  { text: ' you?' }
70
72
  ]
71
73
  end
@@ -85,7 +87,7 @@ describe Prawn::Text::Formatted::Arranger do
85
87
 
86
88
  expect(arranger.consumed[0]).to eq(text: 'hello ')
87
89
  expect(arranger.consumed[1]).to eq(text: 'world how ', styles: [:bold])
88
- expect(arranger.consumed[2]).to eq(text: 'are', styles: [:bold, :italic])
90
+ expect(arranger.consumed[2]).to eq(text: 'are', styles: %i[bold italic])
89
91
  expect(arranger.consumed[3]).to eq(text: ' you?')
90
92
  end
91
93
 
@@ -97,7 +99,7 @@ describe Prawn::Text::Formatted::Arranger do
97
99
  expect(arranger.current_format_state).to eq(styles: [:bold])
98
100
 
99
101
  arranger.next_string
100
- expect(arranger.current_format_state).to eq(styles: [:bold, :italic])
102
+ expect(arranger.current_format_state).to eq(styles: %i[bold italic])
101
103
 
102
104
  arranger.next_string
103
105
  expect(arranger.current_format_state).to eq({})
@@ -155,7 +157,7 @@ describe Prawn::Text::Formatted::Arranger do
155
157
  [
156
158
  { text: 'hello ' },
157
159
  { text: 'world how ', styles: [:bold] },
158
- { text: 'are', styles: [:bold, :italic] },
160
+ { text: 'are', styles: %i[bold italic] },
159
161
  { text: ' you?' }
160
162
  ]
161
163
  end
@@ -164,7 +166,7 @@ describe Prawn::Text::Formatted::Arranger do
164
166
  arranger.format_array = array
165
167
  end
166
168
 
167
- context 'after all strings have been consumed' do
169
+ describe 'after all strings have been consumed' do
168
170
  before do
169
171
  while arranger.next_string
170
172
  end
@@ -174,7 +176,7 @@ describe Prawn::Text::Formatted::Arranger do
174
176
  expect { arranger.retrieve_fragment }.to raise_error(RuntimeError)
175
177
  end
176
178
 
177
- context 'and finalized' do
179
+ describe 'and finalized' do
178
180
  before do
179
181
  arranger.finalize_line
180
182
  end
@@ -196,13 +198,13 @@ describe Prawn::Text::Formatted::Arranger do
196
198
  end
197
199
 
198
200
  describe '#update_last_string' do
199
- it 'should update the last retrieved string with what actually fit on' \
200
- 'the line and the list of unconsumed with what did not' do
201
+ it 'updates the last retrieved string with what actually fit on the line '\
202
+ 'and the list of unconsumed with what did not' do
201
203
  array = [
202
204
  { text: 'hello ' },
203
205
  { text: 'world how ', styles: [:bold] },
204
- { text: 'are', styles: [:bold, :italic] },
205
- { text: ' you now?', styles: [:bold, :italic] }
206
+ { text: 'are', styles: %i[bold italic] },
207
+ { text: ' you now?', styles: %i[bold italic] }
206
208
  ]
207
209
  arranger.format_array = array
208
210
  while arranger.next_string
@@ -210,10 +212,10 @@ describe Prawn::Text::Formatted::Arranger do
210
212
  arranger.update_last_string(' you', ' now?', nil)
211
213
  expect(arranger.consumed[3]).to eq(
212
214
  text: ' you',
213
- styles: [:bold, :italic]
215
+ styles: %i[bold italic]
214
216
  )
215
217
  expect(arranger.unconsumed).to eq([
216
- { text: ' now?', styles: [:bold, :italic] }
218
+ { text: ' now?', styles: %i[bold italic] }
217
219
  ])
218
220
  end
219
221
 
@@ -221,12 +223,12 @@ describe Prawn::Text::Formatted::Arranger do
221
223
  array = [
222
224
  { text: 'hello ' },
223
225
  { text: 'world how ', styles: [:bold] },
224
- { text: 'are', styles: [:bold, :italic] },
226
+ { text: 'are', styles: %i[bold italic] },
225
227
  { text: ' you now?' }
226
228
  ]
227
229
  arranger.format_array = array
228
230
  3.times { arranger.next_string }
229
- expect(arranger.current_format_state).to eq(styles: [:bold, :italic])
231
+ expect(arranger.current_format_state).to eq(styles: %i[bold italic])
230
232
  arranger.update_last_string('', 'are', '-')
231
233
  expect(arranger.current_format_state).to eq(styles: [:bold])
232
234
  end
@@ -236,7 +238,7 @@ describe Prawn::Text::Formatted::Arranger do
236
238
  array = [
237
239
  { text: 'hello ' },
238
240
  { text: 'world how ', styles: [:bold] },
239
- { text: 'are', styles: [:bold, :italic] },
241
+ { text: 'are', styles: %i[bold italic] },
240
242
  { text: ' you now?' }
241
243
  ]
242
244
  arranger.format_array = array
@@ -253,7 +255,7 @@ describe Prawn::Text::Formatted::Arranger do
253
255
  array = [
254
256
  { text: 'hello ' },
255
257
  { text: 'world how ', styles: [:bold] },
256
- { text: 'are', styles: [:bold, :italic] },
258
+ { text: 'are', styles: %i[bold italic] },
257
259
  { text: ' you?' }
258
260
  ]
259
261
  arranger.format_array = array
@@ -274,12 +276,12 @@ describe Prawn::Text::Formatted::Arranger do
274
276
  end
275
277
 
276
278
  describe '#finalize_line' do
277
- it 'should make it so that all trailing white space fragments ' \
278
- 'exclude trailing white space' do
279
+ it 'makes it so that all trailing white space fragments exclude '\
280
+ 'trailing white space' do
279
281
  array = [
280
282
  { text: 'hello ' },
281
283
  { text: 'world how ', styles: [:bold] },
282
- { text: ' ', styles: [:bold, :italic] }
284
+ { text: ' ', styles: %i[bold italic] }
283
285
  ]
284
286
  arranger.format_array = array
285
287
  while arranger.next_string
@@ -374,7 +376,7 @@ describe Prawn::Text::Formatted::Arranger do
374
376
  array = [
375
377
  { text: 'hello ' },
376
378
  { text: 'world how ', styles: [:bold] },
377
- { text: 'are', styles: [:bold, :italic] },
379
+ { text: 'are', styles: %i[bold italic] },
378
380
  { text: ' you now?' }
379
381
  ]
380
382
  arranger.format_array = array
@@ -385,7 +387,7 @@ describe Prawn::Text::Formatted::Arranger do
385
387
  array = [
386
388
  { text: 'hello ' },
387
389
  { text: 'world how ', styles: [:bold] },
388
- { text: 'are', styles: [:bold, :italic] },
390
+ { text: 'are', styles: %i[bold italic] },
389
391
  { text: ' you now?' }
390
392
  ]
391
393
  arranger.format_array = array
@@ -400,7 +402,7 @@ describe Prawn::Text::Formatted::Arranger do
400
402
  array = [
401
403
  { text: 'hello ' },
402
404
  { text: 'world how ', styles: [:bold] },
403
- { text: 'are', styles: [:bold, :italic] },
405
+ { text: 'are', styles: %i[bold italic] },
404
406
  { text: ' you now?' }
405
407
  ]
406
408
  arranger.format_array = array
@@ -414,7 +416,7 @@ describe Prawn::Text::Formatted::Arranger do
414
416
  array = [
415
417
  { text: 'hello ' },
416
418
  { text: 'world how ', styles: [:bold] },
417
- { text: 'are', styles: [:bold, :italic] },
419
+ { text: 'are', styles: %i[bold italic] },
418
420
  { text: ' you now?' }
419
421
  ]
420
422
  arranger.format_array = array
@@ -429,7 +431,7 @@ describe Prawn::Text::Formatted::Arranger do
429
431
  array = [
430
432
  { text: 'hello ' },
431
433
  { text: 'world how ', styles: [:bold] },
432
- { text: 'are', styles: [:bold, :italic], size: 28 },
434
+ { text: 'are', styles: %i[bold italic], size: 28 },
433
435
  { text: ' you now?' }
434
436
  ]
435
437
  arranger.format_array = array
@@ -445,7 +447,7 @@ describe Prawn::Text::Formatted::Arranger do
445
447
  array = [
446
448
  { text: 'hello ' },
447
449
  { text: 'world how ', styles: [:bold] },
448
- { text: 'are', styles: [:bold, :italic] },
450
+ { text: 'are', styles: %i[bold italic] },
449
451
  { text: ' you now?' }
450
452
  ]
451
453
  arranger.format_array = array
@@ -456,7 +458,7 @@ describe Prawn::Text::Formatted::Arranger do
456
458
  arranger.retrieve_fragment
457
459
  arranger.repack_unretrieved
458
460
  expect(arranger.unconsumed).to eq([
459
- { text: 'are', styles: [:bold, :italic] },
461
+ { text: 'are', styles: %i[bold italic] },
460
462
  { text: ' you now?' }
461
463
  ])
462
464
  end