piglop-prawn 0.10.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/HACKING +49 -0
- data/LICENSE +56 -0
- data/README +140 -0
- data/Rakefile +52 -0
- data/data/encodings/win_ansi.txt +29 -0
- 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/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -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/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/examples/bounding_box/bounding_boxes.rb +43 -0
- data/examples/bounding_box/indentation.rb +34 -0
- data/examples/bounding_box/russian_boxes.rb +36 -0
- data/examples/bounding_box/stretched_nesting.rb +67 -0
- data/examples/example_helper.rb +4 -0
- data/examples/general/background.rb +23 -0
- data/examples/general/canvas.rb +15 -0
- data/examples/general/context_sensitive_headers.rb +37 -0
- data/examples/general/float.rb +11 -0
- data/examples/general/margin.rb +36 -0
- data/examples/general/measurement_units.rb +51 -0
- data/examples/general/metadata-info.rb +16 -0
- data/examples/general/multi_page_layout.rb +18 -0
- data/examples/general/outlines.rb +50 -0
- data/examples/general/page_geometry.rb +31 -0
- data/examples/general/page_numbering.rb +15 -0
- data/examples/general/repeaters.rb +47 -0
- data/examples/general/stamp.rb +41 -0
- data/examples/general/templates.rb +13 -0
- data/examples/graphics/basic_images.rb +23 -0
- data/examples/graphics/cmyk.rb +12 -0
- data/examples/graphics/curves.rb +11 -0
- data/examples/graphics/hexagon.rb +13 -0
- data/examples/graphics/image_fit.rb +15 -0
- data/examples/graphics/image_flow.rb +37 -0
- data/examples/graphics/image_position.rb +17 -0
- data/examples/graphics/line.rb +32 -0
- data/examples/graphics/png_types.rb +22 -0
- data/examples/graphics/polygons.rb +16 -0
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/graphics/rounded_polygons.rb +19 -0
- data/examples/graphics/rounded_rectangle.rb +20 -0
- data/examples/graphics/ruport_style_helpers.rb +19 -0
- data/examples/graphics/stroke_bounds.rb +20 -0
- data/examples/graphics/stroke_cap_and_join.rb +45 -0
- data/examples/graphics/stroke_dash.rb +42 -0
- data/examples/graphics/transformations.rb +52 -0
- data/examples/graphics/transparency.rb +26 -0
- data/examples/m17n/chinese_text_wrapping.rb +17 -0
- data/examples/m17n/euro.rb +15 -0
- data/examples/m17n/sjis.rb +28 -0
- data/examples/m17n/utf8.rb +13 -0
- data/examples/m17n/win_ansi_charset.rb +54 -0
- data/examples/security/hello_foo.rb +8 -0
- data/examples/table/bill.rb +53 -0
- data/examples/table/cell.rb +12 -0
- data/examples/table/checkerboard.rb +22 -0
- data/examples/table/header.rb +14 -0
- data/examples/table/inline_format_table.rb +12 -0
- data/examples/table/multi_page_table.rb +9 -0
- data/examples/table/simple_table.rb +24 -0
- data/examples/table/subtable.rb +12 -0
- data/examples/table/widths.rb +20 -0
- data/examples/text/alignment.rb +18 -0
- data/examples/text/dfont.rb +48 -0
- data/examples/text/family_based_styling.rb +24 -0
- data/examples/text/font_calculations.rb +91 -0
- data/examples/text/font_size.rb +33 -0
- data/examples/text/hyphenation.rb +45 -0
- data/examples/text/indent_paragraphs.rb +18 -0
- data/examples/text/inline_format.rb +72 -0
- data/examples/text/kerning.rb +30 -0
- data/examples/text/rotated.rb +98 -0
- data/examples/text/shaped_text_box.rb +31 -0
- data/examples/text/simple_text.rb +17 -0
- data/examples/text/simple_text_ttf.rb +17 -0
- data/examples/text/text_box.rb +88 -0
- data/examples/text/text_box_returning_excess.rb +51 -0
- data/examples/text/text_flow.rb +67 -0
- data/lib/prawn/compatibility.rb +51 -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 +84 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +165 -0
- data/lib/prawn/core/object_store.rb +219 -0
- data/lib/prawn/core/page.rb +179 -0
- data/lib/prawn/core/pdf_object.rb +83 -0
- data/lib/prawn/core/reference.rb +112 -0
- data/lib/prawn/core/text/formatted/arranger.rb +260 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +127 -0
- data/lib/prawn/core/text/formatted/wrap.rb +113 -0
- data/lib/prawn/core/text/line_wrap.rb +198 -0
- data/lib/prawn/core/text/wrap.rb +80 -0
- data/lib/prawn/core/text.rb +115 -0
- data/lib/prawn/core.rb +89 -0
- data/lib/prawn/document/bounding_box.rb +425 -0
- data/lib/prawn/document/graphics_state.rb +48 -0
- data/lib/prawn/document/internals.rb +176 -0
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +87 -0
- data/lib/prawn/document.rb +573 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +94 -0
- data/lib/prawn/font/afm.rb +225 -0
- data/lib/prawn/font/dfont.rb +42 -0
- data/lib/prawn/font/ttf.rb +350 -0
- data/lib/prawn/font.rb +342 -0
- data/lib/prawn/graphics/cap_style.rb +38 -0
- data/lib/prawn/graphics/color.rb +205 -0
- data/lib/prawn/graphics/dash.rb +71 -0
- data/lib/prawn/graphics/join_style.rb +38 -0
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +99 -0
- data/lib/prawn/graphics.rb +321 -0
- data/lib/prawn/images/jpg.rb +46 -0
- data/lib/prawn/images/png.rb +226 -0
- data/lib/prawn/images.rb +348 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/outline.rb +278 -0
- data/lib/prawn/repeater.rb +129 -0
- data/lib/prawn/security/arcfour.rb +51 -0
- data/lib/prawn/security.rb +262 -0
- data/lib/prawn/stamp.rb +126 -0
- data/lib/prawn/table/accessors.rb +180 -0
- data/lib/prawn/table/cell/in_table.rb +27 -0
- data/lib/prawn/table/cell/subtable.rb +65 -0
- data/lib/prawn/table/cell/text.rb +128 -0
- data/lib/prawn/table/cell.rb +330 -0
- data/lib/prawn/table.rb +421 -0
- data/lib/prawn/text/box.rb +380 -0
- data/lib/prawn/text/formatted/box.rb +215 -0
- data/lib/prawn/text/formatted/fragment.rb +127 -0
- data/lib/prawn/text/formatted/parser.rb +202 -0
- data/lib/prawn/text/formatted.rb +4 -0
- data/lib/prawn/text.rb +442 -0
- data/lib/prawn.rb +25 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +190 -0
- data/spec/cell_spec.rb +337 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +461 -0
- data/spec/font_spec.rb +314 -0
- data/spec/formatted_text_arranger_spec.rb +400 -0
- data/spec/formatted_text_box_spec.rb +659 -0
- data/spec/formatted_text_fragment_spec.rb +211 -0
- data/spec/graphics_spec.rb +446 -0
- data/spec/images_spec.rb +96 -0
- data/spec/inline_formatted_text_parser_spec.rb +446 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +341 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +160 -0
- data/spec/outline_spec.rb +229 -0
- data/spec/pdf_object_spec.rb +127 -0
- data/spec/png_spec.rb +237 -0
- data/spec/reference_spec.rb +82 -0
- data/spec/repeater_spec.rb +96 -0
- data/spec/security_spec.rb +120 -0
- data/spec/snapshot_spec.rb +138 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/stamp_spec.rb +108 -0
- data/spec/stroke_styles_spec.rb +163 -0
- data/spec/table_spec.rb +583 -0
- data/spec/template_spec.rb +158 -0
- data/spec/text_at_spec.rb +119 -0
- data/spec/text_box_spec.rb +675 -0
- data/spec/text_spacing_spec.rb +57 -0
- data/spec/text_spec.rb +328 -0
- data/spec/text_with_inline_formatting_spec.rb +193 -0
- data/spec/transparency_spec.rb +75 -0
- data/vendor/pdf-inspector/README +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +46 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +45 -0
- data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +50 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +55 -0
- data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +125 -0
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk.rb +102 -0
- metadata +364 -0
@@ -0,0 +1,400 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "Core::Text::Formatted::Arranger#format_array" do
|
6
|
+
it "should populate unconsumed array" do
|
7
|
+
create_pdf
|
8
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
9
|
+
array = [{ :text => "hello " },
|
10
|
+
{ :text => "world how ", :styles => [:bold] },
|
11
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
12
|
+
{ :text => " you?" }]
|
13
|
+
arranger.format_array = array
|
14
|
+
arranger.unconsumed[0].should == { :text => "hello " }
|
15
|
+
arranger.unconsumed[1].should == { :text => "world how ",
|
16
|
+
:styles => [:bold] }
|
17
|
+
arranger.unconsumed[2].should == { :text => "are",
|
18
|
+
:styles => [:bold, :italic] }
|
19
|
+
arranger.unconsumed[3].should == { :text => " you?" }
|
20
|
+
end
|
21
|
+
it "should split newlines into their own elements" do
|
22
|
+
create_pdf
|
23
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
24
|
+
array = [{ :text => "\nhello\nworld" }]
|
25
|
+
arranger.format_array = array
|
26
|
+
arranger.unconsumed[0].should == { :text => "\n" }
|
27
|
+
arranger.unconsumed[1].should == { :text => "hello" }
|
28
|
+
arranger.unconsumed[2].should == { :text => "\n" }
|
29
|
+
arranger.unconsumed[3].should == { :text => "world" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe "Core::Text::Formatted::Arranger#preview_next_string" do
|
33
|
+
it "should not populate the consumed array" do
|
34
|
+
create_pdf
|
35
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
36
|
+
array = [{ :text => "hello" }]
|
37
|
+
arranger.format_array = array
|
38
|
+
arranger.preview_next_string
|
39
|
+
arranger.consumed.should == []
|
40
|
+
end
|
41
|
+
it "should not consumed array" do
|
42
|
+
create_pdf
|
43
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
44
|
+
array = [{ :text => "hello" }]
|
45
|
+
arranger.format_array = array
|
46
|
+
arranger.preview_next_string.should == "hello"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
describe "Core::Text::Formatted::Arranger#next_string" do
|
50
|
+
before(:each) do
|
51
|
+
create_pdf
|
52
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
53
|
+
array = [{ :text => "hello " },
|
54
|
+
{ :text => "world how ", :styles => [:bold] },
|
55
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
56
|
+
{ :text => " you?" }]
|
57
|
+
@arranger.format_array = array
|
58
|
+
end
|
59
|
+
it "should raise an error if called after a line was finalized and" +
|
60
|
+
" before a new line was initialized" do
|
61
|
+
@arranger.finalize_line
|
62
|
+
lambda do
|
63
|
+
@arranger.next_string
|
64
|
+
end.should.raise(RuntimeError)
|
65
|
+
end
|
66
|
+
it "should populate consumed array" do
|
67
|
+
while string = @arranger.next_string
|
68
|
+
end
|
69
|
+
@arranger.consumed[0].should == { :text => "hello " }
|
70
|
+
@arranger.consumed[1].should == { :text => "world how ",
|
71
|
+
:styles => [:bold] }
|
72
|
+
@arranger.consumed[2].should == { :text => "are",
|
73
|
+
:styles => [:bold, :italic] }
|
74
|
+
@arranger.consumed[3].should == { :text => " you?" }
|
75
|
+
end
|
76
|
+
it "should populate current_format_state array" do
|
77
|
+
create_pdf
|
78
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
79
|
+
array = [{ :text => "hello " },
|
80
|
+
{ :text => "world how ", :styles => [:bold] },
|
81
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
82
|
+
{ :text => " you?" }]
|
83
|
+
arranger.format_array = array
|
84
|
+
counter = 0
|
85
|
+
while string = arranger.next_string
|
86
|
+
case counter
|
87
|
+
when 0
|
88
|
+
arranger.current_format_state.should == { }
|
89
|
+
when 1
|
90
|
+
arranger.current_format_state.should == { :styles => [:bold] }
|
91
|
+
when 2
|
92
|
+
arranger.current_format_state.should == { :styles => [:bold, :italic] }
|
93
|
+
when 3
|
94
|
+
arranger.current_format_state.should == { }
|
95
|
+
end
|
96
|
+
counter += 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
102
|
+
it "should raise an error if called before finalize_line was called" do
|
103
|
+
create_pdf
|
104
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
105
|
+
array = [{ :text => "hello " },
|
106
|
+
{ :text => "world how ", :styles => [:bold] },
|
107
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
108
|
+
{ :text => " you?" }]
|
109
|
+
arranger.format_array = array
|
110
|
+
while string = arranger.next_string
|
111
|
+
end
|
112
|
+
lambda do
|
113
|
+
arranger.retrieve_fragment
|
114
|
+
end.should.raise(RuntimeError)
|
115
|
+
end
|
116
|
+
it "should return the consumed fragments in order of consumption" +
|
117
|
+
" and update" do
|
118
|
+
create_pdf
|
119
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
120
|
+
array = [{ :text => "hello " },
|
121
|
+
{ :text => "world how ", :styles => [:bold] },
|
122
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
123
|
+
{ :text => " you?" }]
|
124
|
+
arranger.format_array = array
|
125
|
+
while string = arranger.next_string
|
126
|
+
end
|
127
|
+
arranger.finalize_line
|
128
|
+
arranger.retrieve_fragment.text.should == "hello "
|
129
|
+
arranger.retrieve_fragment.text.should == "world how "
|
130
|
+
arranger.retrieve_fragment.text.should == "are"
|
131
|
+
arranger.retrieve_fragment.text.should == " you?"
|
132
|
+
end
|
133
|
+
it "should never return a fragment whose text is an empty string" do
|
134
|
+
create_pdf
|
135
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
136
|
+
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
|
137
|
+
{ :text => "\n" },
|
138
|
+
{ :text => "\n" },
|
139
|
+
{ :text => "\n" },
|
140
|
+
{ :text => "" },
|
141
|
+
{ :text => "fine, thanks." },
|
142
|
+
{ :text => "" },
|
143
|
+
{ :text => "\n" },
|
144
|
+
{ :text => "" }]
|
145
|
+
arranger.format_array = array
|
146
|
+
while string = arranger.next_string
|
147
|
+
end
|
148
|
+
arranger.finalize_line
|
149
|
+
while fragment = arranger.retrieve_fragment
|
150
|
+
fragment.text.should.not.be.empty
|
151
|
+
end
|
152
|
+
end
|
153
|
+
it "should not alter the current font style" do
|
154
|
+
create_pdf
|
155
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
156
|
+
array = [{ :text => "hello " },
|
157
|
+
{ :text => "world how ", :styles => [:bold] },
|
158
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
159
|
+
{ :text => " you?" }]
|
160
|
+
arranger.format_array = array
|
161
|
+
while string = arranger.next_string
|
162
|
+
end
|
163
|
+
arranger.finalize_line
|
164
|
+
arranger.retrieve_fragment
|
165
|
+
arranger.current_format_state[:styles].should.be.nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "Core::Text::Formatted::Arranger#update_last_string" do
|
170
|
+
it "should update the last retrieved string with what actually fit on" +
|
171
|
+
"the line and the list of unconsumed with what did not" do
|
172
|
+
create_pdf
|
173
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
174
|
+
array = [{ :text => "hello " },
|
175
|
+
{ :text => "world how ", :styles => [:bold] },
|
176
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
177
|
+
{ :text => " you now?", :styles => [:bold, :italic] }]
|
178
|
+
arranger.format_array = array
|
179
|
+
while string = arranger.next_string
|
180
|
+
end
|
181
|
+
arranger.update_last_string(" you", " now?")
|
182
|
+
arranger.consumed[3].should == { :text => " you",
|
183
|
+
:styles => [:bold, :italic] }
|
184
|
+
arranger.unconsumed.should == [{ :text => " now?",
|
185
|
+
:styles => [:bold, :italic] }]
|
186
|
+
end
|
187
|
+
context "when the entire string was used" do
|
188
|
+
it "should not push empty string onto unconsumed" do
|
189
|
+
create_pdf
|
190
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
191
|
+
array = [{ :text => "hello " },
|
192
|
+
{ :text => "world how ", :styles => [:bold] },
|
193
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
194
|
+
{ :text => " you now?" }]
|
195
|
+
arranger.format_array = array
|
196
|
+
while string = arranger.next_string
|
197
|
+
end
|
198
|
+
arranger.update_last_string(" you now?", "")
|
199
|
+
arranger.unconsumed.should == []
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
describe "Core::Text::Formatted::Arranger#space_count" do
|
204
|
+
before(:each) do
|
205
|
+
create_pdf
|
206
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
207
|
+
array = [{ :text => "hello " },
|
208
|
+
{ :text => "world how ", :styles => [:bold] },
|
209
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
210
|
+
{ :text => " you?" }]
|
211
|
+
@arranger.format_array = array
|
212
|
+
while string = @arranger.next_string
|
213
|
+
end
|
214
|
+
end
|
215
|
+
it "should raise an error if called before finalize_line was called" do
|
216
|
+
lambda do
|
217
|
+
@arranger.space_count
|
218
|
+
end.should.raise(RuntimeError)
|
219
|
+
end
|
220
|
+
it "should return the total number of spaces in all fragments" do
|
221
|
+
@arranger.finalize_line
|
222
|
+
@arranger.space_count.should == 4
|
223
|
+
end
|
224
|
+
end
|
225
|
+
describe "Core::Text::Formatted::Arranger#finalize_line" do
|
226
|
+
it "should make it so the last consumed fragment ends with non-white-space" do
|
227
|
+
create_pdf
|
228
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
229
|
+
array = [{ :text => "hello " },
|
230
|
+
{ :text => "world how ", :styles => [:bold] },
|
231
|
+
{ :text => " ", :styles => [:bold, :italic] }]
|
232
|
+
arranger.format_array = array
|
233
|
+
while string = arranger.next_string
|
234
|
+
end
|
235
|
+
arranger.finalize_line
|
236
|
+
arranger.fragments.length.should == 2
|
237
|
+
arranger.retrieve_fragment.text
|
238
|
+
arranger.retrieve_fragment.text.should == "world how"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "Core::Text::Formatted::Arranger#line_width" do
|
243
|
+
before(:each) do
|
244
|
+
create_pdf
|
245
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
246
|
+
array = [{ :text => "hello " },
|
247
|
+
{ :text => "world", :styles => [:bold] }]
|
248
|
+
@arranger.format_array = array
|
249
|
+
while string = @arranger.next_string
|
250
|
+
end
|
251
|
+
end
|
252
|
+
it "should raise an error if called before finalize_line was called" do
|
253
|
+
lambda do
|
254
|
+
@arranger.line_width
|
255
|
+
end.should.raise(RuntimeError)
|
256
|
+
end
|
257
|
+
it "should return the width of the complete line" do
|
258
|
+
@arranger.finalize_line
|
259
|
+
@arranger.line_width.should.be > 0
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "Core::Text::Formatted::Arranger#line" do
|
264
|
+
before(:each) do
|
265
|
+
create_pdf
|
266
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
267
|
+
array = [{ :text => "hello " },
|
268
|
+
{ :text => "world", :styles => [:bold] }]
|
269
|
+
@arranger.format_array = array
|
270
|
+
while string = @arranger.next_string
|
271
|
+
end
|
272
|
+
end
|
273
|
+
it "should raise an error if called before finalize_line was called" do
|
274
|
+
lambda do
|
275
|
+
@arranger.line
|
276
|
+
end.should.raise(RuntimeError)
|
277
|
+
end
|
278
|
+
it "should return the complete line" do
|
279
|
+
@arranger.finalize_line
|
280
|
+
@arranger.line.should == "hello world"
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "Core::Text::Formatted::Arranger#unconsumed" do
|
285
|
+
it "should return the original array if nothing was consumed" do
|
286
|
+
create_pdf
|
287
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
288
|
+
array = [{ :text => "hello " },
|
289
|
+
{ :text => "world how ", :styles => [:bold] },
|
290
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
291
|
+
{ :text => " you now?" }]
|
292
|
+
arranger.format_array = array
|
293
|
+
arranger.unconsumed.should == array
|
294
|
+
end
|
295
|
+
it "should return an empty array if everything was consumed" do
|
296
|
+
create_pdf
|
297
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
298
|
+
array = [{ :text => "hello " },
|
299
|
+
{ :text => "world how ", :styles => [:bold] },
|
300
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
301
|
+
{ :text => " you now?" }]
|
302
|
+
arranger.format_array = array
|
303
|
+
while string = arranger.next_string
|
304
|
+
end
|
305
|
+
arranger.unconsumed.should == []
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe "Core::Text::Formatted::Arranger#finished" do
|
310
|
+
it "should be false if anything was not printed" do
|
311
|
+
create_pdf
|
312
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
313
|
+
array = [{ :text => "hello " },
|
314
|
+
{ :text => "world how ", :styles => [:bold] },
|
315
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
316
|
+
{ :text => " you now?" }]
|
317
|
+
arranger.format_array = array
|
318
|
+
while string = arranger.next_string
|
319
|
+
end
|
320
|
+
arranger.update_last_string(" you", "now?")
|
321
|
+
arranger.should.not.be.finished
|
322
|
+
end
|
323
|
+
it "should be false if everything was printed" do
|
324
|
+
create_pdf
|
325
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
326
|
+
array = [{ :text => "hello " },
|
327
|
+
{ :text => "world how ", :styles => [:bold] },
|
328
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
329
|
+
{ :text => " you now?" }]
|
330
|
+
arranger.format_array = array
|
331
|
+
while string = arranger.next_string
|
332
|
+
end
|
333
|
+
arranger.should.be.finished
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "Core::Text::Formatted::Arranger#unfinished" do
|
338
|
+
it "should be false if anything was not printed" do
|
339
|
+
create_pdf
|
340
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
341
|
+
array = [{ :text => "hello " },
|
342
|
+
{ :text => "world how ", :styles => [:bold] },
|
343
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
344
|
+
{ :text => " you now?" }]
|
345
|
+
arranger.format_array = array
|
346
|
+
while string = arranger.next_string
|
347
|
+
end
|
348
|
+
arranger.update_last_string(" you", "now?")
|
349
|
+
arranger.should.be.unfinished
|
350
|
+
end
|
351
|
+
it "should be false if everything was printed" do
|
352
|
+
create_pdf
|
353
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
354
|
+
array = [{ :text => "hello " },
|
355
|
+
{ :text => "world how ", :styles => [:bold] },
|
356
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
357
|
+
{ :text => " you now?" }]
|
358
|
+
arranger.format_array = array
|
359
|
+
while string = arranger.next_string
|
360
|
+
end
|
361
|
+
arranger.should.not.be.unfinished
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe "Core::Text::Formatted::Arranger.max_line_height" do
|
366
|
+
it "should be the height of the maximum consumed fragment" do
|
367
|
+
create_pdf
|
368
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
369
|
+
array = [{ :text => "hello " },
|
370
|
+
{ :text => "world how ", :styles => [:bold] },
|
371
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
372
|
+
{ :text => " you now?" }]
|
373
|
+
arranger.format_array = array
|
374
|
+
while string = arranger.next_string
|
375
|
+
end
|
376
|
+
arranger.update_last_string(" you", "now?")
|
377
|
+
arranger.should.be.unfinished
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe "Core::Text::Formatted::Arranger#repack_unretrieved" do
|
382
|
+
it "should restore part of the original string" do
|
383
|
+
create_pdf
|
384
|
+
arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
385
|
+
array = [{ :text => "hello " },
|
386
|
+
{ :text => "world how ", :styles => [:bold] },
|
387
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
388
|
+
{ :text => " you now?" }]
|
389
|
+
arranger.format_array = array
|
390
|
+
while string = arranger.next_string
|
391
|
+
end
|
392
|
+
arranger.finalize_line
|
393
|
+
arranger.retrieve_fragment
|
394
|
+
arranger.retrieve_fragment
|
395
|
+
arranger.repack_unretrieved
|
396
|
+
arranger.unconsumed.should == [
|
397
|
+
{ :text => "are", :styles => [:bold, :italic] },
|
398
|
+
{ :text => " you now?" }]
|
399
|
+
end
|
400
|
+
end
|