prawn 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/COPYING +2 -2
  4. data/Gemfile +8 -15
  5. data/LICENSE +1 -1
  6. data/Rakefile +25 -16
  7. data/data/images/16bit.alpha +0 -0
  8. data/data/images/16bit.color +0 -0
  9. data/data/images/dice.alpha +0 -0
  10. data/data/images/dice.color +0 -0
  11. data/data/images/indexed_color.dat +0 -0
  12. data/data/images/indexed_color.png +0 -0
  13. data/data/images/license.md +8 -0
  14. data/data/images/page_white_text.alpha +0 -0
  15. data/data/images/page_white_text.color +0 -0
  16. data/lib/prawn.rb +85 -23
  17. data/lib/prawn/document.rb +134 -116
  18. data/lib/prawn/document/bounding_box.rb +33 -4
  19. data/lib/prawn/document/column_box.rb +18 -6
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +24 -23
  22. data/lib/prawn/document/span.rb +12 -10
  23. data/lib/prawn/encoding.rb +8 -9
  24. data/lib/prawn/errors.rb +13 -32
  25. data/lib/prawn/font.rb +137 -105
  26. data/lib/prawn/font/afm.rb +76 -32
  27. data/lib/prawn/font/dfont.rb +4 -3
  28. data/lib/prawn/font/ttf.rb +33 -25
  29. data/lib/prawn/font_metric_cache.rb +47 -0
  30. data/lib/prawn/graphics.rb +177 -57
  31. data/lib/prawn/graphics/cap_style.rb +4 -3
  32. data/lib/prawn/graphics/color.rb +5 -4
  33. data/lib/prawn/graphics/dash.rb +53 -31
  34. data/lib/prawn/graphics/join_style.rb +9 -7
  35. data/lib/prawn/graphics/patterns.rb +4 -15
  36. data/lib/prawn/graphics/transformation.rb +10 -9
  37. data/lib/prawn/graphics/transparency.rb +3 -1
  38. data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
  39. data/lib/prawn/image_handler.rb +42 -0
  40. data/lib/prawn/images.rb +58 -54
  41. data/lib/prawn/images/image.rb +6 -22
  42. data/lib/prawn/images/jpg.rb +20 -14
  43. data/lib/prawn/images/png.rb +58 -121
  44. data/lib/prawn/layout.rb +12 -15
  45. data/lib/prawn/measurement_extensions.rb +10 -6
  46. data/lib/prawn/measurements.rb +27 -21
  47. data/lib/prawn/outline.rb +108 -147
  48. data/lib/prawn/repeater.rb +10 -8
  49. data/lib/prawn/security.rb +59 -40
  50. data/lib/prawn/security/arcfour.rb +52 -0
  51. data/lib/prawn/soft_mask.rb +4 -4
  52. data/lib/prawn/stamp.rb +5 -3
  53. data/lib/prawn/table.rb +83 -60
  54. data/lib/prawn/table/cell.rb +17 -21
  55. data/lib/prawn/table/cell/image.rb +2 -3
  56. data/lib/prawn/table/cell/in_table.rb +8 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +5 -0
  58. data/lib/prawn/table/cell/subtable.rb +3 -2
  59. data/lib/prawn/table/cell/text.rb +14 -12
  60. data/lib/prawn/table/cells.rb +58 -14
  61. data/lib/prawn/table/column_width_calculator.rb +61 -0
  62. data/lib/prawn/text.rb +27 -26
  63. data/lib/prawn/text/box.rb +12 -6
  64. data/lib/prawn/text/formatted.rb +5 -4
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +85 -57
  67. data/lib/prawn/text/formatted/fragment.rb +11 -11
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +11 -4
  70. data/lib/prawn/text/formatted/wrap.rb +156 -0
  71. data/lib/prawn/utilities.rb +5 -3
  72. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  73. data/manual/document_and_page_options/metadata.rb +3 -3
  74. data/manual/document_and_page_options/page_size.rb +2 -2
  75. data/manual/document_and_page_options/print_scaling.rb +20 -0
  76. data/manual/example_file.rb +2 -7
  77. data/manual/example_helper.rb +62 -81
  78. data/manual/graphics/common_lines.rb +2 -0
  79. data/manual/graphics/helper.rb +11 -4
  80. data/manual/graphics/stroke_dash.rb +19 -14
  81. data/manual/manual/cover.rb +16 -0
  82. data/manual/manual/manual.rb +1 -5
  83. data/manual/text/fallback_fonts.rb +4 -4
  84. data/manual/text/formatted_text.rb +5 -5
  85. data/manual/text/inline.rb +2 -4
  86. data/manual/text/registering_families.rb +12 -12
  87. data/manual/text/single_usage.rb +4 -4
  88. data/manual/text/text.rb +0 -2
  89. data/prawn.gemspec +21 -13
  90. data/spec/acceptance/png.rb +23 -0
  91. data/spec/annotations_spec.rb +16 -32
  92. data/spec/bounding_box_spec.rb +22 -5
  93. data/spec/cell_spec.rb +49 -5
  94. data/spec/column_box_spec.rb +32 -0
  95. data/spec/destinations_spec.rb +5 -5
  96. data/spec/document_spec.rb +112 -118
  97. data/spec/extensions/encoding_helpers.rb +5 -2
  98. data/spec/font_metric_cache_spec.rb +52 -0
  99. data/spec/font_spec.rb +121 -120
  100. data/spec/formatted_text_arranger_spec.rb +24 -24
  101. data/spec/formatted_text_box_spec.rb +31 -32
  102. data/spec/formatted_text_fragment_spec.rb +2 -2
  103. data/spec/graphics_spec.rb +63 -45
  104. data/spec/grid_spec.rb +24 -13
  105. data/spec/image_handler_spec.rb +54 -0
  106. data/spec/images_spec.rb +34 -21
  107. data/spec/inline_formatted_text_parser_spec.rb +69 -20
  108. data/spec/jpg_spec.rb +3 -3
  109. data/spec/line_wrap_spec.rb +25 -14
  110. data/spec/measurement_units_spec.rb +5 -5
  111. data/spec/outline_spec.rb +68 -64
  112. data/spec/png_spec.rb +15 -18
  113. data/spec/reference_spec.rb +2 -82
  114. data/spec/repeater_spec.rb +1 -1
  115. data/spec/security_spec.rb +41 -9
  116. data/spec/soft_mask_spec.rb +0 -40
  117. data/spec/span_spec.rb +6 -11
  118. data/spec/spec_helper.rb +20 -2
  119. data/spec/stamp_spec.rb +19 -20
  120. data/spec/stroke_styles_spec.rb +31 -13
  121. data/spec/table/span_dummy_spec.rb +17 -0
  122. data/spec/table_spec.rb +268 -43
  123. data/spec/text_at_spec.rb +13 -27
  124. data/spec/text_box_spec.rb +35 -30
  125. data/spec/text_spec.rb +56 -40
  126. data/spec/transparency_spec.rb +5 -5
  127. metadata +214 -217
  128. data/README.md +0 -98
  129. data/data/fonts/Action Man.dfont +0 -0
  130. data/data/fonts/Activa.ttf +0 -0
  131. data/data/fonts/Chalkboard.ttf +0 -0
  132. data/data/fonts/DejaVuSans.ttf +0 -0
  133. data/data/fonts/Dustismo_Roman.ttf +0 -0
  134. data/data/fonts/comicsans.ttf +0 -0
  135. data/data/fonts/gkai00mp.ttf +0 -0
  136. data/data/images/16bit.dat +0 -0
  137. data/data/images/barcode_issue.png +0 -0
  138. data/data/images/dice.dat +0 -0
  139. data/data/images/page_white_text.dat +0 -0
  140. data/data/images/rails.dat +0 -0
  141. data/data/images/rails.png +0 -0
  142. data/lib/prawn/compatibility.rb +0 -87
  143. data/lib/prawn/core.rb +0 -87
  144. data/lib/prawn/core/annotations.rb +0 -61
  145. data/lib/prawn/core/byte_string.rb +0 -9
  146. data/lib/prawn/core/destinations.rb +0 -90
  147. data/lib/prawn/core/document_state.rb +0 -79
  148. data/lib/prawn/core/literal_string.rb +0 -16
  149. data/lib/prawn/core/name_tree.rb +0 -177
  150. data/lib/prawn/core/object_store.rb +0 -320
  151. data/lib/prawn/core/page.rb +0 -212
  152. data/lib/prawn/core/pdf_object.rb +0 -125
  153. data/lib/prawn/core/reference.rb +0 -119
  154. data/lib/prawn/core/text.rb +0 -268
  155. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  156. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
  157. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  158. data/lib/prawn/document/page_geometry.rb +0 -136
  159. data/lib/prawn/document/snapshot.rb +0 -89
  160. data/manual/manual/foreword.rb +0 -13
  161. data/manual/templates/full_template.rb +0 -23
  162. data/manual/templates/page_template.rb +0 -47
  163. data/manual/templates/templates.rb +0 -26
  164. data/manual/text/group.rb +0 -29
  165. data/spec/name_tree_spec.rb +0 -112
  166. data/spec/object_store_spec.rb +0 -170
  167. data/spec/pdf_object_spec.rb +0 -172
  168. data/spec/snapshot_spec.rb +0 -186
  169. data/spec/template_spec.rb +0 -351
