prawn 0.11.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (353) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +10 -0
  3. data/COPYING +2 -2
  4. data/GPLv2 +340 -0
  5. data/GPLv3 +674 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE +1 -1
  8. data/Rakefile +29 -38
  9. data/data/images/16bit.alpha +0 -0
  10. data/data/images/16bit.color +0 -0
  11. data/data/images/dice.alpha +0 -0
  12. data/data/images/dice.color +0 -0
  13. data/data/images/indexed_color.dat +0 -0
  14. data/data/images/indexed_color.png +0 -0
  15. data/data/images/page_white_text.alpha +0 -0
  16. data/data/images/page_white_text.color +0 -0
  17. data/data/pdfs/nested_pages.pdf +13 -13
  18. data/lib/prawn/document/bounding_box.rb +87 -12
  19. data/lib/prawn/document/column_box.rb +57 -28
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +25 -23
  22. data/lib/prawn/document/snapshot.rb +11 -8
  23. data/lib/prawn/document/span.rb +12 -10
  24. data/lib/prawn/document.rb +250 -194
  25. data/lib/prawn/encoding.rb +9 -10
  26. data/lib/prawn/errors.rb +18 -29
  27. data/lib/prawn/font/afm.rb +52 -41
  28. data/lib/prawn/font/dfont.rb +4 -3
  29. data/lib/prawn/font/ttf.rb +44 -48
  30. data/lib/prawn/font.rb +138 -88
  31. data/lib/prawn/font_metric_cache.rb +47 -0
  32. data/lib/prawn/graphics/cap_style.rb +4 -3
  33. data/lib/prawn/graphics/color.rb +13 -5
  34. data/lib/prawn/graphics/dash.rb +53 -31
  35. data/lib/prawn/graphics/join_style.rb +9 -7
  36. data/lib/prawn/graphics/patterns.rb +138 -0
  37. data/lib/prawn/graphics/transformation.rb +10 -9
  38. data/lib/prawn/graphics/transparency.rb +3 -1
  39. data/lib/prawn/graphics.rb +316 -61
  40. data/lib/prawn/image_handler.rb +36 -0
  41. data/lib/prawn/images/image.rb +49 -0
  42. data/lib/prawn/images/jpg.rb +21 -15
  43. data/lib/prawn/images/png.rb +62 -119
  44. data/lib/prawn/images.rb +89 -108
  45. data/lib/prawn/layout/grid.rb +66 -54
  46. data/lib/prawn/layout.rb +10 -15
  47. data/lib/prawn/measurement_extensions.rb +10 -6
  48. data/lib/prawn/measurements.rb +27 -21
  49. data/lib/prawn/outline.rb +6 -308
  50. data/lib/prawn/repeater.rb +11 -9
  51. data/lib/prawn/security/arcfour.rb +1 -0
  52. data/lib/prawn/security.rb +55 -33
  53. data/lib/prawn/soft_mask.rb +96 -0
  54. data/lib/prawn/stamp.rb +5 -3
  55. data/lib/prawn/table/cell/image.rb +69 -0
  56. data/lib/prawn/table/cell/in_table.rb +4 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +93 -0
  58. data/lib/prawn/table/cell/subtable.rb +2 -2
  59. data/lib/prawn/table/cell/text.rb +44 -26
  60. data/lib/prawn/table/cell.rb +302 -50
  61. data/lib/prawn/table/cells.rb +147 -49
  62. data/lib/prawn/table/column_width_calculator.rb +61 -0
  63. data/lib/prawn/table.rb +297 -118
  64. data/lib/prawn/text/box.rb +21 -5
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +103 -59
  67. data/lib/prawn/text/formatted/fragment.rb +34 -23
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +15 -5
  70. data/lib/prawn/text/formatted/wrap.rb +150 -0
  71. data/lib/prawn/text/formatted.rb +5 -4
  72. data/lib/prawn/text.rb +38 -24
  73. data/lib/prawn/utilities.rb +46 -0
  74. data/lib/prawn.rb +85 -20
  75. data/manual/basic_concepts/adding_pages.rb +27 -0
  76. data/manual/basic_concepts/basic_concepts.rb +34 -0
  77. data/manual/basic_concepts/creation.rb +39 -0
  78. data/manual/basic_concepts/cursor.rb +33 -0
  79. data/manual/basic_concepts/measurement.rb +25 -0
  80. data/manual/basic_concepts/origin.rb +38 -0
  81. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  82. data/manual/bounding_box/bounding_box.rb +39 -0
  83. data/manual/bounding_box/bounds.rb +49 -0
  84. data/manual/bounding_box/canvas.rb +24 -0
  85. data/manual/bounding_box/creation.rb +23 -0
  86. data/manual/bounding_box/indentation.rb +46 -0
  87. data/manual/bounding_box/nesting.rb +45 -0
  88. data/manual/bounding_box/russian_boxes.rb +40 -0
  89. data/manual/bounding_box/stretchy.rb +31 -0
  90. data/manual/document_and_page_options/background.rb +27 -0
  91. data/manual/document_and_page_options/document_and_page_options.rb +32 -0
  92. data/manual/document_and_page_options/metadata.rb +23 -0
  93. data/manual/document_and_page_options/page_margins.rb +38 -0
  94. data/manual/document_and_page_options/page_size.rb +34 -0
  95. data/manual/document_and_page_options/print_scaling.rb +20 -0
  96. data/manual/example_file.rb +111 -0
  97. data/manual/example_helper.rb +411 -0
  98. data/manual/example_package.rb +53 -0
  99. data/manual/example_section.rb +46 -0
  100. data/manual/graphics/circle_and_ellipse.rb +22 -0
  101. data/manual/graphics/color.rb +24 -0
  102. data/manual/graphics/common_lines.rb +30 -0
  103. data/manual/graphics/fill_and_stroke.rb +42 -0
  104. data/manual/graphics/fill_rules.rb +37 -0
  105. data/manual/graphics/gradients.rb +37 -0
  106. data/manual/graphics/graphics.rb +58 -0
  107. data/manual/graphics/helper.rb +24 -0
  108. data/manual/graphics/line_width.rb +35 -0
  109. data/manual/graphics/lines_and_curves.rb +41 -0
  110. data/manual/graphics/polygon.rb +29 -0
  111. data/manual/graphics/rectangle.rb +21 -0
  112. data/manual/graphics/rotate.rb +28 -0
  113. data/manual/graphics/scale.rb +41 -0
  114. data/manual/graphics/soft_masks.rb +46 -0
  115. data/manual/graphics/stroke_cap.rb +31 -0
  116. data/manual/graphics/stroke_dash.rb +48 -0
  117. data/manual/graphics/stroke_join.rb +30 -0
  118. data/manual/graphics/translate.rb +29 -0
  119. data/manual/graphics/transparency.rb +35 -0
  120. data/manual/images/absolute_position.rb +23 -0
  121. data/manual/images/fit.rb +21 -0
  122. data/manual/images/horizontal.rb +25 -0
  123. data/manual/images/images.rb +40 -0
  124. data/manual/images/plain_image.rb +18 -0
  125. data/manual/images/scale.rb +22 -0
  126. data/manual/images/vertical.rb +28 -0
  127. data/manual/images/width_and_height.rb +25 -0
  128. data/manual/layout/boxes.rb +27 -0
  129. data/manual/layout/content.rb +25 -0
  130. data/manual/layout/layout.rb +28 -0
  131. data/manual/layout/simple_grid.rb +23 -0
  132. data/manual/manual/cover.rb +36 -0
  133. data/manual/manual/foreword.rb +85 -0
  134. data/manual/manual/how_to_read_this_manual.rb +41 -0
  135. data/manual/manual/manual.rb +34 -0
  136. data/manual/outline/add_subsection_to.rb +61 -0
  137. data/manual/outline/insert_section_after.rb +47 -0
  138. data/manual/outline/outline.rb +32 -0
  139. data/manual/outline/sections_and_pages.rb +67 -0
  140. data/manual/repeatable_content/page_numbering.rb +54 -0
  141. data/manual/repeatable_content/repeatable_content.rb +31 -0
  142. data/manual/repeatable_content/repeater.rb +55 -0
  143. data/manual/repeatable_content/stamp.rb +41 -0
  144. data/manual/security/encryption.rb +31 -0
  145. data/manual/security/permissions.rb +38 -0
  146. data/manual/security/security.rb +28 -0
  147. data/manual/syntax_highlight.rb +52 -0
  148. data/manual/table/basic_block.rb +53 -0
  149. data/manual/table/before_rendering_page.rb +26 -0
  150. data/manual/table/cell_border_lines.rb +24 -0
  151. data/manual/table/cell_borders_and_bg.rb +31 -0
  152. data/manual/table/cell_dimensions.rb +30 -0
  153. data/manual/table/cell_text.rb +38 -0
  154. data/manual/table/column_widths.rb +30 -0
  155. data/manual/table/content_and_subtables.rb +39 -0
  156. data/manual/table/creation.rb +27 -0
  157. data/manual/table/filtering.rb +36 -0
  158. data/manual/table/flow_and_header.rb +17 -0
  159. data/manual/table/image_cells.rb +33 -0
  160. data/manual/table/position.rb +29 -0
  161. data/manual/table/row_colors.rb +20 -0
  162. data/manual/table/span.rb +30 -0
  163. data/manual/table/style.rb +22 -0
  164. data/manual/table/table.rb +52 -0
  165. data/manual/table/width.rb +27 -0
  166. data/manual/text/alignment.rb +44 -0
  167. data/manual/text/color.rb +24 -0
  168. data/manual/text/column_box.rb +32 -0
  169. data/manual/text/fallback_fonts.rb +37 -0
  170. data/manual/text/font.rb +41 -0
  171. data/manual/text/font_size.rb +45 -0
  172. data/manual/text/font_style.rb +23 -0
  173. data/manual/text/formatted_callbacks.rb +60 -0
  174. data/manual/text/formatted_text.rb +54 -0
  175. data/manual/text/free_flowing_text.rb +51 -0
  176. data/manual/text/group.rb +31 -0
  177. data/manual/text/inline.rb +43 -0
  178. data/manual/text/kerning_and_character_spacing.rb +39 -0
  179. data/manual/text/leading.rb +25 -0
  180. data/manual/text/line_wrapping.rb +41 -0
  181. data/manual/text/paragraph_indentation.rb +26 -0
  182. data/manual/text/positioned_text.rb +38 -0
  183. data/manual/text/registering_families.rb +48 -0
  184. data/manual/text/rendering_and_color.rb +37 -0
  185. data/manual/text/right_to_left_text.rb +43 -0
  186. data/manual/text/rotation.rb +43 -0
  187. data/manual/text/single_usage.rb +37 -0
  188. data/manual/text/text.rb +75 -0
  189. data/manual/text/text_box_excess.rb +32 -0
  190. data/manual/text/text_box_extensions.rb +45 -0
  191. data/manual/text/text_box_overflow.rb +44 -0
  192. data/manual/text/utf8.rb +28 -0
  193. data/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
  194. data/prawn.gemspec +27 -17
  195. data/spec/acceptance/png.rb +23 -0
  196. data/spec/annotations_spec.rb +16 -32
  197. data/spec/bounding_box_spec.rb +284 -2
  198. data/spec/cell_spec.rb +169 -38
  199. data/spec/column_box_spec.rb +65 -0
  200. data/spec/data/curves.pdf +66 -0
  201. data/spec/destinations_spec.rb +5 -5
  202. data/spec/document_spec.rb +212 -113
  203. data/spec/extensions/encoding_helpers.rb +9 -0
  204. data/spec/extensions/mocha.rb +2 -3
  205. data/spec/font_metric_cache_spec.rb +52 -0
  206. data/spec/font_spec.rb +205 -95
  207. data/spec/formatted_text_arranger_spec.rb +43 -43
  208. data/spec/formatted_text_box_spec.rb +63 -24
  209. data/spec/formatted_text_fragment_spec.rb +8 -8
  210. data/spec/graphics_spec.rb +175 -68
  211. data/spec/grid_spec.rb +26 -15
  212. data/spec/image_handler_spec.rb +54 -0
  213. data/spec/images_spec.rb +58 -30
  214. data/spec/inline_formatted_text_parser_spec.rb +73 -19
  215. data/spec/jpg_spec.rb +4 -4
  216. data/spec/line_wrap_spec.rb +28 -28
  217. data/spec/measurement_units_spec.rb +6 -6
  218. data/spec/object_store_spec.rb +17 -106
  219. data/spec/outline_spec.rb +103 -63
  220. data/spec/png_spec.rb +25 -25
  221. data/spec/reference_spec.rb +8 -65
  222. data/spec/repeater_spec.rb +25 -11
  223. data/spec/security_spec.rb +44 -12
  224. data/spec/snapshot_spec.rb +38 -6
  225. data/spec/soft_mask_spec.rb +117 -0
  226. data/spec/span_spec.rb +10 -15
  227. data/spec/spec_helper.rb +32 -8
  228. data/spec/stamp_spec.rb +29 -30
  229. data/spec/stroke_styles_spec.rb +36 -18
  230. data/spec/table/span_dummy_spec.rb +17 -0
  231. data/spec/table_spec.rb +850 -104
  232. data/spec/text_at_spec.rb +19 -33
  233. data/spec/text_box_spec.rb +117 -64
  234. data/spec/text_rendering_mode_spec.rb +5 -5
  235. data/spec/text_spacing_spec.rb +20 -2
  236. data/spec/text_spec.rb +111 -59
  237. data/spec/transparency_spec.rb +5 -5
  238. metadata +477 -328
  239. data/HACKING +0 -50
  240. data/README +0 -141
  241. data/data/fonts/Action Man.dfont +0 -0
  242. data/data/fonts/Activa.ttf +0 -0
  243. data/data/fonts/Chalkboard.ttf +0 -0
  244. data/data/fonts/DejaVuSans.ttf +0 -0
  245. data/data/fonts/Dustismo_Roman.ttf +0 -0
  246. data/data/fonts/comicsans.ttf +0 -0
  247. data/data/fonts/gkai00mp.ttf +0 -0
  248. data/data/images/16bit.dat +0 -0
  249. data/data/images/dice.dat +0 -0
  250. data/data/images/page_white_text.dat +0 -0
  251. data/data/images/rails.dat +0 -0
  252. data/data/images/rails.png +0 -0
  253. data/examples/bounding_box/bounding_boxes.rb +0 -44
  254. data/examples/bounding_box/indentation.rb +0 -35
  255. data/examples/bounding_box/russian_boxes.rb +0 -37
  256. data/examples/bounding_box/stretched_nesting.rb +0 -68
  257. data/examples/example_helper.rb +0 -8
  258. data/examples/general/background.rb +0 -24
  259. data/examples/general/canvas.rb +0 -16
  260. data/examples/general/context_sensitive_headers.rb +0 -38
  261. data/examples/general/float.rb +0 -12
  262. data/examples/general/margin.rb +0 -37
  263. data/examples/general/measurement_units.rb +0 -52
  264. data/examples/general/metadata-info.rb +0 -17
  265. data/examples/general/multi_page_layout.rb +0 -19
  266. data/examples/general/outlines.rb +0 -67
  267. data/examples/general/page_geometry.rb +0 -32
  268. data/examples/general/page_numbering.rb +0 -40
  269. data/examples/general/page_templates.rb +0 -20
  270. data/examples/general/repeaters.rb +0 -48
  271. data/examples/general/stamp.rb +0 -42
  272. data/examples/general/templates.rb +0 -14
  273. data/examples/graphics/basic_images.rb +0 -24
  274. data/examples/graphics/cmyk.rb +0 -13
  275. data/examples/graphics/curves.rb +0 -12
  276. data/examples/graphics/gradient.rb +0 -23
  277. data/examples/graphics/hexagon.rb +0 -14
  278. data/examples/graphics/image_fit.rb +0 -16
  279. data/examples/graphics/image_flow.rb +0 -38
  280. data/examples/graphics/image_position.rb +0 -18
  281. data/examples/graphics/line.rb +0 -33
  282. data/examples/graphics/png_types.rb +0 -23
  283. data/examples/graphics/polygons.rb +0 -17
  284. data/examples/graphics/remote_images.rb +0 -13
  285. data/examples/graphics/rounded_polygons.rb +0 -20
  286. data/examples/graphics/rounded_rectangle.rb +0 -21
  287. data/examples/graphics/ruport_style_helpers.rb +0 -20
  288. data/examples/graphics/stroke_bounds.rb +0 -21
  289. data/examples/graphics/stroke_cap_and_join.rb +0 -46
  290. data/examples/graphics/stroke_dash.rb +0 -43
  291. data/examples/graphics/transformations.rb +0 -53
  292. data/examples/graphics/transparency.rb +0 -27
  293. data/examples/grid/bounding_boxes.rb +0 -22
  294. data/examples/grid/column_gutter_grid.rb +0 -21
  295. data/examples/grid/multi_boxes.rb +0 -52
  296. data/examples/grid/show_grid.rb +0 -14
  297. data/examples/grid/simple_grid.rb +0 -21
  298. data/examples/m17n/chinese_text_wrapping.rb +0 -18
  299. data/examples/m17n/euro.rb +0 -16
  300. data/examples/m17n/full_win_ansi_character_list.rb +0 -20
  301. data/examples/m17n/sjis.rb +0 -29
  302. data/examples/m17n/utf8.rb +0 -14
  303. data/examples/security/hello_foo.rb +0 -9
  304. data/examples/table/bill.rb +0 -54
  305. data/examples/table/borders.rb +0 -25
  306. data/examples/table/cell.rb +0 -13
  307. data/examples/table/checkerboard.rb +0 -23
  308. data/examples/table/header.rb +0 -15
  309. data/examples/table/inline_format_table.rb +0 -13
  310. data/examples/table/multi_page_table.rb +0 -10
  311. data/examples/table/simple_table.rb +0 -25
  312. data/examples/table/subtable.rb +0 -13
  313. data/examples/table/widths.rb +0 -21
  314. data/examples/text/alignment.rb +0 -19
  315. data/examples/text/character_spacing.rb +0 -13
  316. data/examples/text/dfont.rb +0 -49
  317. data/examples/text/family_based_styling.rb +0 -25
  318. data/examples/text/font_calculations.rb +0 -92
  319. data/examples/text/font_size.rb +0 -34
  320. data/examples/text/hyphenation.rb +0 -45
  321. data/examples/text/indent_paragraphs.rb +0 -24
  322. data/examples/text/inline_format.rb +0 -104
  323. data/examples/text/kerning.rb +0 -31
  324. data/examples/text/rendering_mode.rb +0 -21
  325. data/examples/text/rotated.rb +0 -99
  326. data/examples/text/shaped_text_box.rb +0 -32
  327. data/examples/text/simple_text.rb +0 -18
  328. data/examples/text/simple_text_ttf.rb +0 -18
  329. data/examples/text/span.rb +0 -30
  330. data/examples/text/text_box.rb +0 -90
  331. data/examples/text/text_box_returning_excess.rb +0 -52
  332. data/examples/text/text_flow.rb +0 -68
  333. data/lib/prawn/compatibility.rb +0 -51
  334. data/lib/prawn/core/annotations.rb +0 -61
  335. data/lib/prawn/core/byte_string.rb +0 -9
  336. data/lib/prawn/core/destinations.rb +0 -90
  337. data/lib/prawn/core/document_state.rb +0 -78
  338. data/lib/prawn/core/literal_string.rb +0 -16
  339. data/lib/prawn/core/name_tree.rb +0 -165
  340. data/lib/prawn/core/object_store.rb +0 -264
  341. data/lib/prawn/core/page.rb +0 -213
  342. data/lib/prawn/core/pdf_object.rb +0 -108
  343. data/lib/prawn/core/reference.rb +0 -112
  344. data/lib/prawn/core/text/formatted/arranger.rb +0 -293
  345. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -272
  346. data/lib/prawn/core/text/formatted/wrap.rb +0 -149
  347. data/lib/prawn/core/text.rb +0 -268
  348. data/lib/prawn/core.rb +0 -85
  349. data/lib/prawn/document/page_geometry.rb +0 -136
  350. data/lib/prawn/graphics/gradient.rb +0 -84
  351. data/spec/name_tree_spec.rb +0 -112
  352. data/spec/pdf_object_spec.rb +0 -170
  353. data/spec/template_spec.rb +0 -291
