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
@@ -224,13 +224,13 @@ describe "Text::Formatted::Fragment that is a subscript" do
224
224
  @fragment.ascender = 17
225
225
  end
226
226
  describe "#subscript?" do
227
- it "should be true" do
228
- @fragment.should.be.subscript
227
+ it "should be_true" do
228
+ @fragment.should be_subscript
229
229
  end
230
230
  end
231
231
  describe "#y_offset" do
232
232
  it "should return a negative value" do
233
- @fragment.y_offset.should.be < 0
233
+ @fragment.y_offset.should be < 0
234
234
  end
235
235
  end
236
236
  end
@@ -252,13 +252,13 @@ describe "Text::Formatted::Fragment that is a superscript" do
252
252
  @fragment.ascender = 17
253
253
  end
254
254
  describe "#superscript?" do
255
- it "should be true" do
256
- @fragment.should.be.superscript
255
+ it "should be_true" do
256
+ @fragment.should be_superscript
257
257
  end
258
258
  end
259
259
  describe "#y_offset" do
260
260
  it "should return a positive value" do
261
- @fragment.y_offset.should.be > 0
261
+ @fragment.y_offset.should be > 0
262
262
  end
263
263
  end
264
264
  end
@@ -68,7 +68,7 @@ describe "When drawing a line" do
68
68
  end
69
69
  it "should require a y coordinate" do
70
70
  lambda { @pdf.vertical_line(400,500) }.
71
- should.raise(ArgumentError)
71
+ should raise_error(ArgumentError)
72
72
  end
73
73
  end
74
74
 
@@ -162,6 +162,29 @@ describe "When drawing an ellipse" do
162
162
  @pdf.ellipse [100,100], 25, 50
163
163
  @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
164
164
  end
165
+
166
+ it "should use a Bézier approximation" do
167
+ @curve.coords.should ==
168
+ [125.0, 100.0,
169
+
170
+ 125.0, 127.614,
171
+ 113.807, 150,
172
+ 100.0, 150.0,
173
+
174
+ 86.193, 150.0,
175
+ 75.0, 127.614,
176
+ 75.0, 100.0,
177
+
178
+ 75.0, 72.386,
179
+ 86.193, 50.0,
180
+ 100.0, 50.0,
181
+
182
+ 113.807, 50.0,
183
+ 125.0, 72.386,
184
+ 125.0, 100.0,
185
+
186
+ 100.0, 100.0]
187
+ end
165
188
 
166
189
  it "should move the pointer to the center of the ellipse after drawing" do
167
190
  @curve.coords[-2..-1].should == [100,100]
@@ -257,37 +280,79 @@ describe "When setting colors" do
257
280
  end
258
281
  end
259
282
 
260
- describe "Gradients" do
283
+ describe "Patterns" do
261
284
  before(:each) { create_pdf }
262
285
 
263
- it "should create a /Pattern resource" do
264
- @pdf.fill_gradient [0, @pdf.bounds.height],
265
- @pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
286
+ describe 'linear gradients' do
287
+ it "should create a /Pattern resource" do
288
+ @pdf.fill_gradient [0, @pdf.bounds.height],
289
+ [@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
290
+
291
+ grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
292
+ pattern = grad.patterns.values.first
293
+
294
+ pattern.should_not be_nil
295
+ pattern[:Shading][:ShadingType].should == 2
296
+ pattern[:Shading][:Coords].should == [0, 0, @pdf.bounds.width, 0]
297
+ pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
298
+ (x1-x2).abs < 0.01
299
+ }.should be_true
300
+ pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
301
+ (x1-x2).abs < 0.01
302
+ }.should be_true
303
+ end
266
304
 
