prawn 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +2 -31
  5. data/lib/prawn.rb +1 -0
  6. data/lib/prawn/document.rb +20 -15
  7. data/lib/prawn/document/bounding_box.rb +10 -2
  8. data/lib/prawn/document/span.rb +2 -1
  9. data/lib/prawn/font.rb +6 -4
  10. data/lib/prawn/font_metric_cache.rb +7 -6
  11. data/lib/prawn/fonts/afm.rb +18 -16
  12. data/lib/prawn/fonts/ttf.rb +55 -29
  13. data/lib/prawn/graphics.rb +11 -11
  14. data/lib/prawn/graphics/color.rb +18 -16
  15. data/lib/prawn/graphics/join_style.rb +1 -1
  16. data/lib/prawn/graphics/patterns.rb +57 -49
  17. data/lib/prawn/graphics/transformation.rb +3 -3
  18. data/lib/prawn/grid.rb +36 -1
  19. data/lib/prawn/images.rb +29 -27
  20. data/lib/prawn/images/jpg.rb +4 -1
  21. data/lib/prawn/images/png.rb +2 -1
  22. data/lib/prawn/outline.rb +6 -5
  23. data/lib/prawn/repeater.rb +1 -1
  24. data/lib/prawn/security.rb +39 -36
  25. data/lib/prawn/text.rb +18 -18
  26. data/lib/prawn/text/box.rb +10 -9
  27. data/lib/prawn/text/formatted/arranger.rb +38 -19
  28. data/lib/prawn/text/formatted/box.rb +20 -15
  29. data/lib/prawn/text/formatted/line_wrap.rb +18 -16
  30. data/lib/prawn/text/formatted/parser.rb +28 -26
  31. data/lib/prawn/text/formatted/wrap.rb +15 -11
  32. data/lib/prawn/version.rb +1 -1
  33. data/lib/prawn/view.rb +2 -2
  34. data/manual/basic_concepts/measurement.rb +1 -1
  35. data/manual/bounding_box/canvas.rb +3 -3
  36. data/manual/bounding_box/nesting.rb +1 -1
  37. data/manual/document_and_page_options/background.rb +6 -2
  38. data/manual/document_and_page_options/document_and_page_options.rb +3 -3
  39. data/manual/document_and_page_options/print_scaling.rb +2 -1
  40. data/manual/graphics/common_lines.rb +1 -1
  41. data/manual/graphics/fill_and_stroke.rb +1 -1
  42. data/manual/graphics/fill_rules.rb +4 -3
  43. data/manual/graphics/helper.rb +11 -4
  44. data/manual/graphics/lines_and_curves.rb +1 -1
  45. data/manual/graphics/stroke_dash.rb +5 -5
  46. data/manual/graphics/translate.rb +2 -1
  47. data/manual/images/horizontal.rb +2 -2
  48. data/manual/images/scale.rb +3 -3
  49. data/manual/images/vertical.rb +6 -3
  50. data/manual/images/width_and_height.rb +3 -3
  51. data/manual/layout/content.rb +2 -2
  52. data/manual/outline/outline.rb +1 -1
  53. data/manual/security/permissions.rb +4 -2
  54. data/manual/security/security.rb +1 -1
  55. data/manual/text/alignment.rb +2 -2
  56. data/manual/text/column_box.rb +2 -2
  57. data/manual/text/font_style.rb +5 -2
  58. data/manual/text/formatted_callbacks.rb +17 -12
  59. data/manual/text/formatted_text.rb +7 -4
  60. data/manual/text/free_flowing_text.rb +3 -3
  61. data/manual/text/kerning_and_character_spacing.rb +4 -4
  62. data/manual/text/paragraph_indentation.rb +4 -5
  63. data/manual/text/rendering_and_color.rb +1 -1
  64. data/manual/text/right_to_left_text.rb +6 -6
  65. data/manual/text/rotation.rb +8 -3
  66. data/manual/text/text_box_extensions.rb +1 -1
  67. data/manual/text/text_box_overflow.rb +11 -9
  68. data/manual/text/win_ansi_charset.rb +9 -9
  69. data/prawn.gemspec +4 -10
  70. data/spec/prawn/document/bounding_box_spec.rb +82 -78
  71. data/spec/prawn/document/security_spec.rb +1 -1
  72. data/spec/prawn/document_span_spec.rb +14 -6
  73. data/spec/prawn/document_spec.rb +29 -26
  74. data/spec/prawn/font_spec.rb +16 -14
  75. data/spec/prawn/graphics_spec.rb +79 -44
  76. data/spec/prawn/images_spec.rb +13 -8
  77. data/spec/prawn/outline_spec.rb +127 -27
  78. data/spec/prawn/repeater_spec.rb +9 -8
  79. data/spec/prawn/soft_mask_spec.rb +1 -1
  80. data/spec/prawn/stamp_spec.rb +3 -2
  81. data/spec/prawn/text/box_spec.rb +57 -59
  82. data/spec/prawn/text/formatted/arranger_spec.rb +10 -10
  83. data/spec/prawn/text/formatted/box_spec.rb +8 -5
  84. data/spec/prawn/text/formatted/line_wrap_spec.rb +2 -1
  85. data/spec/prawn/text_draw_text_spec.rb +9 -8
  86. data/spec/prawn/text_spacing_spec.rb +2 -2
  87. data/spec/prawn/text_spec.rb +9 -9
  88. data/spec/prawn/text_with_inline_formatting_spec.rb +1 -1
  89. data/spec/prawn_manual_spec.rb +4 -4
  90. metadata +14 -98
  91. metadata.gz.sig +0 -0
