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
@@ -109,15 +109,20 @@ describe "drawing bounding boxes" do
109
109
  x.should == [100, 500]
110
110
  end
111
111
 
112
- it "should restore the margin box when bounding box exits" do
113
- margin_box = @pdf.bounds
112
+ it "should restore Document#bounds to the correct margin box on exit" do
113
+ pdf = Prawn::Document.new(:margin => 200)
114
114
 
115
- @pdf.bounding_box [100,500], :width => 100 do
116
- #nothing
115
+ # add a multi-page bounding box
116
+ pdf.bounding_box([100, pdf.bounds.top], :width => 400) do
117
+ pdf.text "The rain in spain falls mainly in the plains.\n" * 30
117
118
  end
118
119
 
119
- @pdf.bounds.should == margin_box
120
+ pdf.start_new_page(:margin => 0)
120
121
 
122
+ x_min, y_min, x_max, y_max = pdf.page.dimensions
123
+
124
+ pdf.bounds.absolute_top_left.should == [x_min, y_max]
125
+ pdf.bounds.absolute_bottom_right.should == [x_max, y_min]
121
126
  end
122
127
 
123
128
  it "should restore the parent bounding box when calls are nested" do
@@ -378,6 +383,18 @@ describe "A canvas" do
378
383
  end
379
384
  @pdf.y.should == 450
380
385
  end
386
+
387
+ it "should restore the original ypos after execution", :issue => 523 do
388
+ doc = Prawn::Document.new(:skip_page_creation => true)
389
+ doc.start_new_page
390
+
391
+ original_ypos = doc.y
392
+
393
+ doc.canvas {}
394
+
395
+ doc.y.should == original_ypos
396
+ end
397
+
381
398
  end
382
399
 
383
400
  describe "Deep-copying" do
@@ -87,6 +87,12 @@ describe "Prawn::Table::Cell" do
87
87
 
88
88
  c.style(:padding => 50, :size => 7)
89
89
  end
90
+
91
+ it "ignores unknown properties" do
92
+ c = cell(:content => 'text')
93
+
94
+ c.style(:foobarbaz => 'frobnitz')
95
+ end
90
96
  end
91
97
 
92
98
  describe "cell width" do
@@ -136,9 +142,6 @@ describe "Prawn::Table::Cell" do
136
142
  c = cell(:content => "text", :padding => 10)
137
143
  min_content_width = c.min_width - c.padding[1] - c.padding[3]
138
144
 
139
- lambda { @pdf.height_of("text", :width => min_content_width) }.
140
- should_not raise_error(Prawn::Errors::CannotFit)
141
-
142
145
  @pdf.height_of("text", :width => min_content_width).should be <
143
146
  (5 * @pdf.height_of("text"))
144
147
  end
@@ -409,7 +412,7 @@ describe "Prawn::Table::Cell" do
409
412
  :border_width => [2, 3, 4, 5])
410
413
  c.border_widths.should == [2, 3, 4, 5]
411
414
  end
412
-
415
+
413
416
  it "should set default border lines to :solid" do
414
417
  c = @pdf.cell(:content => "text")
415
418
  c.border_top_line.should == :solid
@@ -418,7 +421,7 @@ describe "Prawn::Table::Cell" do
418
421
  c.border_left_line.should == :solid
419
422
  c.border_lines.should == [:solid] * 4
420
423
  end
421
-
424
+
422
425
  it "should set border line with :border_..._line" do
423
426
  c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
424
427
  c.border_bottom_line.should == :dotted
@@ -466,6 +469,47 @@ describe "Prawn::Table::Cell" do
466
469
  c.draw
467
470
  end
468
471
 
