prawn 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -5
  3. data/lib/prawn.rb +4 -4
  4. data/lib/prawn/document.rb +47 -46
  5. data/lib/prawn/document/bounding_box.rb +13 -19
  6. data/lib/prawn/document/column_box.rb +3 -5
  7. data/lib/prawn/document/internals.rb +0 -1
  8. data/lib/prawn/document/span.rb +12 -12
  9. data/lib/prawn/errors.rb +32 -33
  10. data/lib/prawn/font.rb +29 -36
  11. data/lib/prawn/font/afm.rb +20 -20
  12. data/lib/prawn/font/dfont.rb +0 -1
  13. data/lib/prawn/font/ttf.rb +30 -27
  14. data/lib/prawn/font_metric_cache.rb +4 -8
  15. data/lib/prawn/graphics.rb +37 -42
  16. data/lib/prawn/graphics/cap_style.rb +1 -1
  17. data/lib/prawn/graphics/color.rb +21 -23
  18. data/lib/prawn/graphics/dash.rb +5 -6
  19. data/lib/prawn/graphics/join_style.rb +1 -2
  20. data/lib/prawn/graphics/patterns.rb +25 -21
  21. data/lib/prawn/graphics/transformation.rb +4 -5
  22. data/lib/prawn/graphics/transparency.rb +6 -8
  23. data/lib/prawn/grid.rb +21 -14
  24. data/lib/prawn/image_handler.rb +2 -2
  25. data/lib/prawn/images.rb +29 -31
  26. data/lib/prawn/images/image.rb +1 -1
  27. data/lib/prawn/images/jpg.rb +10 -12
  28. data/lib/prawn/images/png.rb +13 -13
  29. data/lib/prawn/measurements.rb +7 -14
  30. data/lib/prawn/outline.rb +6 -6
  31. data/lib/prawn/repeater.rb +1 -5
  32. data/lib/prawn/security.rb +17 -25
  33. data/lib/prawn/security/arcfour.rb +1 -1
  34. data/lib/prawn/soft_mask.rb +11 -12
  35. data/lib/prawn/stamp.rb +16 -8
  36. data/lib/prawn/text.rb +23 -20
  37. data/lib/prawn/text/box.rb +3 -6
  38. data/lib/prawn/text/formatted/arranger.rb +9 -12
  39. data/lib/prawn/text/formatted/box.rb +23 -22
  40. data/lib/prawn/text/formatted/fragment.rb +0 -4
  41. data/lib/prawn/text/formatted/line_wrap.rb +13 -24
  42. data/lib/prawn/text/formatted/parser.rb +16 -20
  43. data/lib/prawn/text/formatted/wrap.rb +2 -7
  44. data/lib/prawn/utilities.rb +6 -3
  45. data/lib/prawn/version.rb +1 -1
  46. data/manual/basic_concepts/basic_concepts.rb +0 -2
  47. data/manual/basic_concepts/view.rb +1 -1
  48. data/manual/bounding_box/bounding_box.rb +0 -3
  49. data/manual/bounding_box/russian_boxes.rb +7 -8
  50. data/manual/bounding_box/stretchy.rb +0 -1
  51. data/manual/contents.rb +2 -2
  52. data/manual/cover.rb +11 -12
  53. data/manual/document_and_page_options/document_and_page_options.rb +2 -5
  54. data/manual/document_and_page_options/metadata.rb +10 -10
  55. data/manual/document_and_page_options/page_size.rb +0 -1
  56. data/manual/graphics/fill_rules.rb +5 -4
  57. data/manual/graphics/graphics.rb +0 -3
  58. data/manual/graphics/lines_and_curves.rb +1 -1
  59. data/manual/graphics/rotate.rb +0 -2
  60. data/manual/graphics/scale.rb +4 -2
  61. data/manual/graphics/soft_masks.rb +0 -1
  62. data/manual/graphics/stroke_cap.rb +1 -1
  63. data/manual/graphics/stroke_join.rb +1 -1
  64. data/manual/graphics/translate.rb +3 -3
  65. data/manual/graphics/transparency.rb +0 -1
  66. data/manual/how_to_read_this_manual.rb +0 -1
  67. data/manual/images/images.rb +0 -3
  68. data/manual/layout/boxes.rb +5 -5
  69. data/manual/layout/content.rb +2 -2
  70. data/manual/layout/layout.rb +0 -3
  71. data/manual/outline/outline.rb +0 -3
  72. data/manual/repeatable_content/page_numbering.rb +1 -1
  73. data/manual/repeatable_content/repeatable_content.rb +0 -3
  74. data/manual/repeatable_content/repeater.rb +6 -6
  75. data/manual/security/encryption.rb +0 -2
  76. data/manual/security/permissions.rb +0 -2
  77. data/manual/security/security.rb +0 -3
  78. data/manual/text/alignment.rb +3 -3
  79. data/manual/text/color.rb +0 -1
  80. data/manual/text/column_box.rb +0 -1
  81. data/manual/text/fallback_fonts.rb +2 -2
  82. data/manual/text/formatted_callbacks.rb +3 -2
  83. data/manual/text/paragraph_indentation.rb +2 -3
  84. data/manual/text/registering_families.rb +13 -9
  85. data/manual/text/rotation.rb +0 -1
  86. data/manual/text/text.rb +0 -3
  87. data/manual/text/text_box_overflow.rb +7 -5
  88. data/manual/text/utf8.rb +1 -1
  89. data/manual/text/win_ansi_charset.rb +2 -2
  90. data/prawn.gemspec +4 -4
  91. data/spec/acceptance/png.rb +6 -7
  92. data/spec/annotations_spec.rb +21 -28
  93. data/spec/bounding_box_spec.rb +100 -109
  94. data/spec/column_box_spec.rb +26 -32
  95. data/spec/destinations_spec.rb +2 -4
  96. data/spec/document_spec.rb +145 -151
  97. data/spec/extensions/mocha.rb +0 -1
  98. data/spec/font_metric_cache_spec.rb +7 -7
  99. data/spec/font_spec.rb +103 -102
  100. data/spec/formatted_text_arranger_spec.rb +76 -74
  101. data/spec/formatted_text_box_spec.rb +170 -159
  102. data/spec/formatted_text_fragment_spec.rb +57 -56
  103. data/spec/graphics_spec.rb +158 -175
  104. data/spec/grid_spec.rb +28 -29
  105. data/spec/image_handler_spec.rb +4 -5
  106. data/spec/images_spec.rb +50 -36
  107. data/spec/inline_formatted_text_parser_spec.rb +397 -393
  108. data/spec/jpg_spec.rb +4 -6
  109. data/spec/line_wrap_spec.rb +54 -55
  110. data/spec/measurement_units_spec.rb +12 -15
  111. data/spec/outline_spec.rb +77 -98
  112. data/spec/png_spec.rb +55 -65
  113. data/spec/reference_spec.rb +3 -3
  114. data/spec/repeater_spec.rb +20 -26
  115. data/spec/security_spec.rb +42 -49
  116. data/spec/soft_mask_spec.rb +4 -5
  117. data/spec/span_spec.rb +5 -6
  118. data/spec/spec_helper.rb +2 -4
  119. data/spec/stamp_spec.rb +41 -22
  120. data/spec/stroke_styles_spec.rb +36 -39
  121. data/spec/text_at_spec.rb +28 -29
  122. data/spec/text_box_spec.rb +160 -165
  123. data/spec/text_rendering_mode_spec.rb +9 -9
  124. data/spec/text_spacing_spec.rb +13 -13
  125. data/spec/text_spec.rb +116 -124
  126. data/spec/text_with_inline_formatting_spec.rb +5 -5
  127. data/spec/transparency_spec.rb +20 -20
  128. data/spec/view_spec.rb +0 -1
  129. metadata +7 -7
