prawn 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -9,16 +9,16 @@ describe "#text_rendering_mode" do
|
|
9
9
|
@pdf.text("hello world")
|
10
10
|
end
|
11
11
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
12
|
-
contents.text_rendering_mode.first.
|
12
|
+
expect(contents.text_rendering_mode.first).to eq(1)
|
13
13
|
end
|
14
|
-
it "should not draw the text rendering mode to the document"
|
14
|
+
it "should not draw the text rendering mode to the document" \
|
15
15
|
" when the new mode matches the old" do
|
16
16
|
create_pdf
|
17
17
|
@pdf.text_rendering_mode(:fill) do
|
18
18
|
@pdf.text("hello world")
|
19
19
|
end
|
20
20
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
21
|
-
contents.text_rendering_mode.
|
21
|
+
expect(contents.text_rendering_mode).to be_empty
|
22
22
|
end
|
23
23
|
it "should restore character spacing to 0" do
|
24
24
|
create_pdf
|
@@ -26,20 +26,20 @@ describe "#text_rendering_mode" do
|
|
26
26
|
@pdf.text("hello world")
|
27
27
|
end
|
28
28
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
29
|
-
contents.text_rendering_mode.
|
29
|
+
expect(contents.text_rendering_mode).to eq([1, 0])
|
30
30
|
end
|
31
31
|
it "should function as an accessor when no parameter given" do
|
32
32
|
create_pdf
|
33
33
|
@pdf.text_rendering_mode(:fill_stroke) do
|
34
34
|
@pdf.text("hello world")
|
35
|
-
@pdf.text_rendering_mode.
|
35
|
+
expect(@pdf.text_rendering_mode).to eq(:fill_stroke)
|
36
36
|
end
|
37
|
-
@pdf.text_rendering_mode.
|
37
|
+
expect(@pdf.text_rendering_mode).to eq(:fill)
|
38
38
|
end
|
39
39
|
it "should raise_error an exception when passed an invalid mode" do
|
40
40
|
create_pdf
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
expect { @pdf.text_rendering_mode(-1) }.to raise_error(ArgumentError)
|
42
|
+
expect { @pdf.text_rendering_mode(8) }.to raise_error(ArgumentError)
|
43
|
+
expect { @pdf.text_rendering_mode(:flil) }.to raise_error(ArgumentError)
|
44
44
|
end
|
45
45
|
end
|
data/spec/text_spacing_spec.rb
CHANGED
@@ -9,16 +9,16 @@ describe "#character_spacing" do
|
|
9
9
|
@pdf.text("hello world")
|
10
10
|
end
|
11
11
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
12
|
-
contents.character_spacing.first.
|
12
|
+
expect(contents.character_spacing.first).to eq(10.5556)
|
13
13
|
end
|
14
|
-
it "should not draw the character spacing to the document"
|
14
|
+
it "should not draw the character spacing to the document" \
|
15
15
|
" when the new character spacing matches the old" do
|
16
16
|
create_pdf
|
17
17
|
@pdf.character_spacing(0) do
|
18
18
|
@pdf.text("hello world")
|
19
19
|
end
|
20
20
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
21
|
-
contents.character_spacing.
|
21
|
+
expect(contents.character_spacing).to be_empty
|
22
22
|
end
|
23
23
|
it "should restore character spacing to 0" do
|
24
24
|
create_pdf
|
@@ -26,15 +26,15 @@ describe "#character_spacing" do
|
|
26
26
|
@pdf.text("hello world")
|
27
27
|
end
|
28
28
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
29
|
-
contents.character_spacing.last.
|
29
|
+
expect(contents.character_spacing.last).to eq(0)
|
30
30
|
end
|
31
31
|
it "should function as an accessor when no parameter given" do
|
32
32
|
create_pdf
|
33
33
|
@pdf.character_spacing(10.555555) do
|
34
34
|
@pdf.text("hello world")
|
35
|
-
@pdf.character_spacing.
|
35
|
+
expect(@pdf.character_spacing).to eq(10.555555)
|
36
36
|
end
|
37
|
-
@pdf.character_spacing.
|
37
|
+
expect(@pdf.character_spacing).to eq(0)
|
38
38
|
end
|
39
39
|
|
40
40
|
# ensure that we properly internationalize by using the number of characters
|
@@ -51,7 +51,7 @@ describe "#character_spacing" do
|
|
51
51
|
|
52
52
|
@pdf.character_spacing(10) do
|
53
53
|
# the new width should include seven 10-pt character spaces.
|
54
|
-
@pdf.width_of(str).
|
54
|
+
expect(@pdf.width_of(str)).to be_within(0.001).of(@raw_width + (10 * 7))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -63,16 +63,16 @@ describe "#word_spacing" do
|
|
63
63
|
@pdf.text("hello world")
|
64
64
|
end
|
65
65
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
66
|
-
contents.word_spacing.first.
|
66
|
+
expect(contents.word_spacing.first).to eq(10.5556)
|
67
67
|
end
|
68
|
-
it "should draw the word spacing to the document"
|
68
|
+
it "should draw the word spacing to the document" \
|
69
69
|
" when the new word spacing matches the old" do
|
70
70
|
create_pdf
|
71
71
|
@pdf.word_spacing(0) do
|
72
72
|
@pdf.text("hello world")
|
73
73
|
end
|
74
74
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
75
|
-
contents.word_spacing.
|
75
|
+
expect(contents.word_spacing).to be_empty
|
76
76
|
end
|
77
77
|
it "should restore word spacing to 0" do
|
78
78
|
create_pdf
|
@@ -80,14 +80,14 @@ describe "#word_spacing" do
|
|
80
80
|
@pdf.text("hello world")
|
81
81
|
end
|
82
82
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
83
|
-
contents.word_spacing.last.
|
83
|
+
expect(contents.word_spacing.last).to eq(0)
|
84
84
|
end
|
85
85
|
it "should function as an accessor when no parameter given" do
|
86
86
|
create_pdf
|
87
87
|
@pdf.word_spacing(10.555555) do
|
88
88
|
@pdf.text("hello world")
|
89
|
-
@pdf.word_spacing.
|
89
|
+
expect(@pdf.word_spacing).to eq(10.555555)
|
90
90
|
end
|
91
|
-
@pdf.word_spacing.
|
91
|
+
expect(@pdf.word_spacing).to eq(0)
|
92
92
|
end
|
93
93
|
end
|
data/spec/text_spec.rb
CHANGED
@@ -4,40 +4,40 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
4
4
|
|
5
5
|
describe "Prawn::Text::NBSP" do
|
6
6
|
it "should be defined" do
|
7
|
-
Prawn::Text::NBSP.
|
7
|
+
expect(Prawn::Text::NBSP).to eq(" ")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#height_of" do
|
12
12
|
before(:each) { create_pdf }
|
13
13
|
|
14
|
-
it "should return the height that would be required to print a"
|
14
|
+
it "should return the height that would be required to print a" \
|
15
15
|
"particular string of text" do
|
16
16
|
original_y = @pdf.y
|
17
17
|
@pdf.text("Foo")
|
18
18
|
new_y = @pdf.y
|
19
|
-
@pdf.height_of("Foo").
|
19
|
+
expect(@pdf.height_of("Foo")).to be_within(0.0001).of(original_y - new_y)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should omit the gap below the last descender if :final_gap => false "
|
22
|
+
it "should omit the gap below the last descender if :final_gap => false " \
|
23
23
|
"is given" do
|
24
24
|
original_y = @pdf.y
|
25
25
|
@pdf.text("Foo", :final_gap => false)
|
26
26
|
new_y = @pdf.y
|
27
|
-
@pdf.height_of("Foo", :final_gap => false).
|
27
|
+
expect(@pdf.height_of("Foo", :final_gap => false)).to be_within(0.0001).of(original_y - new_y)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should raise_error CannotFit if a too-small width is given" do
|
31
|
-
|
31
|
+
expect do
|
32
32
|
@pdf.height_of("text", :width => 1)
|
33
|
-
end.
|
33
|
+
end.to raise_error(Prawn::Errors::CannotFit)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should raise_error NotImplementedError if :indent_paragraphs option is provided" do
|
37
|
-
|
37
|
+
expect {
|
38
38
|
@pdf.height_of("hai", :width => 300,
|
39
|
-
|
40
|
-
}.
|
39
|
+
:indent_paragraphs => 60)
|
40
|
+
}.to raise_error(NotImplementedError)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should_not raise_error Prawn::Errors::UnknownOption if :final_gap option is provided" do
|
@@ -59,45 +59,45 @@ describe "#text" do
|
|
59
59
|
@pdf.text " "
|
60
60
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
61
61
|
# If anything is rendered to the page, it should be whitespace.
|
62
|
-
text.strings.each { |str| str.
|
62
|
+
text.strings.each { |str| expect(str).to match(/\A\s*\z/) }
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should ignore call when string is nil" do
|
66
|
-
@pdf.text(nil).
|
66
|
+
expect(@pdf.text(nil)).to be_false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should correctly render empty paragraphs" do
|
70
70
|
@pdf.text "text\n\ntext"
|
71
71
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
72
|
-
@pdf.page_count.
|
73
|
-
text.strings.reject
|
72
|
+
expect(@pdf.page_count).to eq(1)
|
73
|
+
expect(text.strings.reject(&:empty?)).to eq(["text", "text"])
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should correctly render empty paragraphs with :indent_paragraphs" do
|
77
77
|
@pdf.text "text\n\ntext", :indent_paragraphs => 5
|
78
78
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
79
|
-
@pdf.page_count.
|
80
|
-
text.strings.reject
|
79
|
+
expect(@pdf.page_count).to eq(1)
|
80
|
+
expect(text.strings.reject(&:empty?)).to eq(["text", "text"])
|
81
81
|
end
|
82
82
|
|
83
|
-
it "should correctly render strings ending with empty paragraphs and "
|
83
|
+
it "should correctly render strings ending with empty paragraphs and " \
|
84
84
|
":inline_format and :indent_paragraphs" do
|
85
85
|
@pdf.text "text\n\n", :inline_format => true, :indent_paragraphs => 5
|
86
86
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
87
|
-
@pdf.page_count.
|
88
|
-
text.strings.
|
87
|
+
expect(@pdf.page_count).to eq(1)
|
88
|
+
expect(text.strings).to eq(["text"])
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should default to use kerning information" do
|
92
92
|
@pdf.text "hello world"
|
93
93
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
94
|
-
text.kerned[0].
|
94
|
+
expect(text.kerned[0]).to be_true
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should be able to disable kerning with an option" do
|
98
98
|
@pdf.text "hello world", :kerning => false
|
99
99
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
100
|
-
text.kerned[0].
|
100
|
+
expect(text.kerned[0]).to be_false
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should be able to disable kerning document-wide" do
|
@@ -105,95 +105,92 @@ describe "#text" do
|
|
105
105
|
@pdf.default_kerning = false
|
106
106
|
@pdf.text "hello world"
|
107
107
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
108
|
-
text.kerned[0].
|
108
|
+
expect(text.kerned[0]).to be_false
|
109
109
|
end
|
110
110
|
|
111
111
|
it "option should be able to override document-wide kerning disabling" do
|
112
112
|
@pdf.default_kerning = false
|
113
113
|
@pdf.text "hello world", :kerning => true
|
114
114
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
115
|
-
text.kerned[0].
|
115
|
+
expect(text.kerned[0]).to be_true
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should raise_error ArgumentError if :at option included" do
|
119
|
-
|
119
|
+
expect { @pdf.text("hai", :at => [0, 0]) }.to raise_error(ArgumentError)
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should advance down the document based on font_height" do
|
123
123
|
position = @pdf.y
|
124
124
|
@pdf.text "Foo"
|
125
125
|
|
126
|
-
@pdf.y.
|
126
|
+
expect(@pdf.y).to be_within(0.0001).of(position - @pdf.font.height)
|
127
127
|
|
128
128
|
position = @pdf.y
|
129
129
|
@pdf.text "Foo\nBar\nBaz"
|
130
|
-
@pdf.y.
|
130
|
+
expect(@pdf.y).to be_within(0.0001).of(position - 3 * @pdf.font.height)
|
131
131
|
end
|
132
132
|
|
133
|
-
it "should advance down the document based on font_height"
|
134
|
-
" with size option" do
|
133
|
+
it "should advance down the document based on font_height with size option" do
|
135
134
|
position = @pdf.y
|
136
135
|
@pdf.text "Foo", :size => 15
|
137
136
|
|
138
137
|
@pdf.font_size = 15
|
139
|
-
@pdf.y.
|
138
|
+
expect(@pdf.y).to be_within(0.0001).of(position - @pdf.font.height)
|
140
139
|
|
141
140
|
position = @pdf.y
|
142
141
|
@pdf.text "Foo\nBar\nBaz"
|
143
|
-
@pdf.y.
|
142
|
+
expect(@pdf.y).to be_within(0.0001).of(position - 3 * @pdf.font.height)
|
144
143
|
end
|
145
144
|
|
146
|
-
it "should advance down the document based on font_height"
|
147
|
-
" with leading option" do
|
145
|
+
it "should advance down the document based on font_height with leading option" do
|
148
146
|
position = @pdf.y
|
149
147
|
leading = 2
|
150
148
|
@pdf.text "Foo", :leading => leading
|
151
149
|
|
152
|
-
@pdf.y.
|
150
|
+
expect(@pdf.y).to be_within(0.0001).of(position - @pdf.font.height - leading)
|
153
151
|
|
154
152
|
position = @pdf.y
|
155
153
|
@pdf.text "Foo\nBar\nBaz"
|
156
|
-
@pdf.y.
|
154
|
+
expect(@pdf.y).to be_within(0.0001).of(position - 3 * @pdf.font.height)
|
157
155
|
end
|
158
156
|
|
159
|
-
it "should advance only to the bottom of the final descender "
|
160
|
-
"if final_gap is false" do
|
157
|
+
it "should advance only to the bottom of the final descender if final_gap is false" do
|
161
158
|
position = @pdf.y
|
162
159
|
@pdf.text "Foo", :final_gap => false
|
163
160
|
|
164
|
-
@pdf.y.
|
161
|
+
expect(@pdf.y).to be_within(0.0001).of(position - @pdf.font.ascender - @pdf.font.descender)
|
165
162
|
|
166
163
|
position = @pdf.y
|
167
164
|
@pdf.text "Foo\nBar\nBaz", :final_gap => false
|
168
|
-
@pdf.y.
|
165
|
+
expect(@pdf.y).to be_within(0.0001).of(position - 2 * @pdf.font.height - @pdf.font.ascender - @pdf.font.descender)
|
169
166
|
end
|
170
167
|
|
171
168
|
it "should be able to print text starting at the last line of a page" do
|
172
169
|
@pdf.move_cursor_to(@pdf.font.height)
|
173
170
|
@pdf.text("hello world")
|
174
171
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
175
|
-
pages.size.
|
172
|
+
expect(pages.size).to eq(1)
|
176
173
|
end
|
177
174
|
|
178
175
|
it "should default to 12 point helvetica" do
|
179
176
|
@pdf.text "Blah"
|
180
177
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
181
|
-
text.font_settings[0][:name].
|
182
|
-
text.font_settings[0][:size].
|
183
|
-
text.strings.first.
|
178
|
+
expect(text.font_settings[0][:name]).to eq(:Helvetica)
|
179
|
+
expect(text.font_settings[0][:size]).to eq(12)
|
180
|
+
expect(text.strings.first).to eq("Blah")
|
184
181
|
end
|
185
182
|
|
186
183
|
it "should allow setting font size" do
|
187
184
|
@pdf.text "Blah", :size => 16
|
188
185
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
189
|
-
text.font_settings[0][:size].
|
186
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
190
187
|
end
|
191
188
|
|
192
189
|
it "should allow setting a default font size" do
|
193
190
|
@pdf.font_size = 16
|
194
191
|
@pdf.text "Blah"
|
195
192
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
196
|
-
text.font_settings[0][:size].
|
193
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
197
194
|
end
|
198
195
|
|
199
196
|
it "should allow overriding default font for a single instance" do
|
@@ -202,8 +199,8 @@ describe "#text" do
|
|
202
199
|
@pdf.text "Blah", :size => 11
|
203
200
|
@pdf.text "Blaz"
|
204
201
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
205
|
-
text.font_settings[0][:size].
|
206
|
-
text.font_settings[1][:size].
|
202
|
+
expect(text.font_settings[0][:size]).to eq(11)
|
203
|
+
expect(text.font_settings[1][:size]).to eq(16)
|
207
204
|
end
|
208
205
|
|
209
206
|
it "should allow setting a font size transaction with a block" do
|
@@ -214,21 +211,20 @@ describe "#text" do
|
|
214
211
|
@pdf.text 'blah'
|
215
212
|
|
216
213
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
217
|
-
text.font_settings[0][:size].
|
218
|
-
text.font_settings[1][:size].
|
214
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
215
|
+
expect(text.font_settings[1][:size]).to eq(12)
|
219
216
|
end
|
220
217
|
|
221
|
-
it "should allow manual setting the font size "
|
222
|
-
"when in a font size block" do
|
218
|
+
it "should allow manual setting the font size when in a font size block" do
|
223
219
|
@pdf.font_size(16) do
|
224
220
|
@pdf.text 'Foo'
|
225
221
|
@pdf.text 'Blah', :size => 11
|
226
222
|
@pdf.text 'Blaz'
|
227
223
|
end
|
228
224
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
229
|
-
text.font_settings[0][:size].
|
230
|
-
text.font_settings[1][:size].
|
231
|
-
text.font_settings[2][:size].
|
225
|
+
expect(text.font_settings[0][:size]).to eq(16)
|
226
|
+
expect(text.font_settings[1][:size]).to eq(11)
|
227
|
+
expect(text.font_settings[2][:size]).to eq(16)
|
232
228
|
end
|
233
229
|
|
234
230
|
it "should allow registering of built-in font_settings on the fly" do
|
@@ -237,8 +233,8 @@ describe "#text" do
|
|
237
233
|
@pdf.font "Courier"
|
238
234
|
@pdf.text "Blaz"
|
239
235
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
240
|
-
text.font_settings[0][:name].
|
241
|
-
text.font_settings[1][:name].
|
236
|
+
expect(text.font_settings[0][:name]).to eq(:"Times-Roman")
|
237
|
+
expect(text.font_settings[1][:name]).to eq(:Courier)
|
242
238
|
end
|
243
239
|
|
244
240
|
it "should utilise the same default font across multiple pages" do
|
@@ -247,13 +243,13 @@ describe "#text" do
|
|
247
243
|
@pdf.text "Blaz"
|
248
244
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
249
245
|
|
250
|
-
text.font_settings.size.
|
251
|
-
text.font_settings[0][:name].
|
252
|
-
text.font_settings[1][:name].
|
246
|
+
expect(text.font_settings.size).to eq(2)
|
247
|
+
expect(text.font_settings[0][:name]).to eq(:Helvetica)
|
248
|
+
expect(text.font_settings[1][:name]).to eq(:Helvetica)
|
253
249
|
end
|
254
250
|
|
255
251
|
it "should raise_error an exception when an unknown font is used" do
|
256
|
-
|
252
|
+
expect { @pdf.font "Pao bu" }.to raise_error(Prawn::Errors::UnknownFont)
|
257
253
|
end
|
258
254
|
|
259
255
|
it "should_not raise_error an exception when providing Pathname instance as font" do
|
@@ -266,7 +262,7 @@ describe "#text" do
|
|
266
262
|
|
267
263
|
# grab the text from the rendered PDF and ensure it matches
|
268
264
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
269
|
-
text.strings.first.
|
265
|
+
expect(text.strings.first).to eq(str)
|
270
266
|
end
|
271
267
|
|
272
268
|
it "should correctly render a utf-8 string when using a TTF font" do
|
@@ -276,46 +272,44 @@ describe "#text" do
|
|
276
272
|
|
277
273
|
# grab the text from the rendered PDF and ensure it matches
|
278
274
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
279
|
-
text.strings.first.
|
275
|
+
expect(text.strings.first).to eq(str)
|
280
276
|
end
|
281
277
|
|
282
|
-
it "subsets mixed low-ASCII and non-ASCII characters when they can be "
|
283
|
-
"subsetted together" do
|
278
|
+
it "subsets mixed low-ASCII and non-ASCII characters when they can be subsetted together" do
|
284
279
|
str = "It’s super effective!"
|
285
280
|
@pdf.font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
|
286
281
|
@pdf.text str
|
287
282
|
|
288
283
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
289
|
-
text.strings.first.
|
284
|
+
expect(text.strings.first).to eq(str)
|
290
285
|
end
|
291
286
|
|
292
|
-
it "should correctly render a string with higher bit characters across"
|
293
|
-
" a page break when using a built-in font" do
|
287
|
+
it "should correctly render a string with higher bit characters across a page break when using a built-in font" do
|
294
288
|
str = "©"
|
295
289
|
@pdf.move_cursor_to(@pdf.font.height)
|
296
290
|
@pdf.text(str + "\n" + str)
|
297
291
|
|
298
292
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
299
|
-
pages.size.
|
300
|
-
pages[0][:strings].
|
301
|
-
pages[1][:strings].
|
293
|
+
expect(pages.size).to eq(2)
|
294
|
+
expect(pages[0][:strings]).to eq([str])
|
295
|
+
expect(pages[1][:strings]).to eq([str])
|
302
296
|
end
|
303
297
|
|
304
|
-
it "should correctly render a string with higher bit characters across"
|
298
|
+
it "should correctly render a string with higher bit characters across" \
|
305
299
|
" a page break when using a built-in font and :indent_paragraphs option" do
|
306
300
|
str = "©"
|
307
301
|
@pdf.move_cursor_to(@pdf.font.height)
|
308
302
|
@pdf.text(str + "\n" + str, :indent_paragraphs => 20)
|
309
303
|
|
310
304
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
311
|
-
pages.size.
|
312
|
-
pages[0][:strings].
|
313
|
-
pages[1][:strings].
|
305
|
+
expect(pages.size).to eq(2)
|
306
|
+
expect(pages[0][:strings]).to eq([str])
|
307
|
+
expect(pages[1][:strings]).to eq([str])
|
314
308
|
end
|
315
309
|
|
316
310
|
it "should raise_error an exception when a utf-8 incompatible string is rendered" do
|
317
311
|
str = "Blah \xDD"
|
318
|
-
|
312
|
+
expect { @pdf.text str }.to raise_error(
|
319
313
|
Prawn::Errors::IncompatibleStringEncoding)
|
320
314
|
end
|
321
315
|
|
@@ -328,15 +322,15 @@ describe "#text" do
|
|
328
322
|
@pdf.text(sjis_str)
|
329
323
|
end
|
330
324
|
|
331
|
-
it "should call move_past_bottom when printing more text than can fit"
|
325
|
+
it "should call move_past_bottom when printing more text than can fit" \
|
332
326
|
" between the current document.y and bounds.bottom" do
|
333
327
|
@pdf.y = @pdf.font.height
|
334
328
|
@pdf.text "Hello"
|
335
329
|
@pdf.text "World"
|
336
330
|
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
337
|
-
pages.size.
|
338
|
-
pages[0][:strings].
|
339
|
-
pages[1][:strings].
|
331
|
+
expect(pages.size).to eq(2)
|
332
|
+
expect(pages[0][:strings]).to eq(["Hello"])
|
333
|
+
expect(pages[1][:strings]).to eq(["World"])
|
340
334
|
end
|
341
335
|
|
342
336
|
describe "with :indent_paragraphs option" do
|
@@ -345,13 +339,12 @@ describe "#text" do
|
|
345
339
|
hello2 = "hello " * 50
|
346
340
|
@pdf.text(hello + "\n" + hello2, :indent_paragraphs => 60)
|
347
341
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
348
|
-
text.strings[0].
|
349
|
-
text.strings[1].
|
350
|
-
text.strings[3].
|
351
|
-
text.strings[4].
|
342
|
+
expect(text.strings[0]).to eq(("hello " * 19).strip)
|
343
|
+
expect(text.strings[1]).to eq(("hello " * 21).strip)
|
344
|
+
expect(text.strings[3]).to eq(("hello " * 19).strip)
|
345
|
+
expect(text.strings[4]).to eq(("hello " * 21).strip)
|
352
346
|
end
|
353
347
|
|
354
|
-
|
355
348
|
it "should indent from right side when using :rtl direction" do
|
356
349
|
para1 = "The rain in spain falls mainly on the plains " * 3
|
357
350
|
para2 = "The rain in spain falls mainly on the plains " * 3
|
@@ -367,19 +360,19 @@ describe "#text" do
|
|
367
360
|
# text, which isn't necessarily correct. If we change that behavior,
|
368
361
|
# this test will need to be updated.
|
369
362
|
|
370
|
-
x_positions[0].
|
363
|
+
expect(x_positions[0]).to(
|
371
364
|
be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
|
372
365
|
@pdf.width_of(lines[0].reverse, :kerning => true)))
|
373
366
|
|
374
|
-
x_positions[1].
|
367
|
+
expect(x_positions[1]).to(
|
375
368
|
be_within(0.001).of(@pdf.bounds.absolute_right -
|
376
369
|
@pdf.width_of(lines[1].reverse, :kerning => true)))
|
377
370
|
|
378
|
-
x_positions[2].
|
371
|
+
expect(x_positions[2]).to(
|
379
372
|
be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
|
380
373
|
@pdf.width_of(lines[2].reverse, :kerning => true)))
|
381
374
|
|
382
|
-
x_positions[3].
|
375
|
+
expect(x_positions[3]).to(
|
383
376
|
be_within(0.001).of(@pdf.bounds.absolute_right -
|
384
377
|
@pdf.width_of(lines[3].reverse, :kerning => true)))
|
385
378
|
end
|
@@ -400,19 +393,19 @@ describe "#text" do
|
|
400
393
|
# text, which isn't necessarily correct. If we change that behavior,
|
401
394
|
# this test will need to be updated.
|
402
395
|
|
403
|
-
x_positions[0].
|
396
|
+
expect(x_positions[0]).to(
|
404
397
|
be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
|
405
398
|
@pdf.width_of(lines[0].reverse, :kerning => true)))
|
406
399
|
|
407
|
-
x_positions[1].
|
400
|
+
expect(x_positions[1]).to(
|
408
401
|
be_within(0.001).of(@pdf.bounds.absolute_right -
|
409
402
|
@pdf.width_of(lines[1].reverse, :kerning => true)))
|
410
403
|
|
411
|
-
x_positions[2].
|
404
|
+
expect(x_positions[2]).to(
|
412
405
|
be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
|
413
406
|
@pdf.width_of(lines[2].reverse, :kerning => true)))
|
414
407
|
|
415
|
-
x_positions[3].
|
408
|
+
expect(x_positions[3]).to(
|
416
409
|
be_within(0.001).of(@pdf.bounds.absolute_right -
|
417
410
|
@pdf.width_of(lines[3].reverse, :kerning => true)))
|
418
411
|
end
|
@@ -427,11 +420,11 @@ describe "#text" do
|
|
427
420
|
|
428
421
|
x_positions = text.positions.map { |e| e[0] }
|
429
422
|
|
430
|
-
x_positions[0].
|
431
|
-
x_positions[1].
|
423
|
+
expect(x_positions[0]).to eq(60)
|
424
|
+
expect(x_positions[1]).to eq(0)
|
432
425
|
|
433
|
-
x_positions[2].
|
434
|
-
x_positions[3].
|
426
|
+
expect(x_positions[2]).to eq(60)
|
427
|
+
expect(x_positions[3]).to eq(0)
|
435
428
|
end
|
436
429
|
|
437
430
|
it "should indent from left side when document has :ltr direction" do
|
@@ -445,15 +438,15 @@ describe "#text" do
|
|
445
438
|
|
446
439
|
x_positions = text.positions.map { |e| e[0] }
|
447
440
|
|
448
|
-
x_positions[0].
|
449
|
-
x_positions[1].
|
441
|
+
expect(x_positions[0]).to eq(60)
|
442
|
+
expect(x_positions[1]).to eq(0)
|
450
443
|
|
451
|
-
x_positions[2].
|
452
|
-
x_positions[3].
|
444
|
+
expect(x_positions[2]).to eq(60)
|
445
|
+
expect(x_positions[3]).to eq(0)
|
453
446
|
end
|
454
447
|
|
455
|
-
describe "when wrap to new page, and first line of new page"
|
456
|
-
" is not the start of a new paragraph, that line should"
|
448
|
+
describe "when wrap to new page, and first line of new page" \
|
449
|
+
" is not the start of a new paragraph, that line should" \
|
457
450
|
" not be indented" do
|
458
451
|
it "should indent the paragraphs" do
|
459
452
|
hello = "hello " * 50
|
@@ -461,14 +454,14 @@ describe "#text" do
|
|
461
454
|
@pdf.move_cursor_to(@pdf.font.height)
|
462
455
|
@pdf.text(hello + "\n" + hello2, :indent_paragraphs => 60)
|
463
456
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
464
|
-
text.strings[0].
|
465
|
-
text.strings[1].
|
466
|
-
text.strings[3].
|
467
|
-
text.strings[4].
|
457
|
+
expect(text.strings[0]).to eq(("hello " * 19).strip)
|
458
|
+
expect(text.strings[1]).to eq(("hello " * 21).strip)
|
459
|
+
expect(text.strings[3]).to eq(("hello " * 19).strip)
|
460
|
+
expect(text.strings[4]).to eq(("hello " * 21).strip)
|
468
461
|
end
|
469
462
|
end
|
470
|
-
describe "when wrap to new page, and first line of new page"
|
471
|
-
" is the start of a new paragraph, that line should"
|
463
|
+
describe "when wrap to new page, and first line of new page" \
|
464
|
+
" is the start of a new paragraph, that line should" \
|
472
465
|
" be indented" do
|
473
466
|
it "should indent the paragraphs" do
|
474
467
|
hello = "hello " * 50
|
@@ -476,10 +469,10 @@ describe "#text" do
|
|
476
469
|
@pdf.move_cursor_to(@pdf.font.height * 3)
|
477
470
|
@pdf.text(hello + "\n" + hello2, :indent_paragraphs => 60)
|
478
471
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
479
|
-
text.strings[0].
|
480
|
-
text.strings[1].
|
481
|
-
text.strings[3].
|
482
|
-
text.strings[4].
|
472
|
+
expect(text.strings[0]).to eq(("hello " * 19).strip)
|
473
|
+
expect(text.strings[1]).to eq(("hello " * 21).strip)
|
474
|
+
expect(text.strings[3]).to eq(("hello " * 19).strip)
|
475
|
+
expect(text.strings[4]).to eq(("hello " * 21).strip)
|
483
476
|
end
|
484
477
|
end
|
485
478
|
end
|
@@ -511,8 +504,7 @@ describe "#text" do
|
|
511
504
|
end
|
512
505
|
|
513
506
|
describe "#shrink_to_fit with special utf-8 text" do
|
514
|
-
it "Should not throw an exception",
|
515
|
-
:unresolved, :issue => 603 do
|
507
|
+
it "Should not throw an exception", :unresolved, :issue => 603 do
|
516
508
|
pages = 0
|
517
509
|
doc = Prawn::Document.new(page_size: 'A4', margin: [2, 2, 2, 2]) do |pdf|
|
518
510
|
add_unicode_fonts(pdf)
|
@@ -524,15 +516,16 @@ describe "#text" do
|
|
524
516
|
end
|
525
517
|
end
|
526
518
|
|
527
|
-
|
528
519
|
def add_unicode_fonts(pdf)
|
529
520
|
dejavu = "#{::Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
530
|
-
pdf.font_families.update(
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
521
|
+
pdf.font_families.update(
|
522
|
+
"dejavu" => {
|
523
|
+
:normal => dejavu,
|
524
|
+
:italic => dejavu,
|
525
|
+
:bold => dejavu,
|
526
|
+
:bold_italic => dejavu
|
527
|
+
}
|
528
|
+
)
|
536
529
|
pdf.fallback_fonts = ["dejavu"]
|
537
530
|
end
|
538
531
|
|
@@ -548,10 +541,9 @@ describe "#text" do
|
|
548
541
|
text = PDF::Inspector::Text.analyze(@pdf.render)
|
549
542
|
fonts_used = text.font_settings.map { |e| e[:name] }
|
550
543
|
|
551
|
-
fonts_used.length.
|
552
|
-
fonts_used[0].
|
553
|
-
text.strings[0].
|
544
|
+
expect(fonts_used.length).to eq(1)
|
545
|
+
expect(fonts_used[0]).to eq(:"Times-Italic")
|
546
|
+
expect(text.strings[0]).to eq("hello")
|
554
547
|
end
|
555
548
|
end
|
556
|
-
|
557
549
|
end
|