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
@@ -9,6 +9,13 @@ describe "Document built from a template" do
9
9
  page_counter.pages.size.should == 1
10
10
  end
11
11
 
12
+ it "should not set the template page's parent to the document pages catalog (especially with nested pages)" do
13
+ filename = "#{Prawn::DATADIR}/pdfs/nested_pages.pdf"
14
+ @pdf = Prawn::Document.new(:template => filename, :skip_page_creation => true)
15
+ @pdf.state.page.dictionary.data[:Parent].should_not == @pdf.state.store.pages
16
+ end
17
+
18
+
12
19
  it "should have start with the Y cursor at the top of the document" do
13
20
  filename = "#{Prawn::BASEDIR}/spec/data/curves.pdf"
14
21
 
@@ -20,27 +27,27 @@ describe "Document built from a template" do
20
27
  filename = "#{Prawn::BASEDIR}/spec/data/curves.pdf"
21
28
 
22
29
  @pdf = Prawn::Document.new(:template => filename, :margin => 0)
23
- assert_equal @pdf.page.margins, { :left => 0,
24
- :right => 0,
25
- :top => 0,
26
- :bottom => 0 }
30
+ @pdf.page.margins.should == { :left => 0,
31
+ :right => 0,
32
+ :top => 0,
33
+ :bottom => 0 }
27
34
 
28
35
  @pdf = Prawn::Document.new(:template => filename, :left_margin => 0)
29
36
 
30
- assert_equal @pdf.page.margins, { :left => 0,
31
- :right => 36,
32
- :top => 36,
33
- :bottom => 36 }
37
+ @pdf.page.margins.should == { :left => 0,
38
+ :right => 36,
39
+ :top => 36,
40
+ :bottom => 36 }
34
41
 
35
42
  @pdf.start_new_page(:right_margin => 0)
36
43
 
37
- assert_equal @pdf.page.margins, { :left => 0,
38
- :right => 0,
39
- :top => 36,
40
- :bottom => 36 }
44
+ @pdf.page.margins.should == { :left => 0,
45
+ :right => 0,
46
+ :top => 36,
47
+ :bottom => 36 }
48
+
41
49
 
42
50
 
43
-
44
51
  end
45
52
 
46
53
  it "should not add an extra restore_graphics_state operator to the end of any content stream" do
@@ -57,9 +64,9 @@ describe "Document built from a template" do
57
64
  data.include?("QQ").should == false
58
65
  end
59
66
  end
60
-
67
+
61
68
  it "should have a single page object if importing a single page template" do
62
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
69
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
63
70
 
64
71
  @pdf = Prawn::Document.new(:template => filename)
65
72
  output = StringIO.new(@pdf.render)
@@ -71,7 +78,7 @@ describe "Document built from a template" do
71
78
  end
72
79
 
73
80
  it "should have two content streams if importing a single page template" do
74
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
81
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
75
82
 
76
83
  @pdf = Prawn::Document.new(:template => filename)
77
84
  output = StringIO.new(@pdf.render)
@@ -83,16 +90,16 @@ describe "Document built from a template" do
83
90
  end
84
91
 
85
92
  it "should not die if using this PDF as a template" do
86
- filename = "#{Prawn::BASEDIR}/data/pdfs/complex_template.pdf"
93
+ filename = "#{Prawn::DATADIR}/pdfs/complex_template.pdf"
87
94
 
88
- assert_nothing_raised do
95
+ lambda {
89
96
  @pdf = Prawn::Document.new(:template => filename)
90
- end
97
+ }.should_not raise_error
91
98
  end
92
99
 
93
100
 
94
101
  it "should have balance q/Q operators on all content streams" do
95
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
102
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
96
103
 
97
104
  @pdf = Prawn::Document.new(:template => filename)
98
105
  output = StringIO.new(@pdf.render)
@@ -108,7 +115,7 @@ describe "Document built from a template" do
108
115
  end
109
116
 
110
117
  it "should allow text to be added to a single page template" do
111
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
118
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
112
119
 
113
120
  @pdf = Prawn::Document.new(:template => filename)
114
121
 
@@ -119,7 +126,7 @@ describe "Document built from a template" do
119
126
  end
120
127
 
121
128
  it "should allow PDFs with page resources behind an indirect object to be used as templates" do
122
- filename = "#{Prawn::BASEDIR}/data/pdfs/resources_as_indirect_object.pdf"
129
+ filename = "#{Prawn::DATADIR}/pdfs/resources_as_indirect_object.pdf"
123
130
 
124
131
  @pdf = Prawn::Document.new(:template => filename)
125
132
 
@@ -131,7 +138,7 @@ describe "Document built from a template" do
131
138
  end
132
139
 
133
140
  it "should copy the PDF version from the template file" do
