prawn 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +2 -2
  3. data/Gemfile +18 -0
  4. data/LICENSE +1 -1
  5. data/README.md +17 -4
  6. data/Rakefile +18 -22
  7. data/data/images/indexed_color.dat +0 -0
  8. data/data/images/indexed_color.png +0 -0
  9. data/data/pdfs/nested_pages.pdf +13 -13
  10. data/lib/pdf/core.rb +35 -0
  11. data/lib/{prawn → pdf}/core/annotations.rb +6 -7
  12. data/lib/{prawn → pdf}/core/byte_string.rb +1 -1
  13. data/lib/{prawn → pdf}/core/destinations.rb +23 -23
  14. data/lib/{prawn → pdf}/core/document_state.rb +8 -8
  15. data/lib/pdf/core/filter_list.rb +51 -0
  16. data/lib/pdf/core/filters.rb +36 -0
  17. data/lib/pdf/core/graphics_state.rb +68 -0
  18. data/lib/{prawn → pdf}/core/literal_string.rb +1 -1
  19. data/lib/{prawn → pdf}/core/name_tree.rb +14 -2
  20. data/lib/{prawn → pdf}/core/object_store.rb +80 -24
  21. data/lib/pdf/core/outline.rb +315 -0
  22. data/lib/{prawn → pdf}/core/page.rb +23 -26
  23. data/lib/{prawn/document → pdf/core}/page_geometry.rb +11 -21
  24. data/lib/{prawn → pdf}/core/pdf_object.rb +48 -32
  25. data/lib/{prawn → pdf}/core/reference.rb +35 -44
  26. data/lib/pdf/core/stream.rb +98 -0
  27. data/lib/{prawn → pdf}/core/text.rb +24 -17
  28. data/lib/prawn.rb +95 -17
  29. data/lib/prawn/compatibility.rb +66 -26
  30. data/lib/prawn/document.rb +48 -30
  31. data/lib/prawn/document/bounding_box.rb +3 -3
  32. data/lib/prawn/document/column_box.rb +46 -8
  33. data/lib/prawn/document/graphics_state.rb +10 -73
  34. data/lib/prawn/document/internals.rb +24 -23
  35. data/lib/prawn/document/snapshot.rb +6 -7
  36. data/lib/prawn/document/span.rb +10 -10
  37. data/lib/prawn/encoding.rb +7 -7
  38. data/lib/prawn/errors.rb +18 -29
  39. data/lib/prawn/font.rb +64 -28
  40. data/lib/prawn/font/afm.rb +32 -74
  41. data/lib/prawn/font/dfont.rb +2 -2
  42. data/lib/prawn/font/ttf.rb +28 -57
  43. data/lib/prawn/font_metric_cache.rb +45 -0
  44. data/lib/prawn/graphics.rb +307 -41
  45. data/lib/prawn/graphics/cap_style.rb +3 -3
  46. data/lib/prawn/graphics/color.rb +12 -5
  47. data/lib/prawn/graphics/dash.rb +52 -31
  48. data/lib/prawn/graphics/join_style.rb +7 -7
  49. data/lib/prawn/graphics/patterns.rb +137 -0
  50. data/lib/prawn/graphics/transformation.rb +9 -9
  51. data/lib/prawn/graphics/transparency.rb +1 -1
  52. data/lib/prawn/image_handler.rb +30 -0
  53. data/lib/prawn/images.rb +86 -105
  54. data/lib/prawn/images/image.rb +48 -0
  55. data/lib/prawn/images/jpg.rb +14 -10
  56. data/lib/prawn/images/png.rb +50 -37
  57. data/lib/prawn/layout.rb +2 -2
  58. data/lib/prawn/layout/grid.rb +51 -51
  59. data/lib/prawn/measurement_extensions.rb +5 -5
  60. data/lib/prawn/measurements.rb +25 -21
  61. data/lib/prawn/outline.rb +4 -308
  62. data/lib/prawn/repeater.rb +8 -8
  63. data/lib/prawn/security.rb +50 -36
  64. data/lib/prawn/soft_mask.rb +94 -0
  65. data/lib/prawn/stamp.rb +3 -3
  66. data/lib/prawn/table.rb +292 -118
  67. data/lib/prawn/table/cell.rb +272 -45
  68. data/lib/prawn/table/cell/image.rb +70 -0
  69. data/lib/prawn/table/cell/in_table.rb +2 -2
  70. data/lib/prawn/table/cell/span_dummy.rb +92 -0
  71. data/lib/prawn/table/cell/subtable.rb +2 -2
  72. data/lib/prawn/table/cell/text.rb +42 -24
  73. data/lib/prawn/table/cells.rb +137 -48
  74. data/lib/prawn/text.rb +35 -23
  75. data/lib/prawn/text/box.rb +18 -5
  76. data/lib/prawn/text/formatted.rb +5 -4
  77. data/lib/prawn/text/formatted/arranger.rb +292 -0
  78. data/lib/prawn/text/formatted/box.rb +52 -13
  79. data/lib/prawn/text/formatted/fragment.rb +37 -22
  80. data/lib/prawn/text/formatted/line_wrap.rb +286 -0
  81. data/lib/prawn/text/formatted/parser.rb +14 -6
  82. data/lib/prawn/text/formatted/wrap.rb +151 -0
  83. data/lib/prawn/utilities.rb +44 -0
  84. data/manual/basic_concepts/adding_pages.rb +27 -0
  85. data/manual/basic_concepts/basic_concepts.rb +34 -0
  86. data/manual/basic_concepts/creation.rb +39 -0
  87. data/manual/basic_concepts/cursor.rb +33 -0
  88. data/manual/basic_concepts/measurement.rb +25 -0
  89. data/manual/basic_concepts/origin.rb +38 -0
  90. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  91. data/manual/bounding_box/bounding_box.rb +39 -0
  92. data/manual/bounding_box/bounds.rb +49 -0
  93. data/manual/bounding_box/canvas.rb +24 -0
  94. data/manual/bounding_box/creation.rb +23 -0
  95. data/manual/bounding_box/indentation.rb +46 -0
  96. data/manual/bounding_box/nesting.rb +45 -0
  97. data/manual/bounding_box/russian_boxes.rb +40 -0
  98. data/manual/bounding_box/stretchy.rb +31 -0
  99. data/manual/document_and_page_options/background.rb +27 -0
  100. data/manual/document_and_page_options/document_and_page_options.rb +31 -0
  101. data/manual/document_and_page_options/metadata.rb +23 -0
  102. data/manual/document_and_page_options/page_margins.rb +38 -0
  103. data/manual/document_and_page_options/page_size.rb +34 -0
  104. data/manual/example_file.rb +116 -0
  105. data/manual/example_helper.rb +411 -0
  106. data/manual/example_package.rb +53 -0
  107. data/manual/example_section.rb +46 -0
  108. data/manual/graphics/circle_and_ellipse.rb +22 -0
  109. data/manual/graphics/color.rb +24 -0
  110. data/manual/graphics/common_lines.rb +28 -0
  111. data/manual/graphics/fill_and_stroke.rb +42 -0
  112. data/manual/graphics/fill_rules.rb +37 -0
  113. data/manual/graphics/gradients.rb +37 -0
  114. data/manual/graphics/graphics.rb +58 -0
  115. data/manual/graphics/helper.rb +24 -0
  116. data/manual/graphics/line_width.rb +35 -0
  117. data/manual/graphics/lines_and_curves.rb +41 -0
  118. data/manual/graphics/polygon.rb +29 -0
  119. data/manual/graphics/rectangle.rb +21 -0
  120. data/manual/graphics/rotate.rb +28 -0
  121. data/manual/graphics/scale.rb +41 -0
  122. data/manual/graphics/soft_masks.rb +46 -0
  123. data/manual/graphics/stroke_cap.rb +31 -0
  124. data/manual/graphics/stroke_dash.rb +48 -0
  125. data/manual/graphics/stroke_join.rb +30 -0
  126. data/manual/graphics/translate.rb +29 -0
  127. data/manual/graphics/transparency.rb +35 -0
  128. data/manual/images/absolute_position.rb +23 -0
  129. data/manual/images/fit.rb +21 -0
  130. data/manual/images/horizontal.rb +25 -0
  131. data/manual/images/images.rb +40 -0
  132. data/manual/images/plain_image.rb +18 -0
  133. data/manual/images/scale.rb +22 -0
  134. data/manual/images/vertical.rb +28 -0
  135. data/manual/images/width_and_height.rb +25 -0
  136. data/manual/layout/boxes.rb +27 -0
  137. data/manual/layout/content.rb +25 -0
  138. data/manual/layout/layout.rb +28 -0
  139. data/manual/layout/simple_grid.rb +23 -0
  140. data/manual/manual/cover.rb +35 -0
  141. data/manual/manual/foreword.rb +85 -0
  142. data/manual/manual/how_to_read_this_manual.rb +41 -0
  143. data/manual/manual/manual.rb +35 -0
  144. data/manual/outline/add_subsection_to.rb +61 -0
  145. data/manual/outline/insert_section_after.rb +47 -0
  146. data/manual/outline/outline.rb +32 -0
  147. data/manual/outline/sections_and_pages.rb +67 -0
  148. data/manual/repeatable_content/page_numbering.rb +54 -0
  149. data/manual/repeatable_content/repeatable_content.rb +31 -0
  150. data/manual/repeatable_content/repeater.rb +55 -0
  151. data/manual/repeatable_content/stamp.rb +41 -0
  152. data/manual/security/encryption.rb +31 -0
  153. data/manual/security/permissions.rb +38 -0
  154. data/manual/security/security.rb +28 -0
  155. data/manual/syntax_highlight.rb +52 -0
  156. data/manual/table/basic_block.rb +53 -0
  157. data/manual/table/before_rendering_page.rb +26 -0
  158. data/manual/table/cell_border_lines.rb +24 -0
  159. data/manual/table/cell_borders_and_bg.rb +31 -0
  160. data/manual/table/cell_dimensions.rb +30 -0
  161. data/manual/table/cell_text.rb +38 -0
  162. data/manual/table/column_widths.rb +30 -0
  163. data/manual/table/content_and_subtables.rb +39 -0
  164. data/manual/table/creation.rb +27 -0
  165. data/manual/table/filtering.rb +36 -0
  166. data/manual/table/flow_and_header.rb +17 -0
  167. data/manual/table/image_cells.rb +33 -0
  168. data/manual/table/position.rb +29 -0
  169. data/manual/table/row_colors.rb +20 -0
  170. data/manual/table/span.rb +30 -0
  171. data/manual/table/style.rb +22 -0
  172. data/manual/table/table.rb +52 -0
  173. data/manual/table/width.rb +27 -0
  174. data/manual/templates/full_template.rb +25 -0
  175. data/manual/templates/page_template.rb +48 -0
  176. data/manual/templates/templates.rb +27 -0
  177. data/manual/text/alignment.rb +44 -0
  178. data/manual/text/color.rb +24 -0
  179. data/manual/text/column_box.rb +32 -0
  180. data/manual/text/fallback_fonts.rb +37 -0
  181. data/manual/text/font.rb +41 -0
  182. data/manual/text/font_size.rb +45 -0
  183. data/manual/text/font_style.rb +23 -0
  184. data/manual/text/formatted_callbacks.rb +60 -0
  185. data/manual/text/formatted_text.rb +54 -0
  186. data/manual/text/free_flowing_text.rb +51 -0
  187. data/manual/text/group.rb +29 -0
  188. data/manual/text/inline.rb +43 -0
  189. data/manual/text/kerning_and_character_spacing.rb +39 -0
  190. data/manual/text/leading.rb +25 -0
  191. data/manual/text/line_wrapping.rb +41 -0
  192. data/manual/text/paragraph_indentation.rb +26 -0
  193. data/manual/text/positioned_text.rb +38 -0
  194. data/manual/text/registering_families.rb +48 -0
  195. data/manual/text/rendering_and_color.rb +37 -0
  196. data/manual/text/right_to_left_text.rb +43 -0
  197. data/manual/text/rotation.rb +43 -0
  198. data/manual/text/single_usage.rb +37 -0
  199. data/manual/text/text.rb +75 -0
  200. data/manual/text/text_box_excess.rb +32 -0
  201. data/manual/text/text_box_extensions.rb +45 -0
  202. data/manual/text/text_box_overflow.rb +44 -0
  203. data/manual/text/utf8.rb +28 -0
  204. data/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
  205. data/prawn.gemspec +18 -12
  206. data/spec/acceptance/png.rb +23 -0
  207. data/spec/annotations_spec.rb +16 -32
  208. data/spec/bounding_box_spec.rb +128 -15
  209. data/spec/cell_spec.rb +169 -38
  210. data/spec/column_box_spec.rb +33 -0
  211. data/spec/destinations_spec.rb +5 -5
  212. data/spec/document_spec.rb +150 -104
  213. data/spec/extensions/encoding_helpers.rb +10 -0
  214. data/spec/extensions/mocha.rb +1 -0
  215. data/spec/filters_spec.rb +34 -0
  216. data/spec/font_metric_cache_spec.rb +52 -0
  217. data/spec/font_spec.rb +183 -97
  218. data/spec/formatted_text_arranger_spec.rb +43 -43
  219. data/spec/formatted_text_box_spec.rb +30 -20
  220. data/spec/formatted_text_fragment_spec.rb +8 -8
  221. data/spec/graphics_spec.rb +158 -69
  222. data/spec/grid_spec.rb +15 -15
  223. data/spec/image_handler_spec.rb +42 -0
  224. data/spec/images_spec.rb +49 -24
  225. data/spec/inline_formatted_text_parser_spec.rb +73 -19
  226. data/spec/jpg_spec.rb +4 -4
  227. data/spec/line_wrap_spec.rb +26 -26
  228. data/spec/measurement_units_spec.rb +6 -6
  229. data/spec/name_tree_spec.rb +21 -21
  230. data/spec/object_store_spec.rb +39 -39
  231. data/spec/outline_spec.rb +93 -53
  232. data/spec/pdf_object_spec.rb +88 -86
  233. data/spec/png_spec.rb +31 -28
  234. data/spec/reference_spec.rb +32 -32
  235. data/spec/repeater_spec.rb +25 -11
  236. data/spec/security_spec.rb +44 -12
  237. data/spec/snapshot_spec.rb +8 -9
  238. data/spec/soft_mask_spec.rb +117 -0
  239. data/spec/span_spec.rb +10 -15
  240. data/spec/spec_helper.rb +25 -8
  241. data/spec/stamp_spec.rb +29 -30
  242. data/spec/stream_spec.rb +58 -0
  243. data/spec/stroke_styles_spec.rb +36 -18
  244. data/spec/table/span_dummy_spec.rb +17 -0
  245. data/spec/table_spec.rb +697 -105
  246. data/spec/template_spec.rb +108 -54
  247. data/spec/text_at_spec.rb +18 -17
  248. data/spec/text_box_spec.rb +111 -62
  249. data/spec/text_rendering_mode_spec.rb +5 -5
  250. data/spec/text_spacing_spec.rb +4 -4
  251. data/spec/text_spec.rb +57 -49
  252. data/spec/transparency_spec.rb +5 -5
  253. metadata +421 -213
  254. data/data/fonts/Action Man.dfont +0 -0
  255. data/data/fonts/Activa.ttf +0 -0
  256. data/data/fonts/Chalkboard.ttf +0 -0
  257. data/data/fonts/DejaVuSans.ttf +0 -0
  258. data/data/fonts/Dustismo_Roman.ttf +0 -0
  259. data/data/fonts/comicsans.ttf +0 -0
  260. data/data/fonts/gkai00mp.ttf +0 -0
  261. data/data/images/rails.dat +0 -0
  262. data/data/images/rails.png +0 -0
  263. data/examples/bounding_box/russian_boxes.rb +0 -37
  264. data/examples/example_helper.rb +0 -11
  265. data/examples/general/context_sensitive_headers.rb +0 -38
  266. data/examples/graphics/cmyk.rb +0 -13
  267. data/examples/graphics/gradient.rb +0 -23
  268. data/examples/graphics/png_types.rb +0 -23
  269. data/examples/graphics/remote_images.rb +0 -13
  270. data/examples/m17n/full_win_ansi_character_list.rb +0 -20
  271. data/examples/m17n/sjis.rb +0 -29
  272. data/examples/table/bill.rb +0 -54
  273. data/examples/table/header.rb +0 -15
  274. data/examples/text/font_calculations.rb +0 -92
  275. data/examples/text/hyphenation.rb +0 -45
  276. data/examples/text/indent_paragraphs.rb +0 -24
  277. data/lib/prawn/core.rb +0 -85
  278. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  279. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -273
  280. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  281. data/lib/prawn/graphics/gradient.rb +0 -84
  282. data/lib/prawn/security/arcfour.rb +0 -51
