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/cell_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
 
5
5
  module CellHelpers
6
6
 
@@ -10,6 +10,10 @@ module CellHelpers
10
10
  Prawn::Table::Cell::Text.new(@pdf, at, options)
11
11
  end
12
12
 
13
+ def close?(actual, expected, epsilon=0.01)
14
+ (actual - expected).abs < epsilon
15
+ end
16
+
13
17
  end
14
18
 
15
19
  describe "Prawn::Table::Cell" do
@@ -26,18 +30,13 @@ describe "Prawn::Table::Cell" do
26
30
  end
27
31
 
28
32
  it "should return a Cell" do
29
- @pdf.cell(:content => "text").should be_a_kind_of Prawn::Table::Cell
30
- end
31
-
32
- it "accepts :content => nil in a hash" do
33
- @pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
34
- @pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
33
+ @pdf.cell(:content => "text").should.be.a.kind_of Prawn::Table::Cell
35
34
  end
36
35
 
37
36
  it "should convert nil, Numeric, and Date values to strings" do
38
37
  [nil, 123, 123.45, Date.today].each do |value|
39
38
  c = @pdf.cell(:content => value)
40
- c.should be_a_kind_of Prawn::Table::Cell::Text
39
+ c.should.be.a.kind_of Prawn::Table::Cell::Text
41
40
  c.content.should == value.to_s
42
41
  end
43
42
  end
@@ -46,7 +45,7 @@ describe "Prawn::Table::Cell" do
46
45
  # used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
47
46
  c = Prawn::Table::Cell.make(@pdf,
48
47
  {:content => 'hello', :font_style => :bold})
49
- c.should be_a_kind_of Prawn::Table::Cell::Text
48
+ c.should.be.a.kind_of Prawn::Table::Cell::Text
50
49
  c.content.should == "hello"
51
50
  c.font.name.should == 'Helvetica-Bold'
52
51
  end
@@ -57,22 +56,22 @@ describe "Prawn::Table::Cell" do
57
56
  @pdf.expects(:move_down)
58
57
  @pdf.expects(:draw_text!).with { |text, options| text == "hello world" }
59
58
 
60
- @pdf.cell(:content => "hello world",
59
+ @pdf.cell(:content => "hello world",
61
60
  :at => [10, 20],
62
61
  :padding => [30, 40],
63
- :size => 7,
62
+ :size => 7,
64
63
  :font_style => :bold)
65
64
  end
66
65
  end
67
-
66
+
68
67
  describe "Prawn::Document#make_cell" do
69
68
  it "should not draw the cell" do
70
69
  Prawn::Table::Cell::Text.any_instance.expects(:draw).never
71
70
  @pdf.make_cell("text")
72
71
  end
73
-
72
+
74
73
  it "should return a Cell" do
75
- @pdf.make_cell("text", :size => 7).should be_a_kind_of Prawn::Table::Cell
74
+ @pdf.make_cell("text", :size => 7).should.be.a.kind_of Prawn::Table::Cell
76
75
  end
77
76
  end
78
77
 
@@ -87,12 +86,6 @@ describe "Prawn::Table::Cell" do
87
86
 
88
87
  c.style(:padding => 50, :size => 7)
89
88
  end
90
-
91
- it "ignores unknown properties" do
92
- c = cell(:content => 'text')
93
-
94
- c.style(:foobarbaz => 'frobnitz')
95
- end
96
89
  end
97
90
 
98
91
  describe "cell width" do
@@ -110,7 +103,7 @@ describe "Prawn::Table::Cell" do
110
103
 
111
104
  it "should incorporate padding when specified" do
112
105
  c = cell(:content => "text", :padding => [1, 2, 3, 4])
113
- c.width.should be_within(0.01).of(@pdf.width_of("text") + 6)
106
+ c.width.should.be.close(@pdf.width_of("text") + 6, 0.01)
114
107
  end
115
108
 
116
109
  it "should allow width to be reset after it has been calculated" do
@@ -124,7 +117,7 @@ describe "Prawn::Table::Cell" do
124
117
  it "should return proper width with size set" do
125
118
  text = "text " * 4
126
119
  c = cell(:content => text, :size => 7)
127
- c.width.should ==
120
+ c.width.should ==
128
121
  @pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3]
129
122
  end
130
123
 
@@ -135,14 +128,17 @@ describe "Prawn::Table::Cell" do
135
128
 
136
129
  it "content_width should exclude padding even with manual :width" do
137
130
  c = cell(:content => "text", :padding => 10, :width => 400)