@@ -17,7 +17,7 @@ require_relative '../example_helper'
17
17
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
18
18
  Prawn::ManualBuilder::Example.generate(filename) do
19
19
  text 'This text should be left aligned'
20
- text 'This text should be centered', align: :center
20
+ text 'This text should be centered', align: :center
21
21
  text 'This text should be right aligned', align: :right
22
22
 
23
23
  bounding_box([0, 220], width: 250, height: 220) do
@@ -36,7 +36,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
36
36
 
37
37
  bounding_box([300, 220], width: 250, height: 220) do
38
38
  text 'This text should be vertically top aligned'
39
- text 'This text should be vertically centered', valign: :center
39
+ text 'This text should be vertically centered', valign: :center
40
40
  text 'This text should be vertically bottom aligned', valign: :bottom
41
41
  transparent(0.5) { stroke_bounds }
42
42
  end
@@ -9,12 +9,12 @@ require_relative '../example_helper'
9
9
 
10
10
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
11
  Prawn::ManualBuilder::Example.generate(filename) do
12
- text 'The Prince', align: :center, size: 18
12
+ text 'The Prince', align: :center, size: 18
13
13
  text 'Niccolò Machiavelli', align: :center, size: 14
14
14
  move_down 12
15
15
 
16
16
  column_box([0, cursor], columns: 2, width: bounds.width) do
17
- text((<<-TEXT.gsub(/\s+/, ' ') + "\n\n") * 3)
17
+ text("#{<<~TEXT.gsub(/\s+/, ' ')}\n\n" * 3)
18
18
  All the States and Governments by which men are or ever have been ruled,
19
19
  have been and are either Republics or Princedoms. Princedoms are either
20
20
  hereditary, in which the sovereignty is derived through an ancient line
@@ -11,10 +11,13 @@ require_relative '../example_helper'
11
11
 
12
12
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
13
13
  Prawn::ManualBuilder::Example.generate(filename) do
14
- %w[Courier Helvetica Times-Roman].each do |example_font|
14
+ fonts = %w[Courier Helvetica Times-Roman]
15
+ styles = %i[bold bold_italic italic normal]
16
+
17
+ fonts.each do |example_font|
15
18
  move_down 20
16
19
 
17
- %i[bold bold_italic italic normal].each do |style|
20
+ styles.each do |style|
18
21
  font example_font, style: style
19
22
  text "I'm writing in #{example_font} (#{style})"
20
23
  end
@@ -41,25 +41,30 @@ Prawn::ManualBuilder::Example.generate(filename) do
41
41
 
42
42
  def render_in_front(fragment)
43
43
  @document.stroke_polygon(
44
- fragment.top_left, fragment.top_right,
45
- fragment.bottom_right, fragment.bottom_left
44
+ fragment.top_left,
45
+ fragment.top_right,
46
+ fragment.bottom_right,
47
+ fragment.bottom_left
46
48
  )
