prawn 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/Gemfile +18 -0
  2. data/README.md +5 -3
  3. data/Rakefile +8 -14
  4. data/data/pdfs/nested_pages.pdf +13 -13
  5. data/lib/prawn.rb +3 -1
  6. data/lib/prawn/compatibility.rb +46 -10
  7. data/lib/prawn/core.rb +3 -1
  8. data/lib/prawn/core/document_state.rb +2 -1
  9. data/lib/prawn/core/object_store.rb +61 -5
  10. data/lib/prawn/core/page.rb +3 -6
  11. data/lib/prawn/core/pdf_object.rb +21 -4
  12. data/lib/prawn/core/reference.rb +6 -2
  13. data/lib/prawn/core/text.rb +4 -4
  14. data/lib/prawn/core/text/formatted/line_wrap.rb +23 -8
  15. data/lib/prawn/document.rb +21 -15
  16. data/lib/prawn/document/bounding_box.rb +3 -3
  17. data/lib/prawn/document/column_box.rb +22 -4
  18. data/lib/prawn/document/snapshot.rb +1 -1
  19. data/lib/prawn/encoding.rb +1 -1
  20. data/lib/prawn/errors.rb +4 -0
  21. data/lib/prawn/font.rb +1 -1
  22. data/lib/prawn/font/afm.rb +30 -72
  23. data/lib/prawn/font/ttf.rb +6 -33
  24. data/lib/prawn/graphics.rb +148 -23
  25. data/lib/prawn/graphics/color.rb +8 -1
  26. data/lib/prawn/graphics/patterns.rb +137 -0
  27. data/lib/prawn/images.rb +25 -19
  28. data/lib/prawn/images/jpg.rb +4 -4
  29. data/lib/prawn/images/png.rb +18 -12
  30. data/lib/prawn/security.rb +6 -4
  31. data/lib/prawn/soft_mask.rb +94 -0
  32. data/lib/prawn/table.rb +136 -31
  33. data/lib/prawn/table/cell.rb +260 -29
  34. data/lib/prawn/table/cell/span_dummy.rb +88 -0
  35. data/lib/prawn/table/cell/text.rb +36 -14
  36. data/lib/prawn/table/cells.rb +91 -41
  37. data/lib/prawn/text.rb +3 -2
  38. data/lib/prawn/text/formatted/box.rb +14 -5
  39. data/lib/prawn/text/formatted/fragment.rb +33 -22
  40. data/lib/prawn/text/formatted/parser.rb +5 -2
  41. data/lib/prawn/utilities.rb +44 -0
  42. data/manual/basic_concepts/adding_pages.rb +27 -0
  43. data/manual/basic_concepts/basic_concepts.rb +34 -0
  44. data/manual/basic_concepts/creation.rb +39 -0
  45. data/manual/basic_concepts/cursor.rb +33 -0
  46. data/manual/basic_concepts/measurement.rb +25 -0
  47. data/manual/basic_concepts/origin.rb +38 -0
  48. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  49. data/manual/bounding_box/bounding_box.rb +39 -0
  50. data/manual/bounding_box/bounds.rb +49 -0
  51. data/manual/bounding_box/canvas.rb +24 -0
  52. data/manual/bounding_box/creation.rb +23 -0
  53. data/manual/bounding_box/indentation.rb +46 -0
  54. data/manual/bounding_box/nesting.rb +45 -0
  55. data/manual/bounding_box/russian_boxes.rb +40 -0
  56. data/manual/bounding_box/stretchy.rb +31 -0
  57. data/manual/document_and_page_options/background.rb +27 -0
  58. data/manual/document_and_page_options/document_and_page_options.rb +31 -0
  59. data/manual/document_and_page_options/metadata.rb +23 -0
  60. data/manual/document_and_page_options/page_margins.rb +38 -0
  61. data/manual/document_and_page_options/page_size.rb +34 -0
  62. data/manual/example_file.rb +116 -0
  63. data/manual/example_helper.rb +430 -0
  64. data/manual/example_package.rb +53 -0
  65. data/manual/example_section.rb +46 -0
  66. data/manual/graphics/circle_and_ellipse.rb +22 -0
  67. data/manual/graphics/color.rb +24 -0
  68. data/manual/graphics/common_lines.rb +28 -0
  69. data/manual/graphics/fill_and_stroke.rb +42 -0
  70. data/manual/graphics/fill_rules.rb +37 -0
  71. data/manual/graphics/gradients.rb +37 -0
  72. data/manual/graphics/graphics.rb +58 -0
  73. data/manual/graphics/helper.rb +17 -0
  74. data/manual/graphics/line_width.rb +35 -0
  75. data/manual/graphics/lines_and_curves.rb +41 -0
  76. data/manual/graphics/polygon.rb +29 -0
  77. data/manual/graphics/rectangle.rb +21 -0
  78. data/manual/graphics/rotate.rb +28 -0
  79. data/manual/graphics/scale.rb +41 -0
  80. data/manual/graphics/soft_masks.rb +46 -0
  81. data/manual/graphics/stroke_cap.rb +31 -0
  82. data/manual/graphics/stroke_dash.rb +43 -0
  83. data/manual/graphics/stroke_join.rb +30 -0
  84. data/manual/graphics/translate.rb +29 -0
  85. data/manual/graphics/transparency.rb +35 -0
  86. data/manual/images/absolute_position.rb +23 -0
  87. data/manual/images/fit.rb +21 -0
  88. data/manual/images/horizontal.rb +25 -0
  89. data/manual/images/images.rb +40 -0
  90. data/manual/images/plain_image.rb +18 -0
  91. data/manual/images/scale.rb +22 -0
  92. data/manual/images/vertical.rb +28 -0
  93. data/manual/images/width_and_height.rb +25 -0
  94. data/manual/layout/boxes.rb +27 -0
  95. data/manual/layout/content.rb +25 -0
  96. data/manual/layout/layout.rb +28 -0
  97. data/manual/layout/simple_grid.rb +23 -0
  98. data/manual/manual/cover.rb +26 -0
  99. data/manual/manual/foreword.rb +13 -0
  100. data/manual/manual/how_to_read_this_manual.rb +41 -0
  101. data/manual/manual/manual.rb +36 -0
  102. data/manual/outline/add_subsection_to.rb +61 -0
  103. data/manual/outline/insert_section_after.rb +47 -0
  104. data/manual/outline/outline.rb +32 -0
  105. data/manual/outline/sections_and_pages.rb +67 -0
  106. data/manual/repeatable_content/page_numbering.rb +54 -0
  107. data/manual/repeatable_content/repeatable_content.rb +31 -0
  108. data/manual/repeatable_content/repeater.rb +55 -0
  109. data/manual/repeatable_content/stamp.rb +41 -0
  110. data/manual/security/encryption.rb +31 -0
  111. data/manual/security/permissions.rb +38 -0
  112. data/manual/security/security.rb +28 -0
  113. data/manual/syntax_highlight.rb +52 -0
  114. data/manual/table/basic_block.rb +53 -0
  115. data/manual/table/before_rendering_page.rb +26 -0
  116. data/manual/table/cell_border_lines.rb +24 -0
  117. data/manual/table/cell_borders_and_bg.rb +31 -0
  118. data/manual/table/cell_dimensions.rb +30 -0
  119. data/manual/table/cell_text.rb +38 -0
  120. data/manual/table/column_widths.rb +30 -0
  121. data/manual/table/content_and_subtables.rb +39 -0
  122. data/manual/table/creation.rb +27 -0
  123. data/manual/table/filtering.rb +36 -0
  124. data/manual/table/flow_and_header.rb +17 -0
  125. data/manual/table/image_cells.rb +33 -0
  126. data/manual/table/position.rb +29 -0
  127. data/manual/table/row_colors.rb +20 -0
  128. data/manual/table/span.rb +30 -0
  129. data/manual/table/style.rb +22 -0
  130. data/manual/table/table.rb +52 -0
  131. data/manual/table/width.rb +27 -0
  132. data/manual/templates/full_template.rb +23 -0
  133. data/manual/templates/page_template.rb +47 -0
  134. data/manual/templates/templates.rb +26 -0
  135. data/manual/text/alignment.rb +44 -0
  136. data/manual/text/color.rb +24 -0
  137. data/manual/text/column_box.rb +32 -0
  138. data/manual/text/fallback_fonts.rb +37 -0
  139. data/manual/text/font.rb +41 -0
  140. data/manual/text/font_size.rb +45 -0
  141. data/manual/text/font_style.rb +23 -0
  142. data/manual/text/formatted_callbacks.rb +60 -0
  143. data/manual/text/formatted_text.rb +50 -0
  144. data/manual/text/free_flowing_text.rb +51 -0
  145. data/manual/text/group.rb +29 -0
  146. data/manual/text/inline.rb +43 -0
  147. data/manual/text/kerning_and_character_spacing.rb +39 -0
  148. data/manual/text/leading.rb +25 -0
  149. data/manual/text/line_wrapping.rb +41 -0
  150. data/manual/text/paragraph_indentation.rb +26 -0
  151. data/manual/text/positioned_text.rb +38 -0
  152. data/manual/text/registering_families.rb +48 -0
  153. data/manual/text/rendering_and_color.rb +37 -0
  154. data/manual/text/right_to_left_text.rb +43 -0
  155. data/manual/text/rotation.rb +43 -0
  156. data/manual/text/single_usage.rb +37 -0
  157. data/manual/text/text.rb +75 -0
  158. data/manual/text/text_box_excess.rb +32 -0
  159. data/manual/text/text_box_extensions.rb +45 -0
  160. data/manual/text/text_box_overflow.rb +44 -0
  161. data/manual/text/utf8.rb +28 -0
  162. data/manual/text/win_ansi_charset.rb +59 -0
  163. data/prawn.gemspec +10 -7
  164. data/spec/bounding_box_spec.rb +107 -17
  165. data/spec/cell_spec.rb +66 -40
  166. data/spec/column_box_spec.rb +33 -0
  167. data/spec/document_spec.rb +45 -24
  168. data/spec/extensions/encoding_helpers.rb +6 -0
  169. data/spec/extensions/mocha.rb +1 -0
  170. data/spec/font_spec.rb +71 -53
  171. data/spec/formatted_text_arranger_spec.rb +19 -19
  172. data/spec/formatted_text_box_spec.rb +16 -16
  173. data/spec/formatted_text_fragment_spec.rb +6 -6
  174. data/spec/graphics_spec.rb +96 -31
  175. data/spec/grid_spec.rb +2 -2
  176. data/spec/images_spec.rb +18 -10
  177. data/spec/jpg_spec.rb +1 -1
  178. data/spec/line_wrap_spec.rb +14 -14
  179. data/spec/measurement_units_spec.rb +2 -2
  180. data/spec/name_tree_spec.rb +6 -6
  181. data/spec/object_store_spec.rb +17 -17
  182. data/spec/outline_spec.rb +35 -17
  183. data/spec/pdf_object_spec.rb +3 -1
  184. data/spec/png_spec.rb +22 -19
  185. data/spec/reference_spec.rb +24 -1
  186. data/spec/repeater_spec.rb +9 -9
  187. data/spec/security_spec.rb +3 -3
  188. data/spec/snapshot_spec.rb +3 -3
  189. data/spec/soft_mask_spec.rb +117 -0
  190. data/spec/span_spec.rb +4 -4
  191. data/spec/spec_helper.rb +12 -6
  192. data/spec/stamp_spec.rb +12 -12
  193. data/spec/stroke_styles_spec.rb +5 -5
  194. data/spec/table_spec.rb +458 -88
  195. data/spec/template_spec.rb +108 -54
  196. data/spec/text_at_spec.rb +17 -17
  197. data/spec/text_box_spec.rb +76 -45
  198. data/spec/text_rendering_mode_spec.rb +5 -5
  199. data/spec/text_spacing_spec.rb +4 -4
  200. data/spec/text_spec.rb +44 -40
  201. metadata +419 -250
  202. data/lib/prawn/graphics/gradient.rb +0 -84
  203. data/lib/prawn/security/arcfour.rb +0 -51