134
- filename = "#{Prawn::BASEDIR}/data/pdfs/version_1_6.pdf"
141
+ filename = "#{Prawn::DATADIR}/pdfs/version_1_6.pdf"
135
142
 
136
143
  @pdf = Prawn::Document.new(:template => filename)
137
144
  str = @pdf.render
@@ -139,9 +146,9 @@ describe "Document built from a template" do
139
146
  end
140
147
 
141
148
  it "should correctly add a TTF font to a template that has existing fonts" do
142
- filename = "#{Prawn::BASEDIR}/data/pdfs/contains_ttf_font.pdf"
149
+ filename = "#{Prawn::DATADIR}/pdfs/contains_ttf_font.pdf"
143
150
  @pdf = Prawn::Document.new(:template => filename)
144
- @pdf.font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
151
+ @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
145
152
  @pdf.move_down(40)
146
153
  @pdf.text "Hi There"
147
154
 
@@ -155,51 +162,74 @@ describe "Document built from a template" do
155
162
  end
156
163
 
157
164
  it "should correctly import a template file that is missing a MediaBox entry" do
158
- filename = "#{Prawn::BASEDIR}/data/pdfs/page_without_mediabox.pdf"
165
+ filename = "#{Prawn::DATADIR}/pdfs/page_without_mediabox.pdf"
159
166
 
160
167
  @pdf = Prawn::Document.new(:template => filename)
161
168
  str = @pdf.render
162
169
  str[0,4].should == "%PDF"
163
170
  end
164
171
 
172
+ context "with the template as a stream" do
173
+ it "should correctly import a template file from a stream" do
174
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
175
+ io = StringIO.new(File.binread(filename))
176
+ @pdf = Prawn::Document.new(:template => io)
177
+ str = @pdf.render
178
+ str[0,4].should == "%PDF"
179
+ end
180
+ end
181
+
182
+ it "merges metadata info" do
183
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
184
+ info = { :Title => "Sample METADATA",
185
+ :Author => "Me",
186
+ :Subject => "Not Working",
187
+ :CreationDate => Time.now }
188
+
189
+ @pdf = Prawn::Document.new(:template => filename, :info => info)
190
+ output = StringIO.new(@pdf.render)
191
+ hash = PDF::Reader::ObjectHash.new(output)
192
+ info.keys.each { |k| hash[hash.trailer[:Info]].keys.include?(k).should == true }
193
+ end
194
+
165
195
  end
166
196
 
167
197
  describe "Document#start_new_page with :template option" do
168
198
  filename = "#{Prawn::BASEDIR}/spec/data/curves.pdf"
169
-
199
+
170
200
  it "should set the imported page's parent to the document pages catalog" do
171
201
  @pdf = Prawn::Document.new()
172
202
  @pdf.start_new_page(:template => filename)
173
203
  @pdf.state.page.dictionary.data[:Parent].should == @pdf.state.store.pages
174
204
  end
175
-
205
+
176
206
  it "should set start the Y cursor at the top of the page" do
177
207
  @pdf = Prawn::Document.new()
178
208
  @pdf.start_new_page(:template => filename)
179
209
  (@pdf.y == nil).should == false
180
210
  end
181
-
211
+
182
212
  it "should respect margins set by Prawn" do
183
213
  @pdf = Prawn::Document.new(:margin => 0)
184
214
  @pdf.start_new_page(:template => filename)
185
- assert_equal @pdf.page.margins, { :left => 0,
186
- :right => 0,
187
- :top => 0,
188
- :bottom => 0 }
215
+ @pdf.page.margins.should == { :left => 0,
216
+ :right => 0,
217
+ :top => 0,
218
+ :bottom => 0 }
189
219
 
190
220
  @pdf = Prawn::Document.new(:left_margin => 0)
191
221
  @pdf.start_new_page(:template => filename)
192
- assert_equal @pdf.page.margins, { :left => 0,
193
- :right => 36,
194
- :top => 36,
195
- :bottom => 36 }
222
+ @pdf.page.margins.should == { :left => 0,
223
+ :right => 36,
224
+ :top => 36,
225
+ :bottom => 36 }
196
226
  @pdf.start_new_page(:template => filename, :right_margin => 0)
197
- assert_equal @pdf.page.margins, { :left => 0,
198
- :right => 0,
199
- :top => 36,
200
- :bottom => 36 }
227
+ @pdf.page.margins.should == { :left => 0,
228
+ :right => 0,
229
+ :top => 36,
230
+ :bottom => 36 }
201
231
  end
202
-
232
+
203
233
  it "should not add an extra restore_graphics_state operator to the end of any content stream" do
204
234
  @pdf = Prawn::Document.new
205
235
  @pdf.start_new_page(:template => filename)
@@ -213,9 +243,9 @@ describe "Document#start_new_page with :template option" do
213
243
  data.include?("QQ").should == false
214
244
  end