138
- c.content_width.should be_within(0.01).of(380)
131
+ c.content_width.should.be.close(380, 0.01)
139
132
  end
140
133
 
141
134
  it "should have a reasonable minimum width that can fit @content" do
142
135
  c = cell(:content => "text", :padding => 10)
143
136
  min_content_width = c.min_width - c.padding[1] - c.padding[3]
144
137
 
145
- @pdf.height_of("text", :width => min_content_width).should be <
138
+ lambda { @pdf.height_of("text", :width => min_content_width) }.
139
+ should.not.raise(Prawn::Errors::CannotFit)
140
+
141
+ @pdf.height_of("text", :width => min_content_width).should.be <
146
142
  (5 * @pdf.height_of("text"))
147
143
  end
148
144
 
@@ -151,14 +147,14 @@ describe "Prawn::Table::Cell" do
151
147
  c.padding = 0
152
148
 
153
149
  # Make sure we use the new value of padding in calculating min_width
154
- c.min_width.should be < 100
150
+ c.min_width.should.be < 100
155
151
  end
156
152
 
157
153
  it "should defer min_width's evaluation of size" do
158
154
  c = cell(:content => "text", :size => 50)
159
155
  c.size = 8
160
156
  c.padding = 0
161
- c.min_width.should be < 10
157
+ c.min_width.should.be < 10
162
158
  end
163
159
 
164
160
  end
@@ -168,7 +164,7 @@ describe "Prawn::Table::Cell" do
168
164
 
169
165
  it "should be calculated for text" do
170
166
  c = cell(:content => "text")
171
- c.height.should ==
167
+ c.height.should ==
172
168
  @pdf.height_of("text", :width => @pdf.width_of("text")) +
173
169
  c.padding[0] + c.padding[3]
174
170
  end
@@ -180,8 +176,8 @@ describe "Prawn::Table::Cell" do
180
176
 
181
177
  it "should incorporate :padding when specified" do
182
178
  c = cell(:content => "text", :padding => [1, 2, 3, 4])
183
- c.height.should be_within(0.01).of(1 + 3 +
184
- @pdf.height_of("text", :width => @pdf.width_of("text")))
179
+ c.height.should.be.close(1 + 3 +
180
+ @pdf.height_of("text", :width => @pdf.width_of("text")), 0.01)
185
181
  end
186
182
 
187
183
  it "should allow height to be reset after it has been calculated" do
@@ -215,10 +211,10 @@ describe "Prawn::Table::Cell" do
215
211
  c = cell(:content => "text", :padding => 10)
216
212
  c.content_height.should == @pdf.height_of("text")
217
213
  end
218
-
214
+
219
215
  it "content_height should exclude padding even with manual :height" do
220
216
  c = cell(:content => "text", :padding => 10, :height => 400)
221
- c.content_height.should be_within(0.01).of(380)
217
+ c.content_height.should.be.close(380, 0.01)
222
218
  end
223
219
  end
224
220
 
@@ -239,7 +235,7 @@ describe "Prawn::Table::Cell" do
239
235
  c = cell(:content => "text", :padding => [20, 30])
240
236
  c.padding.should == [20, 30, 20, 30]
241
237
  end
242
-
238
+
243
239
  it "should accept [t,h,b]" do
244
240
  c = cell(:content => "text", :padding => [10, 20, 30])
245
241
  c.padding.should == [10, 20, 30, 20]
@@ -253,7 +249,7 @@ describe "Prawn::Table::Cell" do
253
249
  it "should reject other formats" do
254
250
  lambda{
255
251
  cell(:content => "text", :padding => [10])
256
- }.should raise_error(ArgumentError)
252
+ }.should.raise(ArgumentError)
257
253
  end
258
254
  end
259
255
 
@@ -267,10 +263,10 @@ describe "Prawn::Table::Cell" do
267
263
  @pdf.stubs(:fill_color)
268
264
  @pdf.expects(:fill_color).with('123456')
269
265
  @pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
270
- x.should be_within(0.01).of(0)
271
- y.should be_within(0.01).of(@pdf.cursor)
272
- w.should be_within(0.01).of(29.344)
273
- h.should be_within(0.01).of(23.872)
266
+ x.should.be.close(0, 0.01)
267
+ y.should.be.close(@pdf.cursor, 0.01)
268
+ w.should.be.close(29.344, 0.01)
269
+ h.should.be.close(23.872, 0.01)
274
270
  end
275
271
  @pdf.cell(:content => "text", :background_color => '123456')