@@ -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
@@ -1,12 +1,12 @@
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
+
5
+ describe "When creating destinations" do
4
6
 
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 equal pdf.y - bounds.absolute_bottom" do
15
+ it "should == 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,14 +27,40 @@ 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
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
31
57
 
32
58
  describe "when generating a document from a subclass" do
33
59
  it "should be an instance of the subclass" do
34
60
  custom_document = Class.new(Prawn::Document)
35
- custom_document.generate(Tempfile.new("generate_test").path) do |e|
61
+ custom_document.generate(Tempfile.new("generate_test").path) do |e|
36
62
  e.class.should == custom_document
37
- e.should.be.kind_of(Prawn::Document)
63
+ e.should be_a_kind_of(Prawn::Document)
38
64
  end
39
65
  end
40
66
 
@@ -45,51 +71,51 @@ describe "when generating a document from a subclass" do
45
71
  Prawn::Document.extensions << mod1 << mod2
46
72
 
47
73
  custom_document = Class.new(Prawn::Document)
48
- assert_equal [mod1, mod2], custom_document.extensions
74
+ custom_document.extensions.should == [mod1, mod2]
49
75
 
50
76
  # remove the extensions we added to prawn document
51
77
  Prawn::Document.extensions.delete(mod1)
52
78
  Prawn::Document.extensions.delete(mod2)
