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::Text::Formatted::Box do
@@ -260,7 +262,7 @@ describe Prawn::Text::Formatted::Box do
260
262
  expect(fonts_used[1]).to match(/Kai/)
261
263
  end
262
264
 
263
- it 'should omit the fallback fonts overhead when passing an empty array ' \
265
+ it 'omits the fallback fonts overhead when passing an empty array ' \
264
266
  'as the :fallback_fonts' do
265
267
  pdf.font('Kai')
266
268
 
@@ -299,33 +301,63 @@ describe Prawn::Text::Formatted::Box do
299
301
  end
300
302
 
301
303
  describe 'Text::Formatted::Box#extensions' do
304
+ let(:formatted_wrap_override) do
305
+ Module.new do
306
+ # rubocop: disable RSpec/InstanceVariable
307
+ def wrap(_array)
308
+ initialize_wrap([{ text: 'all your base are belong to us' }])
309
+ @line_wrap.wrap_line(
310
+ document: @document,
311
+ kerning: @kerning,
312
+ width: 10_000,
313
+ arranger: @arranger
314
+ )
315
+ fragment = @arranger.retrieve_fragment
316
+ format_and_draw_fragment(fragment, 0, @line_wrap.width, 0)
317
+
318
+ []
319
+ end
320
+ # rubocop: enable RSpec/InstanceVariable
321
+ end
322
+ end
323
+
302
324
  it 'is able to override default line wrapping' do
303
- described_class.extensions << TestFormattedWrapOverride
325
+ described_class.extensions << formatted_wrap_override
304
326
  pdf.formatted_text_box([{ text: 'hello world' }], {})
305
- described_class.extensions.delete(TestFormattedWrapOverride)
327
+ described_class.extensions.delete(formatted_wrap_override)
306
328
  text = PDF::Inspector::Text.analyze(pdf.render)
307
329
  expect(text.strings[0]).to eq('all your base are belong to us')
308
330
  end
309
331
 
310
332
  it 'overrides Text::Formatted::Box line wrapping does not affect ' \
311
333
  'Text::Box wrapping' do
312
- described_class.extensions << TestFormattedWrapOverride
334
+ described_class.extensions << formatted_wrap_override
313
335
  pdf.text_box('hello world', {})
314
- described_class.extensions.delete(TestFormattedWrapOverride)
336
+ described_class.extensions.delete(formatted_wrap_override)
315
337
  text = PDF::Inspector::Text.analyze(pdf.render)
316
338
  expect(text.strings[0]).to eq('hello world')
317
339
  end
318
340
 
319
341
  it "overring Text::Box line wrapping doesn't override Text::Box wrapping" do
320
- Prawn::Text::Box.extensions << TestFormattedWrapOverride
342
+ Prawn::Text::Box.extensions << formatted_wrap_override
321
343
  pdf.text_box('hello world', {})
322
- Prawn::Text::Box.extensions.delete(TestFormattedWrapOverride)
344
+ Prawn::Text::Box.extensions.delete(formatted_wrap_override)
323
345
  text = PDF::Inspector::Text.analyze(pdf.render)
324
346
  expect(text.strings[0]).to eq('all your base are belong to us')
325
347
  end
326
348
  end
327
349
 
328
350
  describe 'Text::Formatted::Box#render' do
351
+ let(:fragment_callback_class) do
352
+ Class.new do
353
+ def initialize(_string, _number, _options); end
354
+
355
+ def render_behind(fragment); end
356
+
357
+ def render_in_front(fragment); end
358
+ end
359
+ end
360
+
329
361
  it 'handles newlines' do
330
362
  array = [{ text: "hello\nworld" }]
331
363
  options = { document: pdf }
@@ -377,11 +409,10 @@ describe Prawn::Text::Formatted::Box do
377
409
  expect(text.strings[2]).to eq(' olleh' * number_of_hellos)
378
410
  expect(text.strings[3]).to eq('?uoy')
379
411
  end
380
- end
381
412
 
382
- describe 'Text::Formatted::Box#render' do
383
413
  it 'is able to perform fragment callbacks' do
384
- callback_object = TestFragmentCallback.new('something', 7, document: pdf)
414
+ callback_object =
415
+ fragment_callback_class.new('something', 7, document: pdf)
385
416
  allow(callback_object).to receive(:render_behind)
386
417
  allow(callback_object).to receive(:render_in_front)