215
245
  end
216
-
246
+
217
247
  it "should have two content streams if importing a single page template" do
218
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
248
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
219
249
  @pdf = Prawn::Document.new()
220
250
  @pdf.start_new_page(:template => filename)
221
251
  output = StringIO.new(@pdf.render)
@@ -224,9 +254,9 @@ describe "Document#start_new_page with :template option" do
224
254
  template_page = hash[pages[1]]
225
255
  template_page[:Contents].size.should == 2
226
256
  end
227
-
257
+
228
258
  it "should have balance q/Q operators on all content streams" do
229
- filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"
259
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
230
260
 
231
261
  @pdf = Prawn::Document.new()
232
262
  @pdf.start_new_page(:template => filename)
@@ -241,7 +271,7 @@ describe "Document#start_new_page with :template option" do
241
271
  data.scan("Q").size.should == 1
242
272
  end
243
273
  end
244
-
274
+
245
275
  it "should allow text to be added to a single page template" do
246
276
 
247
277
  @pdf = Prawn::Document.new()
@@ -252,9 +282,9 @@ describe "Document#start_new_page with :template option" do
252
282
  text = PDF::Inspector::Text.analyze(@pdf.render)
253
283
  text.strings.first.should == "Adding some text"
254
284
  end
255
-
285
+
256
286
  it "should allow PDFs with page resources behind an indirect object to be used as templates" do
257
- filename = "#{Prawn::BASEDIR}/data/pdfs/resources_as_indirect_object.pdf"
287
+ filename = "#{Prawn::DATADIR}/pdfs/resources_as_indirect_object.pdf"
258
288
 
259
289
  @pdf = Prawn::Document.new()
260
290
  @pdf.start_new_page(:template => filename)
@@ -265,12 +295,12 @@ describe "Document#start_new_page with :template option" do
265
295
  all_text = text.strings.join
266
296
  all_text.include?("Adding some text").should == true
267
297
  end
268
-
298
+
269
299
  it "should correctly add a TTF font to a template that has existing fonts" do
270
- filename = "#{Prawn::BASEDIR}/data/pdfs/contains_ttf_font.pdf"
300
+ filename = "#{Prawn::DATADIR}/pdfs/contains_ttf_font.pdf"
271
301
  @pdf = Prawn::Document.new()
272
302
  @pdf.start_new_page(:template => filename)
273
- @pdf.font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
303
+ @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
274
304
  @pdf.move_down(40)
275
305
  @pdf.text "Hi There"
276
306
 
@@ -283,10 +313,34 @@ describe "Document#start_new_page with :template option" do
283
313
  fonts = resources[:Font]
284
314
  fonts.size.should == 2
285
315
  end
286
-
316
+
317
+ it "indexes template pages when used multiple times" do
318
+ filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf"
319
+ @repeated_pdf = Prawn::Document.new()
320
+ 3.times { @repeated_pdf.start_new_page(:template => filename) }
321
+ repeated_hash = PDF::Reader::ObjectHash.new(StringIO.new(@repeated_pdf.render))
322
+ @sequential_pdf = Prawn::Document.new()
323
+ (1..3).each { |p| @sequential_pdf.start_new_page(:template => filename, :template_page => p ) }
324
+ sequential_hash = PDF::Reader::ObjectHash.new(StringIO.new(@sequential_pdf.render))
325
+ (repeated_hash.size < sequential_hash.size).should == true
326
+ end
327
+
328
+ context "with the template as a stream" do
329
+ it "should correctly import a template file from a stream" do
330
+ filename = "#{Prawn::DATADIR}/pdfs/hexagon.pdf"
331
+ io = StringIO.new(File.binread(filename))
332
+
333
+ @pdf = Prawn::Document.new()
334
+ @pdf.start_new_page(:template => io)
335
+
336
+ str = @pdf.render
337
+ str[0,4].should == "%PDF"
338
+ end
339
+ end
340
+
287
341
  context "using template_page option" do
288
342
  it "uses the specified page option" do
289
- filename = "#{Prawn::BASEDIR}/data/pdfs/multipage_template.pdf"
343
+ filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf"
290
344
  @pdf = Prawn::Document.new()
291
345
  @pdf.start_new_page(:template => filename, :template_page => 2)
292
346
  text = PDF::Inspector::Text.analyze(@pdf.render)
@@ -5,12 +5,12 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
  describe "#draw_text" do
6
6
  before(:each) { create_pdf }
7
7
 
8
- it "should raise ArgumentError if :at option omitted" do
9
- lambda { @pdf.draw_text("hai", { }) }.should.raise(ArgumentError)
8
+ it "should raise_error ArgumentError if :at option omitted" do
9
+ lambda { @pdf.draw_text("hai", { }) }.should raise_error(ArgumentError)
10
10
  end
11
11
 