53
79
 
54
- assert ! Prawn::Document.new.respond_to?(:test_extensions1)
55
- assert ! Prawn::Document.new.respond_to?(:test_extensions2)
80
+ Prawn::Document.new.respond_to?(:test_extensions1).should be_false
81
+ Prawn::Document.new.respond_to?(:test_extensions2).should be_false
56
82
 
57
83
  # verify these still exist on custom class
58
- assert_equal [mod1, mod2], custom_document.extensions
84
+ custom_document.extensions.should == [mod1, mod2]
59
85
 
60
- assert custom_document.new.respond_to?(:test_extensions1)
61
- assert custom_document.new.respond_to?(:test_extensions2)
86
+ custom_document.new.respond_to?(:test_extensions1).should be_true
87
+ custom_document.new.respond_to?(:test_extensions2).should be_true
62
88
  end
63
89
 
64
90
  end
65
91
 
66
-
67
- describe "When creating multi-page documents" do
68
-
92
+
93
+ describe "When creating multi-page documents" do
94
+
69
95
  before(:each) { create_pdf }
70
-
71
- it "should initialize with a single page" do
96
+
97
+ it "should initialize with a single page" do
72
98
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
73
-
74
- page_counter.pages.size.should == 1
75
- @pdf.page_count.should == 1
99
+
100
+ page_counter.pages.size.should == 1
101
+ @pdf.page_count.should == 1
76
102
  end