@@ -1,6 +1,9 @@
1
1
  module EncodingHelpers
2
2
  def win1252_string(str)
3
- ruby_19 { str.force_encoding("Windows-1252") }
4
- str
3
+ str.force_encoding(Encoding::Windows_1252)
4
+ end
5
+
6
+ def bin_string(str)
7
+ str.force_encoding(Encoding::ASCII_8BIT)
5
8
  end
6
9
  end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require 'pathname'
5
+
6
+ describe "Font metrics caching" do
7
+ let(:document) { Prawn::Document.new }
8
+
9
+ subject { Prawn::FontMetricCache.new( document ) }
10
+
11
+ it "should start with an empty cache" do
12
+ subject.instance_variable_get( :@cache ).should be_empty
13
+ end
14
+
15
+ it "should cache the width of the provided string" do
16
+ subject.width_of('M', {})
17
+
18
+ subject.instance_variable_get( :@cache ).should have(1).entry
19
+ end
20
+
21
+ it "should only cache a single copy of the same string" do
22
+ subject.width_of('M', {})
23
+ subject.width_of('M', {})
24
+
25
+ subject.instance_variable_get( :@cache ).should have(1).entry
26
+ end
27
+
28
+ it "should cache different copies for different strings" do
29
+ subject.width_of('M', {})
30
+ subject.width_of('W', {})
31
+
32
+ subject.instance_variable_get( :@cache ).should have(2).entries
33
+ end
34
+
35
+ it "should cache different copies of the same string with different font sizes" do
36
+ subject.width_of('M', {})
37
+
38
+ document.font_size 24
39
+ subject.width_of('M', {})
40
+
41
+ subject.instance_variable_get( :@cache ).should have(2).entries
42
+ end
43
+
44
+ it "should cache different copies of the same string with different fonts" do
45
+ subject.width_of('M', {})
46
+
47
+ document.font 'Courier'
48
+ subject.width_of('M', {})
49
+
50
+ subject.instance_variable_get( :@cache ).should have(2).entries
51
+ end
52
+ end
@@ -12,6 +12,32 @@ describe "Font behavior" do
12
12
 