267
- grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
268
- pattern = grad.patterns[:SP1]
305
+ it "fill_gradient should set fill color to the pattern" do
306
+ @pdf.fill_gradient [0, @pdf.bounds.height],
307
+ [@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
269
308
 
270
- pattern.should.not.be.nil
271
- assert pattern[:Shading][:Function][:C0].zip([1, 0, 0]).
272
- all?{ |x1, x2| (x1-x2).abs < 0.01 }
273
- assert pattern[:Shading][:Function][:C1].zip([0, 0, 1]).
274
- all?{ |x1, x2| (x1-x2).abs < 0.01 }
275
- end
309
+ str = @pdf.render
310
+ str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
311
+ end
276
312
 
277
- it "fill_gradient should set fill color to the pattern" do
278
- @pdf.fill_gradient [0, @pdf.bounds.height],
279
- @pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
313
+ it "stroke_gradient should set stroke color to the pattern" do
314
+ @pdf.stroke_gradient [0, @pdf.bounds.height],
315
+ [@pdf.bounds.width, @pdf.bounds.height], 'FF0000', '0000FF'
280
316
 
281
- str = @pdf.render
282
- str.should =~ %r{/Pattern\s+cs\s*/SP1\s+scn}
317
+ str = @pdf.render
318
+ str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
319
+ end
283
320
  end
284
321
 
285
- it "stroke_gradient should set stroke color to the pattern" do
286
- @pdf.stroke_gradient [0, @pdf.bounds.height],
287
- @pdf.bounds.width, @pdf.bounds.height, 'FF0000', '0000FF'
322
+ describe 'radial gradients' do
323
+ it "should create a /Pattern resource" do
324
+ @pdf.fill_gradient [0, @pdf.bounds.height], 10,
325
+ [@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
288
326
 
289
- str = @pdf.render
290
- str.should =~ %r{/Pattern\s+CS\s*/SP1\s+SCN}
327
+ grad = PDF::Inspector::Graphics::Pattern.analyze(@pdf.render)
328
+ pattern = grad.patterns.values.first
329
+
330
+ pattern.should_not be_nil
331
+ pattern[:Shading][:ShadingType].should == 3
332
+ pattern[:Shading][:Coords].should == [0, 0, 10, @pdf.bounds.width, 0, 20]
333
+ pattern[:Shading][:Function][:C0].zip([1, 0, 0]).all?{ |x1, x2|
334
+ (x1-x2).abs < 0.01
335
+ }.should be_true
336
+ pattern[:Shading][:Function][:C1].zip([0, 0, 1]).all?{ |x1, x2|
337
+ (x1-x2).abs < 0.01
338
+ }.should be_true
339
+ end
340
+
341
+ it "fill_gradient should set fill color to the pattern" do
342
+ @pdf.fill_gradient [0, @pdf.bounds.height], 10,
343
+ [@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
344
+
345
+ str = @pdf.render
346
+ str.should =~ %r{/Pattern\s+cs\s*/SP-?\d+\s+scn}
347
+ end
348
+
349
+ it "stroke_gradient should set stroke color to the pattern" do
350
+ @pdf.stroke_gradient [0, @pdf.bounds.height], 10,
351
+ [@pdf.bounds.width, @pdf.bounds.height], 20, 'FF0000', '0000FF'
352
+
353
+ str = @pdf.render
354
+ str.should =~ %r{/Pattern\s+CS\s*/SP-?\d+\s+SCN}
355
+ end
291
356
  end
292
357
  end
293
358
 
@@ -310,7 +375,7 @@ describe "When using painting shortcuts" do
310
375
 
311
376
  it "should not break method_missing" do
312
377
  lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
313
- should.raise(NoMethodError)
378
+ should raise_error(NoMethodError)
314
379
  end
315
380
  end
316
381
 
@@ -407,11 +472,11 @@ describe "When using graphics states" do
407
472
  end
408
473
 
409
474
 
410
- it "should raise error if closing an empty graphic stack" do
411
- assert_raise Prawn::Errors::EmptyGraphicStateStack do
475
+ it "should raise_error error if closing an empty graphic stack" do
476
+ lambda {
412
477
  @pdf.render
413
478
  @pdf.restore_graphics_state
414
- end
479
+ }.should raise_error(Prawn::Errors::EmptyGraphicStateStack)
415
480
  end
416
481
  end
417
482
 
@@ -509,10 +574,10 @@ describe "When using transformations shortcuts" do
509
574
  reduce_precision(@cos), 0, 0]
510
575
  end
511
576
 
512
- it "should raise BlockRequired if no block is given" do
577
+ it "should raise_error BlockRequired if no block is given" do
513
578
  lambda {
514
579
  @pdf.rotate(@angle, :origin => [@x, @y])
515
- }.should.raise(Prawn::Errors::BlockRequired)
580
+ }.should raise_error(Prawn::Errors::BlockRequired)
516
581
  end
517
582
 
518
583
  def reduce_precision(float)
@@ -565,10 +630,10 @@ describe "When using transformations shortcuts" do
565
630
  matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
566
631
  end
567
632
 
568
- it "should raise BlockRequired if no block is given" do
633
+ it "should raise_error BlockRequired if no block is given" do
569
634
  lambda {
570
635
  @pdf.scale(@factor, :origin => [@x, @y])
571
- }.should.raise(Prawn::Errors::BlockRequired)
636
+ }.should raise_error(Prawn::Errors::BlockRequired)
572
637
  end