387
418
  array = [
@@ -400,11 +431,12 @@ describe Prawn::Text::Formatted::Box do
400
431
  end
401
432
 
402
433
  it 'is able to perform fragment callbacks on multiple objects' do
403
- callback_object = TestFragmentCallback.new('something', 7, document: pdf)
434
+ callback_object =
435
+ fragment_callback_class.new('something', 7, document: pdf)
404
436
  allow(callback_object).to receive(:render_behind)
405
437
  allow(callback_object).to receive(:render_in_front)
406
438
 
407
- callback_object2 = TestFragmentCallback.new(
439
+ callback_object2 = fragment_callback_class.new(
408
440
  'something else', 14, document: pdf
409
441
  )
410
442
  allow(callback_object2).to receive(:render_behind)
@@ -432,11 +464,23 @@ describe Prawn::Text::Formatted::Box do
432
464
  end
433
465
 
434
466
  it 'fragment callbacks is able to define only the callback they need' do
435
- behind = TestFragmentCallbackBehind.new(
467
+ behind = (
468
+ Class.new do
469
+ def initialize(_string, _number, _options); end
470
+
471
+ def render_behind(fragment); end
472
+ end
473
+ ).new(
436
474
  'something', 7,
437
475
  document: pdf
438
476
  )
439
- in_front = TestFragmentCallbackInFront.new(
477
+ in_front = (
478
+ Class.new do
479
+ def initialize(_string, _number, _options); end
480
+
481
+ def render_in_front(fragment); end
482
+ end
483
+ ).new(
440
484
  'something', 7,
441
485
  document: pdf
442
486
  )
@@ -463,7 +507,7 @@ describe Prawn::Text::Formatted::Box do
463
507
  text_box.render
464
508
  contents = PDF::Inspector::Text.analyze(pdf.render)
465
509
  fonts = contents.font_settings.map { |e| e[:name] }
466
- expect(fonts).to eq([:Helvetica, :"Times-Bold", :Helvetica])
510
+ expect(fonts).to eq(%i[Helvetica Times-Bold Helvetica])
467
511
  expect(contents.strings[0]).to eq('this contains ')
468
512
  expect(contents.strings[1]).to eq('Times-Bold')
469
513
  expect(contents.strings[2]).to eq(' text')
@@ -479,7 +523,7 @@ describe Prawn::Text::Formatted::Box do
479
523
  text_box.render
480
524
  contents = PDF::Inspector::Text.analyze(pdf.render)
481
525
  fonts = contents.font_settings.map { |e| e[:name] }
482
- expect(fonts).to eq([:Helvetica, :"Helvetica-Bold", :Helvetica])
526
+ expect(fonts).to eq(%i[Helvetica Helvetica-Bold Helvetica])
483
527
  expect(contents.strings[0]).to eq('this contains ')
484
528
  expect(contents.strings[1]).to eq('bold')
485
529
  expect(contents.strings[2]).to eq(' text')
@@ -495,7 +539,7 @@ describe Prawn::Text::Formatted::Box do
495
539
  text_box.render
496
540
  contents = PDF::Inspector::Text.analyze(pdf.render)
497
541
  fonts = contents.font_settings.map { |e| e[:name] }
498
- expect(fonts).to eq([:Helvetica, :"Helvetica-Oblique", :Helvetica])
542
+ expect(fonts).to eq(%i[Helvetica Helvetica-Oblique Helvetica])
499
543
  end
500
544
 
501
545
  it 'is able to set subscript' do
@@ -529,15 +573,16 @@ describe Prawn::Text::Formatted::Box do
529
573
  it 'is able to set compound bold and italic text' do
530
574
  array = [
531
575
  { text: 'this contains ' },
532
- { text: 'bold italic', styles: [:bold, :italic] },
576
+ { text: 'bold italic', styles: %i[bold italic] },
533
577
  { text: ' text' }
534
578
  ]
535
579
  text_box = described_class.new(array, document: pdf)
536
580
  text_box.render
537
581
  contents = PDF::Inspector::Text.analyze(pdf.render)
538
582
  fonts = contents.font_settings.map { |e| e[:name] }
539
- expect(fonts).to eq([:Helvetica, :"Helvetica-BoldOblique", :Helvetica])
583
+ expect(fonts).to eq(%i[Helvetica Helvetica-BoldOblique Helvetica])
540
584
  end
585
+
541
586
  it 'is able to underline' do
542
587
  array = [
543
588
  { text: 'this contains ' },
@@ -740,6 +785,20 @@ describe Prawn::Text::Formatted::Box do
740
785
  contents = PDF::Inspector::Text.analyze(pdf.render)
741
786
  expect(contents.word_spacing).to be_empty
742
787
  end
788
+
789
+ it 'raise an exception when align value is not a symbol' do
790
+ array = [
791
+ { text: 'hello world ' },
792
+ { text: "\n" },
793
+ { text: 'goodbye' }
794
+ ]
795
+ options = { document: pdf, align: 'justify' }
796
+ text_box = described_class.new(array, options)
797
+ expect { text_box.render }.to raise_error(
798
+ ArgumentError,
799
+ 'align must be one of :left, :right, :center or :justify symbols'
800
+ )
801
+ end
743
802
  end
744
803
 
745
804
  describe 'Text::Formatted::Box#render with :valign => :center' do
@@ -784,42 +843,4 @@ describe Prawn::Text::Formatted::Box do
784
843
  expect(text_box.at[1]).to be_within(0.01).of(top_padding)
785
844
  end
786
845
  end
787
-
788
- class TestFragmentCallback
789
- def initialize(_string, _number, _options); end
790
-
791
- def render_behind(fragment); end
792
-
793
- def render_in_front(fragment); end
794
- end
795
-
796
- class TestFragmentCallbackBehind
797
- def initialize(_string, _number, _options); end
798
-
799
- def render_behind(fragment); end
800
- end
801
-
802
- class TestFragmentCallbackInFront
803
- def initialize(_string, _number, _options); end
804
-
805
- def render_in_front(fragment); end
806
- end
807
-
808
- # rubocop: disable RSpec/InstanceVariable
809
- module TestFormattedWrapOverride
810
- def wrap(_array)
811
- initialize_wrap([{ text: 'all your base are belong to us' }])
812
- @line_wrap.wrap_line(
813
- document: @document,
814
- kerning: @kerning,
815
- width: 10_000,
816
- arranger: @arranger
817
- )
818
- fragment = @arranger.retrieve_fragment
819
- format_and_draw_fragment(fragment, 0, @line_wrap.width, 0)
820
-
821
- []
822
- end
823
- end
824
- # rubocop: enable RSpec/InstanceVariable
825
846
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Text::Formatted::Fragment do
@@ -6,7 +8,7 @@ describe Prawn::Text::Formatted::Fragment do
6
8
  describe 'Text::Formatted::Fragment' do
7
9
  let(:fragment) do
8
10
  format_state = {
9
- styles: [:bold, :italic],
11
+ styles: %i[bold italic],
10
12
  color: nil,
11
13
  link: nil,
12
14
  anchor: nil,
@@ -35,7 +37,7 @@ describe Prawn::Text::Formatted::Fragment do
35
37
 
36
38
  describe '#styles' do
37
39
  it 'returns the styles array' do
38
- expect(fragment.styles).to eq([:bold, :italic])
40
+ expect(fragment.styles).to eq(%i[bold italic])
39
41
  end
40
42
 
41
43
  it 'nevers return nil' do
@@ -88,7 +90,7 @@ describe Prawn::Text::Formatted::Fragment do
88
90
  end
89
91
 
90
92
  describe '#absolute_bounding_box' do
91
- it 'should return the bounding box surrounding the fragment' \
93
+ it 'returns the bounding box surrounding the fragment' \
92
94
  ' in absolute coordinates' do
93
95
  target_box = [50, 193, 150, 217]
94
96
  target_box[0] += pdf.bounds.absolute_left
@@ -128,7 +130,7 @@ describe Prawn::Text::Formatted::Fragment do
128
130
  expect(fragment.space_count).to eq(2)
129
131
  end
130
132
 
131
- it 'should exclude trailing spaces from the count when ' \
133
+ it 'excludes trailing spaces from the count when ' \
132
134
  ':exclude_trailing_white_space => true' do
133
135
  format_state = { exclude_trailing_white_space: true }
134
136
  fragment = described_class.new(
@@ -165,7 +167,7 @@ describe Prawn::Text::Formatted::Fragment do
165
167
  expect(fragment.text).to eq('hello world ')
166
168
  end
167
169
 
168
- it 'should return the fragment text without trailing spaces when ' \
170
+ it 'returns the fragment text without trailing spaces when ' \
169
171
  ':exclude_trailing_white_space => true' do
170
172
  format_state = { exclude_trailing_white_space: true }
171
173
  fragment = described_class.new(
@@ -180,7 +182,7 @@ describe Prawn::Text::Formatted::Fragment do
180
182
  describe '#word_spacing=' do
181
183
  let(:fragment) do
182
184
  format_state = {
183
- styles: [:bold, :italic],
185
+ styles: %i[bold italic],
184
186
  color: nil,
185
187
  link: nil,
186
188
  anchor: nil,
@@ -314,7 +316,7 @@ describe Prawn::Text::Formatted::Fragment do
314
316
  end
315
317
 
316
318
  describe '#default_direction=' do
317
- it 'should set the direction if there is no fragment level direction ' \
319
+ it 'sets the direction if there is no fragment level direction ' \
318
320
  'specification' do
319
321
  format_state = {}
320
322
  fragment = described_class.new(
@@ -326,7 +328,7 @@ describe Prawn::Text::Formatted::Fragment do
326
328
  expect(fragment.direction).to eq(:rtl)
327
329
  end
328
330
 
329
- it 'should not set the direction if there is a fragment level direction ' \
331
+ it 'does not set the direction if there is a fragment level direction ' \
330
332
  'specification' do
331
333
  format_state = { direction: :rtl }
332
334
  fragment = described_class.new(
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Text::Formatted::LineWrap do
@@ -18,7 +20,7 @@ describe Prawn::Text::Formatted::LineWrap do
18
20
  end
19
21
  let(:line_wrap) { described_class.new }
20
22
 
21
- it 'should only return an empty string if nothing fit or there' \
23
+ it 'only returns an empty string if nothing fit or there' \
22
24
  'was nothing to wrap' do
23
25
  8.times do
24
26
  line = line_wrap.wrap_line(
@@ -59,7 +61,7 @@ describe Prawn::Text::Formatted::LineWrap do
59
61
  expect(string).to eq('hello world, goodbye')
60
62
  end
61
63
 
62
- it 'should strip trailing spaces when a white-space-only fragment was' \
64
+ it 'strips trailing spaces when a white-space-only fragment was' \
63
65
  ' successfully pushed onto the end of a line but no other non-white' \
64
66
  ' space fragment fits after it' do
65
67
  array = [
@@ -75,6 +77,7 @@ describe Prawn::Text::Formatted::LineWrap do
75
77
  )
76
78
  expect(string).to eq('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
77
79
  end
80
+
78
81
  it 'raise_errors CannotFit if a too-small width is given' do
79
82
  array = [
80
83
  { text: ' hello world, ' },
@@ -183,7 +186,7 @@ describe Prawn::Text::Formatted::LineWrap do
183
186
  expect(string).to eq('hello-')
184
187
  end
185
188
 
186
- it 'should not break after a hyphen that follows white space and' \
189
+ it 'does not break after a hyphen that follows white space and' \
187
190
  'precedes a word' do
188
191
  array = [{ text: 'hello -' }]
189
192
  arranger.format_array = array
@@ -259,7 +262,7 @@ describe Prawn::Text::Formatted::LineWrap do
259
262
  expect(res1).to eq(res2)
260
263
  end
261
264
 
262
- it 'should not display soft hyphens except at the end of a line ' \
265
+ it 'does not display soft hyphens except at the end of a line ' \
263
266
  'for more than one element in format_array', issue: 347 do
264
267
  pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
265
268
  line_wrap = described_class.new
@@ -320,7 +323,7 @@ describe Prawn::Text::Formatted::LineWrap do
320
323
  expect(string).to eq('hello')
321
324
  end
322
325
 
323
- it 'should not break after a hard hyphen that follows a soft hyphen and' \
326
+ it 'does not break after a hard hyphen that follows a soft hyphen and' \
324
327
  'precedes a word' do
325
328
  string = pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-")
326
329
  array = [{ text: string }]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Text::Formatted::Parser do
@@ -17,6 +19,7 @@ describe Prawn::Text::Formatted::Parser do
17
19
  character_spacing: nil
18
20
  )
19
21
  end
22
+
20
23
  it 'handles sub' do
21
24
  string = '<sub>subscript</sub>'
22
25
  array = described_class.format(string)
@@ -32,6 +35,7 @@ describe Prawn::Text::Formatted::Parser do
32
35
  character_spacing: nil
33
36
  )
34
37
  end
38
+
35
39
  it 'handles rgb' do
36
40
  string = "<color rgb='#ff0000'>red text</color>"
37
41
  array = described_class.format(string)
@@ -47,6 +51,7 @@ describe Prawn::Text::Formatted::Parser do
47
51
  character_spacing: nil
48
52
  )
49
53
  end
54
+
50
55
  it '# should be optional in rgb' do
51
56
  string = "<color rgb='ff0000'>red text</color>"
52
57
  array = described_class.format(string)
@@ -62,6 +67,7 @@ describe Prawn::Text::Formatted::Parser do
62
67
  character_spacing: nil
63
68
  )
64
69
  end
70
+
65
71
  it 'handles cmyk' do
66
72
  string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
67
73
  array = described_class.format(string)
@@ -77,6 +83,7 @@ describe Prawn::Text::Formatted::Parser do
77
83
  character_spacing: nil
78
84
  )
79
85
  end
86
+
80
87
  it 'handles fonts' do
81
88
  string = "<font name='Courier'>Courier text</font>"
82
89
  array = described_class.format(string)
@@ -92,6 +99,7 @@ describe Prawn::Text::Formatted::Parser do
92
99
  character_spacing: nil
93
100
  )
94
101
  end
102
+
95
103
  it 'handles size' do
96
104
  string = "<font size='14'>14 point text</font>"
97
105
  array = described_class.format(string)
@@ -107,6 +115,7 @@ describe Prawn::Text::Formatted::Parser do
107
115
  character_spacing: nil
108
116
  )
109
117
  end
118
+
110
119
  it 'handles character_spacing' do
111
120
  string = "<font character_spacing='2.5'>extra character spacing</font>"
112
121
  array = described_class.format(string)
@@ -122,6 +131,7 @@ describe Prawn::Text::Formatted::Parser do
122
131
  character_spacing: 2.5
123
132
  )
124
133
  end
134
+
125
135
  it 'handles links' do
126
136
  string = "<link href='http://example.com'>external link</link>"
127
137
  array = described_class.format(string)
@@ -137,6 +147,7 @@ describe Prawn::Text::Formatted::Parser do
137
147
  character_spacing: nil
138
148
  )
139
149
  end
150
+
140
151
  it 'handles local links' do
141
152
  string = "<link local='/home/example/foo.bar'>local link</link>"
142
153
  array = described_class.format(string)
@@ -152,6 +163,7 @@ describe Prawn::Text::Formatted::Parser do
152
163
  character_spacing: nil
153
164
  )
154
165
  end
166
+
155
167
  it 'handles anchors' do
156
168
  string = "<link anchor='ToC'>internal link</link>"
157
169
  array = described_class.format(string)
@@ -167,6 +179,7 @@ describe Prawn::Text::Formatted::Parser do
167
179
  character_spacing: nil
168
180
  )
169
181
  end
182
+
170
183
  it 'handles higher order characters properly' do
171
184
  string = "<b>©\n©</b>"
172
185
  array = described_class.format(string)
@@ -204,6 +217,7 @@ describe Prawn::Text::Formatted::Parser do
204
217
  character_spacing: nil
205
218
  )
206
219
  end
220
+
207
221
  it 'converts &lt; &gt;, and &amp; to <, >, and &, respectively' do
208
222
  string = 'hello <b>&lt;, &gt;, and &amp;</b>'
209
223
  array = described_class.format(string)
@@ -219,6 +233,7 @@ describe Prawn::Text::Formatted::Parser do
219
233
  character_spacing: nil
220
234
  )
221
235
  end
236
+
222
237
  it 'handles double qoutes around tag attributes' do
223
238
  string = 'some <font size="14">sized</font> text'
224
239
  array = described_class.format(string)
@@ -234,6 +249,7 @@ describe Prawn::Text::Formatted::Parser do
234
249
  character_spacing: nil
235
250
  )