@@ -35,27 +35,27 @@ describe "Prawn::ObjectStore" do
35
35
  end
36
36
 
37
37
  it "should import all objects from a PDF that has an indirect reference in a stream dict" do
38
- filename = "#{Prawn::BASEDIR}/data/pdfs/indirect_reference.pdf"
38
+ filename = "#{Prawn::DATADIR}/pdfs/indirect_reference.pdf"
39
39
  store = Prawn::Core::ObjectStore.new(:template => filename)
40
40
  store.size.should == 8
41
41
  end
42
42
 
43
- it "should raise ArgumentError when given a file that doesn exist as a template" do
43
+ it "should raise_error ArgumentError when given a file that doesn exist as a template" do
44
44
  filename = "not_really_there.pdf"
45
45
 
46
- lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should.raise(ArgumentError)
46
+ lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(ArgumentError)
47
47
  end
48
48
 
49
- it "should raise Prawn::Errors::TemplateError when given a non PDF as a template" do
50
- filename = "#{Prawn::BASEDIR}/data/images/dice.png"
49
+ it "should raise_error Prawn::Errors::TemplateError when given a non PDF as a template" do
50
+ filename = "#{Prawn::DATADIR}/images/dice.png"
51
51
 
52
- lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should.raise(Prawn::Errors::TemplateError)
52
+ lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(Prawn::Errors::TemplateError)
53
53
  end
