nurettin-prawn 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/COPYING +2 -0
  2. data/GPLv2 +340 -0
  3. data/GPLv3 +674 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE +56 -0
  6. data/README.md +98 -0
  7. data/Rakefile +45 -0
  8. data/data/encodings/win_ansi.txt +29 -0
  9. data/data/fonts/Action Man.dfont +0 -0
  10. data/data/fonts/Activa.ttf +0 -0
  11. data/data/fonts/Chalkboard.ttf +0 -0
  12. data/data/fonts/Courier-Bold.afm +342 -0
  13. data/data/fonts/Courier-BoldOblique.afm +342 -0
  14. data/data/fonts/Courier-Oblique.afm +342 -0
  15. data/data/fonts/Courier.afm +342 -0
  16. data/data/fonts/DejaVuSans.ttf +0 -0
  17. data/data/fonts/Dustismo_Roman.ttf +0 -0
  18. data/data/fonts/Helvetica-Bold.afm +2827 -0
  19. data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  20. data/data/fonts/Helvetica-Oblique.afm +3051 -0
  21. data/data/fonts/Helvetica.afm +3051 -0
  22. data/data/fonts/MustRead.html +19 -0
  23. data/data/fonts/Symbol.afm +213 -0
  24. data/data/fonts/Times-Bold.afm +2588 -0
  25. data/data/fonts/Times-BoldItalic.afm +2384 -0
  26. data/data/fonts/Times-Italic.afm +2667 -0
  27. data/data/fonts/Times-Roman.afm +2419 -0
  28. data/data/fonts/ZapfDingbats.afm +225 -0
  29. data/data/fonts/comicsans.ttf +0 -0
  30. data/data/fonts/gkai00mp.ttf +0 -0
  31. data/data/images/16bit.alpha +0 -0
  32. data/data/images/16bit.dat +0 -0
  33. data/data/images/16bit.png +0 -0
  34. data/data/images/arrow.png +0 -0
  35. data/data/images/arrow2.png +0 -0
  36. data/data/images/barcode_issue.png +0 -0
  37. data/data/images/dice.alpha +0 -0
  38. data/data/images/dice.dat +0 -0
  39. data/data/images/dice.png +0 -0
  40. data/data/images/dice_interlaced.png +0 -0
  41. data/data/images/fractal.jpg +0 -0
  42. data/data/images/letterhead.jpg +0 -0
  43. data/data/images/page_white_text.alpha +0 -0
  44. data/data/images/page_white_text.dat +0 -0
  45. data/data/images/page_white_text.png +0 -0
  46. data/data/images/pigs.jpg +0 -0
  47. data/data/images/prawn.png +0 -0
  48. data/data/images/rails.dat +0 -0
  49. data/data/images/rails.png +0 -0
  50. data/data/images/ruport.png +0 -0
  51. data/data/images/ruport_data.dat +0 -0
  52. data/data/images/ruport_transparent.png +0 -0
  53. data/data/images/ruport_type0.png +0 -0
  54. data/data/images/stef.jpg +0 -0
  55. data/data/images/tru256.bmp +0 -0
  56. data/data/images/web-links.dat +1 -0
  57. data/data/images/web-links.png +0 -0
  58. data/data/pdfs/complex_template.pdf +0 -0
  59. data/data/pdfs/contains_ttf_font.pdf +0 -0
  60. data/data/pdfs/encrypted.pdf +0 -0
  61. data/data/pdfs/form.pdf +820 -0
  62. data/data/pdfs/hexagon.pdf +61 -0
  63. data/data/pdfs/indirect_reference.pdf +86 -0
  64. data/data/pdfs/multipage_template.pdf +127 -0
  65. data/data/pdfs/nested_pages.pdf +118 -0
  66. data/data/pdfs/page_without_mediabox.pdf +193 -0
  67. data/data/pdfs/resources_as_indirect_object.pdf +83 -0
  68. data/data/pdfs/two_hexagons.pdf +90 -0
  69. data/data/pdfs/version_1_6.pdf +61 -0
  70. data/data/shift_jis_text.txt +1 -0
  71. data/lib/prawn.rb +29 -0
  72. data/lib/prawn/compatibility.rb +87 -0
  73. data/lib/prawn/core.rb +87 -0
  74. data/lib/prawn/core/annotations.rb +61 -0
  75. data/lib/prawn/core/byte_string.rb +9 -0
  76. data/lib/prawn/core/destinations.rb +90 -0
  77. data/lib/prawn/core/document_state.rb +79 -0
  78. data/lib/prawn/core/literal_string.rb +16 -0
  79. data/lib/prawn/core/name_tree.rb +177 -0
  80. data/lib/prawn/core/object_store.rb +320 -0
  81. data/lib/prawn/core/page.rb +212 -0
  82. data/lib/prawn/core/pdf_object.rb +125 -0
  83. data/lib/prawn/core/reference.rb +119 -0
  84. data/lib/prawn/core/text.rb +268 -0
  85. data/lib/prawn/core/text/formatted/arranger.rb +294 -0
  86. data/lib/prawn/core/text/formatted/line_wrap.rb +288 -0
  87. data/lib/prawn/core/text/formatted/wrap.rb +153 -0
  88. data/lib/prawn/document.rb +707 -0
  89. data/lib/prawn/document/bounding_box.rb +510 -0
  90. data/lib/prawn/document/column_box.rb +132 -0
  91. data/lib/prawn/document/graphics_state.rb +136 -0
  92. data/lib/prawn/document/internals.rb +173 -0
  93. data/lib/prawn/document/page_geometry.rb +136 -0
  94. data/lib/prawn/document/snapshot.rb +89 -0
  95. data/lib/prawn/document/span.rb +55 -0
  96. data/lib/prawn/encoding.rb +121 -0
  97. data/lib/prawn/errors.rb +99 -0
  98. data/lib/prawn/font.rb +386 -0
  99. data/lib/prawn/font/afm.rb +203 -0
  100. data/lib/prawn/font/dfont.rb +42 -0
  101. data/lib/prawn/font/ttf.rb +343 -0
  102. data/lib/prawn/graphics.rb +523 -0
  103. data/lib/prawn/graphics/cap_style.rb +46 -0
  104. data/lib/prawn/graphics/color.rb +231 -0
  105. data/lib/prawn/graphics/dash.rb +82 -0
  106. data/lib/prawn/graphics/join_style.rb +47 -0
  107. data/lib/prawn/graphics/patterns.rb +137 -0
  108. data/lib/prawn/graphics/transformation.rb +156 -0
  109. data/lib/prawn/graphics/transparency.rb +99 -0
  110. data/lib/prawn/images.rb +196 -0
  111. data/lib/prawn/images/image.rb +65 -0
  112. data/lib/prawn/images/jpg.rb +85 -0
  113. data/lib/prawn/images/png.rb +362 -0
  114. data/lib/prawn/layout.rb +20 -0
  115. data/lib/prawn/layout/grid.rb +259 -0
  116. data/lib/prawn/measurement_extensions.rb +46 -0
  117. data/lib/prawn/measurements.rb +71 -0
  118. data/lib/prawn/outline.rb +326 -0
  119. data/lib/prawn/repeater.rb +122 -0
  120. data/lib/prawn/security.rb +269 -0
  121. data/lib/prawn/soft_mask.rb +94 -0
  122. data/lib/prawn/stamp.rb +134 -0
  123. data/lib/prawn/table.rb +609 -0
  124. data/lib/prawn/table/cell.rb +776 -0
  125. data/lib/prawn/table/cell/image.rb +70 -0
  126. data/lib/prawn/table/cell/in_table.rb +27 -0
  127. data/lib/prawn/table/cell/span_dummy.rb +88 -0
  128. data/lib/prawn/table/cell/subtable.rb +65 -0
  129. data/lib/prawn/table/cell/text.rb +152 -0
  130. data/lib/prawn/table/cells.rb +260 -0
  131. data/lib/prawn/text.rb +420 -0
  132. data/lib/prawn/text/box.rb +141 -0
  133. data/lib/prawn/text/formatted.rb +4 -0
  134. data/lib/prawn/text/formatted/box.rb +563 -0
  135. data/lib/prawn/text/formatted/fragment.rb +253 -0
  136. data/lib/prawn/text/formatted/parser.rb +217 -0
  137. data/lib/prawn/utilities.rb +44 -0
  138. data/manual/basic_concepts/adding_pages.rb +27 -0
  139. data/manual/basic_concepts/basic_concepts.rb +34 -0
  140. data/manual/basic_concepts/creation.rb +39 -0
  141. data/manual/basic_concepts/cursor.rb +33 -0
  142. data/manual/basic_concepts/measurement.rb +25 -0
  143. data/manual/basic_concepts/origin.rb +38 -0
  144. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  145. data/manual/bounding_box/bounding_box.rb +39 -0
  146. data/manual/bounding_box/bounds.rb +49 -0
  147. data/manual/bounding_box/canvas.rb +24 -0
  148. data/manual/bounding_box/creation.rb +23 -0
  149. data/manual/bounding_box/indentation.rb +46 -0
  150. data/manual/bounding_box/nesting.rb +45 -0
  151. data/manual/bounding_box/russian_boxes.rb +40 -0
  152. data/manual/bounding_box/stretchy.rb +31 -0
  153. data/manual/document_and_page_options/background.rb +27 -0
  154. data/manual/document_and_page_options/document_and_page_options.rb +31 -0
  155. data/manual/document_and_page_options/metadata.rb +23 -0
  156. data/manual/document_and_page_options/page_margins.rb +38 -0
  157. data/manual/document_and_page_options/page_size.rb +34 -0
  158. data/manual/example_file.rb +116 -0
  159. data/manual/example_helper.rb +430 -0
  160. data/manual/example_package.rb +53 -0
  161. data/manual/example_section.rb +46 -0
  162. data/manual/graphics/circle_and_ellipse.rb +22 -0
  163. data/manual/graphics/color.rb +24 -0
  164. data/manual/graphics/common_lines.rb +28 -0
  165. data/manual/graphics/fill_and_stroke.rb +42 -0
  166. data/manual/graphics/fill_rules.rb +37 -0
  167. data/manual/graphics/gradients.rb +37 -0
  168. data/manual/graphics/graphics.rb +58 -0
  169. data/manual/graphics/helper.rb +17 -0
  170. data/manual/graphics/line_width.rb +35 -0
  171. data/manual/graphics/lines_and_curves.rb +41 -0
  172. data/manual/graphics/polygon.rb +29 -0
  173. data/manual/graphics/rectangle.rb +21 -0
  174. data/manual/graphics/rotate.rb +28 -0
  175. data/manual/graphics/scale.rb +41 -0
  176. data/manual/graphics/soft_masks.rb +46 -0
  177. data/manual/graphics/stroke_cap.rb +31 -0
  178. data/manual/graphics/stroke_dash.rb +43 -0
  179. data/manual/graphics/stroke_join.rb +30 -0
  180. data/manual/graphics/translate.rb +29 -0
  181. data/manual/graphics/transparency.rb +35 -0
  182. data/manual/images/absolute_position.rb +23 -0
  183. data/manual/images/fit.rb +21 -0
  184. data/manual/images/horizontal.rb +25 -0
  185. data/manual/images/images.rb +40 -0
  186. data/manual/images/plain_image.rb +18 -0
  187. data/manual/images/scale.rb +22 -0
  188. data/manual/images/vertical.rb +28 -0
  189. data/manual/images/width_and_height.rb +25 -0
  190. data/manual/layout/boxes.rb +27 -0
  191. data/manual/layout/content.rb +25 -0
  192. data/manual/layout/layout.rb +28 -0
  193. data/manual/layout/simple_grid.rb +23 -0
  194. data/manual/manual/cover.rb +26 -0
  195. data/manual/manual/foreword.rb +13 -0
  196. data/manual/manual/how_to_read_this_manual.rb +41 -0
  197. data/manual/manual/manual.rb +36 -0
  198. data/manual/outline/add_subsection_to.rb +61 -0
  199. data/manual/outline/insert_section_after.rb +47 -0
  200. data/manual/outline/outline.rb +32 -0
  201. data/manual/outline/sections_and_pages.rb +67 -0
  202. data/manual/repeatable_content/page_numbering.rb +54 -0
  203. data/manual/repeatable_content/repeatable_content.rb +31 -0
  204. data/manual/repeatable_content/repeater.rb +55 -0
  205. data/manual/repeatable_content/stamp.rb +41 -0
  206. data/manual/security/encryption.rb +31 -0
  207. data/manual/security/permissions.rb +38 -0
  208. data/manual/security/security.rb +28 -0
  209. data/manual/syntax_highlight.rb +52 -0
  210. data/manual/table/basic_block.rb +53 -0
  211. data/manual/table/before_rendering_page.rb +26 -0
  212. data/manual/table/cell_border_lines.rb +24 -0
  213. data/manual/table/cell_borders_and_bg.rb +31 -0
  214. data/manual/table/cell_dimensions.rb +30 -0
  215. data/manual/table/cell_text.rb +38 -0
  216. data/manual/table/column_widths.rb +30 -0
  217. data/manual/table/content_and_subtables.rb +39 -0
  218. data/manual/table/creation.rb +27 -0
  219. data/manual/table/filtering.rb +36 -0
  220. data/manual/table/flow_and_header.rb +17 -0
  221. data/manual/table/image_cells.rb +33 -0
  222. data/manual/table/position.rb +29 -0
  223. data/manual/table/row_colors.rb +20 -0
  224. data/manual/table/span.rb +30 -0
  225. data/manual/table/style.rb +22 -0
  226. data/manual/table/table.rb +52 -0
  227. data/manual/table/width.rb +27 -0
  228. data/manual/templates/full_template.rb +23 -0
  229. data/manual/templates/page_template.rb +47 -0
  230. data/manual/templates/templates.rb +26 -0
  231. data/manual/text/alignment.rb +44 -0
  232. data/manual/text/color.rb +24 -0
  233. data/manual/text/column_box.rb +32 -0
  234. data/manual/text/fallback_fonts.rb +37 -0
  235. data/manual/text/font.rb +41 -0
  236. data/manual/text/font_size.rb +45 -0
  237. data/manual/text/font_style.rb +23 -0
  238. data/manual/text/formatted_callbacks.rb +60 -0
  239. data/manual/text/formatted_text.rb +50 -0
  240. data/manual/text/free_flowing_text.rb +51 -0
  241. data/manual/text/group.rb +29 -0
  242. data/manual/text/inline.rb +43 -0
  243. data/manual/text/kerning_and_character_spacing.rb +39 -0
  244. data/manual/text/leading.rb +25 -0
  245. data/manual/text/line_wrapping.rb +41 -0
  246. data/manual/text/paragraph_indentation.rb +26 -0
  247. data/manual/text/positioned_text.rb +38 -0
  248. data/manual/text/registering_families.rb +48 -0
  249. data/manual/text/rendering_and_color.rb +37 -0
  250. data/manual/text/right_to_left_text.rb +43 -0
  251. data/manual/text/rotation.rb +43 -0
  252. data/manual/text/single_usage.rb +37 -0
  253. data/manual/text/text.rb +75 -0
  254. data/manual/text/text_box_excess.rb +32 -0
  255. data/manual/text/text_box_extensions.rb +45 -0
  256. data/manual/text/text_box_overflow.rb +44 -0
  257. data/manual/text/utf8.rb +28 -0
  258. data/manual/text/win_ansi_charset.rb +59 -0
  259. data/prawn.gemspec +46 -0
  260. data/spec/annotations_spec.rb +90 -0
  261. data/spec/bounding_box_spec.rb +493 -0
  262. data/spec/cell_spec.rb +584 -0
  263. data/spec/column_box_spec.rb +33 -0
  264. data/spec/data/curves.pdf +66 -0
  265. data/spec/destinations_spec.rb +15 -0
  266. data/spec/document_spec.rb +736 -0
  267. data/spec/extensions/encoding_helpers.rb +6 -0
  268. data/spec/extensions/mocha.rb +44 -0
  269. data/spec/font_spec.rb +433 -0
  270. data/spec/formatted_text_arranger_spec.rb +421 -0
  271. data/spec/formatted_text_box_spec.rb +640 -0
  272. data/spec/formatted_text_fragment_spec.rb +298 -0
  273. data/spec/graphics_spec.rb +651 -0
  274. data/spec/grid_spec.rb +85 -0
  275. data/spec/images_spec.rb +140 -0
  276. data/spec/inline_formatted_text_parser_spec.rb +515 -0
  277. data/spec/jpg_spec.rb +25 -0
  278. data/spec/line_wrap_spec.rb +333 -0
  279. data/spec/measurement_units_spec.rb +23 -0
  280. data/spec/name_tree_spec.rb +112 -0
  281. data/spec/object_store_spec.rb +170 -0
  282. data/spec/outline_spec.rb +426 -0
  283. data/spec/pdf_object_spec.rb +172 -0
  284. data/spec/png_spec.rb +240 -0
  285. data/spec/reference_spec.rb +105 -0
  286. data/spec/repeater_spec.rb +158 -0
  287. data/spec/security_spec.rb +126 -0
  288. data/spec/snapshot_spec.rb +186 -0
  289. data/spec/soft_mask_spec.rb +117 -0
  290. data/spec/span_spec.rb +49 -0
  291. data/spec/spec_helper.rb +36 -0
  292. data/spec/stamp_spec.rb +159 -0
  293. data/spec/stroke_styles_spec.rb +193 -0
  294. data/spec/table_spec.rb +1209 -0
  295. data/spec/template_spec.rb +351 -0
  296. data/spec/text_at_spec.rb +129 -0
  297. data/spec/text_box_spec.rb +1029 -0
  298. data/spec/text_rendering_mode_spec.rb +45 -0
  299. data/spec/text_spacing_spec.rb +93 -0
  300. data/spec/text_spec.rb +421 -0
  301. data/spec/text_with_inline_formatting_spec.rb +35 -0
  302. data/spec/transparency_spec.rb +89 -0
  303. metadata +544 -0
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "A column box" do
6
+ it "has sensible left and right values" do
7
+ create_pdf
8
+ @pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width,
9
+ :height => 200, :columns => 3, :spacer => 25 do
10
+ left = @pdf.bounds.left
11
+ right = @pdf.bounds.right
12
+
13
+ @pdf.bounds.move_past_bottom # next column
14
+
15
+ @pdf.bounds.left.should be > left
16
+ @pdf.bounds.left.should be > right
17
+ @pdf.bounds.right.should be > @pdf.bounds.left
18
+ end
19
+ end
20
+
21
+ it "includes spacers between columns but not at the end" do
22
+ create_pdf
23
+ @pdf.column_box [0, @pdf.cursor], :width => 500,
24
+ :height => 200, :columns => 3, :spacer => 25 do
25
+ @pdf.bounds.width.should == 150 # (500 - (25 * 2)) / 3
26
+
27
+ @pdf.bounds.move_past_bottom
28
+ @pdf.bounds.move_past_bottom
29
+
30
+ @pdf.bounds.right.should == 500
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,66 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator (Prawn)
5
+ /Producer (Prawn)
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Pages
10
+ /Count 1
11
+ /Kids [5 0 R]
12
+ >>
13
+ endobj
14
+ 3 0 obj
15
+ << /Type /Catalog
16
+ /Pages 2 0 R
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 380
21
+ >>
22
+ stream
23
+ /DeviceRGB cs
24
+ 0.000 0.000 0.000 scn
25
+ /DeviceRGB CS
26
+ 0.000 0.000 0.000 SCN
27
+ q
28
+ 136.000 136.000 m
29
+ 96.000 126.000 96.000 126.000 86.000 86.000 c
30
+ S
31
+ 246.000 236.000 m
32
+ 246.000 241.523 241.523 246.000 236.000 246.000 c
33
+ 230.477 246.000 226.000 241.523 226.000 236.000 c
34
+ 226.000 230.477 230.477 226.000 236.000 226.000 c
35
+ 241.523 226.000 246.000 230.477 246.000 236.000 c
36
+ 236.000 236.000 m
37
+ f
38
+ Q
39
+
40
+ endstream
41
+ endobj
42
+ 5 0 obj
43
+ << /Type /Page
44
+ /Parent 2 0 R
45
+ /MediaBox [0 0 612.0 792.0]
46
+ /Contents 4 0 R
47
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
48
+ >>
49
+ >>
50
+ endobj
51
+ xref
52
+ 0 6
53
+ 0000000000 65535 f
54
+ 0000000015 00000 n
55
+ 0000000071 00000 n
56
+ 0000000128 00000 n
57
+ 0000000177 00000 n
58
+ 0000000608 00000 n
59
+ trailer
60
+ << /Size 6
61
+ /Root 3 0 R
62
+ /Info 1 0 R
63
+ >>
64
+ startxref
65
+ 762
66
+ %%EOF
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "When creating destinations" do
6
+
7
+ before(:each) { create_pdf }
8
+
9
+ it "should add entry to Dests name tree" do
10
+ @pdf.dests.data.empty?.should == true
11
+ @pdf.add_dest "candy", "chocolate"
12
+ @pdf.dests.data.size.should == 1
13
+ end
14
+
15
+ end
@@ -0,0 +1,736 @@
1
+ # encoding: utf-8
2
+ require "tempfile"
3
+
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
+
6
+ describe "Prawn::Document.new" do
7
+ it "should not modify its argument" do
8
+ options = {:page_layout => :landscape}
9
+ Prawn::Document.new(options)
10
+ options.should == {:page_layout => :landscape}
11
+ end
12
+ end
13
+
14
+ describe "The cursor" do
15
+ it "should == pdf.y - bounds.absolute_bottom" do
16
+ pdf = Prawn::Document.new
17
+ pdf.cursor.should == pdf.bounds.top
18
+
19
+ pdf.y = 300
20
+ pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
21
+ end
22
+
23
+ it "should be able to move relative to the bottom margin" do
24
+ pdf = Prawn::Document.new
25
+ pdf.move_cursor_to(10)
26
+
27
+ pdf.cursor.should == 10
28
+ pdf.y.should == pdf.cursor + pdf.bounds.absolute_bottom
29
+ end
30
+ end
31
+
32
+ describe "when generating a document from a subclass" do
33
+ it "should be an instance of the subclass" do
34
+ custom_document = Class.new(Prawn::Document)
35
+ custom_document.generate(Tempfile.new("generate_test").path) do |e|
36
+ e.class.should == custom_document
37
+ e.should be_a_kind_of(Prawn::Document)
38
+ end
39
+ end
40
+
41
+ it "should retain any extensions found on Prawn::Document" do
42
+ mod1 = Module.new { attr_reader :test_extensions1 }
43
+ mod2 = Module.new { attr_reader :test_extensions2 }
44
+
45
+ Prawn::Document.extensions << mod1 << mod2
46
+
47
+ custom_document = Class.new(Prawn::Document)
48
+ custom_document.extensions.should == [mod1, mod2]
49
+
50
+ # remove the extensions we added to prawn document
51
+ Prawn::Document.extensions.delete(mod1)
52
+ Prawn::Document.extensions.delete(mod2)
53
+
54
+ Prawn::Document.new.respond_to?(:test_extensions1).should be_false
55
+ Prawn::Document.new.respond_to?(:test_extensions2).should be_false
56
+
57
+ # verify these still exist on custom class
58
+ custom_document.extensions.should == [mod1, mod2]
59
+
60
+ custom_document.new.respond_to?(:test_extensions1).should be_true
61
+ custom_document.new.respond_to?(:test_extensions2).should be_true
62
+ end
63
+
64
+ end
65
+
66
+
67
+ describe "When creating multi-page documents" do
68
+
69
+ before(:each) { create_pdf }
70
+
71
+ it "should initialize with a single page" do
72
+ page_counter = PDF::Inspector::Page.analyze(@pdf.render)
73
+
74
+ page_counter.pages.size.should == 1
75
+ @pdf.page_count.should == 1
76
+ end
77
+
78
+ it "should provide an accurate page_count" do
79
+ 3.times { @pdf.start_new_page }
80
+ page_counter = PDF::Inspector::Page.analyze(@pdf.render)
81
+
82
+ page_counter.pages.size.should == 4
83
+ @pdf.page_count.should == 4
84
+ end
85
+
86
+ end
87
+
88
+ describe "When beginning each new page" do
89
+
90
+ describe "Background template feature" do
91
+ before(:each) do
92
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
93
+ @pdf = Prawn::Document.new(:background => @filename)
94
+ end
95
+ it "should place a background image if it is in options block" do
96
+ output = @pdf.render
97
+ images = PDF::Inspector::XObject.analyze(output)
98
+ # there should be 2 images in the page resources
99
+ images.page_xobjects.first.size.should == 1
100
+ end
101
+ it "should place a background image if it is in options block" do
102
+ @pdf.instance_variable_defined?(:@background).should == true
103
+ @pdf.instance_variable_get(:@background).should == @filename
104
+ end
105
+
106
+
107
+ end
108
+
109
+
110
+ end
111
+
112
+ describe "Prawn::Document#float" do
113
+ it "should restore the original y-position" do
114
+ create_pdf
115
+ orig_y = @pdf.y
116
+ @pdf.float { @pdf.text "Foo" }
117
+ @pdf.y.should == orig_y
118
+ end
119
+
120
+ it "should teleport across pages if necessary" do
121
+ create_pdf
122
+
123
+ @pdf.float do
124
+ @pdf.text "Foo"
125
+ @pdf.start_new_page
126
+ @pdf.text "Bar"
127
+ end
128
+ @pdf.text "Baz"
129
+
130
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
131
+ pages.size.should == 2
132
+ pages[0][:strings].should == ["Foo", "Baz"]
133
+ pages[1][:strings].should == ["Bar"]
134
+ end
135
+ end
136
+
137
+ describe "The page_number method" do
138
+ it "should be 1 for a new document" do
139
+ pdf = Prawn::Document.new
140
+ pdf.page_number.should == 1
141
+ end
142
+
143
+ it "should be 0 for documents with no pages" do
144
+ pdf = Prawn::Document.new(:skip_page_creation => true)
145
+ pdf.page_number.should == 0
146
+ end
147
+
148
+ it "should be changed by go_to_page" do
149
+ pdf = Prawn::Document.new
150
+ 10.times { pdf.start_new_page }
151
+ pdf.go_to_page 3
152
+ pdf.page_number.should == 3
153
+ end
154
+
155
+ end
156
+
157
+ describe "on_page_create callback" do
158
+ before do
159
+ create_pdf
160
+ end
161
+
162
+ it "should be invoked with document" do
163
+ called_with = nil
164
+
165
+ @pdf.on_page_create { |*args| called_with = args }
166
+
167
+ @pdf.start_new_page
168
+
169
+ called_with.should == [@pdf]
170
+ end
171
+
172
+ it "should be invoked for each new page" do
173
+ trigger = mock()
174
+ trigger.expects(:fire).times(5)
175
+
176
+ @pdf.on_page_create { trigger.fire }
177
+
178
+ 5.times { @pdf.start_new_page }
179
+ end
180
+
181
+ it "should be replaceable" do
182
+ trigger1 = mock()
183
+ trigger1.expects(:fire).times(1)
184
+
185
+ trigger2 = mock()
186
+ trigger2.expects(:fire).times(1)
187
+
188
+ @pdf.on_page_create { trigger1.fire }
189
+
190
+ @pdf.start_new_page
191
+
192
+ @pdf.on_page_create { trigger2.fire }
193
+
194
+ @pdf.start_new_page
195
+ end
196
+
197
+ it "should be clearable by calling on_page_create without a block" do
198
+ trigger = mock()
199
+ trigger.expects(:fire).times(1)
200
+
201
+ @pdf.on_page_create { trigger.fire }
202
+
203
+ @pdf.start_new_page
204
+
205
+ @pdf.on_page_create
206
+
207
+ @pdf.start_new_page
208
+ end
209
+
210
+ end
211
+
212
+ describe "Document compression" do
213
+
214
+ it "should not compress the page content stream if compression is disabled" do
215
+
216
+ pdf = Prawn::Document.new(:compress => false)
217
+ pdf.page.content.stubs(:compress_stream).returns(true)
218
+ pdf.page.content.expects(:compress_stream).never
219
+
220
+ pdf.text "Hi There" * 20
221
+ pdf.render
222
+ end
223
+
224
+ it "should compress the page content stream if compression is enabled" do
225
+
226
+ pdf = Prawn::Document.new(:compress => true)
227
+ pdf.page.content.stubs(:compress_stream).returns(true)
228
+ pdf.page.content.expects(:compress_stream).once
229
+
230
+ pdf.text "Hi There" * 20
231
+ pdf.render
232
+ end
233
+
234
+ it "should result in a smaller file size when compressed" do
235
+ doc_uncompressed = Prawn::Document.new
236
+ doc_compressed = Prawn::Document.new(:compress => true)
237
+ [doc_compressed, doc_uncompressed].each do |pdf|
238
+ pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
239
+ pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
240
+ end
241
+
242
+ doc_compressed.render.length.should be < doc_uncompressed.render.length
243
+ end
244
+
245
+ end
246
+
247
+ describe "Document metadata" do
248
+ it "should output strings as UTF-16 with a byte order mark" do
249
+ pdf = Prawn::Document.new(:info => {:Author => "Lóránt"})
250
+ pdf.state.store.info.object.should =~
251
+ # UTF-16: BOM L ó r á n t
252
+ %r{/Author\s*<feff004c00f3007200e1006e0074>}i
253
+ end
254
+ end
255
+
256
+ describe "When reopening pages" do
257
+ it "should modify the content stream size" do
258
+ @pdf = Prawn::Document.new do |pdf|
259
+ pdf.text "Page 1"
260
+ pdf.start_new_page
261
+ pdf.text "Page 2"
262
+ pdf.go_to_page 1
263
+ pdf.text "More for page 1"
264
+ end
265
+
266
+ # MalformedPDFError raised if content stream actual length does not match
267
+ # dictionary length
268
+ lambda{ PDF::Inspector::Page.analyze(@pdf.render) }.
269
+ should_not raise_error(PDF::Reader::MalformedPDFError)
270
+ end
271
+
272
+ it "should insert pages after the current page when calling start_new_page" do
273
+ pdf = Prawn::Document.new
274
+ 3.times { |i| pdf.text "Old page #{i+1}"; pdf.start_new_page }
275
+ pdf.go_to_page 1
276
+ pdf.start_new_page
277
+ pdf.text "New page 2"
278
+
279
+ pdf.page_number.should == 2
280
+
281
+ pages = PDF::Inspector::Page.analyze(pdf.render).pages
282
+ pages.size.should == 5
283
+ pages[1][:strings].should == ["New page 2"]
284
+ pages[2][:strings].should == ["Old page 2"]
285
+ end
286
+
287
+ it "should update the bounding box to the new page's margin box" do
288
+ Prawn::Document.new do
289
+ start_new_page :layout => :landscape
290
+ lsize = [bounds.width, bounds.height]
291
+ go_to_page 1
292
+ [bounds.width, bounds.height].should == lsize.reverse
293
+ end
294
+ end
295
+ end
296
+
297
+ describe "When setting page size" do
298
+ it "should default to LETTER" do
299
+ @pdf = Prawn::Document.new
300
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
301
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
302
+ end
303
+
304
+ (Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
305
+ it "should provide #{k} geometry" do
306
+ @pdf = Prawn::Document.new(:page_size => k)
307
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
308
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
309
+ end
310
+ end
311
+
312
+ it "should allow custom page size" do
313
+ @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
314
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
315
+ pages.first[:size].should == [1920, 1080]
316
+ end
317
+
318
+
319
+ it "should retain page size by default when starting a new page" do
320
+ @pdf = Prawn::Document.new(:page_size => "LEGAL")
321
+ @pdf.start_new_page
322
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
323
+ pages.each do |page|
324
+ page[:size].should == Prawn::Document::PageGeometry::SIZES["LEGAL"]
325
+ end
326
+ end
327
+
328
+ end
329
+
330
+ describe "When setting page layout" do
331
+ it "should reverse coordinates for landscape" do
332
+ @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
333
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
334
+ pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
335
+ end
336
+
337
+ it "should retain page layout by default when starting a new page" do
338
+ @pdf = Prawn::Document.new(:page_layout => :landscape)
339
+ @pdf.start_new_page(:trace => true)
340
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
341
+ pages.each do |page|
342
+ page[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"].reverse
343
+ end
344
+ end
345
+
346
+ it "should swap the bounds when starting a new page with different layout" do
347
+ @pdf = Prawn::Document.new
348
+ size = [@pdf.bounds.width, @pdf.bounds.height]
349
+ @pdf.start_new_page(:layout => :landscape)
350
+ [@pdf.bounds.width, @pdf.bounds.height].should == size.reverse
351
+ end
352
+ end
353
+
354
+ describe "The mask() feature" do
355
+ it "should allow transactional restoration of attributes" do
356
+ @pdf = Prawn::Document.new
357
+ y, line_width = @pdf.y, @pdf.line_width
358
+ @pdf.mask(:y, :line_width) do
359
+ @pdf.y = y + 1
360
+ @pdf.line_width = line_width + 1
361
+ @pdf.y.should_not == y
362
+ @pdf.line_width.should_not == line_width
363
+ end
364
+ @pdf.y.should == y
365
+ @pdf.line_width.should == line_width
366
+ end
367
+ end
368
+
369
+ describe "The group() feature" do
370
+ it "should return a true value if the content fits on one page" do
371
+ pdf = Prawn::Document.new do
372
+ val = group { text "Hello"; text "World" }
373
+ (!!val).should == true
374
+ end
375
+ end
376
+
377
+ it "should group a simple block on a single page" do
378
+ pdf = Prawn::Document.new do
379
+ self.y = 50
380
+ val = group do
381
+ text "Hello"
382
+ text "World"
383
+ end
384
+
385
+ # group should return a false value since a new page was started
386
+ (!!val).should == false
387
+ end
388
+ pages = PDF::Inspector::Page.analyze(pdf.render).pages
389
+ pages.size.should == 2
390
+ pages[0][:strings].should == []
391
+ pages[1][:strings].should == ["Hello", "World"]
392
+ end
393
+
394
+ it "should raise_error CannotGroup if the content is too tall" do
395
+ lambda {
396
+ Prawn::Document.new do
397
+ group do
398
+ 100.times { text "Too long" }
399
+ end
400
+ end.render
401
+ }.should raise_error(Prawn::Errors::CannotGroup)
402
+ end
403
+
404
+ it "should group within individual column boxes" do
405
+ pdf = Prawn::Document.new do
406
+ # Set up columns with grouped blocks of 0..49. 0 to 49 is slightly short
407
+ # of the height of one page / column, so each column should get its own
408
+ # group (every column should start with zero).
409
+ column_box([0, bounds.top], :width => bounds.width, :columns => 7) do
410
+ 10.times do
411
+ group { 50.times { |i| text(i.to_s) } }
412
+ end
413
+ end
414
+ end
415
+
416
+ # Second page should start with a 0 because it's a new group.
417
+ pages = PDF::Inspector::Page.analyze(pdf.render).pages
418
+ pages.size.should == 2
419
+ pages[1][:strings].first.should == '0'
420
+ end
421
+
422
+ end
423
+
424
+ describe "The render() feature" do
425
+ if "spec".respond_to?(:encode!)
426
+ it "should return a 8 bit encoded string on a m17n aware VM" do
427
+ @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
428
+ @pdf.line [100,100], [200,200]
429
+ str = @pdf.render
430
+ str.encoding.to_s.should == "ASCII-8BIT"
431
+ end
432
+ end
433
+
434
+ it "should trigger before_render callbacks just before rendering" do
435
+ pdf = Prawn::Document.new
436
+
437
+ seq = sequence("callback_order")
438
+
439
+ # Verify the order: finalize -> fire callbacks -> render body
440
+ pdf.expects(:finalize_all_page_contents).in_sequence(seq)
441
+ trigger = mock()
442
+ trigger.expects(:fire).in_sequence(seq)
443
+
444
+ # Store away the render_body method to be called below
445
+ render_body = pdf.method(:render_body)
446
+ pdf.expects(:render_body).in_sequence(seq)
447
+
448
+ pdf.before_render{ trigger.fire }
449
+
450
+ # Render the body to set up object offsets
451
+ render_body.call(StringIO.new)
452
+ pdf.render
453
+ end
454
+
455
+ it "should be idempotent" do
456
+ pdf = Prawn::Document.new
457
+
458
+ contents = pdf.render
459
+ contents2 = pdf.render
460
+ contents2.should == contents
461
+ end
462
+ end
463
+
464
+ describe "The :optimize_objects option" do
465
+ before(:all) do
466
+ @wasteful_doc = lambda do |pdf|
467
+ pdf.transaction do
468
+ pdf.start_new_page
469
+ pdf.text "Hidden text"
470
+ pdf.rollback
471
+ end
472
+
473
+ pdf.text "Hello world"
474
+ end
475
+ end
476
+
477
+ it "should result in fewer objects when enabled" do
478
+ wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
479
+ frugal_pdf = Prawn::Document.new(:optimize_objects => true,
480
+ &@wasteful_doc)
481
+ frugal_pdf.render.size.should be < wasteful_pdf.render.size
482
+ end
483
+
484
+ it "should default to :false" do
485
+ default_pdf = Prawn::Document.new(&@wasteful_doc)
486
+ wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
487
+ &@wasteful_doc)
488
+ default_pdf.render.size.should == wasteful_pdf.render.size
489
+ end
490
+
491
+ end
492
+
493
+ describe "PDF file versions" do
494
+ it "should default to 1.3" do
495
+ @pdf = Prawn::Document.new
496
+ str = @pdf.render
497
+ str[0,8].should == "%PDF-1.3"
498
+ end
499
+
500
+ it "should allow the default to be changed" do
501
+ @pdf = Prawn::Document.new
502
+ @pdf.__send__(:min_version, 1.4)
503
+ str = @pdf.render
504
+ str[0,8].should == "%PDF-1.4"
505
+ end
506
+ end
507
+
508
+ describe "Documents that use go_to_page" do
509
+ it "should have 2 pages after calling start_new_page and go_to_page" do
510
+ @pdf = Prawn::Document.new
511
+ @pdf.text "James"
512
+ @pdf.start_new_page
513
+ @pdf.text "Anthony"
514
+ @pdf.go_to_page(1)
515
+ @pdf.text "Healy"
516
+
517
+ page_counter = PDF::Inspector::Page.analyze(@pdf.render)
518
+ page_counter.pages.size.should == 2
519
+ end
520
+
521
+ it "should correctly add text to pages" do
522
+ @pdf = Prawn::Document.new
523
+ @pdf.text "James"
524
+ @pdf.start_new_page
525
+ @pdf.text "Anthony"
526
+ @pdf.go_to_page(1)
527
+ @pdf.text "Healy"
528
+
529
+ text = PDF::Inspector::Text.analyze(@pdf.render)
530
+
531
+ text.strings.size.should == 3
532
+ text.strings.include?("James").should == true
533
+ text.strings.include?("Anthony").should == true
534
+ text.strings.include?("Healy").should == true
535
+ end
536
+ end
537
+
538
+ describe "content stream characteristics" do
539
+ it "should have 1 single content stream for a single page PDF with no templates" do
540
+ @pdf = Prawn::Document.new
541
+ @pdf.text "James"
542
+ output = StringIO.new(@pdf.render)
543
+ hash = PDF::Reader::ObjectHash.new(output)
544
+
545
+ streams = hash.values.select { |obj| obj.kind_of?(PDF::Reader::Stream) }
546
+
547
+ streams.size.should == 1
548
+ end
549
+
550
+ it "should have 1 single content stream for a single page PDF with no templates, even if go_to_page is used" do
551
+ @pdf = Prawn::Document.new
552
+ @pdf.text "James"
553
+ @pdf.go_to_page(1)
554
+ @pdf.text "Healy"
555
+ output = StringIO.new(@pdf.render)
556
+ hash = PDF::Reader::ObjectHash.new(output)
557
+
558
+ streams = hash.values.select { |obj| obj.kind_of?(PDF::Reader::Stream) }
559
+
560
+ streams.size.should == 1
561
+ end
562
+ end
563
+
564
+ describe "The number_pages method" do
565
+ before do
566
+ @pdf = Prawn::Document.new(:skip_page_creation => true)
567
+ end
568
+
569
+ it "replaces the '<page>' string with the proper page number" do
570
+ @pdf.start_new_page
571
+ @pdf.expects(:text_box).with("1, test", { :height => 50 })
572
+ @pdf.number_pages "<page>, test", {:page_filter => :all}
573
+ end
574
+
575
+ it "replaces the '<total>' string with the total page count" do
576
+ @pdf.start_new_page
577
+ @pdf.expects(:text_box).with("test, 1", { :height => 50 })
578
+ @pdf.number_pages "test, <total>", {:page_filter => :all}
579
+ end
580
+
581
+ it "must print each page if given the :all page_filter" do
582
+ 10.times { @pdf.start_new_page }
583
+ @pdf.expects(:text_box).times(10)
584
+ @pdf.number_pages "test", {:page_filter => :all}
585
+ end
586
+
587
+ it "must print each page if no :page_filter is specified" do
588
+ 10.times { @pdf.start_new_page }
589
+ @pdf.expects(:text_box).times(10)
590
+ @pdf.number_pages "test"
591
+ end
592
+
593
+ it "must not print the page number if given a nil filter" do
594
+ 10.times { @pdf.start_new_page }
595
+ @pdf.expects(:text_box).never
596
+ @pdf.number_pages "test", {:page_filter => nil}
597
+ end
598
+
599
+ context "start_count_at option" do
600
+ [1, 2].each do |startat|
601
+ context "equal to #{startat}" do
602
+ it "increments the pages" do
603
+ 2.times { @pdf.start_new_page }
604
+ options = {:page_filter => :all, :start_count_at => startat}
605
+ @pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
606
+ @pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
607
+ @pdf.number_pages "<page> <total>", options
608
+ end
609
+ end
610
+ end
611
+
612
+ [0, nil].each do |val|
613
+ context "equal to #{val}" do
614
+ it "defaults to start at page 1" do
615
+ 3.times { @pdf.start_new_page }
616
+ options = {:page_filter => :all, :start_count_at => val}
617
+ @pdf.expects(:text_box).with("1 3", { :height => 50 })
618
+ @pdf.expects(:text_box).with("2 3", { :height => 50 })
619
+ @pdf.expects(:text_box).with("3 3", { :height => 50 })
620
+ @pdf.number_pages "<page> <total>", options
621
+ end
622
+ end
623
+ end
624
+ end
625
+
626
+ context "total_pages option" do
627
+ it "allows the total pages count to be overridden" do
628
+ 2.times { @pdf.start_new_page }
629
+ @pdf.expects(:text_box).with("1 10", { :height => 50 })
630
+ @pdf.expects(:text_box).with("2 10", { :height => 50 })
631
+ @pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
632
+ end
633
+ end
634
+
635
+ context "special page filter" do
636
+ context "such as :odd" do
637
+ it "increments the pages" do
638
+ 3.times { @pdf.start_new_page }
639
+ @pdf.expects(:text_box).with("1 3", { :height => 50 })
640
+ @pdf.expects(:text_box).with("3 3", { :height => 50 })
641
+ @pdf.expects(:text_box).with("2 3", { :height => 50 }).never
642
+ @pdf.number_pages "<page> <total>", :page_filter => :odd
643
+ end
644
+ end
645
+ context "missing" do
646
+ it "does not print any page numbers" do
647
+ 3.times { @pdf.start_new_page }
648
+ @pdf.expects(:text_box).never
649
+ @pdf.number_pages "<page> <total>", :page_filter => nil
650
+ end
651
+ end
652
+ end
653
+
654
+ context "given both a special page filter and a start_count_at parameter" do
655
+ context "such as :odd and 7" do
656
+ it "increments the pages" do
657
+ 3.times { @pdf.start_new_page }
658
+ @pdf.expects(:text_box).with("1 3", { :height => 50 }).never
659
+ @pdf.expects(:text_box).with("5 3", { :height => 50 }) # page 1
660
+ @pdf.expects(:text_box).with("6 3", { :height => 50 }).never # page 2
661
+ @pdf.expects(:text_box).with("7 3", { :height => 50 }) # page 3
662
+ @pdf.number_pages "<page> <total>", :page_filter => :odd, :start_count_at => 5
663
+ end
664
+ end
665
+ context "some crazy proc and 2" do
666
+ it "increments the pages" do
667
+ 6.times { @pdf.start_new_page }
668
+ options = {:page_filter => lambda {|p| p != 2 && p != 5}, :start_count_at => 4}
669
+ @pdf.expects(:text_box).with("4 6", { :height => 50 }) # page 1
670
+ @pdf.expects(:text_box).with("5 6", { :height => 50 }).never # page 2
671
+ @pdf.expects(:text_box).with("6 6", { :height => 50 }) # page 3
672
+ @pdf.expects(:text_box).with("7 6", { :height => 50 }) # page 4
673
+ @pdf.expects(:text_box).with("8 6", { :height => 50 }).never # page 5
674
+ @pdf.expects(:text_box).with("9 6", { :height => 50 }) # page 6
675
+ @pdf.number_pages "<page> <total>", options
676
+ end
677
+ end
678
+ end
679
+
680
+ context "height option" do
681
+ before do
682
+ @pdf.start_new_page
683
+ end
684
+
685
+ it "with 10 height" do
686
+ @pdf.expects(:text_box).with("1 1", { :height => 10 })
687
+ @pdf.number_pages "<page> <total>", :height => 10
688
+ end
689
+
690
+ it "with nil height" do
691
+ @pdf.expects(:text_box).with("1 1", { :height => nil })
692
+ @pdf.number_pages "<page> <total>", :height => nil
693
+ end
694
+
695
+ it "with no height" do
696
+ @pdf.expects(:text_box).with("1 1", { :height => 50 })
697
+ @pdf.number_pages "<page> <total>"
698
+ end
699
+ end
700
+ end
701
+
702
+ describe "The page_match? method" do
703
+ before do
704
+ @pdf = Prawn::Document.new(:skip_page_creation => true)
705
+ 10.times {@pdf.start_new_page}
706
+ end
707
+
708
+ it "returns nil given no filter" do
709
+ @pdf.page_match?(:nil, 1).should be_false
710
+ end
711
+
712
+ it "must provide an :all filter" do
713
+ (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
714
+ end
715
+
716
+ it "must provide an :odd filter" do
717
+ odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
718
+ odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
719
+ even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
720
+ end
721
+
722
+ it "must be able to filter by an array of page numbers" do
723
+ fltr = [1,2,7]
724
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
725
+ end
726
+
727
+ it "must be able to filter by a range of page numbers" do
728
+ fltr = 2..4
729
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
730
+ end
731
+
732
+ it "must be able to filter by an arbitrary proc" do
733
+ fltr = lambda { |x| x == 1 or x % 3 == 0 }
734
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
735
+ end
736
+ end