data/spec/text_at_spec.rb CHANGED
@@ -5,12 +5,12 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
  describe "#draw_text" do
6
6
  before(:each) { create_pdf }
7
7
 
8
- it "should raise ArgumentError if :at option omitted" do
9
- lambda { @pdf.draw_text("hai", { }) }.should.raise(ArgumentError)
8
+ it "should raise_error ArgumentError if :at option omitted" do
9
+ lambda { @pdf.draw_text("hai", { }) }.should raise_error(ArgumentError)
10
10
  end
11
11
 
12
- it "should raise ArgumentError if :align option included" do
13
- lambda { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.should.raise(ArgumentError)
12
+ it "should raise_error ArgumentError if :align option included" do
13
+ lambda { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.should raise_error(ArgumentError)
14
14
  end
15
15
 
16
16
  it "should allow drawing empty strings to the page" do
@@ -85,8 +85,8 @@ describe "#draw_text" do
85
85
  text.font_settings[1][:name].should == :Courier
86
86
  end
87
87
 
88
- it "should raise an exception when an unknown font is used" do
89
- lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont)
88
+ it "should raise_error an exception when an unknown font is used" do
89
+ lambda { @pdf.font "Pao bu" }.should raise_error(Prawn::Errors::UnknownFont)
90
90
  end
91
91
 
92
92
  it "should correctly render a utf-8 string when using a built-in font" do
@@ -98,32 +98,18 @@ describe "#draw_text" do
98
98
  text.strings.first.should == str
99
99
  end
100
100
 
101
- if "spec".respond_to?(:encode!)
102
- # Handle non utf-8 string encodings in a sane way on M17N aware VMs
103
- it "should raise an exception when a utf-8 incompatible string is rendered" do
104
- str = "Blah \xDD"
105
- str.force_encoding("ASCII-8BIT")
106
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(
107
- Prawn::Errors::IncompatibleStringEncoding)
108
- end
109
- it "should not raise an exception when a shift-jis string is rendered" do
110
- datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
111
- sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
112
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
113
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.not.raise(
114
- Prawn::Errors::IncompatibleStringEncoding)
115
- end
116
- else
117
- # Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
118
- it "should raise an exception when a corrupt utf-8 string is rendered" do
119
- str = "Blah \xDD"
120
- lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(
121
- Prawn::Errors::IncompatibleStringEncoding)
122
- end
123
- it "should raise an exception when a shift-jis string is rendered" do
124
- sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
125
- lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.raise(
126
- Prawn::Errors::IncompatibleStringEncoding)
127
- end
101
+ it "should raise_error an exception when a utf-8 incompatible string is rendered" do
102
+ str = "Blah \xDD"
103
+ str.force_encoding(Encoding::ASCII_8BIT)
104
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
105
+ Prawn::Errors::IncompatibleStringEncoding)
106
+ end
107
+
108
+ it "should not raise an exception when a shift-jis string is rendered" do
109
+ datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
110
+ sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
111
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
112
+
113
+ @pdf.draw_text(sjis_str, :at => [0, 0])
128
114
  end
