prawn 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/COPYING +2 -2
- data/Gemfile +8 -15
- data/LICENSE +1 -1
- data/Rakefile +25 -16
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn.rb +85 -23
- data/lib/prawn/document.rb +134 -116
- data/lib/prawn/document/bounding_box.rb +33 -4
- data/lib/prawn/document/column_box.rb +18 -6
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/encoding.rb +8 -9
- data/lib/prawn/errors.rb +13 -32
- data/lib/prawn/font.rb +137 -105
- data/lib/prawn/font/afm.rb +76 -32
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +33 -25
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics.rb +177 -57
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +5 -4
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +4 -15
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
- data/lib/prawn/image_handler.rb +42 -0
- data/lib/prawn/images.rb +58 -54
- data/lib/prawn/images/image.rb +6 -22
- data/lib/prawn/images/jpg.rb +20 -14
- data/lib/prawn/images/png.rb +58 -121
- data/lib/prawn/layout.rb +12 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +108 -147
- data/lib/prawn/repeater.rb +10 -8
- data/lib/prawn/security.rb +59 -40
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +4 -4
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table.rb +83 -60
- data/lib/prawn/table/cell.rb +17 -21
- data/lib/prawn/table/cell/image.rb +2 -3
- data/lib/prawn/table/cell/in_table.rb +8 -2
- data/lib/prawn/table/cell/span_dummy.rb +5 -0
- data/lib/prawn/table/cell/subtable.rb +3 -2
- data/lib/prawn/table/cell/text.rb +14 -12
- data/lib/prawn/table/cells.rb +58 -14
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/text.rb +27 -26
- data/lib/prawn/text/box.rb +12 -6
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +85 -57
- data/lib/prawn/text/formatted/fragment.rb +11 -11
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +11 -4
- data/lib/prawn/text/formatted/wrap.rb +156 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/document_and_page_options/document_and_page_options.rb +2 -1
- data/manual/document_and_page_options/metadata.rb +3 -3
- data/manual/document_and_page_options/page_size.rb +2 -2
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +2 -7
- data/manual/example_helper.rb +62 -81
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/stroke_dash.rb +19 -14
- data/manual/manual/cover.rb +16 -0
- data/manual/manual/manual.rb +1 -5
- data/manual/text/fallback_fonts.rb +4 -4
- data/manual/text/formatted_text.rb +5 -5
- data/manual/text/inline.rb +2 -4
- data/manual/text/registering_families.rb +12 -12
- data/manual/text/single_usage.rb +4 -4
- data/manual/text/text.rb +0 -2
- data/prawn.gemspec +21 -13
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +22 -5
- data/spec/cell_spec.rb +49 -5
- data/spec/column_box_spec.rb +32 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +112 -118
- data/spec/extensions/encoding_helpers.rb +5 -2
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +121 -120
- data/spec/formatted_text_arranger_spec.rb +24 -24
- data/spec/formatted_text_box_spec.rb +31 -32
- data/spec/formatted_text_fragment_spec.rb +2 -2
- data/spec/graphics_spec.rb +63 -45
- data/spec/grid_spec.rb +24 -13
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +34 -21
- data/spec/inline_formatted_text_parser_spec.rb +69 -20
- data/spec/jpg_spec.rb +3 -3
- data/spec/line_wrap_spec.rb +25 -14
- data/spec/measurement_units_spec.rb +5 -5
- data/spec/outline_spec.rb +68 -64
- data/spec/png_spec.rb +15 -18
- data/spec/reference_spec.rb +2 -82
- data/spec/repeater_spec.rb +1 -1
- data/spec/security_spec.rb +41 -9
- data/spec/soft_mask_spec.rb +0 -40
- data/spec/span_spec.rb +6 -11
- data/spec/spec_helper.rb +20 -2
- data/spec/stamp_spec.rb +19 -20
- data/spec/stroke_styles_spec.rb +31 -13
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +268 -43
- data/spec/text_at_spec.rb +13 -27
- data/spec/text_box_spec.rb +35 -30
- data/spec/text_spec.rb +56 -40
- data/spec/transparency_spec.rb +5 -5
- metadata +214 -217
- data/README.md +0 -98
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/lib/prawn/compatibility.rb +0 -87
- data/lib/prawn/core.rb +0 -87
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -79
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -177
- data/lib/prawn/core/object_store.rb +0 -320
- data/lib/prawn/core/page.rb +0 -212
- data/lib/prawn/core/pdf_object.rb +0 -125
- data/lib/prawn/core/reference.rb +0 -119
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/document/snapshot.rb +0 -89
- data/manual/manual/foreword.rb +0 -13
- data/manual/templates/full_template.rb +0 -23
- data/manual/templates/page_template.rb +0 -47
- data/manual/templates/templates.rb +0 -26
- data/manual/text/group.rb +0 -29
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/snapshot_spec.rb +0 -186
- data/spec/template_spec.rb +0 -351
data/spec/grid_spec.rb
CHANGED
@@ -1,46 +1,57 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
3
|
|
4
4
|
describe "A document's grid" do
|
5
5
|
before do
|
6
6
|
@pdf = Prawn::Document.new
|
7
7
|
end
|
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
11
|
@pdf.grid.columns.should == 5
|
12
12
|
@pdf.grid.rows.should == 8
|
13
13
|
@pdf.grid.gutter.should == 0.1
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
|
+
it "should allow re-definition of a grid" do
|
17
|
+
@pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
|
18
|
+
@pdf.grid.columns.should == 5
|
19
|
+
@pdf.grid.rows.should == 8
|
20
|
+
@pdf.grid.gutter.should == 0.1
|
21
|
+
@pdf.define_grid(:columns => 3, :rows => 6, :gutter => 0.1)
|
22
|
+
@pdf.grid.columns.should == 3
|
23
|
+
@pdf.grid.rows.should == 6
|
24
|
+
@pdf.grid.gutter.should == 0.1
|
25
|
+
end
|
26
|
+
|
16
27
|
describe "when a grid is defined" do
|
17
28
|
before do
|
18
29
|
@num_columns = 5
|
19
30
|
@num_rows = 8
|
20
31
|
@gutter = 10.0
|
21
32
|
@pdf.define_grid(
|
22
|
-
:columns => @num_columns,
|
23
|
-
:rows => @num_rows,
|
33
|
+
:columns => @num_columns,
|
34
|
+
:rows => @num_rows,
|
24
35
|
:gutter => @gutter
|
25
36
|
)
|
26
37
|
end
|
27
|
-
|
38
|
+
|
28
39
|
it "should compute the column width" do
|
29
|
-
(@pdf.grid.column_width * @num_columns.to_f +
|
40
|
+
(@pdf.grid.column_width * @num_columns.to_f +
|
30
41
|
@gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
it "should compute the row height" do
|
34
|
-
(@pdf.grid.row_height * @num_rows.to_f +
|
45
|
+
(@pdf.grid.row_height * @num_rows.to_f +
|
35
46
|
@gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height
|
36
47
|
end
|
37
48
|
|
38
49
|
it "should give the edges of a grid box" do
|
39
|
-
grid_width = (@pdf.bounds.width.to_f -
|
50
|
+
grid_width = (@pdf.bounds.width.to_f -
|
40
51
|
(@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f
|
41
|
-
grid_height = (@pdf.bounds.height.to_f -
|
52
|
+
grid_height = (@pdf.bounds.height.to_f -
|
42
53
|
(@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f
|
43
|
-
|
54
|
+
|
44
55
|
exp_tl_x = (grid_width + @gutter.to_f) * 4.0
|
45
56
|
exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
|
46
57
|
|
@@ -64,7 +75,7 @@ describe "A document's grid" do
|
|
64
75
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
65
76
|
colors.fill_color.should_not == [0.8,0.8,0.8]
|
66
77
|
colors.stroke_color.should_not == [0.8,0.8,0.8]
|
67
|
-
|
78
|
+
|
68
79
|
# Hardcoded default color as I haven't been able to come up with a stable converter
|
69
80
|
# between fill_color without lots code.
|
70
81
|
#colors.fill_color.should == [0.0,0.0,0.0]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "ImageHandler" do
|
6
|
+
let(:image_handler) { Prawn::ImageHandler.new }
|
7
|
+
|
8
|
+
let(:handler_a) { mock("Handler A") }
|
9
|
+
let(:handler_b) { mock("Handler B") }
|
10
|
+
|
11
|
+
it "finds the image handler for an image" do
|
12
|
+
handler_a.expects(:can_render? => true)
|
13
|
+
|
14
|
+
image_handler.register(handler_a)
|
15
|
+
image_handler.register(handler_b)
|
16
|
+
|
17
|
+
handler = image_handler.find("arbitrary blob")
|
18
|
+
handler.should == handler_a
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can prepend handlers" do
|
22
|
+
handler_b.expects(:can_render? => true)
|
23
|
+
|
24
|
+
image_handler.register(handler_a)
|
25
|
+
image_handler.register!(handler_b)
|
26
|
+
|
27
|
+
handler = image_handler.find("arbitrary blob")
|
28
|
+
handler.should == handler_b
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can unregister a handler" do
|
32
|
+
handler_b.expects(:can_render? => true)
|
33
|
+
|
34
|
+
image_handler.register(handler_a)
|
35
|
+
image_handler.register(handler_b)
|
36
|
+
|
37
|
+
image_handler.unregister(handler_a)
|
38
|
+
|
39
|
+
handler = image_handler.find('arbitrary blob')
|
40
|
+
handler.should == handler_b
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error when no matching handler is found" do
|
44
|
+
handler_a.expects(:can_render? => false)
|
45
|
+
handler_b.expects(:can_render? => false)
|
46
|
+
|
47
|
+
image_handler.register(handler_a)
|
48
|
+
image_handler.register(handler_b)
|
49
|
+
|
50
|
+
expect { image_handler.find("arbitrary blob") }.
|
51
|
+
to(raise_error(Prawn::Errors::UnsupportedImageType))
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/images_spec.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
4
|
require 'set'
|
5
5
|
require 'pathname'
|
6
6
|
|
7
7
|
describe "the image() function" do
|
8
8
|
|
9
9
|
before(:each) do
|
10
|
-
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
10
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
11
11
|
create_pdf
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should only embed an image once, even if it's added multiple times" do
|
15
15
|
@pdf.image @filename, :at => [100,100]
|
16
16
|
@pdf.image @filename, :at => [300,300]
|
17
|
-
|
17
|
+
|
18
18
|
output = @pdf.render
|
19
19
|
images = PDF::Inspector::XObject.analyze(output)
|
20
20
|
# there should be 2 images in the page resources
|
21
21
|
images.page_xobjects.first.size.should == 2
|
22
22
|
# but only 1 image xobject
|
23
23
|
output.scan(/\/Type \/XObject/).size.should == 1
|
24
|
-
end
|
25
|
-
|
24
|
+
end
|
25
|
+
|
26
26
|
it "should return the image info object" do
|
27
27
|
info = @pdf.image(@filename)
|
28
|
-
|
28
|
+
|
29
29
|
info.should be_a_kind_of(Prawn::Images::JPG)
|
30
|
-
|
30
|
+
|
31
31
|
info.height.should == 453
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should accept IO objects" do
|
35
35
|
file = File.open(@filename, "rb")
|
36
36
|
info = @pdf.image(file)
|
37
|
-
|
37
|
+
|
38
38
|
info.height.should == 453
|
39
39
|
end
|
40
40
|
|
@@ -51,6 +51,23 @@ describe "the image() function" do
|
|
51
51
|
info.height.should == 453
|
52
52
|
end
|
53
53
|
|
54
|
+
context "setting the length of the bytestream" do
|
55
|
+
it "should correctly work with images from Pathname objects" do
|
56
|
+
info = @pdf.image(Pathname.new(@filename))
|
57
|
+
expect(@pdf).to have_parseable_xobjects
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should correctly work with images from IO objects" do
|
61
|
+
info = @pdf.image(File.open(@filename, 'rb'))
|
62
|
+
expect(@pdf).to have_parseable_xobjects
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should correctly work with images from IO objects not set to mode rb" do
|
66
|
+
info = @pdf.image(File.open(@filename, 'r'))
|
67
|
+
expect(@pdf).to have_parseable_xobjects
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
54
71
|
it "should raise_error an UnsupportedImageType if passed a BMP" do
|
55
72
|
filename = "#{Prawn::DATADIR}/images/tru256.bmp"
|
56
73
|
lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
|
@@ -66,36 +83,32 @@ describe "the image() function" do
|
|
66
83
|
@pdf.state.version.should >= 1.5
|
67
84
|
end
|
68
85
|
|
69
|
-
|
70
|
-
# channels. Verified experimentally [BE] but not confirmed in documentation
|
71
|
-
# or anything. OS X Preview handles those files just fine.
|
72
|
-
#
|
73
|
-
it "should embed 8-bit alpha channels for 16-bit PNGs" do
|
86
|
+
it "should embed 16-bit alpha channels for 16-bit PNGs" do
|
74
87
|
@pdf.image "#{Prawn::DATADIR}/images/16bit.png"
|
75
88
|
|
76
89
|
output = @pdf.render
|
77
90
|
output.should =~ /\/BitsPerComponent 16/
|
78
|
-
output.
|
91
|
+
output.should_not =~ /\/BitsPerComponent 8/
|
79
92
|
end
|
80
|
-
|
93
|
+
|
81
94
|
it "should flow an image to a new page if it will not fit on a page" do
|
82
95
|
@pdf.image @filename, :fit => [600, 600]
|
83
96
|
@pdf.image @filename, :fit => [600, 600]
|
84
97
|
output = StringIO.new(@pdf.render, 'r+')
|
85
98
|
hash = PDF::Reader::ObjectHash.new(output)
|
86
99
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
87
|
-
pages.size.should == 2
|
100
|
+
pages.size.should == 2
|
88
101
|
hash[pages[0]][:Resources][:XObject].keys.should == [:I1]
|
89
102
|
hash[pages[1]][:Resources][:XObject].keys.should == [:I2]
|
90
|
-
end
|
91
|
-
|
103
|
+
end
|
104
|
+
|
92
105
|
it "should not flow an image to a new page if it will fit on one page" do
|
93
106
|
@pdf.image @filename, :fit => [400, 400]
|
94
107
|
@pdf.image @filename, :fit => [400, 400]
|
95
108
|
output = StringIO.new(@pdf.render, 'r+')
|
96
109
|
hash = PDF::Reader::ObjectHash.new(output)
|
97
110
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
98
|
-
pages.size.should == 1
|
111
|
+
pages.size.should == 1
|
99
112
|
Set.new(hash[pages[0]][:Resources][:XObject].keys).should ==
|
100
113
|
Set.new([:I1, :I2])
|
101
114
|
end
|
@@ -106,7 +119,7 @@ describe "the image() function" do
|
|
106
119
|
@pdf.image @filename
|
107
120
|
end
|
108
121
|
end
|
109
|
-
|
122
|
+
|
110
123
|
describe ":fit option" do
|
111
124
|
it "should fit inside the defined constraints" do
|
112
125
|
info = @pdf.image @filename, :fit => [100,400]
|
@@ -1,135 +1,159 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
3
3
|
|
4
|
-
describe "Text::Formatted::Parser#
|
4
|
+
describe "Text::Formatted::Parser#format" do
|
5
5
|
it "should handle sup" do
|
6
6
|
string = "<sup>superscript</sup>"
|
7
|
-
array = Prawn::Text::Formatted::Parser.
|
7
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
8
8
|
array[0].should == { :text => "superscript",
|
9
9
|
:styles => [:superscript],
|
10
10
|
:color => nil,
|
11
11
|
:link => nil,
|
12
12
|
:anchor => nil,
|
13
|
+
:local => nil,
|
13
14
|
:font => nil,
|
14
15
|
:size => nil,
|
15
16
|
:character_spacing => nil }
|
16
17
|
end
|
17
18
|
it "should handle sub" do
|
18
19
|
string = "<sub>subscript</sub>"
|
19
|
-
array = Prawn::Text::Formatted::Parser.
|
20
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
20
21
|
array[0].should == { :text => "subscript",
|
21
22
|
:styles => [:subscript],
|
22
23
|
:color => nil,
|
23
24
|
:link => nil,
|
24
25
|
:anchor => nil,
|
26
|
+
:local => nil,
|
25
27
|
:font => nil,
|
26
28
|
:size => nil,
|
27
29
|
:character_spacing => nil }
|
28
30
|
end
|
29
31
|
it "should handle rgb" do
|
30
32
|
string = "<color rgb='#ff0000'>red text</color>"
|
31
|
-
array = Prawn::Text::Formatted::Parser.
|
33
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
32
34
|
array[0].should == { :text => "red text",
|
33
35
|
:styles => [],
|
34
36
|
:color => "ff0000",
|
35
37
|
:link => nil,
|
36
38
|
:anchor => nil,
|
39
|
+
:local => nil,
|
37
40
|
:font => nil,
|
38
41
|
:size => nil,
|
39
42
|
:character_spacing => nil }
|
40
43
|
end
|
41
44
|
it "# should be optional in rgb" do
|
42
45
|
string = "<color rgb='ff0000'>red text</color>"
|
43
|
-
array = Prawn::Text::Formatted::Parser.
|
46
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
44
47
|
array[0].should == { :text => "red text",
|
45
48
|
:styles => [],
|
46
49
|
:color => "ff0000",
|
47
50
|
:link => nil,
|
48
51
|
:anchor => nil,
|
52
|
+
:local => nil,
|
49
53
|
:font => nil,
|
50
54
|
:size => nil,
|
51
55
|
:character_spacing => nil }
|
52
56
|
end
|
53
57
|
it "should handle cmyk" do
|
54
58
|
string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
|
55
|
-
array = Prawn::Text::Formatted::Parser.
|
59
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
56
60
|
array[0].should == { :text => "magenta text",
|
57
61
|
:styles => [],
|
58
62
|
:color => [0, 100, 0, 0],
|
59
63
|
:link => nil,
|
60
64
|
:anchor => nil,
|
65
|
+
:local => nil,
|
61
66
|
:font => nil,
|
62
67
|
:size => nil,
|
63
68
|
:character_spacing => nil }
|
64
69
|
end
|
65
70
|
it "should handle fonts" do
|
66
71
|
string = "<font name='Courier'>Courier text</font>"
|
67
|
-
array = Prawn::Text::Formatted::Parser.
|
72
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
68
73
|
array[0].should == { :text => "Courier text",
|
69
74
|
:styles => [],
|
70
75
|
:color => nil,
|
71
76
|
:link => nil,
|
72
77
|
:anchor => nil,
|
78
|
+
:local => nil,
|
73
79
|
:font => "Courier",
|
74
80
|
:size => nil,
|
75
81
|
:character_spacing => nil }
|
76
82
|
end
|
77
83
|
it "should handle size" do
|
78
84
|
string = "<font size='14'>14 point text</font>"
|
79
|
-
array = Prawn::Text::Formatted::Parser.
|
85
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
80
86
|
array[0].should == { :text => "14 point text",
|
81
87
|
:styles => [],
|
82
88
|
:color => nil,
|
83
89
|
:link => nil,
|
84
90
|
:anchor => nil,
|
91
|
+
:local => nil,
|
85
92
|
:font => nil,
|
86
93
|
:size => 14,
|
87
94
|
:character_spacing => nil }
|
88
95
|
end
|
89
96
|
it "should handle character_spacing" do
|
90
97
|
string = "<font character_spacing='2.5'>extra character spacing</font>"
|
91
|
-
array = Prawn::Text::Formatted::Parser.
|
98
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
92
99
|
array[0].should == { :text => "extra character spacing",
|
93
100
|
:styles => [],
|
94
101
|
:color => nil,
|
95
102
|
:link => nil,
|
96
103
|
:anchor => nil,
|
104
|
+
:local => nil,
|
97
105
|
:font => nil,
|
98
106
|
:size => nil,
|
99
107
|
:character_spacing => 2.5 }
|
100
108
|
end
|
101
109
|
it "should handle links" do
|
102
110
|
string = "<link href='http://example.com'>external link</link>"
|
103
|
-
array = Prawn::Text::Formatted::Parser.
|
111
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
104
112
|
array[0].should == { :text => "external link",
|
105
113
|
:styles => [],
|
106
114
|
:color => nil,
|
107
115
|
:link => "http://example.com",
|
108
116
|
:anchor => nil,
|
117
|
+
:local => nil,
|
118
|
+
:font => nil,
|
119
|
+
:size => nil,
|
120
|
+
:character_spacing => nil }
|
121
|
+
end
|
122
|
+
it "should handle local links" do
|
123
|
+
string = "<link local='/home/example/foo.bar'>local link</link>"
|
124
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
125
|
+
array[0].should == { :text => "local link",
|
126
|
+
:styles => [],
|
127
|
+
:color => nil,
|
128
|
+
:link => nil,
|
129
|
+
:anchor => nil,
|
130
|
+
:local => "/home/example/foo.bar",
|
109
131
|
:font => nil,
|
110
132
|
:size => nil,
|
111
133
|
:character_spacing => nil }
|
112
134
|
end
|
113
135
|
it "should handle anchors" do
|
114
136
|
string = "<link anchor='ToC'>internal link</link>"
|
115
|
-
array = Prawn::Text::Formatted::Parser.
|
137
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
116
138
|
array[0].should == { :text => "internal link",
|
117
139
|
:styles => [],
|
118
140
|
:color => nil,
|
119
141
|
:link => nil,
|
120
142
|
:anchor => "ToC",
|
143
|
+
:local => nil,
|
121
144
|
:font => nil,
|
122
145
|
:size => nil,
|
123
146
|
:character_spacing => nil }
|
124
147
|
end
|
125
148
|
it "should handle higher order characters properly" do
|
126
149
|
string = "<b>©\n©</b>"
|
127
|
-
array = Prawn::Text::Formatted::Parser.
|
150
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
128
151
|
array[0].should == { :text => "©",
|
129
152
|
:styles => [:bold],
|
130
153
|
:color => nil,
|
131
154
|
:link => nil,
|
132
155
|
:anchor => nil,
|
156
|
+
:local => nil,
|
133
157
|
:font => nil,
|
134
158
|
:size => nil,
|
135
159
|
:character_spacing => nil }
|
@@ -138,6 +162,7 @@ describe "Text::Formatted::Parser#to_array" do
|
|
138
162
|
:color => nil,
|
139
163
|
:link => nil,
|
140
164
|
:anchor => nil,
|
165
|
+
:local => nil,
|
141
166
|
:font => nil,
|
142
167
|
:size => nil,
|
143
168
|
:character_spacing => nil }
|
@@ -146,55 +171,60 @@ describe "Text::Formatted::Parser#to_array" do
|
|
146
171
|
:color => nil,
|
147
172
|
:link => nil,
|
148
173
|
:anchor => nil,
|
174
|
+
:local => nil,
|
149
175
|
:font => nil,
|
150
176
|
:size => nil,
|
151
177
|
:character_spacing => nil }
|
152
178
|
end
|
153
179
|
it "should convert < >, and & to <, >, and &, respectively" do
|
154
180
|
string = "hello <b><, >, and &</b>"
|
155
|
-
array = Prawn::Text::Formatted::Parser.
|
181
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
156
182
|
array[1].should == { :text => "<, >, and &",
|
157
183
|
:styles => [:bold],
|
158
184
|
:color => nil,
|
159
185
|
:link => nil,
|
160
186
|
:anchor => nil,
|
187
|
+
:local => nil,
|
161
188
|
:font => nil,
|
162
189
|
:size => nil,
|
163
190
|
:character_spacing => nil }
|
164
191
|
end
|
165
192
|
it "should handle double qoutes around tag attributes" do
|
166
193
|
string = 'some <font size="14">sized</font> text'
|
167
|
-
array = Prawn::Text::Formatted::Parser.
|
194
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
168
195
|
array[1].should == { :text => "sized",
|
169
196
|
:styles => [],
|
170
197
|
:color => nil,
|
171
198
|
:link => nil,
|
172
199
|
:anchor => nil,
|
200
|
+
:local => nil,
|
173
201
|
:font => nil,
|
174
202
|
:size => 14,
|
175
203
|
:character_spacing => nil }
|
176
204
|
end
|
177
205
|
it "should handle single qoutes around tag attributes" do
|
178
206
|
string = "some <font size='14'>sized</font> text"
|
179
|
-
array = Prawn::Text::Formatted::Parser.
|
207
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
180
208
|
array[1].should == { :text => "sized",
|
181
209
|
:styles => [],
|
182
210
|
:color => nil,
|
183
211
|
:link => nil,
|
184
212
|
:anchor => nil,
|
213
|
+
:local => nil,
|
185
214
|
:font => nil,
|
186
215
|
:size => 14,
|
187
216
|
:character_spacing => nil }
|
188
217
|
end
|
189
218
|
it "should construct a formatted text array from a string" do
|
190
219
|
string = "hello <b>world\nhow <i>are</i></b> you?"
|
191
|
-
array = Prawn::Text::Formatted::Parser.
|
220
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
192
221
|
|
193
222
|
array[0].should == { :text => "hello ",
|
194
223
|
:styles => [],
|
195
224
|
:color => nil,
|
196
225
|
:link => nil,
|
197
226
|
:anchor => nil,
|
227
|
+
:local => nil,
|
198
228
|
:font => nil,
|
199
229
|
:size => nil,
|
200
230
|
:character_spacing => nil }
|
@@ -203,6 +233,7 @@ describe "Text::Formatted::Parser#to_array" do
|
|
203
233
|
:color => nil,
|
204
234
|
:link => nil,
|
205
235
|
:anchor => nil,
|
236
|
+
:local => nil,
|
206
237
|
:font => nil,
|
207
238
|
:size => nil,
|
208
239
|
:character_spacing => nil }
|
@@ -211,6 +242,7 @@ describe "Text::Formatted::Parser#to_array" do
|
|
211
242
|
:color => nil,
|
212
243
|
:link => nil,
|
213
244
|
:anchor => nil,
|
245
|
+
:local => nil,
|
214
246
|
:font => nil,
|
215
247
|
:size => nil,
|
216
248
|
:character_spacing => nil }
|
@@ -219,6 +251,7 @@ describe "Text::Formatted::Parser#to_array" do
|
|
219
251
|
:color => nil,
|
220
252
|
:link => nil,
|
221
253
|
:anchor => nil,
|
254
|
+
:local => nil,
|
222
255
|
:font => nil,
|
223
256
|
:size => nil,
|
224
257
|
:character_spacing => nil }
|
@@ -227,6 +260,7 @@ describe "Text::Formatted::Parser#to_array" do
|
|
227
260
|
:color => nil,
|
228
261
|
:link => nil,
|
229
262
|
:anchor => nil,
|
263
|
+
:local => nil,
|
230
264
|
:font => nil,
|
231
265
|
:size => nil,
|
232
266
|
:character_spacing => nil }
|
@@ -235,19 +269,21 @@ describe "Text::Formatted::Parser#to_array" do
|
|
235
269
|
:color => nil,
|
236
270
|
:link => nil,
|
237
271
|
:anchor => nil,
|
272
|
+
:local => nil,
|
238
273
|
:font => nil,
|
239
274
|
:size => nil,
|
240
275
|
:character_spacing => nil }
|
241
276
|
end
|
242
277
|
it "should accept <strong> as an alternative to <b>" do
|
243
278
|
string = "<strong>bold</strong> not bold"
|
244
|
-
array = Prawn::Text::Formatted::Parser.
|
279
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
245
280
|
|
246
281
|
array[0].should == { :text => "bold",
|
247
282
|
:styles => [:bold],
|
248
283
|
:color => nil,
|
249
284
|
:link => nil,
|
250
285
|
:anchor => nil,
|
286
|
+
:local => nil,
|
251
287
|
:font => nil,
|
252
288
|
:size => nil,
|
253
289
|
:character_spacing => nil }
|
@@ -256,19 +292,21 @@ describe "Text::Formatted::Parser#to_array" do
|
|
256
292
|
:color => nil,
|
257
293
|
:link => nil,
|
258
294
|
:anchor => nil,
|
295
|
+
:local => nil,
|
259
296
|
:font => nil,
|
260
297
|
:size => nil,
|
261
298
|
:character_spacing => nil }
|
262
299
|
end
|
263
300
|
it "should accept <em> as an alternative to <i>" do
|
264
301
|
string = "<em>italic</em> not italic"
|
265
|
-
array = Prawn::Text::Formatted::Parser.
|
302
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
266
303
|
|
267
304
|
array[0].should == { :text => "italic",
|
268
305
|
:styles => [:italic],
|
269
306
|
:color => nil,
|
270
307
|
:link => nil,
|
271
308
|
:anchor => nil,
|
309
|
+
:local => nil,
|
272
310
|
:font => nil,
|
273
311
|
:size => nil,
|
274
312
|
:character_spacing => nil }
|
@@ -277,19 +315,21 @@ describe "Text::Formatted::Parser#to_array" do
|
|
277
315
|
:color => nil,
|
278
316
|
:link => nil,
|
279
317
|
:anchor => nil,
|
318
|
+
:local => nil,
|
280
319
|
:font => nil,
|
281
320
|
:size => nil,
|
282
321
|
:character_spacing => nil }
|
283
322
|
end
|
284
323
|
it "should accept <a> as an alternative to <link>" do
|
285
324
|
string = "<a href='http://example.com'>link</a> not a link"
|
286
|
-
array = Prawn::Text::Formatted::Parser.
|
325
|
+
array = Prawn::Text::Formatted::Parser.format(string)
|
287
326
|
|
288
327
|
array[0].should == { :text => "link",
|
289
328
|
:styles => [],
|
290
329
|
:color => nil,
|
291
330
|
:link => "http://example.com",
|
292
331
|
:anchor => nil,
|
332
|
+
:local => nil,
|
293
333
|
:font => nil,
|
294
334
|
:size => nil,
|
295
335
|
:character_spacing => nil }
|
@@ -298,13 +338,14 @@ describe "Text::Formatted::Parser#to_array" do
|
|
298
338
|
:color => nil,
|
299
339
|
:link => nil,
|
300
340
|
:anchor => nil,
|
341
|
+
:local => nil,
|
301
342
|
:font => nil,
|
302
343
|
:size => nil,
|
303
344
|
:character_spacing => nil }
|
304
345
|
end
|
305
346
|
|
306
347
|
it "should turn <br>, <br/> into newline" do
|
307
|
-
array = Prawn::Text::Formatted::Parser.
|
348
|
+
array = Prawn::Text::Formatted::Parser.format("hello<br>big<br/>world")
|
308
349
|
array.map { |frag| frag[:text] }.join.should == "hello\nbig\nworld"
|
309
350
|
end
|
310
351
|
end
|
@@ -318,6 +359,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
318
359
|
:color => nil,
|
319
360
|
:link => nil,
|
320
361
|
:anchor => nil,
|
362
|
+
:local => nil,
|
321
363
|
:font => nil,
|
322
364
|
:size => nil,
|
323
365
|
:character_spacing => nil }]
|
@@ -330,6 +372,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
330
372
|
:color => nil,
|
331
373
|
:link => nil,
|
332
374
|
:anchor => nil,
|
375
|
+
:local => nil,
|
333
376
|
:font => nil,
|
334
377
|
:size => nil,
|
335
378
|
:character_spacing => nil }]
|
@@ -342,6 +385,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
342
385
|
:color => "ff0000",
|
343
386
|
:link => nil,
|
344
387
|
:anchor => nil,
|
388
|
+
:local => nil,
|
345
389
|
:font => nil,
|
346
390
|
:size => nil,
|
347
391
|
:character_spacing => nil }]
|
@@ -354,6 +398,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
354
398
|
:color => [0, 100, 0, 0],
|
355
399
|
:link => nil,
|
356
400
|
:anchor => nil,
|
401
|
+
:local => nil,
|
357
402
|
:font => nil,
|
358
403
|
:size => nil,
|
359
404
|
:character_spacing => nil }]
|
@@ -366,6 +411,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
366
411
|
:color => nil,
|
367
412
|
:link => nil,
|
368
413
|
:anchor => nil,
|
414
|
+
:local => nil,
|
369
415
|
:font => "Courier",
|
370
416
|
:size => nil,
|
371
417
|
:character_spacing => nil }]
|
@@ -378,6 +424,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
378
424
|
:color => nil,
|
379
425
|
:link => nil,
|
380
426
|
:anchor => nil,
|
427
|
+
:local => nil,
|
381
428
|
:font => nil,
|
382
429
|
:size => 14,
|
383
430
|
:character_spacing => nil }]
|
@@ -390,6 +437,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
390
437
|
:color => nil,
|
391
438
|
:link => nil,
|
392
439
|
:anchor => nil,
|
440
|
+
:local => nil,
|
393
441
|
:font => nil,
|
394
442
|
:size => nil,
|
395
443
|
:character_spacing => 2.5 }]
|
@@ -401,6 +449,7 @@ describe "Text::Formatted::Parser#to_string" do
|
|
401
449
|
:color => nil,
|
402
450
|
:link => "http://example.com",
|
403
451
|
:anchor => nil,
|
452
|
+
:local => nil,
|
404
453
|
:font => nil,
|
405
454
|
:size => nil,
|
406
455
|
:character_spacing => nil }]
|