prawn 0.15.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/COPYING +2 -2
  2. data/LICENSE +1 -1
  3. data/README.md +96 -0
  4. data/Rakefile +27 -30
  5. data/data/fonts/Action Man.dfont +0 -0
  6. data/data/fonts/Activa.ttf +0 -0
  7. data/data/fonts/Chalkboard.ttf +0 -0
  8. data/data/fonts/DejaVuSans.ttf +0 -0
  9. data/data/fonts/Dustismo_Roman.ttf +0 -0
  10. data/data/fonts/comicsans.ttf +0 -0
  11. data/data/fonts/gkai00mp.ttf +0 -0
  12. data/data/images/16bit.alpha +0 -0
  13. data/data/images/16bit.dat +0 -0
  14. data/data/images/dice.alpha +0 -0
  15. data/data/images/dice.dat +0 -0
  16. data/data/images/page_white_text.alpha +0 -0
  17. data/data/images/page_white_text.dat +0 -0
  18. data/data/images/rails.dat +0 -0
  19. data/data/images/rails.png +0 -0
  20. data/data/pdfs/nested_pages.pdf +13 -13
  21. data/lib/prawn.rb +21 -85
  22. data/lib/prawn/compatibility.rb +51 -0
  23. data/lib/prawn/core.rb +85 -0
  24. data/lib/prawn/core/annotations.rb +61 -0
  25. data/lib/prawn/core/byte_string.rb +9 -0
  26. data/lib/prawn/core/destinations.rb +90 -0
  27. data/lib/prawn/core/document_state.rb +78 -0
  28. data/lib/prawn/core/literal_string.rb +16 -0
  29. data/lib/prawn/core/name_tree.rb +177 -0
  30. data/lib/prawn/core/object_store.rb +264 -0
  31. data/lib/prawn/core/page.rb +215 -0
  32. data/lib/prawn/core/pdf_object.rb +108 -0
  33. data/lib/prawn/core/reference.rb +115 -0
  34. data/lib/prawn/core/text.rb +268 -0
  35. data/lib/prawn/core/text/formatted/arranger.rb +294 -0
  36. data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
  37. data/lib/prawn/core/text/formatted/wrap.rb +153 -0
  38. data/lib/prawn/document.rb +122 -155
  39. data/lib/prawn/document/bounding_box.rb +7 -36
  40. data/lib/prawn/document/column_box.rb +10 -38
  41. data/lib/prawn/document/graphics_state.rb +74 -11
  42. data/lib/prawn/document/internals.rb +23 -24
  43. data/lib/prawn/document/page_geometry.rb +136 -0
  44. data/lib/prawn/document/snapshot.rb +6 -7
  45. data/lib/prawn/document/span.rb +10 -12
  46. data/lib/prawn/encoding.rb +10 -9
  47. data/lib/prawn/errors.rb +30 -15
  48. data/lib/prawn/font.rb +104 -136
  49. data/lib/prawn/font/afm.rb +44 -46
  50. data/lib/prawn/font/dfont.rb +3 -4
  51. data/lib/prawn/font/ttf.rb +50 -31
  52. data/lib/prawn/graphics.rb +57 -302
  53. data/lib/prawn/graphics/cap_style.rb +3 -4
  54. data/lib/prawn/graphics/color.rb +5 -13
  55. data/lib/prawn/graphics/dash.rb +31 -53
  56. data/lib/prawn/graphics/gradient.rb +84 -0
  57. data/lib/prawn/graphics/join_style.rb +7 -9
  58. data/lib/prawn/graphics/transformation.rb +9 -10
  59. data/lib/prawn/graphics/transparency.rb +1 -3
  60. data/lib/prawn/images.rb +59 -69
  61. data/lib/prawn/images/image.rb +22 -6
  62. data/lib/prawn/images/jpg.rb +14 -20
  63. data/lib/prawn/images/png.rb +118 -61
  64. data/lib/prawn/layout.rb +15 -10
  65. data/lib/prawn/layout/grid.rb +54 -66
  66. data/lib/prawn/measurement_extensions.rb +6 -10
  67. data/lib/prawn/measurements.rb +21 -27
  68. data/lib/prawn/outline.rb +308 -6
  69. data/lib/prawn/repeater.rb +8 -10
  70. data/lib/prawn/security.rb +33 -55
  71. data/lib/prawn/security/arcfour.rb +0 -1
  72. data/lib/prawn/stamp.rb +3 -5
  73. data/lib/prawn/table.rb +60 -188
  74. data/lib/prawn/table/cell.rb +44 -272
  75. data/lib/prawn/table/cell/image.rb +3 -2
  76. data/lib/prawn/table/cell/in_table.rb +2 -4
  77. data/lib/prawn/table/cell/subtable.rb +2 -2
  78. data/lib/prawn/table/cell/text.rb +18 -41
  79. data/lib/prawn/table/cells.rb +48 -142
  80. data/lib/prawn/text.rb +25 -32
  81. data/lib/prawn/text/box.rb +6 -12
  82. data/lib/prawn/text/formatted.rb +4 -5
  83. data/lib/prawn/text/formatted/box.rb +59 -96
  84. data/lib/prawn/text/formatted/fragment.rb +23 -34
  85. data/lib/prawn/text/formatted/parser.rb +5 -15
  86. data/prawn.gemspec +13 -24
  87. data/spec/annotations_spec.rb +32 -16
  88. data/spec/bounding_box_spec.rb +17 -119
  89. data/spec/cell_spec.rb +42 -112
  90. data/spec/destinations_spec.rb +5 -5
  91. data/spec/document_spec.rb +111 -155
  92. data/spec/extensions/mocha.rb +0 -1
  93. data/spec/font_spec.rb +99 -149
  94. data/spec/formatted_text_arranger_spec.rb +43 -43
  95. data/spec/formatted_text_box_spec.rb +44 -43
  96. data/spec/formatted_text_fragment_spec.rb +8 -8
  97. data/spec/graphics_spec.rb +68 -151
  98. data/spec/grid_spec.rb +15 -26
  99. data/spec/images_spec.rb +30 -51
  100. data/spec/inline_formatted_text_parser_spec.rb +20 -69
  101. data/spec/jpg_spec.rb +4 -4
  102. data/spec/line_wrap_spec.rb +28 -28
  103. data/spec/measurement_units_spec.rb +6 -6
  104. data/spec/name_tree_spec.rb +112 -0
  105. data/spec/object_store_spec.rb +106 -17
  106. data/spec/outline_spec.rb +63 -103
  107. data/spec/pdf_object_spec.rb +170 -0
  108. data/spec/png_spec.rb +25 -25
  109. data/spec/reference_spec.rb +65 -8
  110. data/spec/repeater_spec.rb +10 -10
  111. data/spec/security_spec.rb +12 -44
  112. data/spec/snapshot_spec.rb +7 -7
  113. data/spec/span_spec.rb +15 -10
  114. data/spec/spec_helper.rb +8 -32
  115. data/spec/stamp_spec.rb +30 -29
  116. data/spec/stroke_styles_spec.rb +18 -36
  117. data/spec/table_spec.rb +111 -706
  118. data/spec/template_spec.rb +297 -0
  119. data/spec/text_at_spec.rb +33 -19
  120. data/spec/text_box_spec.rb +64 -100
  121. data/spec/text_rendering_mode_spec.rb +5 -5
  122. data/spec/text_spacing_spec.rb +4 -4
  123. data/spec/text_spec.rb +64 -84
  124. data/spec/transparency_spec.rb +5 -5
  125. metadata +290 -463
  126. checksums.yaml +0 -7
  127. data/.yardopts +0 -10
  128. data/Gemfile +0 -11
  129. data/data/images/16bit.color +0 -0
  130. data/data/images/dice.color +0 -0
  131. data/data/images/indexed_color.dat +0 -0
  132. data/data/images/indexed_color.png +0 -0
  133. data/data/images/page_white_text.color +0 -0
  134. data/lib/prawn/font_metric_cache.rb +0 -47
  135. data/lib/prawn/graphics/patterns.rb +0 -138
  136. data/lib/prawn/image_handler.rb +0 -36
  137. data/lib/prawn/soft_mask.rb +0 -96
  138. data/lib/prawn/table/cell/span_dummy.rb +0 -93
  139. data/lib/prawn/table/column_width_calculator.rb +0 -61
  140. data/lib/prawn/text/formatted/arranger.rb +0 -290
  141. data/lib/prawn/text/formatted/line_wrap.rb +0 -266
  142. data/lib/prawn/text/formatted/wrap.rb +0 -150
  143. data/lib/prawn/utilities.rb +0 -46
  144. data/manual/basic_concepts/adding_pages.rb +0 -27
  145. data/manual/basic_concepts/basic_concepts.rb +0 -34
  146. data/manual/basic_concepts/creation.rb +0 -39
  147. data/manual/basic_concepts/cursor.rb +0 -33
  148. data/manual/basic_concepts/measurement.rb +0 -25
  149. data/manual/basic_concepts/origin.rb +0 -38
  150. data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
  151. data/manual/bounding_box/bounding_box.rb +0 -39
  152. data/manual/bounding_box/bounds.rb +0 -49
  153. data/manual/bounding_box/canvas.rb +0 -24
  154. data/manual/bounding_box/creation.rb +0 -23
  155. data/manual/bounding_box/indentation.rb +0 -46
  156. data/manual/bounding_box/nesting.rb +0 -45
  157. data/manual/bounding_box/russian_boxes.rb +0 -40
  158. data/manual/bounding_box/stretchy.rb +0 -31
  159. data/manual/document_and_page_options/background.rb +0 -27
  160. data/manual/document_and_page_options/document_and_page_options.rb +0 -32
  161. data/manual/document_and_page_options/metadata.rb +0 -23
  162. data/manual/document_and_page_options/page_margins.rb +0 -38
  163. data/manual/document_and_page_options/page_size.rb +0 -34
  164. data/manual/document_and_page_options/print_scaling.rb +0 -20
  165. data/manual/example_file.rb +0 -111
  166. data/manual/example_helper.rb +0 -411
  167. data/manual/example_package.rb +0 -53
  168. data/manual/example_section.rb +0 -46
  169. data/manual/graphics/circle_and_ellipse.rb +0 -22
  170. data/manual/graphics/color.rb +0 -24
  171. data/manual/graphics/common_lines.rb +0 -30
  172. data/manual/graphics/fill_and_stroke.rb +0 -42
  173. data/manual/graphics/fill_rules.rb +0 -37
  174. data/manual/graphics/gradients.rb +0 -37
  175. data/manual/graphics/graphics.rb +0 -58
  176. data/manual/graphics/helper.rb +0 -24
  177. data/manual/graphics/line_width.rb +0 -35
  178. data/manual/graphics/lines_and_curves.rb +0 -41
  179. data/manual/graphics/polygon.rb +0 -29
  180. data/manual/graphics/rectangle.rb +0 -21
  181. data/manual/graphics/rotate.rb +0 -28
  182. data/manual/graphics/scale.rb +0 -41
  183. data/manual/graphics/soft_masks.rb +0 -46
  184. data/manual/graphics/stroke_cap.rb +0 -31
  185. data/manual/graphics/stroke_dash.rb +0 -48
  186. data/manual/graphics/stroke_join.rb +0 -30
  187. data/manual/graphics/translate.rb +0 -29
  188. data/manual/graphics/transparency.rb +0 -35
  189. data/manual/images/absolute_position.rb +0 -23
  190. data/manual/images/fit.rb +0 -21
  191. data/manual/images/horizontal.rb +0 -25
  192. data/manual/images/images.rb +0 -40
  193. data/manual/images/plain_image.rb +0 -18
  194. data/manual/images/scale.rb +0 -22
  195. data/manual/images/vertical.rb +0 -28
  196. data/manual/images/width_and_height.rb +0 -25
  197. data/manual/layout/boxes.rb +0 -27
  198. data/manual/layout/content.rb +0 -25
  199. data/manual/layout/layout.rb +0 -28
  200. data/manual/layout/simple_grid.rb +0 -23
  201. data/manual/manual/cover.rb +0 -36
  202. data/manual/manual/foreword.rb +0 -85
  203. data/manual/manual/how_to_read_this_manual.rb +0 -41
  204. data/manual/manual/manual.rb +0 -34
  205. data/manual/outline/add_subsection_to.rb +0 -61
  206. data/manual/outline/insert_section_after.rb +0 -47
  207. data/manual/outline/outline.rb +0 -32
  208. data/manual/outline/sections_and_pages.rb +0 -67
  209. data/manual/repeatable_content/page_numbering.rb +0 -54
  210. data/manual/repeatable_content/repeatable_content.rb +0 -31
  211. data/manual/repeatable_content/repeater.rb +0 -55
  212. data/manual/repeatable_content/stamp.rb +0 -41
  213. data/manual/security/encryption.rb +0 -31
  214. data/manual/security/permissions.rb +0 -38
  215. data/manual/security/security.rb +0 -28
  216. data/manual/syntax_highlight.rb +0 -52
  217. data/manual/table/basic_block.rb +0 -53
  218. data/manual/table/before_rendering_page.rb +0 -26
  219. data/manual/table/cell_border_lines.rb +0 -24
  220. data/manual/table/cell_borders_and_bg.rb +0 -31
  221. data/manual/table/cell_dimensions.rb +0 -30
  222. data/manual/table/cell_text.rb +0 -38
  223. data/manual/table/column_widths.rb +0 -30
  224. data/manual/table/content_and_subtables.rb +0 -39
  225. data/manual/table/creation.rb +0 -27
  226. data/manual/table/filtering.rb +0 -36
  227. data/manual/table/flow_and_header.rb +0 -17
  228. data/manual/table/image_cells.rb +0 -33
  229. data/manual/table/position.rb +0 -29
  230. data/manual/table/row_colors.rb +0 -20
  231. data/manual/table/span.rb +0 -30
  232. data/manual/table/style.rb +0 -22
  233. data/manual/table/table.rb +0 -52
  234. data/manual/table/width.rb +0 -27
  235. data/manual/text/alignment.rb +0 -44
  236. data/manual/text/color.rb +0 -24
  237. data/manual/text/column_box.rb +0 -32
  238. data/manual/text/fallback_fonts.rb +0 -37
  239. data/manual/text/font.rb +0 -41
  240. data/manual/text/font_size.rb +0 -45
  241. data/manual/text/font_style.rb +0 -23
  242. data/manual/text/formatted_callbacks.rb +0 -60
  243. data/manual/text/formatted_text.rb +0 -54
  244. data/manual/text/free_flowing_text.rb +0 -51
  245. data/manual/text/group.rb +0 -31
  246. data/manual/text/inline.rb +0 -43
  247. data/manual/text/kerning_and_character_spacing.rb +0 -39
  248. data/manual/text/leading.rb +0 -25
  249. data/manual/text/line_wrapping.rb +0 -41
  250. data/manual/text/paragraph_indentation.rb +0 -26
  251. data/manual/text/positioned_text.rb +0 -38
  252. data/manual/text/registering_families.rb +0 -48
  253. data/manual/text/rendering_and_color.rb +0 -37
  254. data/manual/text/right_to_left_text.rb +0 -43
  255. data/manual/text/rotation.rb +0 -43
  256. data/manual/text/single_usage.rb +0 -37
  257. data/manual/text/text.rb +0 -75
  258. data/manual/text/text_box_excess.rb +0 -32
  259. data/manual/text/text_box_extensions.rb +0 -45
  260. data/manual/text/text_box_overflow.rb +0 -44
  261. data/manual/text/utf8.rb +0 -28
  262. data/manual/text/win_ansi_charset.rb +0 -59
  263. data/spec/acceptance/png.rb +0 -23
  264. data/spec/column_box_spec.rb +0 -65
  265. data/spec/extensions/encoding_helpers.rb +0 -9
  266. data/spec/font_metric_cache_spec.rb +0 -52
  267. data/spec/image_handler_spec.rb +0 -54
  268. data/spec/soft_mask_spec.rb +0 -117
  269. data/spec/table/span_dummy_spec.rb +0 -17