129
115
  end
@@ -3,55 +3,55 @@
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
 
5
5
  describe "Text::Box#nothing_printed?" do
6
- it "should be true when nothing printed" do
6
+ it "should be_true when nothing printed" do
7
7
  create_pdf
8
8
  string = "Hello world, how are you?\nI'm fine, thank you."
9
9
  text_box = Prawn::Text::Box.new(string,
10
10
  :height => 2,
11
11
  :document => @pdf)
12
12
  text_box.render
13
- text_box.nothing_printed?.should.be true
13
+ text_box.nothing_printed?.should be_true
14
14
  end
15
- it "should be false when something printed" do
15
+ it "should be_false when something printed" do
16
16
  create_pdf
17
17
  string = "Hello world, how are you?\nI'm fine, thank you."
18
18
  text_box = Prawn::Text::Box.new(string,
19
19
  :height => 14,
20
20
  :document => @pdf)
21
21
  text_box.render
22
- text_box.nothing_printed?.should.be false
22
+ text_box.nothing_printed?.should be_false
23
23
  end
24
24
  end
25
25
 
26
26
  describe "Text::Box#everything_printed?" do
27
- it "should be false when not everything printed" do
27
+ it "should be_false when not everything printed" do
28
28
  create_pdf
29
29
  string = "Hello world, how are you?\nI'm fine, thank you."
