prawn 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/COPYING +2 -2
  4. data/Gemfile +8 -15
  5. data/LICENSE +1 -1
  6. data/Rakefile +25 -16
  7. data/data/images/16bit.alpha +0 -0
  8. data/data/images/16bit.color +0 -0
  9. data/data/images/dice.alpha +0 -0
  10. data/data/images/dice.color +0 -0
  11. data/data/images/indexed_color.dat +0 -0
  12. data/data/images/indexed_color.png +0 -0
  13. data/data/images/license.md +8 -0
  14. data/data/images/page_white_text.alpha +0 -0
  15. data/data/images/page_white_text.color +0 -0
  16. data/lib/prawn.rb +85 -23
  17. data/lib/prawn/document.rb +134 -116
  18. data/lib/prawn/document/bounding_box.rb +33 -4
  19. data/lib/prawn/document/column_box.rb +18 -6
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +24 -23
  22. data/lib/prawn/document/span.rb +12 -10
  23. data/lib/prawn/encoding.rb +8 -9
  24. data/lib/prawn/errors.rb +13 -32
  25. data/lib/prawn/font.rb +137 -105
  26. data/lib/prawn/font/afm.rb +76 -32
  27. data/lib/prawn/font/dfont.rb +4 -3
  28. data/lib/prawn/font/ttf.rb +33 -25
  29. data/lib/prawn/font_metric_cache.rb +47 -0
  30. data/lib/prawn/graphics.rb +177 -57
  31. data/lib/prawn/graphics/cap_style.rb +4 -3
  32. data/lib/prawn/graphics/color.rb +5 -4
  33. data/lib/prawn/graphics/dash.rb +53 -31
  34. data/lib/prawn/graphics/join_style.rb +9 -7
  35. data/lib/prawn/graphics/patterns.rb +4 -15
  36. data/lib/prawn/graphics/transformation.rb +10 -9
  37. data/lib/prawn/graphics/transparency.rb +3 -1
  38. data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
  39. data/lib/prawn/image_handler.rb +42 -0
  40. data/lib/prawn/images.rb +58 -54
  41. data/lib/prawn/images/image.rb +6 -22
  42. data/lib/prawn/images/jpg.rb +20 -14
  43. data/lib/prawn/images/png.rb +58 -121
  44. data/lib/prawn/layout.rb +12 -15
  45. data/lib/prawn/measurement_extensions.rb +10 -6
  46. data/lib/prawn/measurements.rb +27 -21
  47. data/lib/prawn/outline.rb +108 -147
  48. data/lib/prawn/repeater.rb +10 -8
  49. data/lib/prawn/security.rb +59 -40
  50. data/lib/prawn/security/arcfour.rb +52 -0
  51. data/lib/prawn/soft_mask.rb +4 -4
  52. data/lib/prawn/stamp.rb +5 -3
  53. data/lib/prawn/table.rb +83 -60
  54. data/lib/prawn/table/cell.rb +17 -21
  55. data/lib/prawn/table/cell/image.rb +2 -3
  56. data/lib/prawn/table/cell/in_table.rb +8 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +5 -0
  58. data/lib/prawn/table/cell/subtable.rb +3 -2
  59. data/lib/prawn/table/cell/text.rb +14 -12
  60. data/lib/prawn/table/cells.rb +58 -14
  61. data/lib/prawn/table/column_width_calculator.rb +61 -0
  62. data/lib/prawn/text.rb +27 -26
  63. data/lib/prawn/text/box.rb +12 -6
  64. data/lib/prawn/text/formatted.rb +5 -4
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +85 -57
  67. data/lib/prawn/text/formatted/fragment.rb +11 -11
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +11 -4
  70. data/lib/prawn/text/formatted/wrap.rb +156 -0
  71. data/lib/prawn/utilities.rb +5 -3
  72. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  73. data/manual/document_and_page_options/metadata.rb +3 -3
  74. data/manual/document_and_page_options/page_size.rb +2 -2
  75. data/manual/document_and_page_options/print_scaling.rb +20 -0
  76. data/manual/example_file.rb +2 -7
  77. data/manual/example_helper.rb +62 -81
  78. data/manual/graphics/common_lines.rb +2 -0
  79. data/manual/graphics/helper.rb +11 -4
  80. data/manual/graphics/stroke_dash.rb +19 -14
  81. data/manual/manual/cover.rb +16 -0
  82. data/manual/manual/manual.rb +1 -5
  83. data/manual/text/fallback_fonts.rb +4 -4
  84. data/manual/text/formatted_text.rb +5 -5
  85. data/manual/text/inline.rb +2 -4
  86. data/manual/text/registering_families.rb +12 -12
  87. data/manual/text/single_usage.rb +4 -4
  88. data/manual/text/text.rb +0 -2
  89. data/prawn.gemspec +21 -13
  90. data/spec/acceptance/png.rb +23 -0
  91. data/spec/annotations_spec.rb +16 -32
  92. data/spec/bounding_box_spec.rb +22 -5
  93. data/spec/cell_spec.rb +49 -5
  94. data/spec/column_box_spec.rb +32 -0
  95. data/spec/destinations_spec.rb +5 -5
  96. data/spec/document_spec.rb +112 -118
  97. data/spec/extensions/encoding_helpers.rb +5 -2
  98. data/spec/font_metric_cache_spec.rb +52 -0
  99. data/spec/font_spec.rb +121 -120
  100. data/spec/formatted_text_arranger_spec.rb +24 -24
  101. data/spec/formatted_text_box_spec.rb +31 -32
  102. data/spec/formatted_text_fragment_spec.rb +2 -2
  103. data/spec/graphics_spec.rb +63 -45
  104. data/spec/grid_spec.rb +24 -13
  105. data/spec/image_handler_spec.rb +54 -0
  106. data/spec/images_spec.rb +34 -21
  107. data/spec/inline_formatted_text_parser_spec.rb +69 -20
  108. data/spec/jpg_spec.rb +3 -3
  109. data/spec/line_wrap_spec.rb +25 -14
  110. data/spec/measurement_units_spec.rb +5 -5
  111. data/spec/outline_spec.rb +68 -64
  112. data/spec/png_spec.rb +15 -18
  113. data/spec/reference_spec.rb +2 -82
  114. data/spec/repeater_spec.rb +1 -1
  115. data/spec/security_spec.rb +41 -9
  116. data/spec/soft_mask_spec.rb +0 -40
  117. data/spec/span_spec.rb +6 -11
  118. data/spec/spec_helper.rb +20 -2
  119. data/spec/stamp_spec.rb +19 -20
  120. data/spec/stroke_styles_spec.rb +31 -13
  121. data/spec/table/span_dummy_spec.rb +17 -0
  122. data/spec/table_spec.rb +268 -43
  123. data/spec/text_at_spec.rb +13 -27
  124. data/spec/text_box_spec.rb +35 -30
  125. data/spec/text_spec.rb +56 -40
  126. data/spec/transparency_spec.rb +5 -5
  127. metadata +214 -217
  128. data/README.md +0 -98
  129. data/data/fonts/Action Man.dfont +0 -0
  130. data/data/fonts/Activa.ttf +0 -0
  131. data/data/fonts/Chalkboard.ttf +0 -0
  132. data/data/fonts/DejaVuSans.ttf +0 -0
  133. data/data/fonts/Dustismo_Roman.ttf +0 -0
  134. data/data/fonts/comicsans.ttf +0 -0
  135. data/data/fonts/gkai00mp.ttf +0 -0
  136. data/data/images/16bit.dat +0 -0
  137. data/data/images/barcode_issue.png +0 -0
  138. data/data/images/dice.dat +0 -0
  139. data/data/images/page_white_text.dat +0 -0
  140. data/data/images/rails.dat +0 -0
  141. data/data/images/rails.png +0 -0
  142. data/lib/prawn/compatibility.rb +0 -87
  143. data/lib/prawn/core.rb +0 -87
  144. data/lib/prawn/core/annotations.rb +0 -61
  145. data/lib/prawn/core/byte_string.rb +0 -9
  146. data/lib/prawn/core/destinations.rb +0 -90
  147. data/lib/prawn/core/document_state.rb +0 -79
  148. data/lib/prawn/core/literal_string.rb +0 -16
  149. data/lib/prawn/core/name_tree.rb +0 -177
  150. data/lib/prawn/core/object_store.rb +0 -320
  151. data/lib/prawn/core/page.rb +0 -212
  152. data/lib/prawn/core/pdf_object.rb +0 -125
  153. data/lib/prawn/core/reference.rb +0 -119
  154. data/lib/prawn/core/text.rb +0 -268
  155. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  156. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
  157. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  158. data/lib/prawn/document/page_geometry.rb +0 -136
  159. data/lib/prawn/document/snapshot.rb +0 -89
  160. data/manual/manual/foreword.rb +0 -13
  161. data/manual/templates/full_template.rb +0 -23
  162. data/manual/templates/page_template.rb +0 -47
  163. data/manual/templates/templates.rb +0 -26
  164. data/manual/text/group.rb +0 -29
  165. data/spec/name_tree_spec.rb +0 -112
  166. data/spec/object_store_spec.rb +0 -170
  167. data/spec/pdf_object_spec.rb +0 -172
  168. data/spec/snapshot_spec.rb +0 -186
  169. data/spec/template_spec.rb +0 -351
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
4
+ require 'set'
5
+
6
+ describe "Prawn::Table::Cell::SpanDummy" do
7
+ before(:each) do
8
+ @pdf = Prawn::Document.new
9
+ @table = @pdf.table([[{:content => "Row", :colspan => 2}]])
10
+ @master_cell = @table.cells[0,0]
11
+ @span_dummy = @master_cell.dummy_cells.first
12
+ end
13
+
14
+ it "delegates background_color to the master cell" do
15
+ @span_dummy.background_color.should == @master_cell.background_color
16
+ end
17
+ end
@@ -45,6 +45,142 @@ describe "Prawn::Table" do
45
45
  end
