prawn 0.15.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/COPYING +2 -2
  2. data/LICENSE +1 -1
  3. data/README.md +96 -0
  4. data/Rakefile +27 -30
  5. data/data/fonts/Action Man.dfont +0 -0
  6. data/data/fonts/Activa.ttf +0 -0
  7. data/data/fonts/Chalkboard.ttf +0 -0
  8. data/data/fonts/DejaVuSans.ttf +0 -0
  9. data/data/fonts/Dustismo_Roman.ttf +0 -0
  10. data/data/fonts/comicsans.ttf +0 -0
  11. data/data/fonts/gkai00mp.ttf +0 -0
  12. data/data/images/16bit.alpha +0 -0
  13. data/data/images/16bit.dat +0 -0
  14. data/data/images/dice.alpha +0 -0
  15. data/data/images/dice.dat +0 -0
  16. data/data/images/page_white_text.alpha +0 -0
  17. data/data/images/page_white_text.dat +0 -0
  18. data/data/images/rails.dat +0 -0
  19. data/data/images/rails.png +0 -0
  20. data/data/pdfs/nested_pages.pdf +13 -13
  21. data/lib/prawn.rb +21 -85
  22. data/lib/prawn/compatibility.rb +51 -0
  23. data/lib/prawn/core.rb +85 -0
  24. data/lib/prawn/core/annotations.rb +61 -0
  25. data/lib/prawn/core/byte_string.rb +9 -0
  26. data/lib/prawn/core/destinations.rb +90 -0
  27. data/lib/prawn/core/document_state.rb +78 -0
  28. data/lib/prawn/core/literal_string.rb +16 -0
  29. data/lib/prawn/core/name_tree.rb +177 -0
  30. data/lib/prawn/core/object_store.rb +264 -0
  31. data/lib/prawn/core/page.rb +215 -0
  32. data/lib/prawn/core/pdf_object.rb +108 -0
  33. data/lib/prawn/core/reference.rb +115 -0
  34. data/lib/prawn/core/text.rb +268 -0
  35. data/lib/prawn/core/text/formatted/arranger.rb +294 -0
  36. data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
  37. data/lib/prawn/core/text/formatted/wrap.rb +153 -0
  38. data/lib/prawn/document.rb +122 -155
  39. data/lib/prawn/document/bounding_box.rb +7 -36
  40. data/lib/prawn/document/column_box.rb +10 -38
  41. data/lib/prawn/document/graphics_state.rb +74 -11
  42. data/lib/prawn/document/internals.rb +23 -24
  43. data/lib/prawn/document/page_geometry.rb +136 -0
  44. data/lib/prawn/document/snapshot.rb +6 -7
  45. data/lib/prawn/document/span.rb +10 -12
  46. data/lib/prawn/encoding.rb +10 -9
  47. data/lib/prawn/errors.rb +30 -15
  48. data/lib/prawn/font.rb +104 -136
  49. data/lib/prawn/font/afm.rb +44 -46
  50. data/lib/prawn/font/dfont.rb +3 -4
  51. data/lib/prawn/font/ttf.rb +50 -31
  52. data/lib/prawn/graphics.rb +57 -302
  53. data/lib/prawn/graphics/cap_style.rb +3 -4
  54. data/lib/prawn/graphics/color.rb +5 -13
  55. data/lib/prawn/graphics/dash.rb +31 -53
  56. data/lib/prawn/graphics/gradient.rb +84 -0
  57. data/lib/prawn/graphics/join_style.rb +7 -9
  58. data/lib/prawn/graphics/transformation.rb +9 -10
  59. data/lib/prawn/graphics/transparency.rb +1 -3
  60. data/lib/prawn/images.rb +59 -69
  61. data/lib/prawn/images/image.rb +22 -6
  62. data/lib/prawn/images/jpg.rb +14 -20
  63. data/lib/prawn/images/png.rb +118 -61
  64. data/lib/prawn/layout.rb +15 -10
  65. data/lib/prawn/layout/grid.rb +54 -66
  66. data/lib/prawn/measurement_extensions.rb +6 -10
  67. data/lib/prawn/measurements.rb +21 -27
  68. data/lib/prawn/outline.rb +308 -6
  69. data/lib/prawn/repeater.rb +8 -10
  70. data/lib/prawn/security.rb +33 -55
  71. data/lib/prawn/security/arcfour.rb +0 -1
  72. data/lib/prawn/stamp.rb +3 -5
  73. data/lib/prawn/table.rb +60 -188
  74. data/lib/prawn/table/cell.rb +44 -272
  75. data/lib/prawn/table/cell/image.rb +3 -2
  76. data/lib/prawn/table/cell/in_table.rb +2 -4
  77. data/lib/prawn/table/cell/subtable.rb +2 -2
  78. data/lib/prawn/table/cell/text.rb +18 -41
  79. data/lib/prawn/table/cells.rb +48 -142
  80. data/lib/prawn/text.rb +25 -32
  81. data/lib/prawn/text/box.rb +6 -12
  82. data/lib/prawn/text/formatted.rb +4 -5
  83. data/lib/prawn/text/formatted/box.rb +59 -96
  84. data/lib/prawn/text/formatted/fragment.rb +23 -34
  85. data/lib/prawn/text/formatted/parser.rb +5 -15
  86. data/prawn.gemspec +13 -24
  87. data/spec/annotations_spec.rb +32 -16
  88. data/spec/bounding_box_spec.rb +17 -119
  89. data/spec/cell_spec.rb +42 -112
  90. data/spec/destinations_spec.rb +5 -5
  91. data/spec/document_spec.rb +111 -155
  92. data/spec/extensions/mocha.rb +0 -1
  93. data/spec/font_spec.rb +99 -149
  94. data/spec/formatted_text_arranger_spec.rb +43 -43
  95. data/spec/formatted_text_box_spec.rb +44 -43
  96. data/spec/formatted_text_fragment_spec.rb +8 -8
  97. data/spec/graphics_spec.rb +68 -151
  98. data/spec/grid_spec.rb +15 -26
  99. data/spec/images_spec.rb +30 -51
  100. data/spec/inline_formatted_text_parser_spec.rb +20 -69
  101. data/spec/jpg_spec.rb +4 -4
  102. data/spec/line_wrap_spec.rb +28 -28
  103. data/spec/measurement_units_spec.rb +6 -6
  104. data/spec/name_tree_spec.rb +112 -0
  105. data/spec/object_store_spec.rb +106 -17
  106. data/spec/outline_spec.rb +63 -103
  107. data/spec/pdf_object_spec.rb +170 -0
  108. data/spec/png_spec.rb +25 -25
  109. data/spec/reference_spec.rb +65 -8
  110. data/spec/repeater_spec.rb +10 -10
  111. data/spec/security_spec.rb +12 -44
  112. data/spec/snapshot_spec.rb +7 -7
  113. data/spec/span_spec.rb +15 -10
  114. data/spec/spec_helper.rb +8 -32
  115. data/spec/stamp_spec.rb +30 -29
  116. data/spec/stroke_styles_spec.rb +18 -36
  117. data/spec/table_spec.rb +111 -706
  118. data/spec/template_spec.rb +297 -0
  119. data/spec/text_at_spec.rb +33 -19
  120. data/spec/text_box_spec.rb +64 -100
  121. data/spec/text_rendering_mode_spec.rb +5 -5
  122. data/spec/text_spacing_spec.rb +4 -4
  123. data/spec/text_spec.rb +64 -84
  124. data/spec/transparency_spec.rb +5 -5
  125. metadata +290 -463
  126. checksums.yaml +0 -7
  127. data/.yardopts +0 -10
  128. data/Gemfile +0 -11
  129. data/data/images/16bit.color +0 -0
  130. data/data/images/dice.color +0 -0
  131. data/data/images/indexed_color.dat +0 -0
  132. data/data/images/indexed_color.png +0 -0
  133. data/data/images/page_white_text.color +0 -0
  134. data/lib/prawn/font_metric_cache.rb +0 -47
  135. data/lib/prawn/graphics/patterns.rb +0 -138
  136. data/lib/prawn/image_handler.rb +0 -36
  137. data/lib/prawn/soft_mask.rb +0 -96
  138. data/lib/prawn/table/cell/span_dummy.rb +0 -93
  139. data/lib/prawn/table/column_width_calculator.rb +0 -61
  140. data/lib/prawn/text/formatted/arranger.rb +0 -290
  141. data/lib/prawn/text/formatted/line_wrap.rb +0 -266
  142. data/lib/prawn/text/formatted/wrap.rb +0 -150
  143. data/lib/prawn/utilities.rb +0 -46
  144. data/manual/basic_concepts/adding_pages.rb +0 -27
  145. data/manual/basic_concepts/basic_concepts.rb +0 -34
  146. data/manual/basic_concepts/creation.rb +0 -39
  147. data/manual/basic_concepts/cursor.rb +0 -33
  148. data/manual/basic_concepts/measurement.rb +0 -25
  149. data/manual/basic_concepts/origin.rb +0 -38
  150. data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
  151. data/manual/bounding_box/bounding_box.rb +0 -39
  152. data/manual/bounding_box/bounds.rb +0 -49
  153. data/manual/bounding_box/canvas.rb +0 -24
  154. data/manual/bounding_box/creation.rb +0 -23
  155. data/manual/bounding_box/indentation.rb +0 -46
  156. data/manual/bounding_box/nesting.rb +0 -45
  157. data/manual/bounding_box/russian_boxes.rb +0 -40
  158. data/manual/bounding_box/stretchy.rb +0 -31
  159. data/manual/document_and_page_options/background.rb +0 -27
  160. data/manual/document_and_page_options/document_and_page_options.rb +0 -32
  161. data/manual/document_and_page_options/metadata.rb +0 -23
  162. data/manual/document_and_page_options/page_margins.rb +0 -38
  163. data/manual/document_and_page_options/page_size.rb +0 -34
  164. data/manual/document_and_page_options/print_scaling.rb +0 -20
  165. data/manual/example_file.rb +0 -111
  166. data/manual/example_helper.rb +0 -411
  167. data/manual/example_package.rb +0 -53
  168. data/manual/example_section.rb +0 -46
  169. data/manual/graphics/circle_and_ellipse.rb +0 -22
  170. data/manual/graphics/color.rb +0 -24
  171. data/manual/graphics/common_lines.rb +0 -30
  172. data/manual/graphics/fill_and_stroke.rb +0 -42
  173. data/manual/graphics/fill_rules.rb +0 -37
  174. data/manual/graphics/gradients.rb +0 -37
  175. data/manual/graphics/graphics.rb +0 -58
  176. data/manual/graphics/helper.rb +0 -24
  177. data/manual/graphics/line_width.rb +0 -35
  178. data/manual/graphics/lines_and_curves.rb +0 -41
  179. data/manual/graphics/polygon.rb +0 -29
  180. data/manual/graphics/rectangle.rb +0 -21
  181. data/manual/graphics/rotate.rb +0 -28
  182. data/manual/graphics/scale.rb +0 -41
  183. data/manual/graphics/soft_masks.rb +0 -46
  184. data/manual/graphics/stroke_cap.rb +0 -31
  185. data/manual/graphics/stroke_dash.rb +0 -48
  186. data/manual/graphics/stroke_join.rb +0 -30
  187. data/manual/graphics/translate.rb +0 -29
  188. data/manual/graphics/transparency.rb +0 -35
  189. data/manual/images/absolute_position.rb +0 -23
  190. data/manual/images/fit.rb +0 -21
  191. data/manual/images/horizontal.rb +0 -25
  192. data/manual/images/images.rb +0 -40
  193. data/manual/images/plain_image.rb +0 -18
  194. data/manual/images/scale.rb +0 -22
  195. data/manual/images/vertical.rb +0 -28
  196. data/manual/images/width_and_height.rb +0 -25
  197. data/manual/layout/boxes.rb +0 -27
  198. data/manual/layout/content.rb +0 -25
  199. data/manual/layout/layout.rb +0 -28
  200. data/manual/layout/simple_grid.rb +0 -23
  201. data/manual/manual/cover.rb +0 -36
  202. data/manual/manual/foreword.rb +0 -85
  203. data/manual/manual/how_to_read_this_manual.rb +0 -41
  204. data/manual/manual/manual.rb +0 -34
  205. data/manual/outline/add_subsection_to.rb +0 -61
  206. data/manual/outline/insert_section_after.rb +0 -47
  207. data/manual/outline/outline.rb +0 -32
  208. data/manual/outline/sections_and_pages.rb +0 -67
  209. data/manual/repeatable_content/page_numbering.rb +0 -54
  210. data/manual/repeatable_content/repeatable_content.rb +0 -31
  211. data/manual/repeatable_content/repeater.rb +0 -55
  212. data/manual/repeatable_content/stamp.rb +0 -41
  213. data/manual/security/encryption.rb +0 -31
  214. data/manual/security/permissions.rb +0 -38
  215. data/manual/security/security.rb +0 -28
  216. data/manual/syntax_highlight.rb +0 -52
  217. data/manual/table/basic_block.rb +0 -53
  218. data/manual/table/before_rendering_page.rb +0 -26
  219. data/manual/table/cell_border_lines.rb +0 -24
  220. data/manual/table/cell_borders_and_bg.rb +0 -31
  221. data/manual/table/cell_dimensions.rb +0 -30
  222. data/manual/table/cell_text.rb +0 -38
  223. data/manual/table/column_widths.rb +0 -30
  224. data/manual/table/content_and_subtables.rb +0 -39
  225. data/manual/table/creation.rb +0 -27
  226. data/manual/table/filtering.rb +0 -36
  227. data/manual/table/flow_and_header.rb +0 -17
  228. data/manual/table/image_cells.rb +0 -33
  229. data/manual/table/position.rb +0 -29
  230. data/manual/table/row_colors.rb +0 -20
  231. data/manual/table/span.rb +0 -30
  232. data/manual/table/style.rb +0 -22
  233. data/manual/table/table.rb +0 -52
  234. data/manual/table/width.rb +0 -27
  235. data/manual/text/alignment.rb +0 -44
  236. data/manual/text/color.rb +0 -24
  237. data/manual/text/column_box.rb +0 -32
  238. data/manual/text/fallback_fonts.rb +0 -37
  239. data/manual/text/font.rb +0 -41
  240. data/manual/text/font_size.rb +0 -45
  241. data/manual/text/font_style.rb +0 -23
  242. data/manual/text/formatted_callbacks.rb +0 -60
  243. data/manual/text/formatted_text.rb +0 -54
  244. data/manual/text/free_flowing_text.rb +0 -51
  245. data/manual/text/group.rb +0 -31
  246. data/manual/text/inline.rb +0 -43
  247. data/manual/text/kerning_and_character_spacing.rb +0 -39
  248. data/manual/text/leading.rb +0 -25
  249. data/manual/text/line_wrapping.rb +0 -41
  250. data/manual/text/paragraph_indentation.rb +0 -26
  251. data/manual/text/positioned_text.rb +0 -38
  252. data/manual/text/registering_families.rb +0 -48
  253. data/manual/text/rendering_and_color.rb +0 -37
  254. data/manual/text/right_to_left_text.rb +0 -43
  255. data/manual/text/rotation.rb +0 -43
  256. data/manual/text/single_usage.rb +0 -37
  257. data/manual/text/text.rb +0 -75
  258. data/manual/text/text_box_excess.rb +0 -32
  259. data/manual/text/text_box_extensions.rb +0 -45
  260. data/manual/text/text_box_overflow.rb +0 -44
  261. data/manual/text/utf8.rb +0 -28
  262. data/manual/text/win_ansi_charset.rb +0 -59
  263. data/spec/acceptance/png.rb +0 -23
  264. data/spec/column_box_spec.rb +0 -65
  265. data/spec/extensions/encoding_helpers.rb +0 -9
  266. data/spec/font_metric_cache_spec.rb +0 -52
  267. data/spec/image_handler_spec.rb +0 -54
  268. data/spec/soft_mask_spec.rb +0 -117
  269. data/spec/table/span_dummy_spec.rb +0 -17