77
-
103
+
78
104
  it "should provide an accurate page_count" do
79
- 3.times { @pdf.start_new_page }
105
+ 3.times { @pdf.start_new_page }
80
106
  page_counter = PDF::Inspector::Page.analyze(@pdf.render)
81
-
107
+
82
108
  page_counter.pages.size.should == 4
83
109
  @pdf.page_count.should == 4
84
- end
85
-
86
- end
110
+ end
111
+
112
+ end
87
113
 
88
114
  describe "When beginning each new page" do
89
115
 
90
116
  describe "Background template feature" do
91
117
  before(:each) do
92
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
118
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
93
119
  @pdf = Prawn::Document.new(:background => @filename)
94
120
  end
95
121
  it "should place a background image if it is in options block" do
@@ -102,11 +128,11 @@ describe "When beginning each new page" do
102
128
  @pdf.instance_variable_defined?(:@background).should == true
103
129
  @pdf.instance_variable_get(:@background).should == @filename
104
130
  end
105
-
106
-
131
+
132
+
107
133
  end
108
-
109
-
134
+
135
+
110
136
  end
111
137
 
112
138
  describe "Prawn::Document#float" do
@@ -119,7 +145,7 @@ describe "Prawn::Document#float" do
119
145
 
120
146
  it "should teleport across pages if necessary" do