@@ -31,7 +31,6 @@ class Mocha::Expectation
31
31
  end
32
32
  end
33
33
 
34
-
35
34
  # Equivalent to expects(method_name).at_least(0). More useful when combined
36
35
  # with parameter matchers to ignore certain calls for the sake of parameter
37
36
  # matching.
@@ -6,30 +6,30 @@ require 'pathname'
6
6
  describe "Font metrics caching" do
7
7
  let(:document) { Prawn::Document.new }
8
8
 
9
- subject { Prawn::FontMetricCache.new( document ) }
9
+ subject { Prawn::FontMetricCache.new(document) }
10
10
 
11
11
  it "should start with an empty cache" do
12
- subject.instance_variable_get( :@cache ).should be_empty
12
+ expect(subject.instance_variable_get(:@cache)).to be_empty
13
13
  end
14
14
 
15
15
  it "should cache the width of the provided string" do
16
16
  subject.width_of('M', {})
17
17
 
18
- subject.instance_variable_get( :@cache ).should have(1).entry
18
+ expect(subject.instance_variable_get(:@cache).size).to eq(1)
19
19
  end
20
20
 
21
21
  it "should only cache a single copy of the same string" do
22
22
  subject.width_of('M', {})
23
23
  subject.width_of('M', {})
24
24
 