13
13
  end
14
14
 
15
+ describe "Font objects" do
16
+
17
+ it "should be equal" do
18
+ font1 = Prawn::Document.new.font
19
+ font2 = Prawn::Document.new.font
20
+
21
+ font1.should eql( font2 )
22
+ end
23
+
24
+ it "should always be the same key" do
25
+ font1 = Prawn::Document.new.font
26
+ font2 = Prawn::Document.new.font
27
+
28
+ hash = Hash.new
29
+
30
+ hash[ font1 ] = "Original"
31
+ hash[ font2 ] = "Overwritten"
32
+
33
+ hash.size.should == 1
34
+
35
+ hash[ font1 ].should == "Overwritten"
36
+ hash[ font2 ].should == "Overwritten"
37
+ end
38
+
39
+ end
40
+
15
41
  describe "#width_of" do
16
42
  it "should take character spacing into account" do
17
43
  create_pdf
@@ -38,7 +64,7 @@ describe "#width_of" do
38
64
  @pdf.font("Helvetica", :style => :bold) {
39
65
  @bold_hello = @pdf.width_of("hello")
40
66
  }
41
-
67
+
42
68
  inline_bold_hello.should be > normal_hello
43
69
  inline_bold_hello.should == @bold_hello
44
70
  end
@@ -53,6 +79,12 @@ describe "#width_of" do
53
79
 