54
54
 
55
- it "should raise Prawn::Errors::TemplateError when given an encrypted PDF as a template" do
56
- filename = "#{Prawn::BASEDIR}/data/pdfs/encrypted.pdf"
55
+ it "should raise_error Prawn::Errors::TemplateError when given an encrypted PDF as a template" do
56
+ filename = "#{Prawn::DATADIR}/pdfs/encrypted.pdf"
57
57
 
58
- lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should.raise(Prawn::Errors::TemplateError)
58
+ lambda { Prawn::Core::ObjectStore.new(:template => filename) }.should raise_error(Prawn::Errors::TemplateError)
59
59
  end
60
60
 
61
61
  it "should add to its objects when ref() is called" do
@@ -100,7 +100,7 @@ describe "Prawn::ObjectStore#compact" do
100
100
  old_size = store.size
101
101
  store.compact
102
102
 
103
- store.size.should.be < old_size
103
+ store.size.should be < old_size
104
104
  store.map{ |o| o.identifier }.should == (1..store.size).to_a
105
105
  end
106
106
 
@@ -111,44 +111,44 @@ describe "Prawn::ObjectStore#compact" do
111
111
  old_size = store.size
112
112
  store.compact
113
113
 
114
- store.size.should.be < old_size
114
+ store.size.should be < old_size
115
115
  store.map{ |o| o.identifier }.should == (1..store.size).to_a