12
- it "should raise ArgumentError if :align option included" do
13
- lambda { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.should.raise(ArgumentError)
12
+ it "should raise_error ArgumentError if :align option included" do
13
+ lambda { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.should raise_error(ArgumentError)
14
14
  end
15
15
 
16
16
  it "should allow drawing empty strings to the page" do
@@ -85,8 +85,8 @@ describe "#draw_text" do
85
85
  text.font_settings[1][:name].should == :Courier
86
86
  end
87
87
 
88
- it "should raise an exception when an unknown font is used" do
89
- lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont)
88
+ it "should raise_error an exception when an unknown font is used" do
89
+ lambda { @pdf.font "Pao bu" }.should raise_error(Prawn::Errors::UnknownFont)
90
90
  end
91
91
 
92
92
  it "should correctly render a utf-8 string when using a built-in font" do
@@ -100,29 +100,30 @@ describe "#draw_text" do
100
100
 
101
101
  if "spec".respond_to?(:encode!)
102
102
  # Handle non utf-8 string encodings in a sane way on M17N aware VMs
103
- it "should raise an exception when a utf-8 incompatible string is rendered" do
103
+ it "should raise_error an exception when a utf-8 incompatible string is rendered" do
104
104
  str = "Blah \xDD"
105
105
  str.force_encoding("ASCII-8BIT")
106
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(
106
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
107
107
  Prawn::Errors::IncompatibleStringEncoding)
108
108
  end
109
+
109
110
  it "should not raise an exception when a shift-jis string is rendered" do
110
- datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
111
+ datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
111
112
  sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
112
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
113
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.not.raise(
114
- Prawn::Errors::IncompatibleStringEncoding)
113
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
114
+
115
+ @pdf.draw_text(sjis_str, :at => [0, 0])
115
116
  end
116
117
  else
117
118
  # Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
118
- it "should raise an exception when a corrupt utf-8 string is rendered" do
119
+ it "should raise_error an exception when a corrupt utf-8 string is rendered" do
119
120
  str = "Blah \xDD"
120
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(
121
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
121
122
  Prawn::Errors::IncompatibleStringEncoding)
122
123
  end
123
- it "should raise an exception when a shift-jis string is rendered" do
124
- sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
125
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.raise(
124
+ it "should raise_error an exception when a shift-jis string is rendered" do
125
+ sjis_str = File.read("#{Prawn::DATADIR}/shift_jis_text.txt")
126
+ lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should raise_error(
126
127
  Prawn::Errors::IncompatibleStringEncoding)
127
128
  end
128
129
  end
@@ -3,55 +3,55 @@
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
 
5
5
  describe "Text::Box#nothing_printed?" do
6
- it "should be true when nothing printed" do
6
+ it "should be_true when nothing printed" do
7
7
  create_pdf
8
8
  string = "Hello world, how are you?\nI'm fine, thank you."
9
9
  text_box = Prawn::Text::Box.new(string,
10
10
  :height => 2,
11
11
  :document => @pdf)
12
12
  text_box.render
13
- text_box.nothing_printed?.should.be true
13
+ text_box.nothing_printed?.should be_true
14
14
  end
15
- it "should be false when something printed" do
15
+ it "should be_false when something printed" do
16
16
  create_pdf
17
17
  string = "Hello world, how are you?\nI'm fine, thank you."
18
18
  text_box = Prawn::Text::Box.new(string,
19
19
  :height => 14,
20
20
  :document => @pdf)
21
21
  text_box.render
22
- text_box.nothing_printed?.should.be false
22
+ text_box.nothing_printed?.should be_false
23
23
  end
24
24
  end
25
25
 
26
26
  describe "Text::Box#everything_printed?" do
27
- it "should be false when not everything printed" do
27
+ it "should be_false when not everything printed" do
28
28
  create_pdf
29
29
  string = "Hello world, how are you?\nI'm fine, thank you."
30
30
  text_box = Prawn::Text::Box.new(string,
31
31
  :height => 14,
32
32
  :document => @pdf)
33
33
  text_box.render
34
- text_box.everything_printed?.should.be false
34
+ text_box.everything_printed?.should be_false
35
35
  end
36
- it "should be true when everything printed" do
36
+ it "should be_true when everything printed" do
37
37
  create_pdf
38
38
  string = "Hello world, how are you?\nI'm fine, thank you."
39
39
  text_box = Prawn::Text::Box.new(string,
40
40
  :document => @pdf)
41
41
  text_box.render
42
- text_box.everything_printed?.should.be true
42
+ text_box.everything_printed?.should be_true
43
43
  end
44
44
  end
45
45
 
46
46
  describe "Text::Box#line_gap" do
47
- it "should equal the line gap of the font when using a single " +
47
+ it "should == the line gap of the font when using a single " +
48
48
  "font and font size" do
49
49
  create_pdf
50
50
  string = "Hello world, how are you?\nI'm fine, thank you."
51
51
  text_box = Prawn::Text::Box.new(string,
52
52
  :document => @pdf)
53
53
  text_box.render
54
- text_box.line_gap.should.be.close(@pdf.font.line_gap, 0.0001)
54
+ text_box.line_gap.should be_within(0.0001).of(@pdf.font.line_gap)
55
55
  end
56
56
  end
57
57
 
@@ -74,7 +74,7 @@ describe "Text::Box" do
74
74
  @pdf.text_direction(:rtl)
75
75
  @pdf.text_direction = :rtl
76
76
  @pdf.text_direction = :rtl
77
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", :size => 16) do
77
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
78
78
  @pdf.text "写个小"
79
79
  end
80
80
  text = PDF::Inspector::Text.analyze(@pdf.render)
@@ -116,7 +116,7 @@ describe "Text::Box" do
116
116
  end
117
117
  it "should default to document-wide leading if no" +
118
118
  "leading option is provided" do
119
-
119
+
120
120
  end
121
121
  end
122
122
 
@@ -128,7 +128,7 @@ describe "Text::Box#render with :align => :justify" do
128
128
  text_box = Prawn::Text::Box.new(string, options)
129
129
  text_box.render
130
130
  contents = PDF::Inspector::Text.analyze(@pdf.render)
131
- contents.word_spacing[0].should.be > 0
131
+ contents.word_spacing[0].should be > 0
132
132
  end
133
133
  it "should not justify the last line of a paragraph" do
134
134
  create_pdf
@@ -137,7 +137,7 @@ describe "Text::Box#render with :align => :justify" do
137
137
  text_box = Prawn::Text::Box.new(string, options)
138
138
  text_box.render
139
139
  contents = PDF::Inspector::Text.analyze(@pdf.render)
140
- contents.word_spacing.should.be.empty
140
+ contents.word_spacing.should be_empty
141
141
  end
142
142
  end
143
143
 
@@ -160,19 +160,19 @@ describe "Text::Box" do
160
160
  end
161
161
 
162
162
  describe "Text::Box#height without leading" do
163
- it "should equal the sum of the height of each line, " +
163
+ it "should == the sum of the height of each line, " +
164
164
  "not including the space below the last line" do
165
165
  create_pdf
166
166
  text = "Oh hai text rect.\nOh hai text rect."
167
167
  options = { :document => @pdf }
168
168
  text_box = Prawn::Text::Box.new(text, options)
169
169
  text_box.render
170
- text_box.height.should.be.close(@pdf.font.height * 2 - @pdf.font.line_gap, 0.001)
170
+ text_box.height.should be_within(0.001).of(@pdf.font.height * 2 - @pdf.font.line_gap)
171
171
  end
172
172
  end
173
173
 
174
174
  describe "Text::Box#height with leading" do
175
- it "should equal the sum of the height of each line plus leading, " +
175
+ it "should == the sum of the height of each line plus leading, " +
176
176
  "but not including the space below the last line" do
177
177
  create_pdf
178
178
  text = "Oh hai text rect.\nOh hai text rect."
@@ -180,7 +180,38 @@ describe "Text::Box#height with leading" do
180
180
  options = { :document => @pdf, :leading => leading }
181
181
  text_box = Prawn::Text::Box.new(text, options)
182
182
  text_box.render
183
- text_box.height.should.be.close((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading, 0.001)
183
+ text_box.height.should be_within(0.001).of((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading)
184
+ end
185
+ end
186
+
187
+ describe "Text::Box with :draw_text_callback" do
188
+ before(:each) { create_pdf }
189
+
190
+ it "hits the callback whenever text is drawn" do
191
+ draw_block = stub()
192
+ draw_block.expects(:kick).with("this text is long enough to")
193
+ draw_block.expects(:kick).with("span two lines")
194
+
195
+ @pdf.text_box "this text is long enough to span two lines",
196
+ :width => 150,
197
+ :draw_text_callback => lambda { |text, _| draw_block.kick(text) }
198
+ end
199
+
200
+ it "hits the callback once per fragment for :inline_format" do
201
+ draw_block = stub()
202
+ draw_block.expects(:kick).with("this text has ")
203
+ draw_block.expects(:kick).with("fancy")
204
+ draw_block.expects(:kick).with(" formatting")
205
+
206
+ @pdf.text_box "this text has <b>fancy</b> formatting",
207
+ :inline_format => true, :width => 500,
208
+ :draw_text_callback => lambda { |text, _| draw_block.kick(text) }
209
+ end
210
+
211
+ it "does not call #draw_text!" do
212
+ @pdf.expects(:draw_text!).never
213
+ @pdf.text_box "some text", :width => 500,
214
+ :draw_text_callback => lambda { |_, _| }
184
215
  end
185
216
  end
186
217
 
@@ -188,7 +219,7 @@ describe "Text::Box#valid_options" do
188
219
  it "should return an array" do
189
220
  create_pdf
190
221
  text_box = Prawn::Text::Box.new("", :document => @pdf)
191
- text_box.valid_options.should.be.kind_of(Array)
222
+ text_box.valid_options.should be_a_kind_of(Array)
192
223
  end
193
224
  end
194
225
 
@@ -211,7 +242,7 @@ describe "Text::Box#render" do
211
242
  text_box = Prawn::Text::Box.new(@text, @options)
212
243
  text_box.render
213
244
  text = PDF::Inspector::Text.analyze(@pdf.render)
214
- text.strings.should.not.be.empty
245
+ text.strings.should_not be_empty
215
246
  end
216
247
  it "should not draw a transformation matrix" do
217
248
  create_pdf
@@ -245,16 +276,17 @@ describe "Text::Box#render(:dry_run => true)" do
245
276
  text_box = Prawn::Text::Box.new(@text, @options)
246
277
  text_box.render(:dry_run => true)
247
278
  text = PDF::Inspector::Text.analyze(@pdf.render)
248
- text.strings.should.be.empty
279
+ text.strings.should be_empty
249
280
  end
250
- it "subsequent calls to render should not raise an ArgumentError exception" do
281
+
282
+ it "subsequent calls to render should_not raise_error an ArgumentError exception" do
251
283
  create_pdf
252
284
  @text = "™©"
253
285
  @options = { :document => @pdf }
254
286
  text_box = Prawn::Text::Box.new(@text, @options)
255
287
  text_box.render(:dry_run => true)
256
- lambda { text_box.render }.should.not.raise(
257
- Prawn::Errors::IncompatibleStringEncoding)
288
+
289
+ text_box.render
258
290
  end
259
291
  end
260
292
 
@@ -275,6 +307,23 @@ describe "Text::Box#render(:valign => :bottom)" do
275
307
  end
276
308
  end
277
309
 
310
+ describe "Text::Box#render(:valign => :center)" do
311
+ it "#at should be the same from one dry run to the next" do
312
+ create_pdf
313
+ text = "this is center text " * 12
314
+ options = { :width => 162,
315
+ :valign => :center,
316
+ :document => @pdf }
317
+ text_box = Prawn::Text::Box.new(text, options)
318
+
319
+ text_box.render(:dry_run => true)
320
+ original_at = text_box.at.dup
321
+
322
+ text_box.render(:dry_run => true)
323
+ text_box.at.should == original_at
324
+ end
325
+ end
326
+
278
327
  describe "Text::Box#render with :rotate option of 30)" do
279
328
  before(:each) do
280
329
  create_pdf
@@ -312,7 +361,7 @@ describe "Text::Box#render with :rotate option of 30)" do
312
361
  reduce_precision(@cos), 0, 0]
313
362
 
314
363
  text = PDF::Inspector::Text.analyze(@pdf.render)
315
- text.strings.should.not.be.empty
364
+ text.strings.should_not be_empty
316
365
  end
317
366
  end
318
367
  context ":rotate_around option of :upper_left" do
@@ -335,7 +384,7 @@ describe "Text::Box#render with :rotate option of 30)" do
335
384
  reduce_precision(@cos), 0, 0]
336
385
 
337
386
  text = PDF::Inspector::Text.analyze(@pdf.render)
338
- text.strings.should.not.be.empty
387
+ text.strings.should_not be_empty
339
388
  end
340
389
  end
341
390
  context "default :rotate_around" do
@@ -357,7 +406,7 @@ describe "Text::Box#render with :rotate option of 30)" do
357
406
  reduce_precision(@cos), 0, 0]
358
407
 
359
408
  text = PDF::Inspector::Text.analyze(@pdf.render)
360
- text.strings.should.not.be.empty
409
+ text.strings.should_not be_empty
361
410
  end
362
411
  end
363
412
  context ":rotate_around option of :upper_right" do
@@ -380,7 +429,7 @@ describe "Text::Box#render with :rotate option of 30)" do
380
429
  reduce_precision(@cos), 0, 0]