data/spec/span_spec.rb CHANGED
@@ -2,24 +2,24 @@
2
2
 
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
 
5
- describe "drawing span" do
6
-
7
- before do
5
+ describe "drawing span" do
6
+
7
+ def setup
8
8
  Prawn.debug = false
9
9
  create_pdf
10
10
  end
11
11
 
12
- after do
12
+ def teardown
13
13
  Prawn.debug = true
14
14
  end
15
15
 
16
16
  it "should only accept :position as option in debug mode" do
17
17
  Prawn.debug = true
18
- lambda { @pdf.span(350, {:x => 3}) {} }.should raise_error(Prawn::Errors::UnknownOption)
18
+ lambda { @pdf.span(350, {:x => 3}) {} }.should.raise(Prawn::Errors::UnknownOption)
19
19
  end
20
20
 
21
21
  it "should have raise an error if :position is invalid" do
22
- lambda { @pdf.span(350, :position => :x) {} }.should raise_error(ArgumentError)
22
+ lambda { @pdf.span(350, :position => :x) {} }.should.raise(ArgumentError)
23
23
  end
24
24
 
25
25
  it "should restore the margin box when bounding box exits" do
@@ -28,8 +28,9 @@ describe "drawing span" do
28
28
  @pdf.span(350, :position => :center) do
29
29
  @pdf.text "Here's some centered text in a 350 point column. " * 100
30
30
  end
31
-
31
+
32
32
  @pdf.bounds.should == margin_box
33
+
33
34
  end
34
35
 
35
36
  it "should do create a margin box" do
@@ -37,8 +38,12 @@ describe "drawing span" do
37
38
  margin_box = @pdf.span(350, :position => :center) do
38
39
  @pdf.text "Here's some centered text in a 350 point column. " * 100
