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
data/spec/grid_spec.rb
CHANGED
@@ -8,20 +8,20 @@ describe "A document's grid" do
|
|
8
8
|
|
9
9
|
it "should allow definition of a grid" do
|
10
10
|
@pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
|
11
|
-
@pdf.grid.columns.
|
12
|
-
@pdf.grid.rows.
|
13
|
-
@pdf.grid.gutter.
|
11
|
+
expect(@pdf.grid.columns).to eq(5)
|
12
|
+
expect(@pdf.grid.rows).to eq(8)
|
13
|
+
expect(@pdf.grid.gutter).to eq(0.1)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should allow re-definition of a grid" do
|
17
17
|
@pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
|
18
|
-
@pdf.grid.columns.
|
19
|
-
@pdf.grid.rows.
|
20
|
-
@pdf.grid.gutter.
|
18
|
+
expect(@pdf.grid.columns).to eq(5)
|
19
|
+
expect(@pdf.grid.rows).to eq(8)
|
20
|
+
expect(@pdf.grid.gutter).to eq(0.1)
|
21
21
|
@pdf.define_grid(:columns => 3, :rows => 6, :gutter => 0.1)
|
22
|
-
@pdf.grid.columns.
|
23
|
-
@pdf.grid.rows.
|
24
|
-
@pdf.grid.gutter.
|
22
|
+
expect(@pdf.grid.columns).to eq(3)
|
23
|
+
expect(@pdf.grid.rows).to eq(6)
|
24
|
+
expect(@pdf.grid.gutter).to eq(0.1)
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "when a grid is defined" do
|
@@ -37,49 +37,48 @@ describe "A document's grid" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should compute the column width" do
|
40
|
-
(@pdf.grid.column_width * @num_columns.to_f +
|
41
|
-
@gutter * (@num_columns - 1).to_f).
|
40
|
+
expect(@pdf.grid.column_width * @num_columns.to_f +
|
41
|
+
@gutter * (@num_columns - 1).to_f).to eq(@pdf.bounds.width)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should compute the row height" do
|
45
|
-
(@pdf.grid.row_height * @num_rows.to_f +
|
46
|
-
@gutter * (@num_rows - 1).to_f).
|
45
|
+
expect(@pdf.grid.row_height * @num_rows.to_f +
|
46
|
+
@gutter * (@num_rows - 1).to_f).to eq(@pdf.bounds.height)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should give the edges of a grid box" do
|
50
50
|
grid_width = (@pdf.bounds.width.to_f -
|
51
|
-
(@gutter * (@num_columns - 1).to_f
|
51
|
+
(@gutter * (@num_columns - 1).to_f)) / @num_columns.to_f
|
52
52
|
grid_height = (@pdf.bounds.height.to_f -
|
53
|
-
(@gutter * (@num_rows - 1).to_f
|
53
|
+
(@gutter * (@num_rows - 1).to_f)) / @num_rows.to_f
|
54
54
|
|
55
55
|
exp_tl_x = (grid_width + @gutter.to_f) * 4.0
|
56
56
|
exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
|
57
57
|
|
58
|
-
@pdf.grid(1,4).top_left.
|
59
|
-
@pdf.grid(1,4).top_right.
|
60
|
-
@pdf.grid(1,4).bottom_left.
|
61
|
-
@pdf.grid(1,4).bottom_right.
|
58
|
+
expect(@pdf.grid(1, 4).top_left).to eq([exp_tl_x, exp_tl_y])
|
59
|
+
expect(@pdf.grid(1, 4).top_right).to eq([exp_tl_x + grid_width, exp_tl_y])
|
60
|
+
expect(@pdf.grid(1, 4).bottom_left).to eq([exp_tl_x, exp_tl_y - grid_height])
|
61
|
+
expect(@pdf.grid(1, 4).bottom_right).to eq([exp_tl_x + grid_width, exp_tl_y - grid_height])
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should give the edges of a multiple grid boxes" do
|
65
65
|
# Hand verified. Cheating a bit. Don't tell.
|
66
|
-
@pdf.grid([1,3], [2,5]).top_left.
|
67
|
-
@pdf.grid([1,3], [2,5]).top_right.
|
68
|
-
@pdf.grid([1,3], [2,5]).bottom_left.
|
69
|
-
@pdf.grid([1,3], [2,5]).bottom_right.
|
66
|
+
expect(@pdf.grid([1, 3], [2, 5]).top_left).to eq([330.0, 628.75])
|
67
|
+
expect(@pdf.grid([1, 3], [2, 5]).top_right).to eq([650.0, 628.75])
|
68
|
+
expect(@pdf.grid([1, 3], [2, 5]).bottom_left).to eq([330.0, 456.25])
|
69
|
+
expect(@pdf.grid([1, 3], [2, 5]).bottom_right).to eq([650.0, 456.25])
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should draw outlines without changing global default colors to grid color" do
|
73
73
|
@pdf.grid.show_all('cccccc')
|
74
74
|
|
75
75
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
76
|
-
colors.fill_color.
|
77
|
-
colors.stroke_color.
|
76
|
+
expect(colors.fill_color).not_to eq([0.8, 0.8, 0.8])
|
77
|
+
expect(colors.stroke_color).not_to eq([0.8, 0.8, 0.8])
|
78
78
|
|
79
79
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
80
80
|
# between fill_color without lots code.
|
81
|
-
|
82
|
-
colors.stroke_color.should == [0.0,0.0,0.0]
|
81
|
+
expect(colors.stroke_color).to eq([0.0, 0.0, 0.0])
|
83
82
|
end
|
84
83
|
|
85
84
|
it "should draw outlines without curent color settings" do
|
@@ -89,8 +88,8 @@ describe "A document's grid" do
|
|
89
88
|
@pdf.grid.show_all
|
90
89
|
|
91
90
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
92
|
-
colors.fill_color.
|
93
|
-
colors.stroke_color.
|
91
|
+
expect(colors.fill_color).to eq([0.8, 1.0, 0.0])
|
92
|
+
expect(colors.stroke_color).to eq([1.0, 0.8, 0.0])
|
94
93
|
end
|
95
94
|
end
|
96
95
|
end
|
data/spec/image_handler_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe "ImageHandler" do
|
|
15
15
|
image_handler.register(handler_b)
|
16
16
|
|
17
17
|
handler = image_handler.find("arbitrary blob")
|
18
|
-
handler.
|
18
|
+
expect(handler).to eq(handler_a)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can prepend handlers" do
|
@@ -25,7 +25,7 @@ describe "ImageHandler" do
|
|
25
25
|
image_handler.register!(handler_b)
|
26
26
|
|
27
27
|
handler = image_handler.find("arbitrary blob")
|
28
|
-
handler.
|
28
|
+
expect(handler).to eq(handler_b)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "can unregister a handler" do
|
@@ -37,7 +37,7 @@ describe "ImageHandler" do
|
|
37
37
|
image_handler.unregister(handler_a)
|
38
38
|
|
39
39
|
handler = image_handler.find('arbitrary blob')
|
40
|
-
handler.
|
40
|
+
expect(handler).to eq(handler_b)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "raises an error when no matching handler is found" do
|
@@ -48,7 +48,6 @@ describe "ImageHandler" do
|
|
48
48
|
image_handler.register(handler_b)
|
49
49
|
|
50
50
|
expect { image_handler.find("arbitrary blob") }.
|
51
|
-
|
51
|
+
to(raise_error(Prawn::Errors::UnsupportedImageType))
|
52
52
|
end
|
53
|
-
|
54
53
|
end
|
data/spec/images_spec.rb
CHANGED
@@ -5,37 +5,36 @@ require 'set'
|
|
5
5
|
require 'pathname'
|
6
6
|
|
7
7
|
describe "the image() function" do
|
8
|
-
|
9
8
|
before(:each) do
|
10
9
|
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
11
10
|
create_pdf
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should only embed an image once, even if it's added multiple times" do
|
15
|
-
@pdf.image @filename, :at => [100,100]
|
16
|
-
@pdf.image @filename, :at => [300,300]
|
14
|
+
@pdf.image @filename, :at => [100, 100]
|
15
|
+
@pdf.image @filename, :at => [300, 300]
|
17
16
|
|
18
17
|
output = @pdf.render
|
19
18
|
images = PDF::Inspector::XObject.analyze(output)
|
20
19
|
# there should be 2 images in the page resources
|
21
|
-
images.page_xobjects.first.size.
|
20
|
+
expect(images.page_xobjects.first.size).to eq(2)
|
22
21
|
# but only 1 image xobject
|
23
|
-
output.scan(/\/Type \/XObject/).size.
|
22
|
+
expect(output.scan(/\/Type \/XObject/).size).to eq(1)
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should return the image info object" do
|
27
26
|
info = @pdf.image(@filename)
|
28
27
|
|
29
|
-
info.
|
28
|
+
expect(info).to be_a_kind_of(Prawn::Images::JPG)
|
30
29
|
|
31
|
-
info.height.
|
30
|
+
expect(info.height).to eq(453)
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should accept IO objects" do
|
35
34
|
file = File.open(@filename, "rb")
|
36
35
|
info = @pdf.image(file)
|
37
36
|
|
38
|
-
info.height.
|
37
|
+
expect(info.height).to eq(453)
|
39
38
|
end
|
40
39
|
|
41
40
|
it "rewinds IO objects to be able to embed them multiply" do
|
@@ -43,12 +42,12 @@ describe "the image() function" do
|
|
43
42
|
|
44
43
|
@pdf.image(file)
|
45
44
|
info = @pdf.image(file)
|
46
|
-
info.height.
|
45
|
+
expect(info.height).to eq(453)
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should accept Pathname objects" do
|
50
49
|
info = @pdf.image(Pathname.new(@filename))
|
51
|
-
info.height.
|
50
|
+
expect(info.height).to eq(453)
|
52
51
|
end
|
53
52
|
|
54
53
|
context "setting the length of the bytestream" do
|
@@ -70,25 +69,25 @@ describe "the image() function" do
|
|
70
69
|
|
71
70
|
it "should raise_error an UnsupportedImageType if passed a BMP" do
|
72
71
|
filename = "#{Prawn::DATADIR}/images/tru256.bmp"
|
73
|
-
|
72
|
+
expect { @pdf.image filename, :at => [100, 100] }.to raise_error(Prawn::Errors::UnsupportedImageType)
|
74
73
|
end
|
75
74
|
|
76
75
|
it "should raise_error an UnsupportedImageType if passed an interlaced PNG" do
|
77
76
|
filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
|
78
|
-
|
77
|
+
expect { @pdf.image filename, :at => [100, 100] }.to raise_error(Prawn::Errors::UnsupportedImageType)
|
79
78
|
end
|
80
79
|
|
81
80
|
it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
|
82
81
|
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
83
|
-
@pdf.state.version.
|
82
|
+
expect(@pdf.state.version).to be >= 1.5
|
84
83
|
end
|
85
84
|
|
86
85
|
it "should embed 16-bit alpha channels for 16-bit PNGs" do
|
87
86
|
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
88
87
|
|
89
88
|
output = @pdf.render
|
90
|
-
output.
|
91
|
-
output.
|
89
|
+
expect(output).to match(/\/BitsPerComponent 16/)
|
90
|
+
expect(output).not_to match(/\/BitsPerComponent 8/)
|
92
91
|
end
|
93
92
|
|
94
93
|
it "should flow an image to a new page if it will not fit on a page" do
|
@@ -96,10 +95,10 @@ describe "the image() function" do
|
|
96
95
|
@pdf.image @filename, :fit => [600, 600]
|
97
96
|
output = StringIO.new(@pdf.render, 'r+')
|
98
97
|
hash = PDF::Reader::ObjectHash.new(output)
|
99
|
-
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
100
|
-
pages.size.
|
101
|
-
hash[pages[0]][:Resources][:XObject].keys.
|
102
|
-
hash[pages[1]][:Resources][:XObject].keys.
|
98
|
+
pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
|
99
|
+
expect(pages.size).to eq(2)
|
100
|
+
expect(hash[pages[0]][:Resources][:XObject].keys).to eq([:I1])
|
101
|
+
expect(hash[pages[1]][:Resources][:XObject].keys).to eq([:I2])
|
103
102
|
end
|
104
103
|
|
105
104
|
it "should not flow an image to a new page if it will fit on one page" do
|
@@ -107,10 +106,11 @@ describe "the image() function" do
|
|
107
106
|
@pdf.image @filename, :fit => [400, 400]
|
108
107
|
output = StringIO.new(@pdf.render, 'r+')
|
109
108
|
hash = PDF::Reader::ObjectHash.new(output)
|
110
|
-
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
111
|
-
pages.size.
|
112
|
-
Set.new(hash[pages[0]][:Resources][:XObject].keys).
|
109
|
+
pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
|
110
|
+
expect(pages.size).to eq(1)
|
111
|
+
expect(Set.new(hash[pages[0]][:Resources][:XObject].keys)).to eq(
|
113
112
|
Set.new([:I1, :I2])
|
113
|
+
)
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should not start a new page just for a stretchy bounding box" do
|
@@ -122,32 +122,46 @@ describe "the image() function" do
|
|
122
122
|
|
123
123
|
describe ":fit option" do
|
124
124
|
it "should fit inside the defined constraints" do
|
125
|
-
info = @pdf.image @filename, :fit => [100,400]
|
126
|
-
info.scaled_width.
|
127
|
-
info.scaled_height.
|
125
|
+
info = @pdf.image @filename, :fit => [100, 400]
|
126
|
+
expect(info.scaled_width).to be <= 100
|
127
|
+
expect(info.scaled_height).to be <= 400
|
128
128
|
|
129
|
-
info = @pdf.image @filename, :fit => [400,100]
|
130
|
-
info.scaled_width.
|
131
|
-
info.scaled_height.
|
129
|
+
info = @pdf.image @filename, :fit => [400, 100]
|
130
|
+
expect(info.scaled_width).to be <= 400
|
131
|
+
expect(info.scaled_height).to be <= 100
|
132
132
|
|
133
|
-
info = @pdf.image @filename, :fit => [604,453]
|
134
|
-
info.scaled_width.
|
135
|
-
info.scaled_height.
|
133
|
+
info = @pdf.image @filename, :fit => [604, 453]
|
134
|
+
expect(info.scaled_width).to eq(604)
|
135
|
+
expect(info.scaled_height).to eq(453)
|
136
136
|
end
|
137
137
|
it "should move text position" do
|
138
138
|
@y = @pdf.y
|
139
|
-
info = @pdf.image @filename, :fit => [100,400]
|
140
|
-
@pdf.y.
|
139
|
+
info = @pdf.image @filename, :fit => [100, 400]
|
140
|
+
expect(@pdf.y).to be < @y
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
describe ":at option" do
|
145
145
|
it "should not move text position" do
|
146
146
|
@y = @pdf.y
|
147
|
-
info = @pdf.image @filename, :at => [100,400]
|
148
|
-
@pdf.y.
|
147
|
+
info = @pdf.image @filename, :at => [100, 400]
|
148
|
+
expect(@pdf.y).to eq(@y)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
|
152
|
+
describe ":width option without :height option" do
|
153
|
+
it "scales the width and height" do
|
154
|
+
info = @pdf.image @filename, :width => 225
|
155
|
+
expect(info.scaled_height).to eq(168.75)
|
156
|
+
expect(info.scaled_width).to eq(225.0)
|
157
|
+
end
|
158
|
+
end
|
153
159
|
|
160
|
+
describe ":height option without :width option" do
|
161
|
+
it "scales the width and height" do
|
162
|
+
info = @pdf.image @filename, :height => 225
|
163
|
+
expect(info.scaled_height).to eq(225.0)
|
164
|
+
expect(info.scaled_width).to eq(300.0)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -5,443 +5,442 @@ describe "Text::Formatted::Parser#format" do
|
|
5
5
|
it "should handle sup" do
|
6
6
|
string = "<sup>superscript</sup>"
|
7
7
|
array = Prawn::Text::Formatted::Parser.format(string)
|
8
|
-
array[0].
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
expect(array[0]).to eq(:text => "superscript",
|
9
|
+
:styles => [:superscript],
|
10
|
+
:color => nil,
|
11
|
+
:link => nil,
|
12
|
+
:anchor => nil,
|
13
|
+
:local => nil,
|
14
|
+
:font => nil,
|
15
|
+
:size => nil,
|
16
|
+
:character_spacing => nil)
|
17
17
|
end
|
18
18
|
it "should handle sub" do
|
19
19
|
string = "<sub>subscript</sub>"
|
20
20
|
array = Prawn::Text::Formatted::Parser.format(string)
|
21
|
-
array[0].
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
expect(array[0]).to eq(:text => "subscript",
|
22
|
+
:styles => [:subscript],
|
23
|
+
:color => nil,
|
24
|
+
:link => nil,
|
25
|
+
:anchor => nil,
|
26
|
+
:local => nil,
|
27
|
+
:font => nil,
|
28
|
+
:size => nil,
|
29
|
+
:character_spacing => nil)
|
30
30
|
end
|
31
31
|
it "should handle rgb" do
|
32
32
|
string = "<color rgb='#ff0000'>red text</color>"
|
33
33
|
array = Prawn::Text::Formatted::Parser.format(string)
|
34
|
-
array[0].
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
expect(array[0]).to eq(:text => "red text",
|
35
|
+
:styles => [],
|
36
|
+
:color => "ff0000",
|
37
|
+
:link => nil,
|
38
|
+
:anchor => nil,
|
39
|
+
:local => nil,
|
40
|
+
:font => nil,
|
41
|
+
:size => nil,
|
42
|
+
:character_spacing => nil)
|
43
43
|
end
|
44
44
|
it "# should be optional in rgb" do
|
45
45
|
string = "<color rgb='ff0000'>red text</color>"
|
46
46
|
array = Prawn::Text::Formatted::Parser.format(string)
|
47
|
-
array[0].
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
expect(array[0]).to eq(:text => "red text",
|
48
|
+
:styles => [],
|
49
|
+
:color => "ff0000",
|
50
|
+
:link => nil,
|
51
|
+
:anchor => nil,
|
52
|
+
:local => nil,
|
53
|
+
:font => nil,
|
54
|
+
:size => nil,
|
55
|
+
:character_spacing => nil)
|
56
56
|
end
|
57
57
|
it "should handle cmyk" do
|
58
58
|
string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
|
59
59
|
array = Prawn::Text::Formatted::Parser.format(string)
|
60
|
-
array[0].
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
expect(array[0]).to eq(:text => "magenta text",
|
61
|
+
:styles => [],
|
62
|
+
:color => [0, 100, 0, 0],
|
63
|
+
:link => nil,
|
64
|
+
:anchor => nil,
|
65
|
+
:local => nil,
|
66
|
+
:font => nil,
|
67
|
+
:size => nil,
|
68
|
+
:character_spacing => nil)
|
69
69
|
end
|
70
70
|
it "should handle fonts" do
|
71
71
|
string = "<font name='Courier'>Courier text</font>"
|
72
72
|
array = Prawn::Text::Formatted::Parser.format(string)
|
73
|
-
array[0].
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
expect(array[0]).to eq(:text => "Courier text",
|
74
|
+
:styles => [],
|
75
|
+
:color => nil,
|
76
|
+
:link => nil,
|
77
|
+
:anchor => nil,
|
78
|
+
:local => nil,
|
79
|
+
:font => "Courier",
|
80
|
+
:size => nil,
|
81
|
+
:character_spacing => nil)
|
82
82
|
end
|
83
83
|
it "should handle size" do
|
84
84
|
string = "<font size='14'>14 point text</font>"
|
85
85
|
array = Prawn::Text::Formatted::Parser.format(string)
|
86
|
-
array[0].
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
86
|
+
expect(array[0]).to eq(:text => "14 point text",
|
87
|
+
:styles => [],
|
88
|
+
:color => nil,
|
89
|
+
:link => nil,
|
90
|
+
:anchor => nil,
|
91
|
+
:local => nil,
|
92
|
+
:font => nil,
|
93
|
+
:size => 14,
|
94
|
+
:character_spacing => nil)
|
95
95
|
end
|
96
96
|
it "should handle character_spacing" do
|
97
97
|
string = "<font character_spacing='2.5'>extra character spacing</font>"
|
98
98
|
array = Prawn::Text::Formatted::Parser.format(string)
|
99
|
-
array[0].
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
99
|
+
expect(array[0]).to eq(:text => "extra character spacing",
|
100
|
+
:styles => [],
|
101
|
+
:color => nil,
|
102
|
+
:link => nil,
|
103
|
+
:anchor => nil,
|
104
|
+
:local => nil,
|
105
|
+
:font => nil,
|
106
|
+
:size => nil,
|
107
|
+
:character_spacing => 2.5)
|
108
108
|
end
|
109
109
|
it "should handle links" do
|
110
110
|
string = "<link href='http://example.com'>external link</link>"
|
111
111
|
array = Prawn::Text::Formatted::Parser.format(string)
|
112
|
-
array[0].
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
112
|
+
expect(array[0]).to eq(:text => "external link",
|
113
|
+
:styles => [],
|
114
|
+
:color => nil,
|
115
|
+
:link => "http://example.com",
|
116
|
+
:anchor => nil,
|
117
|
+
:local => nil,
|
118
|
+
:font => nil,
|
119
|
+
:size => nil,
|
120
|
+
:character_spacing => nil)
|
121
121
|
end
|
122
122
|
it "should handle local links" do
|
123
123
|
string = "<link local='/home/example/foo.bar'>local link</link>"
|
124
124
|
array = Prawn::Text::Formatted::Parser.format(string)
|
125
|
-
array[0].
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
125
|
+
expect(array[0]).to eq(:text => "local link",
|
126
|
+
:styles => [],
|
127
|
+
:color => nil,
|
128
|
+
:link => nil,
|
129
|
+
:anchor => nil,
|
130
|
+
:local => "/home/example/foo.bar",
|
131
|
+
:font => nil,
|
132
|
+
:size => nil,
|
133
|
+
:character_spacing => nil)
|
134
134
|
end
|
135
135
|
it "should handle anchors" do
|
136
136
|
string = "<link anchor='ToC'>internal link</link>"
|
137
137
|
array = Prawn::Text::Formatted::Parser.format(string)
|
138
|
-
array[0].
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
138
|
+
expect(array[0]).to eq(:text => "internal link",
|
139
|
+
:styles => [],
|
140
|
+
:color => nil,
|
141
|
+
:link => nil,
|
142
|
+
:anchor => "ToC",
|
143
|
+
:local => nil,
|
144
|
+
:font => nil,
|
145
|
+
:size => nil,
|
146
|
+
:character_spacing => nil)
|
147
147
|
end
|
148
148
|
it "should handle higher order characters properly" do
|
149
149
|
string = "<b>©\n©</b>"
|
150
150
|
array = Prawn::Text::Formatted::Parser.format(string)
|
151
|
-
array[0].
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
array[1].
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
array[2].
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
151
|
+
expect(array[0]).to eq(:text => "©",
|
152
|
+
:styles => [:bold],
|
153
|
+
:color => nil,
|
154
|
+
:link => nil,
|
155
|
+
:anchor => nil,
|
156
|
+
:local => nil,
|
157
|
+
:font => nil,
|
158
|
+
:size => nil,
|
159
|
+
:character_spacing => nil)
|
160
|
+
expect(array[1]).to eq(:text => "\n",
|
161
|
+
:styles => [:bold],
|
162
|
+
:color => nil,
|
163
|
+
:link => nil,
|
164
|
+
:anchor => nil,
|
165
|
+
:local => nil,
|
166
|
+
:font => nil,
|
167
|
+
:size => nil,
|
168
|
+
:character_spacing => nil)
|
169
|
+
expect(array[2]).to eq(:text => "©",
|
170
|
+
:styles => [:bold],
|
171
|
+
:color => nil,
|
172
|
+
:link => nil,
|
173
|
+
:anchor => nil,
|
174
|
+
:local => nil,
|
175
|
+
:font => nil,
|
176
|
+
:size => nil,
|
177
|
+
:character_spacing => nil)
|
178
178
|
end
|
179
179
|
it "should convert < >, and & to <, >, and &, respectively" do
|
180
180
|
string = "hello <b><, >, and &</b>"
|
181
181
|
array = Prawn::Text::Formatted::Parser.format(string)
|
182
|
-
array[1].
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
182
|
+
expect(array[1]).to eq(:text => "<, >, and &",
|
183
|
+
:styles => [:bold],
|
184
|
+
:color => nil,
|
185
|
+
:link => nil,
|
186
|
+
:anchor => nil,
|
187
|
+
:local => nil,
|
188
|
+
:font => nil,
|
189
|
+
:size => nil,
|
190
|
+
:character_spacing => nil)
|
191
191
|
end
|
192
192
|
it "should handle double qoutes around tag attributes" do
|
193
193
|
string = 'some <font size="14">sized</font> text'
|
194
194
|
array = Prawn::Text::Formatted::Parser.format(string)
|
195
|
-
array[1].
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
195
|
+
expect(array[1]).to eq(:text => "sized",
|
196
|
+
:styles => [],
|
197
|
+
:color => nil,
|
198
|
+
:link => nil,
|
199
|
+
:anchor => nil,
|
200
|
+
:local => nil,
|
201
|
+
:font => nil,
|
202
|
+
:size => 14,
|
203
|
+
:character_spacing => nil)
|
204
204
|
end
|
205
205
|
it "should handle single qoutes around tag attributes" do
|
206
206
|
string = "some <font size='14'>sized</font> text"
|
207
207
|
array = Prawn::Text::Formatted::Parser.format(string)
|
208
|
-
array[1].
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
208
|
+
expect(array[1]).to eq(:text => "sized",
|
209
|
+
:styles => [],
|
210
|
+
:color => nil,
|
211
|
+
:link => nil,
|
212
|
+
:anchor => nil,
|
213
|
+
:local => nil,
|
214
|
+
:font => nil,
|
215
|
+
:size => 14,
|
216
|
+
:character_spacing => nil)
|
217
217
|
end
|
218
218
|
it "should construct a formatted text array from a string" do
|
219
219
|
string = "hello <b>world\nhow <i>are</i></b> you?"
|
220
220
|
array = Prawn::Text::Formatted::Parser.format(string)
|
221
221
|
|
222
|
-
array[0].
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
array[1].
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
array[2].
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
array[3].
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
array[4].
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
array[5].
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
222
|
+
expect(array[0]).to eq(:text => "hello ",
|
223
|
+
:styles => [],
|
224
|
+
:color => nil,
|
225
|
+
:link => nil,
|
226
|
+
:anchor => nil,
|
227
|
+
:local => nil,
|
228
|
+
:font => nil,
|
229
|
+
:size => nil,
|
230
|
+
:character_spacing => nil)
|
231
|
+
expect(array[1]).to eq(:text => "world",
|
232
|
+
:styles => [:bold],
|
233
|
+
:color => nil,
|
234
|
+
:link => nil,
|
235
|
+
:anchor => nil,
|
236
|
+
:local => nil,
|
237
|
+
:font => nil,
|
238
|
+
:size => nil,
|
239
|
+
:character_spacing => nil)
|
240
|
+
expect(array[2]).to eq(:text => "\n",
|
241
|
+
:styles => [:bold],
|
242
|
+
:color => nil,
|
243
|
+
:link => nil,
|
244
|
+
:anchor => nil,
|
245
|
+
:local => nil,
|
246
|
+
:font => nil,
|
247
|
+
:size => nil,
|
248
|
+
:character_spacing => nil)
|
249
|
+
expect(array[3]).to eq(:text => "how ",
|
250
|
+
:styles => [:bold],
|
251
|
+
:color => nil,
|
252
|
+
:link => nil,
|
253
|
+
:anchor => nil,
|
254
|
+
:local => nil,
|
255
|
+
:font => nil,
|
256
|
+
:size => nil,
|
257
|
+
:character_spacing => nil)
|
258
|
+
expect(array[4]).to eq(:text => "are",
|
259
|
+
:styles => [:bold, :italic],
|
260
|
+
:color => nil,
|
261
|
+
:link => nil,
|
262
|
+
:anchor => nil,
|
263
|
+
:local => nil,
|
264
|
+
:font => nil,
|
265
|
+
:size => nil,
|
266
|
+
:character_spacing => nil)
|
267
|
+
expect(array[5]).to eq(:text => " you?",
|
268
|
+
:styles => [],
|
269
|
+
:color => nil,
|
270
|
+
:link => nil,
|
271
|
+
:anchor => nil,
|
272
|
+
:local => nil,
|
273
|
+
:font => nil,
|
274
|
+
:size => nil,
|
275
|
+
:character_spacing => nil)
|
276
276
|
end
|
277
277
|
it "should accept <strong> as an alternative to <b>" do
|
278
278
|
string = "<strong>bold</strong> not bold"
|
279
279
|
array = Prawn::Text::Formatted::Parser.format(string)
|
280
280
|
|
281
|
-
array[0].
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
array[1].
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
281
|
+
expect(array[0]).to eq(:text => "bold",
|
282
|
+
:styles => [:bold],
|
283
|
+
:color => nil,
|
284
|
+
:link => nil,
|
285
|
+
:anchor => nil,
|
286
|
+
:local => nil,
|
287
|
+
:font => nil,
|
288
|
+
:size => nil,
|
289
|
+
:character_spacing => nil)
|
290
|
+
expect(array[1]).to eq(:text => " not bold",
|
291
|
+
:styles => [],
|
292
|
+
:color => nil,
|
293
|
+
:link => nil,
|
294
|
+
:anchor => nil,
|
295
|
+
:local => nil,
|
296
|
+
:font => nil,
|
297
|
+
:size => nil,
|
298
|
+
:character_spacing => nil)
|
299
299
|
end
|
300
300
|
it "should accept <em> as an alternative to <i>" do
|
301
301
|
string = "<em>italic</em> not italic"
|
302
302
|
array = Prawn::Text::Formatted::Parser.format(string)
|
303
303
|
|
304
|
-
array[0].
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
array[1].
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
304
|
+
expect(array[0]).to eq(:text => "italic",
|
305
|
+
:styles => [:italic],
|
306
|
+
:color => nil,
|
307
|
+
:link => nil,
|
308
|
+
:anchor => nil,
|
309
|
+
:local => nil,
|
310
|
+
:font => nil,
|
311
|
+
:size => nil,
|
312
|
+
:character_spacing => nil)
|
313
|
+
expect(array[1]).to eq(:text => " not italic",
|
314
|
+
:styles => [],
|
315
|
+
:color => nil,
|
316
|
+
:link => nil,
|
317
|
+
:anchor => nil,
|
318
|
+
:local => nil,
|
319
|
+
:font => nil,
|
320
|
+
:size => nil,
|
321
|
+
:character_spacing => nil)
|
322
322
|
end
|
323
323
|
it "should accept <a> as an alternative to <link>" do
|
324
324
|
string = "<a href='http://example.com'>link</a> not a link"
|
325
325
|
array = Prawn::Text::Formatted::Parser.format(string)
|
326
326
|
|
327
|
-
array[0].
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
array[1].
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
327
|
+
expect(array[0]).to eq(:text => "link",
|
328
|
+
:styles => [],
|
329
|
+
:color => nil,
|
330
|
+
:link => "http://example.com",
|
331
|
+
:anchor => nil,
|
332
|
+
:local => nil,
|
333
|
+
:font => nil,
|
334
|
+
:size => nil,
|
335
|
+
:character_spacing => nil)
|
336
|
+
expect(array[1]).to eq(:text => " not a link",
|
337
|
+
:styles => [],
|
338
|
+
:color => nil,
|
339
|
+
:link => nil,
|
340
|
+
:anchor => nil,
|
341
|
+
:local => nil,
|
342
|
+
:font => nil,
|
343
|
+
:size => nil,
|
344
|
+
:character_spacing => nil)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "should turn <br>, <br/> into newline" do
|
348
348
|
array = Prawn::Text::Formatted::Parser.format("hello<br>big<br/>world")
|
349
|
-
array.map { |frag| frag[:text] }.join.
|
349
|
+
expect(array.map { |frag| frag[:text] }.join).to eq("hello\nbig\nworld")
|
350
350
|
end
|
351
351
|
end
|
352
352
|
|
353
|
-
|
354
353
|
describe "Text::Formatted::Parser#to_string" do
|
355
354
|
it "should handle sup" do
|
356
355
|
string = "<sup>superscript</sup>"
|
357
356
|
array = [{ :text => "superscript",
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
357
|
+
:styles => [:superscript],
|
358
|
+
:color => nil,
|
359
|
+
:link => nil,
|
360
|
+
:anchor => nil,
|
361
|
+
:local => nil,
|
362
|
+
:font => nil,
|
363
|
+
:size => nil,
|
364
|
+
:character_spacing => nil }]
|
365
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
367
366
|
end
|
368
367
|
it "should handle sub" do
|
369
368
|
string = "<sub>subscript</sub>"
|
370
369
|
array = [{ :text => "subscript",
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
370
|
+
:styles => [:subscript],
|
371
|
+
:color => nil,
|
372
|
+
:link => nil,
|
373
|
+
:anchor => nil,
|
374
|
+
:local => nil,
|
375
|
+
:font => nil,
|
376
|
+
:size => nil,
|
377
|
+
:character_spacing => nil }]
|
378
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
380
379
|
end
|
381
380
|
it "should handle rgb" do
|
382
381
|
string = "<color rgb='ff0000'>red text</color>"
|
383
382
|
array = [{ :text => "red text",
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
383
|
+
:styles => [],
|
384
|
+
:color => "ff0000",
|
385
|
+
:link => nil,
|
386
|
+
:anchor => nil,
|
387
|
+
:local => nil,
|
388
|
+
:font => nil,
|
389
|
+
:size => nil,
|
390
|
+
:character_spacing => nil }]
|
391
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
393
392
|
end
|
394
393
|
it "should handle cmyk" do
|
395
394
|
string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
|
396
395
|
array = [{ :text => "magenta text",
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
396
|
+
:styles => [],
|
397
|
+
:color => [0, 100, 0, 0],
|
398
|
+
:link => nil,
|
399
|
+
:anchor => nil,
|
400
|
+
:local => nil,
|
401
|
+
:font => nil,
|
402
|
+
:size => nil,
|
403
|
+
:character_spacing => nil }]
|
404
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
406
405
|
end
|
407
406
|
it "should handle fonts" do
|
408
407
|
string = "<font name='Courier'>Courier text</font>"
|
409
408
|
array = [{ :text => "Courier text",
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
409
|
+
:styles => [],
|
410
|
+
:color => nil,
|
411
|
+
:link => nil,
|
412
|
+
:anchor => nil,
|
413
|
+
:local => nil,
|
414
|
+
:font => "Courier",
|
415
|
+
:size => nil,
|
416
|
+
:character_spacing => nil }]
|
417
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
419
418
|
end
|
420
419
|
it "should handle size" do
|
421
420
|
string = "<font size='14'>14 point text</font>"
|
422
421
|
array = [{ :text => "14 point text",
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
422
|
+
:styles => [],
|
423
|
+
:color => nil,
|
424
|
+
:link => nil,
|
425
|
+
:anchor => nil,
|
426
|
+
:local => nil,
|
427
|
+
:font => nil,
|
428
|
+
:size => 14,
|
429
|
+
:character_spacing => nil }]
|
430
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
432
431
|
end
|
433
432
|
it "should handle character spacing" do
|
434
433
|
string = "<font character_spacing='2.5'>2.5 extra character spacing</font>"
|
435
434
|
array = [{ :text => "2.5 extra character spacing",
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
435
|
+
:styles => [],
|
436
|
+
:color => nil,
|
437
|
+
:link => nil,
|
438
|
+
:anchor => nil,
|
439
|
+
:local => nil,
|
440
|
+
:font => nil,
|
441
|
+
:size => nil,
|
442
|
+
:character_spacing => 2.5 }]
|
443
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
445
444
|
end
|
446
445
|
it "should handle links" do
|
447
446
|
array = [{ :text => "external link",
|
@@ -454,7 +453,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
454
453
|
:size => nil,
|
455
454
|
:character_spacing => nil }]
|
456
455
|
string = "<link href='http://example.com'>external link</link>"
|
457
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
456
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
458
457
|
end
|
459
458
|
it "should handle anchors" do
|
460
459
|
array = [{ :text => "internal link",
|
@@ -466,74 +465,79 @@ describe "Text::Formatted::Parser#to_string" do
|
|
466
465
|
:size => nil,
|
467
466
|
:character_spacing => nil }]
|
468
467
|
string = "<link anchor='ToC'>internal link</link>"
|
469
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
468
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
470
469
|
end
|
471
470
|
it "should convert <, >, and & to < >, and &, respectively" do
|
472
|
-
array = [
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
471
|
+
array = [
|
472
|
+
{
|
473
|
+
:text => "hello ",
|
474
|
+
:styles => [],
|
475
|
+
:color => nil,
|
476
|
+
:link => nil,
|
477
|
+
:font => nil,
|
478
|
+
:size => nil,
|
479
|
+
:character_spacing => nil
|
480
|
+
},
|
481
|
+
{
|
482
|
+
:text => "<, >, and &",
|
483
|
+
:styles => [:bold],
|
484
|
+
:color => nil,
|
485
|
+
:link => nil,
|
486
|
+
:font => nil,
|
487
|
+
:size => nil,
|
488
|
+
:character_spacing => nil
|
489
|
+
}
|
490
|
+
]
|
486
491
|
string = "hello <b><, >, and &</b>"
|
487
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
492
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
488
493
|
end
|
489
|
-
it "should construct an HTML-esque string from a formatted"
|
490
|
-
" text array" do
|
494
|
+
it "should construct an HTML-esque string from a formatted text array" do
|
491
495
|
array = [
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
496
|
+
{ :text => "hello ",
|
497
|
+
:styles => [],
|
498
|
+
:color => nil,
|
499
|
+
:link => nil,
|
500
|
+
:font => nil,
|
501
|
+
:size => 14,
|
502
|
+
:character_spacing => nil },
|
503
|
+
{ :text => "world",
|
504
|
+
:styles => [:bold],
|
505
|
+
:color => nil,
|
506
|
+
:link => nil,
|
507
|
+
:font => nil,
|
508
|
+
:size => nil,
|
509
|
+
:character_spacing => nil },
|
510
|
+
{ :text => "\n",
|
511
|
+
:styles => [:bold],
|
512
|
+
:color => nil,
|
513
|
+
:link => nil,
|
514
|
+
:font => nil,
|
515
|
+
:size => nil,
|
516
|
+
:character_spacing => nil },
|
517
|
+
{ :text => "how ",
|
518
|
+
:styles => [:bold],
|
519
|
+
:color => nil,
|
520
|
+
:link => nil,
|
521
|
+
:font => nil,
|
522
|
+
:size => nil,
|
523
|
+
:character_spacing => nil },
|
524
|
+
{ :text => "are",
|
525
|
+
:styles => [:bold, :italic],
|
526
|
+
:color => nil,
|
527
|
+
:link => nil,
|
528
|
+
:font => nil,
|
529
|
+
:size => nil,
|
530
|
+
:character_spacing => nil },
|
531
|
+
{ :text => " you?",
|
532
|
+
:styles => [],
|
533
|
+
:color => nil,
|
534
|
+
:link => nil,
|
535
|
+
:font => nil,
|
536
|
+
:size => nil,
|
537
|
+
:character_spacing => nil }
|
538
|
+
]
|
535
539
|
string = "<font size='14'>hello </font><b>world</b><b>\n</b><b>how </b><b><i>are</i></b> you?"
|
536
|
-
Prawn::Text::Formatted::Parser.to_string(array).
|
540
|
+
expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
|
537
541
|
end
|
538
542
|
end
|
539
543
|
|
@@ -544,14 +548,14 @@ describe "Text::Formatted::Parser#array_paragraphs" do
|
|
544
548
|
{ :text => "how" },
|
545
549
|
{ :text => "are" },
|
546
550
|
{ :text => "you" }]
|
547
|
-
target = [[{ :text => "\n"}],
|
551
|
+
target = [[{ :text => "\n" }],
|
548
552
|
[{ :text => "hello" }],
|
549
553
|
[{ :text => "world" }],
|
550
|
-
[{ :text => "\n"}],
|
554
|
+
[{ :text => "\n" }],
|
551
555
|
[{ :text => "how" },
|
552
556
|
{ :text => "are" },
|
553
557
|
{ :text => "you" }]]
|
554
|
-
Prawn::Text::Formatted::Parser.array_paragraphs(array).
|
558
|
+
expect(Prawn::Text::Formatted::Parser.array_paragraphs(array)).to eq(target)
|
555
559
|
end
|
556
560
|
|
557
561
|
it "should work properly if ending in an empty paragraph" do
|
@@ -559,6 +563,6 @@ describe "Text::Formatted::Parser#array_paragraphs" do
|
|
559
563
|
target = [[{ :text => "\n" }],
|
560
564
|
[{ :text => "hello" }],
|
561
565
|
[{ :text => "world" }]]
|
562
|
-
Prawn::Text::Formatted::Parser.array_paragraphs(array).
|
566
|
+
expect(Prawn::Text::Formatted::Parser.array_paragraphs(array)).to eq(target)
|
563
567
|
end
|
564
568
|
end
|