47
49
 
48
- @document.fill_circle(fragment.top_left, @radius)
49
- @document.fill_circle(fragment.top_right, @radius)
50
+ @document.fill_circle(fragment.top_left, @radius)
51
+ @document.fill_circle(fragment.top_right, @radius)
50
52
  @document.fill_circle(fragment.bottom_right, @radius)
51
- @document.fill_circle(fragment.bottom_left, @radius)
53
+ @document.fill_circle(fragment.bottom_left, @radius)
52
54
  end
53
55
  end
54
56
 
55
57
  highlight = HighlightCallback.new(color: 'ffff00', document: self)
56
58
  border = ConnectedBorderCallback.new(radius: 2.5, document: self)
57
59
 
58
- formatted_text [
59
- { text: 'hello', callback: highlight },
60
- { text: ' ' },
61
- { text: 'world', callback: border },
62
- { text: ' ' },
63
- { text: 'hello world', callback: [highlight, border] }
64
- ], size: 20
60
+ formatted_text(
61
+ [
62
+ { text: 'hello', callback: highlight },
63
+ { text: ' ' },
64
+ { text: 'world', callback: border },
65
+ { text: ' ' },
66
+ { text: 'hello world', callback: [highlight, border] }
67
+ ],
68
+ size: 20
69
+ )
65
70
  end
@@ -24,7 +24,7 @@ require_relative '../example_helper'
24
24
 
25
25
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
26
26
  Prawn::ManualBuilder::Example.generate(filename) do
27
- formatted_text [
27
+ formatted_text([
28
28
  { text: 'Some bold. ', styles: [:bold] },
29
29
  { text: 'Some italic. ', styles: [:italic] },
30
30
  { text: 'Bold italic. ', styles: %i[bold italic] },
@@ -42,7 +42,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
42
42
  color: '0000FF',
43
43
  local: './local_file.txt'
44
44
  }
45
- ]
45
+ ])
46
46
 
47
47
  formatted_text_box(
48
48
  [
@@ -50,9 +50,12 @@ Prawn::ManualBuilder::Example.generate(filename) do
50
50
  { text: ' text_box ', font: 'Courier' },
51
51
  {
52
52
  text: 'with some additional formatting options added to the mix.',
53
- color: [50, 100, 0, 0], styles: [:italic]
53
+ color: [50, 100, 0, 0],
54
+ styles: [:italic]
54
55
  }
55
56
  ],
56
- at: [100, 100], width: 200, height: 100
57
+ at: [100, 100],
58
+ width: 200,
59
+ height: 100
57
60
  )
58
61
  end
@@ -27,7 +27,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
27
27
  end
28
28
 
29
29
  bounding_box([300, y_position], width: 200, height: 150) do
30
- transparent(0.5) { stroke_bounds } # This will stroke on one page
30
+ transparent(0.5) { stroke_bounds } # This will stroke on one page
31
31
 
32
32
  text 'Now look what happens when the free flowing text reaches the end ' \
33
33
  'of a bounding box that is narrower than the margin box.' +
@@ -36,7 +36,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
36
36
  'was cloned. If we want it to have the same border as the one on ' \
37
37
  'the previous page we will need to stroke the boundaries again.'
38
38
 
39
- transparent(0.5) { stroke_bounds } # And this will stroke on the next
39
+ transparent(0.5) { stroke_bounds } # And this will stroke on the next
40
40
  end
41
41
 
42
42
  move_cursor_to 200
@@ -44,7 +44,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
44
44
  text 'Span is a different kind of bounding box as it lets the text ' \
45
45
  "flow gracefully onto the next page. It doesn't matter if the text " \
46
46
  'started on the middle of the previous page, when it flows to the ' \
47
- 'next page it will start at the beginning.' + ' _ ' * 500 +
47
+ "next page it will start at the beginning.#{' _ ' * 500}" \
48
48
  'I told you it would start on the beginning of this page.'
49
49
  end
50
50
  end
@@ -14,16 +14,16 @@ require_relative '../example_helper'
14
14
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
15
  Prawn::ManualBuilder::Example.generate(filename) do
16
16
  font_size(30) do
17
- text_box 'With kerning:', kerning: true, at: [0, y - 40]
17
+ text_box 'With kerning:', kerning: true, at: [0, y - 40]
18
18
  text_box 'Without kerning:', kerning: false, at: [0, y - 80]