381
430
 
382
431
  text = PDF::Inspector::Text.analyze(@pdf.render)
383
- text.strings.should.not.be.empty
432
+ text.strings.should_not be_empty
384
433
  end
385
434
  end
386
435
  context ":rotate_around option of :lower_right" do
@@ -403,7 +452,7 @@ describe "Text::Box#render with :rotate option of 30)" do
403
452
  reduce_precision(@cos), 0, 0]
404
453
 
405
454
  text = PDF::Inspector::Text.analyze(@pdf.render)
406
- text.strings.should.not.be.empty
455
+ text.strings.should_not be_empty
407
456
  end
408
457
  end
409
458
  context ":rotate_around option of :lower_left" do
@@ -426,7 +475,7 @@ describe "Text::Box#render with :rotate option of 30)" do
426
475
  reduce_precision(@cos), 0, 0]
427
476
 
428
477
  text = PDF::Inspector::Text.analyze(@pdf.render)
429
- text.strings.should.not.be.empty
478
+ text.strings.should_not be_empty
430
479
  end
431
480
  end
432
481
  end
@@ -439,7 +488,7 @@ describe "Text::Box default height" do
439
488
  @text = "Oh hai\n" * 60
440
489
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
441
490
  text_box.render
442
- text_box.height.should.be.close(target_height, @pdf.font.height)
491
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
443
492
  end