472
+ it "supports variant styles of the current font" do
473
+ font_path = "#{Prawn::BASEDIR}/data/fonts/Panic+Sans.dfont"
474
+ @pdf.font_families.merge!("Panic Sans" => {
475
+ :normal => { :file => font_path, :font => "PanicSans" },
476
+ :bold => { :file => font_path, :font => "PanicSans-Bold" },
477
+ })
478
+ @pdf.font "Panic Sans"
479
+
480
+ c = cell(:content => "text", :font_style => :bold)
481
+
482
+ box = Prawn::Text::Box.new("text", :document => @pdf)
483
+ Prawn::Text::Box.expects(:new).checking do |text, options|
484
+ text.should == "text"
485
+ options[:style].should == :bold
486
+ @pdf.font.family.should == 'Panic Sans'
487
+ end.at_least_once.returns(box)
488
+
489
+ c.draw
490
+ end
491
+
492
+
493
+ it "uses the style of the current font if none given" do
494
+ font_path = "#{Prawn::BASEDIR}/data/fonts/Panic+Sans.dfont"
495
+ @pdf.font_families.merge!("Panic Sans" => {
496
+ :normal => { :file => font_path, :font => "PanicSans" },
497
+ :bold => { :file => font_path, :font => "PanicSans-Bold" },
498
+ })
499
+ @pdf.font "Panic Sans", :style => :bold
500
+
501
+ c = cell(:content => "text")
502
+
503
+ box = Prawn::Text::Box.new("text", :document => @pdf)
504
+ Prawn::Text::Box.expects(:new).checking do |text, options|
505
+ text.should == "text"
506
+ @pdf.font.family.should == 'Panic Sans'
507
+ @pdf.font.options[:style].should == :bold
508
+ end.at_least_once.returns(box)
509
+
510
+ c.draw
511
+ end
512
+
469
513
  it "should allow inline formatting in cells" do
470
514
  c = cell(:content => "foo <b>bar</b> baz", :inline_format => true)
471
515
 
@@ -30,4 +30,36 @@ describe "A column box" do
30
30
  @pdf.bounds.right.should == 500
31
31
  end
32
32
  end
33
+
34
+ it "does not reset the top margin on a new page by default" do
35
+ create_pdf
36
+ page_top = @pdf.cursor
37
+ @pdf.move_down 50
38
+ init_column_top = @pdf.cursor
39
+ @pdf.column_box [0, @pdf.cursor], :width => 500,
40
+ :height => 200, :columns => 2 do
41
+
42
+ @pdf.bounds.move_past_bottom
43
+ @pdf.bounds.move_past_bottom
44
+
45
+ @pdf.bounds.absolute_top.should == init_column_top
46
+ @pdf.bounds.absolute_top.should_not == page_top
47
+ end
48
+ end
49
+
50
+ it "does reset the top margin when reflow_margins is set" do
51
+ create_pdf
52
+ page_top = @pdf.cursor
53
+ @pdf.move_down 50
54
+ init_column_top = @pdf.cursor
55
+ @pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true,
56
+ :height => 200, :columns => 2 do
57
+
58
+ @pdf.bounds.move_past_bottom
59
+ @pdf.bounds.move_past_bottom
60
+
61
+ @pdf.bounds.absolute_top.should == page_top
62
+ @pdf.bounds.absolute_top.should_not == init_column_top
63
+ end
64
+ end
33
65
  end
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "When creating destinations" do
4
6
 
5
- describe "When creating destinations" do
6
-
7
7
  before(:each) { create_pdf }
8
-
9
- it "should add entry to Dests name tree" do
8
+
9
+ it "should add entry to Dests name tree" do
10
10
  @pdf.dests.data.empty?.should == true
11
11
  @pdf.add_dest "candy", "chocolate"
12
12
  @pdf.dests.data.size.should == 1
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "tempfile"
3
3
 
4
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
 
6
6
  describe "Prawn::Document.new" do
7
7
  it "should not modify its argument" do
@@ -15,9 +15,9 @@ describe "The cursor" do
15
15
  it "should == pdf.y - bounds.absolute_bottom" do
16
16
  pdf = Prawn::Document.new
17
17
  pdf.cursor.should == pdf.bounds.top
18
-
18
+
19
19
  pdf.y = 300
20
- pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
20
+ pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
21
21
  end
22
22
 
23
23
  it "should be able to move relative to the bottom margin" do
@@ -27,12 +27,38 @@ describe "The cursor" do
27
27
  pdf.cursor.should == 10
28
28
  pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom
29
29
  end