46
46
  end
47
47
 
48
+ describe "You can explicitly set the column widths and use a colspan > 1" do
49
+
50
+ it "should tolerate floating point rounding errors < 0.000000001" do
51
+ data=[["a", "b ", "c ", "d", "e", "f", "g", "h", "i", "j", "k", "l"],
52
+ [{:content=>"Foobar", :colspan=>12}]
53
+ ]
54
+ #we need values with lots of decimals so that arithmetic errors will occur
55
+ #the values are not arbitrary but where found converting mm to pdf pt
56
+ column_widths=[137, 40, 40, 54.69291338582678, 54.69291338582678,
57
+ 54.69291338582678, 54.69291338582678, 54.69291338582678,
58
+ 54.69291338582678, 54.69291338582678, 54.69291338582678,
59
+ 54.69291338582678]
60
+
61
+ pdf = Prawn::Document.new({:page_size => 'A4', :page_layout => :landscape})
62
+ table = Prawn::Table.new data, pdf, :column_widths => column_widths
63
+ table.column_widths.should == column_widths
64
+ end
65
+
66
+ it "should work with two different given colspans", :issue => 628 do
67
+ data = [
68
+ [" ", " ", " "],
69
+ [{:content=>" ", :colspan=>3}],
70
+ [" ", {:content=>" ", :colspan=>2}]
71
+ ]
72
+ column_widths = [60, 240, 60]
73
+ pdf = Prawn::Document.new
74
+ #the next line raised an Prawn::Errors::CannotFit exception before issue 628 was fixed
75
+ table = Prawn::Table.new data, pdf, :column_widths => column_widths
76
+ table.column_widths.should == column_widths
77
+ end
78
+
79
+ it "should work with a colspan > 1 with given column_widths (issue #407)" do
80
+ #normal entries in line 1
81
+ data = [
82
+ [ '','',''],
83
+ [ { :content => "", :colspan => 3 } ],
84
+ [ "", "", "" ],
85
+ ]
86
+ pdf = Prawn::Document.new
87
+ table = Prawn::Table.new data, pdf, :column_widths => [100 , 200, 240]
88
+
89
+ #colspan entry in line 1
90
+ data = [
91
+ [ { :content => "", :colspan => 3 } ],
92
+ [ "", "", "" ],
93
+ ]
94
+ pdf = Prawn::Document.new
95
+ table = Prawn::Table.new data, pdf, :column_widths => [100 , 200, 240]
96
+
97
+ #mixed entries in line 1
98
+ data = [
99
+ [ { :content => "", :colspan =>2 }, "" ],
100
+ [ "", "", "" ],
101
+ ]
102
+ pdf = Prawn::Document.new
103
+ table = Prawn::Table.new data, pdf, :column_widths => [100 , 200, 240]
104
+
105
+ data = [['', '', {:content => '', :colspan => 2}, '',''],
106
+ ['',{:content => '', :colspan => 5}]
107
+ ]
108
+ pdf = Prawn::Document.new
109
+ table = Prawn::Table.new data, pdf, :column_widths => [50 , 100, 50, 50, 50, 50]
110
+
111
+ end
112
+
113
+ it "should not increase column width when rendering a subtable",
114
+ :unresolved, :issue => 612 do
115
+
116
+ pdf = Prawn::Document.new
117
+
118
+ first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
119
+ second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
120
+ third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center}
121
+ fourth = {:content=>"Bar",:width=>20,:align=>:center}
122
+
123
+ table_content = [[
124
+ first,
125
+ [[second],[third,fourth]]
126
+ ]]
127
+
128
+ table = Prawn::Table.new table_content, pdf
129
+ table.column_widths.should == [50.0, 70.0]
130
+ end
131
+
132
+ it "illustrate issue #533" do
133
+ data = [['', '', '', '', '',''],
134
+ ['',{:content => '', :colspan => 5}]]
135
+ pdf = Prawn::Document.new
136
+ table = Prawn::Table.new data, pdf, :column_widths => [50, 200, 40, 40, 50, 50]
137
+ end
138
+
139
+ it "illustrates issue #502" do
140
+ pdf = Prawn::Document.new
141
+ first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
142
+ second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
143
+ third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center}
144
+ fourth = {:content=>"Bar",:width=>20,:align=>:center}
145
+ table_content = [[
146
+ first,
147
+ [[second],[third,fourth]]
148
+ ]]
149
+ pdf.move_down(20)
150
+ table = Prawn::Table.new table_content, pdf
151
+ pdf.table(table_content)
152
+ end
153
+
154
+ #https://github.com/prawnpdf/prawn/issues/407#issuecomment-28556698
155
+ it "correctly computes column widths with empty cells + colspan" do
156
+ data = [['', ''],
157
+ [{:content => '', :colspan => 2}]
158
+ ]
159
+ pdf = Prawn::Document.new
160
+
161
+ table = Prawn::Table.new data, pdf, :column_widths => [50, 200]
162
+ table.column_widths.should == [50.0, 200.0]
163
+ end
164
+
165
+ it "illustrates a variant of problem in issue #407 - comment 28556698" do
166
+ pdf = Prawn::Document.new
167
+ table_data = [["a", "b", "c"], [{:content=>"d", :colspan=>3}]]
168
+ column_widths = [50, 60, 400]
169
+
170
+ # Before we fixed #407, this line incorrectly raise a CannotFit error
171
+ pdf.table(table_data, :column_widths => column_widths)
172
+ end
173
+
174
+ it "should not allow oversized subtables when parent column width is constrained" do
175
+ pdf = Prawn::Document.new
176
+ child_1 = pdf.make_table([['foo'*100]])
177
+ child_2 = pdf.make_table([['foo']])
178
+ lambda do
179
+ pdf.table([[child_1], [child_2]], column_widths: [pdf.bounds.width/2] * 2)
180
+ end.should raise_error(Prawn::Errors::CannotFit)
181
+ end
182
+ end
183
+
48
184
  describe "#initialize" do