54
80
  styled_bold_hello.should == @bold_hello
55
81
  end
82
+
83
+ it "should not treat minus as if it were a hyphen", :issue => 578 do
84
+ create_pdf
85
+
86
+ @pdf.width_of("-0.75").should be < @pdf.width_of("25.00")
87
+ end
56
88
  end
57
89
 
58
90
  describe "#font_size" do
@@ -65,86 +97,86 @@ end
65
97
 
66
98
  describe "font style support" do
67
99
  before(:each) { create_pdf }
68
-
100
+
69
101
  it "should complain if there is no @current_page" do
70
102
  pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
71
103
 
72
104
  lambda{ pdf_without_page.font "Helvetica" }.
73
105
  should raise_error(Prawn::Errors::NotOnPage)
74
106
  end
75
-
76
- it "should allow specifying font style by style name and font family" do
107
+
108
+ it "should allow specifying font style by style name and font family" do
77
109
  @pdf.font "Courier", :style => :bold
78
- @pdf.text "In Courier bold"
79
-
110
+ @pdf.text "In Courier bold"
111
+
80
112
  @pdf.font "Courier", :style => :bold_italic
81
- @pdf.text "In Courier bold-italic"
82
-
113
+ @pdf.text "In Courier bold-italic"
114
+
83
115
  @pdf.font "Courier", :style => :italic
84
- @pdf.text "In Courier italic"
85
-
116
+ @pdf.text "In Courier italic"
117
+
86
118
  @pdf.font "Courier", :style => :normal
87
- @pdf.text "In Normal Courier"
88
-
119
+ @pdf.text "In Normal Courier"
120
+
89
121
  @pdf.font "Helvetica"
90
- @pdf.text "In Normal Helvetica"
91
-
122
+ @pdf.text "In Normal Helvetica"
123
+
92
124
  text = PDF::Inspector::Text.analyze(@pdf.render)
