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
@@ -5,7 +5,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
5
5
|
describe "Core::Text::Formatted::Arranger#format_array" do
|
6
6
|
it "should populate unconsumed array" do
|
7
7
|
create_pdf
|
8
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
8
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
9
9
|
array = [{ :text => "hello " },
|
10
10
|
{ :text => "world how ", :styles => [:bold] },
|
11
11
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -20,7 +20,7 @@ describe "Core::Text::Formatted::Arranger#format_array" do
|
|
20
20
|
end
|
21
21
|
it "should split newlines into their own elements" do
|
22
22
|
create_pdf
|
23
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
23
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
24
24
|
array = [{ :text => "\nhello\nworld" }]
|
25
25
|
arranger.format_array = array
|
26
26
|
arranger.unconsumed[0].should == { :text => "\n" }
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
describe "Core::Text::Formatted::Arranger#preview_next_string" do
|
33
33
|
it "should not populate the consumed array" do
|
34
34
|
create_pdf
|
35
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
35
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
36
36
|
array = [{ :text => "hello" }]
|
37
37
|
arranger.format_array = array
|
38
38
|
arranger.preview_next_string
|
@@ -40,7 +40,7 @@ describe "Core::Text::Formatted::Arranger#preview_next_string" do
|
|
40
40
|
end
|
41
41
|
it "should not consumed array" do
|
42
42
|
create_pdf
|
43
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
43
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
44
44
|
array = [{ :text => "hello" }]
|
45
45
|
arranger.format_array = array
|
46
46
|
arranger.preview_next_string.should == "hello"
|
@@ -49,19 +49,19 @@ end
|
|
49
49
|
describe "Core::Text::Formatted::Arranger#next_string" do
|
50
50
|
before(:each) do
|
51
51
|
create_pdf
|
52
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
52
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
53
53
|
array = [{ :text => "hello " },
|
54
54
|
{ :text => "world how ", :styles => [:bold] },
|
55
55
|
{ :text => "are", :styles => [:bold, :italic] },
|
56
56
|
{ :text => " you?" }]
|
57
57
|
@arranger.format_array = array
|
58
58
|
end
|
59
|
-
it "should
|
59
|
+
it "should raise an error if called after a line was finalized and" +
|
60
60
|
" before a new line was initialized" do
|
61
61
|
@arranger.finalize_line
|
62
62
|
lambda do
|
63
63
|
@arranger.next_string
|
64
|
-
end.should
|
64
|
+
end.should.raise(RuntimeError)
|
65
65
|
end
|
66
66
|
it "should populate consumed array" do
|
67
67
|
while string = @arranger.next_string
|
@@ -75,7 +75,7 @@ describe "Core::Text::Formatted::Arranger#next_string" do
|
|
75
75
|
end
|
76
76
|
it "should populate current_format_state array" do
|
77
77
|
create_pdf
|
78
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
78
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
79
79
|
array = [{ :text => "hello " },
|
80
80
|
{ :text => "world how ", :styles => [:bold] },
|
81
81
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -99,9 +99,9 @@ describe "Core::Text::Formatted::Arranger#next_string" do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
102
|
-
it "should
|
102
|
+
it "should raise an error if called before finalize_line was called" do
|
103
103
|
create_pdf
|
104
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
104
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
105
105
|
array = [{ :text => "hello " },
|
106
106
|
{ :text => "world how ", :styles => [:bold] },
|
107
107
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -111,12 +111,12 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
111
111
|
end
|
112
112
|
lambda do
|
113
113
|
arranger.retrieve_fragment
|
114
|
-
end.should
|
114
|
+
end.should.raise(RuntimeError)
|
115
115
|
end
|
116
116
|
it "should return the consumed fragments in order of consumption" +
|
117
117
|
" and update" do
|
118
118
|
create_pdf
|
119
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
119
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
120
120
|
array = [{ :text => "hello " },
|
121
121
|
{ :text => "world how ", :styles => [:bold] },
|
122
122
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -132,7 +132,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
132
132
|
end
|
133
133
|
it "should never return a fragment whose text is an empty string" do
|
134
134
|
create_pdf
|
135
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
135
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
136
136
|
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
|
137
137
|
{ :text => "\n" },
|
138
138
|
{ :text => "\n" },
|
@@ -147,12 +147,12 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
147
147
|
end
|
148
148
|
arranger.finalize_line
|
149
149
|
while fragment = arranger.retrieve_fragment
|
150
|
-
fragment.text.
|
150
|
+
fragment.text.should.not.be.empty
|
151
151
|
end
|
152
152
|
end
|
153
153
|
it "should not alter the current font style" do
|
154
154
|
create_pdf
|
155
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
155
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
156
156
|
array = [{ :text => "hello " },
|
157
157
|
{ :text => "world how ", :styles => [:bold] },
|
158
158
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -162,7 +162,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
162
162
|
end
|
163
163
|
arranger.finalize_line
|
164
164
|
arranger.retrieve_fragment
|
165
|
-
arranger.current_format_state[:styles].should
|
165
|
+
arranger.current_format_state[:styles].should.be.nil
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -170,7 +170,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
170
170
|
it "should update the last retrieved string with what actually fit on" +
|
171
171
|
"the line and the list of unconsumed with what did not" do
|
172
172
|
create_pdf
|
173
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
173
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
174
174
|
array = [{ :text => "hello " },
|
175
175
|
{ :text => "world how ", :styles => [:bold] },
|
176
176
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -186,7 +186,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
186
186
|
end
|
187
187
|
it "should set the format state to the previously processed fragment" do
|
188
188
|
create_pdf
|
189
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
189
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
190
190
|
array = [{ :text => "hello " },
|
191
191
|
{ :text => "world how ", :styles => [:bold] },
|
192
192
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -201,7 +201,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
201
201
|
context "when the entire string was used" do
|
202
202
|
it "should not push empty string onto unconsumed" do
|
203
203
|
create_pdf
|
204
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
204
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
205
205
|
array = [{ :text => "hello " },
|
206
206
|
{ :text => "world how ", :styles => [:bold] },
|
207
207
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -217,7 +217,7 @@ end
|
|
217
217
|
describe "Core::Text::Formatted::Arranger#space_count" do
|
218
218
|
before(:each) do
|
219
219
|
create_pdf
|
220
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
220
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
221
221
|
array = [{ :text => "hello " },
|
222
222
|
{ :text => "world how ", :styles => [:bold] },
|
223
223
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -226,10 +226,10 @@ describe "Core::Text::Formatted::Arranger#space_count" do
|
|
226
226
|
while string = @arranger.next_string
|
227
227
|
end
|
228
228
|
end
|
229
|
-
it "should
|
229
|
+
it "should raise an error if called before finalize_line was called" do
|
230
230
|
lambda do
|
231
231
|
@arranger.space_count
|
232
|
-
end.should
|
232
|
+
end.should.raise(RuntimeError)
|
233
233
|
end
|
234
234
|
it "should return the total number of spaces in all fragments" do
|
235
235
|
@arranger.finalize_line
|
@@ -240,7 +240,7 @@ describe "Core::Text::Formatted::Arranger#finalize_line" do
|
|
240
240
|
it "should make it so that all trailing white space fragments " +
|
241
241
|
"exclude trailing white space" do
|
242
242
|
create_pdf
|
243
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
243
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
244
244
|
array = [{ :text => "hello " },
|
245
245
|
{ :text => "world how ", :styles => [:bold] },
|
246
246
|
{ :text => " ", :styles => [:bold, :italic] }]
|
@@ -264,28 +264,28 @@ end
|
|
264
264
|
describe "Core::Text::Formatted::Arranger#line_width" do
|
265
265
|
before(:each) do
|
266
266
|
create_pdf
|
267
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
267
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
268
268
|
array = [{ :text => "hello " },
|
269
269
|
{ :text => "world", :styles => [:bold] }]
|
270
270
|
@arranger.format_array = array
|
271
271
|
while string = @arranger.next_string
|
272
272
|
end
|
273
273
|
end
|
274
|
-
it "should
|
274
|
+
it "should raise an error if called before finalize_line was called" do
|
275
275
|
lambda do
|
276
276
|
@arranger.line_width
|
277
|
-
end.should
|
277
|
+
end.should.raise(RuntimeError)
|
278
278
|
end
|
279
279
|
it "should return the width of the complete line" do
|
280
280
|
@arranger.finalize_line
|
281
|
-
@arranger.line_width.should
|
281
|
+
@arranger.line_width.should.be > 0
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
285
285
|
describe "Core::Text::Formatted::Arranger#line_width with character_spacing > 0" do
|
286
286
|
it "should return a width greater than a line without a character_spacing" do
|
287
287
|
create_pdf
|
288
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
288
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
289
289
|
|
290
290
|
array = [{ :text => "hello " },
|
291
291
|
{ :text => "world", :styles => [:bold] }]
|
@@ -304,24 +304,24 @@ describe "Core::Text::Formatted::Arranger#line_width with character_spacing > 0"
|
|
304
304
|
while string = arranger.next_string
|
305
305
|
end
|
306
306
|
arranger.finalize_line
|
307
|
-
arranger.line_width.should
|
307
|
+
arranger.line_width.should.be > base_line_width
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
311
311
|
describe "Core::Text::Formatted::Arranger#line" do
|
312
312
|
before(:each) do
|
313
313
|
create_pdf
|
314
|
-
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
314
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
315
315
|
array = [{ :text => "hello " },
|
316
316
|
{ :text => "world", :styles => [:bold] }]
|
317
317
|
@arranger.format_array = array
|
318
318
|
while string = @arranger.next_string
|
319
319
|
end
|
320
320
|
end
|
321
|
-
it "should
|
321
|
+
it "should raise an error if called before finalize_line was called" do
|
322
322
|
lambda do
|
323
323
|
@arranger.line
|
324
|
-
end.should
|
324
|
+
end.should.raise(RuntimeError)
|
325
325
|
end
|
326
326
|
it "should return the complete line" do
|
327
327
|
@arranger.finalize_line
|
@@ -332,7 +332,7 @@ end
|
|
332
332
|
describe "Core::Text::Formatted::Arranger#unconsumed" do
|
333
333
|
it "should return the original array if nothing was consumed" do
|
334
334
|
create_pdf
|
335
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
335
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
336
336
|
array = [{ :text => "hello " },
|
337
337
|
{ :text => "world how ", :styles => [:bold] },
|
338
338
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -342,7 +342,7 @@ describe "Core::Text::Formatted::Arranger#unconsumed" do
|
|
342
342
|
end
|
343
343
|
it "should return an empty array if everything was consumed" do
|
344
344
|
create_pdf
|
345
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
345
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
346
346
|
array = [{ :text => "hello " },
|
347
347
|
{ :text => "world how ", :styles => [:bold] },
|
348
348
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -355,9 +355,9 @@ describe "Core::Text::Formatted::Arranger#unconsumed" do
|
|
355
355
|
end
|
356
356
|
|
357
357
|
describe "Core::Text::Formatted::Arranger#finished" do
|
358
|
-
it "should
|
358
|
+
it "should be false if anything was not printed" do
|
359
359
|
create_pdf
|
360
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
360
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
361
361
|
array = [{ :text => "hello " },
|
362
362
|
{ :text => "world how ", :styles => [:bold] },
|
363
363
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -366,11 +366,11 @@ describe "Core::Text::Formatted::Arranger#finished" do
|
|
366
366
|
while string = arranger.next_string
|
367
367
|
end
|
368
368
|
arranger.update_last_string(" you", "now?", nil)
|
369
|
-
arranger.
|
369
|
+
arranger.should.not.be.finished
|
370
370
|
end
|
371
|
-
it "should
|
371
|
+
it "should be false if everything was printed" do
|
372
372
|
create_pdf
|
373
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
373
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
374
374
|
array = [{ :text => "hello " },
|
375
375
|
{ :text => "world how ", :styles => [:bold] },
|
376
376
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -378,14 +378,14 @@ describe "Core::Text::Formatted::Arranger#finished" do
|
|
378
378
|
arranger.format_array = array
|
379
379
|
while string = arranger.next_string
|
380
380
|
end
|
381
|
-
arranger.should
|
381
|
+
arranger.should.be.finished
|
382
382
|
end
|
383
383
|
end
|
384
384
|
|
385
385
|
describe "Core::Text::Formatted::Arranger.max_line_height" do
|
386
386
|
it "should be the height of the maximum consumed fragment" do
|
387
387
|
create_pdf
|
388
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
388
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
389
389
|
array = [{ :text => "hello " },
|
390
390
|
{ :text => "world how ", :styles => [:bold] },
|
391
391
|
{ :text => "are", :styles => [:bold, :italic],
|
@@ -395,14 +395,14 @@ describe "Core::Text::Formatted::Arranger.max_line_height" do
|
|
395
395
|
while string = arranger.next_string
|
396
396
|
end
|
397
397
|
arranger.finalize_line
|
398
|
-
arranger.max_line_height.should
|
398
|
+
arranger.max_line_height.should.be.close(33.32, 0.0001)
|
399
399
|
end
|
400
400
|
end
|
401
401
|
|
402
402
|
describe "Core::Text::Formatted::Arranger#repack_unretrieved" do
|
403
403
|
it "should restore part of the original string" do
|
404
404
|
create_pdf
|
405
|
-
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
405
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
406
406
|
array = [{ :text => "hello " },
|
407
407
|
{ :text => "world how ", :styles => [:bold] },
|
408
408
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -18,19 +18,22 @@ describe "Text::Formatted::Box wrapping" do
|
|
18
18
|
text_box.text.should == "Hello\nWorld2"
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should not raise
|
21
|
+
it "should not raise Encoding::CompatibilityError when keeping a TTF and an " +
|
22
22
|
"AFM font together" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
ruby_19 do
|
24
|
+
file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
25
|
+
@pdf.font_families["Kai"] = {
|
26
|
+
:normal => { :file => file, :font => "Kai" }
|
27
|
+
}
|
28
|
+
|
29
|
+
texts = [{ :text => "Hello " },
|
30
|
+
{ :text => "再见", :font => "Kai"},
|
31
|
+
{ :text => "World" }]
|
32
|
+
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
|
33
|
+
lambda {
|
34
|
+
text_box.render
|
35
|
+
}.should.not.raise(Encoding::CompatibilityError)
|
36
|
+
end
|
34
37
|
end
|
35
38
|
|
36
39
|
it "should wrap between two fragments when the preceding fragment ends with white space" do
|
@@ -76,30 +79,39 @@ describe "Text::Formatted::Box wrapping" do
|
|
76
79
|
it "should properly handle empty slices using default encoding" do
|
77
80
|
texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
|
78
81
|
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
|
79
|
-
|
82
|
+
assert_nothing_raised do
|
80
83
|
text_box.render
|
81
|
-
|
84
|
+
end
|
82
85
|
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
|
83
86
|
end
|
84
|
-
|
87
|
+
|
85
88
|
describe "Unicode" do
|
86
89
|
before do
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
if RUBY_VERSION < '1.9'
|
91
|
+
@reset_value = $KCODE
|
92
|
+
$KCODE='u'
|
93
|
+
else
|
94
|
+
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
95
|
+
Encoding.default_external = Encoding::UTF_8
|
96
|
+
Encoding.default_internal = Encoding::UTF_8
|
97
|
+
end
|
90
98
|
end
|
91
|
-
|
99
|
+
|
92
100
|
after do
|
93
|
-
|
94
|
-
|
101
|
+
if RUBY_VERSION < '1.9'
|
102
|
+
$KCODE=@reset_value
|
103
|
+
else
|
104
|
+
Encoding.default_external = @reset_value[0]
|
105
|
+
Encoding.default_internal = @reset_value[1]
|
106
|
+
end
|
95
107
|
end
|
96
108
|
|
97
109
|
it "should properly handle empty slices using Unicode encoding" do
|
98
110
|
texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
|
99
111
|
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
|
100
|
-
|
112
|
+
assert_nothing_raised do
|
101
113
|
text_box.render
|
102
|
-
|
114
|
+
end
|
103
115
|
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
|
104
116
|
end
|
105
117
|
end
|
@@ -109,7 +121,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
|
|
109
121
|
"a Chinese font and set of Chinese glyphs not in the current font" do
|
110
122
|
it "should change the font to the Chinese font for the Chinese glyphs" do
|
111
123
|
create_pdf
|
112
|
-
file = "#{Prawn::
|
124
|
+
file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
113
125
|
@pdf.font_families["Kai"] = {
|
114
126
|
:normal => { :file => file, :font => "Kai" }
|
115
127
|
}
|
@@ -137,7 +149,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
|
|
137
149
|
"an AFM font and Win-Ansi glyph not in the current Chinese font" do
|
138
150
|
it "should change the font to the AFM font for the Win-Ansi glyph" do
|
139
151
|
create_pdf
|
140
|
-
file = "#{Prawn::
|
152
|
+
file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
141
153
|
@pdf.font_families["Kai"] = {
|
142
154
|
:normal => { :file => file, :font => "Kai" }
|
143
155
|
}
|
@@ -166,7 +178,7 @@ describe "Text::Formatted::Box with :fallback_fonts option and fragment " +
|
|
166
178
|
"level font" do
|
167
179
|
it "should use the fragment level font except for glyphs not in that font" do
|
168
180
|
create_pdf
|
169
|
-
file = "#{Prawn::
|
181
|
+
file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
170
182
|
@pdf.font_families["Kai"] = {
|
171
183
|
:normal => { :file => file, :font => "Kai" }
|
172
184
|
}
|
@@ -193,7 +205,7 @@ end
|
|
193
205
|
describe "Text::Formatted::Box" do
|
194
206
|
before(:each) do
|
195
207
|
create_pdf
|
196
|
-
file = "#{Prawn::
|
208
|
+
file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
197
209
|
@pdf.font_families["Kai"] = {
|
198
210
|
:normal => { :file => file, :font => "Kai" }
|
199
211
|
}
|
@@ -385,8 +397,7 @@ describe "Text::Formatted::Box#render" do
|
|
385
397
|
{ :text => "callback now",
|
386
398
|
:callback => [behind, in_front] }]
|
387
399
|
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
388
|
-
|
389
|
-
text_box.render # trigger callbacks
|
400
|
+
lambda { text_box.render }.should.not.raise(NoMethodError)
|
390
401
|
end
|
391
402
|
it "should be able to set the font" do
|
392
403
|
create_pdf
|
@@ -438,7 +449,7 @@ describe "Text::Formatted::Box#render" do
|
|
438
449
|
text_box.render
|
439
450
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
440
451
|
contents.font_settings[0][:size].should == 12
|
441
|
-
contents.font_settings[1][:size].should
|
452
|
+
contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
|
442
453
|
end
|
443
454
|
it "should be able to set superscript" do
|
444
455
|
create_pdf
|
@@ -449,7 +460,7 @@ describe "Text::Formatted::Box#render" do
|
|
449
460
|
text_box.render
|
450
461
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
451
462
|
contents.font_settings[0][:size].should == 12
|
452
|
-
contents.font_settings[1][:size].should
|
463
|
+
contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
|
453
464
|
end
|
454
465
|
it "should be able to set compound bold and italic text" do
|
455
466
|
create_pdf
|
@@ -501,16 +512,6 @@ describe "Text::Formatted::Box#render" do
|
|
501
512
|
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
502
513
|
text_box.render
|
503
514
|
end
|
504
|
-
it "should be able to add local actions" do
|
505
|
-
create_pdf
|
506
|
-
@pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
|
507
|
-
:A => { :Type => :Action, :S => :Launch, :F => "../example.pdf", :NewWindow => true })
|
508
|
-
array = [{ :text => "click " },
|
509
|
-
{ :text => "here", :local => "../example.pdf" },
|
510
|
-
{ :text => " to open a local file" }]
|
511
|
-
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
512
|
-
text_box.render
|
513
|
-
end
|
514
515
|
it "should be able to set font size" do
|
515
516
|
create_pdf
|
516
517
|
array = [{ :text => "this contains " },
|
@@ -530,7 +531,7 @@ describe "Text::Formatted::Box#render" do
|
|
530
531
|
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
531
532
|
text_box.render
|
532
533
|
@pdf.font_size(24) do
|
533
|
-
text_box.height.should
|
534
|
+
text_box.height.should.be.close(@pdf.font.ascender + @pdf.font.descender, 0.001)
|
534
535
|
end
|
535
536
|
end
|
536
537
|
it "should be able to set color via an rgb hex string" do
|
@@ -590,7 +591,7 @@ describe "Text::Formatted::Box#render with :align => :justify" do
|
|
590
591
|
text_box = Prawn::Text::Formatted::Box.new(array, options)
|
591
592
|
text_box.render
|
592
593
|
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
593
|
-
contents.word_spacing.should
|
594
|
+
contents.word_spacing.should.be.empty
|
594
595
|
end
|
595
596
|
end
|
596
597
|
|