prawn 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/Gemfile +18 -0
  2. data/README.md +5 -3
  3. data/Rakefile +8 -14
  4. data/data/pdfs/nested_pages.pdf +13 -13
  5. data/lib/prawn.rb +3 -1
  6. data/lib/prawn/compatibility.rb +46 -10
  7. data/lib/prawn/core.rb +3 -1
  8. data/lib/prawn/core/document_state.rb +2 -1
  9. data/lib/prawn/core/object_store.rb +61 -5
  10. data/lib/prawn/core/page.rb +3 -6
  11. data/lib/prawn/core/pdf_object.rb +21 -4
  12. data/lib/prawn/core/reference.rb +6 -2
  13. data/lib/prawn/core/text.rb +4 -4
  14. data/lib/prawn/core/text/formatted/line_wrap.rb +23 -8
  15. data/lib/prawn/document.rb +21 -15
  16. data/lib/prawn/document/bounding_box.rb +3 -3
  17. data/lib/prawn/document/column_box.rb +22 -4
  18. data/lib/prawn/document/snapshot.rb +1 -1
  19. data/lib/prawn/encoding.rb +1 -1
  20. data/lib/prawn/errors.rb +4 -0
  21. data/lib/prawn/font.rb +1 -1
  22. data/lib/prawn/font/afm.rb +30 -72
  23. data/lib/prawn/font/ttf.rb +6 -33
  24. data/lib/prawn/graphics.rb +148 -23
  25. data/lib/prawn/graphics/color.rb +8 -1
  26. data/lib/prawn/graphics/patterns.rb +137 -0
  27. data/lib/prawn/images.rb +25 -19
  28. data/lib/prawn/images/jpg.rb +4 -4
  29. data/lib/prawn/images/png.rb +18 -12
  30. data/lib/prawn/security.rb +6 -4
  31. data/lib/prawn/soft_mask.rb +94 -0
  32. data/lib/prawn/table.rb +136 -31
  33. data/lib/prawn/table/cell.rb +260 -29
  34. data/lib/prawn/table/cell/span_dummy.rb +88 -0
  35. data/lib/prawn/table/cell/text.rb +36 -14
  36. data/lib/prawn/table/cells.rb +91 -41
  37. data/lib/prawn/text.rb +3 -2
  38. data/lib/prawn/text/formatted/box.rb +14 -5
  39. data/lib/prawn/text/formatted/fragment.rb +33 -22
  40. data/lib/prawn/text/formatted/parser.rb +5 -2
  41. data/lib/prawn/utilities.rb +44 -0
  42. data/manual/basic_concepts/adding_pages.rb +27 -0
  43. data/manual/basic_concepts/basic_concepts.rb +34 -0
  44. data/manual/basic_concepts/creation.rb +39 -0
  45. data/manual/basic_concepts/cursor.rb +33 -0
  46. data/manual/basic_concepts/measurement.rb +25 -0
  47. data/manual/basic_concepts/origin.rb +38 -0
  48. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  49. data/manual/bounding_box/bounding_box.rb +39 -0
  50. data/manual/bounding_box/bounds.rb +49 -0
  51. data/manual/bounding_box/canvas.rb +24 -0
  52. data/manual/bounding_box/creation.rb +23 -0
  53. data/manual/bounding_box/indentation.rb +46 -0
  54. data/manual/bounding_box/nesting.rb +45 -0
  55. data/manual/bounding_box/russian_boxes.rb +40 -0
  56. data/manual/bounding_box/stretchy.rb +31 -0
  57. data/manual/document_and_page_options/background.rb +27 -0
  58. data/manual/document_and_page_options/document_and_page_options.rb +31 -0
  59. data/manual/document_and_page_options/metadata.rb +23 -0
  60. data/manual/document_and_page_options/page_margins.rb +38 -0
  61. data/manual/document_and_page_options/page_size.rb +34 -0
  62. data/manual/example_file.rb +116 -0
  63. data/manual/example_helper.rb +430 -0
  64. data/manual/example_package.rb +53 -0
  65. data/manual/example_section.rb +46 -0
  66. data/manual/graphics/circle_and_ellipse.rb +22 -0
  67. data/manual/graphics/color.rb +24 -0
  68. data/manual/graphics/common_lines.rb +28 -0
  69. data/manual/graphics/fill_and_stroke.rb +42 -0
  70. data/manual/graphics/fill_rules.rb +37 -0
  71. data/manual/graphics/gradients.rb +37 -0
  72. data/manual/graphics/graphics.rb +58 -0
  73. data/manual/graphics/helper.rb +17 -0
  74. data/manual/graphics/line_width.rb +35 -0
  75. data/manual/graphics/lines_and_curves.rb +41 -0
  76. data/manual/graphics/polygon.rb +29 -0
  77. data/manual/graphics/rectangle.rb +21 -0
  78. data/manual/graphics/rotate.rb +28 -0
  79. data/manual/graphics/scale.rb +41 -0
  80. data/manual/graphics/soft_masks.rb +46 -0
  81. data/manual/graphics/stroke_cap.rb +31 -0
  82. data/manual/graphics/stroke_dash.rb +43 -0
  83. data/manual/graphics/stroke_join.rb +30 -0
  84. data/manual/graphics/translate.rb +29 -0
  85. data/manual/graphics/transparency.rb +35 -0
  86. data/manual/images/absolute_position.rb +23 -0
  87. data/manual/images/fit.rb +21 -0
  88. data/manual/images/horizontal.rb +25 -0
  89. data/manual/images/images.rb +40 -0
  90. data/manual/images/plain_image.rb +18 -0
  91. data/manual/images/scale.rb +22 -0
  92. data/manual/images/vertical.rb +28 -0
  93. data/manual/images/width_and_height.rb +25 -0
  94. data/manual/layout/boxes.rb +27 -0
  95. data/manual/layout/content.rb +25 -0
  96. data/manual/layout/layout.rb +28 -0
  97. data/manual/layout/simple_grid.rb +23 -0
  98. data/manual/manual/cover.rb +26 -0
  99. data/manual/manual/foreword.rb +13 -0
  100. data/manual/manual/how_to_read_this_manual.rb +41 -0
  101. data/manual/manual/manual.rb +36 -0
  102. data/manual/outline/add_subsection_to.rb +61 -0
  103. data/manual/outline/insert_section_after.rb +47 -0
  104. data/manual/outline/outline.rb +32 -0
  105. data/manual/outline/sections_and_pages.rb +67 -0
  106. data/manual/repeatable_content/page_numbering.rb +54 -0
  107. data/manual/repeatable_content/repeatable_content.rb +31 -0
  108. data/manual/repeatable_content/repeater.rb +55 -0
  109. data/manual/repeatable_content/stamp.rb +41 -0
  110. data/manual/security/encryption.rb +31 -0
  111. data/manual/security/permissions.rb +38 -0
  112. data/manual/security/security.rb +28 -0
  113. data/manual/syntax_highlight.rb +52 -0
  114. data/manual/table/basic_block.rb +53 -0
  115. data/manual/table/before_rendering_page.rb +26 -0
  116. data/manual/table/cell_border_lines.rb +24 -0
  117. data/manual/table/cell_borders_and_bg.rb +31 -0
  118. data/manual/table/cell_dimensions.rb +30 -0
  119. data/manual/table/cell_text.rb +38 -0
  120. data/manual/table/column_widths.rb +30 -0
  121. data/manual/table/content_and_subtables.rb +39 -0
  122. data/manual/table/creation.rb +27 -0
  123. data/manual/table/filtering.rb +36 -0
  124. data/manual/table/flow_and_header.rb +17 -0
  125. data/manual/table/image_cells.rb +33 -0
  126. data/manual/table/position.rb +29 -0
  127. data/manual/table/row_colors.rb +20 -0
  128. data/manual/table/span.rb +30 -0
  129. data/manual/table/style.rb +22 -0
  130. data/manual/table/table.rb +52 -0
  131. data/manual/table/width.rb +27 -0
  132. data/manual/templates/full_template.rb +23 -0
  133. data/manual/templates/page_template.rb +47 -0
  134. data/manual/templates/templates.rb +26 -0
  135. data/manual/text/alignment.rb +44 -0
  136. data/manual/text/color.rb +24 -0
  137. data/manual/text/column_box.rb +32 -0
  138. data/manual/text/fallback_fonts.rb +37 -0
  139. data/manual/text/font.rb +41 -0
  140. data/manual/text/font_size.rb +45 -0
  141. data/manual/text/font_style.rb +23 -0
  142. data/manual/text/formatted_callbacks.rb +60 -0
  143. data/manual/text/formatted_text.rb +50 -0
  144. data/manual/text/free_flowing_text.rb +51 -0
  145. data/manual/text/group.rb +29 -0
  146. data/manual/text/inline.rb +43 -0
  147. data/manual/text/kerning_and_character_spacing.rb +39 -0
  148. data/manual/text/leading.rb +25 -0
  149. data/manual/text/line_wrapping.rb +41 -0
  150. data/manual/text/paragraph_indentation.rb +26 -0
  151. data/manual/text/positioned_text.rb +38 -0
  152. data/manual/text/registering_families.rb +48 -0
  153. data/manual/text/rendering_and_color.rb +37 -0
  154. data/manual/text/right_to_left_text.rb +43 -0
  155. data/manual/text/rotation.rb +43 -0
  156. data/manual/text/single_usage.rb +37 -0
  157. data/manual/text/text.rb +75 -0
  158. data/manual/text/text_box_excess.rb +32 -0
  159. data/manual/text/text_box_extensions.rb +45 -0
  160. data/manual/text/text_box_overflow.rb +44 -0
  161. data/manual/text/utf8.rb +28 -0
  162. data/manual/text/win_ansi_charset.rb +59 -0
  163. data/prawn.gemspec +10 -7
  164. data/spec/bounding_box_spec.rb +107 -17
  165. data/spec/cell_spec.rb +66 -40
  166. data/spec/column_box_spec.rb +33 -0
  167. data/spec/document_spec.rb +45 -24
  168. data/spec/extensions/encoding_helpers.rb +6 -0
  169. data/spec/extensions/mocha.rb +1 -0
  170. data/spec/font_spec.rb +71 -53
  171. data/spec/formatted_text_arranger_spec.rb +19 -19
  172. data/spec/formatted_text_box_spec.rb +16 -16
  173. data/spec/formatted_text_fragment_spec.rb +6 -6
  174. data/spec/graphics_spec.rb +96 -31
  175. data/spec/grid_spec.rb +2 -2
  176. data/spec/images_spec.rb +18 -10
  177. data/spec/jpg_spec.rb +1 -1
  178. data/spec/line_wrap_spec.rb +14 -14
  179. data/spec/measurement_units_spec.rb +2 -2
  180. data/spec/name_tree_spec.rb +6 -6
  181. data/spec/object_store_spec.rb +17 -17
  182. data/spec/outline_spec.rb +35 -17
  183. data/spec/pdf_object_spec.rb +3 -1
  184. data/spec/png_spec.rb +22 -19
  185. data/spec/reference_spec.rb +24 -1
  186. data/spec/repeater_spec.rb +9 -9
  187. data/spec/security_spec.rb +3 -3
  188. data/spec/snapshot_spec.rb +3 -3
  189. data/spec/soft_mask_spec.rb +117 -0
  190. data/spec/span_spec.rb +4 -4
  191. data/spec/spec_helper.rb +12 -6
  192. data/spec/stamp_spec.rb +12 -12
  193. data/spec/stroke_styles_spec.rb +5 -5
  194. data/spec/table_spec.rb +458 -88
  195. data/spec/template_spec.rb +108 -54
  196. data/spec/text_at_spec.rb +17 -17
  197. data/spec/text_box_spec.rb +76 -45
  198. data/spec/text_rendering_mode_spec.rb +5 -5
  199. data/spec/text_spacing_spec.rb +4 -4
  200. data/spec/text_spec.rb +44 -40
  201. metadata +419 -250
  202. data/lib/prawn/graphics/gradient.rb +0 -84
  203. data/lib/prawn/security/arcfour.rb +0 -51