49
185
  before(:each) do
50
186
  @pdf = Prawn::Document.new
@@ -374,13 +510,13 @@ describe "Prawn::Table" do
374
510
  end
375
511
 
376
512
  it "should allow table cells to be resized in block" do
377
- lambda do
378
- @pdf.table([%w[1 2 3 4 5]]) do |t|
379
- t.width = 40
380
- t.cells.size = 8
381
- t.cells.padding = 0
382
- end
383
- end.should_not raise_error(Prawn::Errors::CannotFit)
513
+ # if anything goes wrong, a CannotFit error will be raised
514
+
515
+ @pdf.table([%w[1 2 3 4 5]]) do |t|
516
+ t.width = 40
517
+ t.cells.size = 8
518
+ t.cells.padding = 0
519
+ end
384
520
  end
385
521
 
386
522
  it "should be the width of the :width parameter" do
@@ -660,6 +796,17 @@ describe "Prawn::Table" do
660
796
  end
661
797
  end
662
798
 
799
+ it "updates dummy cell header rows" do
800
+ header = [[{:content => "header", :colspan => 2}]]
801
+ data = [["foo", "bar"]] * 31
802
+ @pdf.table(header + data, :header => true) do |t|
803
+ t.before_rendering_page do |page|
804
+ cell = page[0, 0]
805
+ cell.dummy_cells.each {|dc| dc.row.should == cell.row }
806
+ end
807
+ end
808
+ end
809
+
663
810
  it "allows headers to be changed" do