@@ -11,7 +11,6 @@
11
11
 
12
12
  class ParameterChecker < Mocha::ParametersMatcher
13
13
  def initialize(&matching_block)
14
- @expected_parameters = [Mocha::ParameterMatchers::AnyParameters.new]
15
14
  @matching_block = matching_block
16
15
  end
17
16
 
data/spec/font_spec.rb CHANGED
@@ -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 'pathname'
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require 'iconv'
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
@@ -12,32 +12,6 @@ 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
-
41
15
  describe "#width_of" do
42
16
  it "should take character spacing into account" do
43
17
  create_pdf
@@ -50,7 +24,7 @@ describe "#width_of" do
50
24
  it "should exclude newlines" do
51
25
  create_pdf
52
26
  # Use a TTF font that has a non-zero width for \n
53
- @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
27
+ @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
54
28
 
55
29
  @pdf.width_of("\nhello world\n").should ==
56
30
  @pdf.width_of("hello world")
@@ -64,8 +38,8 @@ describe "#width_of" do
64
38
  @pdf.font("Helvetica", :style => :bold) {
65
39
  @bold_hello = @pdf.width_of("hello")
66
40
  }
67
-
68
- inline_bold_hello.should be > normal_hello
41
+
42
+ inline_bold_hello.should.be > normal_hello
69
43
  inline_bold_hello.should == @bold_hello