116
116
  end
117
117
  end
118
118
 
119
119
  describe "Prawn::ObjectStorie#object_id_for_page" do
120
120
  it "should return the object ID of an imported template page" do
121
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
121
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
122
122
  store = Prawn::Core::ObjectStore.new(:template => filename)
123
123
  store.object_id_for_page(0).should == 4
124
124
  end
125
125
 
126
126
  it "should return the object ID of the first imported template page" do
127
- filename = "#{Prawn::BASEDIR}/data/pdfs/two_hexagons.pdf"
127
+ filename = "#{Prawn::DATADIR}/pdfs/two_hexagons.pdf"
128
128
  store = Prawn::Core::ObjectStore.new(:template => filename)
129
129
  store.object_id_for_page(1).should == 4
130
130
  end
131
131
 
132
132
  it "should return the object ID of the last imported template page" do
133
- filename = "#{Prawn::BASEDIR}/data/pdfs/two_hexagons.pdf"
133
+ filename = "#{Prawn::DATADIR}/pdfs/two_hexagons.pdf"
134
134
  store = Prawn::Core::ObjectStore.new(:template => filename)
135
135
  store.object_id_for_page(-1).should == 6
136
136
  end
137
137
 
138
138
  it "should return the object ID of the first page of a template that uses nested Pages" do
139
- filename = "#{Prawn::BASEDIR}/data/pdfs/nested_pages.pdf"
139
+ filename = "#{Prawn::DATADIR}/pdfs/nested_pages.pdf"
140
140
  store = Prawn::Core::ObjectStore.new(:template => filename)
141
141
  store.object_id_for_page(1).should == 5
142
142
  end
143
143
 
144
144
  it "should return the object ID of the last page of a template that uses nested Pages" do
145
- filename = "#{Prawn::BASEDIR}/data/pdfs/nested_pages.pdf"
145
+ filename = "#{Prawn::DATADIR}/pdfs/nested_pages.pdf"
146
146
  store = Prawn::Core::ObjectStore.new(:template => filename)
147
147
  store.object_id_for_page(-1).should == 8
148
148
  end
149
149
 
150
150
  it "should return nil if given an invalid page number" do
151
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
151
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
152
152
  store = Prawn::Core::ObjectStore.new(:template => filename)
153
153
  store.object_id_for_page(10).should == nil