30
- end
30
+ end
31
+
32
+ describe "when generating a document with a custom text formatter" do
33
+ it "should use the provided text formatter" do
34
+ class TestTextFormatter
35
+ def self.format(string)
36
+ [
37
+ {
38
+ text: string.gsub("Dr. Who?", "Just 'The Doctor'."),
39
+ styles: [],
40
+ color: nil,
41
+ link: nil,
42
+ anchor: nil,
43
+ local: nil,
44
+ font: nil,
45
+ size: nil,
46
+ character_spacing: nil
47
+ }
48
+ ]
49
+ end
50
+ end
51
+ pdf = Prawn::Document.new text_formatter: TestTextFormatter
52
+ pdf.text "Dr. Who?", inline_format: true
53
+ text = PDF::Inspector::Text.analyze(pdf.render)
54
+ text.strings.first.should == "Just 'The Doctor'."
55
+ end
56
+ end
31
57
 
32
58
  describe "when generating a document from a subclass" do
33
59
  it "should be an instance of the subclass" do
34
60
  custom_document = Class.new(Prawn::Document)
35
- custom_document.generate(Tempfile.new("generate_test").path) do |e|
61
+ custom_document.generate(Tempfile.new("generate_test").path) do |e|
36
62
  e.class.should == custom_document
37
63
  e.should be_a_kind_of(Prawn::Document)
38
64
  end
@@ -63,27 +89,27 @@ describe "when generating a document from a subclass" do
63
89
 
64
90
  end
65
91
 
66
-
67
- describe "When creating multi-page documents" do
68
-
92
+
93
+ describe "When creating multi-page documents" do
94
+
69
95
  before(:each) { create_pdf }
70
-
71
- it "should initialize with a single page" do
96
+
97
+ it "should initialize with a single page" do
72
98
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
73
-
74
- page_counter.pages.size.should == 1
75
- @pdf.page_count.should == 1
99
+
100
+ page_counter.pages.size.should == 1
101
+ @pdf.page_count.should == 1
76
102
  end
77
-
103
+
78
104
  it "should provide an accurate page_count" do
79
- 3.times { @pdf.start_new_page }
105
+ 3.times { @pdf.start_new_page }
80
106
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
81
-
107
+
82
108
  page_counter.pages.size.should == 4
83
109
  @pdf.page_count.should == 4
84
- end
85
-
86
- end
110
+ end
111
+
112
+ end
87
113
 
88
114
  describe "When beginning each new page" do
89
115
 
@@ -102,11 +128,11 @@ describe "When beginning each new page" do
102
128
  @pdf.instance_variable_defined?(:@background).should == true
103
129
  @pdf.instance_variable_get(:@background).should == @filename
104
130
  end
105
-
106
-
131
+
132
+
107
133
  end
108
-
109
-
134
+
135
+
110
136
  end
111
137
 
112
138
  describe "Prawn::Document#float" do
@@ -119,7 +145,7 @@ describe "Prawn::Document#float" do
119
145
 
120
146
  it "should teleport across pages if necessary" do
121
147
  create_pdf
122
-
148
+
123
149
  @pdf.float do
124
150
  @pdf.text "Foo"
125
151
  @pdf.start_new_page
@@ -156,7 +182,7 @@ end
156
182
 
157
183
  describe "on_page_create callback" do
158
184
  before do
159
- create_pdf
185
+ create_pdf
160
186
  end
161
187
 
162
188
  it "should be invoked with document" do
@@ -177,34 +203,34 @@ describe "on_page_create callback" do
177
203
 
178
204
  5.times { @pdf.start_new_page }
179
205
  end
180
-
206
+
181
207
  it "should be replaceable" do
182
208
  trigger1 = mock()
183
209
  trigger1.expects(:fire).times(1)
184
-
210
+
185
211
  trigger2 = mock()
186
212
  trigger2.expects(:fire).times(1)
187
213
 
188
214
  @pdf.on_page_create { trigger1.fire }
189
-
215
+
190
216
  @pdf.start_new_page
191
-
217
+
192
218
  @pdf.on_page_create { trigger2.fire }
193
-
219
+
194
220
  @pdf.start_new_page