121
147
  create_pdf
122
-
148
+
123
149
  @pdf.float do
124
150
  @pdf.text "Foo"
125
151
  @pdf.start_new_page
@@ -156,7 +182,7 @@ end
156
182
 
157
183
  describe "on_page_create callback" do
158
184
  before do
159
- create_pdf
185
+ create_pdf
160
186
  end
161
187
 
162
188
  it "should be invoked with document" do
@@ -177,34 +203,34 @@ describe "on_page_create callback" do
177
203
 
178
204
  5.times { @pdf.start_new_page }
179
205
  end
180
-
206
+
181
207
  it "should be replaceable" do
182
208
  trigger1 = mock()
183
209
  trigger1.expects(:fire).times(1)
184
-
210
+
185
211
  trigger2 = mock()
186
212
  trigger2.expects(:fire).times(1)
187
213
 
188
214
  @pdf.on_page_create { trigger1.fire }
189
-
215
+
190
216
  @pdf.start_new_page
191
-
217
+
192
218
  @pdf.on_page_create { trigger2.fire }
193
-
219
+
194
220
  @pdf.start_new_page
195
221
  end
196
-
222
+
197
223
  it "should be clearable by calling on_page_create without a block" do
198
224
  trigger = mock()
199
225
  trigger.expects(:fire).times(1)
200
226
 
201
227
  @pdf.on_page_create { trigger.fire }
202
228
 
203
- @pdf.start_new_page
204
-
229
+ @pdf.start_new_page
230
+
205
231
  @pdf.on_page_create