93
- text.font_settings.map { |e| e[:name] }.should ==
94
- [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
125
+ text.font_settings.map { |e| e[:name] }.should ==
126
+ [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
95
127
  :Courier, :Helvetica]
96
128
  end
97
129
 
98
130
  it "should allow font familes to be defined in a single dfont" do
99
- file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
100
- @pdf.font_families["Action Man"] = {
101
- :normal => { :file => file, :font => "ActionMan" },
102
- :italic => { :file => file, :font => "ActionMan-Italic" },
103
- :bold => { :file => file, :font => "ActionMan-Bold" },
104
- :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
131
+ file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
132
+ @pdf.font_families["Panic Sans"] = {
133
+ :normal => { :file => file, :font => "PanicSans" },
134
+ :italic => { :file => file, :font => "PanicSans-Italic" },
135
+ :bold => { :file => file, :font => "PanicSans-Bold" },
136
+ :bold_italic => { :file => file, :font => "PanicSans-BoldItalic" }
105
137
  }
106
138
 
107
- @pdf.font "Action Man", :style => :italic
108
- @pdf.text "In ActionMan-Italic"
139
+ @pdf.font "Panic Sans", :style => :italic
140
+ @pdf.text "In PanicSans-Italic"
109
141
 
110
142
  text = PDF::Inspector::Text.analyze(@pdf.render)
111
143
  name = text.font_settings.map { |e| e[:name] }.first.to_s
112
144
  name = name.sub(/\w+\+/, "subset+")
113
- name.should == "subset+ActionMan-Italic"
145
+ name.should == "subset+PanicSans-Italic"
114
146
  end
115
147
 
116
148
  it "should accept Pathname objects for font files" do
117
- file = Pathname.new( "#{Prawn::DATADIR}/fonts/Chalkboard.ttf" )
118
- @pdf.font_families["Chalkboard"] = {
149
+ file = Pathname.new( "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" )
150
+ @pdf.font_families["DejaVu Sans"] = {
119
151
  :normal => file
120
152
  }
121
153
 
122
- @pdf.font "Chalkboard"
123
- @pdf.text "In Chalkboard"
154
+ @pdf.font "DejaVu Sans"
155
+ @pdf.text "In DejaVu Sans"
124
156
 
125
157
  text = PDF::Inspector::Text.analyze(@pdf.render)
126
158
  name = text.font_settings.map { |e| e[:name] }.first.to_s
127
159
  name = name.sub(/\w+\+/, "subset+")
128
- name.should == "subset+Chalkboard"
160
+ name.should == "subset+DejaVuSans"
129
161
  end
130
162
  end
131
163
 
132
164
  describe "Transactional font handling" do
133
165
  before(:each) { create_pdf }
134
-
166
+
135
167
  it "should allow setting of size directly when font is created" do
136
168
  @pdf.font "Courier", :size => 16
137
- @pdf.font_size.should == 16
169
+ @pdf.font_size.should == 16
138
170
  end
139
-
171
+
140
172
  it "should allow temporary setting of a new font using a transaction" do
141
173
  @pdf.font "Helvetica", :size => 12
142
-
174
+
143
175
  @pdf.font "Courier", :size => 16 do
144
176
  @pdf.font.name.should == "Courier"
145
177
  @pdf.font_size.should == 16
146
178
  end
147
-
179
+
148
180
  @pdf.font.name.should == "Helvetica"
149
181
  @pdf.font_size.should == 12
150
182
  end
@@ -159,53 +191,53 @@ describe "Transactional font handling" do
159
191
 
160
192
  @pdf.font_size.should == 12
161
193
  end
162
-
194
+
163
195
  end
164
196
 
165
197
  describe "Document#page_fonts" do
166
- before(:each) { create_pdf }
167
-
198
+ before(:each) { create_pdf }
199
+
168
200
  it "should register fonts properly by page" do
169
201
  @pdf.font "Courier"; @pdf.text("hello")
170
202
  @pdf.font "Helvetica"; @pdf.text("hello")
171
203
  @pdf.font "Times-Roman"; @pdf.text("hello")
172
204
  ["Courier","Helvetica","Times-Roman"].each { |f|
173
205
  page_should_include_font(f)
174
- }
175
-
176
- @pdf.start_new_page
206
+ }
207
+
208
+ @pdf.start_new_page
177
209
  @pdf.font "Helvetica"; @pdf.text("hello")
178
210
  page_should_include_font("Helvetica")
179
211
  page_should_not_include_font("Courier")
180
212
  page_should_not_include_font("Times-Roman")
181
- end
182
-
213
+ end
214
+
183
215
  def page_includes_font?(font)
184
216
  @pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
185
- end
186
-
187
- def page_should_include_font(font)
217
+ end
218
+
219
+ def page_should_include_font(font)
188
220
  page_includes_font?(font).should be_true
189
- end
190
-
221
+ end
222
+
191
223
  def page_should_not_include_font(font)
192
224
  page_includes_font?(font).should be_false
193
225
  end
194
-
226
+
195
227
  end
196
-
228
+
197
229
  describe "AFM fonts" do
198
-
230
+
199
231
  before do
200
232
  create_pdf
201
233
  @times = @pdf.find_font "Times-Roman"
202
234
  end
203
-
235
+
204
236
  it "should calculate string width taking into account accented characters" do
205
237
  input = win1252_string("\xE9")# é in win-1252
206
238
  @times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
207
239
  end
208
-
240
+
209
241
  it "should calculate string width taking into account kerning pairs" do
210
242
  @times.compute_width_of(win1252_string("To"), :size => 12).should == 13.332
211
243
  @times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true).should == 12.372
@@ -252,7 +284,7 @@ describe "AFM fonts" do
252
284
  font_dict = zapf.send(:register, nil)
253
285
  font_dict.data[:Encoding].should == nil
254
286
  end
255
-
287
+
256
288
  end
257
289
 
258
290
  describe "#glyph_present" do
@@ -269,12 +301,12 @@ describe "#glyph_present" do
269
301
  end
270
302
 
271
303
  it "should return true when present in a TTF font" do
272
- font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
304
+ font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
273
305
  font.glyph_present?("H").should be_true
274
306
  end
275
307
 
276
308
  it "should return false when absent in a TTF font" do
277
- font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
309
+ font = @pdf.find_font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
278
310
  font.glyph_present?("再").should be_false
279
311
 
280
312
  font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
@@ -283,111 +315,80 @@ describe "#glyph_present" do
283
315
  end
284
316
 
285
317
  describe "TTF fonts" do
286
-
318
+
287
319
  before do
288
320
  create_pdf
289
- @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf"
321
+ @font = @pdf.find_font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
290
322
  end
291
-
323
+
292
324
  it "should calculate string width taking into account accented characters" do
293
- @activa.compute_width_of("é", :size => 12).should == @activa.compute_width_of("e", :size => 12)
325
+ @font.compute_width_of("é", :size => 12).should == @font.compute_width_of("e", :size => 12)
294
326
  end
295
-
327
+
296
328
  it "should calculate string width taking into account kerning pairs" do
297
- @activa.compute_width_of("To", :size => 12).should == 15.228
298
- @activa.compute_width_of("To", :size => 12, :kerning => true).should == 12.996
329
+ @font.compute_width_of("To", :size => 12).should be_within(0.01).of(14.65)
330
+ @font.compute_width_of("To", :size => 12, :kerning => true).should be_within(0.01).of(12.61)
299
331
  end
300
-
332
+
301
333
  it "should encode text without kerning by default" do
302
- @activa.encode_text("To").should == [[0, "To"]]
334
+ @font.encode_text("To").should == [[0, "To"]]
303
335
 
304
336
  tele = "T\216l\216"
305
- result = @activa.encode_text("Télé")
337
+ result = @font.encode_text("Télé")
306
338
  result.length.should == 1
307
339
  result[0][0].should == 0
308
340
  result[0][1].bytes.to_a.should == tele.bytes.to_a
309
341
 
310
- @activa.encode_text("Technology").should == [[0, "Technology"]]
311
- @activa.encode_text("Technology...").should == [[0, "Technology..."]]
312
- @activa.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
342
+ @font.encode_text("Technology").should == [[0, "Technology"]]
343
+ @font.encode_text("Technology...").should == [[0, "Technology..."]]
344
+ @font.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
313
345
  end
314
346
 
315
347
  it "should encode text with kerning if requested" do
316
- @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
317
- @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
318
- @activa.encode_text("Technology", :kerning => true).should == [[0, ["T", 186.0, "echnology"]]]
319
- @activa.encode_text("Technology...", :kerning => true).should == [[0, ["T", 186.0, "echnology", 88.0, "..."]]]
320
- @activa.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 186.0, "e"]], [1, "!"], [0, ["nology", 88.0, "..."]]]
348
+ @font.encode_text("To", :kerning => true).should == [[0, ["T", 169.921875, "o"]]]
349
+ @font.encode_text("Technology", :kerning => true).should == [[0, ["T", 169.921875, "echnology"]]]
350
+ @font.encode_text("Technology...", :kerning => true).should == [[0, ["T", 169.921875, "echnology", 142.578125, "..."]]]
351
+ @font.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 169.921875, "e"]], [1, "!"], [0, ["nology", 142.578125, "..."]]]
321
352
  end
