prawn 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +2 -31
- data/lib/prawn.rb +1 -0
- data/lib/prawn/document.rb +20 -15
- data/lib/prawn/document/bounding_box.rb +10 -2
- data/lib/prawn/document/span.rb +2 -1
- data/lib/prawn/font.rb +6 -4
- data/lib/prawn/font_metric_cache.rb +7 -6
- data/lib/prawn/fonts/afm.rb +18 -16
- data/lib/prawn/fonts/ttf.rb +55 -29
- data/lib/prawn/graphics.rb +11 -11
- data/lib/prawn/graphics/color.rb +18 -16
- data/lib/prawn/graphics/join_style.rb +1 -1
- data/lib/prawn/graphics/patterns.rb +57 -49
- data/lib/prawn/graphics/transformation.rb +3 -3
- data/lib/prawn/grid.rb +36 -1
- data/lib/prawn/images.rb +29 -27
- data/lib/prawn/images/jpg.rb +4 -1
- data/lib/prawn/images/png.rb +2 -1
- data/lib/prawn/outline.rb +6 -5
- data/lib/prawn/repeater.rb +1 -1
- data/lib/prawn/security.rb +39 -36
- data/lib/prawn/text.rb +18 -18
- data/lib/prawn/text/box.rb +10 -9
- data/lib/prawn/text/formatted/arranger.rb +38 -19
- data/lib/prawn/text/formatted/box.rb +20 -15
- data/lib/prawn/text/formatted/line_wrap.rb +18 -16
- data/lib/prawn/text/formatted/parser.rb +28 -26
- data/lib/prawn/text/formatted/wrap.rb +15 -11
- data/lib/prawn/version.rb +1 -1
- data/lib/prawn/view.rb +2 -2
- data/manual/basic_concepts/measurement.rb +1 -1
- data/manual/bounding_box/canvas.rb +3 -3
- data/manual/bounding_box/nesting.rb +1 -1
- data/manual/document_and_page_options/background.rb +6 -2
- data/manual/document_and_page_options/document_and_page_options.rb +3 -3
- data/manual/document_and_page_options/print_scaling.rb +2 -1
- data/manual/graphics/common_lines.rb +1 -1
- data/manual/graphics/fill_and_stroke.rb +1 -1
- data/manual/graphics/fill_rules.rb +4 -3
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/stroke_dash.rb +5 -5
- data/manual/graphics/translate.rb +2 -1
- data/manual/images/horizontal.rb +2 -2
- data/manual/images/scale.rb +3 -3
- data/manual/images/vertical.rb +6 -3
- data/manual/images/width_and_height.rb +3 -3
- data/manual/layout/content.rb +2 -2
- data/manual/outline/outline.rb +1 -1
- data/manual/security/permissions.rb +4 -2
- data/manual/security/security.rb +1 -1
- data/manual/text/alignment.rb +2 -2
- data/manual/text/column_box.rb +2 -2
- data/manual/text/font_style.rb +5 -2
- data/manual/text/formatted_callbacks.rb +17 -12
- data/manual/text/formatted_text.rb +7 -4
- data/manual/text/free_flowing_text.rb +3 -3
- data/manual/text/kerning_and_character_spacing.rb +4 -4
- data/manual/text/paragraph_indentation.rb +4 -5
- data/manual/text/rendering_and_color.rb +1 -1
- data/manual/text/right_to_left_text.rb +6 -6
- data/manual/text/rotation.rb +8 -3
- data/manual/text/text_box_extensions.rb +1 -1
- data/manual/text/text_box_overflow.rb +11 -9
- data/manual/text/win_ansi_charset.rb +9 -9
- data/prawn.gemspec +4 -10
- data/spec/prawn/document/bounding_box_spec.rb +82 -78
- data/spec/prawn/document/security_spec.rb +1 -1
- data/spec/prawn/document_span_spec.rb +14 -6
- data/spec/prawn/document_spec.rb +29 -26
- data/spec/prawn/font_spec.rb +16 -14
- data/spec/prawn/graphics_spec.rb +79 -44
- data/spec/prawn/images_spec.rb +13 -8
- data/spec/prawn/outline_spec.rb +127 -27
- data/spec/prawn/repeater_spec.rb +9 -8
- data/spec/prawn/soft_mask_spec.rb +1 -1
- data/spec/prawn/stamp_spec.rb +3 -2
- data/spec/prawn/text/box_spec.rb +57 -59
- data/spec/prawn/text/formatted/arranger_spec.rb +10 -10
- data/spec/prawn/text/formatted/box_spec.rb +8 -5
- data/spec/prawn/text/formatted/line_wrap_spec.rb +2 -1
- data/spec/prawn/text_draw_text_spec.rb +9 -8
- data/spec/prawn/text_spacing_spec.rb +2 -2
- data/spec/prawn/text_spec.rb +9 -9
- data/spec/prawn/text_with_inline_formatting_spec.rb +1 -1
- data/spec/prawn_manual_spec.rb +4 -4
- metadata +14 -98
- metadata.gz.sig +0 -0
data/manual/text/alignment.rb
CHANGED
@@ -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',
|
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',
|
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
|
data/manual/text/column_box.rb
CHANGED
@@ -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',
|
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(
|
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
|
data/manual/text/font_style.rb
CHANGED
@@ -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]
|
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
|
-
|
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,
|
45
|
-
fragment.
|
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,
|
49
|
-
@document.fill_circle(fragment.top_right,
|
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,
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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],
|
53
|
+
color: [50, 100, 0, 0],
|
54
|
+
styles: [:italic]
|
54
55
|
}
|
55
56
|
],
|
56
|
-
at: [100, 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 }
|
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 }
|
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
|
-
|
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:',
|
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,
|
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,
|
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,
|
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
|
-
|
31
|
-
|
28
|
+
text "#{'This paragraph will be indented. ' * 10}\n#{'This one will too. ' * 10}",
|
29
|
+
indent_paragraphs: 60,
|
30
|
+
direction: :rtl
|
32
31
|
end
|
@@ -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',
|
48
|
+
{ text: 'this', direction: :ltr },
|
49
49
|
{ text: "won't", direction: :ltr, size: 24 },
|
50
|
-
{ text: 'work',
|
50
|
+
{ text: 'work', direction: :ltr },
|
51
51
|
{ text: '中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也不是什么难事' }
|
52
|
-
]
|
52
|
+
])
|
53
53
|
end
|
54
54
|
end
|
data/manual/text/rotation.rb
CHANGED
@@ -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],
|
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],
|
31
|
-
|
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,
|
31
|
-
|
32
|
-
|
33
|
-
|
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,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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:
|
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 -=
|
28
|
+
y -= font_size
|
29
29
|
|
30
|
-
if y <
|
31
|
-
y = bounds.top -
|
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:
|
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:
|
45
|
+
width = width_of(field, size: font_size)
|
46
46
|
|
47
47
|
case align
|
48
|
-
when :left
|
49
|
-
when :right
|
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
|
|
data/prawn.gemspec
CHANGED
@@ -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 = '
|
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.
|
40
|
-
spec.add_dependency('ttfunk', '~> 1.
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
19
|
+
it 'has an anchor at (x, y - height)' do
|
20
|
+
expect(box.anchor).to eq([100, 50])
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
it 'has a left boundary of 0' do
|
24
|
+
expect(box.left).to eq(0)
|
25
|
+
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
it 'has a right boundary equal to the width' do
|
28
|
+
expect(box.right).to eq(50)
|
29
|
+
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
it 'has a top boundary of height' do
|
32
|
+
expect(box.top).to eq(75)
|
33
|
+
end
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
it 'has a bottom boundary of 0' do
|
36
|
+
expect(box.bottom).to eq(0)
|
37
|
+
end
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
it 'has a top-left of [0, height]' do
|
40
|
+
expect(box.top_left).to eq([0, 75])
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
it 'has a top-right of [width, height]' do
|
44
|
+
expect(box.top_right).to eq([50, 75])
|
45
|
+
end
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
it 'has a bottom-left of [0, 0]' do
|
48
|
+
expect(box.bottom_left).to eq([0, 0])
|
49
|
+
end
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
it 'has a bottom-right of [width ,0]' do
|
52
|
+
expect(box.bottom_right).to eq([50, 0])
|
53
|
+
end
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
it 'has an absolute left boundary of x' do
|
56
|
+
expect(box.absolute_left).to eq(100)
|
57
|
+
end
|
64
58
|
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
it 'has an absolute right boundary of x + width' do
|
60
|
+
expect(box.absolute_right).to eq(150)
|
61
|
+
end
|
68
62
|
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
it 'has an absolute top boundary of y' do
|
64
|
+
expect(box.absolute_top).to eq(125)
|
65
|
+
end
|
72
66
|
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
it 'has an absolute bottom boundary of y - height' do
|
68
|
+
expect(box.absolute_bottom).to eq(50)
|
69
|
+
end
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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 =
|
160
|
-
pdf.
|
161
|
-
|
162
|
-
|
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
|