25
- subject.instance_variable_get( :@cache ).should have(1).entry
25
+ expect(subject.instance_variable_get(:@cache).size).to eq(1)
26
26
  end
27
27
 
28
28
  it "should cache different copies for different strings" do
29
29
  subject.width_of('M', {})
30
30
  subject.width_of('W', {})
31
31
 
32
- subject.instance_variable_get( :@cache ).should have(2).entries
32
+ expect(subject.instance_variable_get(:@cache).entries.size).to eq(2)
33
33
  end
34
34
 
35
35
  it "should cache different copies of the same string with different font sizes" do
@@ -38,7 +38,7 @@ describe "Font metrics caching" do
38
38
  document.font_size 24
39
39
  subject.width_of('M', {})
40
40
 
41
- subject.instance_variable_get( :@cache ).should have(2).entries
41
+ expect(subject.instance_variable_get(:@cache).entries.size).to eq(2)
42
42
  end
43
43
 
44
44
  it "should cache different copies of the same string with different fonts" do
@@ -47,6 +47,6 @@ describe "Font metrics caching" do
47
47
  document.font 'Courier'
48
48
  subject.width_of('M', {})
49
49
 
50
- subject.instance_variable_get( :@cache ).should have(2).entries
50
+ expect(subject.instance_variable_get(:@cache).entries.size).to eq(2)
51
51
  end
52
52
  end
@@ -4,38 +4,34 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
  require 'pathname'
5
5
 
6
6
  describe "Font behavior" do
7
-
8
7
  it "should default to Helvetica if no font is specified" do
9
8
  @pdf = Prawn::Document.new
10
- @pdf.font.name.should == "Helvetica"
9
+ expect(@pdf.font.name).to eq("Helvetica")
11
10
  end
12
-
13
11
  end
14
12
 
15
13
  describe "Font objects" do
16
-
17
14
  it "should be equal" do
18
15
  font1 = Prawn::Document.new.font
19
16
  font2 = Prawn::Document.new.font
20
17
 
21
- font1.should eql( font2 )
18
+ expect(font1).to eql(font2)
22
19
  end
23
20
 
24
21
  it "should always be the same key" do
25
22
  font1 = Prawn::Document.new.font
26
23
  font2 = Prawn::Document.new.font
27
24
 
28
- hash = Hash.new
25
+ hash = {}
29
26
 
30
27
  hash[ font1 ] = "Original"
31
28
  hash[ font2 ] = "Overwritten"
32
29
 
33
- hash.size.should == 1
30
+ expect(hash.size).to eq(1)
34
31
 
35
- hash[ font1 ].should == "Overwritten"
36
- hash[ font2 ].should == "Overwritten"
32
+ expect(hash[ font1 ]).to eq("Overwritten")
33
+ expect(hash[ font2 ]).to eq("Overwritten")
37
34
  end
38
-
39
35
  end
40
36
 
41
37
  describe "#width_of" do
@@ -43,7 +39,7 @@ describe "#width_of" do
43
39
  create_pdf
44
40
  original_width = @pdf.width_of("hello world")
45
41
  @pdf.character_spacing(7) do
46
- @pdf.width_of("hello world").should == original_width + 11 * 7
42
+ expect(@pdf.width_of("hello world")).to eq(original_width + 11 * 7)
47
43
  end
48
44
  end
49
45
 
@@ -52,8 +48,9 @@ describe "#width_of" do
52
48
  # Use a TTF font that has a non-zero width for \n
53
49
  @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
54
50
 
55
- @pdf.width_of("\nhello world\n").should ==
51
+ expect(@pdf.width_of("\nhello world\n")).to eq(
56
52
  @pdf.width_of("hello world")
53
+ )
57
54
  end
58
55
 
59
56
  it "should take formatting into account" do
@@ -65,8 +62,8 @@ describe "#width_of" do
65
62
  @bold_hello = @pdf.width_of("hello")