39
40
  end
40
-
41
+
41
42
  margin_box.top.should == 792.0
42
- margin_box.bottom.should == 0
43
- end
43
+ margin_box.bottom.should == 0
44
+
45
+ end
46
+
44
47
  end
48
+
49
+
data/spec/spec_helper.rb CHANGED
@@ -2,53 +2,29 @@
2
2
 
3
3
  puts "Prawn specs: Running on Ruby Version: #{RUBY_VERSION}"
4
4
 
5
+ require "rubygems"
5
6
  require "bundler"
6
7
  Bundler.setup
7
8
 
8
- if ENV["COVERAGE"]
9
- require "simplecov"
10
- SimpleCov.start do
11
- add_filter "/spec/"
12
- end
13
- end
14
-
15
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
16
10
  require "prawn"
17
11
 
18
12
  Prawn.debug = true
19
13
 
20
- #require "test/spec"
21
- require "rspec"
22
- require "mocha/api"
14
+ require "test/spec"
15
+ require "mocha"
23
16
  require "pdf/reader"
24
17
  require "pdf/inspector"
25
18
 
26
- # Requires supporting ruby files with custom matchers and macros, etc,
27
- # in spec/extensions/ and its subdirectories.
28
- Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each {|f| require f }
29
-
30
- RSpec.configure do |config|
31
- config.mock_framework = :mocha
32
- config.include EncodingHelpers
33
- config.treat_symbols_as_metadata_keys_with_true_values = true
34
- end
35
-
36
19
  def create_pdf(klass=Prawn::Document)
37
20
  @pdf = klass.new(:margin => 0)
38
- end
39
-
40
- RSpec::Matchers.define :have_parseable_xobjects do
41
- match do |actual|
42
- expect { PDF::Inspector::XObject.analyze(actual.render) }.not_to raise_error
43
- true
44
- end
45
- failure_message_for_should do |actual|
46
- "expected that #{actual}'s XObjects could be successfully parsed"
47
- end
48
- end
21
+ end
49
22
 
50
23
  # Make some methods public to assist in testing
51
24
  module Prawn::Graphics
52
25
  public :map_to_absolute
53
26
  end
54
27
 
28
+ require File.expand_path(File.join(File.dirname(__FILE__),
29
+ %w[extensions mocha]))
30
+
data/spec/stamp_spec.rb CHANGED
@@ -3,20 +3,19 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
  describe "create_stamp before any page is added" do
4
4
  it "should work with the font class" do
5
5
  @pdf = Prawn::Document.new(:skip_page_creation => true)
6
-
7
- # If anything goes wrong, Prawn::Errors::NotOnPage will be raised
8
- @pdf.create_stamp("my_stamp") do
9
- @pdf.font.height
10
- end
6
+ lambda {
7
+ @pdf.create_stamp("my_stamp") do
8
+ @pdf.font.height
9
+ end
10
+ }.should.not.raise(Prawn::Errors::NotOnPage)
11
11
  end
12
-
13
12
  it "should work with setting color" do
14
13
  @pdf = Prawn::Document.new(:skip_page_creation => true)
15
-
16
- # If anything goes wrong, Prawn::Errors::NotOnPage will be raised
17
- @pdf.create_stamp("my_stamp") do
18
- @pdf.fill_color = 'ff0000'
19
- end
14
+ lambda {
15
+ @pdf.create_stamp("my_stamp") do
16
+ @pdf.fill_color = 'ff0000'
17
+ end
18
+ }.should.not.raise(Prawn::Errors::NotOnPage)
20
19
  end
21
20
  end
22
21
 
@@ -34,42 +33,42 @@ describe "#stamp_at" do
34
33
  end
35
34
 
36
35
  describe "Document with a stamp" do
37
- it "should raise_error NameTaken error when attempt to create stamp "+
36
+ it "should raise NameTaken error when attempt to create stamp "+
38
37
  "with same name as an existing stamp" do
39
38
  create_pdf
40
39
  @pdf.create_stamp("MyStamp")
41
40
  lambda {
42
41
  @pdf.create_stamp("MyStamp")
43
- }.should raise_error(Prawn::Errors::NameTaken)
42
+ }.should.raise(Prawn::Errors::NameTaken)
44
43
  end
45
-
46
- it "should raise_error InvalidName error when attempt to create "+
44
+
45
+ it "should raise InvalidName error when attempt to create "+
47
46
  "stamp with a blank name" do
48
47
  create_pdf
49
48
  lambda {
50
49
  @pdf.create_stamp("")
51
- }.should raise_error(Prawn::Errors::InvalidName)
50
+ }.should.raise(Prawn::Errors::InvalidName)
52
51
  end
53
-
52
+
54
53
  it "a new XObject should be defined for each stamp created" do
55
54
  create_pdf
56
55
  @pdf.create_stamp("MyStamp")
57
56
  @pdf.create_stamp("AnotherStamp")
58
57
  @pdf.stamp("MyStamp")
59
58
  @pdf.stamp("AnotherStamp")
60
-
59
+
61
60
  inspector = PDF::Inspector::XObject.analyze(@pdf.render)
62
61
  xobjects = inspector.page_xobjects.last
63
62
  xobjects.length.should == 2
64
63
  end
65
64
 
66
65
  it "calling stamp with a name that does not match an existing stamp "+
67
- "should raise_error UndefinedObjectName" do
66
+ "should raise UndefinedObjectName" do
68
67
  create_pdf
69
68
  @pdf.create_stamp("MyStamp")
70
69
  lambda {
71
70
  @pdf.stamp("OtherStamp")
72
- }.should raise_error(Prawn::Errors::UndefinedObjectName)
71
+ }.should.raise(Prawn::Errors::UndefinedObjectName)
73
72
  end
74
73
 
75
74
  it "stamp should be drawn into the document each time stamp is called" do
@@ -100,13 +99,13 @@ describe "Document with a stamp" do
100
99
  objects = output.split("endobj")
101
100
  objects.each do |object|
102
101
  if object =~ /\/Type \/Page$/
103
- object.should_not =~ /\/ExtGState/
102
+ object.should.not =~ /\/ExtGState/
104
103
  elsif object =~ /\/Type \/XObject$/
105
104
  object.should =~ /\/ExtGState/
106
105
  end
107
106
  end
108
107
  end
109
-
108
+
110
109
  it "stamp stream should be wrapped in a graphic state" do
111
110
  create_pdf
112
111
  @pdf.create_stamp("MyStamp") do
@@ -116,11 +115,11 @@ describe "Document with a stamp" do
116
115
  stamps = PDF::Inspector::XObject.analyze(@pdf.render)
117
116
  stamps.xobject_streams[:Stamp1].data.chomp.should =~ /q(.|\s)*Q\Z/
118
117
  end
119
-
118
+
120
119
  it "should not add to the page graphic state stack " do
121
120
  create_pdf
122
121
  @pdf.state.page.stack.stack.size.should == 1
123
-
122
+
124
123
  @pdf.create_stamp("MyStamp") do
125
124
  @pdf.save_graphics_state
126
125
  @pdf.save_graphics_state
@@ -130,7 +129,7 @@ describe "Document with a stamp" do
130
129
  end
131
130
  @pdf.state.page.stack.stack.size.should == 1
132
131
  end
133
-
132
+
134
133
  it "should be able to change fill and stroke colors within the stamp stream" do
135
134
  create_pdf
136
135
  @pdf.create_stamp("MyStamp") do
@@ -140,10 +139,10 @@ describe "Document with a stamp" do
140
139
  @pdf.stamp("MyStamp")
141
140
  stamps = PDF::Inspector::XObject.analyze(@pdf.render)
142
141
  stamp_stream = stamps.xobject_streams[:Stamp1].data
143
- stamp_stream.should include("/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn")
144
- stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
142
+ stamp_stream.should.include "/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn"
143
+ stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN"
145
144
  end
146
-
145
+
147
146
  it "should save the color space even when same as current page color space" do
148
147
  create_pdf
149
148
  @pdf.stroke_color(100, 100, 20, 0)
@@ -153,6 +152,8 @@ describe "Document with a stamp" do
153
152
  @pdf.stamp("MyStamp")
154
153
  stamps = PDF::Inspector::XObject.analyze(@pdf.render)
155
154
  stamp_stream = stamps.xobject_streams[:Stamp1].data
156
- stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
155
+ stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN"
157
156
  end
157
+
158
+
158
159
  end
@@ -7,24 +7,24 @@ describe "When stroking with default settings" do
7
7
  it "cap_style should be :butt" do
8
8
  @pdf.cap_style.should == :butt
9
9
  end
10
-
10
+
11
11
  it "join_style should be :miter" do
12
12
  @pdf.join_style.should == :miter
13
13
  end
14
14
 
15
- it "dashed? should be_false" do
16
- @pdf.should_not be_dashed
15
+ it "dashed? should be false" do
16
+ @pdf.should.not.be.dashed
17
17
  end
18
18
  end
19
19
 