444
493
 
445
494
  it "should use the margin-box bottom if only in a stretchy bbox" do
@@ -448,7 +497,7 @@ describe "Text::Box default height" do
448
497
  @text = "Oh hai\n" * 60
449
498
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
450
499
  text_box.render
451
- text_box.height.should.be.close(target_height, @pdf.font.height)
500
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
452
501
  end
453
502
  end
454
503
 
@@ -460,7 +509,7 @@ describe "Text::Box default height" do
460
509
  text_box = Prawn::Text::Box.new(@text, :document => @pdf,
461
510
  :height => 100, :overflow => :expand)
462
511
  text_box.render
463
- text_box.height.should.be.close(target_height, @pdf.font.height)
512
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
464
513
  end
465
514
  end
466
515
 
@@ -471,7 +520,7 @@ describe "Text::Box default height" do
471
520
  @text = "Oh hai\n" * 60
472
521
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
473
522
  text_box.render
474
- text_box.height.should.be.close(200, @pdf.font.height)
523
+ text_box.height.should be_within(@pdf.font.height).of(200)
475
524
  end
476
525
  end
477
526
  end
@@ -500,7 +549,7 @@ describe "Text::Box with text than can fit in the box" do
500
549
  :document => @pdf
501
550
  }
502
551
  end