195
221
  end
196
-
222
+
197
223
  it "should be clearable by calling on_page_create without a block" do
198
224
  trigger = mock()
199
225
  trigger.expects(:fire).times(1)
200
226
 
201
227
  @pdf.on_page_create { trigger.fire }
202
228
 
203
- @pdf.start_new_page
204
-
229
+ @pdf.start_new_page
230
+
205
231
  @pdf.on_page_create
206
-
207
- @pdf.start_new_page
232
+
233
+ @pdf.start_new_page
208
234
  end
209
235
 
210
236
  end
@@ -214,8 +240,8 @@ describe "Document compression" do
214
240
  it "should not compress the page content stream if compression is disabled" do
215
241
 
216
242
  pdf = Prawn::Document.new(:compress => false)
217
- pdf.page.content.stubs(:compress_stream).returns(true)
218
- pdf.page.content.expects(:compress_stream).never
243
+ pdf.page.content.stream.stubs(:compress!).returns(true)
244
+ pdf.page.content.stream.expects(:compress!).never
219
245
 
220
246
  pdf.text "Hi There" * 20
221
247
  pdf.render
@@ -224,8 +250,8 @@ describe "Document compression" do
224
250
  it "should compress the page content stream if compression is enabled" do
225
251
 
226
252
  pdf = Prawn::Document.new(:compress => true)
227
- pdf.page.content.stubs(:compress_stream).returns(true)
228
- pdf.page.content.expects(:compress_stream).once
253
+ pdf.page.content.stream.stubs(:compress!).returns(true)
254
+ pdf.page.content.stream.expects(:compress!).once
229
255
 
230
256
  pdf.text "Hi There" * 20
231
257
  pdf.render
@@ -240,9 +266,9 @@ describe "Document compression" do
240
266
  end
241
267
 
242
268
  doc_compressed.render.length.should be < doc_uncompressed.render.length
243
- end
269
+ end
244
270
 
245
- end
271
+ end
246
272
 
247
273
  describe "Document metadata" do
248
274
  it "should output strings as UTF-16 with a byte order mark" do
@@ -262,11 +288,10 @@ describe "When reopening pages" do
262
288
  pdf.go_to_page 1
263
289
  pdf.text "More for page 1"
264
290
  end
265
-
266
- # MalformedPDFError raised if content stream actual length does not match
267
- # dictionary length
268
- lambda{ PDF::Inspector::Page.analyze(@pdf.render) }.
269
- should_not raise_error(PDF::Reader::MalformedPDFError)
291
+
292
+ # Indirectly verify that the actual length does not match dictionary length.
293
+ # If it isn't, a MalformedPDFError will be raised
294
+ PDF::Inspector::Page.analyze(@pdf.render)
270
295
  end
271
296
 
272
297
  it "should insert pages after the current page when calling start_new_page" do
@@ -298,21 +323,21 @@ describe "When setting page size" do
298
323
  it "should default to LETTER" do
299
324
  @pdf = Prawn::Document.new