154
154
  end
@@ -36,7 +36,7 @@ describe "Outline" do
36
36
  end
37
37
 
38
38
  it "should create a root outline dictionary item" do
39
- assert_not_nil @outline_root
39
+ @outline_root.should_not be_nil
40
40
  end
41
41
 
42
42
  it "should set the first and last top items of the root outline dictionary item" do
@@ -46,7 +46,7 @@ describe "Outline" do
46
46
 
47
47
  describe "#create_outline_item" do
48
48
  it "should create outline items for each section and page" do
49
- [@section_1, @page_1, @page_2].each {|item| assert_not_nil item}
49
+ [@section_1, @page_1, @page_2].each {|item| item.should_not be_nil}
50
50
  end
51
51
  end
52
52
 
@@ -70,7 +70,7 @@ describe "Outline" do
70
70
 
71
71
  it "should add the count of all descendant items" do
72
72
  @outline_root[:Count].should == 3
73
- @section_1[:Count].should.abs == 2
73
+ @section_1[:Count].abs.should == 2
74
74
  @page_1[:Count].should == 0
75
75
  @page_2[:Count].should == 0
76
76
  end
@@ -100,7 +100,7 @@ describe "Outline" do
100
100
  end
101
101
 
102
102
  it "should add new outline items to document" do
103
- [@section_2, @page_3].each { |item| assert_not_nil item}
103
+ [@section_2, @page_3].each { |item| item.should_not be_nil}
104
104
  end
105
105
 
106
106
  it "should reset the last items for root outline dictionary" do
@@ -139,7 +139,7 @@ describe "Outline" do
139
139
  end
140
140
 
141
141
  it "should add new outline items to document" do
142
- [@subsection, @added_page_3].each { |item| assert_not_nil item}
142
+ [@subsection, @added_page_3].each { |item| item.should_not be_nil}
143
143
  end
144
144
 
145
145
  it "should reset the last item for parent item dictionary" do
@@ -186,7 +186,7 @@ describe "Outline" do
186
186
  end
187
187
 
188
188
  it "should add new outline items to document" do
189
- [@subsection, @added_page_3].each { |item| assert_not_nil item}
189
+ [@subsection, @added_page_3].each { |item| item.should_not be_nil}
190
190
  end
191
191
 
192
192
  it "should reset the first item for parent item dictionary" do
@@ -217,7 +217,7 @@ describe "Outline" do
217
217
  end
218
218
 
219
219
  it "should require an existing title" do
220
- assert_raise Prawn::Errors::UnknownOutlineTitle do
220
+ lambda do
221
221
  @pdf.go_to_page 1
222
222
  @pdf.start_new_page
223
223
  @pdf.text "Inserted Page"
@@ -227,7 +227,7 @@ describe "Outline" do
227
227
  end
228
228
  end
229
229
  render_and_find_objects
230
- end
230
+ end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
231
231
  end
232
232
  end
233
233
 
@@ -246,13 +246,13 @@ describe "Outline" do
246
246
 
247
247
  it "should insert new outline items to document" do
248
248
  render_and_find_objects
249
- assert_not_nil @inserted_page
249
+ @inserted_page.should_not be_nil
250
250
  end
251
251
 
252
252
  it "should adjust the count of all ancestors" do
253
253
  render_and_find_objects
254
254
  @outline_root[:Count].should == 4
255
- @section_1[:Count].should.abs == 3
255
+ @section_1[:Count].abs.should == 3
256
256
  end
257
257
 
258
258
  describe "#adjust_relations" do
@@ -317,7 +317,7 @@ describe "Outline" do
317
317
  end
318
318
 
319
319
  it "should set the sibling relation of added item to adjoining items" do
320
- assert_nil referenced_object(@inserted_page[:Next])
320
+ referenced_object(@inserted_page[:Next]).should be_nil
321
321
  referenced_object(@inserted_page[:Prev]).should == @page_2
322
322
  end
323
323
 
@@ -329,7 +329,7 @@ describe "Outline" do
329
329
  end
330
330
 
331
331
  it "should require an existing title" do
332
- assert_raise Prawn::Errors::UnknownOutlineTitle do
332
+ lambda do
333
333
  @pdf.go_to_page 1
334
334
  @pdf.start_new_page
335
335
  @pdf.text "Inserted Page"