503
-
552
+
504
553
  it "printed text should match requested text, except that preceding and " +
505
554
  "trailing white space will be stripped from each line, and newlines may " +
506
555
  "be inserted" do
@@ -508,7 +557,7 @@ describe "Text::Box with text than can fit in the box" do
508
557
  text_box.render
509
558
  text_box.text.gsub("\n", " ").should == @text.strip
510
559
  end
511
-
560
+
512
561
  it "render should return an empty string because no text remains unprinted" do
513
562
  text_box = Prawn::Text::Box.new(@text, @options)
514
563
  text_box.render.should == ""
@@ -518,7 +567,7 @@ describe "Text::Box with text than can fit in the box" do
518
567
  @options[:leading] = 40
519
568
  text_box = Prawn::Text::Box.new(@text, @options)
520
569
  text_box.render
521
- text_box.text.gsub("\n", " ").should.not == @text.strip
570
+ text_box.text.gsub("\n", " ").should_not == @text.strip
522
571
  end
523
572
  end
524
573
 
@@ -534,12 +583,12 @@ describe "Text::Box with text that fits exactly in the box" do
534
583
  :document => @pdf
535
584
  }
536
585
  end
537
-
586
+
538
587
  it "should have the expected height" do
539
588
  expected_height = @options.delete(:height)
540
589
  text_box = Prawn::Text::Box.new(@text, @options)
541
590
  text_box.render
542
- text_box.height.should.be.close(expected_height, 0.0001)
591
+ text_box.height.should be_within(0.0001).of(expected_height)
543
592
  end
544
593
 
545
594
  it "should print everything" do
@@ -564,7 +613,7 @@ describe "Text::Box with text that fits exactly in the box" do
564
613
  @options[:height] += @options[:leading] * @interlines - 1
565
614
  text_box = Prawn::Text::Box.new(@text, @options)
566
615
  text_box.render
567
- text_box.text.should.not == @text
616
+ text_box.text.should_not == @text
568
617
  end
569
618
  end
570
619
 
@@ -584,14 +633,14 @@ describe "Text::Box with text that fits exactly in the box" do
584
633
  @options[:height] += @options[:leading] * @interlines - 1
585
634
  text_box = Prawn::Text::Box.new(@text, @options)
586
635
  text_box.render
587
- text_box.text.should.not == @text
636
+ text_box.text.should_not == @text
588
637
  end
589
638
  end
590
639
  end
591
640
 
592
641
  describe "Text::Box printing UTF-8 string with higher bit characters" do
593
642
  before(:each) do
594
- create_pdf
643
+ create_pdf
595
644
  @text = "©"
596
645
  # not enough height to print any text, so we can directly compare against
597
646
  # the input string
@@ -600,7 +649,7 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
600
649
  :height => bounding_height,
601
650
  :document => @pdf
