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
@@ -5,7 +5,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
  describe "Core::Text::Formatted::Arranger#format_array" do
6
6
  it "should populate unconsumed array" do
7
7
  create_pdf
8
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
8
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
9
9
  array = [{ :text => "hello " },
10
10
  { :text => "world how ", :styles => [:bold] },
11
11
  { :text => "are", :styles => [:bold, :italic] },
@@ -20,7 +20,7 @@ describe "Core::Text::Formatted::Arranger#format_array" do
20
20
  end
21
21
  it "should split newlines into their own elements" do
22
22
  create_pdf
23
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
23
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
24
24
  array = [{ :text => "\nhello\nworld" }]
25
25
  arranger.format_array = array
26
26
  arranger.unconsumed[0].should == { :text => "\n" }
@@ -32,7 +32,7 @@ end
32
32
  describe "Core::Text::Formatted::Arranger#preview_next_string" do
33
33
  it "should not populate the consumed array" do
34
34
  create_pdf
35
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
35
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
36
36
  array = [{ :text => "hello" }]
37
37
  arranger.format_array = array
38
38
  arranger.preview_next_string
@@ -40,7 +40,7 @@ describe "Core::Text::Formatted::Arranger#preview_next_string" do
40
40
  end
41
41
  it "should not consumed array" do
42
42
  create_pdf
43
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
43
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
44
44
  array = [{ :text => "hello" }]
45
45
  arranger.format_array = array
46
46
  arranger.preview_next_string.should == "hello"
@@ -49,19 +49,19 @@ end
49
49
  describe "Core::Text::Formatted::Arranger#next_string" do
50
50
  before(:each) do
51
51
  create_pdf
52
- @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
52
+ @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
53
53
  array = [{ :text => "hello " },
54
54
  { :text => "world how ", :styles => [:bold] },
55
55
  { :text => "are", :styles => [:bold, :italic] },
56
56
  { :text => " you?" }]
57
57
  @arranger.format_array = array
58
58
  end
59
- it "should raise_error an error if called after a line was finalized and" +
59
+ it "should raise 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_error(RuntimeError)
64
+ end.should.raise(RuntimeError)
65
65
  end
66
66
  it "should populate consumed array" do
67
67
  while string = @arranger.next_string
@@ -75,7 +75,7 @@ describe "Core::Text::Formatted::Arranger#next_string" do
75
75
  end
76
76
  it "should populate current_format_state array" do
77
77
  create_pdf
78
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
78
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
79
79
  array = [{ :text => "hello " },
80
80
  { :text => "world how ", :styles => [:bold] },
81
81
  { :text => "are", :styles => [:bold, :italic] },
@@ -99,9 +99,9 @@ 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_error an error if called before finalize_line was called" do
102
+ it "should raise an error if called before finalize_line was called" do
103
103
  create_pdf
104
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
104
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
105
105
  array = [{ :text => "hello " },
106
106
  { :text => "world how ", :styles => [:bold] },
107
107
  { :text => "are", :styles => [:bold, :italic] },
@@ -111,12 +111,12 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
111
111
  end
112
112
  lambda do
113
113
  arranger.retrieve_fragment
114
- end.should raise_error(RuntimeError)
114
+ end.should.raise(RuntimeError)
115
115
  end
116
116
  it "should return the consumed fragments in order of consumption" +
117
117
  " and update" do
118
118
  create_pdf
119
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
119
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
120
120
  array = [{ :text => "hello " },
121
121
  { :text => "world how ", :styles => [:bold] },
122
122
  { :text => "are", :styles => [:bold, :italic] },
@@ -132,7 +132,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
132
132
  end
133
133
  it "should never return a fragment whose text is an empty string" do
134
134
  create_pdf
135
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
135
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
136
136
  array = [{ :text => "hello\nworld\n\n\nhow are you?" },
137
137
  { :text => "\n" },
138
138
  { :text => "\n" },
@@ -147,12 +147,12 @@ 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
154
154
  create_pdf
155
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
155
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
156
156
  array = [{ :text => "hello " },
157
157
  { :text => "world how ", :styles => [:bold] },
158
158
  { :text => "are", :styles => [:bold, :italic] },
@@ -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
 
@@ -170,7 +170,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
170
170
  it "should update the last retrieved string with what actually fit on" +
171
171
  "the line and the list of unconsumed with what did not" do
172
172
  create_pdf
173
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
173
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
174
174
  array = [{ :text => "hello " },
175
175
  { :text => "world how ", :styles => [:bold] },
176
176
  { :text => "are", :styles => [:bold, :italic] },
@@ -186,7 +186,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
186
186
  end
187
187
  it "should set the format state to the previously processed fragment" do
188
188
  create_pdf
189
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
189
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
190
190
  array = [{ :text => "hello " },
191
191
  { :text => "world how ", :styles => [:bold] },
192
192
  { :text => "are", :styles => [:bold, :italic] },
@@ -201,7 +201,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
201
201
  context "when the entire string was used" do
202
202
  it "should not push empty string onto unconsumed" do
203
203
  create_pdf
204
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
204
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
205
205
  array = [{ :text => "hello " },
206
206
  { :text => "world how ", :styles => [:bold] },
207
207
  { :text => "are", :styles => [:bold, :italic] },
@@ -217,7 +217,7 @@ end
217
217
  describe "Core::Text::Formatted::Arranger#space_count" do
218
218
  before(:each) do
219
219
  create_pdf
220
- @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
220
+ @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
221
221
  array = [{ :text => "hello " },
222
222
  { :text => "world how ", :styles => [:bold] },
223
223
  { :text => "are", :styles => [:bold, :italic] },
@@ -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_error an error if called before finalize_line was called" do
229
+ it "should raise an error if called before finalize_line was called" do
230
230
  lambda do
231
231
  @arranger.space_count
232
- end.should raise_error(RuntimeError)
232
+ end.should.raise(RuntimeError)
233
233
  end
234
234
  it "should return the total number of spaces in all fragments" do
235
235
  @arranger.finalize_line
@@ -240,7 +240,7 @@ describe "Core::Text::Formatted::Arranger#finalize_line" do
240
240
  it "should make it so that all trailing white space fragments " +
241
241
  "exclude trailing white space" do
242
242
  create_pdf
243
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
243
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
244
244
  array = [{ :text => "hello " },
245
245
  { :text => "world how ", :styles => [:bold] },
246
246
  { :text => " ", :styles => [:bold, :italic] }]
@@ -264,28 +264,28 @@ end
264
264
  describe "Core::Text::Formatted::Arranger#line_width" do
265
265
  before(:each) do
266
266
  create_pdf
267
- @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
267
+ @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
268
268
  array = [{ :text => "hello " },
269
269
  { :text => "world", :styles => [:bold] }]
270
270
  @arranger.format_array = array
271
271
  while string = @arranger.next_string
272
272
  end
273
273
  end
274
- it "should raise_error an error if called before finalize_line was called" do
274
+ it "should raise an error if called before finalize_line was called" do
275
275
  lambda do
276
276
  @arranger.line_width
277
- end.should raise_error(RuntimeError)
277
+ end.should.raise(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
 
285
285
  describe "Core::Text::Formatted::Arranger#line_width with character_spacing > 0" do
286
286
  it "should return a width greater than a line without a character_spacing" do
287
287
  create_pdf
288
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
288
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
289
289
 
290
290
  array = [{ :text => "hello " },
291
291
  { :text => "world", :styles => [:bold] }]
@@ -304,24 +304,24 @@ 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
 
311
311
  describe "Core::Text::Formatted::Arranger#line" do
312
312
  before(:each) do
313
313
  create_pdf
314
- @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
314
+ @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
315
315
  array = [{ :text => "hello " },
316
316
  { :text => "world", :styles => [:bold] }]
317
317
  @arranger.format_array = array
318
318
  while string = @arranger.next_string
319
319
  end
320
320
  end
321
- it "should raise_error an error if called before finalize_line was called" do
321
+ it "should raise an error if called before finalize_line was called" do
322
322
  lambda do
323
323
  @arranger.line
324
- end.should raise_error(RuntimeError)
324
+ end.should.raise(RuntimeError)
325
325
  end
326
326
  it "should return the complete line" do
327
327
  @arranger.finalize_line
@@ -332,7 +332,7 @@ end
332
332
  describe "Core::Text::Formatted::Arranger#unconsumed" do
333
333
  it "should return the original array if nothing was consumed" do
334
334
  create_pdf
335
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
335
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
336
336
  array = [{ :text => "hello " },
337
337
  { :text => "world how ", :styles => [:bold] },
338
338
  { :text => "are", :styles => [:bold, :italic] },
@@ -342,7 +342,7 @@ describe "Core::Text::Formatted::Arranger#unconsumed" do
342
342
  end
343
343
  it "should return an empty array if everything was consumed" do
344
344
  create_pdf
345
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
345
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
346
346
  array = [{ :text => "hello " },
347
347
  { :text => "world how ", :styles => [:bold] },
348
348
  { :text => "are", :styles => [:bold, :italic] },
@@ -355,9 +355,9 @@ 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
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
360
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
361
361
  array = [{ :text => "hello " },
362
362
  { :text => "world how ", :styles => [:bold] },
363
363
  { :text => "are", :styles => [:bold, :italic] },
@@ -366,11 +366,11 @@ 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
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
373
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
374
374
  array = [{ :text => "hello " },
375
375
  { :text => "world how ", :styles => [:bold] },
376
376
  { :text => "are", :styles => [:bold, :italic] },
@@ -378,14 +378,14 @@ 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
 
385
385
  describe "Core::Text::Formatted::Arranger.max_line_height" do
386
386
  it "should be the height of the maximum consumed fragment" do
387
387
  create_pdf
388
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
388
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
389
389
  array = [{ :text => "hello " },
390
390
  { :text => "world how ", :styles => [:bold] },
391
391
  { :text => "are", :styles => [:bold, :italic],
@@ -395,14 +395,14 @@ 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_within(0.0001).of(33.32)
398
+ arranger.max_line_height.should.be.close(33.32, 0.0001)
399
399
  end
400
400
  end
401
401
 
402
402
  describe "Core::Text::Formatted::Arranger#repack_unretrieved" do
403
403
  it "should restore part of the original string" do
404
404
  create_pdf
405
- arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
405
+ arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
406
406
  array = [{ :text => "hello " },
407
407
  { :text => "world how ", :styles => [:bold] },
408
408
  { :text => "are", :styles => [:bold, :italic] },
@@ -18,19 +18,22 @@ describe "Text::Formatted::Box wrapping" do
18
18
  text_box.text.should == "Hello\nWorld2"
19
19
  end
20
20
 
21
- it "should not raise an Encoding::CompatibilityError when keeping a TTF and an " +
21
+ it "should not raise Encoding::CompatibilityError when keeping a TTF and an " +
22
22
  "AFM font together" do
23
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
24
- @pdf.font_families["Kai"] = {
25
- :normal => { :file => file, :font => "Kai" }
26
- }
27
-
28
- texts = [{ :text => "Hello " },
29
- { :text => "再见", :font => "Kai"},
30
- { :text => "World" }]
31
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
32
-
33
- text_box.render
23
+ ruby_19 do
24
+ file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
25
+ @pdf.font_families["Kai"] = {
26
+ :normal => { :file => file, :font => "Kai" }
27
+ }
28
+
29
+ texts = [{ :text => "Hello " },
30
+ { :text => "再见", :font => "Kai"},
31
+ { :text => "World" }]
32
+ text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
33
+ lambda {
34
+ text_box.render
35
+ }.should.not.raise(Encoding::CompatibilityError)
36
+ end
34
37
  end
35
38
 
36
39
  it "should wrap between two fragments when the preceding fragment ends with white space" do
@@ -76,30 +79,39 @@ describe "Text::Formatted::Box wrapping" do
76
79
  it "should properly handle empty slices using default encoding" do
77
80
  texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
78
81
  text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
79
- lambda {
82
+ assert_nothing_raised do
80
83
  text_box.render
81
- }.should_not raise_error
84
+ end
82
85
  text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
83
86
  end
84
-
87
+
85
88
  describe "Unicode" do
86
89
  before do
87
- @reset_value = [Encoding.default_external, Encoding.default_internal]
88
- Encoding.default_external = Encoding::UTF_8
89
- Encoding.default_internal = Encoding::UTF_8
90
+ if RUBY_VERSION < '1.9'
91
+ @reset_value = $KCODE
92
+ $KCODE='u'
93
+ else
94
+ @reset_value = [Encoding.default_external, Encoding.default_internal]
95
+ Encoding.default_external = Encoding::UTF_8
96
+ Encoding.default_internal = Encoding::UTF_8
97
+ end
90
98
  end
91
-
99
+
92
100
  after do
93
- Encoding.default_external = @reset_value[0]
94
- Encoding.default_internal = @reset_value[1]
101
+ if RUBY_VERSION < '1.9'
102
+ $KCODE=@reset_value
103
+ else
104
+ Encoding.default_external = @reset_value[0]
105
+ Encoding.default_internal = @reset_value[1]
106
+ end
95
107
  end
96
108
 
97
109
  it "should properly handle empty slices using Unicode encoding" do
98
110
  texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
99
111
  text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
100
- lambda {
112
+ assert_nothing_raised do
101
113
  text_box.render
102
- }.should_not raise_error
114
+ end
103
115
  text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
104
116
  end
105
117
  end
@@ -109,7 +121,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
109
121
  "a Chinese font and set of Chinese glyphs not in the current font" do
110
122
  it "should change the font to the Chinese font for the Chinese glyphs" do
111
123
  create_pdf
112
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
124
+ file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
113
125
  @pdf.font_families["Kai"] = {
114
126
  :normal => { :file => file, :font => "Kai" }
115
127
  }
@@ -137,7 +149,7 @@ describe "Text::Formatted::Box with :fallback_fonts option that includes" +
137
149
  "an AFM font and Win-Ansi glyph not in the current Chinese font" do
138
150
  it "should change the font to the AFM font for the Win-Ansi glyph" do
139
151
  create_pdf
140
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
152
+ file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
141
153
  @pdf.font_families["Kai"] = {
142
154
  :normal => { :file => file, :font => "Kai" }
143
155
  }
@@ -166,7 +178,7 @@ describe "Text::Formatted::Box with :fallback_fonts option and fragment " +
166
178
  "level font" do
167
179
  it "should use the fragment level font except for glyphs not in that font" do
168
180
  create_pdf
169
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
181
+ file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
170
182
  @pdf.font_families["Kai"] = {
171
183
  :normal => { :file => file, :font => "Kai" }
172
184
  }
@@ -193,7 +205,7 @@ end
193
205
  describe "Text::Formatted::Box" do
194
206
  before(:each) do
195
207
  create_pdf
196
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
208
+ file = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
197
209
  @pdf.font_families["Kai"] = {
198
210
  :normal => { :file => file, :font => "Kai" }
199
211
  }
@@ -385,8 +397,7 @@ describe "Text::Formatted::Box#render" do
385
397
  { :text => "callback now",
386
398
  :callback => [behind, in_front] }]
387
399
  text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
388
-
389
- text_box.render # trigger callbacks
400
+ lambda { text_box.render }.should.not.raise(NoMethodError)
390
401
  end
391
402
  it "should be able to set the font" do
392
403
  create_pdf
@@ -438,7 +449,7 @@ describe "Text::Formatted::Box#render" do
438
449
  text_box.render
439
450
  contents = PDF::Inspector::Text.analyze(@pdf.render)
440
451
  contents.font_settings[0][:size].should == 12
441
- contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
452
+ contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
442
453
  end
443
454
  it "should be able to set superscript" do
444
455
  create_pdf
@@ -449,7 +460,7 @@ describe "Text::Formatted::Box#render" do
449
460
  text_box.render
450
461
  contents = PDF::Inspector::Text.analyze(@pdf.render)
451
462
  contents.font_settings[0][:size].should == 12
452
- contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
463
+ contents.font_settings[1][:size].should.be.close(18 * 0.583, 0.0001)
453
464
  end
454
465
  it "should be able to set compound bold and italic text" do
455
466
  create_pdf
@@ -501,16 +512,6 @@ describe "Text::Formatted::Box#render" do
501
512
  text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
502
513
  text_box.render
503
514
  end
504
- it "should be able to add local actions" do
505
- create_pdf
506
- @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
507
- :A => { :Type => :Action, :S => :Launch, :F => "../example.pdf", :NewWindow => true })
508
- array = [{ :text => "click " },
509
- { :text => "here", :local => "../example.pdf" },
510
- { :text => " to open a local file" }]
511
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
512
- text_box.render
513
- end
514
515
  it "should be able to set font size" do
515
516
  create_pdf
516
517
  array = [{ :text => "this contains " },
@@ -530,7 +531,7 @@ describe "Text::Formatted::Box#render" do
530
531
  text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
531
532
  text_box.render
532
533
  @pdf.font_size(24) do
533
- text_box.height.should be_within(0.001).of(@pdf.font.ascender + @pdf.font.descender)
534
+ text_box.height.should.be.close(@pdf.font.ascender + @pdf.font.descender, 0.001)
534
535
  end
535
536
  end
536
537
  it "should be able to set color via an rgb hex string" do
@@ -590,7 +591,7 @@ describe "Text::Formatted::Box#render with :align => :justify" do
590
591
  text_box = Prawn::Text::Formatted::Box.new(array, options)
591
592
  text_box.render
592
593
  contents = PDF::Inspector::Text.analyze(@pdf.render)
593
- contents.word_spacing.should be_empty
594
+ contents.word_spacing.should.be.empty
594
595
  end
595
596
  end
596
597