236
251
  end
252
+
237
253
  it 'handles single qoutes around tag attributes' do
238
254
  string = "some <font size='14'>sized</font> text"
239
255
  array = described_class.format(string)
@@ -249,6 +265,7 @@ describe Prawn::Text::Formatted::Parser do
249
265
  character_spacing: nil
250
266
  )
251
267
  end
268
+
252
269
  it 'constructs a formatted text array from a string' do
253
270
  string = "hello <b>world\nhow <i>are</i></b> you?"
254
271
  array = described_class.format(string)
@@ -299,7 +316,7 @@ describe Prawn::Text::Formatted::Parser do
299
316
  )
300
317
  expect(array[4]).to eq(
301
318
  text: 'are',
302
- styles: [:bold, :italic],
319
+ styles: %i[bold italic],
303
320
  color: nil,
304
321
  link: nil,
305
322
  anchor: nil,
@@ -320,6 +337,7 @@ describe Prawn::Text::Formatted::Parser do
320
337
  character_spacing: nil
321
338
  )
322
339
  end
340
+
323
341
  it 'accepts <strong> as an alternative to <b>' do
324
342
  string = '<strong>bold</strong> not bold'
325
343
  array = described_class.format(string)
@@ -347,6 +365,7 @@ describe Prawn::Text::Formatted::Parser do
347
365
  character_spacing: nil