30
30
  text_box = Prawn::Text::Box.new(string,
31
31
  :height => 14,
32
32
  :document => @pdf)
33
33
  text_box.render
34
- text_box.everything_printed?.should.be false
34
+ text_box.everything_printed?.should be_false
35
35
  end
36
- it "should be true when everything printed" do
36
+ it "should be_true when everything printed" do
37
37
  create_pdf
38
38
  string = "Hello world, how are you?\nI'm fine, thank you."
39
39
  text_box = Prawn::Text::Box.new(string,
40
40
  :document => @pdf)
41
41
  text_box.render
42
- text_box.everything_printed?.should.be true
42
+ text_box.everything_printed?.should be_true
43
43
  end
44
44
  end
45
45
 
46
46
  describe "Text::Box#line_gap" do
47
- it "should equal the line gap of the font when using a single " +
47
+ it "should == the line gap of the font when using a single " +
48
48
  "font and font size" do
49
49
  create_pdf
50
50
  string = "Hello world, how are you?\nI'm fine, thank you."
51
51
  text_box = Prawn::Text::Box.new(string,
52
52
  :document => @pdf)
53
53
  text_box.render
54
- text_box.line_gap.should.be.close(@pdf.font.line_gap, 0.0001)
54
+ text_box.line_gap.should be_within(0.0001).of(@pdf.font.line_gap)
55
55
  end