70
44
  end
71
45
 
@@ -79,12 +53,6 @@ describe "#width_of" do
79
53
 
80
54
  styled_bold_hello.should == @bold_hello
81
55
  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
88
56
  end
89
57
 
90
58
  describe "#font_size" do
@@ -97,38 +65,38 @@ end
97
65
 
98
66
  describe "font style support" do
99
67
  before(:each) { create_pdf }
100
-
68
+
101
69
  it "should complain if there is no @current_page" do
102
70
  pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
103
71
 
104
72
  lambda{ pdf_without_page.font "Helvetica" }.
105
- should raise_error(Prawn::Errors::NotOnPage)
73
+ should.raise(Prawn::Errors::NotOnPage)
106
74
  end
107
-
108
- it "should allow specifying font style by style name and font family" do
75
+
76
+ it "should allow specifying font style by style name and font family" do
109
77
  @pdf.font "Courier", :style => :bold
110
- @pdf.text "In Courier bold"
111
-
78
+ @pdf.text "In Courier bold"
79
+
112
80
  @pdf.font "Courier", :style => :bold_italic
113
- @pdf.text "In Courier bold-italic"
114
-
81
+ @pdf.text "In Courier bold-italic"
82
+
115
83
  @pdf.font "Courier", :style => :italic
116
- @pdf.text "In Courier italic"
117
-
84
+ @pdf.text "In Courier italic"
85
+
118
86
  @pdf.font "Courier", :style => :normal