206
-
207
- @pdf.start_new_page
232
+
233
+ @pdf.start_new_page
208
234
  end
209
235
 
210
236
  end
@@ -214,8 +240,8 @@ describe "Document compression" do
214
240
  it "should not compress the page content stream if compression is disabled" do
215
241
 
216
242
  pdf = Prawn::Document.new(:compress => false)
217
- pdf.page.content.stubs(:compress_stream).returns(true)
218
- pdf.page.content.expects(:compress_stream).never
243
+ pdf.page.content.stream.stubs(:compress!).returns(true)
244
+ pdf.page.content.stream.expects(:compress!).never
219
245
 
220
246
  pdf.text "Hi There" * 20
221
247
  pdf.render
@@ -224,8 +250,8 @@ describe "Document compression" do
224
250
  it "should compress the page content stream if compression is enabled" do
225
251
 
226
252
  pdf = Prawn::Document.new(:compress => true)
227
- pdf.page.content.stubs(:compress_stream).returns(true)
228
- pdf.page.content.expects(:compress_stream).once
253
+ pdf.page.content.stream.stubs(:compress!).returns(true)
254
+ pdf.page.content.stream.expects(:compress!).once
229
255
 
230
256
  pdf.text "Hi There" * 20
231
257
  pdf.render
@@ -235,14 +261,14 @@ describe "Document compression" do
235
261
  doc_uncompressed = Prawn::Document.new
236
262
  doc_compressed = Prawn::Document.new(:compress => true)
237
263
  [doc_compressed, doc_uncompressed].each do |pdf|
238
- pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
264
+ pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
239
265
  pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
240
266
  end
241
267
 
242
- doc_compressed.render.length.should.be < doc_uncompressed.render.length
243
- end
268
+ doc_compressed.render.length.should be < doc_uncompressed.render.length
269
+ end
244
270
 
245
- end
271
+ end
246
272
 
247
273
  describe "Document metadata" do
248
274
  it "should output strings as UTF-16 with a byte order mark" do
@@ -262,11 +288,10 @@ describe "When reopening pages" do
262
288
  pdf.go_to_page 1
263
289
  pdf.text "More for page 1"
264
290
  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(PDF::Reader::MalformedPDFError)
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)
270
295
  end
271
296
 
272
297
  it "should insert pages after the current page when calling start_new_page" do
@@ -298,21 +323,21 @@ describe "When setting page size" do
298
323
  it "should default to LETTER" do
299
324
  @pdf = Prawn::Document.new
300
325
  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|
326
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"]
327
+ end
328
+
329
+ (PDF::Core::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
305
330
  it "should provide #{k} geometry" do
306
331
  @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]
332
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
333
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES[k]
309
334
  end
310
335
  end
311
-
312
- it "should allow custom page size" do
336
+
337
+ it "should allow custom page size" do
313
338
  @pdf = Prawn::Document.new(:page_size => [1920, 1080] )
314
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
315
- pages.first[:size].should == [1920, 1080]
339
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
340
+ pages.first[:size].should == [1920, 1080]
316
341
  end
317
342
 
318
343
 
@@ -321,25 +346,25 @@ describe "When setting page size" do
321
346
  @pdf.start_new_page
322
347
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
323
348
  pages.each do |page|
324
- page[:size].should == Prawn::Document::PageGeometry::SIZES["LEGAL"]
349
+ page[:size].should == PDF::Core::PageGeometry::SIZES["LEGAL"]
325
350
  end
326
351
  end
327
352
 
328
- end
353
+ end
329
354
 
330
355
  describe "When setting page layout" do
331
356
  it "should reverse coordinates for landscape" do
332
357
  @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
358
+ pages = PDF::Inspector::Page.analyze(@pdf.render).pages
359
+ pages.first[:size].should == PDF::Core::PageGeometry::SIZES["A4"].reverse
360
+ end
336
361
 
337
362
  it "should retain page layout by default when starting a new page" do
338
363
  @pdf = Prawn::Document.new(:page_layout => :landscape)
339
364
  @pdf.start_new_page(:trace => true)
340
365
  pages = PDF::Inspector::Page.analyze(@pdf.render).pages
341
366
  pages.each do |page|