20
20
  describe "Cap styles" do
21
21
  before(:each) { create_pdf }
22
-
22
+
23
23
  it "should be able to use assignment operator" do
24
24
  @pdf.cap_style = :round
25
25
  @pdf.cap_style.should == :round
26
26
  end
27
-
27
+
28
28
  describe "#cap_style(:butt)" do
29
29
  it "rendered PDF should include butt style cap" do
30
30
  @pdf.cap_style(:butt)
@@ -60,12 +60,12 @@ end
60
60
 
61
61
  describe "Join styles" do
62
62
  before(:each) { create_pdf }
63
-
63
+
64
64
  it "should be able to use assignment operator" do
65
65
  @pdf.join_style = :round
66
66
  @pdf.join_style.should == :round
67
67
  end
68
-
68
+
69
69
  describe "#join_style(:miter)" do
70
70
  it "rendered PDF should include miter style join" do
71
71
  @pdf.join_style(:miter)
@@ -101,16 +101,16 @@ end
101
101
 
102
102
  describe "Dashes" do
103
103
  before(:each) { create_pdf }
104
-
104
+
105
105
  it "should be able to use assignment operator" do
106
106
  @pdf.dash = 2
107
- @pdf.should be_dashed
107
+ @pdf.should.be.dashed
108
108
  end
109
109
 
110
110
  describe "setting a dash" do
111
- it "dashed? should be_true" do
111
+ it "dashed? should be true" do
112
112
  @pdf.dash(2)
113
- @pdf.should be_dashed
113
+ @pdf.should.be.dashed
114
114
  end
115
115
  it "rendered PDF should include a stroked dash" do
116
116
  @pdf.dash(2)
@@ -143,24 +143,6 @@ describe "Dashes" do
143
143
  end
144
144
  end
145
145
 
146
- describe "setting a dash by using an array" do
147
- it "dash and spaces should be set from the array" do
148
- @pdf.dash([1,2,3,4])
149
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
150
- dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
151
- end
152
- it "space options has to be ignored" do
153
- @pdf.dash([1,2,3,4], :space => 3)
154
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
155
- dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
156
- end
157
- it "phase options should be correctly used" do
158
- @pdf.dash([1,2,3,4], :phase => 3)
159
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
160
- dashes.stroke_dash.should == [[1, 2, 3, 4], 3]
161
- end
162
- end
163
-
164
146
  describe "clearing stroke dash" do
165
147
  it "should restore solid line" do
166
148
  @pdf.dash(2)
@@ -169,7 +151,7 @@ describe "Dashes" do
169
151
  dashes.stroke_dash.should == [[], 0]
170
152
  end
171
153
  end
172
-
154
+
173
155
  it "should carry the current dash settings over to new pages" do
174
156
  @pdf.dash(2)
175
157
  @pdf.start_new_page
@@ -177,19 +159,19 @@ describe "Dashes" do
177
159
  dashes.stroke_dash_count.should == 2
178
160
  dashes.stroke_dash.should == [[2, 2], 0]
179
161
  end
180
-
162
+
181
163
  describe "#dashed?" do
182
-
164
+
183
165
  it "an initial document should not be dashed" do
184
166
  @pdf.dashed?.should == false
185
167
  end
186
-
168
+
187
169
  it "should return true if any of the currently active settings are dashed" do
188
170
  @pdf.dash(2)
189
171
  @pdf.save_graphics_state
190
172
  @pdf.dashed?.should == true
191
173
  end
192
-
174
+
193
175
  it "should return false if the document was most recently undashed" do
194
176
  @pdf.dash(2)
195
177
  @pdf.save_graphics_state
@@ -197,7 +179,7 @@ describe "Dashes" do
197
179
  @pdf.save_graphics_state
198
180
  @pdf.dashed?.should == false
199
181
  end
200
-
182
+
201
183
  it "should return true when restoring to a state that was dashed" do
202
184
  @pdf.dash(2)
203
185
  @pdf.save_graphics_state
@@ -205,7 +187,7 @@ describe "Dashes" do
205
187
  @pdf.restore_graphics_state
206
188
  @pdf.dashed?.should == true
207
189
  end
208
-
190
+
209
191
  end
210
192
 
211
193
  end
data/spec/table_spec.rb CHANGED
@@ -1,6 +1,6 @@
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
4
  require 'set'
5
5
 
6
6
  describe "Prawn::Table" do
@@ -12,7 +12,7 @@ describe "Prawn::Table" do
12
12
  end
13
13
 
14
14
  it "should return a Prawn::Table" do
15
- @table.should be_a_kind_of Prawn::Table
15
+ @table.should.be.an.instance_of Prawn::Table
16
16
  end
17
17
 
18
18
  it "should flatten the data into the @cells array in row-major order" do
@@ -29,158 +29,23 @@ describe "Prawn::Table" do
29
29
  lambda {
30
30
  data = [["foo","bar"],["baz",""]]
31
31
  @pdf.table(data)
32
- }.should_not raise_error
33
- end
32
+ }.should.not.raise
33
+ end
34
34
 
35
35
  it "should allow a table with a header but no body" do
36
- lambda { @pdf.table([["Header"]], :header => true) }.should_not raise_error
36
+ lambda { @pdf.table([["Header"]], :header => true) }.should.not.raise
37
37
  end
38
38
 
39
- it "should accurately count columns from data" do
39
+ # TODO: pending colspan
40
+ xit "should accurately count columns from data" do
40
41
  # First data row may contain colspan which would hide true column count
41
- data = [["Name:", {:content => "Some very long name", :colspan => 5}]]
42
+ data = [["Name:",{:text => "Some very long name", :colspan => 5}]]
42
43
  pdf = Prawn::Document.new
43
44
  table = Prawn::Table.new data, pdf
44
45
  table.column_widths.length.should == 6
45
46
  end
46
47
  end
47
48
 
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
-
184
49
  describe "#initialize" do
185
50
  before(:each) do
186
51
  @pdf = Prawn::Document.new
@@ -191,8 +56,7 @@ describe "Prawn::Table" do
191
56
  initializer.expects(:kick).once
192
57
 
193
58
  @pdf.table([["a"]]){
194
- initializer.kick
195
- }
59
+ self.should.be.an.instance_of(Prawn::Table); initializer.kick }
196
60
  end
197
61
 
198
62
  it "should call a 1-arg block with the document as the argument" do
@@ -200,7 +64,7 @@ describe "Prawn::Table" do
200
64
  initializer.expects(:kick).once
201
65
 
202
66
  @pdf.table([["a"]]){ |doc|
203
- doc.should be_a_kind_of(Prawn::Table); initializer.kick }
67
+ doc.should.be.an.instance_of(Prawn::Table); initializer.kick }
204
68
  end
205
69
 
206
70
  it "should proxy cell methods to #cells" do
@@ -216,7 +80,7 @@ describe "Prawn::Table" do
216
80
 
217
81
  it "should generate a text cell based on a String" do
218
82
  t = @pdf.table([["foo"]])
219
- t.cells[0,0].should be_a_kind_of(Prawn::Table::Cell::Text)
83
+ t.cells[0,0].should.be.a.kind_of(Prawn::Table::Cell::Text)
220
84
  end
221
85
 
222
86
  it "should pass through a text cell" do
@@ -233,14 +97,14 @@ describe "Prawn::Table" do
233
97
  end
234
98
 
235
99
  it "should select rows by number or range" do
236
- Set.new(@table.row(0).map { |c| c.content }).should ==
100
+ Set.new(@table.row(0).map { |c| c.content }).should ==
237
101
  Set.new(%w[R0C0 R0C1])
238
- Set.new(@table.rows(0..1).map { |c| c.content }).should ==
102
+ Set.new(@table.rows(0..1).map { |c| c.content }).should ==
239
103
  Set.new(%w[R0C0 R0C1 R1C0 R1C1])
240
104
  end
241
105
 
242
106
  it "should select rows by array" do
243
- Set.new(@table.rows([0, 1]).map { |c| c.content }).should ==
107
+ Set.new(@table.rows([0, 1]).map { |c| c.content }).should ==
244
108
  Set.new(%w[R0C0 R0C1 R1C0 R1C1])
245
109
  end
246
110
 
@@ -254,14 +118,14 @@ describe "Prawn::Table" do
254
118
  end
255
119
 
256
120
  it "should select columns by number or range" do
257
- Set.new(@table.column(0).map { |c| c.content }).should ==
121
+ Set.new(@table.column(0).map { |c| c.content }).should ==
258
122
  Set.new(%w[R0C0 R1C0])
259
- Set.new(@table.columns(0..1).map { |c| c.content }).should ==
123
+ Set.new(@table.columns(0..1).map { |c| c.content }).should ==
260
124
  Set.new(%w[R0C0 R0C1 R1C0 R1C1])
261
125
  end
262
126
 
263
127
  it "should select columns by array" do
264
- Set.new(@table.columns([0, 1]).map { |c| c.content }).should ==
128
+ Set.new(@table.columns([0, 1]).map { |c| c.content }).should ==
265
129
  Set.new(%w[R0C0 R0C1 R1C0 R1C1])