348
366
  )
349
367
  end
368
+
350
369
  it 'accepts <em> as an alternative to <i>' do
351
370
  string = '<em>italic</em> not italic'
352
371
  array = described_class.format(string)
@@ -374,6 +393,7 @@ describe Prawn::Text::Formatted::Parser do
374
393
  character_spacing: nil
375
394
  )
376
395
  end
396
+
377
397
  it 'accepts <a> as an alternative to <link>' do
378
398
  string = "<a href='http://example.com'>link</a> not a link"
379
399
  array = described_class.format(string)
@@ -424,6 +444,7 @@ describe Prawn::Text::Formatted::Parser do
424
444
  }]
425
445
  expect(described_class.to_string(array)).to eq(string)
426
446
  end
447
+
427
448
  it 'handles sub' do
428
449
  string = '<sub>subscript</sub>'
429
450
  array = [{
@@ -439,6 +460,7 @@ describe Prawn::Text::Formatted::Parser do
439
460
  }]
440
461
  expect(described_class.to_string(array)).to eq(string)
441
462
  end
463
+
442
464
  it 'handles rgb' do
443
465
  string = "<color rgb='ff0000'>red text</color>"
444
466
  array = [{
@@ -454,6 +476,7 @@ describe Prawn::Text::Formatted::Parser do
454
476
  }]