119
- @pdf.text "In Normal Courier"
120
-
87
+ @pdf.text "In Normal Courier"
88
+
121
89
  @pdf.font "Helvetica"
122
- @pdf.text "In Normal Helvetica"
123
-
90
+ @pdf.text "In Normal Helvetica"
91
+
124
92
  text = PDF::Inspector::Text.analyze(@pdf.render)
125
- text.font_settings.map { |e| e[:name] }.should ==
126
- [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
93
+ text.font_settings.map { |e| e[:name] }.should ==
94
+ [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
127
95
  :Courier, :Helvetica]
128
96
  end
129
97
 
130
98
  it "should allow font familes to be defined in a single dfont" do
131
- file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
99
+ file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
132
100
  @pdf.font_families["Action Man"] = {
133
101
  :normal => { :file => file, :font => "ActionMan" },
134
102
  :italic => { :file => file, :font => "ActionMan-Italic" },
@@ -144,39 +112,24 @@ describe "font style support" do
144
112
  name = name.sub(/\w+\+/, "subset+")
145
113
  name.should == "subset+ActionMan-Italic"
146
114
  end
147
-
148
- it "should accept Pathname objects for font files" do
149
- file = Pathname.new( "#{Prawn::DATADIR}/fonts/Chalkboard.ttf" )
150
- @pdf.font_families["Chalkboard"] = {
151
- :normal => file
152
- }
153
-
154
- @pdf.font "Chalkboard"
155
- @pdf.text "In Chalkboard"
156
-
157
- text = PDF::Inspector::Text.analyze(@pdf.render)
158
- name = text.font_settings.map { |e| e[:name] }.first.to_s
159
- name = name.sub(/\w+\+/, "subset+")
160
- name.should == "subset+Chalkboard"
161
- end
162
115
  end
163
116
 
164
117
  describe "Transactional font handling" do
165
118
  before(:each) { create_pdf }
166
-
119
+
167
120
  it "should allow setting of size directly when font is created" do
168
121
  @pdf.font "Courier", :size => 16
169
- @pdf.font_size.should == 16
122
+ @pdf.font_size.should == 16
170
123
  end
171
-
124
+
172
125
  it "should allow temporary setting of a new font using a transaction" do
173
126
  @pdf.font "Helvetica", :size => 12
174
-
127
+
175
128
  @pdf.font "Courier", :size => 16 do
176
129
  @pdf.font.name.should == "Courier"
177
130
  @pdf.font_size.should == 16
178
131
  end
179
-
132
+
180
133
  @pdf.font.name.should == "Helvetica"
181
134
  @pdf.font_size.should == 12
182
135
  end
@@ -191,76 +144,75 @@ describe "Transactional font handling" do
191
144
 
192
145
  @pdf.font_size.should == 12
193
146
  end
194
-
147
+
195
148
  end
196
149
 
197
150
  describe "Document#page_fonts" do
198
- before(:each) { create_pdf }
199
-
151
+ before(:each) { create_pdf }
152
+
200
153
  it "should register fonts properly by page" do
201
154
  @pdf.font "Courier"; @pdf.text("hello")
202
155
  @pdf.font "Helvetica"; @pdf.text("hello")
203
156
  @pdf.font "Times-Roman"; @pdf.text("hello")
204
157
  ["Courier","Helvetica","Times-Roman"].each { |f|
205
158
  page_should_include_font(f)
206
- }
207
-
208
- @pdf.start_new_page
159
+ }
160
+
161
+ @pdf.start_new_page
209
162
  @pdf.font "Helvetica"; @pdf.text("hello")
210
163
  page_should_include_font("Helvetica")
211
164
  page_should_not_include_font("Courier")
212
165
  page_should_not_include_font("Times-Roman")
213
- end
214
-
166
+ end
167
+
215
168
  def page_includes_font?(font)
216
169
  @pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
217
- end
218
-
219
- def page_should_include_font(font)
220
- page_includes_font?(font).should be_true
221
- end
222
-
170
+ end
171
+
172
+ def page_should_include_font(font)
173
+ assert_block("Expected page to include font: #{font}") do
174
+ page_includes_font?(font)
175
+ end
176
+ end
177
+
223
178
  def page_should_not_include_font(font)
224
- page_includes_font?(font).should be_false
179
+ assert_block("Did not expect page to include font: #{font}") do
180
+ not page_includes_font?(font)
181
+ end
225
182
  end
226
-
183
+
227
184
  end
228
-
185
+
229
186
  describe "AFM fonts" do
230
-
231
- before do
187
+
188
+ setup do
232
189
  create_pdf
233
190
  @times = @pdf.find_font "Times-Roman"
191
+ @iconv = ::Iconv.new('Windows-1252', 'utf-8')
234
192
  end
235
-
193
+
236
194
  it "should calculate string width taking into account accented characters" do
237
- input = win1252_string("\xE9")# é in win-1252
238
- @times.compute_width_of(input, :size => 12).should == @times.compute_width_of("e", :size => 12)
195
+ @times.compute_width_of(@iconv.iconv("é"), :size => 12).should == @times.compute_width_of("e", :size => 12)
239
196
  end
240
-
197
+
241
198
  it "should calculate string width taking into account kerning pairs" do
242
- @times.compute_width_of(win1252_string("To"), :size => 12).should == 13.332
243
- @times.compute_width_of(win1252_string("To"), :size => 12, :kerning => true).should == 12.372
244
-
245
- input = win1252_string("T\xF6") # Tö in win-1252
246
- @times.compute_width_of(input, :size => 12, :kerning => true).should == 12.372
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
247
202
  end
248
203
 
249
204
  it "should encode text without kerning by default" do
250
- @times.encode_text(win1252_string("To")).should == [[0, "To"]]
251
- input = win1252_string("T\xE9l\xE9") # Télé in win-1252
252
- @times.encode_text(input).should == [[0, input]]
253
- @times.encode_text(win1252_string("Technology")).should == [[0, "Technology"]]
254
- @times.encode_text(win1252_string("Technology...")).should == [[0, "Technology..."]]
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..."]]
255
209
  end
256
210
 
257
211
  it "should encode text with kerning if requested" do
258
- @times.encode_text(win1252_string("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
259
- input = win1252_string("T\xE9l\xE9") # Télé in win-1252
260
- output = win1252_string("\xE9l\xE9") # élé in win-1252
261
- @times.encode_text(input, :kerning => true).should == [[0, ["T", 70, output]]]
262
- @times.encode_text(win1252_string("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
263
- @times.encode_text(win1252_string("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
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, "..."]]]
264
216
  end
265
217
 
266
218
  describe "when normalizing encoding" do
@@ -268,13 +220,13 @@ describe "AFM fonts" do
268
220
  it "should not modify the original string when normalize_encoding() is used" do
269
221
  original = "Foo"
270
222
  normalized = @times.normalize_encoding(original)
271
- original.equal?(normalized).should be_false
223
+ assert ! original.equal?(normalized)
272
224
  end
273
225
 
274
226
  it "should modify the original string when normalize_encoding!() is used" do
275
227
  original = "Foo"
276
228
  normalized = @times.normalize_encoding!(original)
277
- original.equal?(normalized).should be_true
229
+ assert original.equal?(normalized)
278
230
  end
279
231
 
280
232
  end
@@ -284,7 +236,7 @@ describe "AFM fonts" do
284
236
  font_dict = zapf.send(:register, nil)
285
237
  font_dict.data[:Encoding].should == nil
286
238
  end
287
-
239
+
288
240
  end
289
241
 
290
242
  describe "#glyph_present" do
@@ -292,52 +244,50 @@ describe "#glyph_present" do
292
244
 
293
245
  it "should return true when present in an AFM font" do
294
246
  font = @pdf.find_font("Helvetica")
295
- font.glyph_present?("H").should be_true
247
+ font.glyph_present?("H").should.be true
296
248
  end
297
249
 
298
250
  it "should return false when absent in an AFM font" do
299
251
  font = @pdf.find_font("Helvetica")
300
- font.glyph_present?("再").should be_false
252
+ font.glyph_present?("再").should.be false
301
253
  end
302
254
 
303
255
  it "should return true when present in a TTF font" do
304
- font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
305
- font.glyph_present?("H").should be_true
256
+ font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
257
+ font.glyph_present?("H").should.be true
306
258
  end
307
259
 
308
260
  it "should return false when absent in a TTF font" do
309
- font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
310
- font.glyph_present?("再").should be_false
261
+ font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/Activa.ttf")
262
+ font.glyph_present?("再").should.be false
311
263
 
312
- font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
313
- font.glyph_present?("€").should be_false
264
+ font = @pdf.find_font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
265
+ font.glyph_present?("€").should.be false
314
266
  end
315
267
  end
316
268
 
317
269
  describe "TTF fonts" do
318
-
319
- before do
270
+
271
+ setup do
320
272
  create_pdf
321
- @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf"
273
+ @activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
322
274
  end
323
-
275
+
324
276
  it "should calculate string width taking into account accented characters" do
325
277
  @activa.compute_width_of("é", :size => 12).should == @activa.compute_width_of("e", :size => 12)
326
278
  end
327
-
279
+
328
280
  it "should calculate string width taking into account kerning pairs" do
329
281
  @activa.compute_width_of("To", :size => 12).should == 15.228
330
282
  @activa.compute_width_of("To", :size => 12, :kerning => true).should == 12.996
331
283
  end
332
-
284
+
333
285
  it "should encode text without kerning by default" do
334
286
  @activa.encode_text("To").should == [[0, "To"]]
335
287
 
336
- tele = "T\216l\216"
337
- result = @activa.encode_text("Télé")
338
- result.length.should == 1
339
- result[0][0].should == 0
340
- result[0][1].bytes.to_a.should == tele.bytes.to_a
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]]
341
291
 
342
292
  @activa.encode_text("Technology").should == [[0, "Technology"]]
343
293
  @activa.encode_text("Technology...").should == [[0, "Technology..."]]
@@ -370,33 +320,33 @@ describe "TTF fonts" do
370
320
  it "should not modify the original string when normalize_encoding() is used" do
371
321
  original = "Foo"
372
322
  normalized = @activa.normalize_encoding(original)
373
- original.equal?(normalized).should be_false
323
+ assert ! original.equal?(normalized)
374
324
  end
375
325
 
376
326
  it "should modify the original string when normalize_encoding!() is used" do
377
327
  original = "Foo"
378
328
  normalized = @activa.normalize_encoding!(original)
379
- original.equal?(normalized).should be_true
329
+ assert original.equal?(normalized)
380
330
  end
381
331
 
382
332
  end
383
333
 
384
334
  describe "when used with snapshots or transactions" do
385
-
335
+
386
336
  it "should allow TTF fonts to be used alongside document transactions" do
387
337
  lambda {
388
338
  Prawn::Document.new do
389
- font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
339
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
390
340
  text "Hi there"
391
341
  transaction { text "Nice, thank you" }
392
342
  end
393
- }.should_not raise_error
343
+ }.should.not.raise
394
344
  end
395
345
 
396
346
  it "should allow TTF fonts to be used inside transactions" do
397
347
  pdf = Prawn::Document.new do
398
348
  transaction do
399
- font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
349
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
400
350
  text "Hi there"
401
351
  end
402
352
  end
@@ -408,13 +358,13 @@ describe "TTF fonts" do
408
358
  end
409
359
 
410
360
  end
411
-
361
+
412
362
  end
413
363
 
414
364
  describe "DFont fonts" do
415
- before do
365
+ setup do
416
366
  create_pdf
417
- @file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
367
+ @file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
418
368
  end
419
369
 
420
370
  it "should list all named fonts" do
@@ -444,16 +394,16 @@ describe "DFont fonts" do
444
394
  it "should cache font object based on selected font" do
445
395
  f1 = @pdf.find_font(@file, :font => "ActionMan")
446
396
  f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
447
- f2.object_id.should_not == f1.object_id
448
- @pdf.find_font(@file, :font => "ActionMan").object_id.should == f1.object_id
449
- @pdf.find_font(@file, :font => "ActionMan-Bold").object_id.should == f2.object_id
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
450
400
  end
451
401
  end
452
402
 
453
403
  describe "#character_count(text)" do
454
404
  it "should work on TTF fonts" do
455
405
  create_pdf
456
- @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
406
+ @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
457
407
  @pdf.font.character_count("こんにちは世界").should == 7
458
408
  @pdf.font.character_count("Hello, world!").should == 13
459
409
  end