@@ -0,0 +1,6 @@
1
+ module EncodingHelpers
2
+ def win1252_string(str)
3
+ ruby_19 { str.force_encoding("Windows-1252") }
4
+ str
5
+ end
6
+ end
@@ -11,6 +11,7 @@
11
11
 
12
12
  class ParameterChecker < Mocha::ParametersMatcher
13
13
  def initialize(&matching_block)
14
+ @expected_parameters = [Mocha::ParameterMatchers::AnyParameters.new]
14
15
  @matching_block = matching_block
15
16
  end
16
17
 
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
- require 'iconv'
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require 'pathname'
5
5
 
6
- describe "Font behavior" do
6
+ describe "Font behavior" do
7
7
 
8
8
  it "should default to Helvetica if no font is specified" do
9
9
  @pdf = Prawn::Document.new
@@ -24,7 +24,7 @@ describe "#width_of" do
24
24
  it "should exclude newlines" do
25
25
  create_pdf
26
26
  # Use a TTF font that has a non-zero width for \n
27
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
27
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
28
28
 
29
29
  @pdf.width_of("\nhello world\n").should ==
30
30
  @pdf.width_of("hello world")
@@ -39,7 +39,7 @@ describe "#width_of" do
39
39
  @bold_hello = @pdf.width_of("hello")
