prawn 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -5
- data/lib/prawn.rb +4 -4
- data/lib/prawn/document.rb +47 -46
- data/lib/prawn/document/bounding_box.rb +13 -19
- data/lib/prawn/document/column_box.rb +3 -5
- data/lib/prawn/document/internals.rb +0 -1
- data/lib/prawn/document/span.rb +12 -12
- data/lib/prawn/errors.rb +32 -33
- data/lib/prawn/font.rb +29 -36
- data/lib/prawn/font/afm.rb +20 -20
- data/lib/prawn/font/dfont.rb +0 -1
- data/lib/prawn/font/ttf.rb +30 -27
- data/lib/prawn/font_metric_cache.rb +4 -8
- data/lib/prawn/graphics.rb +37 -42
- data/lib/prawn/graphics/cap_style.rb +1 -1
- data/lib/prawn/graphics/color.rb +21 -23
- data/lib/prawn/graphics/dash.rb +5 -6
- data/lib/prawn/graphics/join_style.rb +1 -2
- data/lib/prawn/graphics/patterns.rb +25 -21
- data/lib/prawn/graphics/transformation.rb +4 -5
- data/lib/prawn/graphics/transparency.rb +6 -8
- data/lib/prawn/grid.rb +21 -14
- data/lib/prawn/image_handler.rb +2 -2
- data/lib/prawn/images.rb +29 -31
- data/lib/prawn/images/image.rb +1 -1
- data/lib/prawn/images/jpg.rb +10 -12
- data/lib/prawn/images/png.rb +13 -13
- data/lib/prawn/measurements.rb +7 -14
- data/lib/prawn/outline.rb +6 -6
- data/lib/prawn/repeater.rb +1 -5
- data/lib/prawn/security.rb +17 -25
- data/lib/prawn/security/arcfour.rb +1 -1
- data/lib/prawn/soft_mask.rb +11 -12
- data/lib/prawn/stamp.rb +16 -8
- data/lib/prawn/text.rb +23 -20
- data/lib/prawn/text/box.rb +3 -6
- data/lib/prawn/text/formatted/arranger.rb +9 -12
- data/lib/prawn/text/formatted/box.rb +23 -22
- data/lib/prawn/text/formatted/fragment.rb +0 -4
- data/lib/prawn/text/formatted/line_wrap.rb +13 -24
- data/lib/prawn/text/formatted/parser.rb +16 -20
- data/lib/prawn/text/formatted/wrap.rb +2 -7
- data/lib/prawn/utilities.rb +6 -3
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/basic_concepts.rb +0 -2
- data/manual/basic_concepts/view.rb +1 -1
- data/manual/bounding_box/bounding_box.rb +0 -3
- data/manual/bounding_box/russian_boxes.rb +7 -8
- data/manual/bounding_box/stretchy.rb +0 -1
- data/manual/contents.rb +2 -2
- data/manual/cover.rb +11 -12
- data/manual/document_and_page_options/document_and_page_options.rb +2 -5
- data/manual/document_and_page_options/metadata.rb +10 -10
- data/manual/document_and_page_options/page_size.rb +0 -1
- data/manual/graphics/fill_rules.rb +5 -4
- data/manual/graphics/graphics.rb +0 -3
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/rotate.rb +0 -2
- data/manual/graphics/scale.rb +4 -2
- data/manual/graphics/soft_masks.rb +0 -1
- data/manual/graphics/stroke_cap.rb +1 -1
- data/manual/graphics/stroke_join.rb +1 -1
- data/manual/graphics/translate.rb +3 -3
- data/manual/graphics/transparency.rb +0 -1
- data/manual/how_to_read_this_manual.rb +0 -1
- data/manual/images/images.rb +0 -3
- data/manual/layout/boxes.rb +5 -5
- data/manual/layout/content.rb +2 -2
- data/manual/layout/layout.rb +0 -3
- data/manual/outline/outline.rb +0 -3
- data/manual/repeatable_content/page_numbering.rb +1 -1
- data/manual/repeatable_content/repeatable_content.rb +0 -3
- data/manual/repeatable_content/repeater.rb +6 -6
- data/manual/security/encryption.rb +0 -2
- data/manual/security/permissions.rb +0 -2
- data/manual/security/security.rb +0 -3
- data/manual/text/alignment.rb +3 -3
- data/manual/text/color.rb +0 -1
- data/manual/text/column_box.rb +0 -1
- data/manual/text/fallback_fonts.rb +2 -2
- data/manual/text/formatted_callbacks.rb +3 -2
- data/manual/text/paragraph_indentation.rb +2 -3
- data/manual/text/registering_families.rb +13 -9
- data/manual/text/rotation.rb +0 -1
- data/manual/text/text.rb +0 -3
- data/manual/text/text_box_overflow.rb +7 -5
- data/manual/text/utf8.rb +1 -1
- data/manual/text/win_ansi_charset.rb +2 -2
- data/prawn.gemspec +4 -4
- data/spec/acceptance/png.rb +6 -7
- data/spec/annotations_spec.rb +21 -28
- data/spec/bounding_box_spec.rb +100 -109
- data/spec/column_box_spec.rb +26 -32
- data/spec/destinations_spec.rb +2 -4
- data/spec/document_spec.rb +145 -151
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_metric_cache_spec.rb +7 -7
- data/spec/font_spec.rb +103 -102
- data/spec/formatted_text_arranger_spec.rb +76 -74
- data/spec/formatted_text_box_spec.rb +170 -159
- data/spec/formatted_text_fragment_spec.rb +57 -56
- data/spec/graphics_spec.rb +158 -175
- data/spec/grid_spec.rb +28 -29
- data/spec/image_handler_spec.rb +4 -5
- data/spec/images_spec.rb +50 -36
- data/spec/inline_formatted_text_parser_spec.rb +397 -393
- data/spec/jpg_spec.rb +4 -6
- data/spec/line_wrap_spec.rb +54 -55
- data/spec/measurement_units_spec.rb +12 -15
- data/spec/outline_spec.rb +77 -98
- data/spec/png_spec.rb +55 -65
- data/spec/reference_spec.rb +3 -3
- data/spec/repeater_spec.rb +20 -26
- data/spec/security_spec.rb +42 -49
- data/spec/soft_mask_spec.rb +4 -5
- data/spec/span_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -4
- data/spec/stamp_spec.rb +41 -22
- data/spec/stroke_styles_spec.rb +36 -39
- data/spec/text_at_spec.rb +28 -29
- data/spec/text_box_spec.rb +160 -165
- data/spec/text_rendering_mode_spec.rb +9 -9
- data/spec/text_spacing_spec.rb +13 -13
- data/spec/text_spec.rb +116 -124
- data/spec/text_with_inline_formatting_spec.rb +5 -5
- data/spec/transparency_spec.rb +20 -20
- data/spec/view_spec.rb +0 -1
- metadata +7 -7
data/spec/text_at_spec.rb
CHANGED
@@ -6,31 +6,31 @@ describe "#draw_text" do
|
|
6
6
|
before(:each) { create_pdf }
|
7
7
|
|
8
8
|
it "should raise_error ArgumentError if :at option omitted" do
|
9
|
-
|
9
|
+
expect { @pdf.draw_text("hai", {}) }.to raise_error(ArgumentError)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should raise_error ArgumentError if :align option included" do
|
13
|
-
|
13
|
+
expect { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.to raise_error(ArgumentError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should allow drawing empty strings to the page" do
|
17
|
-
@pdf.draw_text(" ", :at => [100,100])
|
17
|
+
@pdf.draw_text(" ", :at => [100, 100])
|
18
18
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
19
|
-
text.strings.first.
|
19
|
+
expect(text.strings.first).to eq(" ")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should default to 12 point helvetica" do
|
23
|
-
@pdf.draw_text("Blah", :at => [100,100])
|
23
|
+
@pdf.draw_text("Blah", :at => [100, 100])
|
24
24
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
25
|
-
text.font_settings[0][:name].
|
26
|
-
text.font_settings[0][:size].
|
27
|
-
text.strings.first.
|
25
|
+
expect(text.font_settings[0][:name]).to eq(:Helvetica)
|
26
|
+
expect(text.font_settings[0][:size]).to eq(12)
|
27
|
+
expect(text.strings.first).to eq("Blah")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should allow setting font size" do
|
31
|
-
@pdf.draw_text("Blah", :at => [100,100], :size => 16)
|
31
|
+
@pdf.draw_text("Blah", :at => [100, 100], :size => 16)
|
32
32
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
33
|
-
text.font_settings[0][:size].
|
33
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should allow setting a default font size" do
|
@@ -38,7 +38,7 @@ describe "#draw_text" do
|
|
38
38
|
@pdf.draw_text("Blah", :at => [0, 0])
|
39
39
|
|
40
40
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
41
|
-
text.font_settings[0][:size].
|
41
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
42
42
|
end
|
43
43
|
|
44
44
|
rotated_text_inspector = Class.new(PDF::Inspector) do
|
@@ -58,7 +58,7 @@ describe "#draw_text" do
|
|
58
58
|
|
59
59
|
text = rotated_text_inspector.analyze(@pdf.render)
|
60
60
|
|
61
|
-
text.tm_operator_used.
|
61
|
+
expect(text.tm_operator_used).to(be_true)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should not use rotation matrix by default" do
|
@@ -66,7 +66,7 @@ describe "#draw_text" do
|
|
66
66
|
|
67
67
|
text = rotated_text_inspector.analyze(@pdf.render)
|
68
68
|
|
69
|
-
text.tm_operator_used.
|
69
|
+
expect(text.tm_operator_used).to(be_false)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should allow overriding default font for a single instance" do
|
@@ -75,8 +75,8 @@ describe "#draw_text" do
|
|
75
75
|
@pdf.draw_text("Blah", :size => 11, :at => [0, 0])
|
76
76
|
@pdf.draw_text("Blaz", :at => [0, 0])
|
77
77
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
78
|
-
text.font_settings[0][:size].
|
79
|
-
text.font_settings[1][:size].
|
78
|
+
expect(text.font_settings[0][:size]).to eq(11)
|
79
|
+
expect(text.font_settings[1][:size]).to eq(16)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should allow setting a font size transaction with a block" do
|
@@ -87,35 +87,34 @@ describe "#draw_text" do
|
|
87
87
|
@pdf.draw_text('blah', :at => [0, 0])
|
88
88
|
|
89
89
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
90
|
-
text.font_settings[0][:size].
|
91
|
-
text.font_settings[1][:size].
|
90
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
91
|
+
expect(text.font_settings[1][:size]).to eq(12)
|
92
92
|
end
|
93
93
|
|
94
|
-
it "should allow manual setting the font size "
|
95
|
-
"when in a font size block" do
|
94
|
+
it "should allow manual setting the font size when in a font size block" do
|
96
95
|
@pdf.font_size(16) do
|
97
96
|
@pdf.draw_text('Foo', :at => [0, 0])
|
98
97
|
@pdf.draw_text('Blah', :size => 11, :at => [0, 0])
|
99
98
|
@pdf.draw_text('Blaz', :at => [0, 0])
|
100
99
|
end
|
101
100
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
102
|
-
text.font_settings[0][:size].
|
103
|
-
text.font_settings[1][:size].
|
104
|
-
text.font_settings[2][:size].
|
101
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
102
|
+
expect(text.font_settings[1][:size]).to eq(11)
|
103
|
+
expect(text.font_settings[2][:size]).to eq(16)
|
105
104
|
end
|
106
105
|
|
107
106
|
it "should allow registering of built-in font_settings on the fly" do
|
108
107
|
@pdf.font "Times-Roman"
|
109
|
-
@pdf.draw_text("Blah", :at => [100,100]
|
108
|
+
@pdf.draw_text("Blah", :at => [100, 100])
|
110
109
|
@pdf.font "Courier"
|
111
|
-
@pdf.draw_text("Blaz", :at => [150,150]
|
110
|
+
@pdf.draw_text("Blaz", :at => [150, 150])
|
112
111
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
113
|
-
text.font_settings[0][:name].
|
114
|
-
text.font_settings[1][:name].
|
112
|
+
expect(text.font_settings[0][:name]).to eq(:"Times-Roman")
|
113
|
+
expect(text.font_settings[1][:name]).to eq(:Courier)
|
115
114
|
end
|
116
115
|
|
117
116
|
it "should raise_error an exception when an unknown font is used" do
|
118
|
-
|
117
|
+
expect { @pdf.font "Pao bu" }.to raise_error(Prawn::Errors::UnknownFont)
|
119
118
|
end
|
120
119
|
|
121
120
|
it "should correctly render a utf-8 string when using a built-in font" do
|
@@ -124,12 +123,12 @@ describe "#draw_text" do
|
|
124
123
|
|
125
124
|
# grab the text from the rendered PDF and ensure it matches
|
126
125
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
127
|
-
text.strings.first.
|
126
|
+
expect(text.strings.first).to eq(str)
|
128
127
|
end
|
129
128
|
|
130
129
|
it "should raise_error an exception when a utf-8 incompatible string is rendered" do
|
131
130
|
str = "Blah \xDD"
|
132
|
-
|
131
|
+
expect { @pdf.draw_text(str, :at => [0, 0]) }.to raise_error(
|
133
132
|
Prawn::Errors::IncompatibleStringEncoding)
|
134
133
|
end
|
135
134
|
|
data/spec/text_box_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe "Text::Box#nothing_printed?" do
|
|
10
10
|
:height => 2,
|
11
11
|
:document => @pdf)
|
12
12
|
text_box.render
|
13
|
-
text_box.nothing_printed
|
13
|
+
expect(text_box.nothing_printed?).to be_true
|
14
14
|
end
|
15
15
|
it "should be_false when something printed" do
|
16
16
|
create_pdf
|
@@ -19,7 +19,7 @@ describe "Text::Box#nothing_printed?" do
|
|
19
19
|
:height => 14,
|
20
20
|
:document => @pdf)
|
21
21
|
text_box.render
|
22
|
-
text_box.nothing_printed
|
22
|
+
expect(text_box.nothing_printed?).to be_false
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -31,7 +31,7 @@ describe "Text::Box#everything_printed?" do
|
|
31
31
|
:height => 14,
|
32
32
|
:document => @pdf)
|
33
33
|
text_box.render
|
34
|
-
text_box.everything_printed
|
34
|
+
expect(text_box.everything_printed?).to be_false
|
35
35
|
end
|
36
36
|
it "should be_true when everything printed" do
|
37
37
|
create_pdf
|
@@ -39,19 +39,19 @@ describe "Text::Box#everything_printed?" do
|
|
39
39
|
text_box = Prawn::Text::Box.new(string,
|
40
40
|
:document => @pdf)
|
41
41
|
text_box.render
|
42
|
-
text_box.everything_printed
|
42
|
+
expect(text_box.everything_printed?).to be_true
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "Text::Box#line_gap" do
|
47
|
-
it "should == the line gap of the font when using a single "
|
47
|
+
it "should == the line gap of the font when using a single " \
|
48
48
|
"font and font size" do
|
49
49
|
create_pdf
|
50
50
|
string = "Hello world, how are you?\nI'm fine, thank you."
|
51
51
|
text_box = Prawn::Text::Box.new(string,
|
52
52
|
:document => @pdf)
|
53
53
|
text_box.render
|
54
|
-
text_box.line_gap.
|
54
|
+
expect(text_box.line_gap).to be_within(0.0001).of(@pdf.font.line_gap)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -65,8 +65,8 @@ describe "Text::Box" do
|
|
65
65
|
:document => @pdf)
|
66
66
|
text_box.render
|
67
67
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
68
|
-
text.strings[0].
|
69
|
-
text.strings[1].
|
68
|
+
expect(text.strings[0]).to eq("?uoy era woh ,dlrow olleH")
|
69
|
+
expect(text.strings[1]).to eq(".uoy knaht ,enif m'I")
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should be able to reverse multi-byte text" do
|
@@ -78,7 +78,7 @@ describe "Text::Box" do
|
|
78
78
|
@pdf.text "写个小"
|
79
79
|
end
|
80
80
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
81
|
-
text.strings[0].
|
81
|
+
expect(text.strings[0]).to eq("小个写")
|
82
82
|
end
|
83
83
|
|
84
84
|
it "option should be able to override document-wide text direction" do
|
@@ -90,20 +90,19 @@ describe "Text::Box" do
|
|
90
90
|
:direction => :ltr)
|
91
91
|
text_box.render
|
92
92
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
93
|
-
text.strings[0].
|
94
|
-
text.strings[1].
|
93
|
+
expect(text.strings[0]).to eq("Hello world, how are you?")
|
94
|
+
expect(text.strings[1]).to eq("I'm fine, thank you.")
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe "Text::Box" do
|
99
|
-
|
100
99
|
it "should be able to set leading document-wide" do
|
101
100
|
create_pdf
|
102
101
|
@pdf.default_leading(7)
|
103
102
|
@pdf.default_leading = 7
|
104
103
|
text_box = Prawn::Text::Box.new("hello world",
|
105
104
|
:document => @pdf)
|
106
|
-
text_box.leading.
|
105
|
+
expect(text_box.leading).to eq(7)
|
107
106
|
end
|
108
107
|
|
109
108
|
it "option should be able to override document-wide leading" do
|
@@ -112,11 +111,10 @@ describe "Text::Box" do
|
|
112
111
|
text_box = Prawn::Text::Box.new("hello world",
|
113
112
|
:document => @pdf,
|
114
113
|
:leading => 20)
|
115
|
-
text_box.leading.
|
114
|
+
expect(text_box.leading).to eq(20)
|
116
115
|
end
|
117
|
-
it "should default to document-wide leading if no"
|
116
|
+
it "should default to document-wide leading if no" \
|
118
117
|
"leading option is provided" do
|
119
|
-
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
@@ -128,7 +126,7 @@ describe "Text::Box#render with :align => :justify" do
|
|
128
126
|
text_box = Prawn::Text::Box.new(string, options)
|
129
127
|
text_box.render
|
130
128
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
131
|
-
contents.word_spacing[0].
|
129
|
+
expect(contents.word_spacing[0]).to be > 0
|
132
130
|
end
|
133
131
|
it "should not justify the last line of a paragraph" do
|
134
132
|
create_pdf
|
@@ -137,42 +135,42 @@ describe "Text::Box#render with :align => :justify" do
|
|
137
135
|
text_box = Prawn::Text::Box.new(string, options)
|
138
136
|
text_box.render
|
139
137
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
140
|
-
contents.word_spacing.
|
138
|
+
expect(contents.word_spacing).to be_empty
|
141
139
|
end
|
142
140
|
end
|
143
141
|
|
144
142
|
describe "Text::Box" do
|
145
|
-
it "should only require enough space for the descender and the ascender "
|
143
|
+
it "should only require enough space for the descender and the ascender " \
|
146
144
|
"when determining whether a line can fit" do
|
147
145
|
create_pdf
|
148
146
|
text = "Oh hai text rect"
|
149
147
|
options = { :document => @pdf, :height => @pdf.font.ascender + @pdf.font.descender }
|
150
148
|
text_box = Prawn::Text::Box.new(text, options)
|
151
149
|
text_box.render
|
152
|
-
text_box.text.
|
150
|
+
expect(text_box.text).to eq("Oh hai text rect")
|
153
151
|
|
154
152
|
text = "Oh hai text rect\nOh hai text rect"
|
155
153
|
options = { :document => @pdf, :height => @pdf.font.height + @pdf.font.ascender + @pdf.font.descender }
|
156
154
|
text_box = Prawn::Text::Box.new(text, options)
|
157
155
|
text_box.render
|
158
|
-
text_box.text.
|
156
|
+
expect(text_box.text).to eq("Oh hai text rect\nOh hai text rect")
|
159
157
|
end
|
160
158
|
end
|
161
159
|
|
162
160
|
describe "Text::Box#height without leading" do
|
163
|
-
it "should == the sum of the height of each line, "
|
161
|
+
it "should == the sum of the height of each line, " \
|
164
162
|
"not including the space below the last line" do
|
165
163
|
create_pdf
|
166
164
|
text = "Oh hai text rect.\nOh hai text rect."
|
167
165
|
options = { :document => @pdf }
|
168
166
|
text_box = Prawn::Text::Box.new(text, options)
|
169
167
|
text_box.render
|
170
|
-
text_box.height.
|
168
|
+
expect(text_box.height).to be_within(0.001).of(@pdf.font.height * 2 - @pdf.font.line_gap)
|
171
169
|
end
|
172
170
|
end
|
173
171
|
|
174
172
|
describe "Text::Box#height with leading" do
|
175
|
-
it "should == the sum of the height of each line plus leading, "
|
173
|
+
it "should == the sum of the height of each line plus leading, " \
|
176
174
|
"but not including the space below the last line" do
|
177
175
|
create_pdf
|
178
176
|
text = "Oh hai text rect.\nOh hai text rect."
|
@@ -180,7 +178,7 @@ describe "Text::Box#height with leading" do
|
|
180
178
|
options = { :document => @pdf, :leading => leading }
|
181
179
|
text_box = Prawn::Text::Box.new(text, options)
|
182
180
|
text_box.render
|
183
|
-
text_box.height.
|
181
|
+
expect(text_box.height).to be_within(0.001).of((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading)
|
184
182
|
end
|
185
183
|
end
|
186
184
|
|
@@ -188,30 +186,30 @@ describe "Text::Box with :draw_text_callback" do
|
|
188
186
|
before(:each) { create_pdf }
|
189
187
|
|
190
188
|
it "hits the callback whenever text is drawn" do
|
191
|
-
draw_block = stub
|
189
|
+
draw_block = stub
|
192
190
|
draw_block.expects(:kick).with("this text is long enough to")
|
193
191
|
draw_block.expects(:kick).with("span two lines")
|
194
192
|
|
195
193
|
@pdf.text_box "this text is long enough to span two lines",
|
196
|
-
|
197
|
-
|
194
|
+
:width => 150,
|
195
|
+
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
198
196
|
end
|
199
197
|
|
200
198
|
it "hits the callback once per fragment for :inline_format" do
|
201
|
-
draw_block = stub
|
199
|
+
draw_block = stub
|
202
200
|
draw_block.expects(:kick).with("this text has ")
|
203
201
|
draw_block.expects(:kick).with("fancy")
|
204
202
|
draw_block.expects(:kick).with(" formatting")
|
205
203
|
|
206
204
|
@pdf.text_box "this text has <b>fancy</b> formatting",
|
207
|
-
|
208
|
-
|
205
|
+
:inline_format => true, :width => 500,
|
206
|
+
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
209
207
|
end
|
210
208
|
|
211
209
|
it "does not call #draw_text!" do
|
212
210
|
@pdf.expects(:draw_text!).never
|
213
211
|
@pdf.text_box "some text", :width => 500,
|
214
|
-
|
212
|
+
:draw_text_callback => lambda { |_, _| }
|
215
213
|
end
|
216
214
|
end
|
217
215
|
|
@@ -219,7 +217,7 @@ describe "Text::Box#valid_options" do
|
|
219
217
|
it "should return an array" do
|
220
218
|
create_pdf
|
221
219
|
text_box = Prawn::Text::Box.new("", :document => @pdf)
|
222
|
-
text_box.valid_options.
|
220
|
+
expect(text_box.valid_options).to be_a_kind_of(Array)
|
223
221
|
end
|
224
222
|
end
|
225
223
|
|
@@ -233,7 +231,7 @@ describe "Text::Box#render" do
|
|
233
231
|
}
|
234
232
|
text_box = Prawn::Text::Box.new(@text, @options)
|
235
233
|
text_box.render
|
236
|
-
text_box.text.
|
234
|
+
expect(text_box.text).to eq("")
|
237
235
|
end
|
238
236
|
it "should draw content to the page" do
|
239
237
|
create_pdf
|
@@ -242,7 +240,7 @@ describe "Text::Box#render" do
|
|
242
240
|
text_box = Prawn::Text::Box.new(@text, @options)
|
243
241
|
text_box.render
|
244
242
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
245
|
-
text.strings.
|
243
|
+
expect(text.strings).not_to be_empty
|
246
244
|
end
|
247
245
|
it "should not draw a transformation matrix" do
|
248
246
|
create_pdf
|
@@ -251,7 +249,7 @@ describe "Text::Box#render" do
|
|
251
249
|
text_box = Prawn::Text::Box.new(@text, @options)
|
252
250
|
text_box.render
|
253
251
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
254
|
-
matrices.matrices.length.
|
252
|
+
expect(matrices.matrices.length).to eq(0)
|
255
253
|
end
|
256
254
|
end
|
257
255
|
|
@@ -264,7 +262,7 @@ describe "Text::Box#render(:single_line => true)" do
|
|
264
262
|
text_box = Prawn::Text::Box.new(@text, @options)
|
265
263
|
text_box.render
|
266
264
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
267
|
-
text.strings.length.
|
265
|
+
expect(text.strings.length).to eq(1)
|
268
266
|
end
|
269
267
|
end
|
270
268
|
|
@@ -276,7 +274,7 @@ describe "Text::Box#render(:dry_run => true)" do
|
|
276
274
|
text_box = Prawn::Text::Box.new(@text, @options)
|
277
275
|
text_box.render(:dry_run => true)
|
278
276
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
279
|
-
text.strings.
|
277
|
+
expect(text.strings).to be_empty
|
280
278
|
end
|
281
279
|
|
282
280
|
it "subsequent calls to render should_not raise_error an ArgumentError exception" do
|
@@ -303,7 +301,7 @@ describe "Text::Box#render(:valign => :bottom)" do
|
|
303
301
|
original_at = text_box.at.dup
|
304
302
|
|
305
303
|
text_box.render(:dry_run => true)
|
306
|
-
text_box.at.
|
304
|
+
expect(text_box.at).to eq(original_at)
|
307
305
|
end
|
308
306
|
end
|
309
307
|
|
@@ -320,7 +318,7 @@ describe "Text::Box#render(:valign => :center)" do
|
|
320
318
|
original_at = text_box.at.dup
|
321
319
|
|
322
320
|
text_box.render(:dry_run => true)
|
323
|
-
text_box.at.
|
321
|
+
expect(text_box.at).to eq(original_at)
|
324
322
|
end
|
325
323
|
end
|
326
324
|
|
@@ -352,16 +350,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
352
350
|
y = @y - @height / 2
|
353
351
|
x_prime = x * @cos - y * @sin
|
354
352
|
y_prime = x * @sin + y * @cos
|
355
|
-
matrices.matrices[0].
|
356
|
-
|
357
|
-
|
358
|
-
matrices.matrices[1].
|
359
|
-
|
360
|
-
|
361
|
-
|
353
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
354
|
+
reduce_precision(x - x_prime),
|
355
|
+
reduce_precision(y - y_prime)])
|
356
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
357
|
+
reduce_precision(@sin),
|
358
|
+
reduce_precision(-@sin),
|
359
|
+
reduce_precision(@cos), 0, 0])
|
362
360
|
|
363
361
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
364
|
-
text.strings.
|
362
|
+
expect(text.strings).not_to be_empty
|
365
363
|
end
|
366
364
|
end
|
367
365
|
context ":rotate_around option of :upper_left" do
|
@@ -375,16 +373,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
375
373
|
y = @y
|
376
374
|
x_prime = x * @cos - y * @sin
|
377
375
|
y_prime = x * @sin + y * @cos
|
378
|
-
matrices.matrices[0].
|
379
|
-
|
380
|
-
|
381
|
-
matrices.matrices[1].
|
382
|
-
|
383
|
-
|
384
|
-
|
376
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
377
|
+
reduce_precision(x - x_prime),
|
378
|
+
reduce_precision(y - y_prime)])
|
379
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
380
|
+
reduce_precision(@sin),
|
381
|
+
reduce_precision(-@sin),
|
382
|
+
reduce_precision(@cos), 0, 0])
|
385
383
|
|
386
384
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
387
|
-
text.strings.
|
385
|
+
expect(text.strings).not_to be_empty
|
388
386
|
end
|
389
387
|
end
|
390
388
|
context "default :rotate_around" do
|
@@ -397,16 +395,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
397
395
|
y = @y
|
398
396
|
x_prime = x * @cos - y * @sin
|
399
397
|
y_prime = x * @sin + y * @cos
|
400
|
-
matrices.matrices[0].
|
401
|
-
|
402
|
-
|
403
|
-
matrices.matrices[1].
|
404
|
-
|
405
|
-
|
406
|
-
|
398
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
399
|
+
reduce_precision(x - x_prime),
|
400
|
+
reduce_precision(y - y_prime)])
|
401
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
402
|
+
reduce_precision(@sin),
|
403
|
+
reduce_precision(-@sin),
|
404
|
+
reduce_precision(@cos), 0, 0])
|
407
405
|
|
408
406
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
409
|
-
text.strings.
|
407
|
+
expect(text.strings).not_to be_empty
|
410
408
|
end
|
411
409
|
end
|
412
410
|
context ":rotate_around option of :upper_right" do
|
@@ -420,16 +418,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
420
418
|
y = @y
|
421
419
|
x_prime = x * @cos - y * @sin
|
422
420
|
y_prime = x * @sin + y * @cos
|
423
|
-
matrices.matrices[0].
|
424
|
-
|
425
|
-
|
426
|
-
matrices.matrices[1].
|
427
|
-
|
428
|
-
|
429
|
-
|
421
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
422
|
+
reduce_precision(x - x_prime),
|
423
|
+
reduce_precision(y - y_prime)])
|
424
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
425
|
+
reduce_precision(@sin),
|
426
|
+
reduce_precision(-@sin),
|
427
|
+
reduce_precision(@cos), 0, 0])
|
430
428
|
|
431
429
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
432
|
-
text.strings.
|
430
|
+
expect(text.strings).not_to be_empty
|
433
431
|
end
|
434
432
|
end
|
435
433
|
context ":rotate_around option of :lower_right" do
|
@@ -443,16 +441,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
443
441
|
y = @y - @height
|
444
442
|
x_prime = x * @cos - y * @sin
|
445
443
|
y_prime = x * @sin + y * @cos
|
446
|
-
matrices.matrices[0].
|
447
|
-
|
448
|
-
|
449
|
-
matrices.matrices[1].
|
450
|
-
|
451
|
-
|
452
|
-
|
444
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
445
|
+
reduce_precision(x - x_prime),
|
446
|
+
reduce_precision(y - y_prime)])
|
447
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
448
|
+
reduce_precision(@sin),
|
449
|
+
reduce_precision(-@sin),
|
450
|
+
reduce_precision(@cos), 0, 0])
|
453
451
|
|
454
452
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
455
|
-
text.strings.
|
453
|
+
expect(text.strings).not_to be_empty
|
456
454
|
end
|
457
455
|
end
|
458
456
|
context ":rotate_around option of :lower_left" do
|
@@ -466,16 +464,16 @@ describe "Text::Box#render with :rotate option of 30)" do
|
|
466
464
|
y = @y - @height
|
467
465
|
x_prime = x * @cos - y * @sin
|
468
466
|
y_prime = x * @sin + y * @cos
|
469
|
-
matrices.matrices[0].
|
470
|
-
|
471
|
-
|
472
|
-
matrices.matrices[1].
|
473
|
-
|
474
|
-
|
475
|
-
|
467
|
+
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
468
|
+
reduce_precision(x - x_prime),
|
469
|
+
reduce_precision(y - y_prime)])
|
470
|
+
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
471
|
+
reduce_precision(@sin),
|
472
|
+
reduce_precision(-@sin),
|
473
|
+
reduce_precision(@cos), 0, 0])
|
476
474
|
|
477
475
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
478
|
-
text.strings.
|
476
|
+
expect(text.strings).not_to be_empty
|
479
477
|
end
|
480
478
|
end
|
481
479
|
end
|
@@ -488,7 +486,7 @@ describe "Text::Box default height" do
|
|
488
486
|
@text = "Oh hai\n" * 60
|
489
487
|
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
490
488
|
text_box.render
|
491
|
-
text_box.height.
|
489
|
+
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
492
490
|
end
|
493
491
|
|
494
492
|
it "should use the margin-box bottom if only in a stretchy bbox" do
|
@@ -497,34 +495,34 @@ describe "Text::Box default height" do
|
|
497
495
|
@text = "Oh hai\n" * 60
|
498
496
|
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
499
497
|
text_box.render
|
500
|
-
text_box.height.
|
498
|
+
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
501
499
|
end
|
502
500
|
end
|
503
501
|
|
504
|
-
it "should use the parent-box bottom if in a stretchy bbox and "
|
502
|
+
it "should use the parent-box bottom if in a stretchy bbox and " \
|
505
503
|
"overflow is :expand, even with an explicit height"do
|
506
504
|
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
507
505
|
target_height = @pdf.y - @pdf.bounds.bottom
|
508
506
|
@text = "Oh hai\n" * 60
|
509
507
|
text_box = Prawn::Text::Box.new(@text, :document => @pdf,
|
510
|
-
|
508
|
+
:height => 100,
|
509
|
+
:overflow => :expand)
|
511
510
|
text_box.render
|
512
|
-
text_box.height.
|
511
|
+
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
513
512
|
end
|
514
513
|
end
|
515
514
|
|
516
515
|
it "should use the innermost non-stretchy bbox, not the margin box" do
|
517
516
|
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width,
|
518
|
-
|
517
|
+
:height => 200) do
|
519
518
|
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
520
519
|
@text = "Oh hai\n" * 60
|
521
520
|
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
522
521
|
text_box.render
|
523
|
-
text_box.height.
|
522
|
+
expect(text_box.height).to be_within(@pdf.font.height).of(200)
|
524
523
|
end
|
525
524
|
end
|
526
525
|
end
|
527
|
-
|
528
526
|
end
|
529
527
|
|
530
528
|
describe "Text::Box default at" do
|
@@ -535,7 +533,7 @@ describe "Text::Box default at" do
|
|
535
533
|
@options = { :document => @pdf }
|
536
534
|
text_box = Prawn::Text::Box.new(@text, @options)
|
537
535
|
text_box.render
|
538
|
-
text_box.at.
|
536
|
+
expect(text_box.at).to eq(target_at)
|
539
537
|
end
|
540
538
|
end
|
541
539
|
|
@@ -550,24 +548,24 @@ describe "Text::Box with text than can fit in the box" do
|
|
550
548
|
}
|
551
549
|
end
|
552
550
|
|
553
|
-
it "printed text should match requested text, except that preceding and "
|
554
|
-
"trailing white space will be stripped from each line, and newlines may "
|
551
|
+
it "printed text should match requested text, except that preceding and " \
|
552
|
+
"trailing white space will be stripped from each line, and newlines may " \
|
555
553
|
"be inserted" do
|
556
554
|
text_box = Prawn::Text::Box.new(" " + @text, @options)
|
557
555
|
text_box.render
|
558
|
-
text_box.text.gsub("\n", " ").
|
556
|
+
expect(text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
559
557
|
end
|
560
558
|
|
561
559
|
it "render should return an empty string because no text remains unprinted" do
|
562
560
|
text_box = Prawn::Text::Box.new(@text, @options)
|
563
|
-
text_box.render.
|
561
|
+
expect(text_box.render).to eq("")
|
564
562
|
end
|
565
563
|
|
566
564
|
it "should be truncated when the leading is set high enough to prevent all the lines from being printed" do
|
567
565
|
@options[:leading] = 40
|
568
566
|
text_box = Prawn::Text::Box.new(@text, @options)
|
569
567
|
text_box.render
|
570
|
-
text_box.text.gsub("\n", " ").
|
568
|
+
expect(text_box.text.gsub("\n", " ")).not_to eq(@text.strip)
|
571
569
|
end
|
572
570
|
end
|
573
571
|
|
@@ -588,13 +586,13 @@ describe "Text::Box with text that fits exactly in the box" do
|
|
588
586
|
expected_height = @options.delete(:height)
|
589
587
|
text_box = Prawn::Text::Box.new(@text, @options)
|
590
588
|
text_box.render
|
591
|
-
text_box.height.
|
589
|
+
expect(text_box.height).to be_within(0.0001).of(expected_height)
|
592
590
|
end
|
593
591
|
|
594
592
|
it "should print everything" do
|
595
593
|
text_box = Prawn::Text::Box.new(@text, @options)
|
596
594
|
text_box.render
|
597
|
-
text_box.text.
|
595
|
+
expect(text_box.text).to eq(@text)
|
598
596
|
end
|
599
597
|
|
600
598
|
describe "with leading" do
|
@@ -606,14 +604,14 @@ describe "Text::Box with text that fits exactly in the box" do
|
|
606
604
|
@options[:height] += @options[:leading] * @interlines
|
607
605
|
text_box = Prawn::Text::Box.new(@text, @options)
|
608
606
|
text_box.render
|
609
|
-
text_box.text.
|
607
|
+
expect(text_box.text).to eq(@text)
|
610
608
|
end
|
611
609
|
|
612
610
|
it "should overflow when insufficient height is added" do
|
613
611
|
@options[:height] += @options[:leading] * @interlines - 1
|
614
612
|
text_box = Prawn::Text::Box.new(@text, @options)
|
615
613
|
text_box.render
|
616
|
-
text_box.text.
|
614
|
+
expect(text_box.text).not_to eq(@text)
|
617
615
|
end
|
618
616
|
end
|
619
617
|
|
@@ -626,14 +624,14 @@ describe "Text::Box with text that fits exactly in the box" do
|
|
626
624
|
@options[:height] += @options[:leading] * @interlines
|
627
625
|
text_box = Prawn::Text::Box.new(@text, @options)
|
628
626
|
text_box.render
|
629
|
-
text_box.text.
|
627
|
+
expect(text_box.text).to eq(@text)
|
630
628
|
end
|
631
629
|
|
632
630
|
it "should overflow when too much height is removed" do
|
633
631
|
@options[:height] += @options[:leading] * @interlines - 1
|
634
632
|
text_box = Prawn::Text::Box.new(@text, @options)
|
635
633
|
text_box.render
|
636
|
-
text_box.text.
|
634
|
+
expect(text_box.text).not_to eq(@text)
|
637
635
|
end
|
638
636
|
end
|
639
637
|
end
|
@@ -662,14 +660,14 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
|
|
662
660
|
it "unprinted text should be in UTF-8 encoding" do
|
663
661
|
@pdf.font("Panic Sans")
|
664
662
|
remaining_text = @text_box.render
|
665
|
-
remaining_text.
|
663
|
+
expect(remaining_text).to eq(@text)
|
666
664
|
end
|
667
665
|
end
|
668
666
|
|
669
667
|
describe "when using an AFM font" do
|
670
668
|
it "unprinted text should be in UTF-8 encoding" do
|
671
669
|
remaining_text = @text_box.render
|
672
|
-
remaining_text.
|
670
|
+
expect(remaining_text).to eq(@text)
|
673
671
|
end
|
674
672
|
end
|
675
673
|
end
|
@@ -693,18 +691,18 @@ describe "Text::Box with more text than can fit in the box" do
|
|
693
691
|
end
|
694
692
|
it "should be truncated" do
|
695
693
|
@text_box.render
|
696
|
-
@text_box.text.gsub("\n", " ").
|
694
|
+
expect(@text_box.text.gsub("\n", " ")).not_to eq(@text.strip)
|
697
695
|
end
|
698
696
|
it "render should not return an empty string because some text remains unprinted" do
|
699
|
-
@text_box.render.
|
697
|
+
expect(@text_box.render).not_to be_empty
|
700
698
|
end
|
701
699
|
it "#height should be no taller than the specified height" do
|
702
700
|
@text_box.render
|
703
|
-
@text_box.height.
|
701
|
+
expect(@text_box.height).to be <= @bounding_height
|
704
702
|
end
|
705
703
|
it "#height should be within one font height of the specified height" do
|
706
704
|
@text_box.render
|
707
|
-
@bounding_height.
|
705
|
+
expect(@bounding_height).to be_within(@pdf.font.height).of(@text_box.height)
|
708
706
|
end
|
709
707
|
context "with :rotate option" do
|
710
708
|
it "unrendered text should be the same as when not rotated" do
|
@@ -719,22 +717,22 @@ describe "Text::Box with more text than can fit in the box" do
|
|
719
717
|
@options[:rotate] = rotate
|
720
718
|
@options[:at] = [x, y]
|
721
719
|
rotated_text_box = Prawn::Text::Box.new(@text, @options)
|
722
|
-
rotated_text_box.render.
|
720
|
+
expect(rotated_text_box.render).to eq(remaining_text)
|
723
721
|
end
|
724
722
|
end
|
725
723
|
end
|
726
724
|
|
727
725
|
context "truncated with text and size taken from the manual" do
|
728
726
|
it "should return the right text" do
|
729
|
-
@text = "This is the beginning of the text. It will be cut somewhere and "
|
730
|
-
"the rest of the text will procede to be rendered this time by "
|
727
|
+
@text = "This is the beginning of the text. It will be cut somewhere and " \
|
728
|
+
"the rest of the text will procede to be rendered this time by " \
|
731
729
|
"calling another method." + " . " * 50
|
732
730
|
@options[:width] = 300
|
733
731
|
@options[:height] = 50
|
734
732
|
@options[:size] = 18
|
735
733
|
@text_box = Prawn::Text::Box.new(@text, @options)
|
736
734
|
remaining_text = @text_box.render
|
737
|
-
remaining_text.
|
735
|
+
expect(remaining_text).to eq("text will procede to be rendered this time by calling another method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ")
|
738
736
|
end
|
739
737
|
end
|
740
738
|
|
@@ -745,14 +743,14 @@ describe "Text::Box with more text than can fit in the box" do
|
|
745
743
|
end
|
746
744
|
it "height should expand to encompass all the text (but not exceed the height of the page)" do
|
747
745
|
@text_box.render
|
748
|
-
@text_box.height.
|
746
|
+
expect(@text_box.height).to be > @bounding_height
|
749
747
|
end
|
750
748
|
it "should display the entire string (as long as there was space remaining on the page to print all the text)" do
|
751
749
|
@text_box.render
|
752
|
-
@text_box.text.gsub("\n", " ").
|
750
|
+
expect(@text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
753
751
|
end
|
754
752
|
it "render should return an empty string because no text remains unprinted(as long as there was space remaining on the page to print all the text)" do
|
755
|
-
@text_box.render.
|
753
|
+
expect(@text_box.render).to eq("")
|
756
754
|
end
|
757
755
|
end
|
758
756
|
|
@@ -764,10 +762,10 @@ describe "Text::Box with more text than can fit in the box" do
|
|
764
762
|
end
|
765
763
|
it "should display the entire text" do
|
766
764
|
@text_box.render
|
767
|
-
@text_box.text.gsub("\n", " ").
|
765
|
+
expect(@text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
768
766
|
end
|
769
767
|
it "render should return an empty string because no text remains unprinted" do
|
770
|
-
@text_box.render.
|
768
|
+
expect(@text_box.render).to eq("")
|
771
769
|
end
|
772
770
|
end
|
773
771
|
|
@@ -779,12 +777,12 @@ describe "Text::Box with more text than can fit in the box" do
|
|
779
777
|
@text_box.render
|
780
778
|
|
781
779
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
782
|
-
text.font_settings[0][:size].
|
780
|
+
expect(text.font_settings[0][:size]).to eq(10.1)
|
783
781
|
end
|
784
782
|
end
|
785
783
|
end
|
786
784
|
|
787
|
-
describe "Text::Box with enough space to fit the text but using the "
|
785
|
+
describe "Text::Box with enough space to fit the text but using the " \
|
788
786
|
"shrink_to_fit overflow" do
|
789
787
|
it "should not shrink the text when there is no need to" do
|
790
788
|
create_pdf
|
@@ -800,7 +798,7 @@ describe "Text::Box with enough space to fit the text but using the " +
|
|
800
798
|
@text_box.render
|
801
799
|
|
802
800
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
803
|
-
text.font_settings[0][:size].
|
801
|
+
expect(text.font_settings[0][:size]).to eq(12)
|
804
802
|
end
|
805
803
|
end
|
806
804
|
|
@@ -817,11 +815,10 @@ describe "Text::Box with a solid block of Chinese characters" do
|
|
817
815
|
@options[:overflow] = :truncate
|
818
816
|
text_box = Prawn::Text::Box.new(@text, @options)
|
819
817
|
text_box.render
|
820
|
-
text_box.text.gsub("\n", "").
|
818
|
+
expect(text_box.text.gsub("\n", "")).to eq(@text)
|
821
819
|
end
|
822
820
|
end
|
823
821
|
|
824
|
-
|
825
822
|
describe "drawing bounding boxes" do
|
826
823
|
before(:each) { create_pdf }
|
827
824
|
|
@@ -830,12 +827,10 @@ describe "drawing bounding boxes" do
|
|
830
827
|
|
831
828
|
@pdf.text_box "Oh hai text box. " * 11, :height => @pdf.font.height * 10
|
832
829
|
|
833
|
-
@pdf.bounds.
|
834
|
-
|
830
|
+
expect(@pdf.bounds).to eq(margin_box)
|
835
831
|
end
|
836
832
|
end
|
837
833
|
|
838
|
-
|
839
834
|
describe "Text::Box#render with :character_spacing option" do
|
840
835
|
it "should draw the character spacing to the document" do
|
841
836
|
create_pdf
|
@@ -844,7 +839,7 @@ describe "Text::Box#render with :character_spacing option" do
|
|
844
839
|
text_box = Prawn::Text::Box.new(string, options)
|
845
840
|
text_box.render
|
846
841
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
847
|
-
contents.character_spacing[0].
|
842
|
+
expect(contents.character_spacing[0]).to eq(10)
|
848
843
|
end
|
849
844
|
it "should take character spacing into account when wrapping" do
|
850
845
|
create_pdf
|
@@ -855,7 +850,7 @@ describe "Text::Box#render with :character_spacing option" do
|
|
855
850
|
:character_spacing => 10,
|
856
851
|
:document => @pdf)
|
857
852
|
text_box.render
|
858
|
-
text_box.text.
|
853
|
+
expect(text_box.text).to eq("hello\nworld")
|
859
854
|
end
|
860
855
|
end
|
861
856
|
|
@@ -874,7 +869,7 @@ describe "Text::Box wrapping" do
|
|
874
869
|
:overflow => :expand,
|
875
870
|
:document => @pdf)
|
876
871
|
text_box.render
|
877
|
-
text_box.text.
|
872
|
+
expect(text_box.text).to eq(expect)
|
878
873
|
end
|
879
874
|
|
880
875
|
# white space was being stripped after the entire line was generated, meaning
|
@@ -882,7 +877,7 @@ describe "Text::Box wrapping" do
|
|
882
877
|
# for other characters, so wrapping "hello hello" resulted in
|
883
878
|
# "hello\n\nhello", rather than "hello\nhello"
|
884
879
|
#
|
885
|
-
it "white space at beginning of line should not be taken into account when"
|
880
|
+
it "white space at beginning of line should not be taken into account when" \
|
886
881
|
" computing line width" do
|
887
882
|
text = "hello hello"
|
888
883
|
expect = "hello\nhello"
|
@@ -893,7 +888,7 @@ describe "Text::Box wrapping" do
|
|
893
888
|
:overflow => :expand,
|
894
889
|
:document => @pdf)
|
895
890
|
text_box.render
|
896
|
-
text_box.text.
|
891
|
+
expect(text_box.text).to eq(expect)
|
897
892
|
end
|
898
893
|
|
899
894
|
it "should respect end of line when wrapping text" do
|
@@ -902,24 +897,24 @@ describe "Text::Box wrapping" do
|
|
902
897
|
|
903
898
|
@pdf.font "Courier"
|
904
899
|
text_box = Prawn::Text::Box.new(text,
|
905
|
-
|
906
|
-
|
907
|
-
|
900
|
+
:width => 220,
|
901
|
+
:overflow => :expand,
|
902
|
+
:document => @pdf)
|
908
903
|
text_box.render
|
909
|
-
text_box.text.
|
904
|
+
expect(text_box.text).to eq(expect)
|
910
905
|
end
|
911
906
|
|
912
907
|
it "should respect multiple newlines when wrapping text" do
|
913
908
|
text = "Please wrap only before THIS\n\nword. Don't wrap this"
|
914
|
-
expect= "Please wrap only before\nTHIS\n\nword. Don't wrap this"
|
909
|
+
expect = "Please wrap only before\nTHIS\n\nword. Don't wrap this"
|
915
910
|
|
916
911
|
@pdf.font "Courier"
|
917
912
|
text_box = Prawn::Text::Box.new(text,
|
918
|
-
|
919
|
-
|
920
|
-
|
913
|
+
:width => 200,
|
914
|
+
:overflow => :expand,
|
915
|
+
:document => @pdf)
|
921
916
|
text_box.render
|
922
|
-
text_box.text.
|
917
|
+
expect(text_box.text).to eq(expect)
|
923
918
|
end
|
924
919
|
|
925
920
|
it "should respect multiple newlines when wrapping text when those newlines coincide with a line break" do
|
@@ -928,11 +923,11 @@ describe "Text::Box wrapping" do
|
|
928
923
|
|
929
924
|
@pdf.font "Courier"
|
930
925
|
text_box = Prawn::Text::Box.new(text,
|
931
|
-
|
932
|
-
|
933
|
-
|
926
|
+
:width => 220,
|
927
|
+
:overflow => :expand,
|
928
|
+
:document => @pdf)
|
934
929
|
text_box.render
|
935
|
-
text_box.text.
|
930
|
+
expect(text_box.text).to eq(expect)
|
936
931
|
end
|
937
932
|
|
938
933
|
it "should respect initial newlines" do
|
@@ -941,11 +936,11 @@ describe "Text::Box wrapping" do
|
|
941
936
|
|
942
937
|
@pdf.font "Courier"
|
943
938
|
text_box = Prawn::Text::Box.new(text,
|
944
|
-
|
945
|
-
|
946
|
-
|
939
|
+
:width => 220,
|
940
|
+
:overflow => :expand,
|
941
|
+
:document => @pdf)
|
947
942
|
text_box.render
|
948
|
-
text_box.text.
|
943
|
+
expect(text_box.text).to eq(expect)
|
949
944
|
end
|
950
945
|
|
951
946
|
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
@@ -954,11 +949,11 @@ describe "Text::Box wrapping" do
|
|
954
949
|
|
955
950
|
@pdf.font "Courier"
|
956
951
|
text_box = Prawn::Text::Box.new(text,
|
957
|
-
|
958
|
-
|
959
|
-
|
952
|
+
:width => 180,
|
953
|
+
:overflow => :expand,
|
954
|
+
:document => @pdf)
|
960
955
|
text_box.render
|
961
|
-
text_box.text.
|
956
|
+
expect(text_box.text).to eq(expect)
|
962
957
|
end
|
963
958
|
|
964
959
|
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
@@ -966,31 +961,31 @@ describe "Text::Box wrapping" do
|
|
966
961
|
|
967
962
|
@pdf.font "Courier"
|
968
963
|
text_box = Prawn::Text::Box.new(text, :width => 180,
|
969
|
-
|
970
|
-
|
964
|
+
:overflow => :expand,
|
965
|
+
:document => @pdf)
|
971
966
|
|
972
967
|
text_box.render
|
973
968
|
|
974
969
|
expected = "©" * 25 + "\n" + "©" * 5
|
975
970
|
@pdf.font.normalize_encoding!(expected)
|
976
971
|
expected = expected.force_encoding(Encoding::UTF_8)
|
977
|
-
text_box.text.
|
972
|
+
expect(text_box.text).to eq(expected)
|
978
973
|
end
|
979
974
|
|
980
975
|
it "should wrap non-unicode strings using single-byte word-wrapping" do
|
981
976
|
text = "continúa esforzandote " * 5
|
982
977
|
text_box = Prawn::Text::Box.new(text, :width => 180,
|
983
|
-
|
978
|
+
:document => @pdf)
|
984
979
|
text_box.render
|
985
980
|
results_with_accent = text_box.text
|
986
981
|
|
987
982
|
text = "continua esforzandote " * 5
|
988
983
|
text_box = Prawn::Text::Box.new(text, :width => 180,
|
989
|
-
|
984
|
+
:document => @pdf)
|
990
985
|
text_box.render
|
991
986
|
results_without_accent = text_box.text
|
992
987
|
|
993
|
-
first_line(results_with_accent).length.
|
988
|
+
expect(first_line(results_with_accent).length).to eq(first_line(results_without_accent).length)
|
994
989
|
end
|
995
990
|
|
996
991
|
it "should allow you to disable wrapping by char" do
|
@@ -1018,7 +1013,7 @@ describe "Text::Box wrapping" do
|
|
1018
1013
|
:disable_wrap_by_char => true,
|
1019
1014
|
:document => @pdf)
|
1020
1015
|
text_box.render
|
1021
|
-
text_box.text.
|
1016
|
+
expect(text_box.text).to eq(expect)
|
1022
1017
|
end
|
1023
1018
|
end
|
1024
1019
|
|
@@ -1030,7 +1025,7 @@ describe "Text::Box#render with :mode option" do
|
|
1030
1025
|
text_box = Prawn::Text::Box.new(string, options)
|
1031
1026
|
text_box.render
|
1032
1027
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
1033
|
-
contents.text_rendering_mode.
|
1028
|
+
expect(contents.text_rendering_mode).to eq([2, 0])
|
1034
1029
|
end
|
1035
1030
|
end
|
1036
1031
|
|