664
811
  seq = sequence("render order")
665
812
  @pdf.expects(:draw_text!).with { |t, _| t == "hdr1"}.in_sequence(seq)
@@ -703,6 +850,12 @@ describe "Prawn::Table" do
703
850
  table([["x"]]) { style(stylable) }
704
851
  end
705
852
  end
853
+
854
+ it "ignores unknown values on a cell-by-cell basis" do
855
+ Prawn::Document.new do
856
+ table([["x", [["y"]]]], :cell_style => {:overflow => :shrink_to_fit})
857
+ end
858
+ end
706
859
  end
707
860
 
708
861
  describe "row_colors" do
@@ -862,49 +1015,123 @@ describe "Prawn::Table" do
862
1015
  end
863
1016
 
864
1017
  describe "headers" do
865
- it "should add headers to output when specified" do
866
- data = [["a", "b"], ["foo","bar"],["baz","bang"]]
867
- @pdf = Prawn::Document.new
868
- @pdf.table(data, :header => true)
869
- output = PDF::Inspector::Text.analyze(@pdf.render)
870
- output.strings.should == data.flatten
871
- end
1018
+ context "single row header" do
1019
+ it "should add headers to output when specified" do
1020
+ data = [["a", "b"], ["foo","bar"],["baz","bang"]]
1021
+ @pdf = Prawn::Document.new
1022
+ @pdf.table(data, :header => true)
1023
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1024
+ output.strings.should == data.flatten
1025
+ end
872
1026
 
