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::Document do
@@ -26,6 +28,7 @@ describe Prawn::Document do
26
28
  let(:num_columns) { 5 }
27
29
  let(:num_rows) { 8 }
28
30
  let(:gutter) { 10.0 }
31
+
29
32
  before do
30
33
  pdf.define_grid(
31
34
  columns: num_columns,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Document do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Document do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'tempfile'
3
5
 
@@ -32,7 +34,7 @@ describe Prawn::Document do
32
34
 
33
35
  describe 'when generating a document with a custom text formatter' do
34
36
  it 'uses the provided text formatter' do
35
- class TestTextFormatter
37
+ text_formatter = Class.new do
36
38
  def self.format(string)
37
39
  [
38
40
  {
@@ -49,7 +51,7 @@ describe Prawn::Document do
49
51
  ]
50
52
  end
51
53
  end
52
- pdf = described_class.new text_formatter: TestTextFormatter
54
+ pdf = described_class.new text_formatter: text_formatter
53
55
  pdf.text 'Dr. Who?', inline_format: true
54
56
  text = PDF::Inspector::Text.analyze(pdf.render)
55
57
  expect(text.strings.first).to eq("Just 'The Doctor'.")
@@ -161,6 +163,48 @@ describe Prawn::Document do
161
163
  end
162
164
  end
163
165
 
166
+ describe '#delete_page(index)' do
167
+ before do
168
+ pdf.text 'Page one'
169
+ pdf.start_new_page
170
+ pdf.text 'Page two'
171
+ pdf.start_new_page
172
+ pdf.text 'Page three'
173
+ end
174
+
175
+ it 'destroy a specific page of the document' do
176
+ pdf.delete_page(1)
177
+ expect(pdf.page_number).to eq(2)
178
+ text_analysis = PDF::Inspector::Text.analyze(pdf.render)
179
+ expect(text_analysis.strings).to eq(['Page one', 'Page three'])
180
+ end
181
+
182
+ it 'destroy the last page of the document' do
183
+ pdf.delete_page(-1)
184
+ expect(pdf.page_number).to eq(2)
185
+ text_analysis = PDF::Inspector::Text.analyze(pdf.render)
186
+ expect(text_analysis.strings).to eq(['Page one', 'Page two'])
187
+ end
188
+
189
+ context 'with an invalid index' do
190
+ let(:expected_content) { ['Page one', 'Page two', 'Page three'] }
191
+
192
+ it 'does not destroy an invalid positve index' do
193
+ pdf.delete_page(42)
194
+ expect(pdf.page_number).to eq(3)
195
+ text_analysis = PDF::Inspector::Text.analyze(pdf.render)
196
+ expect(text_analysis.strings).to eq(expected_content)
197
+ end
198
+
199
+ it 'does not destroy an invalid negative index' do
200
+ pdf.delete_page(-42)
201
+ expect(pdf.page_number).to eq(3)
202
+ text_analysis = PDF::Inspector::Text.analyze(pdf.render)
203
+ expect(text_analysis.strings).to eq(expected_content)
204
+ end
205
+ end
206
+ end
207
+
164
208
  describe '#page_number' do
165
209
  it 'is 1 for a new document' do
166
210
  pdf = described_class.new
@@ -356,7 +400,7 @@ describe Prawn::Document do
356
400
  end
357
401
 
358
402
  (PDF::Core::PageGeometry::SIZES.keys - ['LETTER']).each do |k|
359
- it "should provide #{k} geometry" do
403
+ it "provides #{k} geometry" do
360
404
  pdf = described_class.new(page_size: k)
361
405
  pages = PDF::Inspector::Page.analyze(pdf.render).pages
362
406
  expect(pages.first[:size]).to eq(PDF::Core::PageGeometry::SIZES[k])
@@ -572,7 +616,7 @@ describe Prawn::Document do
572
616
  expect(pdf).to_not have_received(:text_box)
573
617
  end
574
618
 
575
- context 'start_count_at option' do
619
+ context 'with start_count_at option' do
576
620
  [1, 2].each do |startat|
577
621
  context "equal to #{startat}" do
578
622
  it 'increments the pages' do
@@ -605,7 +649,7 @@ describe Prawn::Document do
605
649
  end
606
650
  end
607
651
 
608
- context 'total_pages option' do
652
+ context 'with total_pages option' do
609
653
  it 'allows the total pages count to be overridden' do
610
654
  2.times { pdf.start_new_page }
611
655
  allow(pdf).to receive(:text_box)
@@ -616,8 +660,8 @@ describe Prawn::Document do
616
660
  end
617
661
  end
618
662
 
619
- context 'special page filter' do
620
- context 'such as :odd' do
663
+ context 'with special page filter' do
664
+ describe 'such as :odd' do
621
665
  it 'increments the pages' do
622
666
  3.times { pdf.start_new_page }
623
667
  allow(pdf).to receive(:text_box)
@@ -629,7 +673,7 @@ describe Prawn::Document do
629
673
  end
630
674
  end
631
675
 
632
- context 'missing' do
676
+ describe 'missing' do
633
677
  it 'does not print any page numbers' do
634
678
  3.times { pdf.start_new_page }
635
679
  allow(pdf).to receive(:text_box)
@@ -640,8 +684,8 @@ describe Prawn::Document do
640
684
  end
641
685
  end
642
686
 
643
- context 'given both a special page filter and a start_count_at parameter' do
644
- context 'such as :odd and 7' do
687
+ context 'with both a special page filter and a start_count_at parameter' do
688
+ describe 'such as :odd and 7' do
645
689
  it 'increments the pages' do
646
690
  3.times { pdf.start_new_page }
647
691
  allow(pdf).to receive(:text_box)
@@ -660,7 +704,8 @@ describe Prawn::Document do
660
704
  expect(pdf).to have_received(:text_box).with('7 3', height: 50)
661
705
  end
662
706
  end
663
- context 'some crazy proc and 2' do
707
+
708
+ context 'with some crazy proc and 2' do
664
709
  it 'increments the pages' do
665
710
  6.times { pdf.start_new_page }
666
711
  options = {
@@ -691,7 +736,7 @@ describe Prawn::Document do
691
736
  end
692
737
  end
693
738
 
694
- context 'height option' do
739
+ describe 'height option' do
695
740
  before do
696
741
  pdf.start_new_page
697
742
  end
@@ -724,7 +769,7 @@ describe Prawn::Document do
724
769
  end
725
770
 
726
771
  it 'returns nil given no filter' do
727
- expect(pdf.page_match?(:nil, 1)).to be_falsey
772
+ expect(pdf).to_not be_page_match(:nil, 1)
728
773
  end
729
774
 
730
775
  it 'must provide an :all filter' do
@@ -735,7 +780,7 @@ describe Prawn::Document do
735
780
  it 'must provide an :odd filter' do
736
781
  odd, even = (1..pdf.page_count).partition(&:odd?)
737
782
  expect(odd.all? { |i| pdf.page_match?(:odd, i) }).to eq true
738
- expect(even.any? { |i| pdf.page_match?(:odd, i) }).to be_falsey
783
+ expect(even).to_not(be_any { |i| pdf.page_match?(:odd, i) })
739
784
  end
740
785
 
741
786
  it 'must be able to filter by an array of page numbers' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'pathname'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'pathname'
3
5
 
@@ -39,7 +41,7 @@ describe Prawn::Font do
39
41
  it 'takes character spacing into account' do
40
42
  original_width = pdf.width_of('hello world')
41
43
  pdf.character_spacing(7) do
42
- expect(pdf.width_of('hello world')).to eq(original_width + 11 * 7)
44
+ expect(pdf.width_of('hello world')).to eq(original_width + 10 * 7)
43
45
  end
44
46
  end
45
47
 
@@ -69,6 +71,14 @@ describe Prawn::Font do
69
71
  end
70
72
  end
71
73
 
74
+ it 'reports missing font with style' do
75
+ expect do
76
+ pdf.font('Nada', style: :bold) do
77
+ pdf.width_of('hello')
78
+ end
79
+ end.to raise_error(Prawn::Errors::UnknownFont, /Nada \(bold\)/)
80
+ end
81
+
72
82
  it 'calculates styled widths correctly using TTFs' do
73
83
  pdf.font_families.update(
74
84
  'DejaVu Sans' => {
@@ -134,9 +144,9 @@ describe Prawn::Font do
134
144
 
135
145
  text = PDF::Inspector::Text.analyze(pdf.render)
136
146
  expect(text.font_settings.map { |e| e[:name] }).to eq(
137
- [
138
- :"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
139
- :Courier, :Helvetica
147
+ %i[
148
+ Courier-Bold Courier-BoldOblique Courier-Oblique
149
+ Courier Helvetica
140
150
  ]
141
151
  )
142
152
  end
@@ -263,7 +273,7 @@ describe Prawn::Font do
263
273
  pdf.font 'Times-Roman'
264
274
  pdf.text('hello')
265
275
 
266
- ['Courier', 'Helvetica', 'Times-Roman'].each do |f|
276
+ %w[Courier Helvetica Times-Roman].each do |f|
267
277
  page_should_include_font(f)
268
278
  end
269
279
 
@@ -342,12 +352,6 @@ describe Prawn::Font do
342
352
  normalized = times.normalize_encoding(original)
343
353
  expect(original.equal?(normalized)).to eq false
344
354
  end
345
-
346
- it 'modifies the original string when normalize_encoding!() is used' do
347
- original = 'Foo'
348
- normalized = times.normalize_encoding!(original)
349
- expect(original.equal?(normalized)).to eq true
350
- end
351
355
  end
352
356
 
353
357
  it 'omits /Encoding for symbolic fonts' do
@@ -450,11 +454,36 @@ describe Prawn::Font do
450
454
  normalized = font.normalize_encoding(original)
451
455
  expect(original.equal?(normalized)).to eq false
452
456
  end
457
+ end
458
+ end
459
+
460
+ describe 'OTF fonts' do
461
+ let(:font) { pdf.find_font "#{Prawn::DATADIR}/fonts/Bodoni-Book.otf" }
453
462
 
454
- it 'modifies the original string when normalize_encoding!() is used' do
463
+ it 'calculates string width taking into account accented characters' do
464
+ expect(font.compute_width_of('é', size: 12)).to eq(
465
+ font.compute_width_of('e', size: 12)
466
+ )
467
+ end
468
+
469
+ it 'uses the ascender, descender, and cap height from the OTF verbatim' do
470
+ # These metrics are relative to the font's own bbox. They should not be
471
+ # scaled with font size.
472
+ ref = pdf.ref!({})
473
+ font.send :embed, ref, 0
474
+
475
+ # Pull out the embedded font descriptor
476
+ descriptor = ref.data[:FontDescriptor].data
477
+ expect(descriptor[:Ascent]).to eq(1023)
478
+ expect(descriptor[:Descent]).to eq(-200)
479
+ expect(descriptor[:CapHeight]).to eq(3072)
480
+ end
481
+
482
+ describe 'when normalizing encoding' do
483
+ it 'does not modify the original string with normalize_encoding()' do
455
484
  original = 'Foo'
456
- normalized = font.normalize_encoding!(original)
457
- expect(original.equal?(normalized)).to eq true
485
+ normalized = font.normalize_encoding(original)
486
+ expect(original).to_not be_equal(normalized)
458
487
  end
459
488
  end
460
489
  end
@@ -463,14 +492,14 @@ describe Prawn::Font do
463
492
  let(:file) { "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont" }
464
493
 
465
494
  it 'lists all named fonts' do
466
- list = Prawn::Font::DFont.named_fonts(file)
495
+ list = Prawn::Fonts::DFont.named_fonts(file)
467
496
  expect(list).to match_array(%w[
468
497
  PanicSans PanicSans-Bold PanicSans-BoldItalic PanicSans-Italic
469
498
  ])
470
499
  end
471
500
 
472
501
  it 'counts the number of fonts in the file' do
473
- expect(Prawn::Font::DFont.font_count(file)).to eq(4)
502
+ expect(Prawn::Fonts::DFont.font_count(file)).to eq(4)
474
503
  end
475
504
 
476
505
  it 'defaults selected font to the first one if not specified' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Graphics::BlendMode do
@@ -42,9 +44,9 @@ describe Prawn::Graphics::BlendMode do
42
44
 
43
45
  it 'setting the blend mode with multiple parameters sets an array of '\
44
46
  'blend modes' do
45
- make_blend_mode([:Multiply, :Screen, :Overlay])
47
+ make_blend_mode(%i[Multiply Screen Overlay])
46
48
  extgstate = PDF::Inspector::ExtGState.analyze(pdf.render).extgstates.first
47
- expect(extgstate[:blend_mode]).to eq([:Multiply, :Screen, :Overlay])
49
+ expect(extgstate[:blend_mode]).to eq(%i[Multiply Screen Overlay])
48
50
  end
49
51
 
50
52
  describe 'with more than one page' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Graphics::Transparency do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Prawn::Graphics do
@@ -12,8 +14,7 @@ describe Prawn::Graphics do
12
14
  expect(line_drawing.points).to eq([[100, 600], [100, 500]])
13
15
  end
14
16
 
15
- it 'should draw two lines at (100,600) to (100,500) ' \
16
- 'and (75,100) to (50,125)' do
17
+ it 'draws two lines at (100,600) to (100,500) and (75,100) to (50,125)' do
17
18
  pdf.line(100, 600, 100, 500)
18
19
  pdf.line(75, 100, 50, 125)
19
20
 
@@ -67,6 +68,7 @@ describe Prawn::Graphics do
67
68
  line_drawing = PDF::Inspector::Graphics::Line.analyze(pdf.render)
68
69
  expect(line_drawing.points).to eq([[350, 300], [350, 400]])
69
70
  end
71
+
70
72
  it 'requires a y coordinate' do
71
73
  expect { pdf.vertical_line(400, 500) }
72
74
  .to raise_error(ArgumentError)
@@ -116,6 +118,7 @@ describe Prawn::Graphics do
116
118
 
117
119
  describe 'When drawing a rounded rectangle' do
118
120
  before { pdf.rounded_rectangle([50, 550], 50, 100, 10) }
121
+
119
122
  let(:original_point) do
120
123
  curve = PDF::Inspector::Graphics::Curve.analyze(pdf.render)
121
124
  curve_points = curve.coords.each_slice(2).to_a
@@ -245,6 +248,10 @@ describe Prawn::Graphics do
245
248
  expect { pdf.fill_color 'zcff00' }.to raise_error(ArgumentError)
246
249
  end
247
250
 
251
+ it 'raises an error for a color string with invalid characters' do
252
+ expect { pdf.fill_color 'f0f0f?' }.to raise_error(ArgumentError)
253
+ end
254
+
248
255
  it 'resets the colors on each new page if they have been defined' do
249
256
  pdf.fill_color 'ccff00'
250
257
 
@@ -295,6 +302,23 @@ describe Prawn::Graphics do
295
302
  end).to eq true
296
303
  end
297
304
 
305
+ it 'creates a unique ID for each pattern resource' do
306
+ pdf.fill_gradient(
307
+ [256, 512],
308
+ [356, 512],
309
+ 'ffffff', 'fe00ff'
310
+ )
311
+ pdf.fill_gradient(
312
+ [256, 256],
313
+ [356, 256],
314
+ 'ffffff', '0000ff'
315
+ )
316
+
317
+ str = pdf.render
318
+ pattern_ids = str.scan(/SP\h{40}\s+scn/)
319
+ expect(pattern_ids.uniq.length).to eq 2
320
+ end
321
+
298
322
  it 'fill_gradient should set fill color to the pattern' do
299
323
  pdf.fill_gradient(
300
324
  [0, pdf.bounds.height],
@@ -411,7 +435,7 @@ describe Prawn::Graphics do
411
435
  end
412
436
 
413
437
  describe 'gradient transformations' do
414
- subject do
438
+ subject(:transformations) do
415
439
  pdf.scale 2 do
416
440
  pdf.translate 40, 40 do
417
441
  pdf.fill_gradient [0, 10], [15, 15], 'FF0000', '0000FF', opts
@@ -429,7 +453,7 @@ describe Prawn::Graphics do
429
453
 
430
454
  it 'uses the transformation stack to translate user co-ordinates to '\
431
455
  'document co-ordinates required by /Pattern' do
432
- is_expected.to eq([[2, 0, 0, 2, 80, 100]])
456
+ expect(transformations).to eq([[2, 0, 0, 2, 80, 100]])
433
457
  end
434
458
  end
435
459
 
@@ -437,7 +461,7 @@ describe Prawn::Graphics do
437
461
  let(:opts) { { apply_transformations: false } }
438
462
 
439
463
  it "doesn't transform the gradient" do
440
- is_expected.to eq([[1, 0, 0, 1, 0, 10]])
464
+ expect(transformations).to eq([[1, 0, 0, 1, 0, 10]])
441
465
  end
442
466
  end
443
467
 
@@ -446,7 +470,7 @@ describe Prawn::Graphics do
446
470
 
447
471
  it "doesn't transform the gradient and displays a warning" do
448
472
  allow(pdf).to receive(:warn).twice
449
- is_expected.to eq([[1, 0, 0, 1, 0, 10]])
473
+ expect(transformations).to eq([[1, 0, 0, 1, 0, 10]])
450
474
  expect(pdf).to have_received(:warn).twice
451
475
  end
452
476
  end
@@ -607,7 +631,7 @@ describe Prawn::Graphics do
607
631
  'the initializer' do
608
632
  new_state = PDF::Core::GraphicState.new(pdf.graphic_state)
609
633
 
610
- [:color_space, :dash, :fill_color, :stroke_color].each do |attr|
634
+ %i[color_space dash fill_color stroke_color].each do |attr|
611
635
  expect(new_state.send(attr)).to eq(pdf.graphic_state.send(attr))
612
636
  expect(new_state.send(attr)).to_not equal(pdf.graphic_state.send(attr))
613
637
  end
@@ -616,7 +640,7 @@ describe Prawn::Graphics do
616
640
  it 'copies mutable attributes when duping' do
617
641
  new_state = pdf.graphic_state.dup
618
642
 
619
- [:color_space, :dash, :fill_color, :stroke_color].each do |attr|
643
+ %i[color_space dash fill_color stroke_color].each do |attr|
620
644
  expect(new_state.send(attr)).to eq(pdf.graphic_state.send(attr))
621
645
  expect(new_state.send(attr)).to_not equal(pdf.graphic_state.send(attr))
622
646
  end
@@ -629,15 +653,15 @@ describe Prawn::Graphics do
629
653
 
630
654
  it 'sends the right content on transformation_matrix' do
631
655
  allow(pdf.renderer).to receive(:add_content)
632
- .with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
656
+ .with('1.0 0.0 0.12346 -1.0 5.5 20.0 cm')
633
657
  pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
634
658
  expect(pdf.renderer).to have_received(:add_content)
635
- .with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
659
+ .with('1.0 0.0 0.12346 -1.0 5.5 20.0 cm')
636
660
  end
637
661
 
638
662
  it 'uses fixed digits with very small number' do
639
663
  values = Array.new(6, 0.000000000001)
640
- string = Array.new(6, '0.00000').join ' '
664
+ string = Array.new(6, '0.0').join ' '
641
665
  allow(pdf.renderer).to receive(:add_content).with("#{string} cm")
642
666
  pdf.transformation_matrix(*values)
643
667
  expect(pdf.renderer).to have_received(:add_content).with("#{string} cm")
@@ -651,7 +675,7 @@ describe Prawn::Graphics do
651
675
 
652
676
  it 'saves the graphics state inside the given block' do
653
677
  values = Array.new(6, 0.000000000001)
654
- string = Array.new(6, '0.00000').join ' '
678
+ string = Array.new(6, '0.0').join ' '
655
679
 
656
680
  allow(pdf).to receive(:save_graphics_state).with(no_args)
657
681
  allow(pdf.renderer).to receive(:add_content).with(any_args).twice
@@ -742,10 +766,6 @@ describe Prawn::Graphics do
742
766
  pdf.rotate(angle, origin: [x, y])
743
767
  end.to raise_error(Prawn::Errors::BlockRequired)
744
768
  end
745
-
746
- def reduce_precision(float)
747
- (format '%.5f', float).to_f
748
- end
749
769
  end
750
770
 
751
771
  describe '#translate' do
@@ -808,10 +828,10 @@ describe Prawn::Graphics do
808
828
  pdf.scale(factor, origin: [x, y])
809
829
  end.to raise_error(Prawn::Errors::BlockRequired)
810
830
  end
811
-
812
- def reduce_precision(float)
813
- (format '%.5f', float).to_f
814
- end
815
831
  end
816
832
  end
833
+
834
+ def reduce_precision(float)
835
+ float.round(5)
836
+ end
817
837
  end