573
638
 
574
639
  def reduce_precision(float)
@@ -62,8 +62,8 @@ describe "A document's grid" do
62
62
  @pdf.grid.show_all('cccccc')
63
63
 
64
64
  colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
65
- colors.fill_color.should.not == [0.8,0.8,0.8]
66
- colors.stroke_color.should.not == [0.8,0.8,0.8]
65
+ colors.fill_color.should_not == [0.8,0.8,0.8]
66
+ colors.stroke_color.should_not == [0.8,0.8,0.8]
67
67
 
68
68
  # Hardcoded default color as I haven't been able to come up with a stable converter
69
69
  # between fill_color without lots code.
@@ -7,7 +7,7 @@ require 'pathname'
7
7
  describe "the image() function" do
8
8
 
9
9
  before(:each) do
10
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
10
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
11
11
  create_pdf
12
12
  end
13
13
 
@@ -26,7 +26,7 @@ describe "the image() function" do
26
26
  it "should return the image info object" do
27
27
  info = @pdf.image(@filename)
28
28
 
29
- info.should.be.kind_of(Prawn::Images::JPG)
29
+ info.should be_a_kind_of(Prawn::Images::JPG)
30
30
 
31
31
  info.height.should == 453
32
32
  end
@@ -38,23 +38,31 @@ describe "the image() function" do
38
38
  info.height.should == 453
39
39
  end
40
40
 
41
+ it "rewinds IO objects to be able to embed them multiply" do
42
+ file = File.open(@filename, "rb")
43
+
44
+ @pdf.image(file)
45
+ info = @pdf.image(file)
46
+ info.height.should == 453
47
+ end
48
+
41
49
  it "should accept Pathname objects" do
42
50
  info = @pdf.image(Pathname.new(@filename))
43
51
  info.height.should == 453
44
52
  end
45
53
 
46
- it "should raise an UnsupportedImageType if passed a BMP" do
47
- filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
48
- lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
54
+ it "should raise_error an UnsupportedImageType if passed a BMP" do
55
+ filename = "#{Prawn::DATADIR}/images/tru256.bmp"
56
+ lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
49
57
  end
50
58
 
51
- it "should raise an UnsupportedImageType if passed an interlaced PNG" do
52
- filename = "#{Prawn::BASEDIR}/data/images/dice_interlaced.png"
53
- lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
59
+ it "should raise_error an UnsupportedImageType if passed an interlaced PNG" do
60
+ filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
61
+ lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
54
62
  end
55
63
 
56
64
  it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
57
- @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
65
+ @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
58
66
  @pdf.state.version.should >= 1.5
59
67
  end
60
68
 
@@ -63,7 +71,7 @@ describe "the image() function" do
63
71
  # or anything. OS X Preview handles those files just fine.
64
72
  #
65
73
  it "should embed 8-bit alpha channels for 16-bit PNGs" do
66
- @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
74
+ @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
67
75
 