19
19
 
20
- text_box 'Tomato', kerning: true, at: [250, y - 40]
20
+ text_box 'Tomato', kerning: true, at: [250, y - 40]
21
21
  text_box 'Tomato', kerning: false, at: [250, y - 80]
22
22
 
23
- text_box 'WAR', kerning: true, at: [400, y - 40]
23
+ text_box 'WAR', kerning: true, at: [400, y - 40]
24
24
  text_box 'WAR', kerning: false, at: [400, y - 80]
25
25
 
26
- text_box 'F.', kerning: true, at: [500, y - 40]
26
+ text_box 'F.', kerning: true, at: [500, y - 40]
27
27
  text_box 'F.', kerning: false, at: [500, y - 80]
28
28
  end
29
29
 
@@ -19,14 +19,13 @@ Prawn::ManualBuilder::Example.generate(filename) do
19
19
  "\n#{Prawn::Text::NBSP * 10}" + 'This one will with NBSP. ' * 10
20
20
 
21
21
  move_down 20
22
- text 'This paragraph will be indented. ' * 10 +
23
- "\n" + 'This one will too. ' * 10,
22
+ text "#{'This paragraph will be indented. ' * 10}\n#{'This one will too. ' * 10}",
24
23
  indent_paragraphs: 60
25
24
 
26
25
  move_down 20
27
26
 
28
27
  text 'FROM RIGHT TO LEFT:'
29
- text 'This paragraph will be indented. ' * 10 +
30
- "\n" + 'This one will too. ' * 10,
31
- indent_paragraphs: 60, direction: :rtl
28
+ text "#{'This paragraph will be indented. ' * 10}\n#{'This one will too. ' * 10}",
29
+ indent_paragraphs: 60,
30
+ direction: :rtl
32
31
  end
@@ -16,7 +16,7 @@ require_relative '../example_helper'
16
16
 
17
17
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
18
18
  Prawn::ManualBuilder::Example.generate(filename) do
19
- fill_color '00ff00'
19
+ fill_color '00ff00'
20
20
  stroke_color '0000ff'
21
21
 
22
22
  font_size(40) do
@@ -31,7 +31,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
31
31
  text 'You can override the document direction.', direction: :ltr
32
32
  move_down 20
33
33
 
34
- formatted_text [
34
+ formatted_text([
35
35
  { text: '更可怕的是,同质化竞争对手可以按照' },
36
36
  { text: 'URL', direction: :ltr },
37
37
  { text: '中后面这个' },
@@ -40,15 +40,15 @@ Prawn::ManualBuilder::Example.generate(filename) do
40
40
  { text: 'DB', direction: :ltr },
41
41
  { text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么'\
42
42
  '难事,这样的话,你就非常被动了。' }
43
- ]
43
+ ])
44
44
  move_down 20
45
45
 