66
63
  }
67
64
 
68
- inline_bold_hello.should be > normal_hello
69
- inline_bold_hello.should == @bold_hello
65
+ expect(inline_bold_hello).to be > normal_hello
66
+ expect(inline_bold_hello).to eq(@bold_hello)
70
67
  end
71
68
 
72
69
  it "should accept :style as an argument" do
@@ -77,7 +74,7 @@ describe "#width_of" do
77
74
  @bold_hello = @pdf.width_of("hello")
78
75
  }
79
76
 
80
- styled_bold_hello.should == @bold_hello
77
+ expect(styled_bold_hello).to eq(@bold_hello)
81
78
  end
82
79
 
83
80
  it "should calculate styled widths correctly using TTFs" do
@@ -86,7 +83,7 @@ describe "#width_of" do
86
83
  @pdf.font_families.update(
87
84
  'DejaVu Sans' => {
88
85
  :normal => "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf",
89
- :bold => "#{Prawn::DATADIR}/fonts/DejaVuSans-Bold.ttf",
86
+ :bold => "#{Prawn::DATADIR}/fonts/DejaVuSans-Bold.ttf"
90
87
  }
91
88
  )
92
89
  @pdf.font("DejaVu Sans") {
@@ -100,15 +97,15 @@ describe "#width_of" do
100
97
  @plain_hello = @pdf.width_of("hello")
101
98
  }
102
99
 
103
- @plain_hello.should_not == @bold_hello
100
+ expect(@plain_hello).not_to eq(@bold_hello)
104
101
 
105
- @styled_bold_hello.should == @bold_hello
102
+ expect(@styled_bold_hello).to eq(@bold_hello)
106
103
  end
107
104
 
108
105
  it "should not treat minus as if it were a hyphen", :issue => 578 do
109
106
  create_pdf
110
107
 
111
- @pdf.width_of("-0.75").should be < @pdf.width_of("25.00")
108
+ expect(@pdf.width_of("-0.75")).to be < @pdf.width_of("25.00")
112
109
  end
113
110
  end
114
111
 
@@ -116,7 +113,7 @@ describe "#font_size" do
116
113
  it "should allow setting font size in DSL style" do
117
114
  create_pdf
118
115
  @pdf.font_size 20
119
- @pdf.font_size.should == 20
116
+ expect(@pdf.font_size).to eq(20)
120
117
  end
121
118
  end
122
119
 
@@ -126,8 +123,8 @@ describe "font style support" do
126
123
  it "should complain if there is no @current_page" do
127
124
  pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
128
125
 
129
- lambda{ pdf_without_page.font "Helvetica" }.
130
- should raise_error(Prawn::Errors::NotOnPage)
126
+ expect{ pdf_without_page.font "Helvetica" }.
127
+ to raise_error(Prawn::Errors::NotOnPage)
131
128
  end
132
129
 
133
130
  it "should allow specifying font style by style name and font family" do
@@ -147,9 +144,12 @@ describe "font style support" do
147
144
  @pdf.text "In Normal Helvetica"
148
145
 
149
146
  text = PDF::Inspector::Text.analyze(@pdf.render)
150
- text.font_settings.map { |e| e[:name] }.should ==
151
- [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
152
- :Courier, :Helvetica]
147
+ expect(text.font_settings.map { |e| e[:name] }).to eq(
148
+ [
149
+ :"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
150
+ :Courier, :Helvetica
151
+ ]
152
+ )
153
153
  end
154
154
 
155
155
  it "should allow font familes to be defined in a single dfont" do
@@ -167,11 +167,11 @@ describe "font style support" do
167
167
  text = PDF::Inspector::Text.analyze(@pdf.render)
168
168
  name = text.font_settings.map { |e| e[:name] }.first.to_s
169
169
  name = name.sub(/\w+\+/, "subset+")
170
- name.should == "subset+PanicSans-Italic"
170
+ expect(name).to eq("subset+PanicSans-Italic")
171
171
  end
172
172
 
173
173
  it "should accept Pathname objects for font files" do