342
- page[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"].reverse
367
+ page[:size].should == PDF::Core::PageGeometry::SIZES["LETTER"].reverse
343
368
  end
344
369
  end
345
370
 
@@ -358,11 +383,11 @@ describe "The mask() feature" do
358
383
  @pdf.mask(:y, :line_width) do
359
384
  @pdf.y = y + 1
360
385
  @pdf.line_width = line_width + 1
361
- @pdf.y.should.not == y
362
- @pdf.line_width.should.not == line_width
386
+ @pdf.y.should_not == y
387
+ @pdf.line_width.should_not == line_width
363
388
  end
364
389
  @pdf.y.should == y
365
- @pdf.line_width.should == line_width
390
+ @pdf.line_width.should == line_width
366
391
  end
367
392
  end
368
393
 
@@ -391,14 +416,14 @@ describe "The group() feature" do
391
416
  pages[1][:strings].should == ["Hello", "World"]
392
417
  end
393
418
 
394
- it "should raise CannotGroup if the content is too tall" do
419
+ it "should raise_error CannotGroup if the content is too tall" do
395
420
  lambda {
396
421
  Prawn::Document.new do
397
422
  group do
398
423
  100.times { text "Too long" }
399
424
  end
400
425
  end.render
401
- }.should.raise(Prawn::Errors::CannotGroup)
426
+ }.should raise_error(Prawn::Errors::CannotGroup)
402
427
  end
403
428
 
404
429
  it "should group within individual column boxes" do
@@ -433,14 +458,14 @@ describe "The render() feature" do
433
458
 
434
459
  it "should trigger before_render callbacks just before rendering" do
435
460
  pdf = Prawn::Document.new
436
-
461
+
437
462
  seq = sequence("callback_order")
438
463
 
439
464
  # Verify the order: finalize -> fire callbacks -> render body
440
465
  pdf.expects(:finalize_all_page_contents).in_sequence(seq)
441
466
  trigger = mock()
442
467
  trigger.expects(:fire).in_sequence(seq)
443
-
468
+
444
469
  # Store away the render_body method to be called below
445
470
  render_body = pdf.method(:render_body)
446
471
  pdf.expects(:render_body).in_sequence(seq)
@@ -464,10 +489,10 @@ end
464
489
  describe "The :optimize_objects option" do
465
490
  before(:all) do
466
491
  @wasteful_doc = lambda do |pdf|
467
- pdf.transaction do
492
+ pdf.transaction do
468
493
  pdf.start_new_page
469
494
  pdf.text "Hidden text"
470
- pdf.rollback
495
+ pdf.rollback
471
496
  end
472
497
 
473
498
  pdf.text "Hello world"
@@ -478,12 +503,12 @@ describe "The :optimize_objects option" do
478
503
  wasteful_pdf = Prawn::Document.new(&@wasteful_doc)
479
504
  frugal_pdf = Prawn::Document.new(:optimize_objects => true,
480
505
  &@wasteful_doc)
481
- frugal_pdf.render.size.should.be < wasteful_pdf.render.size
506
+ frugal_pdf.render.size.should be < wasteful_pdf.render.size
482
507
  end
483
508
 
484
509
  it "should default to :false" do
485
510
  default_pdf = Prawn::Document.new(&@wasteful_doc)
486
- wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
511
+ wasteful_pdf = Prawn::Document.new(:optimize_objects => false,
487
512
  &@wasteful_doc)
488
513
  default_pdf.render.size.should == wasteful_pdf.render.size
489
514
  end
@@ -565,25 +590,25 @@ describe "The number_pages method" do
565
590
  before do
566
591
  @pdf = Prawn::Document.new(:skip_page_creation => true)
567
592
  end
568
-
593
+
569
594
  it "replaces the '<page>' string with the proper page number" do
570
595
  @pdf.start_new_page
571
596
  @pdf.expects(:text_box).with("1, test", { :height => 50 })
572
597
  @pdf.number_pages "<page>, test", {:page_filter => :all}
573
598
  end
574
-
599
+
575
600
  it "replaces the '<total>' string with the total page count" do
576
601
  @pdf.start_new_page
577
602
  @pdf.expects(:text_box).with("test, 1", { :height => 50 })
578
603
  @pdf.number_pages "test, <total>", {:page_filter => :all}
579
604
  end
580
-
605
+
581
606
  it "must print each page if given the :all page_filter" do
582
607
  10.times { @pdf.start_new_page }
583
608
  @pdf.expects(:text_box).times(10)
584
609
  @pdf.number_pages "test", {:page_filter => :all}
585
610
  end
586
-
611
+
587
612
  it "must print each page if no :page_filter is specified" do
588
613
  10.times { @pdf.start_new_page }
589
614
  @pdf.expects(:text_box).times(10)
@@ -595,8 +620,8 @@ describe "The number_pages method" do
595
620
  @pdf.expects(:text_box).never