322
353
 
323
354
  it "should use the ascender, descender, and cap height from the TTF verbatim" do
324
355
  # These metrics are relative to the font's own bbox. They should not be
325
356
  # scaled with font size.
326
357
  ref = @pdf.ref!({})
327
- @activa.send :embed, ref, 0
358
+ @font.send :embed, ref, 0
328
359
 
329
360
  # Pull out the embedded font descriptor
330
361
  descriptor = ref.data[:FontDescriptor].data
331
- descriptor[:Ascent].should == 804
332
- descriptor[:Descent].should == -195
333
- descriptor[:CapHeight].should == 804
362
+ descriptor[:Ascent].should == 759
363
+ descriptor[:Descent].should == -240
364
+ descriptor[:CapHeight].should == 759
334
365
  end
335
366
 
336
367
  describe "when normalizing encoding" do
337
-
338
368
  it "should not modify the original string when normalize_encoding() is used" do
339
369
  original = "Foo"
340
- normalized = @activa.normalize_encoding(original)
370
+ normalized = @font.normalize_encoding(original)
341
371
  original.equal?(normalized).should be_false
342
372
  end
343
373
 
344
374
  it "should modify the original string when normalize_encoding!() is used" do
345
375
  original = "Foo"
346
- normalized = @activa.normalize_encoding!(original)
376
+ normalized = @font.normalize_encoding!(original)
347
377
  original.equal?(normalized).should be_true