873
- it "should repeat headers across pages" do
874
- data = [["foo","bar"]] * 30
875
- headers = ["baz","foobar"]
876
- @pdf = Prawn::Document.new
877
- @pdf.table([headers] + data, :header => true)
878
- output = PDF::Inspector::Text.analyze(@pdf.render)
879
- output.strings.should == headers + data.flatten[0..-3] + headers +
880
- data.flatten[-2..-1]
881
- end
1027
+ it "should repeat headers across pages" do
1028
+ data = [["foo","bar"]] * 30
1029
+ headers = ["baz","foobar"]
1030
+ @pdf = Prawn::Document.new
1031
+ @pdf.table([headers] + data, :header => true)
1032
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1033
+ output.strings.should == headers + data.flatten[0..-3] + headers +
1034
+ data.flatten[-2..-1]
1035
+ end
882
1036
 
883
- it "draws headers at the correct position" do
884
- data = [["header"]] + [["foo"]] * 40
1037
+ it "draws headers at the correct position" do
1038
+ data = [["header"]] + [["foo"]] * 40
1039
+
1040
+ Prawn::Table::Cell.expects(:draw_cells).times(2).checking do |cells|
1041
+ cells.each do |cell, pt|
1042
+ if cell.content == "header"
1043
+ # Assert that header text is drawn at the same location on each page
1044
+ if @header_location
1045
+ pt.should == @header_location
1046
+ else
1047
+ @header_location = pt
1048
+ end
1049
+ end
1050
+ end
1051
+ end
1052
+ @pdf = Prawn::Document.new
1053
+ @pdf.table(data, :header => true)
1054
+ end
1055
+
1056
+ it "draws headers at the correct position with column box" do
1057
+ data = [["header"]] + [["foo"]] * 40
885
1058
 
886
- Prawn::Table::Cell.expects(:draw_cells).times(2).checking do |cells|
887
- cells.each do |cell, pt|
888
- if cell.content == "header"
889
- # Assert that header text is drawn at the same location on each page
890
- if @header_location
891
- pt.should == @header_location
892
- else
893
- @header_location = pt
1059
+ Prawn::Table::Cell.expects(:draw_cells).times(2).checking do |cells|
1060
+ cells.each do |cell, pt|
1061
+ if cell.content == "header"
1062
+ pt[0].should == @pdf.bounds.left
894
1063
  end
895
1064
  end
896
1065
  end