455
477
  expect(described_class.to_string(array)).to eq(string)
456
478
  end
479
+
457
480
  it 'handles cmyk' do
458
481
  string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
459
482
  array = [{
@@ -469,6 +492,7 @@ describe Prawn::Text::Formatted::Parser do
469
492
  }]
470
493
  expect(described_class.to_string(array)).to eq(string)
471
494
  end
495
+
472
496
  it 'handles fonts' do
473
497
  string = "<font name='Courier'>Courier text</font>"
474
498
  array = [{
@@ -484,6 +508,7 @@ describe Prawn::Text::Formatted::Parser do
484
508
  }]
485
509
  expect(described_class.to_string(array)).to eq(string)
486
510
  end
511
+
487
512
  it 'handles size' do
488
513
  string = "<font size='14'>14 point text</font>"
489
514
  array = [{
@@ -499,6 +524,7 @@ describe Prawn::Text::Formatted::Parser do
499
524
  }]
500
525
  expect(described_class.to_string(array)).to eq(string)
501
526
  end
527
+
502
528
  it 'handles character spacing' do
503
529
  string =
504
530
  "<font character_spacing='2.5'>2.5 extra character spacing</font>"
@@ -515,6 +541,7 @@ describe Prawn::Text::Formatted::Parser do
515
541
  }]