68
76
  output = @pdf.render
69
77
  output.should =~ /\/BitsPerComponent 16/
@@ -9,7 +9,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
9
9
  describe "When reading a JPEG file" do
10
10
 
11
11
  before(:each) do
12
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
12
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
13
13
  @img_data = File.open(@filename, "rb") { |f| f.read }
14
14
  end
15
15
 
@@ -30,7 +30,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
30
30
  :document => @pdf)
31
31
  string.should == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
32
32
  end
33
- it "should raise CannotFit if a too-small width is given" do
33
+ it "should raise_error CannotFit if a too-small width is given" do
34
34
  array = [{ :text => " hello world, " },
35
35
  { :text => "goodbye ", :style => [:bold] }]
36
36
  @arranger.format_array = array
@@ -38,7 +38,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
38
38
  @line_wrap.wrap_line(:arranger => @arranger,
39
39
  :width => 1,
40
40
  :document => @pdf)
41
- end.should.raise(Prawn::Errors::CannotFit)
41
+ end.should raise_error(Prawn::Errors::CannotFit)
42
42
  end
43
43
 
44
44
  it "should break on space" do
@@ -51,7 +51,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
51
51
  end
52
52
 
53
53
  it "should break on zero-width space" do
54
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
54
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
55
55
  array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
56
56
  @arranger.format_array = array
57
57
  string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -61,7 +61,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
61
61
  end
62
62
 
63
63
  it "should not display zero-width space" do
64
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
64
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
65
65
  array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
66
66
  @arranger.format_array = array
67
67
  string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -116,7 +116,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
116
116
  expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
117
117
  string.should == expected
118
118
 
119
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
119
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
120
120
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
121
121
 
122
122
  string = "hello#{Prawn::Text::SHY}world"
@@ -137,7 +137,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
137
137
  :document => @pdf)
138
138
  string.should == "helloworld"
139
139
 
140
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
140
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
141
141
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
142
142
 
143
143
  string = "hello#{Prawn::Text::SHY}world"
@@ -166,7 +166,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
166
166
  :document => @pdf)
167
167
  string.should == "hello"
168
168
 
169
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
169
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
170
170
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
171
171
  enough_width_for_hello_world = 68
172
172
 
@@ -205,7 +205,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
205
205
  expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
206
206
  string.should == expected
207
207
 
208
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
208
+ @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
209
209
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
210
210
 
211
211
  string = "hello#{Prawn::Text::SHY}-"
@@ -273,12 +273,12 @@ describe "Core::Text::Formatted::LineWrap" do
273
273
  line = @line_wrap.wrap_line(:arranger => @arranger,
274
274
  :width => 200,
275
275
  :document => @pdf)
276
- line.should.not.be.empty
276
+ line.should_not be_empty
277
277
  end
278
278
  line = @line_wrap.wrap_line(:arranger => @arranger,
279
279
  :width => 200,
280
280
  :document => @pdf)
281
- line.should.be.empty
281
+ line.should be_empty
282
282
  end
283
283
  end
284
284
 
@@ -289,7 +289,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
289
289
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
290
290
  @one_word_width = 50
291
291
  end
292
- it "should be false when the last printed line is not the end of the paragraph" do
292
+ it "should be_false when the last printed line is not the end of the paragraph" do
293
293
  array = [{ :text => "hello world" }]
294
294
  @arranger.format_array = array
295
295
  string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -298,7 +298,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
298
298
 
299
299
  @line_wrap.paragraph_finished?.should == false
300
300
  end
301
- it "should be true when the last printed line is the last fragment to print" do
301
+ it "should be_true when the last printed line is the last fragment to print" do
302
302
  array = [{ :text => "hello world" }]
303
303
  @arranger.format_array = array
304
304
  string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -310,7 +310,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
310
310
 
311
311
  @line_wrap.paragraph_finished?.should == true
312
312
  end
313
- it "should be true when a newline exists on the current line" do
313
+ it "should be_true when a newline exists on the current line" do
314
314
  array = [{ :text => "hello\n world" }]