46
- formatted_text [
46
+ formatted_text([
47
47
  { text: '更可怕的是,同质化竞争对手可以按照' },
48
- { text: 'this', direction: :ltr },
48
+ { text: 'this', direction: :ltr },
49
49
  { text: "won't", direction: :ltr, size: 24 },
50
- { text: 'work', direction: :ltr },
50
+ { text: 'work', direction: :ltr },
51
51
  { text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事' }
52
- ]
52
+ ])
53
53
  end
54
54
  end
@@ -21,14 +21,19 @@ Prawn::ManualBuilder::Example.generate(filename) do
21
21
  stroke_rectangle [0, y], width, height
22
22
  text_box(
23
23
  'This text was not rotated',
24
- at: [0, y], width: width, height: height
24
+ at: [0, y],
25
+ width: width,
26
+ height: height
25
27
  )
26
28
 
27
29
  stroke_rectangle [0, y - 100], width, height
28
30
  text_box(
29
31
  'This text was rotated around the center',
30
- at: [0, y - 100], width: width, height: height,
31
- rotate: angle, rotate_around: :center
32
+ at: [0, y - 100],
33
+ width: width,
34
+ height: height,
35
+ rotate: angle,
36
+ rotate_around: :center
32
37
  )
33
38
 
34
39
  %i[lower_left upper_left lower_right upper_right]
@@ -36,7 +36,7 @@ Prawn::ManualBuilder::Example.generate(filename) do
36
36
  Prawn::Text::Formatted::Box.extensions << TriangleBox
37
37
  stroke_rectangle([200, y_position], width, height)
38
38
  formatted_text_box(
39
- [text: 'A' * 100, color: '009900'],
39
+ [{ text: 'A' * 100, color: '009900' }],
40
40
  at: [200, y_position],
41
41
  width: width,
42
42
  height: height
@@ -27,10 +27,11 @@ Prawn::ManualBuilder::Example.generate(filename) do
27
27
 
28
28
  y_position = cursor - 20
29
29
  %i[truncate expand shrink_to_fit].each_with_index do |mode, i|
30
- text_box string, at: [i * 150, y_position],
31
- width: 100,
32
- height: 50,
33
- overflow: mode
30
+ text_box string,
31
+ at: [i * 150, y_position],
32
+ width: 100,
33
+ height: 50,
34
+ overflow: mode
34
35
  end
35
36
 
36
37
  string = 'If the box is too small for the text, :shrink_to_fit ' \
@@ -40,10 +41,11 @@ Prawn::ManualBuilder::Example.generate(filename) do
40
41
  text string
41
42
  y_position = cursor - 20
42
43
  [nil, 8, 10, 12].each_with_index do |value, index|
43
- text_box string, at: [index * 150, y_position],
44
- width: 50,
45
- height: 50,
46
- overflow: :shrink_to_fit,
47
- min_font_size: value
44
+ text_box string,
45
+ at: [index * 150, y_position],
46
+ width: 50,
47
+ height: 50,
48
+ overflow: :shrink_to_fit,
49
+ min_font_size: value
48
50
  end
49
51
  end
@@ -8,7 +8,7 @@ require_relative '../example_helper'
8
8
 
9
9
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
10
10
  Prawn::ManualBuilder::Example.generate(filename) do
11
- FONT_SIZE = 9.5
11
+ font_size = 9.5
12
12
 
13
13
  x = 0
14
14
  y = bounds.top
@@ -18,35 +18,35 @@ Prawn::ManualBuilder::Example.generate(filename) do
18
18
  [0, :left]
19
19
  ]
20
20
 
21
- font 'Helvetica', size: FONT_SIZE
21
+ font 'Helvetica', size: font_size
22
22
 
23
23
  start_new_page
24
24
 
25
25
  Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
26
26
  next if name == '.notdef'
27
27
 
28
- y -= FONT_SIZE
28
+ y -= font_size
29
29
 
30
- if y < FONT_SIZE
31
- y = bounds.top - FONT_SIZE
30
+ if y < font_size
31
+ y = bounds.top - font_size
32
32
  x += 170
33
33
  end
34
34
 
35
35
  code = format('%<index>d.', index: index)
36
36
  char = index.chr.force_encoding(::Encoding::Windows_1252)
37
37
 
38
- width = 1000 * width_of(char, size: FONT_SIZE) / FONT_SIZE
38
+ width = 1000 * width_of(char, size: font_size) / font_size
39
39
  size = format('%<width>d', width: width)
40
40
 
41
41
  data = [code, nil, char, size, nil, name]
42
42
  dx = x
43
43
  fields.zip(data).each do |(total_width, align), field|
44
44
  if field
45
- width = width_of(field, size: FONT_SIZE)
45
+ width = width_of(field, size: font_size)
46
46
 
47
47
  case align
48
- when :left then offset = 0
49
- when :right then offset = total_width - width
48
+ when :left then offset = 0
49
+ when :right then offset = total_width - width
50
50
  when :center then offset = (total_width - width) / 2
51
51
  end
52
52
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  '.yardopts'
24
24
  ]
25
25
  spec.require_path = 'lib'
26
- spec.required_ruby_version = '~> 2.5'
26
+ spec.required_ruby_version = '>= 2.5'
27
27
  spec.required_rubygems_version = '>= 1.3.6'
28
28
 
29
29
  spec.authors = [
@@ -36,19 +36,13 @@ Gem::Specification.new do |spec|
36
36
  ]
37
37
  spec.licenses = %w[PRAWN GPL-2.0 GPL-3.0]
38
38
 