276
272
  end
@@ -283,10 +279,10 @@ describe "Prawn::Table::Cell" do
283
279
  @pdf.stubs(:fill_color)
284
280
  @pdf.expects(:fill_color).with('123456')
285
281
  @pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
286
- x.should be_within(0.01).of(12.0)
287
- y.should be_within(0.01).of(34.0)
288
- w.should be_within(0.01).of(29.344)
289
- h.should be_within(0.01).of(23.872)
282
+ x.should.be.close(12.0, 0.01)
283
+ y.should.be.close(34.0, 0.01)
284
+ w.should.be.close(29.344, 0.01)
285
+ h.should.be.close(23.872, 0.01)
290
286
  end
291
287
  c = @pdf.make_cell(:content => "text", :background_color => '123456')
292
288
  c.draw([12.0, 34.0])
@@ -412,34 +408,8 @@ describe "Prawn::Table::Cell" do
412
408
  :border_width => [2, 3, 4, 5])
413
409
  c.border_widths.should == [2, 3, 4, 5]
414
410
  end
415
-
416
- it "should set default border lines to :solid" do
417
- c = @pdf.cell(:content => "text")
418
- c.border_top_line.should == :solid
419
- c.border_right_line.should == :solid
420
- c.border_bottom_line.should == :solid
421
- c.border_left_line.should == :solid
422
- c.border_lines.should == [:solid] * 4
423
- end
424
-
425
- it "should set border line with :border_..._line" do
426
- c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
427
- c.border_bottom_line.should == :dotted
428
- c.border_lines[2].should == :dotted
429
- end
430
-
431
- it "should set border lines with :border_lines" do
432
- c = @pdf.cell(:content => "text",
433
- :border_lines => [:solid, :dotted, :dashed, :solid])
434
- c.border_lines.should == [:solid, :dotted, :dashed, :solid]
435
- end
436
411
  end
437
412
 
438
-
439
-
440
-
441
-
442
-
443
413
  describe "Text cell attributes" do
444
414
  include CellHelpers
445
415
 
@@ -469,47 +439,6 @@ describe "Prawn::Table::Cell" do
469
439
  c.draw
470
440
  end
471
441
 
472
- it "supports variant styles of the current font" do
473
- font_path = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
474
- @pdf.font_families.merge!("Action Man" => {
475
- :normal => { :file => font_path, :font => "ActionMan" },
476
- :bold => { :file => font_path, :font => "ActionMan-Bold" },
477
- })
478
- @pdf.font "Action Man"
479
-
480
- c = cell(:content => "text", :font_style => :bold)
481
-
482
- box = Prawn::Text::Box.new("text", :document => @pdf)
483
- Prawn::Text::Box.expects(:new).checking do |text, options|
484
- text.should == "text"
485
- options[:style].should == :bold
486
- @pdf.font.family.should == 'Action Man'
487
- end.at_least_once.returns(box)
488
-
489
- c.draw
490
- end
491
-
492
-
493
- it "uses the style of the current font if none given" do
494
- font_path = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
495
- @pdf.font_families.merge!("Action Man" => {
496
- :normal => { :file => font_path, :font => "ActionMan" },
497
- :bold => { :file => font_path, :font => "ActionMan-Bold" },
498
- })
499
- @pdf.font "Action Man", :style => :bold
500
-
501
- c = cell(:content => "text")
502
-
503
- box = Prawn::Text::Box.new("text", :document => @pdf)
504
- Prawn::Text::Box.expects(:new).checking do |text, options|
505
- text.should == "text"
506
- @pdf.font.family.should == 'Action Man'
507
- @pdf.font.options[:style].should == :bold
508
- end.at_least_once.returns(box)
509
-
510
- c.draw
511
- end
512
-
513
442
  it "should allow inline formatting in cells" do
514
443
  c = cell(:content => "foo <b>bar</b> baz", :inline_format => true)
515
444
 
@@ -569,6 +498,7 @@ describe "Prawn::Table::Cell" do
569
498
  c.content_width.should == font.compute_width_of("text")
570
499
  end
571
500
  end
501
+
572
502
  end
573
503
 
574
504
  describe "Image cells" do
@@ -579,11 +509,11 @@ describe "Image cells" do
579
509
  describe "with default options" do
580
510
  before(:each) do
581
511
  @cell = Prawn::Table::Cell.make(@pdf,
582
- :image => "#{Prawn::DATADIR}/images/prawn.png")
512
+ :image => "#{Prawn::BASEDIR}/data/images/prawn.png")
583
513
  end