@@ -339,26 +339,26 @@ describe "Outline" do
339
339
  end
340
340
  end
341
341
  render_and_find_objects
342
- end
342
+ end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
343
343
  end
344
344
 
345
345
  end
346
346
 
347
347
  describe "#page" do
348
348
  it "should require a title option to be set" do
349
- assert_raise Prawn::Errors::RequiredOption do
349
+ lambda do
350
350
  @pdf = Prawn::Document.new() do
351
351
  text "Page 1. This is the first Chapter. "
352
352
  outline.define do
353
353
  page :destination => 1, :title => nil
354
354
  end
355
355
  end
356
- end
356
+ end.should raise_error(Prawn::Errors::RequiredOption)
357
357
  end
358
358
  end
359
359
  end
360
360
 
361
- context "foreign character encoding" do
361
+ describe "foreign character encoding" do
362
362
  before(:each) do
363
363
  pdf = Prawn::Document.new() do
364
364
  outline.define do
@@ -370,7 +370,25 @@ context "foreign character encoding" do
370
370
 
371
371
  it "should handle other encodings for the title" do
372
372
  object = find_by_title('La pomme croquée')
373
- object.should.not == nil
373
+ object.should_not == nil
374
+ end
375
+ end
376
+
377
+ describe "with optimize_objects option" do
378
+ before(:each) do
379
+ @pdf = Prawn::Document.new(:optimize_objects => true) do
380
+ outline.define do
381
+ section 'Chapter 1', :destination => 1, :closed => true do
382
+ page :destination => 1, :title => 'Page 1'
383
+ end
384
+ end
385
+ end
386
+ render_and_find_objects
387
+ end
388
+
389
+ it "should generate an outline" do
390
+ @section_1.should_not be_nil
391
+ @page_1.should_not be_nil
374
392
  end
375
393
  end
376
394
 
@@ -17,6 +17,8 @@ describe "PDF Object Serialization" do
17
17
  it "should convert a Ruby number to PDF number" do
18
18
  Prawn::Core::PdfObject(1).should == "1"
19
19
  Prawn::Core::PdfObject(1.214112421).should == "1.214112421"
20
+ # scientific notation is not valid in PDF
21
+ Prawn::Core::PdfObject(0.000005).should == "0.000005"
20
22
  end
21
23
 
22
24
  it "should convert a Ruby time object to a PDF timestamp" do
@@ -151,7 +153,7 @@ describe "PDF Object Serialization" do
151
153
 
152
154
  it "should not allow keys other than strings or symbols for PDF dicts" do
153
155
  lambda { Prawn::Core::PdfObject(:foo => :bar, :baz => :bang, 1 => 4) }.
154
- should.raise(Prawn::Errors::FailedObjectConversion)
156
+ should raise_error(Prawn::Errors::FailedObjectConversion)
155
157
  end
156
158
 
157
159
  it "should convert a Prawn::Reference to a PDF indirect object reference" do
@@ -12,8 +12,8 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
12
12
  describe "When reading a greyscale PNG file (color type 0)" do
13
13
 
14
14
  before(:each) do
15
- @filename = "#{Prawn::BASEDIR}/data/images/web-links.png"
16
- @data_filename = "#{Prawn::BASEDIR}/data/images/web-links.dat"
15
+ @filename = "#{Prawn::DATADIR}/images/web-links.png"
16
+ @data_filename = "#{Prawn::DATADIR}/images/web-links.dat"
17
17
  @img_data = File.binread(@filename)
18
18
  end
19
19
 
@@ -39,7 +39,7 @@ end
39
39
  describe "When reading a greyscale PNG file with transparency (color type 0)" do
40
40
 
41
41
  before(:each) do
42
- @filename = "#{Prawn::BASEDIR}/data/images/ruport_type0.png"
42
+ @filename = "#{Prawn::DATADIR}/images/ruport_type0.png"
43
43
  @img_data = File.binread(@filename)
44
44
  end
45
45
 
@@ -56,8 +56,8 @@ end
56
56
  describe "When reading an RGB PNG file (color type 2)" do
57
57
 
58
58
  before(:each) do
59
- @filename = "#{Prawn::BASEDIR}/data/images/ruport.png"
60
- @data_filename = "#{Prawn::BASEDIR}/data/images/ruport_data.dat"
59
+ @filename = "#{Prawn::DATADIR}/images/ruport.png"
60
+ @data_filename = "#{Prawn::DATADIR}/images/ruport_data.dat"
61
61
  @img_data = File.binread(@filename)