1066
+ @pdf = Prawn::Document.new
1067
+ @pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 2 do
1068
+ @pdf.table(data, :header => true)
1069
+ end
1070
+ end
1071
+
1072
+ it "should_not draw header twice when starting new page" do
1073
+ @pdf = Prawn::Document.new
1074
+ @pdf.y = 0
1075
+ @pdf.table([["Header"], ["Body"]], :header => true)
1076
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1077
+ output.strings.should == ["Header", "Body"]
897
1078
  end
898
- @pdf = Prawn::Document.new
899
- @pdf.table(data, :header => true)
900
1079
  end
901
1080
 
902
- it "should_not draw header twice when starting new page" do
903
- @pdf = Prawn::Document.new
904
- @pdf.y = 0
905
- @pdf.table([["Header"], ["Body"]], :header => true)
906
- output = PDF::Inspector::Text.analyze(@pdf.render)
907
- output.strings.should == ["Header", "Body"]
1081
+ context "multiple row header" do
1082
+ it "should add headers to output when specified" do
1083
+ data = [["a", "b"], ["c", "d"], ["foo","bar"],["baz","bang"]]
1084
+ @pdf = Prawn::Document.new
1085
+ @pdf.table(data, :header => 2)
1086
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1087
+ output.strings.should == data.flatten
1088
+ end
1089
+
1090
+ it "should repeat headers across pages" do
1091
+ data = [["foo","bar"]] * 30
1092
+ headers = ["baz","foobar"] + ["bas", "foobaz"]
1093
+ @pdf = Prawn::Document.new
1094
+ @pdf.table([headers] + data, :header => 2)
1095
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1096
+ output.strings.should == headers + data.flatten[0..-3] + headers +
1097
+ data.flatten[-4..-1]
1098
+ end
1099
+
1100
+ it "draws headers at the correct position" do
1101
+ data = [["header"]] + [["header2"]] + [["foo"]] * 40
1102
+
1103
+ Prawn::Table::Cell.expects(:draw_cells).times(2).checking do |cells|
1104
+ cells.each do |cell, pt|
1105
+ if cell.content == "header"
1106
+ # Assert that header text is drawn at the same location on each page
1107
+ if @header_location
1108
+ pt.should == @header_location
1109
+ else
1110
+ @header_location = pt
1111
+ end
1112
+ end
1113
+
1114
+ if cell.content == "header2"
1115
+ # Assert that header text is drawn at the same location on each page
1116
+ if @header2_location
1117
+ pt.should == @header2_location
1118
+ else
1119
+ @header2_location = pt
1120
+ end
1121
+ end
1122
+ end
1123
+ end
1124
+ @pdf = Prawn::Document.new
1125
+ @pdf.table(data, :header => 2)
1126
+ end
1127
+
1128
+ it "should_not draw header twice when starting new page" do
1129
+ @pdf = Prawn::Document.new
1130
+ @pdf.y = 0
1131
+ @pdf.table([["Header"], ["Header2"], ["Body"]], :header => 2)
1132
+ output = PDF::Inspector::Text.analyze(@pdf.render)
1133
+ output.strings.should == ["Header", "Header2", "Body"]
1134
+ end
908
1135
  end
909
1136
  end
910
1137
 
@@ -1165,7 +1392,6 @@ describe "colspan / rowspan" do
1165
1392
  :colspan => 3}],
1166
1393
  ["A", "B", "C"]],
1167
1394
  :width => 200)
1168
-
1169
1395
  t.column_widths.inject(0) { |sum, w| sum + w }.
1170
1396
  should be_within(0.01).of(200)
1171
1397
  end
@@ -1206,4 +1432,3 @@ describe "colspan / rowspan" do
1206
1432
  t.cells[2, 3].content.should == "i"
1207
1433
  end
1208
1434
  end
1209
-
@@ -98,32 +98,18 @@ describe "#draw_text" do
98
98
  text.strings.first.should == str
99
99
  end
100
100
 