266
130
  end
267
131
 
@@ -279,13 +143,13 @@ describe "Prawn::Table" do
279
143
  end
280
144
 
281
145
  it "should accept a filter block, returning a cell proxy" do
282
- @table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c|
146
+ @table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c|
283
147
  c.content }.should == ["R0C1"]
284
148
  end
285
149
 
286
150
  it "should accept the [] method, returning a Cell or nil" do
287
151
  @table.cells[0, 0].content.should == "R0C0"
288
- @table.cells[12, 12].should be_nil
152
+ @table.cells[12, 12].should.be.nil
289
153
  end
290
154
 
291
155
  it "should proxy unknown methods to the cells" do
@@ -296,20 +160,6 @@ describe "Prawn::Table" do
296
160
  @table.cells[1, 0].height.should == 100
297
161
  end
298
162
 
299
- it "should ignore non-setter methods" do
300
- lambda {
301
- @table.cells.content_width
302
- }.should raise_error(NoMethodError)
303
- end
304
-
305
- it "skips cells that don't respond to the given method" do
306
- table = @pdf.make_table([[{:content => "R0", :colspan => 2}],
307
- %w[R1C0 R1C1]])
308
- lambda {
309
- table.row(0).font_style = :bold
310
- }.should_not raise_error
311
- end
312
-
313
163
  it "should accept the style method, proxying its calls to the cells" do
314
164
  @table.cells.style(:height => 200, :width => 200)
315
165
  @table.column(0).style(:width => 100)
@@ -354,14 +204,14 @@ describe "Prawn::Table" do
354
204
  end
355
205
 
356
206
  describe "width" do
357
- it "should raise_error an error if the given width is outside of range" do
207
+ it "should raise an error if the given width is outside of range" do
358
208
  lambda do
359
209
  @pdf.table([["foo"]], :width => 1)
360
- end.should raise_error(Prawn::Errors::CannotFit)
210
+ end.should.raise(Prawn::Errors::CannotFit)
361
211
 
362
212
  lambda do
363
213
  @pdf.table([[@long_text]], :width => @pdf.bounds.width + 100)
364
- end.should raise_error(Prawn::Errors::CannotFit)
214
+ end.should.raise(Prawn::Errors::CannotFit)
365
215
  end
366
216
 
367
217
  it "should accept the natural width for small tables" do
@@ -370,7 +220,7 @@ describe "Prawn::Table" do
370
220
  @table.width.should == @table.cells[0, 0].natural_content_width + pad
371
221
  end
372
222
 
373
- it "width should == sum(column_widths)" do
223
+ it "width should equal sum(column_widths)" do
374
224
  table = Prawn::Table.new([%w[ a b c ], %w[d e f]], @pdf) do
375
225
  column(0).width = 50
376
226
  column(1).width = 100
@@ -403,13 +253,13 @@ describe "Prawn::Table" do
403
253
  "column widths within a single table" do
404
254
  hpad, fs = 10, 6
405
255
  stretchy_columns = 2
406
-
256
+
407
257
  col0_width = 50
408
258
  col1_width = @pdf.width_of("foo", :size => fs)
409
259
  col2_width = @pdf.width_of("foobar", :size => fs)
410
260
  col3_width = 150
411
261
 