39
- spec.add_dependency('pdf-core', '~> 0.8.1')
40
- spec.add_dependency('ttfunk', '~> 1.6')
39
+ spec.add_dependency('pdf-core', '~> 0.9.0')
40
+ spec.add_dependency('ttfunk', '~> 1.7')
41
41
 
42
42
  spec.add_development_dependency('pdf-inspector', '>= 1.2.1', '< 2.0.a')
43
43
  spec.add_development_dependency('pdf-reader', ['~> 1.4', '>= 1.4.1'])
44
+ spec.add_development_dependency('prawn-dev', '~> 0.1.0')
44
45
  spec.add_development_dependency('prawn-manual_builder', '>= 0.3.0')
45
- spec.add_development_dependency('rake', '~> 12.0')
46
- spec.add_development_dependency('rspec', '~> 3.0')
47
- spec.add_development_dependency('rubocop', '~> 0.84.0')
48
- spec.add_development_dependency('rubocop-performance', '~> 1.1')
49
- spec.add_development_dependency('rubocop-rspec', '~> 1.32')
50
- spec.add_development_dependency('simplecov')
51
- spec.add_development_dependency('yard')
52
46
 
53
47
  spec.homepage = 'http://prawnpdf.org'
54
48
  spec.description = <<END_DESC
@@ -4,99 +4,100 @@ require 'spec_helper'
4
4
 
5
5
  describe Prawn::Document::BoundingBox do
6
6
  let(:pdf) { create_pdf }
7
- let(:x) { 100 }
8
- let(:y) { 125 }
9
- let(:width) { 50 }
10
- let(:height) { 75 }
11
- let(:box) do
12
- described_class.new(
13
- nil,
14
- nil,
15
- [x, y],
16
- width: width,
17
- height: height
18
- )
19
- end
20
7
 
21
- it 'has an anchor at (x, y - height)' do
22
- expect(box.anchor).to eq([x, y - height])
23
- end
8
+ describe 'attributes' do
9
+ let(:box) do
10
+ described_class.new(
11
+ nil,
12
+ nil,
13
+ [100, 125],
14
+ width: 50,
15
+ height: 75
16
+ )
17
+ end
24
18
 
25
- it 'has a left boundary of 0' do
26
- expect(box.left).to eq(0)
27
- end
19
+ it 'has an anchor at (x, y - height)' do
20
+ expect(box.anchor).to eq([100, 50])
21
+ end
28
22
 
29
- it 'has a right boundary equal to the width' do
30
- expect(box.right).to eq(width)
31
- end
23
+ it 'has a left boundary of 0' do
24
+ expect(box.left).to eq(0)
25
+ end
32
26
 
33
- it 'has a top boundary of height' do
34
- expect(box.top).to eq(height)
35
- end
27
+ it 'has a right boundary equal to the width' do
28
+ expect(box.right).to eq(50)
29
+ end
36
30
 
37
- it 'has a bottom boundary of 0' do
38
- expect(box.bottom).to eq(0)
39
- end
31
+ it 'has a top boundary of height' do
32
+ expect(box.top).to eq(75)
33
+ end
40
34
 
41
- it 'has a top-left of [0,height]' do
42
- expect(box.top_left).to eq([0, height])
43
- end
35
+ it 'has a bottom boundary of 0' do
36
+ expect(box.bottom).to eq(0)
37
+ end
44
38
 
45
- it 'has a top-right of [width,height]' do
46
- expect(box.top_right).to eq([width, height])
47
- end
39
+ it 'has a top-left of [0, height]' do
40
+ expect(box.top_left).to eq([0, 75])
41
+ end
48
42
 
49
- it 'has a bottom-left of [0,0]' do
50
- expect(box.bottom_left).to eq([0, 0])
51
- end
43
+ it 'has a top-right of [width, height]' do
44
+ expect(box.top_right).to eq([50, 75])
45
+ end
52
46
 
53
- it 'has a bottom-right of [width,0]' do
54
- expect(box.bottom_right).to eq([width, 0])
55
- end
47
+ it 'has a bottom-left of [0, 0]' do
48
+ expect(box.bottom_left).to eq([0, 0])
49
+ end
56
50
 
57
- it 'has an absolute left boundary of x' do
58
- expect(box.absolute_left).to eq(x)
59
- end
51
+ it 'has a bottom-right of [width ,0]' do
52
+ expect(box.bottom_right).to eq([50, 0])
53
+ end
60
54
 