101
- if "spec".respond_to?(:encode!)
102
- # Handle non utf-8 string encodings in a sane way on M17N aware VMs
103
- it "should raise_error an exception when a utf-8 incompatible string is rendered" do
104
- str = "Blah \xDD"
105
- str.force_encoding("ASCII-8BIT")
106
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
107
- Prawn::Errors::IncompatibleStringEncoding)
108
- end
109
- it "should_not raise_error an exception when a shift-jis string is rendered" do
110
- datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
111
- sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
112
- @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
113
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should_not raise_error(
114
- Prawn::Errors::IncompatibleStringEncoding)
115
- end
116
- else
117
- # Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
118
- it "should raise_error an exception when a corrupt utf-8 string is rendered" do
119
- str = "Blah \xDD"
120
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
121
- Prawn::Errors::IncompatibleStringEncoding)
122
- end
123
- it "should raise_error an exception when a shift-jis string is rendered" do
124
- sjis_str = File.read("#{Prawn::DATADIR}/shift_jis_text.txt")
125
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should raise_error(
126
- Prawn::Errors::IncompatibleStringEncoding)
127
- end
101
+ it "should raise_error an exception when a utf-8 incompatible string is rendered" do
102
+ str = "Blah \xDD"
103
+ str.force_encoding(Encoding::ASCII_8BIT)
104
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
105
+ Prawn::Errors::IncompatibleStringEncoding)
106
+ end
107
+
108
+ it "should not raise an exception when a shift-jis string is rendered" do
109
+ datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
110
+ sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
111
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
112
+
113
+ @pdf.draw_text(sjis_str, :at => [0, 0])
128
114
  end
129
115
  end
@@ -116,7 +116,7 @@ describe "Text::Box" do
116
116
  end
117
117
  it "should default to document-wide leading if no" +
118
118
  "leading option is provided" do
119
-
119
+
120
120
  end
121
121
  end
122
122
 
@@ -278,14 +278,15 @@ describe "Text::Box#render(:dry_run => true)" do
278
278
  text = PDF::Inspector::Text.analyze(@pdf.render)
279
279
  text.strings.should be_empty
280
280
  end
281
+
281
282
  it "subsequent calls to render should_not raise_error an ArgumentError exception" do
282
283
  create_pdf
283
284
  @text = "™©"
284
285
  @options = { :document => @pdf }
285
286
  text_box = Prawn::Text::Box.new(@text, @options)
286
287
  text_box.render(:dry_run => true)
287
- lambda { text_box.render }.should_not raise_error(
288
- Prawn::Errors::IncompatibleStringEncoding)
288
+
289
+ text_box.render
289
290
  end
290
291
  end
291
292
 
@@ -548,7 +549,7 @@ describe "Text::Box with text than can fit in the box" do
548
549
  :document => @pdf
549
550
  }
550
551
  end
551
-
552
+
552
553
  it "printed text should match requested text, except that preceding and " +
553
554
  "trailing white space will be stripped from each line, and newlines may " +
554
555
  "be inserted" do
@@ -556,7 +557,7 @@ describe "Text::Box with text than can fit in the box" do
556
557
  text_box.render
557
558
  text_box.text.gsub("\n", " ").should == @text.strip
558
559
  end
559
-
560
+
560
561
  it "render should return an empty string because no text remains unprinted" do
561
562
  text_box = Prawn::Text::Box.new(@text, @options)
562
563
  text_box.render.should == ""
@@ -582,7 +583,7 @@ describe "Text::Box with text that fits exactly in the box" do
582
583
  :document => @pdf
583
584
  }
584
585
  end
585
-
586
+
586
587
  it "should have the expected height" do
587
588
  expected_height = @options.delete(:height)
588
589
  text_box = Prawn::Text::Box.new(@text, @options)
@@ -639,7 +640,7 @@ end
639
640
 
640
641
  describe "Text::Box printing UTF-8 string with higher bit characters" do
641
642
  before(:each) do
642
- create_pdf
643
+ create_pdf
643
644
  @text = "©"
644
645
  # not enough height to print any text, so we can directly compare against
645
646
  # the input string
@@ -648,28 +649,29 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
648
649
  :height => bounding_height,
649
650
  :document => @pdf
650
651
  }