62
62
  end
63
63
 
@@ -83,7 +83,7 @@ end
83
83
  describe "When reading an RGB PNG file with transparency (color type 2)" do
84
84
 
85
85
  before(:each) do
86
- @filename = "#{Prawn::BASEDIR}/data/images/arrow2.png"
86
+ @filename = "#{Prawn::DATADIR}/images/arrow2.png"
87
87
  @img_data = File.binread(@filename)
88
88
  end
89
89
 
@@ -103,8 +103,8 @@ end
103
103
  describe "When reading an indexed color PNG file (color type 3)" do
104
104
 
105
105
  before(:each) do
106
- @filename = "#{Prawn::BASEDIR}/data/images/rails.png"
107
- @data_filename = "#{Prawn::BASEDIR}/data/images/rails.dat"
106
+ @filename = "#{Prawn::DATADIR}/images/rails.png"
107
+ @data_filename = "#{Prawn::DATADIR}/images/rails.dat"
108
108
  @img_data = File.binread(@filename)
109
109
  end
110
110
 
@@ -130,9 +130,9 @@ end
130
130
  describe "When reading a greyscale+alpha PNG file (color type 4)" do
131
131
 
132
132
  before(:each) do
133
- @filename = "#{Prawn::BASEDIR}/data/images/page_white_text.png"
134
- @data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.dat"
135
- @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.alpha"
133
+ @filename = "#{Prawn::DATADIR}/images/page_white_text.png"
134
+ @data_filename = "#{Prawn::DATADIR}/images/page_white_text.dat"
135
+ @alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
136
136
  @img_data = File.binread(@filename)
137
137
  end
138
138
 
@@ -166,9 +166,9 @@ end
166
166
  describe "When reading an RGB+alpha PNG file (color type 6)" do
167
167
 
168
168
  before(:each) do
169
- @filename = "#{Prawn::BASEDIR}/data/images/dice.png"
170
- @data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
171
- @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
169
+ @filename = "#{Prawn::DATADIR}/images/dice.png"
170
+ @data_filename = "#{Prawn::DATADIR}/images/dice.dat"
171
+ @alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
172
172
  @img_data = File.binread(@filename)
173
173
  end
174
174
 
@@ -188,24 +188,27 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
188
188
  png = Prawn::Images::PNG.new(@img_data)
189
189
  png.split_alpha_channel!
190
190
  data = File.binread(@data_filename)
191
- png.img_data.should == data
191
+ # compare decompressed rather than compressed image data
192
+ # because JRuby's implementation of Zlib is different from MRI --
193
+ # both generate valid gzipped data, but not bit-identical to each other
194
+ Zlib::Inflate.inflate(png.img_data).should == Zlib::Inflate.inflate(data)
192
195
  end
193
196
 
194
197
  it "should correctly extract the alpha channel data from the image data chunk" do
195
198
  png = Prawn::Images::PNG.new(@img_data)
196
199
  png.split_alpha_channel!
197
200
  data = File.binread(@alpha_data_filename)
198
- png.alpha_channel.should == data
201
+ Zlib::Inflate.inflate(png.alpha_channel).should == Zlib::Inflate.inflate(data)
199
202
  end
200
203
  end
201
204
 
202
205
  describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
203
206
 
204
207
  before(:each) do
205
- @filename = "#{Prawn::BASEDIR}/data/images/16bit.png"
206
- @data_filename = "#{Prawn::BASEDIR}/data/images/16bit.dat"
208
+ @filename = "#{Prawn::DATADIR}/images/16bit.png"
209
+ @data_filename = "#{Prawn::DATADIR}/images/16bit.dat"
207
210
  # alpha channel truncated to 8-bit
208
- @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/16bit.alpha"
211
+ @alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
209
212
  @img_data = File.binread(@filename)
210
213
  end
211
214
 
@@ -35,7 +35,7 @@ describe "A Reference object" do
35
35
  cref << "Hi There " * 20
36
36
  cref.compress_stream
37
37
 
38
- assert cref.stream.size < ref.stream.size,
38
+ cref.stream.size.should be < ref.stream.size,
39
39
  "compressed stream expected to be smaller than source but wasn't"
40
40
  cref.data[:Filter].should == :FlateDecode