61
- it 'has an absolute right boundary of x + width' do
62
- expect(box.absolute_right).to eq(x + width)
63
- end
55
+ it 'has an absolute left boundary of x' do
56
+ expect(box.absolute_left).to eq(100)
57
+ end
64
58
 
65
- it 'has an absolute top boundary of y' do
66
- expect(box.absolute_top).to eq(y)
67
- end
59
+ it 'has an absolute right boundary of x + width' do
60
+ expect(box.absolute_right).to eq(150)
61
+ end
68
62
 
69
- it 'has an absolute bottom boundary of y - height' do
70
- expect(box.absolute_bottom).to eq(y - height)
71
- end
63
+ it 'has an absolute top boundary of y' do
64
+ expect(box.absolute_top).to eq(125)
65
+ end
72
66
 
73
- it 'has an absolute bottom-left of [x,y-height]' do
74
- expect(box.absolute_bottom_left).to eq([x, y - height])
75
- end
67
+ it 'has an absolute bottom boundary of y - height' do
68
+ expect(box.absolute_bottom).to eq(50)
69
+ end
76
70
 
77
- it 'has an absolute bottom-right of [x+width,y-height]' do
78
- expect(box.absolute_bottom_right).to eq([x + width, y - height])
79
- end
71
+ it 'has an absolute bottom-left of [x, y - height]' do
72
+ expect(box.absolute_bottom_left).to eq([100, 50])
73
+ end
80
74
 
81
- it 'has an absolute top-left of [x,y]' do
82
- expect(box.absolute_top_left).to eq([x, y])
83
- end
75
+ it 'has an absolute bottom-right of [x + width, y - height]' do
76
+ expect(box.absolute_bottom_right).to eq([150, 50])
77
+ end
84
78
 
85
- it 'has an absolute top-right of [x+width,y]' do
86
- expect(box.absolute_top_right).to eq([x + width, y])
87
- end
79
+ it 'has an absolute top-left of [x, y]' do
80
+ expect(box.absolute_top_left).to eq([100, 125])
81
+ end
88
82
 
89
- it 'requires width to be set' do
90
- expect do
91
- described_class.new(nil, nil, [100, 100])
92
- end.to raise_error(ArgumentError)
83
+ it 'has an absolute top-right of [x + width, y]' do
84
+ expect(box.absolute_top_right).to eq([150, 125])
85
+ end
93
86
  end
94
87
 
95
- it 'raise_errors an ArgumentError if a block is not passed' do
96
- pdf = Prawn::Document.new
97
- expect do
98
- pdf.bounding_box([0, 0], width: 200)
99
- end.to raise_error(ArgumentError)
88
+ describe 'validations' do
89
+ it 'requires width to be set' do
90
+ expect do
91
+ described_class.new(nil, nil, [100, 100])
92
+ end.to raise_error(ArgumentError)
93
+ end
94
+
95
+ it 'raise_errors an ArgumentError if a block is not passed' do
96
+ pdf = Prawn::Document.new
97
+ expect do
98
+ pdf.bounding_box([0, 0], width: 200)
99
+ end.to raise_error(ArgumentError)
100
+ end
100
101
  end
101
102
 
102
103
  describe 'drawing' do
@@ -156,10 +157,11 @@ describe Prawn::Document::BoundingBox do
156
157
  end
157
158
 
158
159
  it 'keeps track of the max height the box was stretched to' do
159
- box = pdf.bounding_box(pdf.bounds.top_left, width: 100) do
160
- pdf.move_down 100
161
- pdf.move_up 15
162
- end
160
+ box =
161
+ pdf.bounding_box(pdf.bounds.top_left, width: 100) do
162
+ pdf.move_down 100
163
+ pdf.move_up 15
164
+ end
163
165
 
164
166
  expect(box.height).to eq(100)
165
167
  end
@@ -431,7 +433,9 @@ describe Prawn::Document::BoundingBox do
431
433
 
432
434
  original_ypos = doc.y
433
435
 
434
- doc.canvas {}
436
+ doc.canvas do
437
+ # draw
438
+ end
435
439
 
436
440
  expect(doc.y).to eq(original_ypos)
437
441
  end