516
542
  expect(described_class.to_string(array)).to eq(string)
517
543
  end
544
+
518
545
  it 'handles links' do
519
546
  array = [{
520
547
  text: 'external link',
@@ -530,6 +557,7 @@ describe Prawn::Text::Formatted::Parser do
530
557
  string = "<link href='http://example.com'>external link</link>"
531
558
  expect(described_class.to_string(array)).to eq(string)
532
559
  end
560
+
533
561
  it 'handles anchors' do
534
562
  array = [{
535
563
  text: 'internal link',
@@ -544,6 +572,7 @@ describe Prawn::Text::Formatted::Parser do
544
572
  string = "<link anchor='ToC'>internal link</link>"
545
573
  expect(described_class.to_string(array)).to eq(string)
546
574
  end
575
+
547
576
  it 'converts <, >, and & to &lt; &gt;, and &amp;, respectively' do
548
577
  array = [
549
578
  {
@@ -568,6 +597,7 @@ describe Prawn::Text::Formatted::Parser do
568
597
  string = 'hello <b>&lt;, &gt;, and &amp;</b>'
569
598
  expect(described_class.to_string(array)).to eq(string)
570
599
  end
600
+
571
601
  it 'constructs an HTML-esque string from a formatted text array' do
572
602
  array = [
573
603
  {
@@ -608,7 +638,7 @@ describe Prawn::Text::Formatted::Parser do
608
638
  },
609
639
  {
610
640
  text: 'are',
611
- styles: [:bold, :italic],
641
+ styles: %i[bold italic],
612
642
  color: nil,
613
643
  link: nil,
614
644
  font: nil,