174
- file = Pathname.new( "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" )
174
+ file = Pathname.new("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
175
175
  @pdf.font_families["DejaVu Sans"] = {
176
176
  :normal => file
177
177
  }
@@ -182,7 +182,7 @@ describe "font style support" do
182
182
  text = PDF::Inspector::Text.analyze(@pdf.render)
183
183
  name = text.font_settings.map { |e| e[:name] }.first.to_s
184
184
  name = name.sub(/\w+\+/, "subset+")
185
- name.should == "subset+DejaVuSans"
185
+ expect(name).to eq("subset+DejaVuSans")
186
186
  end
187
187
 
188
188
  it "should accept IO objects for font files" do
@@ -197,7 +197,7 @@ describe "font style support" do
197
197
  text = PDF::Inspector::Text.analyze(@pdf.render)
198
198
  name = text.font_settings.map { |e| e[:name] }.first.to_s
199
199
  name = name.sub(/\w+\+/, "subset+")
200
- name.should == "subset+DejaVuSans"
200
+ expect(name).to eq("subset+DejaVuSans")
201
201
  end
202
202
  end
203
203
 
@@ -206,47 +206,55 @@ describe "Transactional font handling" do
206
206
 
207
207
  it "should allow setting of size directly when font is created" do
208
208
  @pdf.font "Courier", :size => 16
209
- @pdf.font_size.should == 16
209
+ expect(@pdf.font_size).to eq(16)
210
210
  end
211
211
 
212
212
  it "should allow temporary setting of a new font using a transaction" do
213
213
  @pdf.font "Helvetica", :size => 12
214
214
 
215
215
  @pdf.font "Courier", :size => 16 do
216
- @pdf.font.name.should == "Courier"
217
- @pdf.font_size.should == 16
216
+ expect(@pdf.font.name).to eq("Courier")
217
+ expect(@pdf.font_size).to eq(16)
218
218
  end
219
219
 
220
- @pdf.font.name.should == "Helvetica"
221
- @pdf.font_size.should == 12
220
+ expect(@pdf.font.name).to eq("Helvetica")
221
+ expect(@pdf.font_size).to eq(12)
222
222
  end
223
223
 
224
224
  it "should mask font size when using a transacation" do
225
225
  @pdf.font "Courier", :size => 16 do
226
- @pdf.font_size.should == 16
226
+ expect(@pdf.font_size).to eq(16)
227
227
  end
228
228
 
229
229
  @pdf.font "Times-Roman"
230
230
  @pdf.font "Courier"
231
231
 
232
- @pdf.font_size.should == 12
232
+ expect(@pdf.font_size).to eq(12)
233
233
  end
234
-
235
234
  end
236
235
 
237
236
  describe "Document#page_fonts" do
238
237
  before(:each) { create_pdf }
239
238
 
240
239
  it "should register fonts properly by page" do
241
- @pdf.font "Courier"; @pdf.text("hello")
242
- @pdf.font "Helvetica"; @pdf.text("hello")
243
- @pdf.font "Times-Roman"; @pdf.text("hello")
244
- ["Courier","Helvetica","Times-Roman"].each { |f|
240
+ @pdf.font "Courier"
241
+ @pdf.text("hello")
242
+
243
+ @pdf.font "Helvetica"
244
+ @pdf.text("hello")
245
+
246
+ @pdf.font "Times-Roman"
247
+ @pdf.text("hello")
248
+
249
+ ["Courier", "Helvetica", "Times-Roman"].each { |f|
245
250
  page_should_include_font(f)
246
251
  }
247
252
 
248
253
  @pdf.start_new_page
249
- @pdf.font "Helvetica"; @pdf.text("hello")
254
+
255
+ @pdf.font "Helvetica"
256
+ @pdf.text("hello")
257
+
250
258
  page_should_include_font("Helvetica")
251
259
  page_should_not_include_font("Courier")
252
260
  page_should_not_include_font("Times-Roman")
@@ -257,74 +265,69 @@ describe "Document#page_fonts" do
257
265
  end
258
266
 
259
267
  def page_should_include_font(font)
260
- page_includes_font?(font).should be_true
268
+ expect(page_includes_font?(font)).to be_true
261
269
  end
262
270
 
263
271
  def page_should_not_include_font(font)
264
- page_includes_font?(font).should be_false
272
+ expect(page_includes_font?(font)).to be_false
265
273
  end
266
-
267
274
  end
268
275
 
269
276
  describe "AFM fonts" do
270
-
271
277
  before do
272
278
  create_pdf
273
279
  @times = @pdf.find_font "Times-Roman"
274
280
  end
275
281
 
276
282
  it "should calculate string width taking into account accented characters" do
277
- input = win1252_string("\xE9")# é in win-1252
278
- @times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
283
+ input = win1252_string("\xE9") # é in win-1252
284
+ expect(@times.compute_width_of(input, :size => 12)).to eq(@times.compute_width_of("e", :size => 12))
279
285
  end
280
286
 
281
287
  it "should calculate string width taking into account kerning pairs" do
282
- @times.compute_width_of(win1252_string("To"), :size => 12).should == 13.332
283
- @times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true).should == 12.372
288
+ expect(@times.compute_width_of(win1252_string("To"), :size => 12)).to eq(13.332)
289
+ expect(@times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true)).to eq(12.372)
284
290
 