651
- file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
652
- @pdf.font_families["Action Man"] = {
653
- :normal => { :file => file, :font => "ActionMan" },
654
- :italic => { :file => file, :font => "ActionMan-Italic" },
655
- :bold => { :file => file, :font => "ActionMan-Bold" },
656
- :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
652
+ file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
653
+ @pdf.font_families["Panic Sans"] = {
654
+ :normal => { :file => file, :font => "PanicSans" },
655
+ :italic => { :file => file, :font => "PanicSans-Italic" },
656
+ :bold => { :file => file, :font => "PanicSans-Bold" },
657
+ :bold_italic => { :file => file, :font => "PanicSans-BoldItalic" }
657
658
  }
658
659
  @text_box = Prawn::Text::Box.new(@text, options)
659
660
  end
660
661
  describe "when using a TTF font" do
661
662
  it "unprinted text should be in UTF-8 encoding" do
662
- @pdf.font("Action Man")
663
+ @pdf.font("Panic Sans")
663
664
  remaining_text = @text_box.render
664
665
  remaining_text.should == @text
665
666
  end
667
+
666
668
  it "subsequent calls to Text::Box need not include the" +
667
669
  " :skip_encoding => true option" do
668
- @pdf.font("Action Man")
670
+ @pdf.font("Panic Sans")
669
671
  remaining_text = @text_box.render
670
- lambda {
671
- @pdf.text_box(remaining_text, :document => @pdf)
672
- }.should_not raise_error(Prawn::Errors::IncompatibleStringEncoding)
672
+
673
+ # expect that calling text_box will not raise an encoding error
674
+ @pdf.text_box(remaining_text, :document => @pdf)
673
675
  end
674
676
  end
675
677
 
@@ -684,17 +686,16 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
684
686
  lambda {
685
687
  @pdf.text_box(remaining_text, :document => @pdf)
686
688
  }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
687
- lambda {
688
- @pdf.text_box(remaining_text, :skip_encoding => true,
689
- :document => @pdf)
690
- }.should_not raise_error(Prawn::Errors::IncompatibleStringEncoding)
689
+
690
+ @pdf.text_box(remaining_text, :skip_encoding => true,
691
+ :document => @pdf)
691
692
  end
692
693
  end
693
694
  end
694
695
 
695
696
  describe "Text::Box with more text than can fit in the box" do
696
697
  before(:each) do
697
- create_pdf
698
+ create_pdf
698
699
  @text = "Oh hai text rect. " * 30
699
700
  @bounding_height = 162.0
700
701
  @options = {
@@ -703,7 +704,7 @@ describe "Text::Box with more text than can fit in the box" do
703
704
  :document => @pdf
704
705
  }
705
706
  end
706
-
707
+
707
708
  context "truncated overflow" do
708
709
  before(:each) do
709
710
  @options[:overflow] = :truncate
@@ -741,7 +742,7 @@ describe "Text::Box with more text than can fit in the box" do
741
742
  end
742
743
  end
743
744
  end
744
-
745
+
745
746
  context "truncated with text and size taken from the manual" do
746
747
  it "should return the right text" do
747
748
  @text = "This is the beginning of the text. It will be cut somewhere and " +
@@ -840,8 +841,8 @@ describe "Text::Box with a solid block of Chinese characters" do
840
841
  end
841
842
 
842
843
 
843
- describe "drawing bounding boxes" do
844
- before(:each) { create_pdf }
844
+ describe "drawing bounding boxes" do
845
+ before(:each) { create_pdf }
845
846
 
846
847
  it "should restore the margin box when bounding box exits" do
847
848
  margin_box = @pdf.bounds
@@ -876,7 +877,7 @@ describe "Text::Box#render with :character_spacing option" do
876
877
  text_box.text.should == "hello\nworld"
877
878
  end
878
879
  end
879
-
880
+
880
881
  describe "Text::Box wrapping" do
881
882
  before(:each) do
882
883
  create_pdf
@@ -991,7 +992,7 @@ describe "Text::Box wrapping" do
991
992
 
992
993
  expected = "©" * 25 + "\n" + "©" * 5
993
994
  @pdf.font.normalize_encoding!(expected)
994
- expected = expected.force_encoding("utf-8") if expected.respond_to?(:force_encoding)
995
+ expected = expected.force_encoding(Encoding::UTF_8)
995
996
  text_box.text.should == expected
996
997
  end
997
998
 
@@ -1008,7 +1009,7 @@ describe "Text::Box wrapping" do
1008
1009
  text_box.render
1009
1010
  results_without_accent = text_box.text
1010
1011
 
1011
- results_with_accent.first_line.length.should == results_without_accent.first_line.length
1012
+ first_line(results_with_accent).length.should == first_line(results_without_accent).length
1012
1013
  end
1013
1014
  end
1014
1015
 
@@ -1027,3 +1028,7 @@ end
1027
1028
  def reduce_precision(float)
1028
1029
  ("%.5f" % float).to_f
1029
1030
  end
1031
+
1032
+ def first_line(str)
1033
+ str.each_line { |line| return line }
1034
+ end