56
56
  end
57
57
 
@@ -74,7 +74,7 @@ describe "Text::Box" do
74
74
  @pdf.text_direction(:rtl)
75
75
  @pdf.text_direction = :rtl
76
76
  @pdf.text_direction = :rtl
77
- @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", :size => 16) do
77
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
78
78
  @pdf.text "写个小"
79
79
  end
80
80
  text = PDF::Inspector::Text.analyze(@pdf.render)
@@ -116,7 +116,7 @@ describe "Text::Box" do
116
116
  end
117
117
  it "should default to document-wide leading if no" +
118
118
  "leading option is provided" do
119
-
119
+
120
120
  end
121
121
  end
122
122
 
@@ -128,7 +128,7 @@ describe "Text::Box#render with :align => :justify" do
128
128
  text_box = Prawn::Text::Box.new(string, options)
129
129
  text_box.render
130
130
  contents = PDF::Inspector::Text.analyze(@pdf.render)
131
- contents.word_spacing[0].should.be > 0
131
+ contents.word_spacing[0].should be > 0
132
132
  end
133
133
  it "should not justify the last line of a paragraph" do
134
134
  create_pdf
@@ -137,7 +137,7 @@ describe "Text::Box#render with :align => :justify" do
137
137
  text_box = Prawn::Text::Box.new(string, options)
138
138
  text_box.render
139
139
  contents = PDF::Inspector::Text.analyze(@pdf.render)
140
- contents.word_spacing.should.be.empty
140
+ contents.word_spacing.should be_empty
141
141
  end
142
142
  end
143
143
 
@@ -160,19 +160,19 @@ describe "Text::Box" do
160
160
  end
161
161
 
162
162
  describe "Text::Box#height without leading" do
163
- it "should equal the sum of the height of each line, " +
163
+ it "should == the sum of the height of each line, " +
164
164
  "not including the space below the last line" do
165
165
  create_pdf
166
166
  text = "Oh hai text rect.\nOh hai text rect."
167
167
  options = { :document => @pdf }
168
168
  text_box = Prawn::Text::Box.new(text, options)
169
169
  text_box.render
170
- text_box.height.should.be.close(@pdf.font.height * 2 - @pdf.font.line_gap, 0.001)
170
+ text_box.height.should be_within(0.001).of(@pdf.font.height * 2 - @pdf.font.line_gap)
171
171
  end
172
172
  end
173
173
 
174
174
  describe "Text::Box#height with leading" do
175
- it "should equal the sum of the height of each line plus leading, " +
175
+ it "should == the sum of the height of each line plus leading, " +
176
176
  "but not including the space below the last line" do
177
177
  create_pdf
178
178
  text = "Oh hai text rect.\nOh hai text rect."
@@ -180,7 +180,38 @@ describe "Text::Box#height with leading" do
180
180
  options = { :document => @pdf, :leading => leading }
181
181
  text_box = Prawn::Text::Box.new(text, options)
182
182
  text_box.render