315
315
  @arranger.format_array = array
316
316
  string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -319,7 +319,7 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
319
319
 
320
320
  @line_wrap.paragraph_finished?.should == true
321
321
  end
322
- it "should be true when a newline exists in the next fragment" do
322
+ it "should be_true when a newline exists in the next fragment" do
323
323
  array = [{ :text => "hello " },
324
324
  { :text => " \n" },
325
325
  { :text => "world" }]
@@ -4,7 +4,7 @@ require "prawn/measurement_extensions"
4
4
  describe "Measurement units" do
5
5
 
6
6
  it "should convert units to PostScriptPoints" do
7
- 1.mm.should.be.close(2.834645669, 0.000000001)
7
+ 1.mm.should be_within(0.000000001).of(2.834645669)
8
8
  1.mm.should == (72 / 25.4)
9
9
  2.mm.should == (2 * 72 / 25.4)
10
10
  3.mm.should == 3 * 72 / 25.4
@@ -20,4 +20,4 @@ describe "Measurement units" do
20
20
  end
21
21
 
22
22
  end
23
-
23
+
@@ -48,7 +48,7 @@ describe "Name Tree" do
48
48
  ref_count = @pdf.object_store.length
49
49
  node = Prawn::Core::NameTree::Node.new(@pdf, 3)
50
50
  tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
51
- @pdf.object_store.length.should.equal ref_count+2
51
+ @pdf.object_store.length.should == ref_count+2
52
52
  end
53
53
 
54
54
  it "should create a one new reference when subtree is split" do
@@ -58,7 +58,7 @@ describe "Name Tree" do
58
58
  ref_count = @pdf.object_store.length # save when root is split
59
59
  tree_add(node, ["five", 5], ["six", 6], ["seven", 7])
60
60
  tree_dump(node).should == "[[five=5,four=4,one=1],[seven=7,six=6],[three=3,two=2]]"
61
- @pdf.object_store.length.should.equal ref_count+1
61
+ @pdf.object_store.length.should == ref_count+1
62
62
  end
63
63
 
64
64
  it "should keep tree balanced when subtree split cascades to root" do
@@ -78,7 +78,7 @@ describe "Name Tree" do
78
78
  it "should emit only :Names key with to_hash if root is only node" do
79
79
  node = Prawn::Core::NameTree::Node.new(@pdf, 3)
80
80
  tree_add(node, ["one", 1], ["two", 2], ["three", 3])
81
- node.to_hash.should.equal(
81
+ node.to_hash.should ==(
82
82
  { :Names => [tree_value("one", 1), tree_value("three", 3), tree_value("two", 2)] }
83
83
  )
84
84
  end
@@ -86,13 +86,13 @@ describe "Name Tree" do
86
86
  it "should emit only :Kids key with to_hash if root has children" do
87
87
  node = Prawn::Core::NameTree::Node.new(@pdf, 3)
88
88
  tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
89
- node.to_hash.should.equal({ :Kids => node.children.map { |child| child.ref } })
89
+ node.to_hash.should ==({ :Kids => node.children.map { |child| child.ref } })
90
90
  end
91
91
 
92
92
  it "should emit :Limits and :Names keys with to_hash for leaf node" do
93
93
  node = Prawn::Core::NameTree::Node.new(@pdf, 3)
94
94
  tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
95
- node.children.first.to_hash.should.equal(
95
+ node.children.first.to_hash.should ==(
96
96
  { :Limits => %w(four one),
97
97
  :Names => [tree_value("four", 4), tree_value("one", 1)] }
98
98
  )
@@ -104,7 +104,7 @@ describe "Name Tree" do
104
104
  tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
105
105
  tree_add(node, ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12])
106
106
  tree_add(node, ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16])
107
- node.children.first.to_hash.should.equal(
107
+ node.children.first.to_hash.should ==(
108
108
  { :Limits => %w(eight one),
109
109
  :Kids => node.children.first.children.map { |child| child.ref } }
110
110
  )