596
621
  @pdf.number_pages "test", {:page_filter => nil}
597
622
  end
598
-
599
- context "start_count_at option" do
623
+
624
+ context "start_count_at option" do
600
625
  [1, 2].each do |startat|
601
626
  context "equal to #{startat}" do
602
627
  it "increments the pages" do
@@ -605,10 +630,10 @@ describe "The number_pages method" do
605
630
  @pdf.expects(:text_box).with("#{startat} 2", { :height => 50 })
606
631
  @pdf.expects(:text_box).with("#{startat+1} 2", { :height => 50 })
607
632
  @pdf.number_pages "<page> <total>", options
608
- end
633
+ end
609
634
  end
610
635
  end
611
-
636
+
612
637
  [0, nil].each do |val|
613
638
  context "equal to #{val}" do
614
639
  it "defaults to start at page 1" do
@@ -622,7 +647,7 @@ describe "The number_pages method" do
622
647
  end
623
648
  end
624
649
  end
625
-
650
+
626
651
  context "total_pages option" do
627
652
  it "allows the total pages count to be overridden" do
628
653
  2.times { @pdf.start_new_page }
@@ -631,7 +656,7 @@ describe "The number_pages method" do
631
656
  @pdf.number_pages "<page> <total>", :page_filter => :all, :total_pages => 10
632
657
  end
633
658
  end
634
-
659
+
635
660
  context "special page filter" do
636
661
  context "such as :odd" do
637
662
  it "increments the pages" do
@@ -676,6 +701,27 @@ describe "The number_pages method" do
676
701
  end
677
702
  end
678
703
  end
704
+
705
+ context "height option" do
706
+ before do
707
+ @pdf.start_new_page
708
+ end
709
+
710
+ it "with 10 height" do
711
+ @pdf.expects(:text_box).with("1 1", { :height => 10 })
712
+ @pdf.number_pages "<page> <total>", :height => 10
713
+ end
714
+
715
+ it "with nil height" do
716
+ @pdf.expects(:text_box).with("1 1", { :height => nil })
717
+ @pdf.number_pages "<page> <total>", :height => nil
718
+ end
719
+
720
+ it "with no height" do
721
+ @pdf.expects(:text_box).with("1 1", { :height => 50 })
722
+ @pdf.number_pages "<page> <total>"
723
+ end
724
+ end
679
725
  end
680
726
 
681
727
  describe "The page_match? method" do
@@ -683,33 +729,33 @@ describe "The page_match? method" do
683
729
  @pdf = Prawn::Document.new(:skip_page_creation => true)
684
730
  10.times {@pdf.start_new_page}
685
731
  end
686
-
732
+
687
733
  it "returns nil given no filter" do
688
- assert ! @pdf.page_match?(:nil, 1)
734
+ @pdf.page_match?(:nil, 1).should be_false
689
735
  end
690
-
736
+
691
737
  it "must provide an :all filter" do
692
- assert (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }
738
+ (1..@pdf.page_count).all? { |i| @pdf.page_match?(:all, i) }.should be_true
693
739
  end
694
740
 
695
741
  it "must provide an :odd filter" do
696
742
  odd, even = (1..@pdf.page_count).partition { |e| e % 2 == 1 }
697
- assert odd.all? { |i| @pdf.page_match?(:odd, i) }
698
- assert ! even.any? { |i| @pdf.page_match?(:odd, i) }
743
+ odd.all? { |i| @pdf.page_match?(:odd, i) }.should be_true
744
+ even.any? { |i| @pdf.page_match?(:odd, i) }.should be_false
699
745
  end
700
746
 
701
747
  it "must be able to filter by an array of page numbers" do
702
748
  fltr = [1,2,7]
703
- assert_equal [1,2,7], (1..10).select { |i| @pdf.page_match?(fltr, i) }
749
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,2,7]
704
750
  end
705
751
 
706
752
  it "must be able to filter by a range of page numbers" do
707
753
  fltr = 2..4
708
- assert_equal [2,3,4], (1..10).select { |i| @pdf.page_match?(fltr, i) }
754
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [2,3,4]
709
755
  end
710
756
 
711
757
  it "must be able to filter by an arbitrary proc" do
712
758
  fltr = lambda { |x| x == 1 or x % 3 == 0 }
713
- assert_equal [1,3,6,9], (1..10).select { |i| @pdf.page_match?(fltr, i) }
714
- end
759
+ (1..10).select { |i| @pdf.page_match?(fltr, i) }.should == [1,3,6,9]
760
+ end
715
761
  end