183
- text_box.height.should.be.close((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading, 0.001)
183
+ text_box.height.should be_within(0.001).of((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading)
184
+ end
185
+ end
186
+
187
+ describe "Text::Box with :draw_text_callback" do
188
+ before(:each) { create_pdf }
189
+
190
+ it "hits the callback whenever text is drawn" do
191
+ draw_block = stub()
192
+ draw_block.expects(:kick).with("this text is long enough to")
193
+ draw_block.expects(:kick).with("span two lines")
194
+
195
+ @pdf.text_box "this text is long enough to span two lines",
196
+ :width => 150,
197
+ :draw_text_callback => lambda { |text, _| draw_block.kick(text) }
198
+ end
199
+
200
+ it "hits the callback once per fragment for :inline_format" do
201
+ draw_block = stub()
202
+ draw_block.expects(:kick).with("this text has ")
203
+ draw_block.expects(:kick).with("fancy")
204
+ draw_block.expects(:kick).with(" formatting")
205
+
206
+ @pdf.text_box "this text has <b>fancy</b> formatting",
207
+ :inline_format => true, :width => 500,
208
+ :draw_text_callback => lambda { |text, _| draw_block.kick(text) }
209
+ end
210
+
211
+ it "does not call #draw_text!" do
212
+ @pdf.expects(:draw_text!).never
213
+ @pdf.text_box "some text", :width => 500,
214
+ :draw_text_callback => lambda { |_, _| }
184
215
  end
185
216
  end
186
217
 
@@ -188,7 +219,7 @@ describe "Text::Box#valid_options" do
188
219
  it "should return an array" do
189
220
  create_pdf
190
221
  text_box = Prawn::Text::Box.new("", :document => @pdf)
191
- text_box.valid_options.should.be.kind_of(Array)
222
+ text_box.valid_options.should be_a_kind_of(Array)
192
223
  end
193
224
  end
194
225
 
@@ -211,7 +242,7 @@ describe "Text::Box#render" do
211
242
  text_box = Prawn::Text::Box.new(@text, @options)
212
243
  text_box.render
213
244
  text = PDF::Inspector::Text.analyze(@pdf.render)
214
- text.strings.should.not.be.empty
245
+ text.strings.should_not be_empty
215
246
  end
216
247
  it "should not draw a transformation matrix" do
217
248
  create_pdf
@@ -245,16 +276,17 @@ describe "Text::Box#render(:dry_run => true)" do
245
276
  text_box = Prawn::Text::Box.new(@text, @options)
246
277
  text_box.render(:dry_run => true)
247
278
  text = PDF::Inspector::Text.analyze(@pdf.render)
248
- text.strings.should.be.empty
279
+ text.strings.should be_empty
249
280
  end
250
- it "subsequent calls to render should not raise an ArgumentError exception" do
281
+
282
+ it "subsequent calls to render should_not raise_error an ArgumentError exception" do
251
283
  create_pdf
252
284
  @text = "™©"
253
285
  @options = { :document => @pdf }
254
286
  text_box = Prawn::Text::Box.new(@text, @options)
255
287
  text_box.render(:dry_run => true)
256
- lambda { text_box.render }.should.not.raise(
257
- Prawn::Errors::IncompatibleStringEncoding)
288
+
289
+ text_box.render
258
290
  end
259
291
  end
260
292
 
@@ -275,6 +307,23 @@ describe "Text::Box#render(:valign => :bottom)" do
275
307
  end
276
308
  end
277
309
 
310
+ describe "Text::Box#render(:valign => :center)" do
311
+ it "#at should be the same from one dry run to the next" do
312
+ create_pdf
313
+ text = "this is center text " * 12
314
+ options = { :width => 162,
315
+ :valign => :center,
316
+ :document => @pdf }
317
+ text_box = Prawn::Text::Box.new(text, options)
318
+
319
+ text_box.render(:dry_run => true)
320
+ original_at = text_box.at.dup
321
+
322
+ text_box.render(:dry_run => true)
323
+ text_box.at.should == original_at
324
+ end
325
+ end
326
+
278
327
  describe "Text::Box#render with :rotate option of 30)" do
279
328
  before(:each) do
280
329
  create_pdf
@@ -312,7 +361,7 @@ describe "Text::Box#render with :rotate option of 30)" do
312
361
  reduce_precision(@cos), 0, 0]
313
362
 
314
363
  text = PDF::Inspector::Text.analyze(@pdf.render)
315
- text.strings.should.not.be.empty
364
+ text.strings.should_not be_empty
316
365
  end
317
366
  end
318
367
  context ":rotate_around option of :upper_left" do
@@ -335,7 +384,7 @@ describe "Text::Box#render with :rotate option of 30)" do
335
384
  reduce_precision(@cos), 0, 0]
336
385
 
337
386
  text = PDF::Inspector::Text.analyze(@pdf.render)
338
- text.strings.should.not.be.empty
387
+ text.strings.should_not be_empty
339
388
  end
340
389
  end
341
390
  context "default :rotate_around" do
@@ -357,7 +406,7 @@ describe "Text::Box#render with :rotate option of 30)" do
357
406
  reduce_precision(@cos), 0, 0]
358
407
 
359
408
  text = PDF::Inspector::Text.analyze(@pdf.render)
360
- text.strings.should.not.be.empty
409
+ text.strings.should_not be_empty
361
410
  end
362
411
  end
363
412
  context ":rotate_around option of :upper_right" do
@@ -380,7 +429,7 @@ describe "Text::Box#render with :rotate option of 30)" do
380
429
  reduce_precision(@cos), 0, 0]
381
430
 
382
431
  text = PDF::Inspector::Text.analyze(@pdf.render)
383
- text.strings.should.not.be.empty
432
+ text.strings.should_not be_empty
384
433
  end
385
434
  end
386
435
  context ":rotate_around option of :lower_right" do
@@ -403,7 +452,7 @@ describe "Text::Box#render with :rotate option of 30)" do
403
452
  reduce_precision(@cos), 0, 0]
404
453
 
405
454
  text = PDF::Inspector::Text.analyze(@pdf.render)
406
- text.strings.should.not.be.empty
455
+ text.strings.should_not be_empty
407
456
  end
408
457
  end
409
458
  context ":rotate_around option of :lower_left" do
@@ -426,7 +475,7 @@ describe "Text::Box#render with :rotate option of 30)" do
426
475
  reduce_precision(@cos), 0, 0]
427
476
 
428
477
  text = PDF::Inspector::Text.analyze(@pdf.render)
429
- text.strings.should.not.be.empty
478
+ text.strings.should_not be_empty
430
479
  end
431
480
  end
432
481
  end
@@ -439,7 +488,7 @@ describe "Text::Box default height" do
439
488
  @text = "Oh hai\n" * 60
440
489
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
441
490
  text_box.render
442
- text_box.height.should.be.close(target_height, @pdf.font.height)
491
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
443
492
  end
444
493
 
445
494
  it "should use the margin-box bottom if only in a stretchy bbox" do
@@ -448,7 +497,7 @@ describe "Text::Box default height" do
448
497
  @text = "Oh hai\n" * 60
449
498
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
450
499
  text_box.render
451
- text_box.height.should.be.close(target_height, @pdf.font.height)
500
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
452
501
  end
453
502
  end
454
503
 
@@ -460,7 +509,7 @@ describe "Text::Box default height" do
460
509
  text_box = Prawn::Text::Box.new(@text, :document => @pdf,
461
510
  :height => 100, :overflow => :expand)
462
511
  text_box.render
463
- text_box.height.should.be.close(target_height, @pdf.font.height)
512
+ text_box.height.should be_within(@pdf.font.height).of(target_height)
464
513
  end