41
41
  end
@@ -67,6 +67,22 @@ describe "A Reference object" do
67
67
  to.compressed?.should == true
68
68
  end
69
69
 
70
+ it "should have Length if stream present" do
71
+ ref = Prawn::Core::Reference(7, {})
72
+ ref << "Hello"
73
+
74
+ ref.data[:Length].should == 5
75
+ end
76
+
77
+ it "should update Length when stream is updated" do
78
+ ref = Prawn::Core::Reference(7, {})
79
+ ref << "Hello"
80
+ ref.data[:Length].should == 5
81
+
82
+ ref << " world"
83
+ ref.data[:Length].should == 11
84
+ end
85
+
70
86
  describe "generated via Prawn::Document" do
71
87
  it "should return a proper reference on ref!" do
72
88
  pdf = Prawn::Document.new
@@ -78,5 +94,12 @@ describe "A Reference object" do
78
94
  r = pdf.ref({})
79
95
  r.is_a?(Integer).should == true
80
96
  end
97
+
98
+ it "should have :Length of stream if it has one when compression disabled" do
99
+ pdf = Prawn::Document.new :compress => false
100
+ ref = pdf.ref!({})
101
+ ref << 'Hello'
102
+ ref.data[:Length].should == 5
103
+ end
81
104
  end
82
105
  end
@@ -10,14 +10,14 @@ describe "Repeaters" do
10
10
 
11
11
  r = repeater(doc, :all) { :do_nothing }
12
12
 
13
- assert_equal orig_count + 1, Prawn::Repeater.count
13
+ Prawn::Repeater.count.should == orig_count + 1
14
14
  end
15
15
 
16
16
  it "must provide an :all filter" do
17
17
  doc = sample_document
18
18
  r = repeater(doc, :all) { :do_nothing }
19
19
 
20
- assert (1..doc.page_count).all? { |i| r.match?(i) }
20
+ (1..doc.page_count).all? { |i| r.match?(i) }.should be_true
21
21
  end
22
22
 
23
23
  it "must provide an :odd filter" do
@@ -26,29 +26,29 @@ describe "Repeaters" do
26
26
 
27
27
  odd, even = (1..doc.page_count).partition { |e| e % 2 == 1 }
28
28
 
29
- assert odd.all? { |i| r.match?(i) }
30
- assert ! even.any? { |i| r.match?(i) }
29
+ odd.all? { |i| r.match?(i) }.should be_true
30
+ even.any? { |i| r.match?(i) }.should be_false
31
31
  end
32
32
 
33
33
  it "must be able to filter by an array of page numbers" do
34
34
  doc = sample_document
35
35
  r = repeater(doc, [1,2,7]) { :do_nothing }
36
36
 
37
- assert_equal [1,2,7], (1..10).select { |i| r.match?(i) }
37
+ (1..10).select { |i| r.match?(i) }.should == [1,2,7]
38
38
  end
39
39
 
40
40
  it "must be able to filter by a range of page numbers" do
41
41
  doc = sample_document
42
42
  r = repeater(doc, 2..4) { :do_nothing }
43
43
 
44
- assert_equal [2,3,4], (1..10).select { |i| r.match?(i) }
44
+ (1..10).select { |i| r.match?(i) }.should == [2,3,4]
45
45
  end
46
46
 
47
47
  it "must be able to filter by an arbitrary proc" do
48
48
  doc = sample_document
49
49
  r = repeater(doc, lambda { |x| x == 1 or x % 3 == 0 })
50
50
 
51
- assert_equal [1,3,6,9], (1..10).select { |i| r.match?(i) }
51
+ (1..10).select { |i| r.match?(i) }.should == [1,3,6,9]
52
52
  end
53
53
 
54
54
  it "must try to run a stamp if the page number matches" do
@@ -95,7 +95,7 @@ describe "Repeaters" do
95
95
  end
96
96
 
97
97
  text = PDF::Inspector::Text.analyze(doc.render)
98
- assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
98
+ text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
99
99
  end
100
100
 
101
101
  it "must treat any block as a closure (Document.new instance_eval form)" do
@@ -110,7 +110,7 @@ describe "Repeaters" do
110
110
  end
111
111
 
112
112
  text = PDF::Inspector::Text.analyze(doc.render)
113
- assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
113
+ text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
114
114
  end
115
115
 
116
116
  def sample_document