584
514
 
585
515
  it "should create a Cell::Image" do
586
- @cell.should be_a_kind_of(Prawn::Table::Cell::Image)
516
+ @cell.should.be.a.kind_of(Prawn::Table::Cell::Image)
587
517
  end
588
518
 
589
519
  it "should pull the natural width and height from the image" do
@@ -595,7 +525,7 @@ describe "Image cells" do
595
525
  describe "hash syntax" do
596
526
  before(:each) do
597
527
  @table = @pdf.make_table([[{
598
- :image => "#{Prawn::DATADIR}/images/prawn.png",
528
+ :image => "#{Prawn::BASEDIR}/data/images/prawn.png",
599
529
  :scale => 2,
600
530
  :fit => [100, 200],
601
531
  :image_width => 123,
@@ -608,7 +538,7 @@ describe "Image cells" do
608
538
 
609
539
 
610
540
  it "should create a Cell::Image" do
611
- @cell.should be_a_kind_of(Prawn::Table::Cell::Image)
541
+ @cell.should.be.a.kind_of(Prawn::Table::Cell::Image)
612
542
  end
613
543
 
614
544
  it "should pass through image options" do
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When creating destinations" do
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
6
4
 
5
+ describe "When creating destinations" do
6
+
7
7
  before(:each) { create_pdf }
8
-
9
- it "should add entry to Dests name tree" do
8
+
9
+ it "should add entry to Dests name tree" do
10
10
  @pdf.dests.data.empty?.should == true
11
11
  @pdf.add_dest "candy", "chocolate"
12
12
  @pdf.dests.data.size.should == 1
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "tempfile"
3
3
 
4
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
 
6
6
  describe "Prawn::Document.new" do
7
7
  it "should not modify its argument" do
@@ -12,12 +12,12 @@ describe "Prawn::Document.new" do
12
12
  end
13
13
 
14
14
  describe "The cursor" do
15
- it "should == pdf.y - bounds.absolute_bottom" do
15
+ it "should equal pdf.y - bounds.absolute_bottom" do
16
16
  pdf = Prawn::Document.new
17
17
  pdf.cursor.should == pdf.bounds.top
18
-
18
+
19
19
  pdf.y = 300
20
- pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
20
+ pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
21
21
  end
22
22
 
23
23
  it "should be able to move relative to the bottom margin" do
@@ -27,40 +27,14 @@ describe "The cursor" do
27
27
  pdf.cursor.should == 10
28
28
  pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom
29
29
  end
30
- end
31
-
32
- describe "when generating a document with a custom text formatter" do
33
- it "should use the provided text formatter" do
34
- class TestTextFormatter
35
- def self.format(string)
36
- [
37
- {
38
- text: string.gsub("Dr. Who?", "Just 'The Doctor'."),
39
- styles: [],
40
- color: nil,
41
- link: nil,
42
- anchor: nil,
43
- local: nil,
44
- font: nil,
45
- size: nil,
46
- character_spacing: nil
47
- }
48
- ]
49
- end
50
- end
51
- pdf = Prawn::Document.new text_formatter: TestTextFormatter
52
- pdf.text "Dr. Who?", inline_format: true
53
- text = PDF::Inspector::Text.analyze(pdf.render)
54
- text.strings.first.should == "Just 'The Doctor'."
55
- end
56
- end
30
+ end
57
31
 
58
32
  describe "when generating a document from a subclass" do
59
33
  it "should be an instance of the subclass" do
60
34
  custom_document = Class.new(Prawn::Document)
61
- custom_document.generate(Tempfile.new("generate_test").path) do |e|
35
+ custom_document.generate(Tempfile.new("generate_test").path) do |e|
62
36
  e.class.should == custom_document
63
- e.should be_a_kind_of(Prawn::Document)
37
+ e.should.be.kind_of(Prawn::Document)
64
38
  end
65
39
  end
66
40
 
@@ -71,51 +45,51 @@ describe "when generating a document from a subclass" do
71
45
  Prawn::Document.extensions << mod1 << mod2
72
46
 
73
47
  custom_document = Class.new(Prawn::Document)
74
- custom_document.extensions.should == [mod1, mod2]
48
+ assert_equal [mod1, mod2], custom_document.extensions
75
49
 
76
50
  # remove the extensions we added to prawn document
77
51
  Prawn::Document.extensions.delete(mod1)
78
52
  Prawn::Document.extensions.delete(mod2)
79
53
 
80
- Prawn::Document.new.respond_to?(:test_extensions1).should be_false
81
- Prawn::Document.new.respond_to?(:test_extensions2).should be_false
54
+ assert ! Prawn::Document.new.respond_to?(:test_extensions1)
55
+ assert ! Prawn::Document.new.respond_to?(:test_extensions2)
82
56
 
83
57
  # verify these still exist on custom class
84
- custom_document.extensions.should == [mod1, mod2]
58
+ assert_equal [mod1, mod2], custom_document.extensions
85
59
 
86
- custom_document.new.respond_to?(:test_extensions1).should be_true
87
- custom_document.new.respond_to?(:test_extensions2).should be_true
60
+ assert custom_document.new.respond_to?(:test_extensions1)
61
+ assert custom_document.new.respond_to?(:test_extensions2)
88
62
  end
89
63
 
90
64
  end
91
65
 
92
-
93
- describe "When creating multi-page documents" do
94
-
66
+
67
+ describe "When creating multi-page documents" do
68
+
95
69
  before(:each) { create_pdf }
96
-
97
- it "should initialize with a single page" do
70
+
71
+ it "should initialize with a single page" do
98
72
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
99
-
100
- page_counter.pages.size.should == 1
101
- @pdf.page_count.should == 1
73
+
74
+ page_counter.pages.size.should == 1
75
+ @pdf.page_count.should == 1
102
76
  end
103
-
77
+
104
78
  it "should provide an accurate page_count" do
105
- 3.times { @pdf.start_new_page }
79
+ 3.times { @pdf.start_new_page }
106
80
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
107
-
81
+
108
82
  page_counter.pages.size.should == 4
109
83
  @pdf.page_count.should == 4
110
- end
111
-
112
- end
84
+ end
85
+
86
+ end
113
87
 
114
88
  describe "When beginning each new page" do
115
89
 
116
90
  describe "Background template feature" do
117
91
  before(:each) do
118
- @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
92
+ @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
119
93
  @pdf = Prawn::Document.new(:background => @filename)
120
94
  end
121
95
  it "should place a background image if it is in options block" do
@@ -128,11 +102,11 @@ describe "When beginning each new page" do
128
102
  @pdf.instance_variable_defined?(:@background).should == true
129
103
  @pdf.instance_variable_get(:@background).should == @filename
130
104
  end
131
-
132
-
105
+
106
+
133
107
  end
134
-
135
-
108
+
109
+
136
110
  end
137
111
 
138
112
  describe "Prawn::Document#float" do
@@ -145,7 +119,7 @@ describe "Prawn::Document#float" do
145
119
 
146
120
  it "should teleport across pages if necessary" do
147
121
  create_pdf
148
-
122
+
149
123
  @pdf.float do
150
124
  @pdf.text "Foo"
151
125
  @pdf.start_new_page
@@ -182,7 +156,7 @@ end
182
156
 
183
157
  describe "on_page_create callback" do
184
158
  before do
185
- create_pdf
159
+ create_pdf
186
160
  end
187
161
 
188
162
  it "should be invoked with document" do
@@ -203,34 +177,34 @@ describe "on_page_create callback" do
203
177
 
204
178
  5.times { @pdf.start_new_page }
205
179
  end
206
-
180
+
207
181
  it "should be replaceable" do
208
182
  trigger1 = mock()
209
183
  trigger1.expects(:fire).times(1)
210
-
184
+
211
185
  trigger2 = mock()
212
186
  trigger2.expects(:fire).times(1)
213
187
 
214
188
  @pdf.on_page_create { trigger1.fire }
215
-
189
+
216
190
  @pdf.start_new_page
217
-
191
+
218
192
  @pdf.on_page_create { trigger2.fire }
219
-
193
+
220
194
  @pdf.start_new_page
221
195
  end
222
-
196
+
223
197
  it "should be clearable by calling on_page_create without a block" do
224
198
  trigger = mock()
225
199
  trigger.expects(:fire).times(1)
226
200
 
227
201
  @pdf.on_page_create { trigger.fire }
228
202
 
229
- @pdf.start_new_page
230
-
203
+ @pdf.start_new_page
204
+
231
205
  @pdf.on_page_create
232
-
233
- @pdf.start_new_page
206
+
207
+ @pdf.start_new_page
234
208
  end
235
209
 
236
210
  end
@@ -240,8 +214,8 @@ describe "Document compression" do
240
214
  it "should not compress the page content stream if compression is disabled" do
241
215
 
242
216
  pdf = Prawn::Document.new(:compress => false)
243
- pdf.page.content.stream.stubs(:compress!).returns(true)
244
- pdf.page.content.stream.expects(:compress!).never
217
+ pdf.page.content.stubs(:compress_stream).returns(true)
218
+ pdf.page.content.expects(:compress_stream).never
245
219
 
246
220
  pdf.text "Hi There" * 20
247
221
  pdf.render
@@ -250,8 +224,8 @@ describe "Document compression" do
250
224
  it "should compress the page content stream if compression is enabled" do
251
225
 
252
226
  pdf = Prawn::Document.new(:compress => true)
253
- pdf.page.content.stream.stubs(:compress!).returns(true)
254
- pdf.page.content.stream.expects(:compress!).once
227
+ pdf.page.content.stubs(:compress_stream).returns(true)
228
+ pdf.page.content.expects(:compress_stream).once
255
229
 
256
230
  pdf.text "Hi There" * 20
257
231
  pdf.render
@@ -261,14 +235,14 @@ describe "Document compression" do
261
235
  doc_uncompressed = Prawn::Document.new
262
236
  doc_compressed = Prawn::Document.new(:compress => true)
263
237
  [doc_compressed, doc_uncompressed].each do |pdf|
264
- pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
238
+ pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
265
239
  pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
266
240
  end
267
241
 
268
- doc_compressed.render.length.should be < doc_uncompressed.render.length
269
- end
242
+ doc_compressed.render.length.should.be < doc_uncompressed.render.length
243
+ end
270
244
 
271
- end
245
+ end
272
246
 
273
247
  describe "Document metadata" do
274
248
  it "should output strings as UTF-16 with a byte order mark" do
@@ -288,10 +262,11 @@ describe "When reopening pages" do
288
262
  pdf.go_to_page 1
289
263
  pdf.text "More for page 1"
290
264
  end
291
-
292
- # Indirectly verify that the actual length does not match dictionary length.
293
- # If it isn't, a MalformedPDFError will be raised
294
- PDF::Inspector::Page.analyze(@pdf.render)
265
+
266
+ # MalformedPDFError raised if content stream actual length does not match
267
+ # dictionary length
268
+ lambda{ PDF::Inspector::Page.analyze(@pdf.render) }.
269
+ should.not.raise(PDF::Reader::MalformedPDFError)
295
270
  end
296
271
 
297
272
  it "should insert pages after the current page when calling start_new_page" do
@@ -323,21 +298,21 @@ describe "When setting page size" do
323
298
  it "should default to LETTER" do
324
299
  @pdf = Prawn::Document.new
325
300
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
326
- pages.first[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"]
327
- end
328
-
329
- (PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
301
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
302
+ end
303
+
304
+ (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
330
305
  it "should provide #{k} geometry" do
331
306
  @pdf = Prawn::Document.new(:page_size => k)
332
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
333
- pages.first[:size].should == PDF::Core::PageGeometry::SIZES[k]
307
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
308
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
334
309
  end
335
310
  end
336
-
337
- it "should allow custom page size" do
311
+
312
+ it "should allow custom page size" do
338
313
  @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
339
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
340
- pages.first[:size].should == [1920, 1080]
314
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
315
+ pages.first[:size].should == [1920, 1080]
341
316
  end
342
317
 
343
318
 
@@ -346,25 +321,25 @@ describe "When setting page size" do
346
321
  @pdf.start_new_page
347
322
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
348
323
  pages.each do |page|
349
- page[:size].should == PDF::Core::PageGeometry::SIZES["LEGAL"]
324
+ page[:size].should == Prawn::Document::PageGeometry::SIZES["LEGAL"]
350
325
  end
351
326
  end
352
327
 
353
- end
328
+ end
354
329
 
355
330
  describe "When setting page layout" do
356
331
  it "should reverse coordinates for landscape" do
357
332
  @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
358
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
359
- pages.first[:size].should == PDF::Core::PageGeometry::SIZES["A4"].reverse
360
- end
333
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
334
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
335
+ end
361
336
 
362
337
  it "should retain page layout by default when starting a new page" do
363
338
  @pdf = Prawn::Document.new(:page_layout => :landscape)
364
339
  @pdf.start_new_page(:trace => true)
365
340
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
366
341
  pages.each do |page|
367
- page[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"].reverse
342
+ page[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"].reverse
368
343
  end
369
344
  end
370
345
 
@@ -383,11 +358,11 @@ describe "The mask() feature" do
383
358
  @pdf.mask(:y, :line_width) do
384
359
  @pdf.y = y + 1
385
360
  @pdf.line_width = line_width + 1
386
- @pdf.y.should_not == y
387
- @pdf.line_width.should_not == line_width
361
+ @pdf.y.should.not == y
362
+ @pdf.line_width.should.not == line_width
388
363
  end
389
364
  @pdf.y.should == y
390
- @pdf.line_width.should == line_width
365
+ @pdf.line_width.should == line_width
391
366
  end
392
367
  end
393
368
 
@@ -416,14 +391,14 @@ describe "The group() feature" do
416
391
  pages[1][:strings].should == ["Hello", "World"]
417
392
  end
418
393
 
419
- it "should raise_error CannotGroup if the content is too tall" do
394
+ it "should raise CannotGroup if the content is too tall" do
420
395
  lambda {
421
396
  Prawn::Document.new do
422
397
  group do
423
398
  100.times { text "Too long" }
424
399
  end
425
400
  end.render
426
- }.should raise_error(Prawn::Errors::CannotGroup)
401
+ }.should.raise(Prawn::Errors::CannotGroup)
427
402
  end
428
403
 
429
404
  it "should group within individual column boxes" do
@@ -447,23 +422,25 @@ describe "The group() feature" do
447
422
  end
448
423
 
449
424
  describe "The render() feature" do
450
- it "should return a 8 bit encoded string on a m17n aware VM" do
451
- @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
452
- @pdf.line [100,100], [200,200]
453
- str = @pdf.render
454
- str.encoding.to_s.should == "ASCII-8BIT"
425
+ if "spec".respond_to?(:encode!)
426
+ it "should return a 8 bit encoded string on a m17n aware VM" do
427
+ @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
428
+ @pdf.line [100,100], [200,200]
429
+ str = @pdf.render
430
+ str.encoding.to_s.should == "ASCII-8BIT"
431
+ end
455
432
  end
456
433
 
457
434
  it "should trigger before_render callbacks just before rendering" do
458
435
  pdf = Prawn::Document.new
459
-
436
+
460
437
  seq = sequence("callback_order")
461
438
 
462
439
  # Verify the order: finalize -> fire callbacks -> render body
463
440
  pdf.expects(:finalize_all_page_contents).in_sequence(seq)
464
441
  trigger = mock()
465
442
  trigger.expects(:fire).in_sequence(seq)
466
-
443
+
467
444
  # Store away the render_body method to be called below
468
445
  render_body = pdf.method(:render_body)
469
446
  pdf.expects(:render_body).in_sequence(seq)
@@ -487,10 +464,10 @@ end
487
464
  describe "The :optimize_objects option" do
488
465
  before(:all) do
489
466
  @wasteful_doc = lambda do |pdf|
490
- pdf.transaction do
467
+ pdf.transaction do
491
468
  pdf.start_new_page
492
469
  pdf.text "Hidden text"
493
- pdf.rollback
470
+ pdf.rollback
494
471
  end
495
472
 
496
473
  pdf.text "Hello world"
@@ -501,12 +478,12 @@ describe "The :optimize_objects option" do
501
478
  wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
502
479
  frugal_pdf = Prawn::Document.new(:optimize_objects => true,
503
480
  &@wasteful_doc)
504
- frugal_pdf.render.size.should be < wasteful_pdf.render.size
481
+ frugal_pdf.render.size.should.be < wasteful_pdf.render.size
505
482
  end
506
483
 
507
484
  it "should default to :false" do
508
485
  default_pdf = Prawn::Document.new(&@wasteful_doc)
509
- wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
486
+ wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
510
487
  &@wasteful_doc)
511
488
  default_pdf.render.size.should == wasteful_pdf.render.size
512
489
  end
@@ -588,25 +565,25 @@ describe "The number_pages method" do
588
565
  before do
589
566
  @pdf = Prawn::Document.new(:skip_page_creation => true)
590
567
  end
591
-
568
+
592
569
  it "replaces the '<page>' string with the proper page number" do
593
570
  @pdf.start_new_page
594
571
  @pdf.expects(:text_box).with("1, test", { :height => 50 })
595
572
  @pdf.number_pages "<page>, test", {:page_filter => :all}
596
573
  end
597
-
574
+
598
575
  it "replaces the '<total>' string with the total page count" do
599
576
  @pdf.start_new_page
600
577
  @pdf.expects(:text_box).with("test, 1", { :height => 50 })
601
578
  @pdf.number_pages "test, <total>", {:page_filter => :all}
602
579
  end
603
-
580
+
604
581
  it "must print each page if given the :all page_filter" do
605
582
  10.times { @pdf.start_new_page }
606
583
  @pdf.expects(:text_box).times(10)
607
584
  @pdf.number_pages "test", {:page_filter => :all}
608
585
  end
609
-
586
+
610
587
  it "must print each page if no :page_filter is specified" do
611
588
  10.times { @pdf.start_new_page }
612
589
  @pdf.expects(:text_box).times(10)
@@ -618,8 +595,8 @@ describe "The number_pages method" do
618
595
  @pdf.expects(:text_box).never
619
596
  @pdf.number_pages "test", {:page_filter => nil}
620
597
  end
621
-
622
- context "start_count_at option" do
598
+
599
+ context "start_count_at option" do
623
600
  [1, 2].each do |startat|
624
601
  context "equal to #{startat}" do
625
602
  it "increments the pages" do
@@ -628,10 +605,10 @@ describe "The number_pages method" do
628
605
  @pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
629
606
  @pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
630
607
  @pdf.number_pages "<page> <total>", options
631
- end
608
+ end
632
609
  end
633
610
  end
634
-
611
+
635
612
  [0, nil].each do |val|
636
613
  context "equal to #{val}" do
637
614
  it "defaults to start at page 1" do
@@ -645,7 +622,7 @@ describe "The number_pages method" do
645
622
  end
646
623
  end
647
624
  end
648
-
625
+
649
626
  context "total_pages option" do
650
627
  it "allows the total pages count to be overridden" do
651
628
  2.times { @pdf.start_new_page }
@@ -654,7 +631,7 @@ describe "The number_pages method" do
654
631
  @pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
655
632
  end
656
633
  end
657
-
634
+
658
635
  context "special page filter" do
659
636
  context "such as :odd" do
660
637
  it "increments the pages" do
@@ -699,27 +676,6 @@ describe "The number_pages method" do
699
676
  end
700
677
  end
701
678
  end
702
-
703
- context "height option" do
704
- before do
705
- @pdf.start_new_page
706
- end
707
-
708
- it "with 10 height" do
709
- @pdf.expects(:text_box).with("1 1", { :height => 10 })
710
- @pdf.number_pages "<page> <total>", :height => 10
711
- end
712
-
713
- it "with nil height" do
714
- @pdf.expects(:text_box).with("1 1", { :height => nil })
715
- @pdf.number_pages "<page> <total>", :height => nil
716
- end
717
-
718
- it "with no height" do
719
- @pdf.expects(:text_box).with("1 1", { :height => 50 })
720
- @pdf.number_pages "<page> <total>"
721
- end
722
- end
723
679
  end
724
680
 
725
681
  describe "The page_match? method" do
@@ -727,33 +683,33 @@ describe "The page_match? method" do
727
683
  @pdf = Prawn::Document.new(:skip_page_creation => true)
728
684
  10.times {@pdf.start_new_page}
729
685
  end
730
-
686
+
731
687
  it "returns nil given no filter" do
732
- @pdf.page_match?(:nil, 1).should be_false
688
+ assert ! @pdf.page_match?(:nil, 1)
733
689
  end
734
-
690
+
735
691
  it "must provide an :all filter" do
736
- (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
692
+ assert (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }
737
693
  end
738
694
 
739
695
  it "must provide an :odd filter" do
740
696
  odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
741
- odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
742
- even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
697
+ assert odd.all? { |i| @pdf.page_match?(:odd, i) }
698
+ assert ! even.any? { |i| @pdf.page_match?(:odd, i) }
743
699
  end
744
700
 
745
701
  it "must be able to filter by an array of page numbers" do
746
702
  fltr = [1,2,7]
747
- (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
703
+ assert_equal [1,2,7], (1..10).select { |i| @pdf.page_match?(fltr, i) }
748
704
  end
749
705
 
750
706
  it "must be able to filter by a range of page numbers" do
751
707
  fltr = 2..4
752
- (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
708
+ assert_equal [2,3,4], (1..10).select { |i| @pdf.page_match?(fltr, i) }
753
709
  end
754
710
 
755
711
  it "must be able to filter by an arbitrary proc" do
756
712
  fltr = lambda { |x| x == 1 or x % 3 == 0 }
757
- (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
758
- end
713
+ assert_equal [1,3,6,9], (1..10).select { |i| @pdf.page_match?(fltr, i) }
714
+ end
759
715
  end