prawn 0.13.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +10 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -16
  6. data/Rakefile +17 -39
  7. data/lib/prawn/document/bounding_box.rb +85 -42
  8. data/lib/prawn/document/column_box.rb +21 -11
  9. data/lib/prawn/document/internals.rb +40 -147
  10. data/lib/prawn/document/span.rb +25 -17
  11. data/lib/prawn/document.rb +286 -245
  12. data/lib/prawn/encoding.rb +68 -101
  13. data/lib/prawn/errors.rb +47 -43
  14. data/lib/prawn/font.rb +204 -155
  15. data/lib/prawn/font_metric_cache.rb +25 -21
  16. data/lib/prawn/fonts/afm.rb +292 -0
  17. data/lib/prawn/{font → fonts}/dfont.rb +7 -13
  18. data/lib/prawn/fonts/otf.rb +11 -0
  19. data/lib/prawn/fonts/ttc.rb +36 -0
  20. data/lib/prawn/{font → fonts}/ttf.rb +142 -80
  21. data/lib/prawn/graphics/blend_mode.rb +65 -0
  22. data/lib/prawn/graphics/cap_style.rb +6 -5
  23. data/lib/prawn/graphics/color.rb +47 -44
  24. data/lib/prawn/graphics/dash.rb +30 -13
  25. data/lib/prawn/graphics/join_style.rb +13 -6
  26. data/lib/prawn/graphics/patterns.rb +221 -90
  27. data/lib/prawn/graphics/transformation.rb +21 -12
  28. data/lib/prawn/graphics/transparency.rb +21 -17
  29. data/lib/prawn/graphics.rb +155 -128
  30. data/lib/prawn/{layout/grid.rb → grid.rb} +110 -47
  31. data/lib/prawn/image_handler.rb +16 -2
  32. data/lib/prawn/images/image.rb +4 -2
  33. data/lib/prawn/images/jpg.rb +39 -30
  34. data/lib/prawn/images/png.rb +132 -169
  35. data/lib/prawn/images.rb +70 -62
  36. data/lib/prawn/measurement_extensions.rb +15 -10
  37. data/lib/prawn/measurements.rb +22 -23
  38. data/lib/prawn/outline.rb +301 -13
  39. data/lib/prawn/repeater.rb +19 -17
  40. data/lib/prawn/security/arcfour.rb +54 -0
  41. data/lib/prawn/security.rb +108 -86
  42. data/lib/prawn/soft_mask.rb +40 -41
  43. data/lib/prawn/stamp.rb +29 -12
  44. data/lib/prawn/text/box.rb +27 -29
  45. data/lib/prawn/text/formatted/arranger.rb +110 -67
  46. data/lib/prawn/text/formatted/box.rb +233 -165
  47. data/lib/prawn/text/formatted/fragment.rb +27 -27
  48. data/lib/prawn/text/formatted/line_wrap.rb +137 -97
  49. data/lib/prawn/text/formatted/parser.rb +149 -127
  50. data/lib/prawn/text/formatted/wrap.rb +57 -37
  51. data/lib/prawn/text/formatted.rb +6 -4
  52. data/lib/prawn/text.rb +105 -73
  53. data/lib/prawn/transformation_stack.rb +44 -0
  54. data/lib/prawn/utilities.rb +11 -21
  55. data/lib/prawn/version.rb +5 -0
  56. data/lib/prawn/view.rb +101 -0
  57. data/lib/prawn.rb +42 -68
  58. data/{data/images/fractal.jpg → manual/absolute_position.pdf} +0 -0
  59. data/manual/basic_concepts/adding_pages.rb +9 -10
  60. data/manual/basic_concepts/basic_concepts.rb +33 -24
  61. data/manual/basic_concepts/creation.rb +10 -11
  62. data/manual/basic_concepts/cursor.rb +9 -10
  63. data/manual/basic_concepts/measurement.rb +10 -11
  64. data/manual/basic_concepts/origin.rb +8 -9
  65. data/manual/basic_concepts/other_cursor_helpers.rb +17 -18
  66. data/manual/basic_concepts/view.rb +48 -0
  67. data/manual/bounding_box/bounding_box.rb +31 -29
  68. data/manual/bounding_box/bounds.rb +17 -18
  69. data/manual/bounding_box/canvas.rb +8 -9
  70. data/manual/bounding_box/creation.rb +8 -9
  71. data/manual/bounding_box/indentation.rb +22 -23
  72. data/manual/bounding_box/nesting.rb +32 -25
  73. data/manual/bounding_box/russian_boxes.rb +19 -19
  74. data/manual/bounding_box/stretchy.rb +18 -20
  75. data/manual/contents.rb +35 -0
  76. data/manual/cover.rb +43 -0
  77. data/manual/document_and_page_options/background.rb +16 -14
  78. data/manual/document_and_page_options/document_and_page_options.rb +26 -23
  79. data/manual/document_and_page_options/metadata.rb +21 -19
  80. data/manual/document_and_page_options/page_margins.rb +20 -22
  81. data/manual/document_and_page_options/page_size.rb +15 -15
  82. data/manual/document_and_page_options/print_scaling.rb +23 -0
  83. data/manual/example_helper.rb +5 -408
  84. data/manual/graphics/blend_mode.rb +52 -0
  85. data/manual/graphics/circle_and_ellipse.rb +8 -9
  86. data/manual/graphics/color.rb +11 -13
  87. data/manual/graphics/common_lines.rb +13 -12
  88. data/manual/graphics/fill_and_stroke.rb +10 -11
  89. data/manual/graphics/fill_rules.rb +13 -12
  90. data/manual/graphics/gradients.rb +28 -22
  91. data/manual/graphics/graphics.rb +52 -46
  92. data/manual/graphics/helper.rb +20 -10
  93. data/manual/graphics/line_width.rb +13 -12
  94. data/manual/graphics/lines_and_curves.rb +13 -14
  95. data/manual/graphics/polygon.rb +10 -12
  96. data/manual/graphics/rectangle.rb +7 -8
  97. data/manual/graphics/rotate.rb +9 -12
  98. data/manual/graphics/scale.rb +19 -18
  99. data/manual/graphics/soft_masks.rb +5 -7
  100. data/manual/graphics/stroke_cap.rb +10 -11
  101. data/manual/graphics/stroke_dash.rb +16 -17
  102. data/manual/graphics/stroke_join.rb +10 -11
  103. data/manual/graphics/translate.rb +13 -13
  104. data/manual/graphics/transparency.rb +11 -13
  105. data/manual/{manual/how_to_read_this_manual.rb → how_to_read_this_manual.rb} +23 -25
  106. data/manual/images/absolute_position.rb +9 -10
  107. data/manual/images/fit.rb +9 -10
  108. data/manual/images/horizontal.rb +13 -14
  109. data/manual/images/images.rb +31 -30
  110. data/manual/images/plain_image.rb +6 -7
  111. data/manual/images/scale.rb +12 -13
  112. data/manual/images/vertical.rb +19 -17
  113. data/manual/images/width_and_height.rb +13 -14
  114. data/manual/layout/boxes.rb +14 -15
  115. data/manual/layout/content.rb +12 -13
  116. data/manual/layout/layout.rb +19 -20
  117. data/manual/layout/simple_grid.rb +8 -9
  118. data/manual/outline/add_subsection_to.rb +26 -27
  119. data/manual/outline/insert_section_after.rb +19 -20
  120. data/manual/outline/outline.rb +23 -22
  121. data/manual/outline/sections_and_pages.rb +24 -25
  122. data/manual/repeatable_content/alternate_page_numbering.rb +36 -0
  123. data/manual/repeatable_content/page_numbering.rb +20 -19
  124. data/manual/repeatable_content/repeatable_content.rb +26 -22
  125. data/manual/repeatable_content/repeater.rb +18 -19
  126. data/manual/repeatable_content/stamp.rb +18 -19
  127. data/manual/security/encryption.rb +8 -11
  128. data/manual/security/permissions.rb +20 -15
  129. data/manual/security/security.rb +20 -20
  130. data/manual/table.rb +16 -0
  131. data/manual/text/alignment.rb +17 -18
  132. data/manual/text/color.rb +13 -13
  133. data/manual/text/column_box.rb +10 -12
  134. data/manual/text/fallback_fonts.rb +29 -25
  135. data/manual/text/font.rb +17 -18
  136. data/manual/text/font_size.rb +21 -22
  137. data/manual/text/font_style.rb +12 -10
  138. data/manual/text/formatted_callbacks.rb +36 -26
  139. data/manual/text/formatted_text.rb +41 -34
  140. data/manual/text/free_flowing_text.rb +28 -29
  141. data/manual/text/inline.rb +23 -26
  142. data/manual/text/kerning_and_character_spacing.rb +20 -21
  143. data/manual/text/leading.rb +10 -11
  144. data/manual/text/line_wrapping.rb +40 -21
  145. data/manual/text/paragraph_indentation.rb +17 -12
  146. data/manual/text/positioned_text.rb +19 -20
  147. data/manual/text/registering_families.rb +33 -30
  148. data/manual/text/rendering_and_color.rb +11 -12
  149. data/manual/text/right_to_left_text.rb +31 -20
  150. data/manual/text/rotation.rb +36 -27
  151. data/manual/text/single_usage.rb +13 -14
  152. data/manual/text/text.rb +62 -62
  153. data/manual/text/text_box_excess.rb +22 -19
  154. data/manual/text/text_box_extensions.rb +21 -18
  155. data/manual/text/text_box_overflow.rb +28 -21
  156. data/manual/text/utf8.rb +16 -17
  157. data/manual/text/win_ansi_charset.rb +29 -26
  158. data/prawn.gemspec +45 -43
  159. data/spec/extensions/encoding_helpers.rb +4 -3
  160. data/spec/prawn/document/bounding_box_spec.rb +550 -0
  161. data/spec/prawn/document/column_box_spec.rb +75 -0
  162. data/spec/prawn/document/security_spec.rb +176 -0
  163. data/spec/prawn/document_annotations_spec.rb +76 -0
  164. data/spec/prawn/document_destinations_spec.rb +15 -0
  165. data/spec/prawn/document_grid_spec.rb +99 -0
  166. data/spec/prawn/document_reference_spec.rb +27 -0
  167. data/spec/prawn/document_span_spec.rb +44 -0
  168. data/spec/prawn/document_spec.rb +805 -0
  169. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  170. data/spec/prawn/font_spec.rb +544 -0
  171. data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
  172. data/spec/prawn/graphics/transparency_spec.rb +81 -0
  173. data/spec/prawn/graphics_spec.rb +872 -0
  174. data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
  175. data/spec/prawn/image_handler_spec.rb +53 -0
  176. data/spec/prawn/images/jpg_spec.rb +20 -0
  177. data/spec/prawn/images/png_spec.rb +283 -0
  178. data/spec/prawn/images_spec.rb +229 -0
  179. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  180. data/spec/prawn/outline_spec.rb +512 -0
  181. data/spec/prawn/repeater_spec.rb +166 -0
  182. data/spec/prawn/soft_mask_spec.rb +74 -0
  183. data/spec/prawn/stamp_spec.rb +173 -0
  184. data/spec/prawn/text/box_spec.rb +1110 -0
  185. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  186. data/spec/prawn/text/formatted/box_spec.rb +849 -0
  187. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  188. data/spec/prawn/text/formatted/line_wrap_spec.rb +495 -0
  189. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  190. data/spec/prawn/text_draw_text_spec.rb +150 -0
  191. data/spec/prawn/text_rendering_mode_spec.rb +48 -0
  192. data/spec/prawn/text_spacing_spec.rb +95 -0
  193. data/spec/prawn/text_spec.rb +603 -0
  194. data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
  195. data/spec/prawn/transformation_stack_spec.rb +66 -0
  196. data/spec/prawn/view_spec.rb +63 -0
  197. data/spec/prawn_manual_spec.rb +35 -0
  198. data/spec/spec_helper.rb +22 -21
  199. data.tar.gz.sig +0 -0
  200. metadata +168 -307
  201. metadata.gz.sig +0 -0
  202. data/README.md +0 -109
  203. data/data/encodings/win_ansi.txt +0 -29
  204. data/data/images/16bit.alpha +0 -0
  205. data/data/images/16bit.dat +0 -0
  206. data/data/images/16bit.png +0 -0
  207. data/data/images/arrow.png +0 -0
  208. data/data/images/arrow2.png +0 -0
  209. data/data/images/barcode_issue.png +0 -0
  210. data/data/images/dice.alpha +0 -0
  211. data/data/images/dice.dat +0 -0
  212. data/data/images/dice.png +0 -0
  213. data/data/images/dice_interlaced.png +0 -0
  214. data/data/images/indexed_color.dat +0 -0
  215. data/data/images/indexed_color.png +0 -0
  216. data/data/images/letterhead.jpg +0 -0
  217. data/data/images/page_white_text.alpha +0 -0
  218. data/data/images/page_white_text.dat +0 -0
  219. data/data/images/page_white_text.png +0 -0
  220. data/data/images/pigs.jpg +0 -0
  221. data/data/images/prawn.png +0 -0
  222. data/data/images/ruport.png +0 -0
  223. data/data/images/ruport_data.dat +0 -0
  224. data/data/images/ruport_transparent.png +0 -0
  225. data/data/images/ruport_type0.png +0 -0
  226. data/data/images/stef.jpg +0 -0
  227. data/data/images/tru256.bmp +0 -0
  228. data/data/images/web-links.dat +0 -1
  229. data/data/images/web-links.png +0 -0
  230. data/data/pdfs/complex_template.pdf +0 -0
  231. data/data/pdfs/contains_ttf_font.pdf +0 -0
  232. data/data/pdfs/encrypted.pdf +0 -0
  233. data/data/pdfs/form.pdf +1 -819
  234. data/data/pdfs/hexagon.pdf +0 -61
  235. data/data/pdfs/indirect_reference.pdf +0 -86
  236. data/data/pdfs/multipage_template.pdf +0 -127
  237. data/data/pdfs/nested_pages.pdf +0 -118
  238. data/data/pdfs/page_without_mediabox.pdf +0 -193
  239. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  240. data/data/pdfs/two_hexagons.pdf +0 -90
  241. data/data/pdfs/version_1_6.pdf +0 -61
  242. data/data/shift_jis_text.txt +0 -1
  243. data/lib/pdf/core/annotations.rb +0 -60
  244. data/lib/pdf/core/byte_string.rb +0 -9
  245. data/lib/pdf/core/destinations.rb +0 -90
  246. data/lib/pdf/core/document_state.rb +0 -78
  247. data/lib/pdf/core/filter_list.rb +0 -51
  248. data/lib/pdf/core/filters.rb +0 -36
  249. data/lib/pdf/core/graphics_state.rb +0 -68
  250. data/lib/pdf/core/literal_string.rb +0 -16
  251. data/lib/pdf/core/name_tree.rb +0 -177
  252. data/lib/pdf/core/object_store.rb +0 -320
  253. data/lib/pdf/core/outline.rb +0 -315
  254. data/lib/pdf/core/page.rb +0 -212
  255. data/lib/pdf/core/page_geometry.rb +0 -126
  256. data/lib/pdf/core/pdf_object.rb +0 -124
  257. data/lib/pdf/core/reference.rb +0 -103
  258. data/lib/pdf/core/stream.rb +0 -98
  259. data/lib/pdf/core/text.rb +0 -275
  260. data/lib/pdf/core.rb +0 -35
  261. data/lib/prawn/compatibility.rb +0 -91
  262. data/lib/prawn/document/graphics_state.rb +0 -73
  263. data/lib/prawn/document/snapshot.rb +0 -89
  264. data/lib/prawn/font/afm.rb +0 -203
  265. data/lib/prawn/layout.rb +0 -20
  266. data/lib/prawn/table/cell/image.rb +0 -70
  267. data/lib/prawn/table/cell/in_table.rb +0 -27
  268. data/lib/prawn/table/cell/span_dummy.rb +0 -92
  269. data/lib/prawn/table/cell/subtable.rb +0 -65
  270. data/lib/prawn/table/cell/text.rb +0 -153
  271. data/lib/prawn/table/cell.rb +0 -770
  272. data/lib/prawn/table/cells.rb +0 -295
  273. data/lib/prawn/table.rb +0 -643
  274. data/manual/example_file.rb +0 -116
  275. data/manual/example_package.rb +0 -53
  276. data/manual/example_section.rb +0 -46
  277. data/manual/manual/cover.rb +0 -35
  278. data/manual/manual/foreword.rb +0 -85
  279. data/manual/manual/manual.rb +0 -35
  280. data/manual/syntax_highlight.rb +0 -52
  281. data/manual/table/basic_block.rb +0 -53
  282. data/manual/table/before_rendering_page.rb +0 -26
  283. data/manual/table/cell_border_lines.rb +0 -24
  284. data/manual/table/cell_borders_and_bg.rb +0 -31
  285. data/manual/table/cell_dimensions.rb +0 -30
  286. data/manual/table/cell_text.rb +0 -38
  287. data/manual/table/column_widths.rb +0 -30
  288. data/manual/table/content_and_subtables.rb +0 -39
  289. data/manual/table/creation.rb +0 -27
  290. data/manual/table/filtering.rb +0 -36
  291. data/manual/table/flow_and_header.rb +0 -17
  292. data/manual/table/image_cells.rb +0 -33
  293. data/manual/table/position.rb +0 -29
  294. data/manual/table/row_colors.rb +0 -20
  295. data/manual/table/span.rb +0 -30
  296. data/manual/table/style.rb +0 -22
  297. data/manual/table/table.rb +0 -52
  298. data/manual/table/width.rb +0 -27
  299. data/manual/templates/full_template.rb +0 -25
  300. data/manual/templates/page_template.rb +0 -48
  301. data/manual/templates/templates.rb +0 -27
  302. data/manual/text/group.rb +0 -29
  303. data/spec/acceptance/png.rb +0 -23
  304. data/spec/annotations_spec.rb +0 -74
  305. data/spec/bounding_box_spec.rb +0 -493
  306. data/spec/cell_spec.rb +0 -628
  307. data/spec/column_box_spec.rb +0 -33
  308. data/spec/destinations_spec.rb +0 -15
  309. data/spec/document_spec.rb +0 -761
  310. data/spec/extensions/mocha.rb +0 -44
  311. data/spec/filters_spec.rb +0 -34
  312. data/spec/font_metric_cache_spec.rb +0 -52
  313. data/spec/font_spec.rb +0 -464
  314. data/spec/formatted_text_arranger_spec.rb +0 -421
  315. data/spec/formatted_text_box_spec.rb +0 -650
  316. data/spec/formatted_text_fragment_spec.rb +0 -298
  317. data/spec/graphics_spec.rb +0 -651
  318. data/spec/grid_spec.rb +0 -85
  319. data/spec/image_handler_spec.rb +0 -42
  320. data/spec/images_spec.rb +0 -157
  321. data/spec/inline_formatted_text_parser_spec.rb +0 -564
  322. data/spec/jpg_spec.rb +0 -25
  323. data/spec/line_wrap_spec.rb +0 -333
  324. data/spec/measurement_units_spec.rb +0 -23
  325. data/spec/name_tree_spec.rb +0 -112
  326. data/spec/object_store_spec.rb +0 -170
  327. data/spec/outline_spec.rb +0 -448
  328. data/spec/pdf_object_spec.rb +0 -172
  329. data/spec/png_spec.rb +0 -240
  330. data/spec/reference_spec.rb +0 -82
  331. data/spec/repeater_spec.rb +0 -158
  332. data/spec/security_spec.rb +0 -158
  333. data/spec/snapshot_spec.rb +0 -186
  334. data/spec/soft_mask_spec.rb +0 -117
  335. data/spec/span_spec.rb +0 -44
  336. data/spec/stamp_spec.rb +0 -158
  337. data/spec/stream_spec.rb +0 -58
  338. data/spec/stroke_styles_spec.rb +0 -211
  339. data/spec/table/span_dummy_spec.rb +0 -17
  340. data/spec/table_spec.rb +0 -1355
  341. data/spec/template_spec.rb +0 -351
  342. data/spec/text_at_spec.rb +0 -130
  343. data/spec/text_box_spec.rb +0 -1030
  344. data/spec/text_rendering_mode_spec.rb +0 -45
  345. data/spec/text_spacing_spec.rb +0 -93
  346. data/spec/text_spec.rb +0 -425
  347. data/spec/text_with_inline_formatting_spec.rb +0 -35
  348. data/spec/transparency_spec.rb +0 -89