40
40
  }
41
41
 
42
- inline_bold_hello.should.be > normal_hello
42
+ inline_bold_hello.should be > normal_hello
43
43
  inline_bold_hello.should == @bold_hello
44
44
  end
45
45
 
@@ -70,7 +70,7 @@ describe "font style support" do
70
70
  pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
71
71
 
72
72
  lambda{ pdf_without_page.font "Helvetica" }.
73
- should.raise(Prawn::Errors::NotOnPage)
73
+ should raise_error(Prawn::Errors::NotOnPage)
74
74
  end
75
75
 
76
76
  it "should allow specifying font style by style name and font family" do
@@ -96,7 +96,7 @@ describe "font style support" do
96
96
  end
97
97
 
98
98
  it "should allow font familes to be defined in a single dfont" do
99
- file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
99
+ file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
100
100
  @pdf.font_families["Action Man"] = {
101
101
  :normal => { :file => file, :font => "ActionMan" },
102
102
  :italic => { :file => file, :font => "ActionMan-Italic" },
@@ -112,6 +112,21 @@ describe "font style support" do
112
112
  name = name.sub(/\w+\+/, "subset+")
113
113
  name.should == "subset+ActionMan-Italic"
114
114
  end
115
+
116
+ it "should accept Pathname objects for font files" do
117
+ file = Pathname.new( "#{Prawn::DATADIR}/fonts/Chalkboard.ttf" )
118
+ @pdf.font_families["Chalkboard"] = {
119
+ :normal => file
120
+ }
121
+
122
+ @pdf.font "Chalkboard"
123
+ @pdf.text "In Chalkboard"
124
+
125
+ text = PDF::Inspector::Text.analyze(@pdf.render)
126
+ name = text.font_settings.map { |e| e[:name] }.first.to_s
127
+ name = name.sub(/\w+\+/, "subset+")
128
+ name.should == "subset+Chalkboard"
129
+ end
115
130
  end
116
131
 
117
132
  describe "Transactional font handling" do
@@ -170,49 +185,50 @@ describe "Document#page_fonts" do
170
185
  end
171
186
 
172
187
  def page_should_include_font(font)
173
- assert_block("Expected page to include font: #{font}") do
174
- page_includes_font?(font)
175
- end
188
+ page_includes_font?(font).should be_true
176
189
  end
177
190
 
178
191
  def page_should_not_include_font(font)
179
- assert_block("Did not expect page to include font: #{font}") do
180
- not page_includes_font?(font)
181
- end
192
+ page_includes_font?(font).should be_false
182
193
  end
183
194
 
184
195
  end
185
196
 
186
197
  describe "AFM fonts" do
187
198
 
188
- setup do
199
+ before do
189
200
  create_pdf
190
201
  @times = @pdf.find_font "Times-Roman"
191
- @iconv = ::Iconv.new('Windows-1252', 'utf-8')
192
202
  end
193
203
 
194
204
  it "should calculate string width taking into account accented characters" do
195
- @times.compute_width_of(@iconv.iconv("é"), :size => 12).should == @times.compute_width_of("e", :size => 12)
205
+ input = win1252_string("\xE9")# é in win-1252
206
+ @times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
196
207
  end
197
208
 
198
209
  it "should calculate string width taking into account kerning pairs" do
199
- @times.compute_width_of(@iconv.iconv("To"), :size => 12).should == 13.332
200
- @times.compute_width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372
201
- @times.compute_width_of(@iconv.iconv("Tö"), :size => 12, :kerning => true).should == 12.372
210
+ @times.compute_width_of(win1252_string("To"), :size => 12).should == 13.332
211
+ @times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true).should == 12.372
212
+
213
+ input = win1252_string("T\xF6") # Tö in win-1252
214
+ @times.compute_width_of(input, :size => 12, :kerning => true).should == 12.372
202
215
  end