602
651
  }
603
- file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
652
+ file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
604
653
  @pdf.font_families["Action Man"] = {
605
654
  :normal => { :file => file, :font => "ActionMan" },
606
655
  :italic => { :file => file, :font => "ActionMan-Italic" },
@@ -615,13 +664,14 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
615
664
  remaining_text = @text_box.render
616
665
  remaining_text.should == @text
617
666
  end
667
+
618
668
  it "subsequent calls to Text::Box need not include the" +
619
669
  " :skip_encoding => true option" do
620
670
  @pdf.font("Action Man")
621
671
  remaining_text = @text_box.render
622
- lambda {
623
- @pdf.text_box(remaining_text, :document => @pdf)
624
- }.should.not.raise(Prawn::Errors::IncompatibleStringEncoding)
672
+
673
+ # expect that calling text_box will not raise an encoding error
674
+ @pdf.text_box(remaining_text, :document => @pdf)
625
675
  end
626
676
  end
627
677
 
@@ -635,18 +685,17 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
635
685
  remaining_text = @text_box.render
636
686
  lambda {
637
687
  @pdf.text_box(remaining_text, :document => @pdf)
638
- }.should.raise(Prawn::Errors::IncompatibleStringEncoding)
639
- lambda {
640
- @pdf.text_box(remaining_text, :skip_encoding => true,
641
- :document => @pdf)
642
- }.should.not.raise(Prawn::Errors::IncompatibleStringEncoding)
688
+ }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
689
+
690
+ @pdf.text_box(remaining_text, :skip_encoding => true,
691
+ :document => @pdf)
643
692
  end
644
693
  end
645
694
  end
646
695
 
647
696
  describe "Text::Box with more text than can fit in the box" do
648
697
  before(:each) do
649
- create_pdf
698
+ create_pdf
650
699
  @text = "Oh hai text rect. " * 30
651
700
  @bounding_height = 162.0
652
701
  @options = {
@@ -655,7 +704,7 @@ describe "Text::Box with more text than can fit in the box" do
655
704
  :document => @pdf
656
705
  }
657
706
  end
658
-
707
+
659
708
  context "truncated overflow" do
660
709
  before(:each) do
661
710
  @options[:overflow] = :truncate
@@ -663,18 +712,18 @@ describe "Text::Box with more text than can fit in the box" do
663
712
  end
664
713
  it "should be truncated" do
665
714
  @text_box.render
666
- @text_box.text.gsub("\n", " ").should.not == @text.strip
715
+ @text_box.text.gsub("\n", " ").should_not == @text.strip
667
716
  end
668
717
  it "render should not return an empty string because some text remains unprinted" do
669
- @text_box.render.should.not.be.empty
718
+ @text_box.render.should_not be_empty
670
719
  end
671
720
  it "#height should be no taller than the specified height" do
672
721
  @text_box.render
673
- @text_box.height.should.be <= @bounding_height
722
+ @text_box.height.should be <= @bounding_height
674
723
  end
675
724
  it "#height should be within one font height of the specified height" do
676
725
  @text_box.render
677
- @bounding_height.should.be.close(@text_box.height, @pdf.font.height)
726
+ @bounding_height.should be_within(@pdf.font.height).of(@text_box.height)
678
727
  end
679
728
  context "with :rotate option" do
680
729
  it "unrendered text should be the same as when not rotated" do
@@ -693,7 +742,7 @@ describe "Text::Box with more text than can fit in the box" do
693
742
  end
694
743
  end
695
744
  end
696
-
745
+
697
746
  context "truncated with text and size taken from the manual" do
698
747
  it "should return the right text" do
699
748
  @text = "This is the beginning of the text. It will be cut somewhere and " +
@@ -783,7 +832,7 @@ describe "Text::Box with a solid block of Chinese characters" do
783
832
  :height => 162.0,
784
833
  :document => @pdf
785
834
  }
786
- @pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
835
+ @pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
787
836
  @options[:overflow] = :truncate
788
837
  text_box = Prawn::Text::Box.new(@text, @options)
789
838
  text_box.render
@@ -792,8 +841,8 @@ describe "Text::Box with a solid block of Chinese characters" do
792
841
  end
793
842
 
794
843
 
795
- describe "drawing bounding boxes" do
796
- before(:each) { create_pdf }
844
+ describe "drawing bounding boxes" do
845
+ before(:each) { create_pdf }
797
846
 
798
847
  it "should restore the margin box when bounding box exits" do
799
848
  margin_box = @pdf.bounds
@@ -828,7 +877,7 @@ describe "Text::Box#render with :character_spacing option" do
828
877
  text_box.text.should == "hello\nworld"
829
878
  end
830
879
  end
831
-
880
+
832
881
  describe "Text::Box wrapping" do
833
882
  before(:each) do
834
883
  create_pdf