285
291
  input = win1252_string("T\xF6") # Tö in win-1252
286
- @times.compute_width_of(input, :size => 12, :kerning => true).should == 12.372
292
+ expect(@times.compute_width_of(input, :size => 12, :kerning => true)).to eq(12.372)
287
293
  end
288
294
 
289
295
  it "should encode text without kerning by default" do
290
- @times.encode_text(win1252_string("To")).should == [[0, "To"]]
296
+ expect(@times.encode_text(win1252_string("To"))).to eq([[0, "To"]])
291
297
  input = win1252_string("T\xE9l\xE9") # Télé in win-1252
292
- @times.encode_text(input).should == [[0, input]]
293
- @times.encode_text(win1252_string("Technology")).should == [[0, "Technology"]]
294
- @times.encode_text(win1252_string("Technology...")).should == [[0, "Technology..."]]
298
+ expect(@times.encode_text(input)).to eq([[0, input]])
299
+ expect(@times.encode_text(win1252_string("Technology"))).to eq([[0, "Technology"]])
300
+ expect(@times.encode_text(win1252_string("Technology..."))).to eq([[0, "Technology..."]])
295
301
  end
296
302
 
297
303
  it "should encode text with kerning if requested" do
298
- @times.encode_text(win1252_string("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
304
+ expect(@times.encode_text(win1252_string("To"), :kerning => true)).to eq([[0, ["T", 80, "o"]]])
299
305
  input = win1252_string("T\xE9l\xE9") # Télé in win-1252
300
306
  output = win1252_string("\xE9l\xE9") # élé in win-1252
301
- @times.encode_text(input, :kerning => true).should == [[0, ["T", 70, output]]]
302
- @times.encode_text(win1252_string("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
303
- @times.encode_text(win1252_string("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
307
+ expect(@times.encode_text(input, :kerning => true)).to eq([[0, ["T", 70, output]]])
308
+ expect(@times.encode_text(win1252_string("Technology"), :kerning => true)).to eq([[0, ["T", 70, "echnology"]]])
309
+ expect(@times.encode_text(win1252_string("Technology..."), :kerning => true)).to eq([[0, ["T", 70, "echnology", 65, "..."]]])
304
310
  end
305
311
 
306
312
  describe "when normalizing encoding" do
307
-
308
313
  it "should not modify the original string when normalize_encoding() is used" do
309
314
  original = "Foo"
310
315
  normalized = @times.normalize_encoding(original)
311
- original.equal?(normalized).should be_false
316
+ expect(original.equal?(normalized)).to be_false
312
317
  end
313
318
 
314
319
  it "should modify the original string when normalize_encoding!() is used" do
315
320
  original = "Foo"
316
321
  normalized = @times.normalize_encoding!(original)
317
- original.equal?(normalized).should be_true
322
+ expect(original.equal?(normalized)).to be_true
318
323
  end
319
-
320
324
  end
321
325
 
322
326
  it "should omit /Encoding for symbolic fonts" do
323
327
  zapf = @pdf.find_font "ZapfDingbats"
324
328
  font_dict = zapf.send(:register, nil)
325
- font_dict.data[:Encoding].should == nil
329
+ expect(font_dict.data[:Encoding]).to be_nil
326
330
  end
327
-
328
331
  end
329
332
 
330
333
  describe "#glyph_present" do
@@ -332,63 +335,62 @@ describe "#glyph_present" do
332
335
 
333
336
  it "should return true when present in an AFM font" do
334
337
  font = @pdf.find_font("Helvetica")
335
- font.glyph_present?("H").should be_true
338
+ expect(font.glyph_present?("H")).to be_true
336
339
  end
337
340
 
338
341
  it "should return false when absent in an AFM font" do
339
342
  font = @pdf.find_font("Helvetica")
340
- font.glyph_present?("再").should be_false
343
+ expect(font.glyph_present?("再")).to be_false
341
344
  end
342
345
 
343
346
  it "should return true when present in a TTF font" do
344
347
  font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
345
- font.glyph_present?("H").should be_true
348
+ expect(font.glyph_present?("H")).to be_true
346
349
  end
347
350
 
348
351
  it "should return false when absent in a TTF font" do
349
352
  font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
350
- font.glyph_present?("再").should be_false
353
+ expect(font.glyph_present?("再")).to be_false
351
354
 
352
355
  font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
353
- font.glyph_present?("€").should be_false
356
+ expect(font.glyph_present?("€")).to be_false
354
357
  end
355
358
  end
356
359
 
357
360
  describe "TTF fonts" do
358
-
359
361
  before do
360
362
  create_pdf
361
363
  @font = @pdf.find_font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
362
364
  end
363
365
 
364
366
  it "should calculate string width taking into account accented characters" do
365
- @font.compute_width_of("é", :size => 12).should == @font.compute_width_of("e", :size => 12)
367
+ expect(@font.compute_width_of("é", :size => 12)).to eq(@font.compute_width_of("e", :size => 12))
366
368
  end
367
369
 
368
370
  it "should calculate string width taking into account kerning pairs" do
369
- @font.compute_width_of("To", :size => 12).should be_within(0.01).of(14.65)
370
- @font.compute_width_of("To", :size => 12, :kerning => true).should be_within(0.01).of(12.61)
371
+ expect(@font.compute_width_of("To", :size => 12)).to be_within(0.01).of(14.65)
372
+ expect(@font.compute_width_of("To", :size => 12, :kerning => true)).to be_within(0.01).of(12.61)
371
373
  end
372
374
 
373
375
  it "should encode text without kerning by default" do
374
- @font.encode_text("To").should == [[0, "To"]]
376
+ expect(@font.encode_text("To")).to eq([[0, "To"]])
375
377
 
376
378
  tele = "T\216l\216"
377
379
  result = @font.encode_text("Télé")
378
- result.length.should == 1
379
- result[0][0].should == 0
380
- result[0][1].bytes.to_a.should == tele.bytes.to_a
380
+ expect(result.length).to eq(1)
381
+ expect(result[0][0]).to eq(0)
382
+ expect(result[0][1].bytes.to_a).to eq(tele.bytes.to_a)
381
383
 
382
- @font.encode_text("Technology").should == [[0, "Technology"]]
383
- @font.encode_text("Technology...").should == [[0, "Technology..."]]
384
- @font.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
384
+ expect(@font.encode_text("Technology")).to eq([[0, "Technology"]])
385
+ expect(@font.encode_text("Technology...")).to eq([[0, "Technology..."]])
386
+ expect(@font.encode_text("Teχnology...")).to eq([[0, "Te"], [1, "!"], [0, "nology..."]])
385
387
  end
386
388
 
387
389
  it "should encode text with kerning if requested" do
388
- @font.encode_text("To", :kerning => true).should == [[0, ["T", 169.921875, "o"]]]
389
- @font.encode_text("Technology", :kerning => true).should == [[0, ["T", 169.921875, "echnology"]]]
390
- @font.encode_text("Technology...", :kerning => true).should == [[0, ["T", 169.921875, "echnology", 142.578125, "..."]]]
391
- @font.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 169.921875, "e"]], [1, "!"], [0, ["nology", 142.578125, "..."]]]
390
+ expect(@font.encode_text("To", :kerning => true)).to eq([[0, ["T", 169.921875, "o"]]])
391
+ expect(@font.encode_text("Technology", :kerning => true)).to eq([[0, ["T", 169.921875, "echnology"]]])
392
+ expect(@font.encode_text("Technology...", :kerning => true)).to eq([[0, ["T", 169.921875, "echnology", 142.578125, "..."]]])
393
+ expect(@font.encode_text("Teχnology...", :kerning => true)).to eq([[0, ["T", 169.921875, "e"]], [1, "!"], [0, ["nology", 142.578125, "..."]]])
392
394
  end
393
395
 
394
396
  it "should use the ascender, descender, and cap height from the TTF verbatim" do
@@ -399,24 +401,23 @@ describe "TTF fonts" do
399
401
 
400
402
  # Pull out the embedded font descriptor
401
403
  descriptor = ref.data[:FontDescriptor].data
402
- descriptor[:Ascent].should == 759
403
- descriptor[:Descent].should == -240
404
- descriptor[:CapHeight].should == 759
404
+ expect(descriptor[:Ascent]).to eq(759)
405
+ expect(descriptor[:Descent]).to eq(-240)
406
+ expect(descriptor[:CapHeight]).to eq(759)
405
407
  end
406
408
 
407
409
  describe "when normalizing encoding" do
408
410
  it "should not modify the original string when normalize_encoding() is used" do
409
411
  original = "Foo"
410
412
  normalized = @font.normalize_encoding(original)
411
- original.equal?(normalized).should be_false
413
+ expect(original.equal?(normalized)).to be_false
412
414
  end
413
415
 
414
416
  it "should modify the original string when normalize_encoding!() is used" do
415
417
  original = "Foo"
416
418
  normalized = @font.normalize_encoding!(original)
417
- original.equal?(normalized).should be_true
419
+ expect(original.equal?(normalized)).to be_true
418
420
  end
419
-
420
421
  end
421
422
  end
422
423
 
@@ -428,34 +429,34 @@ describe "DFont fonts" do
428
429
 
429
430
  it "should list all named fonts" do
430
431
  list = Prawn::Font::DFont.named_fonts(@file)
431
- list.sort.should == %w(PanicSans PanicSans-Italic PanicSans-Bold PanicSans-BoldItalic).sort
432
+ expect(list.sort).to eq(%w(PanicSans PanicSans-Italic PanicSans-Bold PanicSans-BoldItalic).sort)
432
433
  end
433
434
 
434
435
  it "should count the number of fonts in the file" do
435
- Prawn::Font::DFont.font_count(@file).should == 4
436
+ expect(Prawn::Font::DFont.font_count(@file)).to eq(4)
436
437
  end
437
438
 
438
439
  it "should default selected font to the first one if not specified" do
439
440
  font = @pdf.find_font(@file)
440
- font.basename.should == "PanicSans"
441
+ expect(font.basename).to eq("PanicSans")
441
442
  end
442
443
 
443
444
  it "should allow font to be selected by index" do
444
445
  font = @pdf.find_font(@file, :font => 2)
445
- font.basename.should == "PanicSans-Italic"
446
+ expect(font.basename).to eq("PanicSans-Italic")
446
447
  end
447
448
 
448
449
  it "should allow font to be selected by name" do
449
450
  font = @pdf.find_font(@file, :font => "PanicSans-BoldItalic")
450
- font.basename.should == "PanicSans-BoldItalic"
451
+ expect(font.basename).to eq("PanicSans-BoldItalic")
451
452
  end
452
453
 
453
454
  it "should cache font object based on selected font" do
454
455
  f1 = @pdf.find_font(@file, :font => "PanicSans")
455
456
  f2 = @pdf.find_font(@file, :font => "PanicSans-Bold")
456
- f2.object_id.should_not == f1.object_id
457
- @pdf.find_font(@file, :font => "PanicSans").object_id.should == f1.object_id
458
- @pdf.find_font(@file, :font => "PanicSans-Bold").object_id.should == f2.object_id
457
+ expect(f2.object_id).not_to eq(f1.object_id)
458
+ expect(@pdf.find_font(@file, :font => "PanicSans").object_id).to eq(f1.object_id)
459
+ expect(@pdf.find_font(@file, :font => "PanicSans-Bold").object_id).to eq(f2.object_id)
459
460
  end
460
461
  end
461
462
 
@@ -463,12 +464,12 @@ describe "#character_count(text)" do
463
464
  it "should work on TTF fonts" do
464
465
  create_pdf
465
466
  @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
466
- @pdf.font.character_count("こんにちは世界").should == 7
467
- @pdf.font.character_count("Hello, world!").should == 13
467
+ expect(@pdf.font.character_count("こんにちは世界")).to eq(7)
468
+ expect(@pdf.font.character_count("Hello, world!")).to eq(13)
468
469
  end
469
470
 
470
471
  it "should work on AFM fonts" do
471
472
  create_pdf
472
- @pdf.font.character_count("Hello, world!").should == 13
473
+ expect(@pdf.font.character_count("Hello, world!")).to eq(13)
473
474
  end
474
475
  end