300
325
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
301
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
302
- end
303
-
304
- (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
326
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"]
327
+ end
328
+
329
+ (PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
305
330
  it "should provide #{k} geometry" do
306
331
  @pdf = Prawn::Document.new(:page_size => k)
307
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
308
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
332
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
333
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES[k]
309
334
  end
310
335
  end
311
-
312
- it "should allow custom page size" do
336
+
337
+ it "should allow custom page size" do
313
338
  @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
314
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
315
- pages.first[:size].should == [1920, 1080]
339
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
340
+ pages.first[:size].should == [1920, 1080]
316
341
  end
317
342
 
318
343
 
@@ -321,25 +346,25 @@ describe "When setting page size" do
321
346
  @pdf.start_new_page
322
347
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
323
348
  pages.each do |page|
324
- page[:size].should == Prawn::Document::PageGeometry::SIZES["LEGAL"]
349
+ page[:size].should == PDF::Core::PageGeometry::SIZES["LEGAL"]
325
350
  end
326
351
  end
327
352
 
328
- end
353
+ end
329
354
 
330
355
  describe "When setting page layout" do
331
356
  it "should reverse coordinates for landscape" do
332
357
  @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
333
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
334
- pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
335
- end
358
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
359
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES["A4"].reverse
360
+ end
336
361
 
337
362
  it "should retain page layout by default when starting a new page" do
338
363
  @pdf = Prawn::Document.new(:page_layout => :landscape)
339
364
  @pdf.start_new_page(:trace => true)
340
365
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
341
366
  pages.each do |page|
342
- page[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"].reverse
367
+ page[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"].reverse
343
368
  end
344
369
  end
345
370
 
@@ -362,19 +387,19 @@ describe "The mask() feature" do
362
387
  @pdf.line_width.should_not == line_width
363
388
  end
364
389
  @pdf.y.should == y
365
- @pdf.line_width.should == line_width
390
+ @pdf.line_width.should == line_width
366
391
  end
367
392
  end
368
393
 
369
394
  describe "The group() feature" do
370
- it "should return a true value if the content fits on one page" do
395
+ xit "should return a true value if the content fits on one page" do
371
396
  pdf = Prawn::Document.new do
372
397
  val = group { text "Hello"; text "World" }
373
398
  (!!val).should == true
374
399
  end
375
400
  end
376
401
 
377
- it "should group a simple block on a single page" do
402
+ xit "should group a simple block on a single page" do
378
403
  pdf = Prawn::Document.new do
379
404
  self.y = 50
380
405
  val = group do
@@ -391,7 +416,7 @@ describe "The group() feature" do
391
416
  pages[1][:strings].should == ["Hello", "World"]
392
417
  end
393
418
 
394
- it "should raise_error CannotGroup if the content is too tall" do
419
+ xit "should raise_error CannotGroup if the content is too tall" do
395
420
  lambda {
396
421
  Prawn::Document.new do
397
422
  group do
@@ -401,7 +426,7 @@ describe "The group() feature" do
401
426
  }.should raise_error(Prawn::Errors::CannotGroup)
402
427
  end
403
428
 
404
- it "should group within individual column boxes" do
429
+ xit "should group within individual column boxes" do
405
430
  pdf = Prawn::Document.new do
406
431
  # Set up columns with grouped blocks of 0..49. 0 to 49 is slightly short
407
432
  # of the height of one page / column, so each column should get its own
@@ -422,25 +447,23 @@ describe "The group() feature" do
422
447
  end
423
448
 
424
449
  describe "The render() feature" do
425
- if "spec".respond_to?(:encode!)
426
- it "should return a 8 bit encoded string on a m17n aware VM" do
427
- @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
428
- @pdf.line [100,100], [200,200]
429
- str = @pdf.render
430
- str.encoding.to_s.should == "ASCII-8BIT"
431
- end
450
+ it "should return a 8 bit encoded string on a m17n aware VM" do
451
+ @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
452
+ @pdf.line [100,100], [200,200]
453
+ str = @pdf.render
454
+ str.encoding.to_s.should == "ASCII-8BIT"
432
455
  end
433
456
 
434
457
  it "should trigger before_render callbacks just before rendering" do
435
458
  pdf = Prawn::Document.new
436
-
459
+
437
460
  seq = sequence("callback_order")
438
461
 
439
462
  # Verify the order: finalize -> fire callbacks -> render body
440
463
  pdf.expects(:finalize_all_page_contents).in_sequence(seq)
441
464
  trigger = mock()
442
465
  trigger.expects(:fire).in_sequence(seq)
443
-
466
+
444
467
  # Store away the render_body method to be called below
445
468
  render_body = pdf.method(:render_body)
446
469
  pdf.expects(:render_body).in_sequence(seq)
@@ -461,35 +484,6 @@ describe "The render() feature" do
461
484
  end
462
485
  end
463
486
 
464
- describe "The :optimize_objects option" do
465
- before(:all) do
466
- @wasteful_doc = lambda do |pdf|
467
- pdf.transaction do
468
- pdf.start_new_page
469
- pdf.text "Hidden text"
470
- pdf.rollback
471
- end
472
-
473
- pdf.text "Hello world"
474
- end
475
- end
476
-
477
- it "should result in fewer objects when enabled" do
478
- wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
479
- frugal_pdf = Prawn::Document.new(:optimize_objects => true,
480
- &@wasteful_doc)
481
- frugal_pdf.render.size.should be < wasteful_pdf.render.size
482
- end
483
-
484
- it "should default to :false" do
485
- default_pdf = Prawn::Document.new(&@wasteful_doc)
486
- wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
487
- &@wasteful_doc)
488
- default_pdf.render.size.should == wasteful_pdf.render.size
489
- end
490
-
491
- end
492
-
493
487
  describe "PDF file versions" do
494
488
  it "should default to 1.3" do
495
489
  @pdf = Prawn::Document.new
@@ -565,25 +559,25 @@ describe "The number_pages method" do
565
559
  before do
566
560
  @pdf = Prawn::Document.new(:skip_page_creation => true)
567
561
  end
568
-
562
+
569
563
  it "replaces the '<page>' string with the proper page number" do
570
564
  @pdf.start_new_page
571
565
  @pdf.expects(:text_box).with("1, test", { :height => 50 })
572
566
  @pdf.number_pages "<page>, test", {:page_filter => :all}
573
567
  end
574
-
568
+
575
569
  it "replaces the '<total>' string with the total page count" do
576
570
  @pdf.start_new_page
577
571
  @pdf.expects(:text_box).with("test, 1", { :height => 50 })
578
572
  @pdf.number_pages "test, <total>", {:page_filter => :all}
579
573
  end
580
-
574
+
581
575
  it "must print each page if given the :all page_filter" do
582
576
  10.times { @pdf.start_new_page }
583
577
  @pdf.expects(:text_box).times(10)
584
578
  @pdf.number_pages "test", {:page_filter => :all}
585
579
  end
586
-
580
+
587
581
  it "must print each page if no :page_filter is specified" do
588
582
  10.times { @pdf.start_new_page }
589
583
  @pdf.expects(:text_box).times(10)
@@ -595,8 +589,8 @@ describe "The number_pages method" do
595
589
  @pdf.expects(:text_box).never
596
590
  @pdf.number_pages "test", {:page_filter => nil}
597
591
  end
598
-
599
- context "start_count_at option" do
592
+
593
+ context "start_count_at option" do
600
594
  [1, 2].each do |startat|
601
595
  context "equal to #{startat}" do
602
596
  it "increments the pages" do
@@ -605,10 +599,10 @@ describe "The number_pages method" do
605
599
  @pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
606
600
  @pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
607
601
  @pdf.number_pages "<page> <total>", options
608
- end
602
+ end
609
603
  end
610
604
  end
611
-
605
+
612
606
  [0, nil].each do |val|
613
607
  context "equal to #{val}" do
614
608
  it "defaults to start at page 1" do
@@ -622,7 +616,7 @@ describe "The number_pages method" do
622
616
  end
623
617
  end
624
618
  end
625
-
619
+
626
620
  context "total_pages option" do
627
621
  it "allows the total pages count to be overridden" do
628
622
  2.times { @pdf.start_new_page }
@@ -631,7 +625,7 @@ describe "The number_pages method" do
631
625
  @pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
632
626
  end
633
627
  end
634
-
628
+
635
629
  context "special page filter" do
636
630
  context "such as :odd" do
637
631
  it "increments the pages" do
@@ -704,11 +698,11 @@ describe "The page_match? method" do
704
698
  @pdf = Prawn::Document.new(:skip_page_creation => true)
705
699
  10.times {@pdf.start_new_page}
706
700
  end
707
-
701
+
708
702
  it "returns nil given no filter" do
709
703
  @pdf.page_match?(:nil, 1).should be_false
710
704
  end
711
-
705
+
712
706
  it "must provide an :all filter" do
713
707
  (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
714
708
  end
@@ -732,5 +726,5 @@ describe "The page_match? method" do
732
726
  it "must be able to filter by an arbitrary proc" do
733
727
  fltr = lambda { |x| x == 1 or x % 3 == 0 }
734
728
  (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
735
- end
729
+ end
736
730
  end