465
514
  end
466
515
 
@@ -471,7 +520,7 @@ describe "Text::Box default height" do
471
520
  @text = "Oh hai\n" * 60
472
521
  text_box = Prawn::Text::Box.new(@text, :document => @pdf)
473
522
  text_box.render
474
- text_box.height.should.be.close(200, @pdf.font.height)
523
+ text_box.height.should be_within(@pdf.font.height).of(200)
475
524
  end
476
525
  end
477
526
  end
@@ -500,7 +549,7 @@ describe "Text::Box with text than can fit in the box" do
500
549
  :document => @pdf
501
550
  }
502
551
  end
503
-
552
+
504
553
  it "printed text should match requested text, except that preceding and " +
505
554
  "trailing white space will be stripped from each line, and newlines may " +
506
555
  "be inserted" do
@@ -508,7 +557,7 @@ describe "Text::Box with text than can fit in the box" do
508
557
  text_box.render
509
558
  text_box.text.gsub("\n", " ").should == @text.strip
510
559
  end
511
-
560
+
512
561
  it "render should return an empty string because no text remains unprinted" do
513
562
  text_box = Prawn::Text::Box.new(@text, @options)
514
563
  text_box.render.should == ""
@@ -518,7 +567,7 @@ describe "Text::Box with text than can fit in the box" do
518
567
  @options[:leading] = 40
519
568
  text_box = Prawn::Text::Box.new(@text, @options)
520
569
  text_box.render
521
- text_box.text.gsub("\n", " ").should.not == @text.strip
570
+ text_box.text.gsub("\n", " ").should_not == @text.strip
522
571
  end
523
572
  end
524
573
 
@@ -534,12 +583,12 @@ describe "Text::Box with text that fits exactly in the box" do
534
583
  :document => @pdf
535
584
  }
536
585
  end
537
-
586
+
538
587
  it "should have the expected height" do
539
588
  expected_height = @options.delete(:height)
540
589
  text_box = Prawn::Text::Box.new(@text, @options)
541
590
  text_box.render
542
- text_box.height.should.be.close(expected_height, 0.0001)
591
+ text_box.height.should be_within(0.0001).of(expected_height)
543
592
  end
544
593
 
545
594
  it "should print everything" do
@@ -564,7 +613,7 @@ describe "Text::Box with text that fits exactly in the box" do
564
613
  @options[:height] += @options[:leading] * @interlines - 1
565
614
  text_box = Prawn::Text::Box.new(@text, @options)
566
615
  text_box.render
567
- text_box.text.should.not == @text
616
+ text_box.text.should_not == @text
568
617
  end
569
618
  end
570
619
 
@@ -584,14 +633,14 @@ describe "Text::Box with text that fits exactly in the box" do
584
633
  @options[:height] += @options[:leading] * @interlines - 1
585
634
  text_box = Prawn::Text::Box.new(@text, @options)
586
635
  text_box.render
587
- text_box.text.should.not == @text
636
+ text_box.text.should_not == @text
588
637
  end
589
638
  end
590
639
  end
591
640
 
592
641
  describe "Text::Box printing UTF-8 string with higher bit characters" do
593
642
  before(:each) do
594
- create_pdf
643
+ create_pdf
595
644
  @text = "©"
596
645
  # not enough height to print any text, so we can directly compare against
597
646
  # the input string
@@ -600,7 +649,7 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
600
649
  :height => bounding_height,
601
650
  :document => @pdf
602
651
  }
603
- file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
652
+ file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
604
653
  @pdf.font_families["Action Man"] = {
605
654
  :normal => { :file => file, :font => "ActionMan" },
606
655
  :italic => { :file => file, :font => "ActionMan-Italic" },
@@ -615,13 +664,14 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
615
664
  remaining_text = @text_box.render
616
665
  remaining_text.should == @text
617
666
  end
667
+
618
668
  it "subsequent calls to Text::Box need not include the" +
619
669
  " :skip_encoding => true option" do
620
670
  @pdf.font("Action Man")
621
671
  remaining_text = @text_box.render
622
- lambda {
623
- @pdf.text_box(remaining_text, :document => @pdf)
624
- }.should.not.raise(Prawn::Errors::IncompatibleStringEncoding)
672
+
673
+ # expect that calling text_box will not raise an encoding error
674
+ @pdf.text_box(remaining_text, :document => @pdf)
625
675
  end
626
676
  end
627
677
 
@@ -635,18 +685,17 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
635
685
  remaining_text = @text_box.render
636
686
  lambda {
637
687
  @pdf.text_box(remaining_text, :document => @pdf)
638
- }.should.raise(Prawn::Errors::IncompatibleStringEncoding)
639
- lambda {
640
- @pdf.text_box(remaining_text, :skip_encoding => true,
641
- :document => @pdf)
642
- }.should.not.raise(Prawn::Errors::IncompatibleStringEncoding)
688
+ }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
689
+
690
+ @pdf.text_box(remaining_text, :skip_encoding => true,
691
+ :document => @pdf)
643
692
  end
644
693
  end
645
694
  end
646
695
 
647
696
  describe "Text::Box with more text than can fit in the box" do
648
697
  before(:each) do
649
- create_pdf
698
+ create_pdf
650
699
  @text = "Oh hai text rect. " * 30
651
700
  @bounding_height = 162.0
652
701
  @options = {
@@ -655,7 +704,7 @@ describe "Text::Box with more text than can fit in the box" do
655
704
  :document => @pdf
656
705
  }
657
706
  end
658
-
707
+
659
708
  context "truncated overflow" do
660
709
  before(:each) do
661
710
  @options[:overflow] = :truncate
@@ -663,18 +712,18 @@ describe "Text::Box with more text than can fit in the box" do
663
712
  end
664
713
  it "should be truncated" do
665
714
  @text_box.render
666
- @text_box.text.gsub("\n", " ").should.not == @text.strip
715
+ @text_box.text.gsub("\n", " ").should_not == @text.strip
667
716
  end
668
717
  it "render should not return an empty string because some text remains unprinted" do
669
- @text_box.render.should.not.be.empty
718
+ @text_box.render.should_not be_empty
670
719
  end
671
720
  it "#height should be no taller than the specified height" do