@@ -1,650 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "Text::Formatted::Box wrapping" do
6
- before(:each) do
7
- create_pdf
8
- end
9
-
10
- it "should not wrap between two fragments" do
11
- texts = [
12
- {:text => "Hello "},
13
- {:text => "World"},
14
- {:text => "2", :styles => [:superscript]},
15
- ]
16
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
17
- text_box.render
18
- text_box.text.should == "Hello\nWorld2"
19
- end
20
-
21
- it "should not raise an Encoding::CompatibilityError when keeping a TTF and an " +
22
- "AFM font together" do
23
- ruby_19 do
24
- file = "#{Prawn::DATADIR}/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
-
34
- text_box.render
35
- end
36
- end
37
-
38
- it "should wrap between two fragments when the preceding fragment ends with white space" do
39
- texts = [
40
- {:text => "Hello "},
41
- {:text => "World "},
42
- {:text => "2", :styles => [:superscript]},
43
- ]
44
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
45
- text_box.render
46
- text_box.text.should == "Hello World\n2"
47
-
48
- texts = [
49
- {:text => "Hello "},
50
- {:text => "World\n"},
51
- {:text => "2", :styles => [:superscript]},
52
- ]
53
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
54
- text_box.render
55
- text_box.text.should == "Hello World\n2"
56
- end
57
-
58
- it "should wrap between two fragments when the final fragment begins with white space" do
59
- texts = [
60
- {:text => "Hello "},
61
- {:text => "World"},
62
- {:text => " 2", :styles => [:superscript]},
63
- ]
64
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
65
- text_box.render
66
- text_box.text.should == "Hello World\n2"
67
-
68
- texts = [
69
- {:text => "Hello "},
70
- {:text => "World"},
71
- {:text => "\n2", :styles => [:superscript]},
72
- ]
73
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
74
- text_box.render
75
- text_box.text.should == "Hello World\n2"
76
- end
77
-
78
- it "should properly handle empty slices using default encoding" do
79
- texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
80
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
81
- lambda {
82
- text_box.render
83
- }.should_not raise_error
84
- text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
85
- end
86
-
87
- describe "Unicode" do
88
- before do
89
- if RUBY_VERSION < '1.9'
90
- @reset_value = $KCODE
91
- $KCODE='u'
92
- else
93
- @reset_value = [Encoding.default_external, Encoding.default_internal]
94
- Encoding.default_external = Encoding::UTF_8
95
- Encoding.default_internal = Encoding::UTF_8
96
- end
97
- end
98
-
99
- after do
100
- if RUBY_VERSION < '1.9'
101
- $KCODE=@reset_value
102
- else
103
- Encoding.default_external = @reset_value[0]
104
- Encoding.default_internal = @reset_value[1]
105
- end
106
- end
107
-
108
- it "should properly handle empty slices using Unicode encoding" do
109
- texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
110
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
111
- lambda {
112
- text_box.render
113
- }.should_not raise_error
114
- text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
115
- end
116
- end
117
- end
118
-
119
- describe "Text::Formatted::Box with :fallback_fonts option that includes" +
120
- "a Chinese font and set of Chinese glyphs not in the current font" do
121
- it "should change the font to the Chinese font for the Chinese glyphs" do
122
- create_pdf
123
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
124
- @pdf.font_families["Kai"] = {
125
- :normal => { :file => file, :font => "Kai" }
126
- }
127
- formatted_text = [{ :text => "hello你好" },
128
- { :text => "再见goodbye" }]
129
- @pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Kai"])
130
-
131
- text = PDF::Inspector::Text.analyze(@pdf.render)
132
-
133
- fonts_used = text.font_settings.map { |e| e[:name] }
134
- fonts_used.length.should == 4
135
- fonts_used[0].should == :"Helvetica"
136
- fonts_used[1].to_s.should =~ /GBZenKai-Medium/
137
- fonts_used[2].to_s.should =~ /GBZenKai-Medium/
138
- fonts_used[3].should == :"Helvetica"
139
-
140
- text.strings[0].should == "hello"
141
- text.strings[1].should == "你好"
142
- text.strings[2].should == "再见"
143
- text.strings[3].should == "goodbye"
144
- end
145
- end
146
-
147
- describe "Text::Formatted::Box with :fallback_fonts option that includes" +
148
- "an AFM font and Win-Ansi glyph not in the current Chinese font" do
149
- it "should change the font to the AFM font for the Win-Ansi glyph" do
150
- create_pdf
151
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
152
- @pdf.font_families["Kai"] = {
153
- :normal => { :file => file, :font => "Kai" }
154
- }
155
- @pdf.font("Kai")
156
- formatted_text = [{ :text => "hello你好" },
157
- { :text => "再见€" }]
158
- @pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Helvetica"])
159
-
160
- text = PDF::Inspector::Text.analyze(@pdf.render)
161
-
162
- fonts_used = text.font_settings.map { |e| e[:name] }
163
- fonts_used.length.should == 4
164
- fonts_used[0].to_s.should =~ /GBZenKai-Medium/
165
- fonts_used[1].to_s.should =~ /GBZenKai-Medium/
166
- fonts_used[2].to_s.should =~ /GBZenKai-Medium/
167
- fonts_used[3].should == :"Helvetica"
168
-
169
- text.strings[0].should == "hello"
170
- text.strings[1].should == "你好"
171
- text.strings[2].should == "再见"
172
- text.strings[3].should == "€"
173
- end
174
- end
175
-
176
- describe "Text::Formatted::Box with :fallback_fonts option and fragment " +
177
- "level font" do
178
- it "should use the fragment level font except for glyphs not in that font" do
179
- create_pdf
180
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
181
- @pdf.font_families["Kai"] = {
182
- :normal => { :file => file, :font => "Kai" }
183
- }
184
- formatted_text = [{ :text => "hello你好" },
185
- { :text => "再见goodbye", :font => "Times-Roman" }]
186
- @pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Kai"])
187
-
188
- text = PDF::Inspector::Text.analyze(@pdf.render)
189
-
190
- fonts_used = text.font_settings.map { |e| e[:name] }
191
- fonts_used.length.should == 4
192
- fonts_used[0].should == :"Helvetica"
193
- fonts_used[1].to_s.should =~ /GBZenKai-Medium/
194
- fonts_used[2].to_s.should =~ /GBZenKai-Medium/
195
- fonts_used[3].should == :"Times-Roman"
196
-
197
- text.strings[0].should == "hello"
198
- text.strings[1].should == "你好"
199
- text.strings[2].should == "再见"
200
- text.strings[3].should == "goodbye"
201
- end
202
- end
203
-
204
- describe "Text::Formatted::Box" do
205
- before(:each) do
206
- create_pdf
207
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
208
- @pdf.font_families["Kai"] = {
209
- :normal => { :file => file, :font => "Kai" }
210
- }
211
- @formatted_text = [{ :text => "hello你好" }]
212
- @pdf.fallback_fonts(["Kai"])
213
- @pdf.fallback_fonts = ["Kai"]
214
- end
215
- it "#fallback_fonts should return the document-wide fallback fonts" do
216
- @pdf.fallback_fonts.should == ["Kai"]
217
- end
218
- it "should be able to set text fallback_fonts document-wide" do
219
- @pdf.formatted_text_box(@formatted_text)
220
-
221
- text = PDF::Inspector::Text.analyze(@pdf.render)
222
-
223
- fonts_used = text.font_settings.map { |e| e[:name] }
224
- fonts_used.length.should == 2
225
- fonts_used[0].should == :"Helvetica"
226
- fonts_used[1].to_s.should =~ /GBZenKai-Medium/
227
- end
228
- it "should be able to override document-wide fallback_fonts" do
229
- @pdf.formatted_text_box(@formatted_text, :fallback_fonts => ["Courier"])
230
-
231
- text = PDF::Inspector::Text.analyze(@pdf.render)
232
-
233
- fonts_used = text.font_settings.map { |e| e[:name] }
234
- fonts_used.length.should == 1
235
- fonts_used[0].should == :"Helvetica"
236
- end
237
- it "should omit the fallback fonts overhead when passing an empty array " +
238
- "as the :fallback_fonts" do
239
- box = Prawn::Text::Formatted::Box.new(@formatted_text,
240
- :document => @pdf,
241
- :fallback_fonts => [])
242
- box.expects(:process_fallback_fonts).never
243
- box.render
244
- end
245
- it "should be able to clear document-wide fallback_fonts" do
246
- @pdf.fallback_fonts([])
247
- box = Prawn::Text::Formatted::Box.new(@formatted_text,
248
- :document => @pdf)
249
- box.expects(:process_fallback_fonts).never
250
- box.render
251
- end
252
- end
253
-
254
- describe "Text::Formatted::Box with :fallback_fonts option " +
255
- "with glyphs not in the primary or the fallback fonts" do
256
- it "should use the primary font" do
257
- create_pdf
258
- formatted_text = [{ :text => "hello world. 世界你好。" }]
259
- @pdf.formatted_text_box(formatted_text, :fallback_fonts => ["Helvetica"])
260
-
261
- text = PDF::Inspector::Text.analyze(@pdf.render)
262
-
263
- fonts_used = text.font_settings.map { |e| e[:name] }
264
- fonts_used.length.should == 1
265
- fonts_used[0].should == :"Helvetica"
266
- end
267
- end
268
-
269
- describe "Text::Formatted::Box#extensions" do
270
- it "should be able to override default line wrapping" do
271
- create_pdf
272
- Prawn::Text::Formatted::Box.extensions << TestFormattedWrapOverride
273
- @pdf.formatted_text_box([{ :text => "hello world" }], {})
274
- Prawn::Text::Formatted::Box.extensions.delete(TestFormattedWrapOverride)
275
- text = PDF::Inspector::Text.analyze(@pdf.render)
276
- text.strings[0].should == "all your base are belong to us"
277
- end
278
- it "overriding Text::Formatted::Box line wrapping should not affect " +
279
- "Text::Box wrapping" do
280
- create_pdf
281
- Prawn::Text::Formatted::Box.extensions << TestFormattedWrapOverride
282
- @pdf.text_box("hello world", {})
283
- Prawn::Text::Formatted::Box.extensions.delete(TestFormattedWrapOverride)
284
- text = PDF::Inspector::Text.analyze(@pdf.render)
285
- text.strings[0].should == "hello world"
286
- end
287
- it "overriding Text::Box line wrapping should override Text::Box wrapping" do
288
- create_pdf
289
- Prawn::Text::Box.extensions << TestFormattedWrapOverride
290
- @pdf.text_box("hello world", {})
291
- Prawn::Text::Box.extensions.delete(TestFormattedWrapOverride)
292
- text = PDF::Inspector::Text.analyze(@pdf.render)
293
- text.strings[0].should == "all your base are belong to us"
294
- end
295
- end
296
-
297
- describe "Text::Formatted::Box#render" do
298
- it "should handle newlines" do
299
- create_pdf
300
- array = [{ :text => "hello\nworld"}]
301
- options = { :document => @pdf }
302
- text_box = Prawn::Text::Formatted::Box.new(array, options)
303
- text_box.render
304
- text_box.text.should == "hello\nworld"
305
- end
306
- it "should omit spaces from the beginning of the line" do
307
- create_pdf
308
- array = [{ :text => " hello\n world"}]
309
- options = { :document => @pdf }
310
- text_box = Prawn::Text::Formatted::Box.new(array, options)
311
- text_box.render
312
- text_box.text.should == "hello\nworld"
313
- end
314
- it "should be okay printing a line of whitespace" do
315
- create_pdf
316
- array = [{ :text => "hello\n \nworld"}]
317
- options = { :document => @pdf }
318
- text_box = Prawn::Text::Formatted::Box.new(array, options)
319
- text_box.render
320
- text_box.text.should == "hello\n\nworld"
321
-
322
-
323
- array = [{ :text => "hello" + " " * 500},
324
- { :text => " " * 500 },
325
- { :text => " " * 500 + "\n"},
326
- { :text => "world"}]
327
- options = { :document => @pdf }
328
- text_box = Prawn::Text::Formatted::Box.new(array, options)
329
- text_box.render
330
- text_box.text.should == "hello\n\nworld"
331
- end
332
- it "should enable fragment level direction setting" do
333
- create_pdf
334
- number_of_hellos = 18
335
- array = [
336
- { :text => "hello " * number_of_hellos },
337
- { :text => "world", :direction => :ltr },
338
- { :text => ", how are you?" }
339
- ]
340
- options = { :document => @pdf, :direction => :rtl }
341
- text_box = Prawn::Text::Formatted::Box.new(array, options)
342
- text_box.render
343
- text = PDF::Inspector::Text.analyze(@pdf.render)
344
- text.strings[0].should == "era woh ,"
345
- text.strings[1].should == "world"
346
- text.strings[2].should == " olleh" * number_of_hellos
347
- text.strings[3].should == "?uoy"
348
- end
349
- end
350
-
351
- describe "Text::Formatted::Box#render" do
352
- it "should be able to perform fragment callbacks" do
353
- create_pdf
354
- callback_object = TestFragmentCallback.new("something", 7,
355
- :document => @pdf)
356
- callback_object.expects(:render_behind).with(
357
- kind_of(Prawn::Text::Formatted::Fragment))
358
- callback_object.expects(:render_in_front).with(
359
- kind_of(Prawn::Text::Formatted::Fragment))
360
- array = [{ :text => "hello world " },
361
- { :text => "callback now",
362
- :callback => callback_object }]
363
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
364
- text_box.render
365
- end
366
- it "should be able to perform fragment callbacks on multiple objects" do
367
- create_pdf
368
-
369
- callback_object = TestFragmentCallback.new("something", 7,
370
- :document => @pdf)
371
- callback_object.expects(:render_behind).with(
372
- kind_of(Prawn::Text::Formatted::Fragment))
373
- callback_object.expects(:render_in_front).with(
374
- kind_of(Prawn::Text::Formatted::Fragment))
375
-
376
- callback_object2 = TestFragmentCallback.new("something else", 14,
377
- :document => @pdf)
378
- callback_object2.expects(:render_behind).with(
379
- kind_of(Prawn::Text::Formatted::Fragment))
380
- callback_object2.expects(:render_in_front).with(
381
- kind_of(Prawn::Text::Formatted::Fragment))
382
-
383
- array = [{ :text => "hello world " },
384
- { :text => "callback now",
385
- :callback => [callback_object, callback_object2] }]
386
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
387
- text_box.render
388
- end
389
- it "fragment callbacks should be able to define only the callback they need" do
390
- create_pdf
391
- behind = TestFragmentCallbackBehind.new("something", 7,
392
- :document => @pdf)
393
- in_front = TestFragmentCallbackInFront.new("something", 7,
394
- :document => @pdf)
395
- array = [{ :text => "hello world " },
396
- { :text => "callback now",
397
- :callback => [behind, in_front] }]
398
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
399
-
400
- text_box.render # trigger callbacks
401
- end
402
- it "should be able to set the font" do
403
- create_pdf
404
- array = [{ :text => "this contains " },
405
- { :text => "Times-Bold",
406
- :styles => [:bold],
407
- :font => "Times-Roman" },
408
- { :text => " text" }]
409
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
410
- text_box.render
411
- contents = PDF::Inspector::Text.analyze(@pdf.render)
412
- fonts = contents.font_settings.map { |e| e[:name] }
413
- fonts.should == [:Helvetica, :"Times-Bold", :Helvetica]
414
- contents.strings[0].should == "this contains "
415
- contents.strings[1].should == "Times-Bold"
416
- contents.strings[2].should == " text"
417
- end
418
- it "should be able to set bold" do
419
- create_pdf
420
- array = [{ :text => "this contains " },
421
- { :text => "bold", :styles => [:bold] },
422
- { :text => " text" }]
423
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
424
- text_box.render
425
- contents = PDF::Inspector::Text.analyze(@pdf.render)
426
- fonts = contents.font_settings.map { |e| e[:name] }
427
- fonts.should == [:Helvetica, :"Helvetica-Bold", :Helvetica]
428
- contents.strings[0].should == "this contains "
429
- contents.strings[1].should == "bold"
430
- contents.strings[2].should == " text"
431
- end
432
- it "should be able to set italics" do
433
- create_pdf
434
- array = [{ :text => "this contains " },
435
- { :text => "italic", :styles => [:italic] },
436
- { :text => " text" }]
437
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
438
- text_box.render
439
- contents = PDF::Inspector::Text.analyze(@pdf.render)
440
- fonts = contents.font_settings.map { |e| e[:name] }
441
- fonts.should == [:Helvetica, :"Helvetica-Oblique", :Helvetica]
442
- end
443
- it "should be able to set subscript" do
444
- create_pdf
445
- array = [{ :text => "this contains " },
446
- { :text => "subscript", :size => 18, :styles => [:subscript] },
447
- { :text => " text" }]
448
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
449
- text_box.render
450
- contents = PDF::Inspector::Text.analyze(@pdf.render)
451
- contents.font_settings[0][:size].should == 12
452
- contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
453
- end
454
- it "should be able to set superscript" do
455
- create_pdf
456
- array = [{ :text => "this contains " },
457
- { :text => "superscript", :size => 18, :styles => [:superscript] },
458
- { :text => " text" }]
459
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
460
- text_box.render
461
- contents = PDF::Inspector::Text.analyze(@pdf.render)
462
- contents.font_settings[0][:size].should == 12
463
- contents.font_settings[1][:size].should be_within(0.0001).of(18 * 0.583)
464
- end
465
- it "should be able to set compound bold and italic text" do
466
- create_pdf
467
- array = [{ :text => "this contains " },
468
- { :text => "bold italic", :styles => [:bold, :italic] },
469
- { :text => " text" }]
470
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
471
- text_box.render
472
- contents = PDF::Inspector::Text.analyze(@pdf.render)
473
- fonts = contents.font_settings.map { |e| e[:name] }
474
- fonts.should == [:Helvetica, :"Helvetica-BoldOblique", :Helvetica]
475
- end
476
- it "should be able to underline" do
477
- create_pdf
478
- array = [{ :text => "this contains " },
479
- { :text => "underlined", :styles => [:underline] },
480
- { :text => " text" }]
481
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
482
- text_box.render
483
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
484
- line_drawing.points.length.should == 2
485
- end
486
- it "should be able to strikethrough" do
487
- create_pdf
488
- array = [{ :text => "this contains " },
489
- { :text => "struckthrough", :styles => [:strikethrough] },
490
- { :text => " text" }]
491
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
492
- text_box.render
493
- line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
494
- line_drawing.points.length.should == 2
495
- end
496
- it "should be able to add URL links" do
497
- create_pdf
498
- @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
499
- :A => { :Type => :Action, :S => :URI, :URI => "http://example.com" })
500
- array = [{ :text => "click " },
501
- { :text => "here", :link => "http://example.com" },
502
- { :text => " to visit" }]
503
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
504
- text_box.render
505
- end
506
- it "should be able to add destination links" do
507
- create_pdf
508
- @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
509
- :Dest => "ToC")
510
- array = [{ :text => "Go to the " },
511
- { :text => "Table of Contents", :anchor => "ToC" }]
512
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
513
- text_box.render
514
- end
515
- it "should be able to add local actions" do
516
- create_pdf
517
- @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
518
- :A => { :Type => :Action, :S => :Launch, :F => "../example.pdf", :NewWindow => true })
519
- array = [{ :text => "click " },
520
- { :text => "here", :local => "../example.pdf" },
521
- { :text => " to open a local file" }]
522
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
523
- text_box.render
524
- end
525
- it "should be able to set font size" do
526
- create_pdf
527
- array = [{ :text => "this contains " },
528
- { :text => "sized", :size => 24 },
529
- { :text => " text" }]
530
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
531
- text_box.render
532
- contents = PDF::Inspector::Text.analyze(@pdf.render)
533
- contents.font_settings[0][:size].should == 12
534
- contents.font_settings[1][:size].should == 24
535
- end
536
- it "should set the baseline based on the tallest fragment on a given line" do
537
- create_pdf
538
- array = [{ :text => "this contains " },
539
- { :text => "sized", :size => 24 },
540
- { :text => " text" }]
541
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
542
- text_box.render
543
- @pdf.font_size(24) do
544
- text_box.height.should be_within(0.001).of(@pdf.font.ascender + @pdf.font.descender)
545
- end
546
- end
547
- it "should be able to set color via an rgb hex string" do
548
- create_pdf
549
- array = [{ :text => "rgb",
550
- :color => "ff0000" }]
551
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
552
- text_box.render
553
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
554
- colors.fill_color_count.should == 2
555
- colors.stroke_color_count.should == 2
556
- end
557
- it "should be able to set color using a cmyk array" do
558
- create_pdf
559
- array = [{ :text => "cmyk",
560
- :color => [100, 0, 0, 0] }]
561
- text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
562
- text_box.render
563
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
564
- colors.fill_color_count.should == 2
565
- colors.stroke_color_count.should == 2
566
- end
567
- end
568
-
569
- describe "Text::Formatted::Box#render with fragment level :character_spacing option" do
570
- it "should draw the character spacing to the document" do
571
- create_pdf
572
- array = [{ :text => "hello world",
573
- :character_spacing => 7 }]
574
- options = { :document => @pdf }
575
- text_box = Prawn::Text::Formatted::Box.new(array, options)
576
- text_box.render
577
- contents = PDF::Inspector::Text.analyze(@pdf.render)
578
- contents.character_spacing[0].should == 7
579
- end
580
- it "should draw the character spacing to the document" do
581
- create_pdf
582
- array = [{ :text => "hello world",
583
- :font => "Courier",
584
- :character_spacing => 10 }]
585
- options = { :document => @pdf,
586
- :width => 100,
587
- :overflow => :expand }
588
- text_box = Prawn::Text::Formatted::Box.new(array, options)
589
- text_box.render
590
- text_box.text.should == "hello\nworld"
591
- end
592
- end
593
-
594
- describe "Text::Formatted::Box#render with :align => :justify" do
595
- it "should not justify the last line of a paragraph" do
596
- create_pdf
597
- array = [{ :text => "hello world " },
598
- { :text => "\n" },
599
- { :text => "goodbye" }]
600
- options = { :document => @pdf, :align => :justify }
601
- text_box = Prawn::Text::Formatted::Box.new(array, options)
602
- text_box.render
603
- contents = PDF::Inspector::Text.analyze(@pdf.render)
604
- contents.word_spacing.should be_empty
605
- end
606
- end
607
-
608
- class TestFragmentCallback
609
- def initialize(string, number, options)
610
- @document = options[:document]
611
- end
612
-
613
- def render_behind(fragment)
614
- end
615
-
616
- def render_in_front(fragment)
617
- end
618
- end
619
-
620
- class TestFragmentCallbackBehind
621
- def initialize(string, number, options)
622
- @document = options[:document]
623
- end
624
-
625
- def render_behind(fragment)
626
- end
627
- end
628
-
629
- class TestFragmentCallbackInFront
630
- def initialize(string, number, options)
631
- @document = options[:document]
632
- end
633
-
634
- def render_in_front(fragment)
635
- end
636
- end
637
-
638
- module TestFormattedWrapOverride
639
- def wrap(array)
640
- initialize_wrap([{ :text => 'all your base are belong to us' }])
641
- line_to_print = @line_wrap.wrap_line(:document => @document,
642
- :kerning => @kerning,
643
- :width => 10000,
644
- :arranger => @arranger)
645
- fragment = @arranger.retrieve_fragment
646
- format_and_draw_fragment(fragment, 0, @line_wrap.width, 0)
647
-
648
- []
649
- end
650
- end