412
- table = Prawn::Table.new( [%w[snake foo b apple],
262
+ table = Prawn::Table.new( [%w[snake foo b apple],
413
263
  %w[kitten d foobar banana]], @pdf,
414
264
  :cell_style => { :padding => hpad, :size => fs }) do
415
265
 
@@ -417,8 +267,8 @@ describe "Prawn::Table" do
417
267
  column(3).width = col3_width
418
268
  end
419
269
 
420
- table.width.should == col1_width + col2_width +
421
- 2*stretchy_columns*hpad +
270
+ table.width.should == col1_width + col2_width +
271
+ 2*stretchy_columns*hpad +
422
272
  col0_width + col3_width
423
273
  end
424
274
 
@@ -427,7 +277,7 @@ describe "Prawn::Table" do
427
277
  col1_width = 20
428
278
  col3_width = 60
429
279
 
430
- table = Prawn::Table.new( [["snake", "foo", "b",
280
+ table = Prawn::Table.new( [["snake", "foo", "b",
431
281
  "some long, long text that will wrap"],
432
282
  %w[kitten d foobar banana]], @pdf,
433
283
  :width => 150) do
@@ -444,11 +294,11 @@ describe "Prawn::Table" do
444
294
  table.column(3).width.should == col3_width
445
295
  end
446
296
 
447
- it "should_not exceed the maximum width of the margin_box" do
297
+ it "should not exceed the maximum width of the margin_box" do
448
298
  expected_width = @pdf.margin_box.width
449
299
  data = [
450
300
  ['This is a column with a lot of text that should comfortably exceed '+
451
- 'the width of a normal document margin_box width', 'Some more text',
301
+ 'the width of a normal document margin_box width', 'Some more text',
452
302
  'and then some more', 'Just a bit more to be extra sure']
453
303
  ]
454
304
  table = Prawn::Table.new(data, @pdf)
@@ -456,25 +306,25 @@ describe "Prawn::Table" do
456
306
  table.width.should == expected_width
457
307
  end
458
308
 
459
- it "should_not exceed the maximum width of the margin_box even with" +
309
+ it "should not exceed the maximum width of the margin_box even with" +
460
310
  "manual widths specified" do
461
311
  expected_width = @pdf.margin_box.width
462
312
  data = [
463
313
  ['This is a column with a lot of text that should comfortably exceed '+
464
- 'the width of a normal document margin_box width', 'Some more text',
314
+ 'the width of a normal document margin_box width', 'Some more text',
465
315
  'and then some more', 'Just a bit more to be extra sure']
466
316
  ]
467
317
  table = Prawn::Table.new(data, @pdf) { column(1).width = 100 }
468
318
 
469
319
  table.width.should == expected_width
470
320
  end
471
-
321
+
472
322
  it "scales down only the non-preset column widths when the natural width" +
473
323
  "exceeds the maximum width of the margin_box" do
474
324
  expected_width = @pdf.margin_box.width
475
325
  data = [
476
326
  ['This is a column with a lot of text that should comfortably exceed '+
477
- 'the width of a normal document margin_box width', 'Some more text',
327
+ 'the width of a normal document margin_box width', 'Some more text',
478
328
  'and then some more', 'Just a bit more to be extra sure']
479
329
  ]
480
330
  table = Prawn::Table.new(data, @pdf) { column(1).width = 100; column(3).width = 50 }
@@ -510,29 +360,29 @@ describe "Prawn::Table" do
510
360
  end
511
361
 
512
362
  it "should allow table cells to be resized in block" do
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
363
+ lambda do
364
+ @pdf.table([%w[1 2 3 4 5]]) do |t|
365
+ t.width = 40
366
+ t.cells.size = 8
367
+ t.cells.padding = 0
368
+ end
369
+ end.should.not.raise(Prawn::Errors::CannotFit)
520
370
  end
521
371
 
522
372
  it "should be the width of the :width parameter" do
523
373
  expected_width = 300
524
- table = Prawn::Table.new( [%w[snake foo b apple],
374
+ table = Prawn::Table.new( [%w[snake foo b apple],
525
375
  %w[kitten d foobar banana]], @pdf,
526
376
  :width => expected_width)
527
377
 
528
378
  table.width.should == expected_width
529
379
  end
530
380
 
531
- it "should_not exceed the :width option" do
381
+ it "should not exceed the :width option" do
532
382
  expected_width = 400
533
383
  data = [
534
384
  ['This is a column with a lot of text that should comfortably exceed '+
535
- 'the width of a normal document margin_box width', 'Some more text',
385
+ 'the width of a normal document margin_box width', 'Some more text',
536
386
  'and then some more', 'Just a bit more to be extra sure']
537
387
  ]
538
388
  table = Prawn::Table.new(data, @pdf, :width => expected_width)
@@ -540,11 +390,11 @@ describe "Prawn::Table" do
540
390
  table.width.should == expected_width
541
391
  end
542
392
 
543
- it "should_not exceed the :width option even with manual widths specified" do
393
+ it "should not exceed the :width option even with manual widths specified" do
544
394
  expected_width = 400
545
395
  data = [
546
396
  ['This is a column with a lot of text that should comfortably exceed '+
547
- 'the width of a normal document margin_box width', 'Some more text',
397
+ 'the width of a normal document margin_box width', 'Some more text',
548
398
  'and then some more', 'Just a bit more to be extra sure']
549
399
  ]
550
400
  table = Prawn::Table.new(data, @pdf, :width => expected_width) do
@@ -554,26 +404,25 @@ describe "Prawn::Table" do
554
404
  table.width.should == expected_width
555
405
  end
556
406
 
557
- it "should calculate unspecified column widths even " +
407
+ # TODO: pending colspan
408
+ xit "should calculate unspecified column widths even " +
558
409
  "with colspan cells declared" do
559
410
  pdf = Prawn::Document.new
560
411
  hpad, fs = 3, 5
561
412
  columns = 3
562
413
 
563
- data = [ [ { :content => 'foo', :colspan => 2 }, "foobar" ],
414
+ data = [ [ { :text => 'foo', :colspan => 2 }, "foobar" ],
564
415
  [ "foo", "foo", "foo" ] ]
565
416
  table = Prawn::Table.new( data, pdf,
566
- :cell_style => {
567
- :padding_left => hpad, :padding_right => hpad,
568
- :size => fs
569
- })
417
+ :horizontal_padding => hpad,
418
+ :font_size => fs )
570
419
 
571
420
  col0_width = pdf.width_of("foo", :size => fs) # cell 1, 0
572
421
  col1_width = pdf.width_of("foo", :size => fs) # cell 1, 1
573
422
  col2_width = pdf.width_of("foobar", :size => fs) # cell 0, 1 (at col 2)
574
423
 
575
- table.width.should == col0_width + col1_width +
576
- col2_width + 2*columns*hpad
424
+ table.width.should == col0_width.ceil + col1_width.ceil +
425
+ col2_width.ceil + 2*columns*hpad
577
426
  end
578
427
  end
579
428
 
@@ -589,16 +438,16 @@ describe "Prawn::Table" do
589
438
  @pdf.y.should == old_y - table.height
590
439
  end
591
440
 
592
- it "should_not wrap unnecessarily" do
441
+ it "should not wrap unnecessarily" do
593
442
  # Test for FP errors and glitches
594
443
  t = @pdf.table([["Bender Bending Rodriguez"]])
595
444
  h = @pdf.height_of("one line")
596
- (t.height - 10).should be < h*1.5
445
+ (t.height - 10).should.be < h*1.5
597
446
  end
598
447
 
599
- it "should have a height of n rows" do
448
+ it "should have a height of n rows" do
600
449
  data = [["foo"],["bar"],["baaaz"]]
601
-
450
+
602
451
  vpad = 4
603
452
  origin = @pdf.y
604
453
  @pdf.table data, :cell_style => { :padding => vpad }
@@ -608,8 +457,8 @@ describe "Prawn::Table" do
608
457
  line_gap = @pdf.font.line_gap
609
458
 
610
459
  num_rows = data.length
611
- table_height.should be_within(0.001).of(
612
- num_rows * font_height + 2*vpad*num_rows )
460
+ table_height.should.be.close(
461
+ num_rows * font_height + 2*vpad*num_rows, 0.001 )
613
462
  end
614
463
 
615
464
  end
@@ -642,10 +491,10 @@ describe "Prawn::Table" do
642
491
  @pdf.table([["foo"]], :column_widths => 500, :position => 123)
643
492
  end
644
493
 
645
- it "should raise_error an ArgumentError on unknown :position" do
494
+ it "should raise an ArgumentError on unknown :position" do
646
495
  lambda do
647
496
  @pdf.table([["foo"]], :position => :bratwurst)
648
- end.should raise_error(ArgumentError)
497
+ end.should.raise(ArgumentError)
649
498
  end
650
499
  end
651
500
 
@@ -667,7 +516,7 @@ describe "Prawn::Table" do
667
516
  end.page_count.should == 2
668
517
  end
669
518
 
670
- it "should_not start a new page before finishing out a row" do
519
+ it "should not start a new page before finishing out a row" do
671
520
  Prawn::Document.new do
672
521
  table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]])
673
522
  end.page_count.should == 1
@@ -680,7 +529,7 @@ describe "Prawn::Table" do
680
529
  end.page_count.should == 2
681
530
  end
682
531
 
683
- it "should_not start a new page to gain height when at the top of " +
532
+ it "should not start a new page to gain height when at the top of " +
684
533
  "a bounding box, even if stretchy" do
685
534
  Prawn::Document.new do
686
535
  bounding_box([bounds.left, bounds.top - 20], :width => 400) do
@@ -707,7 +556,7 @@ describe "Prawn::Table" do
707
556
 
708
557
  output = PDF::Inspector::Page.analyze(pdf.render)
709
558
  # Ensure we only drew the header once, on the second page
710
- output.pages[0][:strings].should be_empty
559
+ output.pages[0][:strings].should.be.empty
711
560
  output.pages[1][:strings].should == ["Header", "Body"]
712
561
  end
713
562
 
@@ -741,90 +590,6 @@ describe "Prawn::Table" do
741
590
 
742
591
  t.draw
743
592
  end
744
-
745
- describe "before_rendering_page callback" do
746
- before(:each) { @pdf = Prawn::Document.new }
747
-
748
- it "is passed all cells to be rendered on that page" do
749
- kicked = 0
750
-
751
- @pdf.table([["foo"]] * 100) do |t|
752
- t.before_rendering_page do |page|
753
- page.row_count.should == ((kicked < 3) ? 30 : 10)
754
- page.column_count.should == 1
755
- page.row(0).first.content.should == "foo"
756
- page.row(-1).first.content.should == "foo"
757
- kicked += 1
758
- end
759
- end
760
-
761
- kicked.should == 4
762
- end
763
-
764
- it "numbers cells relative to their position on page" do
765
- @pdf.table([["foo"]] * 100) do |t|
766
- t.before_rendering_page do |page|
767
- page[0, 0].content.should == "foo"
768
- end
769
- end
770
- end
771
-
772
- it "changing cells in the callback affects their rendering" do
773
- seq = sequence("render order")
774
-
775
- t = @pdf.make_table([["foo"]] * 40) do |table|
776
- table.before_rendering_page do |page|
777
- page[0, 0].background_color = "ff0000"
778
- end
779
- end
780
-
781
- t.cells[30, 0].stubs(:draw_background).checking do |xy|
782
- t.cells[30, 0].background_color.should == 'ff0000'
783
- end
784
- t.cells[31, 0].stubs(:draw_background).checking do |xy|
785
- t.cells[31, 0].background_color.should == nil
786
- end
787
-
788
- t.draw
789
- end
790
-
791
- it "passes headers on page 2+" do
792
- @pdf.table([["header"]] + [["foo"]] * 100, :header => true) do |t|
793
- t.before_rendering_page do |page|
794
- page[0, 0].content.should == "header"
795
- end
796
- end
797
- end
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
-
810
- it "allows headers to be changed" do
811
- seq = sequence("render order")
812
- @pdf.expects(:draw_text!).with { |t, _| t == "hdr1"}.in_sequence(seq)
813
- @pdf.expects(:draw_text!).with { |t, _| t == "foo"}.times(29).in_sequence(seq)
814
- # Verify that the changed cell doesn't mutate subsequent pages
815
- @pdf.expects(:draw_text!).with { |t, _| t == "header"}.in_sequence(seq)
816
- @pdf.expects(:draw_text!).with { |t, _| t == "foo"}.times(11).in_sequence(seq)
817
-
818
- set_first_page_headers = false
819
- @pdf.table([["header"]] + [["foo"]] * 40, :header => true) do |t|
820
- t.before_rendering_page do |page|
821
- # only change first page header
822
- page[0, 0].content = "hdr1" unless set_first_page_headers
823
- set_first_page_headers = true
824
- end
825
- end
826
- end
827
- end
828
593
  end
829
594
 
830
595
  describe "#style" do
@@ -845,17 +610,11 @@ describe "Prawn::Table" do
845
610
  it "should default to {} for the hash argument" do
846
611
  stylable = stub()
847
612
  stylable.expects(:style).with({}).once
848
-
613
+
849
614
  Prawn::Document.new do
850
615
  table([["x"]]) { style(stylable) }
851
616
  end
852
617
  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
859
618
  end
860
619
 
861
620
  describe "row_colors" do
@@ -869,41 +628,16 @@ describe "Prawn::Table" do
869
628
  it "should ignore headers" do
870
629
  data = [["header"], ["foo"], ["bar"], ["baz"]]
871
630
  pdf = Prawn::Document.new
872
- t = pdf.table(data, :header => true,
631
+ t = pdf.table(data, :header => true,
873
632
  :row_colors => ['cccccc', 'ffffff']) do
874
633
  row(0).background_color = '333333'
875
634
  end
876
635
 
877
- t.cells.map{|x| x.background_color}.should ==
636
+ t.cells.map{|x| x.background_color}.should ==
878
637
  %w[333333 cccccc ffffff cccccc]
879
638
  end
880
639
 
881
- it "stripes rows consistently from page to page, skipping header rows" do
882
- data = [["header"]] + [["foo"]] * 70
883
- pdf = Prawn::Document.new
884
- t = pdf.make_table(data, :header => true,
885
- :row_colors => ['cccccc', 'ffffff']) do
886
- cells.padding = 0
887
- cells.size = 9
888
- row(0).size = 11
889
- end
890
-
891
- # page 1: header + 67 cells (odd number -- verifies that the next
892
- # page disrupts the even/odd coloring, since both the last data cell
893
- # on this page and the first one on the next are colored cccccc)
894
- Prawn::Table::Cell.expects(:draw_cells).with do |cells|
895
- cells.map { |c, (x, y)| c.background_color } ==
896
- [nil] + (%w[cccccc ffffff] * 33) + %w[cccccc]
897
- end
898
- # page 2: header and 3 data cells
899
- Prawn::Table::Cell.expects(:draw_cells).with do |cells|
900
- cells.map { |c, (x, y)| c.background_color } ==
901
- [nil] + %w[cccccc ffffff cccccc]
902
- end
903
- t.draw
904
- end
905
-
906
- it "should_not override an explicit background_color" do
640
+ it "should not override an explicit background_color" do
907
641
  data = [["foo"], ["bar"], ["baz"]]
908
642
  pdf = Prawn::Document.new
909
643
  table = pdf.table(data, :row_colors => ['cccccc', 'ffffff']) { |t|
@@ -920,7 +654,7 @@ describe "Prawn::Table" do
920
654
 
921
655
  it "should set the x-position of each cell based on widths" do
922
656
  @table = @pdf.table([["foo", "bar", "baz"]])
923
-
657
+
924
658
  x = 0
925
659
  (0..2).each do |col|
926
660
  cell = @table.cells[0, col]
@@ -935,7 +669,7 @@ describe "Prawn::Table" do
935
669
 
936
670
  (0..2).each do |row|
937
671
  cell = @table.cells[row, 0]
938
- cell.y.should be_within(0.01).of(y)
672
+ cell.y.should.be.close(y, 0.01)
939
673
  y -= cell.height
940
674
  end
941
675
  end
@@ -948,16 +682,16 @@ describe "Prawn::Table" do
948
682
  output.strings.should == data.flatten
949
683
  end
950
684
 
951
- it "should_not cause an error if rendering the very first row causes a " +
685
+ it "should not cause an error if rendering the very first row causes a " +
952
686
  "page break" do
953
- Prawn::Document.new do |pdf|
687
+ Prawn::Document.new do
954
688
  arr = Array(1..5).collect{|i| ["cell #{i}"] }
955
689
 
956
- pdf.move_down( pdf.y - (pdf.bounds.absolute_bottom + 3) )
690
+ move_down( y - (bounds.absolute_bottom + 3) )
957
691
 
958
692
  lambda {
959
- pdf.table(arr)
960
- }.should_not raise_error
693
+ table(arr)
694
+ }.should.not.raise
961
695
  end
962
696
  end
963
697
 
@@ -1000,7 +734,7 @@ describe "Prawn::Table" do
1000
734
  describe "in stretchy bounding boxes" do
1001
735
  it "should draw all cells on a row at the same y-position" do
1002
736
  pdf = Prawn::Document.new
1003
-
737
+
1004
738
  text_y = pdf.y.to_i - 5 # text starts 5pt below current y pos (padding)
1005
739
 
1006
740
  pdf.bounding_box([0, pdf.cursor], :width => pdf.bounds.width) do
@@ -1015,123 +749,30 @@ describe "Prawn::Table" do
1015
749
  end
1016
750
 
1017
751
  describe "headers" do
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
1026
-
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
1036
-
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
1058
-
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
1063
- end
1064
- end
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"]
1078
- end
752
+ it "should add headers to output when specified" do
753
+ data = [["a", "b"], ["foo","bar"],["baz","bang"]]
754
+ @pdf = Prawn::Document.new
755
+ @pdf.table(data, :header => true)
756
+ output = PDF::Inspector::Text.analyze(@pdf.render)
757
+ output.strings.should == data.flatten
1079
758
  end
1080
759
 
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
760
+ it "should repeat headers across pages" do
761
+ data = [["foo","bar"]] * 30
762
+ headers = ["baz","foobar"]
763
+ @pdf = Prawn::Document.new
764
+ @pdf.table([headers] + data, :header => true)
765
+ output = PDF::Inspector::Text.analyze(@pdf.render)
766
+ output.strings.should == headers + data.flatten[0..-3] + headers +
767
+ data.flatten[-2..-1]
768
+ end
1127
769
 
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
770
+ it "should not draw header twice when starting new page" do
771
+ @pdf = Prawn::Document.new
772
+ @pdf.y = 0
773
+ @pdf.table([["Header"], ["Body"]], :header => true)
774
+ output = PDF::Inspector::Text.analyze(@pdf.render)
775
+ output.strings.should == ["Header", "Body"]
1135
776
  end
1136
777
  end
1137
778
 
@@ -1144,8 +785,8 @@ describe "Prawn::Table" do
1144
785
 
1145
786
  it "can be created from an Array" do
1146
787
  cell = Prawn::Table::Cell.make(@pdf, [["foo"]])
1147
- cell.should be_a_kind_of(Prawn::Table::Cell::Subtable)
1148
- cell.subtable.should be_a_kind_of(Prawn::Table)
788
+ cell.should.be.an.instance_of(Prawn::Table::Cell::Subtable)
789
+ cell.subtable.should.be.an.instance_of(Prawn::Table)
1149
790
  end
1150
791
 
1151
792
  it "defaults its padding to zero" do
@@ -1155,7 +796,7 @@ describe "Prawn::Table" do
1155
796
  it "has a subtable accessor" do
1156
797
  @table.cells[0, 0].subtable.should == @subtable
1157
798
  end
1158
-
799
+
1159
800
  it "determines its dimensions from the subtable" do
1160
801
  @table.cells[0, 0].width.should == @subtable.width
1161
802
  @table.cells[0, 0].height.should == @subtable.height
@@ -1164,271 +805,35 @@ describe "Prawn::Table" do
1164
805
  end
1165
806
 
1166
807
  describe "An invalid table" do
1167
-
808
+
1168
809
  before(:each) do
1169
810
  @pdf = Prawn::Document.new
1170
811
  @bad_data = ["Single Nested Array"]
1171
812
  end
1172
-
1173
- it "should raise_error error when invalid table data is given" do
1174
- lambda {
813
+
814
+ it "should raise error when invalid table data is given" do
815
+ assert_raises(Prawn::Errors::InvalidTableData) do
1175
816
  @pdf.table(@bad_data)
1176
- }.should raise_error(Prawn::Errors::InvalidTableData)
817
+ end
1177
818
  end
1178
819
 
1179
- it "should raise_error an EmptyTableError with empty table data" do
820
+ it "should raise an EmptyTableError with empty table data" do
1180
821
  lambda {
1181
822
  data = []
1182
823
  @pdf = Prawn::Document.new
1183
824
  @pdf.table(data)
1184
- }.should raise_error( Prawn::Errors::EmptyTable )
1185
- end
825
+ }.should.raise( Prawn::Errors::EmptyTable )
826
+ end
1186
827
 
1187
- it "should raise_error an EmptyTableError with nil table data" do
828
+ it "should raise an EmptyTableError with nil table data" do
1188
829
  lambda {
1189
830
  data = nil
1190
831
  @pdf = Prawn::Document.new
1191
832
  @pdf.table(data)
1192
- }.should raise_error( Prawn::Errors::EmptyTable )
1193
- end
833
+ }.should.raise( Prawn::Errors::EmptyTable )
834
+ end
1194
835
 
1195
836
  end
1196
837
 
1197
838
  end
1198
839
 
1199
- describe "colspan / rowspan" do
1200
- before(:each) { create_pdf }
1201
-
1202
- it "doesn't raise an error" do
1203
- lambda {
1204
- @pdf.table([[{:content => "foo", :colspan => 2, :rowspan => 2}]])
1205
- }.should_not raise_error
1206
- end
1207
-
1208
- it "colspan is properly counted" do
1209
- t = @pdf.make_table([[{:content => "foo", :colspan => 2}]])
1210
- t.column_length.should == 2
1211
- end
1212
-
1213
- it "rowspan is properly counted" do
1214
- t = @pdf.make_table([[{:content => "foo", :rowspan => 2}]])
1215
- t.row_length.should == 2
1216
- end
1217
-
1218
- it "raises if colspan or rowspan are called after layout" do
1219
- lambda {
1220
- @pdf.table([["foo"]]) { cells[0, 0].colspan = 2 }
1221
- }.should raise_error(Prawn::Errors::InvalidTableSpan)
1222
-
1223
- lambda {
1224
- @pdf.table([["foo"]]) { cells[0, 0].rowspan = 2 }
1225
- }.should raise_error(Prawn::Errors::InvalidTableSpan)
1226
- end
1227
-
1228
- it "raises when spans overlap" do
1229
- lambda {
1230
- @pdf.table([["foo", {:content => "bar", :rowspan => 2}],
1231
- [{:content => "baz", :colspan => 2}]])
1232
- }.should raise_error(Prawn::Errors::InvalidTableSpan)
1233
- end
1234
-
1235
- it "table and cell width account for colspan" do
1236
- t = @pdf.table([["a", {:content => "b", :colspan => 2}]],
1237
- :column_widths => [100, 100, 100])
1238
- spanned = t.cells[0, 1]
1239
- spanned.colspan.should == 2
1240
- t.width.should == 300
1241
- t.cells.min_width.should == 300
1242
- t.cells.max_width.should == 300
1243
- spanned.width.should == 200
1244
- end
1245
-
1246
- it "table and cell height account for rowspan" do
1247
- t = @pdf.table([["a"], [{:content => "b", :rowspan => 2}]]) do
1248
- row(0..2).height = 100
1249
- end
1250
- spanned = t.cells[1, 0]
1251
- spanned.rowspan.should == 2
1252
- t.height.should == 300
1253
- spanned.height.should == 200
1254
- end
1255
-
1256
- it "provides the full content_width as drawing space" do
1257
- w = @pdf.make_table([["foo"]]).cells[0, 0].content_width
1258
-
1259
- t = @pdf.make_table([[{:content => "foo", :colspan => 2}]])
1260
- t.cells[0, 0].spanned_content_width.should == w
1261
- end
1262
-
1263
- it "dummy cells are not drawn" do
1264
- # make a fake master cell for the dummy cell to slave to
1265
- t = @pdf.make_table([[{:content => "foo", :colspan => 2}]])
1266
-
1267
- # drawing just a dummy cell should_not ink
1268
- @pdf.expects(:stroke_line).never
1269
- @pdf.expects(:draw_text!).never
1270
- Prawn::Table::Cell.draw_cells([t.cells[0, 1]])
1271
- end
1272
-
1273
- it "dummy cells do not add any height or width" do
1274
- t1 = @pdf.table([["foo"]])
1275
-
1276
- t2 = @pdf.table([[{:content => "foo", :colspan => 2}]])
1277
- t2.width.should == t1.width
1278
-
1279
- t3 = @pdf.table([[{:content => "foo", :rowspan => 2}]])
1280
- t3.height.should == t1.height
1281
- end
1282
-
1283
- it "dummy cells ignored by #style" do
1284
- t = @pdf.table([[{:content => "blah", :colspan => 2}]],
1285
- :cell_style => { :size => 9 })
1286
- t.cells[0, 0].size.should == 9
1287
- end
1288
-
1289
- context "inheriting master cell styles from dummy cell" do
1290
- # Relatively full coverage for all these attributes that should be
1291
- # inherited.
1292
- [["border_X_width", 20],
1293
- ["border_X_color", "123456"],
1294
- ["padding_X", 20]].each do |attribute, val|
1295
- attribute_right = attribute.sub("X", "right")
1296
- attribute_left = attribute.sub("X", "left")
1297
- attribute_bottom = attribute.sub("X", "bottom")
1298
- attribute_top = attribute.sub("X", "top")
1299
-
1300
- specify "#{attribute_right} of right column is inherited" do
1301
- t = @pdf.table([[{:content => "blah", :colspan => 2}]]) do |table|
1302
- table.column(1).send("#{attribute_right}=", val)
1303
- end
1304
-
1305
- t.cells[0, 0].send(attribute_right).should == val
1306
- end
1307
-
1308
- specify "#{attribute_bottom} of bottom row is inherited" do
1309
- t = @pdf.table([[{:content => "blah", :rowspan => 2}]]) do |table|
1310
- table.row(1).send("#{attribute_bottom}=", val)
1311
- end
1312
-
1313
- t.cells[0, 0].send(attribute_bottom).should == val
1314
- end
1315
-
1316
- specify "#{attribute_left} of right column is not inherited" do
1317
- t = @pdf.table([[{:content => "blah", :colspan => 2}]]) do |table|
1318
- table.column(1).send("#{attribute_left}=", val)
1319
- end
1320
-
1321
- t.cells[0, 0].send(attribute_left).should_not == val
1322
- end
1323
-
1324
- specify "#{attribute_right} of interior column is not inherited" do
1325
- t = @pdf.table([[{:content => "blah", :colspan => 3}]]) do |table|
1326
- table.column(1).send("#{attribute_right}=", val)
1327
- end
1328
-
1329
- t.cells[0, 0].send(attribute_right).should_not == val
1330
- end
1331
-
1332
- specify "#{attribute_bottom} of interior row is not inherited" do
1333
- t = @pdf.table([[{:content => "blah", :rowspan => 3}]]) do |table|
1334
- table.row(1).send("#{attribute_bottom}=", val)
1335
- end
1336
-
1337
- t.cells[0, 0].send(attribute_bottom).should_not == val
1338
- end
1339
-
1340
- specify "#{attribute_top} of bottom row is not inherited" do
1341
- t = @pdf.table([[{:content => "blah", :rowspan => 2}]]) do |table|
1342
- table.row(1).send("#{attribute_top}=", val)
1343
- end
1344
-
1345
- t.cells[0, 0].send(attribute_top).should_not == val
1346
- end
1347
- end
1348
- end
1349
-
1350
- it "splits natural width between cols in the group" do
1351
- t = @pdf.table([[{:content => "foo", :colspan => 2}]])
1352
- widths = t.column_widths
1353
- widths[0].should == widths[1]
1354
- end
1355
-
1356
- it "splits natural width between cols when width is increased" do
1357
- t = @pdf.table([[{:content => "foo", :colspan => 2}]],
1358
- :width => @pdf.bounds.width)
1359
- widths = t.column_widths
1360
- widths[0].should == widths[1]
1361
- end
1362
-
1363
- it "splits min-width between cols in the group" do
1364
- # Since column_widths, when reducing column widths, reduces proportional to
1365
- # the remaining width after each column's min width, we must ensure that the
1366
- # min-width is split proportionally in order to ensure the width is still
1367
- # split evenly when the width is reduced. (See "splits natural width between
1368
- # cols when width is reduced".)
1369
- t = @pdf.table([[{:content => "foo", :colspan => 2}]],
1370
- :width => 20)
1371
- t.column(0).min_width.should == t.column(1).min_width
1372
- end
1373
-
1374
- it "splits natural width between cols when width is reduced" do
1375
- t = @pdf.table([[{:content => "foo", :colspan => 2}]],
1376
- :width => 20)
1377
- widths = t.column_widths
1378
- widths[0].should == widths[1]
1379
- end
1380
-
1381
- it "honors a large, explicitly set table width" do
1382
- t = @pdf.table([[{:content => "AAAAAAAAAA", :colspan => 3}],
1383
- ["A", "B", "C"]],
1384
- :width => 400)
1385
-
1386
- t.column_widths.inject(0) { |sum, w| sum + w }.
1387
- should be_within(0.01).of(400)
1388
- end
1389
-
1390
- it "honors a small, explicitly set table width" do
1391
- t = @pdf.table([[{:content => "Lorem ipsum dolor sit amet " * 20,
1392
- :colspan => 3}],
1393
- ["A", "B", "C"]],
1394
- :width => 200)
1395
- t.column_widths.inject(0) { |sum, w| sum + w }.
1396
- should be_within(0.01).of(200)
1397
- end
1398
-
1399
- it "splits natural_content_height between rows in the group" do
1400
- t = @pdf.table([[{:content => "foo", :rowspan => 2}]])
1401
- heights = t.row_heights
1402
- heights[0].should == heights[1]
1403
- end
1404
-
1405
- it "skips column numbers that have been col-spanned" do
1406
- t = @pdf.table([["a", "b", {:content => "c", :colspan => 3}, "d"]])
1407
- t.cells[0, 0].content.should == "a"
1408
- t.cells[0, 1].content.should == "b"
1409
- t.cells[0, 2].content.should == "c"
1410
- t.cells[0, 3].should be_a_kind_of(Prawn::Table::Cell::SpanDummy)
1411
- t.cells[0, 4].should be_a_kind_of(Prawn::Table::Cell::SpanDummy)
1412
- t.cells[0, 5].content.should == "d"
1413
- end
1414
-
1415
- it "skips row/col positions that have been row-spanned" do
1416
- t = @pdf.table([["a", {:content => "b", :colspan => 2, :rowspan => 2}, "c"],
1417
- ["d", "e"],
1418
- ["f", "g", "h", "i"]])
1419
- t.cells[0, 0].content.should == "a"
1420
- t.cells[0, 1].content.should == "b"
1421
- t.cells[0, 2].should be_a_kind_of(Prawn::Table::Cell::SpanDummy)
1422
- t.cells[0, 3].content.should == "c"
1423
-
1424
- t.cells[1, 0].content.should == "d"
1425
- t.cells[1, 1].should be_a_kind_of(Prawn::Table::Cell::SpanDummy)
1426
- t.cells[1, 2].should be_a_kind_of(Prawn::Table::Cell::SpanDummy)
1427
- t.cells[1, 3].content.should == "e"
1428
-
1429
- t.cells[2, 0].content.should == "f"
1430
- t.cells[2, 1].content.should == "g"
1431
- t.cells[2, 2].content.should == "h"
1432
- t.cells[2, 3].content.should == "i"
1433
- end
1434
- end