203
216
 
204
217
  it "should encode text without kerning by default" do
205
- @times.encode_text(@iconv.iconv("To")).should == [[0, "To"]]
206
- @times.encode_text(@iconv.iconv("Télé")).should == [[0, @iconv.iconv("Télé")]]
207
- @times.encode_text(@iconv.iconv("Technology")).should == [[0, "Technology"]]
208
- @times.encode_text(@iconv.iconv("Technology...")).should == [[0, "Technology..."]]
218
+ @times.encode_text(win1252_string("To")).should == [[0, "To"]]
219
+ input = win1252_string("T\xE9l\xE9") # Télé in win-1252
220
+ @times.encode_text(input).should == [[0, input]]
221
+ @times.encode_text(win1252_string("Technology")).should == [[0, "Technology"]]
222
+ @times.encode_text(win1252_string("Technology...")).should == [[0, "Technology..."]]
209
223
  end
210
224
 
211
225
  it "should encode text with kerning if requested" do
212
- @times.encode_text(@iconv.iconv("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
213
- @times.encode_text(@iconv.iconv("Télé"), :kerning => true).should == [[0, ["T", 70, @iconv.iconv("élé")]]]
214
- @times.encode_text(@iconv.iconv("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
215
- @times.encode_text(@iconv.iconv("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
226
+ @times.encode_text(win1252_string("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
227
+ input = win1252_string("T\xE9l\xE9") # Télé in win-1252
228
+ output = win1252_string("\xE9l\xE9") # élé in win-1252
229
+ @times.encode_text(input, :kerning => true).should == [[0, ["T", 70, output]]]
230
+ @times.encode_text(win1252_string("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
231
+ @times.encode_text(win1252_string("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
216
232
  end
217
233
 
218
234
  describe "when normalizing encoding" do
@@ -220,13 +236,13 @@ describe "AFM fonts" do
220
236
  it "should not modify the original string when normalize_encoding() is used" do
221
237
  original = "Foo"
222
238
  normalized = @times.normalize_encoding(original)
223
- assert ! original.equal?(normalized)
239
+ original.equal?(normalized).should be_false
224
240
  end
225
241
 
226
242
  it "should modify the original string when normalize_encoding!() is used" do
227
243
  original = "Foo"
228
244
  normalized = @times.normalize_encoding!(original)
229
- assert original.equal?(normalized)
245
+ original.equal?(normalized).should be_true
230
246
  end
231
247
 
232
248
  end
@@ -244,33 +260,33 @@ describe "#glyph_present" do
244
260
 
245
261
  it "should return true when present in an AFM font" do
246
262
  font = @pdf.find_font("Helvetica")
247
- font.glyph_present?("H").should.be true
263
+ font.glyph_present?("H").should be_true
248
264
  end
249
265
 
250
266
  it "should return false when absent in an AFM font" do
251
267
  font = @pdf.find_font("Helvetica")
252
- font.glyph_present?("再").should.be false
268
+ font.glyph_present?("再").should be_false
253
269
  end
254
270
 
255
271
  it "should return true when present in a TTF font" do
256
- font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
257
- font.glyph_present?("H").should.be true
272
+ font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
273
+ font.glyph_present?("H").should be_true
258
274
  end
259
275
 
260
276
  it "should return false when absent in a TTF font" do
261
- font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
262
- font.glyph_present?("再").should.be false
277
+ font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
278
+ font.glyph_present?("再").should be_false
263
279
 
264
- font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
265
- font.glyph_present?("€").should.be false
280
+ font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
281
+ font.glyph_present?("€").should be_false
266
282
  end
267
283
  end
268
284
 
269
285
  describe "TTF fonts" do
270
286
 
271
- setup do
287
+ before do
272
288
  create_pdf
273
- @activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
289
+ @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf"
274
290
  end
275
291
 
276
292
  it "should calculate string width taking into account accented characters" do
@@ -285,9 +301,11 @@ describe "TTF fonts" do
285
301
  it "should encode text without kerning by default" do
286
302
  @activa.encode_text("To").should == [[0, "To"]]
287
303
 
288
- tele = (RUBY_VERSION < '1.9') ? "T\216l\216" :
289
- "T\216l\216".force_encoding("US-ASCII")
290
- @activa.encode_text("Télé").should == [[0, tele]]
304
+ tele = "T\216l\216"
305
+ result = @activa.encode_text("Télé")
306
+ result.length.should == 1
307
+ result[0][0].should == 0
308
+ result[0][1].bytes.to_a.should == tele.bytes.to_a
291
309
 
292
310
  @activa.encode_text("Technology").should == [[0, "Technology"]]
293
311
  @activa.encode_text("Technology...").should == [[0, "Technology..."]]
@@ -320,13 +338,13 @@ describe "TTF fonts" do
320
338
  it "should not modify the original string when normalize_encoding() is used" do
321
339
  original = "Foo"
322
340
  normalized = @activa.normalize_encoding(original)
323
- assert ! original.equal?(normalized)
341
+ original.equal?(normalized).should be_false
324
342
  end
325
343
 
326
344
  it "should modify the original string when normalize_encoding!() is used" do
327
345
  original = "Foo"
328
346
  normalized = @activa.normalize_encoding!(original)
329
- assert original.equal?(normalized)
347
+ original.equal?(normalized).should be_true
330
348
  end
331
349
 
332
350
  end
@@ -336,17 +354,17 @@ describe "TTF fonts" do
336
354
  it "should allow TTF fonts to be used alongside document transactions" do
337
355
  lambda {
338
356
  Prawn::Document.new do
339
- font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
357
+ font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
340
358
  text "Hi there"
341
359
  transaction { text "Nice, thank you" }
342
360
  end
343
- }.should.not.raise
361
+ }.should_not raise_error
344
362
  end
345
363
 
346
364
  it "should allow TTF fonts to be used inside transactions" do
347
365
  pdf = Prawn::Document.new do
348
366
  transaction do
349
- font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
367
+ font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
350
368
  text "Hi there"
351
369
  end
352
370
  end
@@ -362,9 +380,9 @@ describe "TTF fonts" do
362
380
  end
363
381
 
364
382
  describe "DFont fonts" do
365
- setup do
383
+ before do
366
384
  create_pdf
367
- @file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
385
+ @file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
368
386
  end
369
387
 
370
388
  it "should list all named fonts" do
@@ -394,16 +412,16 @@ describe "DFont fonts" do
394
412
  it "should cache font object based on selected font" do
395
413
  f1 = @pdf.find_font(@file, :font => "ActionMan")
396
414
  f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
397
- assert_not_equal f1.object_id, f2.object_id
398
- assert_equal f1.object_id, @pdf.find_font(@file, :font => "ActionMan").object_id
399
- assert_equal f2.object_id, @pdf.find_font(@file, :font => "ActionMan-Bold").object_id
415
+ f2.object_id.should_not == f1.object_id
416
+ @pdf.find_font(@file, :font => "ActionMan").object_id.should == f1.object_id
417
+ @pdf.find_font(@file, :font => "ActionMan-Bold").object_id.should == f2.object_id
400
418
  end
401
419
  end
402
420
 
403
421
  describe "#character_count(text)" do
404
422
  it "should work on TTF fonts" do
405
423
  create_pdf
406
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
424
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
407
425
  @pdf.font.character_count("こんにちは世界").should == 7
408
426
  @pdf.font.character_count("Hello, world!").should == 13
409
427
  end
@@ -56,12 +56,12 @@ describe "Core::Text::Formatted::Arranger#next_string" do
56
56
  { :text => " you?" }]
57
57
  @arranger.format_array = array
58
58
  end
59
- it "should raise an error if called after a line was finalized and" +
59
+ it "should raise_error an error if called after a line was finalized and" +
60
60
  " before a new line was initialized" do
61
61
  @arranger.finalize_line
62
62
  lambda do
63
63
  @arranger.next_string
64
- end.should.raise(RuntimeError)
64
+ end.should raise_error(RuntimeError)
65
65
  end
66
66
  it "should populate consumed array" do
67
67
  while string = @arranger.next_string
@@ -99,7 +99,7 @@ describe "Core::Text::Formatted::Arranger#next_string" do
99
99
  end
100
100
 
101
101
  describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
102
- it "should raise an error if called before finalize_line was called" do
102
+ it "should raise_error an error if called before finalize_line was called" do
103
103
  create_pdf
104
104
  arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
105
105
  array = [{ :text => "hello " },
@@ -111,7 +111,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
111
111
  end
112
112
  lambda do
113
113
  arranger.retrieve_fragment
114
- end.should.raise(RuntimeError)
114
+ end.should raise_error(RuntimeError)
115
115
  end
116
116
  it "should return the consumed fragments in order of consumption" +
117
117
  " and update" do
@@ -147,7 +147,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
147
147
  end
148
148
  arranger.finalize_line
149
149
  while fragment = arranger.retrieve_fragment
150
- fragment.text.should.not.be.empty
150
+ fragment.text.should_not be_empty
151
151
  end
152
152
  end
153
153
  it "should not alter the current font style" do
@@ -162,7 +162,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
162
162
  end
163
163
  arranger.finalize_line
164
164
  arranger.retrieve_fragment
165
- arranger.current_format_state[:styles].should.be.nil
165
+ arranger.current_format_state[:styles].should be_nil
166
166
  end
167
167
  end
168
168
 
@@ -226,10 +226,10 @@ describe "Core::Text::Formatted::Arranger#space_count" do
226
226
  while string = @arranger.next_string
227
227
  end
228
228
  end
229
- it "should raise an error if called before finalize_line was called" do
229
+ it "should raise_error an error if called before finalize_line was called" do
230
230
  lambda do
231
231
  @arranger.space_count
232
- end.should.raise(RuntimeError)
232
+ end.should raise_error(RuntimeError)
233
233
  end
234
234
  it "should return the total number of spaces in all fragments" do
235
235
  @arranger.finalize_line
@@ -271,14 +271,14 @@ describe "Core::Text::Formatted::Arranger#line_width" do
271
271
  while string = @arranger.next_string
272
272
  end
273
273
  end
274
- it "should raise an error if called before finalize_line was called" do
274
+ it "should raise_error an error if called before finalize_line was called" do
275
275
  lambda do
276
276
  @arranger.line_width
277
- end.should.raise(RuntimeError)
277
+ end.should raise_error(RuntimeError)
278
278
  end
279
279
  it "should return the width of the complete line" do
280
280
  @arranger.finalize_line
281
- @arranger.line_width.should.be > 0
281
+ @arranger.line_width.should be > 0
282
282
  end
283
283
  end
284
284
 
@@ -304,7 +304,7 @@ describe "Core::Text::Formatted::Arranger#line_width with character_spacing > 0"
304
304
  while string = arranger.next_string
305
305
  end
306
306
  arranger.finalize_line
307
- arranger.line_width.should.be > base_line_width
307
+ arranger.line_width.should be > base_line_width
308
308
  end
309
309
  end
310
310
 
@@ -318,10 +318,10 @@ describe "Core::Text::Formatted::Arranger#line" do
318
318
  while string = @arranger.next_string
319
319
  end
320
320
  end
321
- it "should raise an error if called before finalize_line was called" do
321
+ it "should raise_error an error if called before finalize_line was called" do
322
322
  lambda do
323
323
  @arranger.line
324
- end.should.raise(RuntimeError)
324
+ end.should raise_error(RuntimeError)
325
325
  end
326
326
  it "should return the complete line" do
327
327
  @arranger.finalize_line
@@ -355,7 +355,7 @@ describe "Core::Text::Formatted::Arranger#unconsumed" do
355
355
  end
356
356
 
357
357
  describe "Core::Text::Formatted::Arranger#finished" do
358
- it "should be false if anything was not printed" do
358
+ it "should be_false if anything was not printed" do
359
359
  create_pdf
360
360
  arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
361
361
  array = [{ :text => "hello " },
@@ -366,9 +366,9 @@ describe "Core::Text::Formatted::Arranger#finished" do
366
366
  while string = arranger.next_string
367
367
  end
368
368
  arranger.update_last_string(" you", "now?", nil)
369
- arranger.should.not.be.finished
369
+ arranger.should_not be_finished
370
370
  end
371
- it "should be false if everything was printed" do
371
+ it "should be_false if everything was printed" do
372
372
  create_pdf
373
373
  arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
374
374
  array = [{ :text => "hello " },
@@ -378,7 +378,7 @@ describe "Core::Text::Formatted::Arranger#finished" do
378
378
  arranger.format_array = array
379
379
  while string = arranger.next_string
380
380
  end
381
- arranger.should.be.finished
381
+ arranger.should be_finished
382
382
  end
383
383
  end
384
384
 
@@ -395,7 +395,7 @@ describe "Core::Text::Formatted::Arranger.max_line_height" do
395
395
  while string = arranger.next_string
396
396
  end
397
397
  arranger.finalize_line
398
- arranger.max_line_height.should.be.close(33.32, 0.0001)
398
+ arranger.max_line_height.should be_within(0.0001).of(33.32)
399
399
  end
400
400
  end
401
401
 
@@ -18,10 +18,10 @@ describe "Text::Formatted::Box wrapping" do
18
18
  text_box.text.should == "Hello\nWorld2"
19
19
  end
20
20
 
21
- it "should not raise Encoding::CompatibilityError when keeping a TTF and an " +
21
+ it "should_not raise_error Encoding::CompatibilityError when keeping a TTF and an " +
22
22
  "AFM font together" do
23
23
  ruby_19 do
24
- file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
24
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
25
25
  @pdf.font_families["Kai"] = {
26
26
  :normal => { :file => file, :font => "Kai" }
27
27
  }
@@ -32,7 +32,7 @@ describe "Text::Formatted::Box wrapping" do
32
32
  text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
33
33
  lambda {
34
34
  text_box.render
35
- }.should.not.raise(Encoding::CompatibilityError)
35
+ }.should_not raise_error(Encoding::CompatibilityError)
36
36
  end
37
37
  end
38
38
 
@@ -79,9 +79,9 @@ describe "Text::Formatted::Box wrapping" do
79
79
  it "should properly handle empty slices using default encoding" do
80
80
  texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
81
81
  text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
82
- assert_nothing_raised do
82
+ lambda {
83
83
  text_box.render
84
- end
84
+ }.should_not raise_error
85
85
  text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
86
86
  end
87
87
 
@@ -109,9 +109,9 @@ describe "Text::Formatted::Box wrapping" do
109
109
  it "should properly handle empty slices using Unicode encoding" do
110
110
  texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
111
111
  text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
112
- assert_nothing_raised do
112
+ lambda {
113
113
  text_box.render
114
- end
114
+ }.should_not raise_error
115
115
  text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
116
116
  end
117
117
  end
@@ -121,7 +121,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
121
121
  "a Chinese font and set of Chinese glyphs not in the current font" do
122
122
  it "should change the font to the Chinese font for the Chinese glyphs" do
123
123
  create_pdf
124
- file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
124
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
125
125
  @pdf.font_families["Kai"] = {
126
126
  :normal => { :file => file, :font => "Kai" }
127
127
  }
@@ -149,7 +149,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
149
149
  "an AFM font and Win-Ansi glyph not in the current Chinese font" do
150
150
  it "should change the font to the AFM font for the Win-Ansi glyph" do
151
151
  create_pdf
152
- file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
152
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
153
153
  @pdf.font_families["Kai"] = {
154
154
  :normal => { :file => file, :font => "Kai" }
155
155
  }
@@ -178,7 +178,7 @@ describe "Text::Formatted::Box with :fallback_fonts option and fragment " +
178
178
  "level font" do
179
179
  it "should use the fragment level font except for glyphs not in that font" do
180
180
  create_pdf
181
- file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
181
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
182
182
  @pdf.font_families["Kai"] = {
183
183
  :normal => { :file => file, :font => "Kai" }
184
184
  }
@@ -205,7 +205,7 @@ end
205
205
  describe "Text::Formatted::Box" do
206
206
  before(:each) do
207
207
  create_pdf
208
- file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
208
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
209
209
  @pdf.font_families["Kai"] = {
210
210
  :normal => { :file => file, :font => "Kai" }
211
211
  }
@@ -397,7 +397,7 @@ describe "Text::Formatted::Box#render" do
397
397
  { :text => "callback now",
398
398
  :callback => [behind, in_front] }]
399
399
  text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
400
- lambda { text_box.render }.should.not.raise(NoMethodError)
400
+ lambda { text_box.render }.should_not raise_error(NoMethodError)
401
401
  end
402
402
  it "should be able to set the font" do
403
403
  create_pdf
@@ -449,7 +449,7 @@ describe "Text::Formatted::Box#render" do
449
449
  text_box.render
450
450
  contents = PDF::Inspector::Text.analyze(@pdf.render)
451
451
  contents.font_settings[0][:size].should == 12
452
- contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
452
+ contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
453
453
  end
454
454
  it "should be able to set superscript" do
455
455
  create_pdf
@@ -460,7 +460,7 @@ describe "Text::Formatted::Box#render" do
460
460
  text_box.render
461
461
  contents = PDF::Inspector::Text.analyze(@pdf.render)
462
462
  contents.font_settings[0][:size].should == 12
463
- contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
463
+ contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
464
464
  end
465
465
  it "should be able to set compound bold and italic text" do
466
466
  create_pdf
@@ -531,7 +531,7 @@ describe "Text::Formatted::Box#render" do
531
531
  text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
532
532
  text_box.render
533
533
  @pdf.font_size(24) do
534
- text_box.height.should.be.close(@pdf.font.ascender + @pdf.font.descender, 0.001)
534
+ text_box.height.should be_within(0.001).of(@pdf.font.ascender + @pdf.font.descender)
535
535
  end
536
536
  end
537
537
  it "should be able to set color via an rgb hex string" do
@@ -591,7 +591,7 @@ describe "Text::Formatted::Box#render with :align => :justify" do
591
591
  text_box = Prawn::Text::Formatted::Box.new(array, options)
592
592
  text_box.render
593
593
  contents = PDF::Inspector::Text.analyze(@pdf.render)
594
- contents.word_spacing.should.be.empty
594
+ contents.word_spacing.should be_empty
595
595
  end
596
596
  end
597
597