prawn 0.15.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/LICENSE +1 -1
- data/README.md +96 -0
- data/Rakefile +27 -30
- 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.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.alpha +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/data/pdfs/nested_pages.pdf +13 -13
- data/lib/prawn.rb +21 -85
- data/lib/prawn/compatibility.rb +51 -0
- data/lib/prawn/core.rb +85 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +78 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +264 -0
- data/lib/prawn/core/page.rb +215 -0
- data/lib/prawn/core/pdf_object.rb +108 -0
- data/lib/prawn/core/reference.rb +115 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +122 -155
- data/lib/prawn/document/bounding_box.rb +7 -36
- data/lib/prawn/document/column_box.rb +10 -38
- data/lib/prawn/document/graphics_state.rb +74 -11
- data/lib/prawn/document/internals.rb +23 -24
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +6 -7
- data/lib/prawn/document/span.rb +10 -12
- data/lib/prawn/encoding.rb +10 -9
- data/lib/prawn/errors.rb +30 -15
- data/lib/prawn/font.rb +104 -136
- data/lib/prawn/font/afm.rb +44 -46
- data/lib/prawn/font/dfont.rb +3 -4
- data/lib/prawn/font/ttf.rb +50 -31
- data/lib/prawn/graphics.rb +57 -302
- data/lib/prawn/graphics/cap_style.rb +3 -4
- data/lib/prawn/graphics/color.rb +5 -13
- data/lib/prawn/graphics/dash.rb +31 -53
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +7 -9
- data/lib/prawn/graphics/transformation.rb +9 -10
- data/lib/prawn/graphics/transparency.rb +1 -3
- data/lib/prawn/images.rb +59 -69
- data/lib/prawn/images/image.rb +22 -6
- data/lib/prawn/images/jpg.rb +14 -20
- data/lib/prawn/images/png.rb +118 -61
- data/lib/prawn/layout.rb +15 -10
- data/lib/prawn/layout/grid.rb +54 -66
- data/lib/prawn/measurement_extensions.rb +6 -10
- data/lib/prawn/measurements.rb +21 -27
- data/lib/prawn/outline.rb +308 -6
- data/lib/prawn/repeater.rb +8 -10
- data/lib/prawn/security.rb +33 -55
- data/lib/prawn/security/arcfour.rb +0 -1
- data/lib/prawn/stamp.rb +3 -5
- data/lib/prawn/table.rb +60 -188
- data/lib/prawn/table/cell.rb +44 -272
- data/lib/prawn/table/cell/image.rb +3 -2
- data/lib/prawn/table/cell/in_table.rb +2 -4
- data/lib/prawn/table/cell/subtable.rb +2 -2
- data/lib/prawn/table/cell/text.rb +18 -41
- data/lib/prawn/table/cells.rb +48 -142
- data/lib/prawn/text.rb +25 -32
- data/lib/prawn/text/box.rb +6 -12
- data/lib/prawn/text/formatted.rb +4 -5
- data/lib/prawn/text/formatted/box.rb +59 -96
- data/lib/prawn/text/formatted/fragment.rb +23 -34
- data/lib/prawn/text/formatted/parser.rb +5 -15
- data/prawn.gemspec +13 -24
- data/spec/annotations_spec.rb +32 -16
- data/spec/bounding_box_spec.rb +17 -119
- data/spec/cell_spec.rb +42 -112
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +111 -155
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_spec.rb +99 -149
- data/spec/formatted_text_arranger_spec.rb +43 -43
- data/spec/formatted_text_box_spec.rb +44 -43
- data/spec/formatted_text_fragment_spec.rb +8 -8
- data/spec/graphics_spec.rb +68 -151
- data/spec/grid_spec.rb +15 -26
- data/spec/images_spec.rb +30 -51
- data/spec/inline_formatted_text_parser_spec.rb +20 -69
- data/spec/jpg_spec.rb +4 -4
- data/spec/line_wrap_spec.rb +28 -28
- data/spec/measurement_units_spec.rb +6 -6
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +106 -17
- data/spec/outline_spec.rb +63 -103
- data/spec/pdf_object_spec.rb +170 -0
- data/spec/png_spec.rb +25 -25
- data/spec/reference_spec.rb +65 -8
- data/spec/repeater_spec.rb +10 -10
- data/spec/security_spec.rb +12 -44
- data/spec/snapshot_spec.rb +7 -7
- data/spec/span_spec.rb +15 -10
- data/spec/spec_helper.rb +8 -32
- data/spec/stamp_spec.rb +30 -29
- data/spec/stroke_styles_spec.rb +18 -36
- data/spec/table_spec.rb +111 -706
- data/spec/template_spec.rb +297 -0
- data/spec/text_at_spec.rb +33 -19
- data/spec/text_box_spec.rb +64 -100
- data/spec/text_rendering_mode_spec.rb +5 -5
- data/spec/text_spacing_spec.rb +4 -4
- data/spec/text_spec.rb +64 -84
- data/spec/transparency_spec.rb +5 -5
- metadata +290 -463
- checksums.yaml +0 -7
- data/.yardopts +0 -10
- data/Gemfile +0 -11
- data/data/images/16bit.color +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/page_white_text.color +0 -0
- data/lib/prawn/font_metric_cache.rb +0 -47
- data/lib/prawn/graphics/patterns.rb +0 -138
- data/lib/prawn/image_handler.rb +0 -36
- data/lib/prawn/soft_mask.rb +0 -96
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/column_width_calculator.rb +0 -61
- data/lib/prawn/text/formatted/arranger.rb +0 -290
- data/lib/prawn/text/formatted/line_wrap.rb +0 -266
- data/lib/prawn/text/formatted/wrap.rb +0 -150
- data/lib/prawn/utilities.rb +0 -46
- data/manual/basic_concepts/adding_pages.rb +0 -27
- data/manual/basic_concepts/basic_concepts.rb +0 -34
- data/manual/basic_concepts/creation.rb +0 -39
- data/manual/basic_concepts/cursor.rb +0 -33
- data/manual/basic_concepts/measurement.rb +0 -25
- data/manual/basic_concepts/origin.rb +0 -38
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
- data/manual/bounding_box/bounding_box.rb +0 -39
- data/manual/bounding_box/bounds.rb +0 -49
- data/manual/bounding_box/canvas.rb +0 -24
- data/manual/bounding_box/creation.rb +0 -23
- data/manual/bounding_box/indentation.rb +0 -46
- data/manual/bounding_box/nesting.rb +0 -45
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -31
- data/manual/document_and_page_options/background.rb +0 -27
- data/manual/document_and_page_options/document_and_page_options.rb +0 -32
- data/manual/document_and_page_options/metadata.rb +0 -23
- data/manual/document_and_page_options/page_margins.rb +0 -38
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -20
- data/manual/example_file.rb +0 -111
- data/manual/example_helper.rb +0 -411
- data/manual/example_package.rb +0 -53
- data/manual/example_section.rb +0 -46
- data/manual/graphics/circle_and_ellipse.rb +0 -22
- data/manual/graphics/color.rb +0 -24
- data/manual/graphics/common_lines.rb +0 -30
- data/manual/graphics/fill_and_stroke.rb +0 -42
- data/manual/graphics/fill_rules.rb +0 -37
- data/manual/graphics/gradients.rb +0 -37
- data/manual/graphics/graphics.rb +0 -58
- data/manual/graphics/helper.rb +0 -24
- data/manual/graphics/line_width.rb +0 -35
- data/manual/graphics/lines_and_curves.rb +0 -41
- data/manual/graphics/polygon.rb +0 -29
- data/manual/graphics/rectangle.rb +0 -21
- data/manual/graphics/rotate.rb +0 -28
- data/manual/graphics/scale.rb +0 -41
- data/manual/graphics/soft_masks.rb +0 -46
- data/manual/graphics/stroke_cap.rb +0 -31
- data/manual/graphics/stroke_dash.rb +0 -48
- data/manual/graphics/stroke_join.rb +0 -30
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -35
- data/manual/images/absolute_position.rb +0 -23
- data/manual/images/fit.rb +0 -21
- data/manual/images/horizontal.rb +0 -25
- data/manual/images/images.rb +0 -40
- data/manual/images/plain_image.rb +0 -18
- data/manual/images/scale.rb +0 -22
- data/manual/images/vertical.rb +0 -28
- data/manual/images/width_and_height.rb +0 -25
- data/manual/layout/boxes.rb +0 -27
- data/manual/layout/content.rb +0 -25
- data/manual/layout/layout.rb +0 -28
- data/manual/layout/simple_grid.rb +0 -23
- data/manual/manual/cover.rb +0 -36
- data/manual/manual/foreword.rb +0 -85
- data/manual/manual/how_to_read_this_manual.rb +0 -41
- data/manual/manual/manual.rb +0 -34
- data/manual/outline/add_subsection_to.rb +0 -61
- data/manual/outline/insert_section_after.rb +0 -47
- data/manual/outline/outline.rb +0 -32
- data/manual/outline/sections_and_pages.rb +0 -67
- data/manual/repeatable_content/page_numbering.rb +0 -54
- data/manual/repeatable_content/repeatable_content.rb +0 -31
- data/manual/repeatable_content/repeater.rb +0 -55
- data/manual/repeatable_content/stamp.rb +0 -41
- data/manual/security/encryption.rb +0 -31
- data/manual/security/permissions.rb +0 -38
- data/manual/security/security.rb +0 -28
- data/manual/syntax_highlight.rb +0 -52
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/manual/text/alignment.rb +0 -44
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -32
- data/manual/text/fallback_fonts.rb +0 -37
- data/manual/text/font.rb +0 -41
- data/manual/text/font_size.rb +0 -45
- data/manual/text/font_style.rb +0 -23
- data/manual/text/formatted_callbacks.rb +0 -60
- data/manual/text/formatted_text.rb +0 -54
- data/manual/text/free_flowing_text.rb +0 -51
- data/manual/text/group.rb +0 -31
- data/manual/text/inline.rb +0 -43
- data/manual/text/kerning_and_character_spacing.rb +0 -39
- data/manual/text/leading.rb +0 -25
- data/manual/text/line_wrapping.rb +0 -41
- data/manual/text/paragraph_indentation.rb +0 -26
- data/manual/text/positioned_text.rb +0 -38
- data/manual/text/registering_families.rb +0 -48
- data/manual/text/rendering_and_color.rb +0 -37
- data/manual/text/right_to_left_text.rb +0 -43
- data/manual/text/rotation.rb +0 -43
- data/manual/text/single_usage.rb +0 -37
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -32
- data/manual/text/text_box_extensions.rb +0 -45
- data/manual/text/text_box_overflow.rb +0 -44
- data/manual/text/utf8.rb +0 -28
- data/manual/text/win_ansi_charset.rb +0 -59
- data/spec/acceptance/png.rb +0 -23
- data/spec/column_box_spec.rb +0 -65
- data/spec/extensions/encoding_helpers.rb +0 -9
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/image_handler_spec.rb +0 -54
- data/spec/soft_mask_spec.rb +0 -117
- data/spec/table/span_dummy_spec.rb +0 -17
data/spec/images_spec.rb
CHANGED
@@ -1,48 +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::
|
10
|
+
@filename = "#{Prawn::BASEDIR}/data/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
|
-
|
29
|
-
info.should
|
30
|
-
|
28
|
+
|
29
|
+
info.should.be.kind_of(Prawn::Images::JPG)
|
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
|
-
|
38
|
-
info.height.should == 453
|
39
|
-
end
|
40
|
-
|
41
|
-
it "rewinds IO objects to be able to embed them multiply" do
|
42
|
-
file = File.open(@filename, "rb")
|
43
|
-
|
44
|
-
@pdf.image(file)
|
45
|
-
info = @pdf.image(file)
|
37
|
+
|
46
38
|
info.height.should == 453
|
47
39
|
end
|
48
40
|
|
@@ -51,64 +43,51 @@ describe "the image() function" do
|
|
51
43
|
info.height.should == 453
|
52
44
|
end
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
71
|
-
it "should raise_error an UnsupportedImageType if passed a BMP" do
|
72
|
-
filename = "#{Prawn::DATADIR}/images/tru256.bmp"
|
73
|
-
lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
|
46
|
+
it "should raise an UnsupportedImageType if passed a BMP" do
|
47
|
+
filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
|
48
|
+
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
|
74
49
|
end
|
75
50
|
|
76
|
-
it "should
|
77
|
-
filename = "#{Prawn::
|
78
|
-
lambda { @pdf.image filename, :at => [100,100] }.should
|
51
|
+
it "should raise an UnsupportedImageType if passed an interlaced PNG" do
|
52
|
+
filename = "#{Prawn::BASEDIR}/data/images/dice_interlaced.png"
|
53
|
+
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
|
79
54
|
end
|
80
55
|
|
81
56
|
it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
|
82
|
-
@pdf.image "#{Prawn::
|
57
|
+
@pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
|
83
58
|
@pdf.state.version.should >= 1.5
|
84
59
|
end
|
85
60
|
|
86
|
-
|
87
|
-
|
61
|
+
# to support Adobe Reader, which apparently doesn't handle 16-bit alpha
|
62
|
+
# channels. Verified experimentally [BE] but not confirmed in documentation
|
63
|
+
# or anything. OS X Preview handles those files just fine.
|
64
|
+
#
|
65
|
+
it "should embed 8-bit alpha channels for 16-bit PNGs" do
|
66
|
+
@pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
|
88
67
|
|
89
68
|
output = @pdf.render
|
90
69
|
output.should =~ /\/BitsPerComponent 16/
|
91
|
-
output.
|
70
|
+
output.should =~ /\/BitsPerComponent 8/
|
92
71
|
end
|
93
|
-
|
72
|
+
|
94
73
|
it "should flow an image to a new page if it will not fit on a page" do
|
95
74
|
@pdf.image @filename, :fit => [600, 600]
|
96
75
|
@pdf.image @filename, :fit => [600, 600]
|
97
76
|
output = StringIO.new(@pdf.render, 'r+')
|
98
77
|
hash = PDF::Reader::ObjectHash.new(output)
|
99
78
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
100
|
-
pages.size.should == 2
|
79
|
+
pages.size.should == 2
|
101
80
|
hash[pages[0]][:Resources][:XObject].keys.should == [:I1]
|
102
81
|
hash[pages[1]][:Resources][:XObject].keys.should == [:I2]
|
103
|
-
end
|
104
|
-
|
82
|
+
end
|
83
|
+
|
105
84
|
it "should not flow an image to a new page if it will fit on one page" do
|
106
85
|
@pdf.image @filename, :fit => [400, 400]
|
107
86
|
@pdf.image @filename, :fit => [400, 400]
|
108
87
|
output = StringIO.new(@pdf.render, 'r+')
|
109
88
|
hash = PDF::Reader::ObjectHash.new(output)
|
110
89
|
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
111
|
-
pages.size.should == 1
|
90
|
+
pages.size.should == 1
|
112
91
|
Set.new(hash[pages[0]][:Resources][:XObject].keys).should ==
|
113
92
|
Set.new([:I1, :I2])
|
114
93
|
end
|
@@ -119,7 +98,7 @@ describe "the image() function" do
|
|
119
98
|
@pdf.image @filename
|
120
99
|
end
|
121
100
|
end
|
122
|
-
|
101
|
+
|
123
102
|
describe ":fit option" do
|
124
103
|
it "should fit inside the defined constraints" do
|
125
104
|
info = @pdf.image @filename, :fit => [100,400]
|
@@ -1,159 +1,135 @@
|
|
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#to_array" 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.to_array(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,
|
14
13
|
:font => nil,
|
15
14
|
:size => nil,
|
16
15
|
:character_spacing => nil }
|
17
16
|
end
|
18
17
|
it "should handle sub" do
|
19
18
|
string = "<sub>subscript</sub>"
|
20
|
-
array = Prawn::Text::Formatted::Parser.
|
19
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
21
20
|
array[0].should == { :text => "subscript",
|
22
21
|
:styles => [:subscript],
|
23
22
|
:color => nil,
|
24
23
|
:link => nil,
|
25
24
|
:anchor => nil,
|
26
|
-
:local => nil,
|
27
25
|
:font => nil,
|
28
26
|
:size => nil,
|
29
27
|
:character_spacing => nil }
|
30
28
|
end
|
31
29
|
it "should handle rgb" do
|
32
30
|
string = "<color rgb='#ff0000'>red text</color>"
|
33
|
-
array = Prawn::Text::Formatted::Parser.
|
31
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
34
32
|
array[0].should == { :text => "red text",
|
35
33
|
:styles => [],
|
36
34
|
:color => "ff0000",
|
37
35
|
:link => nil,
|
38
36
|
:anchor => nil,
|
39
|
-
:local => nil,
|
40
37
|
:font => nil,
|
41
38
|
:size => nil,
|
42
39
|
:character_spacing => nil }
|
43
40
|
end
|
44
41
|
it "# should be optional in rgb" do
|
45
42
|
string = "<color rgb='ff0000'>red text</color>"
|
46
|
-
array = Prawn::Text::Formatted::Parser.
|
43
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
47
44
|
array[0].should == { :text => "red text",
|
48
45
|
:styles => [],
|
49
46
|
:color => "ff0000",
|
50
47
|
:link => nil,
|
51
48
|
:anchor => nil,
|
52
|
-
:local => nil,
|
53
49
|
:font => nil,
|
54
50
|
:size => nil,
|
55
51
|
:character_spacing => nil }
|
56
52
|
end
|
57
53
|
it "should handle cmyk" do
|
58
54
|
string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
|
59
|
-
array = Prawn::Text::Formatted::Parser.
|
55
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
60
56
|
array[0].should == { :text => "magenta text",
|
61
57
|
:styles => [],
|
62
58
|
:color => [0, 100, 0, 0],
|
63
59
|
:link => nil,
|
64
60
|
:anchor => nil,
|
65
|
-
:local => nil,
|
66
61
|
:font => nil,
|
67
62
|
:size => nil,
|
68
63
|
:character_spacing => nil }
|
69
64
|
end
|
70
65
|
it "should handle fonts" do
|
71
66
|
string = "<font name='Courier'>Courier text</font>"
|
72
|
-
array = Prawn::Text::Formatted::Parser.
|
67
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
73
68
|
array[0].should == { :text => "Courier text",
|
74
69
|
:styles => [],
|
75
70
|
:color => nil,
|
76
71
|
:link => nil,
|
77
72
|
:anchor => nil,
|
78
|
-
:local => nil,
|
79
73
|
:font => "Courier",
|
80
74
|
:size => nil,
|
81
75
|
:character_spacing => nil }
|
82
76
|
end
|
83
77
|
it "should handle size" do
|
84
78
|
string = "<font size='14'>14 point text</font>"
|
85
|
-
array = Prawn::Text::Formatted::Parser.
|
79
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
86
80
|
array[0].should == { :text => "14 point text",
|
87
81
|
:styles => [],
|
88
82
|
:color => nil,
|
89
83
|
:link => nil,
|
90
84
|
:anchor => nil,
|
91
|
-
:local => nil,
|
92
85
|
:font => nil,
|
93
86
|
:size => 14,
|
94
87
|
:character_spacing => nil }
|
95
88
|
end
|
96
89
|
it "should handle character_spacing" do
|
97
90
|
string = "<font character_spacing='2.5'>extra character spacing</font>"
|
98
|
-
array = Prawn::Text::Formatted::Parser.
|
91
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
99
92
|
array[0].should == { :text => "extra character spacing",
|
100
93
|
:styles => [],
|
101
94
|
:color => nil,
|
102
95
|
:link => nil,
|
103
96
|
:anchor => nil,
|
104
|
-
:local => nil,
|
105
97
|
:font => nil,
|
106
98
|
:size => nil,
|
107
99
|
:character_spacing => 2.5 }
|
108
100
|
end
|
109
101
|
it "should handle links" do
|
110
102
|
string = "<link href='http://example.com'>external link</link>"
|
111
|
-
array = Prawn::Text::Formatted::Parser.
|
103
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
112
104
|
array[0].should == { :text => "external link",
|
113
105
|
:styles => [],
|
114
106
|
:color => nil,
|
115
107
|
:link => "http://example.com",
|
116
108
|
: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",
|
131
109
|
:font => nil,
|
132
110
|
:size => nil,
|
133
111
|
:character_spacing => nil }
|
134
112
|
end
|
135
113
|
it "should handle anchors" do
|
136
114
|
string = "<link anchor='ToC'>internal link</link>"
|
137
|
-
array = Prawn::Text::Formatted::Parser.
|
115
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
138
116
|
array[0].should == { :text => "internal link",
|
139
117
|
:styles => [],
|
140
118
|
:color => nil,
|
141
119
|
:link => nil,
|
142
120
|
:anchor => "ToC",
|
143
|
-
:local => nil,
|
144
121
|
:font => nil,
|
145
122
|
:size => nil,
|
146
123
|
:character_spacing => nil }
|
147
124
|
end
|
148
125
|
it "should handle higher order characters properly" do
|
149
126
|
string = "<b>©\n©</b>"
|
150
|
-
array = Prawn::Text::Formatted::Parser.
|
127
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
151
128
|
array[0].should == { :text => "©",
|
152
129
|
:styles => [:bold],
|
153
130
|
:color => nil,
|
154
131
|
:link => nil,
|
155
132
|
:anchor => nil,
|
156
|
-
:local => nil,
|
157
133
|
:font => nil,
|
158
134
|
:size => nil,
|
159
135
|
:character_spacing => nil }
|
@@ -162,7 +138,6 @@ describe "Text::Formatted::Parser#format" do
|
|
162
138
|
:color => nil,
|
163
139
|
:link => nil,
|
164
140
|
:anchor => nil,
|
165
|
-
:local => nil,
|
166
141
|
:font => nil,
|
167
142
|
:size => nil,
|
168
143
|
:character_spacing => nil }
|
@@ -171,60 +146,55 @@ describe "Text::Formatted::Parser#format" do
|
|
171
146
|
:color => nil,
|
172
147
|
:link => nil,
|
173
148
|
:anchor => nil,
|
174
|
-
:local => nil,
|
175
149
|
:font => nil,
|
176
150
|
:size => nil,
|
177
151
|
:character_spacing => nil }
|
178
152
|
end
|
179
153
|
it "should convert < >, and & to <, >, and &, respectively" do
|
180
154
|
string = "hello <b><, >, and &</b>"
|
181
|
-
array = Prawn::Text::Formatted::Parser.
|
155
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
182
156
|
array[1].should == { :text => "<, >, and &",
|
183
157
|
:styles => [:bold],
|
184
158
|
:color => nil,
|
185
159
|
:link => nil,
|
186
160
|
:anchor => nil,
|
187
|
-
:local => nil,
|
188
161
|
:font => nil,
|
189
162
|
:size => nil,
|
190
163
|
:character_spacing => nil }
|
191
164
|
end
|
192
165
|
it "should handle double qoutes around tag attributes" do
|
193
166
|
string = 'some <font size="14">sized</font> text'
|
194
|
-
array = Prawn::Text::Formatted::Parser.
|
167
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
195
168
|
array[1].should == { :text => "sized",
|
196
169
|
:styles => [],
|
197
170
|
:color => nil,
|
198
171
|
:link => nil,
|
199
172
|
:anchor => nil,
|
200
|
-
:local => nil,
|
201
173
|
:font => nil,
|
202
174
|
:size => 14,
|
203
175
|
:character_spacing => nil }
|
204
176
|
end
|
205
177
|
it "should handle single qoutes around tag attributes" do
|
206
178
|
string = "some <font size='14'>sized</font> text"
|
207
|
-
array = Prawn::Text::Formatted::Parser.
|
179
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
208
180
|
array[1].should == { :text => "sized",
|
209
181
|
:styles => [],
|
210
182
|
:color => nil,
|
211
183
|
:link => nil,
|
212
184
|
:anchor => nil,
|
213
|
-
:local => nil,
|
214
185
|
:font => nil,
|
215
186
|
:size => 14,
|
216
187
|
:character_spacing => nil }
|
217
188
|
end
|
218
189
|
it "should construct a formatted text array from a string" do
|
219
190
|
string = "hello <b>world\nhow <i>are</i></b> you?"
|
220
|
-
array = Prawn::Text::Formatted::Parser.
|
191
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
221
192
|
|
222
193
|
array[0].should == { :text => "hello ",
|
223
194
|
:styles => [],
|
224
195
|
:color => nil,
|
225
196
|
:link => nil,
|
226
197
|
:anchor => nil,
|
227
|
-
:local => nil,
|
228
198
|
:font => nil,
|
229
199
|
:size => nil,
|
230
200
|
:character_spacing => nil }
|
@@ -233,7 +203,6 @@ describe "Text::Formatted::Parser#format" do
|
|
233
203
|
:color => nil,
|
234
204
|
:link => nil,
|
235
205
|
:anchor => nil,
|
236
|
-
:local => nil,
|
237
206
|
:font => nil,
|
238
207
|
:size => nil,
|
239
208
|
:character_spacing => nil }
|
@@ -242,7 +211,6 @@ describe "Text::Formatted::Parser#format" do
|
|
242
211
|
:color => nil,
|
243
212
|
:link => nil,
|
244
213
|
:anchor => nil,
|
245
|
-
:local => nil,
|
246
214
|
:font => nil,
|
247
215
|
:size => nil,
|
248
216
|
:character_spacing => nil }
|
@@ -251,7 +219,6 @@ describe "Text::Formatted::Parser#format" do
|
|
251
219
|
:color => nil,
|
252
220
|
:link => nil,
|
253
221
|
:anchor => nil,
|
254
|
-
:local => nil,
|
255
222
|
:font => nil,
|
256
223
|
:size => nil,
|
257
224
|
:character_spacing => nil }
|
@@ -260,7 +227,6 @@ describe "Text::Formatted::Parser#format" do
|
|
260
227
|
:color => nil,
|
261
228
|
:link => nil,
|
262
229
|
:anchor => nil,
|
263
|
-
:local => nil,
|
264
230
|
:font => nil,
|
265
231
|
:size => nil,
|
266
232
|
:character_spacing => nil }
|
@@ -269,21 +235,19 @@ describe "Text::Formatted::Parser#format" do
|
|
269
235
|
:color => nil,
|
270
236
|
:link => nil,
|
271
237
|
:anchor => nil,
|
272
|
-
:local => nil,
|
273
238
|
:font => nil,
|
274
239
|
:size => nil,
|
275
240
|
:character_spacing => nil }
|
276
241
|
end
|
277
242
|
it "should accept <strong> as an alternative to <b>" do
|
278
243
|
string = "<strong>bold</strong> not bold"
|
279
|
-
array = Prawn::Text::Formatted::Parser.
|
244
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
280
245
|
|
281
246
|
array[0].should == { :text => "bold",
|
282
247
|
:styles => [:bold],
|
283
248
|
:color => nil,
|
284
249
|
:link => nil,
|
285
250
|
:anchor => nil,
|
286
|
-
:local => nil,
|
287
251
|
:font => nil,
|
288
252
|
:size => nil,
|
289
253
|
:character_spacing => nil }
|
@@ -292,21 +256,19 @@ describe "Text::Formatted::Parser#format" do
|
|
292
256
|
:color => nil,
|
293
257
|
:link => nil,
|
294
258
|
:anchor => nil,
|
295
|
-
:local => nil,
|
296
259
|
:font => nil,
|
297
260
|
:size => nil,
|
298
261
|
:character_spacing => nil }
|
299
262
|
end
|
300
263
|
it "should accept <em> as an alternative to <i>" do
|
301
264
|
string = "<em>italic</em> not italic"
|
302
|
-
array = Prawn::Text::Formatted::Parser.
|
265
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
303
266
|
|
304
267
|
array[0].should == { :text => "italic",
|
305
268
|
:styles => [:italic],
|
306
269
|
:color => nil,
|
307
270
|
:link => nil,
|
308
271
|
:anchor => nil,
|
309
|
-
:local => nil,
|
310
272
|
:font => nil,
|
311
273
|
:size => nil,
|
312
274
|
:character_spacing => nil }
|
@@ -315,21 +277,19 @@ describe "Text::Formatted::Parser#format" do
|
|
315
277
|
:color => nil,
|
316
278
|
:link => nil,
|
317
279
|
:anchor => nil,
|
318
|
-
:local => nil,
|
319
280
|
:font => nil,
|
320
281
|
:size => nil,
|
321
282
|
:character_spacing => nil }
|
322
283
|
end
|
323
284
|
it "should accept <a> as an alternative to <link>" do
|
324
285
|
string = "<a href='http://example.com'>link</a> not a link"
|
325
|
-
array = Prawn::Text::Formatted::Parser.
|
286
|
+
array = Prawn::Text::Formatted::Parser.to_array(string)
|
326
287
|
|
327
288
|
array[0].should == { :text => "link",
|
328
289
|
:styles => [],
|
329
290
|
:color => nil,
|
330
291
|
:link => "http://example.com",
|
331
292
|
:anchor => nil,
|
332
|
-
:local => nil,
|
333
293
|
:font => nil,
|
334
294
|
:size => nil,
|
335
295
|
:character_spacing => nil }
|
@@ -338,14 +298,13 @@ describe "Text::Formatted::Parser#format" do
|
|
338
298
|
:color => nil,
|
339
299
|
:link => nil,
|
340
300
|
:anchor => nil,
|
341
|
-
:local => nil,
|
342
301
|
:font => nil,
|
343
302
|
:size => nil,
|
344
303
|
:character_spacing => nil }
|
345
304
|
end
|
346
305
|
|
347
306
|
it "should turn <br>, <br/> into newline" do
|
348
|
-
array = Prawn::Text::Formatted::Parser.
|
307
|
+
array = Prawn::Text::Formatted::Parser.to_array("hello<br>big<br/>world")
|
349
308
|
array.map { |frag| frag[:text] }.join.should == "hello\nbig\nworld"
|
350
309
|
end
|
351
310
|
end
|
@@ -359,7 +318,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
359
318
|
:color => nil,
|
360
319
|
:link => nil,
|
361
320
|
:anchor => nil,
|
362
|
-
:local => nil,
|
363
321
|
:font => nil,
|
364
322
|
:size => nil,
|
365
323
|
:character_spacing => nil }]
|
@@ -372,7 +330,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
372
330
|
:color => nil,
|
373
331
|
:link => nil,
|
374
332
|
:anchor => nil,
|
375
|
-
:local => nil,
|
376
333
|
:font => nil,
|
377
334
|
:size => nil,
|
378
335
|
:character_spacing => nil }]
|
@@ -385,7 +342,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
385
342
|
:color => "ff0000",
|
386
343
|
:link => nil,
|
387
344
|
:anchor => nil,
|
388
|
-
:local => nil,
|
389
345
|
:font => nil,
|
390
346
|
:size => nil,
|
391
347
|
:character_spacing => nil }]
|
@@ -398,7 +354,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
398
354
|
:color => [0, 100, 0, 0],
|
399
355
|
:link => nil,
|
400
356
|
:anchor => nil,
|
401
|
-
:local => nil,
|
402
357
|
:font => nil,
|
403
358
|
:size => nil,
|
404
359
|
:character_spacing => nil }]
|
@@ -411,7 +366,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
411
366
|
:color => nil,
|
412
367
|
:link => nil,
|
413
368
|
:anchor => nil,
|
414
|
-
:local => nil,
|
415
369
|
:font => "Courier",
|
416
370
|
:size => nil,
|
417
371
|
:character_spacing => nil }]
|
@@ -424,7 +378,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
424
378
|
:color => nil,
|
425
379
|
:link => nil,
|
426
380
|
:anchor => nil,
|
427
|
-
:local => nil,
|
428
381
|
:font => nil,
|
429
382
|
:size => 14,
|
430
383
|
:character_spacing => nil }]
|
@@ -437,7 +390,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
437
390
|
:color => nil,
|
438
391
|
:link => nil,
|
439
392
|
:anchor => nil,
|
440
|
-
:local => nil,
|
441
393
|
:font => nil,
|
442
394
|
:size => nil,
|
443
395
|
:character_spacing => 2.5 }]
|
@@ -449,7 +401,6 @@ describe "Text::Formatted::Parser#to_string" do
|
|
449
401
|
:color => nil,
|
450
402
|
:link => "http://example.com",
|
451
403
|
:anchor => nil,
|
452
|
-
:local => nil,
|
453
404
|
:font => nil,
|
454
405
|
:size => nil,
|
455
406
|
:character_spacing => nil }]
|