672
721
  @text_box.render
673
- @text_box.height.should.be <= @bounding_height
722
+ @text_box.height.should be <= @bounding_height
674
723
  end
675
724
  it "#height should be within one font height of the specified height" do
676
725
  @text_box.render
677
- @bounding_height.should.be.close(@text_box.height, @pdf.font.height)
726
+ @bounding_height.should be_within(@pdf.font.height).of(@text_box.height)
678
727
  end
679
728
  context "with :rotate option" do
680
729
  it "unrendered text should be the same as when not rotated" do
@@ -693,7 +742,7 @@ describe "Text::Box with more text than can fit in the box" do
693
742
  end
694
743
  end
695
744
  end
696
-
745
+
697
746
  context "truncated with text and size taken from the manual" do
698
747
  it "should return the right text" do
699
748
  @text = "This is the beginning of the text. It will be cut somewhere and " +
@@ -783,7 +832,7 @@ describe "Text::Box with a solid block of Chinese characters" do
783
832
  :height => 162.0,
784
833
  :document => @pdf
785
834
  }
786
- @pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
835
+ @pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
787
836
  @options[:overflow] = :truncate
788
837
  text_box = Prawn::Text::Box.new(@text, @options)
789
838
  text_box.render
@@ -792,8 +841,8 @@ describe "Text::Box with a solid block of Chinese characters" do
792
841
  end
793
842
 
794
843
 
795
- describe "drawing bounding boxes" do
796
- before(:each) { create_pdf }
844
+ describe "drawing bounding boxes" do
845
+ before(:each) { create_pdf }
797
846
 
798
847
  it "should restore the margin box when bounding box exits" do
799
848
  margin_box = @pdf.bounds
@@ -828,7 +877,7 @@ describe "Text::Box#render with :character_spacing option" do
828
877
  text_box.text.should == "hello\nworld"
829
878
  end
830
879
  end
831
-
880
+
832
881
  describe "Text::Box wrapping" do
833
882
  before(:each) do
834
883
  create_pdf
@@ -943,7 +992,7 @@ describe "Text::Box wrapping" do
943
992
 
944
993
  expected = "©" * 25 + "\n" + "©" * 5
945
994
  @pdf.font.normalize_encoding!(expected)
946
- expected = expected.force_encoding("utf-8") if expected.respond_to?(:force_encoding)
995
+ expected = expected.force_encoding(Encoding::UTF_8)
947
996
  text_box.text.should == expected
948
997
  end
949
998
 
@@ -960,7 +1009,7 @@ describe "Text::Box wrapping" do
960
1009
  text_box.render
961
1010
  results_without_accent = text_box.text
962
1011
 
963
- results_with_accent.first_line.length.should == results_without_accent.first_line.length
1012
+ first_line(results_with_accent).length.should == first_line(results_without_accent).length
964
1013
  end
965
1014
  end
966
1015
 
@@ -979,3 +1028,7 @@ end
979
1028
  def reduce_precision(float)
980
1029
  ("%.5f" % float).to_f
981
1030
  end
1031
+
1032
+ def first_line(str)
1033
+ str.each_line { |line| return line }
1034
+ end
@@ -18,7 +18,7 @@ describe "#text_rendering_mode" do
18
18
  @pdf.text("hello world")
19
19
  end
20
20
  contents = PDF::Inspector::Text.analyze(@pdf.render)
21
- contents.text_rendering_mode.should.be.empty
21
+ contents.text_rendering_mode.should be_empty
22
22
  end
23
23
  it "should restore character spacing to 0" do
24
24
  create_pdf
@@ -36,10 +36,10 @@ describe "#text_rendering_mode" do
36
36
  end
37
37
  @pdf.text_rendering_mode.should == :fill
38
38
  end
39
- it "should raise an exception when passed an invalid mode" do
39
+ it "should raise_error an exception when passed an invalid mode" do
40
40
  create_pdf
41
- lambda { @pdf.text_rendering_mode(-1) }.should.raise(ArgumentError)
42
- lambda { @pdf.text_rendering_mode(8) }.should.raise(ArgumentError)
43
- lambda { @pdf.text_rendering_mode(:flil) }.should.raise(ArgumentError)
41
+ lambda { @pdf.text_rendering_mode(-1) }.should raise_error(ArgumentError)
42
+ lambda { @pdf.text_rendering_mode(8) }.should raise_error(ArgumentError)
43
+ lambda { @pdf.text_rendering_mode(:flil) }.should raise_error(ArgumentError)
44
44
  end
45
45
  end
@@ -18,7 +18,7 @@ describe "#character_spacing" do
18
18
  @pdf.text("hello world")
19
19
  end
20
20
  contents = PDF::Inspector::Text.analyze(@pdf.render)
21
- contents.character_spacing.should.be.empty
21
+ contents.character_spacing.should be_empty
22
22
  end
23
23
  it "should restore character spacing to 0" do
24
24
  create_pdf
@@ -36,6 +36,24 @@ describe "#character_spacing" do
36
36
  end
37
37
  @pdf.character_spacing.should == 0
38
38
  end
39
+
40
+ # ensure that we properly internationalize by using the number of characters
41
+ # in a string, not the number of bytes, to insert character spaces
42
+ #
43
+ it "should calculate character spacing widths by characters, not bytes" do
44
+ create_pdf
45
+ @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
46
+
47
+ str = "こんにちは世界"
48
+ @pdf.character_spacing(0) do
49
+ @raw_width = @pdf.width_of(str)
50
+ end
51
+
52
+ @pdf.character_spacing(10) do
53
+ # the new width should include seven 10-pt character spaces.
54
+ @pdf.width_of(str).should be_within(0.001).of(@raw_width + (10 * 7))
55
+ end
56
+ end
39
57
  end
40
58
 
41
59
  describe "#word_spacing" do
@@ -54,7 +72,7 @@ describe "#word_spacing" do
54
72
  @pdf.text("hello world")
55
73
  end
56
74
  contents = PDF::Inspector::Text.analyze(@pdf.render)
57
- contents.word_spacing.should.be.empty
75
+ contents.word_spacing.should be_empty
58
76
  end
59
77
  it "should restore word spacing to 0" do
60
78
  create_pdf