348
378
  end
349
379
 
350
380
  end
351
-
352
- describe "when used with snapshots or transactions" do
353
-
354
- it "should allow TTF fonts to be used alongside document transactions" do
355
- lambda {
356
- Prawn::Document.new do
357
- font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
358
- text "Hi there"
359
- transaction { text "Nice, thank you" }
360
- end
361
- }.should_not raise_error
362
- end
363
-
364
- it "should allow TTF fonts to be used inside transactions" do
365
- pdf = Prawn::Document.new do
366
- transaction do
367
- font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
368
- text "Hi there"
369
- end
370
- end
371
-
372
- text = PDF::Inspector::Text.analyze(pdf.render)
373
- name = text.font_settings.map { |e| e[:name] }.first.to_s
374
- name = name.sub(/\w+\+/, "subset+")
375
- name.should == "subset+DejaVuSans"
376
- end
377
-
378
- end
379
-
380
381
  end
381
382
 
382
383
  describe "DFont fonts" do
383
384
  before do
384
385
  create_pdf
385
- @file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
386
+ @file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
386
387
  end
387
388
 
388
389
  it "should list all named fonts" do
389
390
  list = Prawn::Font::DFont.named_fonts(@file)
390
- list.sort.should == %w(ActionMan ActionMan-Italic ActionMan-Bold ActionMan-BoldItalic).sort
391
+ list.sort.should == %w(PanicSans PanicSans-Italic PanicSans-Bold PanicSans-BoldItalic).sort
391
392
  end
392
393
 
393
394
  it "should count the number of fonts in the file" do
@@ -396,25 +397,25 @@ describe "DFont fonts" do
396
397
 
397
398
  it "should default selected font to the first one if not specified" do
398
399
  font = @pdf.find_font(@file)
399
- font.basename.should == "ActionMan"
400
+ font.basename.should == "PanicSans"
400
401
  end
401
402
 
402
403
  it "should allow font to be selected by index" do
403
404
  font = @pdf.find_font(@file, :font => 2)
404
- font.basename.should == "ActionMan-Italic"
405
+ font.basename.should == "PanicSans-Italic"
405
406
  end
406
407
 
407
408
  it "should allow font to be selected by name" do
408
- font = @pdf.find_font(@file, :font => "ActionMan-BoldItalic")
409
- font.basename.should == "ActionMan-BoldItalic"
409
+ font = @pdf.find_font(@file, :font => "PanicSans-BoldItalic")
410
+ font.basename.should == "PanicSans-BoldItalic"
410
411
  end
411
412
 
412
413
  it "should cache font object based on selected font" do
413
- f1 = @pdf.find_font(@file, :font => "ActionMan")
414
- f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
414
+ f1 = @pdf.find_font(@file, :font => "PanicSans")
415
+ f2 = @pdf.find_font(@file, :font => "PanicSans-Bold")
415
416
  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
417
+ @pdf.find_font(@file, :font => "PanicSans").object_id.should == f1.object_id
418
+ @pdf.find_font(@file, :font => "PanicSans-Bold").object_id.should == f2.object_id
418
419
  end
419
420
  end
420
421