prawn-graph 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (317) hide show
  1. data/README.markdown +3 -0
  2. data/Rakefile +34 -0
  3. data/examples/example_helper.rb +10 -0
  4. data/examples/graph/advanced_bar_chart.rb +22 -0
  5. data/examples/graph/bar_chart.rb +18 -0
  6. data/examples/graph/line_chart.rb +18 -0
  7. data/lib/prawn/graph.rb +94 -0
  8. data/lib/prawn/graph/bar.rb +172 -0
  9. data/lib/prawn/graph/chart.rb +4 -0
  10. data/lib/prawn/graph/errors.rb +6 -0
  11. data/lib/prawn/graph/grid.rb +43 -0
  12. data/lib/prawn/graph/line.rb +43 -0
  13. data/vendor/prawn-core/COPYING +340 -0
  14. data/vendor/prawn-core/HACKING +46 -0
  15. data/vendor/prawn-core/LICENSE +56 -0
  16. data/vendor/prawn-core/README +138 -0
  17. data/vendor/prawn-core/Rakefile +75 -0
  18. data/vendor/prawn-core/bench/afm_text_bench.rb +18 -0
  19. data/vendor/prawn-core/bench/png_type_6.rb +15 -0
  20. data/vendor/prawn-core/bench/ttf_text_bench.rb +19 -0
  21. data/vendor/prawn-core/bugs/indentation_across_pagebreaks.rb +15 -0
  22. data/vendor/prawn-core/bugs/resolved/canvas_sets_y_to_0.rb +15 -0
  23. data/vendor/prawn-core/bugs/resolved/png_barcode_issue.rb +11 -0
  24. data/vendor/prawn-core/bugs/resolved/transaction_page_number_issue_79.rb +21 -0
  25. data/vendor/prawn-core/bugs/resolved/ttf_fails_in_transactions.rb +24 -0
  26. data/vendor/prawn-core/data/encodings/win_ansi.txt +29 -0
  27. data/vendor/prawn-core/data/fonts/Action Man.dfont +0 -0
  28. data/vendor/prawn-core/data/fonts/Activa.ttf +0 -0
  29. data/vendor/prawn-core/data/fonts/Chalkboard.ttf +0 -0
  30. data/vendor/prawn-core/data/fonts/Courier-Bold.afm +342 -0
  31. data/vendor/prawn-core/data/fonts/Courier-BoldOblique.afm +342 -0
  32. data/vendor/prawn-core/data/fonts/Courier-Oblique.afm +342 -0
  33. data/vendor/prawn-core/data/fonts/Courier.afm +342 -0
  34. data/vendor/prawn-core/data/fonts/DejaVuSans.ttf +0 -0
  35. data/vendor/prawn-core/data/fonts/Dustismo_Roman.ttf +0 -0
  36. data/vendor/prawn-core/data/fonts/Helvetica-Bold.afm +2827 -0
  37. data/vendor/prawn-core/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  38. data/vendor/prawn-core/data/fonts/Helvetica-Oblique.afm +3051 -0
  39. data/vendor/prawn-core/data/fonts/Helvetica.afm +3051 -0
  40. data/vendor/prawn-core/data/fonts/MustRead.html +19 -0
  41. data/vendor/prawn-core/data/fonts/Symbol.afm +213 -0
  42. data/vendor/prawn-core/data/fonts/Times-Bold.afm +2588 -0
  43. data/vendor/prawn-core/data/fonts/Times-BoldItalic.afm +2384 -0
  44. data/vendor/prawn-core/data/fonts/Times-Italic.afm +2667 -0
  45. data/vendor/prawn-core/data/fonts/Times-Roman.afm +2419 -0
  46. data/vendor/prawn-core/data/fonts/ZapfDingbats.afm +225 -0
  47. data/vendor/prawn-core/data/fonts/comicsans.ttf +0 -0
  48. data/vendor/prawn-core/data/fonts/gkai00mp.ttf +0 -0
  49. data/vendor/prawn-core/data/images/16bit.alpha +0 -0
  50. data/vendor/prawn-core/data/images/16bit.dat +0 -0
  51. data/vendor/prawn-core/data/images/16bit.png +0 -0
  52. data/vendor/prawn-core/data/images/arrow.png +0 -0
  53. data/vendor/prawn-core/data/images/arrow2.png +0 -0
  54. data/vendor/prawn-core/data/images/barcode_issue.png +0 -0
  55. data/vendor/prawn-core/data/images/dice.alpha +0 -0
  56. data/vendor/prawn-core/data/images/dice.dat +0 -0
  57. data/vendor/prawn-core/data/images/dice.png +0 -0
  58. data/vendor/prawn-core/data/images/dice_interlaced.png +0 -0
  59. data/vendor/prawn-core/data/images/fractal.jpg +0 -0
  60. data/vendor/prawn-core/data/images/letterhead.jpg +0 -0
  61. data/vendor/prawn-core/data/images/page_white_text.alpha +0 -0
  62. data/vendor/prawn-core/data/images/page_white_text.dat +0 -0
  63. data/vendor/prawn-core/data/images/page_white_text.png +0 -0
  64. data/vendor/prawn-core/data/images/pigs.jpg +0 -0
  65. data/vendor/prawn-core/data/images/rails.dat +0 -0
  66. data/vendor/prawn-core/data/images/rails.png +0 -0
  67. data/vendor/prawn-core/data/images/ruport.png +0 -0
  68. data/vendor/prawn-core/data/images/ruport_data.dat +0 -0
  69. data/vendor/prawn-core/data/images/ruport_transparent.png +0 -0
  70. data/vendor/prawn-core/data/images/ruport_type0.png +0 -0
  71. data/vendor/prawn-core/data/images/stef.jpg +0 -0
  72. data/vendor/prawn-core/data/images/tru256.bmp +0 -0
  73. data/vendor/prawn-core/data/images/web-links.dat +1 -0
  74. data/vendor/prawn-core/data/images/web-links.png +0 -0
  75. data/vendor/prawn-core/data/shift_jis_text.txt +1 -0
  76. data/vendor/prawn-core/examples/bounding_box/bounding_boxes.rb +43 -0
  77. data/vendor/prawn-core/examples/bounding_box/indentation.rb +34 -0
  78. data/vendor/prawn-core/examples/bounding_box/russian_boxes.rb +36 -0
  79. data/vendor/prawn-core/examples/bounding_box/stretched_nesting.rb +67 -0
  80. data/vendor/prawn-core/examples/column_box/column_box_example.rb +43 -0
  81. data/vendor/prawn-core/examples/example_helper.rb +3 -0
  82. data/vendor/prawn-core/examples/general/background.rb +23 -0
  83. data/vendor/prawn-core/examples/general/canvas.rb +15 -0
  84. data/vendor/prawn-core/examples/general/context_sensitive_headers.rb +37 -0
  85. data/vendor/prawn-core/examples/general/float.rb +11 -0
  86. data/vendor/prawn-core/examples/general/margin.rb +36 -0
  87. data/vendor/prawn-core/examples/general/measurement_units.rb +51 -0
  88. data/vendor/prawn-core/examples/general/metadata-info.rb +16 -0
  89. data/vendor/prawn-core/examples/general/multi_page_layout.rb +18 -0
  90. data/vendor/prawn-core/examples/general/outlines.rb +50 -0
  91. data/vendor/prawn-core/examples/general/page_geometry.rb +31 -0
  92. data/vendor/prawn-core/examples/general/page_numbering.rb +15 -0
  93. data/vendor/prawn-core/examples/general/repeaters.rb +47 -0
  94. data/vendor/prawn-core/examples/general/stamp.rb +41 -0
  95. data/vendor/prawn-core/examples/graphics/basic_images.rb +23 -0
  96. data/vendor/prawn-core/examples/graphics/cmyk.rb +12 -0
  97. data/vendor/prawn-core/examples/graphics/curves.rb +11 -0
  98. data/vendor/prawn-core/examples/graphics/hexagon.rb +13 -0
  99. data/vendor/prawn-core/examples/graphics/image_fit.rb +15 -0
  100. data/vendor/prawn-core/examples/graphics/image_flow.rb +37 -0
  101. data/vendor/prawn-core/examples/graphics/image_position.rb +17 -0
  102. data/vendor/prawn-core/examples/graphics/line.rb +32 -0
  103. data/vendor/prawn-core/examples/graphics/png_types.rb +22 -0
  104. data/vendor/prawn-core/examples/graphics/polygons.rb +16 -0
  105. data/vendor/prawn-core/examples/graphics/remote_images.rb +12 -0
  106. data/vendor/prawn-core/examples/graphics/rounded_polygons.rb +19 -0
  107. data/vendor/prawn-core/examples/graphics/rounded_rectangle.rb +20 -0
  108. data/vendor/prawn-core/examples/graphics/ruport_style_helpers.rb +19 -0
  109. data/vendor/prawn-core/examples/graphics/stroke_bounds.rb +20 -0
  110. data/vendor/prawn-core/examples/graphics/stroke_cap_and_join.rb +45 -0
  111. data/vendor/prawn-core/examples/graphics/stroke_dash.rb +42 -0
  112. data/vendor/prawn-core/examples/graphics/transformations.rb +52 -0
  113. data/vendor/prawn-core/examples/graphics/transparency.rb +26 -0
  114. data/vendor/prawn-core/examples/m17n/chinese_text_wrapping.rb +17 -0
  115. data/vendor/prawn-core/examples/m17n/euro.rb +15 -0
  116. data/vendor/prawn-core/examples/m17n/sjis.rb +28 -0
  117. data/vendor/prawn-core/examples/m17n/utf8.rb +13 -0
  118. data/vendor/prawn-core/examples/m17n/win_ansi_charset.rb +54 -0
  119. data/vendor/prawn-core/examples/text/alignment.rb +18 -0
  120. data/vendor/prawn-core/examples/text/dfont.rb +48 -0
  121. data/vendor/prawn-core/examples/text/family_based_styling.rb +24 -0
  122. data/vendor/prawn-core/examples/text/font_calculations.rb +91 -0
  123. data/vendor/prawn-core/examples/text/font_size.rb +33 -0
  124. data/vendor/prawn-core/examples/text/indent_paragraphs.rb +18 -0
  125. data/vendor/prawn-core/examples/text/kerning.rb +30 -0
  126. data/vendor/prawn-core/examples/text/rotated.rb +98 -0
  127. data/vendor/prawn-core/examples/text/simple_text.rb +17 -0
  128. data/vendor/prawn-core/examples/text/simple_text_ttf.rb +17 -0
  129. data/vendor/prawn-core/examples/text/span.rb +29 -0
  130. data/vendor/prawn-core/examples/text/text_box.rb +88 -0
  131. data/vendor/prawn-core/examples/text/text_box_returning_excess.rb +51 -0
  132. data/vendor/prawn-core/examples/text/text_flow.rb +67 -0
  133. data/vendor/prawn-core/lib/prawn/byte_string.rb +7 -0
  134. data/vendor/prawn-core/lib/prawn/compatibility.rb +51 -0
  135. data/vendor/prawn-core/lib/prawn/core.rb +87 -0
  136. data/vendor/prawn-core/lib/prawn/core/page.rb +88 -0
  137. data/vendor/prawn-core/lib/prawn/core/text.rb +65 -0
  138. data/vendor/prawn-core/lib/prawn/document.rb +596 -0
  139. data/vendor/prawn-core/lib/prawn/document/annotations.rb +65 -0
  140. data/vendor/prawn-core/lib/prawn/document/bounding_box.rb +402 -0
  141. data/vendor/prawn-core/lib/prawn/document/column_box.rb +113 -0
  142. data/vendor/prawn-core/lib/prawn/document/destinations.rb +92 -0
  143. data/vendor/prawn-core/lib/prawn/document/graphics_state.rb +49 -0
  144. data/vendor/prawn-core/lib/prawn/document/internals.rb +153 -0
  145. data/vendor/prawn-core/lib/prawn/document/page_geometry.rb +136 -0
  146. data/vendor/prawn-core/lib/prawn/document/snapshot.rb +80 -0
  147. data/vendor/prawn-core/lib/prawn/document/span.rb +55 -0
  148. data/vendor/prawn-core/lib/prawn/encoding.rb +121 -0
  149. data/vendor/prawn-core/lib/prawn/errors.rb +83 -0
  150. data/vendor/prawn-core/lib/prawn/font.rb +329 -0
  151. data/vendor/prawn-core/lib/prawn/font/afm.rb +217 -0
  152. data/vendor/prawn-core/lib/prawn/font/dfont.rb +34 -0
  153. data/vendor/prawn-core/lib/prawn/font/ttf.rb +341 -0
  154. data/vendor/prawn-core/lib/prawn/graphics.rb +321 -0
  155. data/vendor/prawn-core/lib/prawn/graphics/cap_style.rb +38 -0
  156. data/vendor/prawn-core/lib/prawn/graphics/color.rb +205 -0
  157. data/vendor/prawn-core/lib/prawn/graphics/dash.rb +71 -0
  158. data/vendor/prawn-core/lib/prawn/graphics/join_style.rb +38 -0
  159. data/vendor/prawn-core/lib/prawn/graphics/transformation.rb +157 -0
  160. data/vendor/prawn-core/lib/prawn/graphics/transparency.rb +99 -0
  161. data/vendor/prawn-core/lib/prawn/images.rb +337 -0
  162. data/vendor/prawn-core/lib/prawn/images/jpg.rb +46 -0
  163. data/vendor/prawn-core/lib/prawn/images/png.rb +219 -0
  164. data/vendor/prawn-core/lib/prawn/literal_string.rb +14 -0
  165. data/vendor/prawn-core/lib/prawn/measurement_extensions.rb +46 -0
  166. data/vendor/prawn-core/lib/prawn/measurements.rb +71 -0
  167. data/vendor/prawn-core/lib/prawn/name_tree.rb +166 -0
  168. data/vendor/prawn-core/lib/prawn/object_store.rb +93 -0
  169. data/vendor/prawn-core/lib/prawn/outline.rb +278 -0
  170. data/vendor/prawn-core/lib/prawn/pdf_object.rb +83 -0
  171. data/vendor/prawn-core/lib/prawn/reference.rb +92 -0
  172. data/vendor/prawn-core/lib/prawn/repeater.rb +129 -0
  173. data/vendor/prawn-core/lib/prawn/stamp.rb +128 -0
  174. data/vendor/prawn-core/lib/prawn/text.rb +271 -0
  175. data/vendor/prawn-core/lib/prawn/text/box.rb +414 -0
  176. data/vendor/prawn-core/meta/Rakefile +36 -0
  177. data/vendor/prawn-core/meta/lib/prawn.rb +2 -0
  178. data/vendor/prawn-core/reference_pdfs/alignment.pdf +229 -0
  179. data/vendor/prawn-core/reference_pdfs/background.pdf +0 -0
  180. data/vendor/prawn-core/reference_pdfs/basic_images.pdf +0 -0
  181. data/vendor/prawn-core/reference_pdfs/bounding_boxes.pdf +128 -0
  182. data/vendor/prawn-core/reference_pdfs/canvas.pdf +78 -0
  183. data/vendor/prawn-core/reference_pdfs/chinese_flow.pdf +0 -0
  184. data/vendor/prawn-core/reference_pdfs/cmyk.pdf +0 -0
  185. data/vendor/prawn-core/reference_pdfs/column_box.pdf +3671 -0
  186. data/vendor/prawn-core/reference_pdfs/context_sensitive_headers.pdf +2331 -0
  187. data/vendor/prawn-core/reference_pdfs/curves.pdf +62 -0
  188. data/vendor/prawn-core/reference_pdfs/dfont.pdf +0 -0
  189. data/vendor/prawn-core/reference_pdfs/euro.pdf +75 -0
  190. data/vendor/prawn-core/reference_pdfs/family_style.pdf +286 -0
  191. data/vendor/prawn-core/reference_pdfs/flow.pdf +964 -0
  192. data/vendor/prawn-core/reference_pdfs/font_calculations.pdf +0 -0
  193. data/vendor/prawn-core/reference_pdfs/font_size.pdf +142 -0
  194. data/vendor/prawn-core/reference_pdfs/hexagon.pdf +61 -0
  195. data/vendor/prawn-core/reference_pdfs/image-flow.pdf +0 -0
  196. data/vendor/prawn-core/reference_pdfs/image_fit.pdf +0 -0
  197. data/vendor/prawn-core/reference_pdfs/image_position.pdf +0 -0
  198. data/vendor/prawn-core/reference_pdfs/indentation.pdf +124 -0
  199. data/vendor/prawn-core/reference_pdfs/kerning.pdf +0 -0
  200. data/vendor/prawn-core/reference_pdfs/landscape_a4.pdf +52 -0
  201. data/vendor/prawn-core/reference_pdfs/landscape_legal.pdf +52 -0
  202. data/vendor/prawn-core/reference_pdfs/landscape_letter.pdf +52 -0
  203. data/vendor/prawn-core/reference_pdfs/lines.pdf +116 -0
  204. data/vendor/prawn-core/reference_pdfs/margin.pdf +3850 -0
  205. data/vendor/prawn-core/reference_pdfs/measurement_units.pdf +4667 -0
  206. data/vendor/prawn-core/reference_pdfs/metadata-info.pdf +88 -0
  207. data/vendor/prawn-core/reference_pdfs/multi-layout.pdf +209 -0
  208. data/vendor/prawn-core/reference_pdfs/page_with_numbering.pdf +156 -0
  209. data/vendor/prawn-core/reference_pdfs/png_types.pdf +0 -0
  210. data/vendor/prawn-core/reference_pdfs/portrait_a4.pdf +52 -0
  211. data/vendor/prawn-core/reference_pdfs/portrait_legal.pdf +52 -0
  212. data/vendor/prawn-core/reference_pdfs/portrait_letter.pdf +52 -0
  213. data/vendor/prawn-core/reference_pdfs/pretty_polygons.pdf +122 -0
  214. data/vendor/prawn-core/reference_pdfs/remote_images.pdf +0 -0
  215. data/vendor/prawn-core/reference_pdfs/ruport.pdf +101 -0
  216. data/vendor/prawn-core/reference_pdfs/russian_boxes.pdf +2780 -0
  217. data/vendor/prawn-core/reference_pdfs/simple_text.pdf +136 -0
  218. data/vendor/prawn-core/reference_pdfs/simple_text_ttf.pdf +0 -0
  219. data/vendor/prawn-core/reference_pdfs/sjis.pdf +0 -0
  220. data/vendor/prawn-core/reference_pdfs/span.pdf +1975 -0
  221. data/vendor/prawn-core/reference_pdfs/stamp.pdf +649 -0
  222. data/vendor/prawn-core/reference_pdfs/stretched_nesting.pdf +200 -0
  223. data/vendor/prawn-core/reference_pdfs/stroke_bounds.pdf +135 -0
  224. data/vendor/prawn-core/reference_pdfs/stroke_cap_and_join.pdf +80 -0
  225. data/vendor/prawn-core/reference_pdfs/stroke_dash.pdf +457 -0
  226. data/vendor/prawn-core/reference_pdfs/text_box.pdf +962 -0
  227. data/vendor/prawn-core/reference_pdfs/text_box_returning_excess.pdf +271 -0
  228. data/vendor/prawn-core/reference_pdfs/transparency.pdf +347 -0
  229. data/vendor/prawn-core/reference_pdfs/utf8.pdf +0 -0
  230. data/vendor/prawn-core/reference_pdfs/win-ansi.pdf +6172 -0
  231. data/vendor/prawn-core/spec/annotations_spec.rb +90 -0
  232. data/vendor/prawn-core/spec/bounding_box_spec.rb +185 -0
  233. data/vendor/prawn-core/spec/destinations_spec.rb +15 -0
  234. data/vendor/prawn-core/spec/document_spec.rb +408 -0
  235. data/vendor/prawn-core/spec/font_spec.rb +314 -0
  236. data/vendor/prawn-core/spec/graphics_spec.rb +438 -0
  237. data/vendor/prawn-core/spec/images_spec.rb +79 -0
  238. data/vendor/prawn-core/spec/jpg_spec.rb +25 -0
  239. data/vendor/prawn-core/spec/measurement_units_spec.rb +23 -0
  240. data/vendor/prawn-core/spec/name_tree_spec.rb +112 -0
  241. data/vendor/prawn-core/spec/object_store_spec.rb +75 -0
  242. data/vendor/prawn-core/spec/outline_spec.rb +229 -0
  243. data/vendor/prawn-core/spec/pdf_object_spec.rb +122 -0
  244. data/vendor/prawn-core/spec/png_spec.rb +236 -0
  245. data/vendor/prawn-core/spec/reference_spec.rb +82 -0
  246. data/vendor/prawn-core/spec/repeater_spec.rb +96 -0
  247. data/vendor/prawn-core/spec/snapshot_spec.rb +138 -0
  248. data/vendor/prawn-core/spec/span_spec.rb +49 -0
  249. data/vendor/prawn-core/spec/spec_helper.rb +24 -0
  250. data/vendor/prawn-core/spec/stamp_spec.rb +108 -0
  251. data/vendor/prawn-core/spec/stroke_styles_spec.rb +152 -0
  252. data/vendor/prawn-core/spec/text_at_spec.rb +119 -0
  253. data/vendor/prawn-core/spec/text_box_spec.rb +603 -0
  254. data/vendor/prawn-core/spec/text_spec.rb +308 -0
  255. data/vendor/prawn-core/spec/transparency_spec.rb +75 -0
  256. data/vendor/prawn-core/vendor/pdf-inspector/README +18 -0
  257. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
  258. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
  259. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
  260. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
  261. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/text.rb +31 -0
  262. data/vendor/prawn-core/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
  263. data/vendor/prawn-core/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  264. data/vendor/prawn-core/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  265. data/vendor/prawn-core/vendor/ttfunk/example.rb +45 -0
  266. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk.rb +102 -0
  267. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
  268. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
  269. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
  270. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
  271. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
  272. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
  273. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
  274. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +46 -0
  275. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
  276. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
  277. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +51 -0
  278. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
  279. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
  280. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
  281. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
  282. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
  283. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
  284. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
  285. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
  286. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
  287. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
  288. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
  289. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
  290. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
  291. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
  292. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
  293. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
  294. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/name.rb +119 -0
  295. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
  296. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
  297. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
  298. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
  299. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
  300. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
  301. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
  302. data/vendor/prawn-core/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
  303. data/vendor/prawn-core/www/index.html +196 -0
  304. data/vendor/prawn-core/www/media/bounding_boxes.pdf +146 -0
  305. data/vendor/prawn-core/www/media/bounding_boxes.png +0 -0
  306. data/vendor/prawn-core/www/media/bounding_boxes_out.png +0 -0
  307. data/vendor/prawn-core/www/media/fancy_table.pdf +350 -0
  308. data/vendor/prawn-core/www/media/image.pdf +0 -0
  309. data/vendor/prawn-core/www/media/images.png +0 -0
  310. data/vendor/prawn-core/www/media/prawn_logo.png +0 -0
  311. data/vendor/prawn-core/www/media/tables.png +0 -0
  312. data/vendor/prawn-core/www/media/utf8.pdf +0 -0
  313. data/vendor/prawn-core/www/media/utf8.png +0 -0
  314. data/vendor/prawn-core/www/prawn-Chinese.html +113 -0
  315. data/vendor/prawn-core/www/prawn.css +86 -0
  316. data/vendor/prawn-core/www/twilight.css +266 -0
  317. metadata +374 -0
@@ -0,0 +1,119 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "#draw_text" do
6
+ before(:each) { create_pdf }
7
+
8
+ it "should raise ArgumentError if :at option omitted" do
9
+ lambda { @pdf.draw_text("hai", { }) }.should.raise(ArgumentError)
10
+ end
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)
14
+ end
15
+
16
+ it "should default to 12 point helvetica" do
17
+ @pdf.draw_text("Blah", :at => [100,100])
18
+ text = PDF::Inspector::Text.analyze(@pdf.render)
19
+ text.font_settings[0][:name].should == :Helvetica
20
+ text.font_settings[0][:size].should == 12
21
+ text.strings.first.should == "Blah"
22
+ end
23
+
24
+ it "should allow setting font size" do
25
+ @pdf.draw_text("Blah", :at => [100,100], :size => 16)
26
+ text = PDF::Inspector::Text.analyze(@pdf.render)
27
+ text.font_settings[0][:size].should == 16
28
+ end
29
+
30
+ it "should allow setting a default font size" do
31
+ @pdf.font_size = 16
32
+ @pdf.draw_text("Blah", :at => [0, 0])
33
+ text = PDF::Inspector::Text.analyze(@pdf.render)
34
+ text.font_settings[0][:size].should == 16
35
+ end
36
+
37
+ it "should allow overriding default font for a single instance" do
38
+ @pdf.font_size = 16
39
+
40
+ @pdf.draw_text("Blah", :size => 11, :at => [0, 0])
41
+ @pdf.draw_text("Blaz", :at => [0, 0])
42
+ text = PDF::Inspector::Text.analyze(@pdf.render)
43
+ text.font_settings[0][:size].should == 11
44
+ text.font_settings[1][:size].should == 16
45
+ end
46
+
47
+ it "should allow setting a font size transaction with a block" do
48
+ @pdf.font_size 16 do
49
+ @pdf.draw_text('Blah', :at => [0, 0])
50
+ end
51
+
52
+ @pdf.draw_text('blah', :at => [0, 0])
53
+
54
+ text = PDF::Inspector::Text.analyze(@pdf.render)
55
+ text.font_settings[0][:size].should == 16
56
+ text.font_settings[1][:size].should == 12
57
+ end
58
+
59
+ it "should allow manual setting the font size " +
60
+ "when in a font size block" do
61
+ @pdf.font_size(16) do
62
+ @pdf.draw_text('Foo', :at => [0, 0])
63
+ @pdf.draw_text('Blah', :size => 11, :at => [0, 0])
64
+ @pdf.draw_text('Blaz', :at => [0, 0])
65
+ end
66
+ text = PDF::Inspector::Text.analyze(@pdf.render)
67
+ text.font_settings[0][:size].should == 16
68
+ text.font_settings[1][:size].should == 11
69
+ text.font_settings[2][:size].should == 16
70
+ end
71
+
72
+ it "should allow registering of built-in font_settings on the fly" do
73
+ @pdf.font "Times-Roman"
74
+ @pdf.draw_text("Blah", :at => [100,100], :at => [0, 0])
75
+ @pdf.font "Courier"
76
+ @pdf.draw_text("Blaz", :at => [150,150], :at => [0, 0])
77
+ text = PDF::Inspector::Text.analyze(@pdf.render)
78
+ text.font_settings[0][:name].should == :"Times-Roman"
79
+ text.font_settings[1][:name].should == :Courier
80
+ end
81
+
82
+ it "should raise an exception when an unknown font is used" do
83
+ lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont)
84
+ end
85
+
86
+ it "should correctly render a utf-8 string when using a built-in font" do
87
+ str = "©" # copyright symbol
88
+ @pdf.draw_text(str, :at => [0, 0])
89
+
90
+ # grab the text from the rendered PDF and ensure it matches
91
+ text = PDF::Inspector::Text.analyze(@pdf.render)
92
+ text.strings.first.should == str
93
+ end
94
+
95
+ if "spec".respond_to?(:encode!)
96
+ # Handle non utf-8 string encodings in a sane way on M17N aware VMs
97
+ it "should raise an exception when a utf-8 incompatible string is rendered" do
98
+ str = "Blah \xDD"
99
+ str.force_encoding("ASCII-8BIT")
100
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(ArgumentError)
101
+ end
102
+ it "should not raise an exception when a shift-jis string is rendered" do
103
+ datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"
104
+ sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
105
+ @pdf.font("#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf")
106
+ lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.not.raise(ArgumentError)
107
+ end
108
+ else
109
+ # Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
110
+ it "should raise an exception when a corrupt utf-8 string is rendered" do
111
+ str = "Blah \xDD"
112
+ lambda { @pdf.draw_text(str, :at => [0, 0]) }.should.raise(ArgumentError)
113
+ end
114
+ it "should raise an exception when a shift-jis string is rendered" do
115
+ sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
116
+ lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.raise(ArgumentError)
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,603 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+
6
+ describe "Text::Box#render" do
7
+ it "should not fail if height is smaller than 1 line" do
8
+ create_pdf
9
+ @text = "Oh hai text rect. " * 10
10
+ @options = {
11
+ :height => @pdf.font.height * 0.5,
12
+ :document => @pdf
13
+ }
14
+ text_box = Prawn::Text::Box.new(@text, @options)
15
+ text_box.render
16
+ text_box.text.should == ""
17
+ end
18
+ it "should draw content to the page" do
19
+ create_pdf
20
+ @text = "Oh hai text rect. " * 10
21
+ @options = { :document => @pdf }
22
+ text_box = Prawn::Text::Box.new(@text, @options)
23
+ text_box.render()
24
+ text = PDF::Inspector::Text.analyze(@pdf.render)
25
+ text.strings.should.not.be.empty
26
+ end
27
+ it "should not draw a transformation matrix" do
28
+ create_pdf
29
+ @text = "Oh hai text rect. " * 10
30
+ @options = { :document => @pdf }
31
+ text_box = Prawn::Text::Box.new(@text, @options)
32
+ text_box.render()
33
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
34
+ matrices.matrices.length.should == 0
35
+ end
36
+ end
37
+
38
+ describe "Text::Box#render(:single_line => true)" do
39
+ it "should draw only one line to the page" do
40
+ create_pdf
41
+ @text = "Oh hai text rect. " * 10
42
+ @options = { :document => @pdf,
43
+ :single_line => true }
44
+ text_box = Prawn::Text::Box.new(@text, @options)
45
+ text_box.render()
46
+ text = PDF::Inspector::Text.analyze(@pdf.render)
47
+ text.strings.length.should == 1
48
+ end
49
+ end
50
+
51
+ describe "Text::Box#render(:dry_run => true)" do
52
+ it "should not draw any content to the page" do
53
+ create_pdf
54
+ @text = "Oh hai text rect. " * 10
55
+ @options = { :document => @pdf }
56
+ text_box = Prawn::Text::Box.new(@text, @options)
57
+ text_box.render(:dry_run => true)
58
+ text = PDF::Inspector::Text.analyze(@pdf.render)
59
+ text.strings.should.be.empty
60
+ end
61
+ it "subsequent calls to render should not raise an ArgumentError exception" do
62
+ create_pdf
63
+ @text = "™©"
64
+ @options = { :document => @pdf }
65
+ text_box = Prawn::Text::Box.new(@text, @options)
66
+ text_box.render(:dry_run => true)
67
+ lambda { text_box.render }.should.not.raise(ArgumentError)
68
+ end
69
+ end
70
+
71
+ describe "Text::Box#render with :rotation option of 30)" do
72
+ before(:each) do
73
+ create_pdf
74
+ rotation = 30
75
+ @x = 300
76
+ @y = 70
77
+ @width = 100
78
+ @height = 50
79
+ @cos = Math.cos(rotation * Math::PI / 180)
80
+ @sin = Math.sin(rotation * Math::PI / 180)
81
+ @text = "Oh hai text rect. " * 10
82
+ @options = { :document => @pdf,
83
+ :rotation => rotation,
84
+ :at => [@x, @y],
85
+ :width => @width,
86
+ :height => @height }
87
+ end
88
+ context ":rotate_around option of :center" do
89
+ it "should draw content to the page rotated about the center of the text" do
90
+ @options[:rotate_around] = :center
91
+ text_box = Prawn::Text::Box.new(@text, @options)
92
+ text_box.render()
93
+
94
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
95
+ x = @x + @width / 2
96
+ y = @y - @height / 2
97
+ x_prime = x * @cos - y * @sin
98
+ y_prime = x * @sin + y * @cos
99
+ matrices.matrices[0].should == [1, 0, 0, 1,
100
+ reduce_precision(x - x_prime),
101
+ reduce_precision(y - y_prime)]
102
+ matrices.matrices[1].should == [reduce_precision(@cos),
103
+ reduce_precision(@sin),
104
+ reduce_precision(-@sin),
105
+ reduce_precision(@cos), 0, 0]
106
+
107
+ text = PDF::Inspector::Text.analyze(@pdf.render)
108
+ text.strings.should.not.be.empty
109
+ end
110
+ end
111
+ context ":rotate_around option of :upper_left" do
112
+ it "should draw content to the page rotated about the upper left corner of the text" do
113
+ @options[:rotate_around] = :upper_left
114
+ text_box = Prawn::Text::Box.new(@text, @options)
115
+ text_box.render()
116
+
117
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
118
+ x = @x
119
+ y = @y
120
+ x_prime = x * @cos - y * @sin
121
+ y_prime = x * @sin + y * @cos
122
+ matrices.matrices[0].should == [1, 0, 0, 1,
123
+ reduce_precision(x - x_prime),
124
+ reduce_precision(y - y_prime)]
125
+ matrices.matrices[1].should == [reduce_precision(@cos),
126
+ reduce_precision(@sin),
127
+ reduce_precision(-@sin),
128
+ reduce_precision(@cos), 0, 0]
129
+
130
+ text = PDF::Inspector::Text.analyze(@pdf.render)
131
+ text.strings.should.not.be.empty
132
+ end
133
+ end
134
+ context "default :rotate_around" do
135
+ it "should draw content to the page rotated about the upper left corner of the text" do
136
+ text_box = Prawn::Text::Box.new(@text, @options)
137
+ text_box.render()
138
+
139
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
140
+ x = @x
141
+ y = @y
142
+ x_prime = x * @cos - y * @sin
143
+ y_prime = x * @sin + y * @cos
144
+ matrices.matrices[0].should == [1, 0, 0, 1,
145
+ reduce_precision(x - x_prime),
146
+ reduce_precision(y - y_prime)]
147
+ matrices.matrices[1].should == [reduce_precision(@cos),
148
+ reduce_precision(@sin),
149
+ reduce_precision(-@sin),
150
+ reduce_precision(@cos), 0, 0]
151
+
152
+ text = PDF::Inspector::Text.analyze(@pdf.render)
153
+ text.strings.should.not.be.empty
154
+ end
155
+ end
156
+ context ":rotate_around option of :upper_right" do
157
+ it "should draw content to the page rotated about the upper right corner of the text" do
158
+ @options[:rotate_around] = :upper_right
159
+ text_box = Prawn::Text::Box.new(@text, @options)
160
+ text_box.render()
161
+
162
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
163
+ x = @x + @width
164
+ y = @y
165
+ x_prime = x * @cos - y * @sin
166
+ y_prime = x * @sin + y * @cos
167
+ matrices.matrices[0].should == [1, 0, 0, 1,
168
+ reduce_precision(x - x_prime),
169
+ reduce_precision(y - y_prime)]
170
+ matrices.matrices[1].should == [reduce_precision(@cos),
171
+ reduce_precision(@sin),
172
+ reduce_precision(-@sin),
173
+ reduce_precision(@cos), 0, 0]
174
+
175
+ text = PDF::Inspector::Text.analyze(@pdf.render)
176
+ text.strings.should.not.be.empty
177
+ end
178
+ end
179
+ context ":rotate_around option of :lower_right" do
180
+ it "should draw content to the page rotated about the lower right corner of the text" do
181
+ @options[:rotate_around] = :lower_right
182
+ text_box = Prawn::Text::Box.new(@text, @options)
183
+ text_box.render()
184
+
185
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
186
+ x = @x + @width
187
+ y = @y - @height
188
+ x_prime = x * @cos - y * @sin
189
+ y_prime = x * @sin + y * @cos
190
+ matrices.matrices[0].should == [1, 0, 0, 1,
191
+ reduce_precision(x - x_prime),
192
+ reduce_precision(y - y_prime)]
193
+ matrices.matrices[1].should == [reduce_precision(@cos),
194
+ reduce_precision(@sin),
195
+ reduce_precision(-@sin),
196
+ reduce_precision(@cos), 0, 0]
197
+
198
+ text = PDF::Inspector::Text.analyze(@pdf.render)
199
+ text.strings.should.not.be.empty
200
+ end
201
+ end
202
+ context ":rotate_around option of :lower_left" do
203
+ it "should draw content to the page rotated about the lower left corner of the text" do
204
+ @options[:rotate_around] = :lower_left
205
+ text_box = Prawn::Text::Box.new(@text, @options)
206
+ text_box.render()
207
+
208
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
209
+ x = @x
210
+ y = @y - @height
211
+ x_prime = x * @cos - y * @sin
212
+ y_prime = x * @sin + y * @cos
213
+ matrices.matrices[0].should == [1, 0, 0, 1,
214
+ reduce_precision(x - x_prime),
215
+ reduce_precision(y - y_prime)]
216
+ matrices.matrices[1].should == [reduce_precision(@cos),
217
+ reduce_precision(@sin),
218
+ reduce_precision(-@sin),
219
+ reduce_precision(@cos), 0, 0]
220
+
221
+ text = PDF::Inspector::Text.analyze(@pdf.render)
222
+ text.strings.should.not.be.empty
223
+ end
224
+ end
225
+ end
226
+
227
+ describe "Text::Box default height" do
228
+ it "should be the height from the bottom bound to document.y" do
229
+ create_pdf
230
+ target_height = @pdf.y - @pdf.bounds.bottom
231
+ @text = "Oh hai\n" * 60
232
+ @options = { :document => @pdf }
233
+ text_box = Prawn::Text::Box.new(@text, @options)
234
+ text_box.render
235
+ text_box.height.should.be.close(target_height, @pdf.font.height)
236
+ end
237
+ end
238
+
239
+ describe "Text::Box default at" do
240
+ it "should be the left corner of the bounds, and the current document.y" do
241
+ create_pdf
242
+ target_at = [@pdf.bounds.left, @pdf.y]
243
+ @text = "Oh hai text rect. " * 100
244
+ @options = { :document => @pdf }
245
+ text_box = Prawn::Text::Box.new(@text, @options)
246
+ text_box.render
247
+ text_box.at.should == target_at
248
+ end
249
+ end
250
+
251
+ describe "Text::Box with text than can fit in the box" do
252
+ before(:each) do
253
+ create_pdf
254
+ @text = "Oh hai text rect. " * 10
255
+ @options = {
256
+ :width => 162.0,
257
+ :height => 162.0,
258
+ :document => @pdf
259
+ }
260
+ end
261
+
262
+ it "printed text should match requested text, except for trailing or leading white space and that spaces may be replaced by newlines" do
263
+ text_box = Prawn::Text::Box.new(@text, @options)
264
+ text_box.render
265
+ text_box.text.gsub("\n", " ").should == @text.strip
266
+ end
267
+
268
+ it "render should return an empty string because no text remains unprinted" do
269
+ text_box = Prawn::Text::Box.new(@text, @options)
270
+ text_box.render.should == ""
271
+ end
272
+
273
+ it "should be truncated when the leading is set high enough to prevent all the lines from being printed" do
274
+ @options[:leading] = 40
275
+ text_box = Prawn::Text::Box.new(@text, @options)
276
+ text_box.render
277
+ text_box.text.gsub("\n", " ").should.not == @text.strip
278
+ end
279
+ end
280
+
281
+ describe "Text::Box with text than can fit in the box with :ellipses overflow and :valign => :bottom" do
282
+ it "should not print ellipses" do
283
+ create_pdf
284
+ @text = "Oh hai text rect. " * 10
285
+ @options = {
286
+ :width => 162.0,
287
+ :height => 162.0,
288
+ :overflow => :ellipses,
289
+ :valign => :bottom,
290
+ :document => @pdf
291
+ }
292
+ @text_box = Prawn::Text::Box.new(@text, @options)
293
+ @text_box.render
294
+ @text_box.text.should.not =~ /\.\.\./
295
+ end
296
+ end
297
+
298
+
299
+
300
+ describe "Text::Box printing UTF-8 string with higher bit characters" do
301
+ before(:each) do
302
+ create_pdf
303
+ @text = "©"
304
+ # not enough height to print any text, so we can directly compare against
305
+ # the input string
306
+ bounding_height = 1.0
307
+ options = {
308
+ :height => bounding_height,
309
+ :document => @pdf
310
+ }
311
+ @text_box = Prawn::Text::Box.new(@text, options)
312
+ end
313
+ describe "when using a TTF font" do
314
+ it "unprinted text should be in UTF-8 encoding" do
315
+ @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
316
+ remaining_text = @text_box.render
317
+ remaining_text.should == @text
318
+ end
319
+ it "subsequent calls to Text::Box need not include the" +
320
+ " :skip_encoding => true option" do
321
+ @pdf.font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
322
+ remaining_text = @text_box.render
323
+ lambda {
324
+ @pdf.text_box(remaining_text, :document => @pdf)
325
+ }.should.not.raise(ArgumentError)
326
+ end
327
+ end
328
+ describe "when using an AFM font" do
329
+ it "unprinted text should be in WinAnsi encoding" do
330
+ remaining_text = @text_box.render
331
+ remaining_text.should == @pdf.font.normalize_encoding(@text)
332
+ end
333
+ it "subsequent calls to Text::Box must include the" +
334
+ " :skip_encoding => true option" do
335
+ remaining_text = @text_box.render
336
+ lambda {
337
+ @pdf.text_box(remaining_text, :document => @pdf)
338
+ }.should.raise(ArgumentError)
339
+ lambda {
340
+ @pdf.text_box(remaining_text, :skip_encoding => true,
341
+ :document => @pdf)
342
+ }.should.not.raise(ArgumentError)
343
+ end
344
+ end
345
+ end
346
+
347
+
348
+ describe "Text::Box with more text than can fit in the box" do
349
+ before(:each) do
350
+ create_pdf
351
+ @text = "Oh hai text rect. " * 30
352
+ @bounding_height = 162.0
353
+ @options = {
354
+ :width => 162.0,
355
+ :height => @bounding_height,
356
+ :document => @pdf
357
+ }
358
+ end
359
+
360
+ context "truncated overflow" do
361
+ before(:each) do
362
+ @options[:overflow] = :truncate
363
+ @text_box = Prawn::Text::Box.new(@text, @options)
364
+ end
365
+ it "should not display ellipses" do
366
+ @text_box.render
367
+ @text_box.text.should.not =~ /\.\.\./
368
+ end
369
+ it "should be truncated" do
370
+ @text_box.render
371
+ @text_box.text.gsub("\n", " ").should.not == @text.strip
372
+ end
373
+ it "render should not return an empty string because some text remains unprinted" do
374
+ @text_box.render.should.not == ""
375
+ end
376
+ it "#height should be no taller than the specified height" do
377
+ @text_box.render
378
+ @text_box.height.should.be <= @bounding_height
379
+ end
380
+ it "#height should be within one font height of the specified height" do
381
+ @text_box.render
382
+ @bounding_height.should.be.close(@text_box.height, @pdf.font.height)
383
+ end
384
+ context "with :rotation option" do
385
+ it "unrendered text should be the same as when not rotated" do
386
+ remaining_text = @text_box.render
387
+
388
+ rotation = 30
389
+ x = 300
390
+ y = 70
391
+ width = @options[:width]
392
+ height = @options[:height]
393
+ @options[:document] = @pdf
394
+ @options[:rotation] = rotation
395
+ @options[:at] = [x, y]
396
+ rotated_text_box = Prawn::Text::Box.new(@text, @options)
397
+ rotated_text_box.render.should == remaining_text
398
+ end
399
+ end
400
+ end
401
+
402
+ context "ellipses overflow" do
403
+ before(:each) do
404
+ @options[:overflow] = :ellipses
405
+ @text_box = Prawn::Text::Box.new(@text, @options)
406
+ end
407
+ it "should display ellipses" do
408
+ @text_box.render
409
+ @text_box.text.should =~ /\.\.\./
410
+ end
411
+ it "render should not return an empty string because some text remains unprinted" do
412
+ @text_box.render.should.not == ""
413
+ end
414
+ end
415
+
416
+ context "expand overflow" do
417
+ before(:each) do
418
+ @options[:overflow] = :expand
419
+ @text_box = Prawn::Text::Box.new(@text, @options)
420
+ end
421
+ it "height should expand to encompass all the text (but not exceed the height of the page)" do
422
+ @text_box.render
423
+ @text_box.height.should > @bounding_height
424
+ end
425
+ it "should display the entire string (as long as there was space remaining on the page to print all the text)" do
426
+ @text_box.render
427
+ @text_box.text.gsub("\n", " ").should == @text.strip
428
+ end
429
+ it "render should return an empty string because no text remains unprinted(as long as there was space remaining on the page to print all the text)" do
430
+ @text_box.render.should == ""
431
+ end
432
+ end
433
+
434
+ context "shrink_to_fit overflow" do
435
+ before(:each) do
436
+ @options[:overflow] = :shrink_to_fit
437
+ @options[:min_font_size] = 2
438
+ @text_box = Prawn::Text::Box.new(@text, @options)
439
+ end
440
+ it "should display the entire text" do
441
+ @text_box.render
442
+ @text_box.text.gsub("\n", " ").should == @text.strip
443
+ end
444
+ it "render should return an empty string because no text remains unprinted" do
445
+ @text_box.render.should == ""
446
+ end
447
+ end
448
+ end
449
+
450
+ describe "Text::Box with a solid block of Chinese characters" do
451
+ it "printed text should match requested text, except for newlines" do
452
+ create_pdf
453
+ @text = "写中国字" * 10
454
+ @options = {
455
+ :width => 162.0,
456
+ :height => 162.0,
457
+ :document => @pdf
458
+ }
459
+ @pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
460
+ @options[:overflow] = :truncate
461
+ text_box = Prawn::Text::Box.new(@text, @options)
462
+ text_box.render
463
+ text_box.text.gsub("\n", "").should == @text.strip
464
+ end
465
+ end
466
+
467
+
468
+ describe "drawing bounding boxes" do
469
+
470
+ before(:each) { create_pdf }
471
+
472
+ it "should restore the margin box when bounding box exits" do
473
+ margin_box = @pdf.bounds
474
+
475
+ @pdf.text_box "Oh hai text box. " * 11, :height => @pdf.font.height * 10
476
+
477
+ @pdf.bounds.should == margin_box
478
+
479
+ end
480
+
481
+ end
482
+
483
+
484
+ describe 'Text::Box wrapping' do
485
+ before(:each) do
486
+ create_pdf
487
+ end
488
+
489
+ it "should wrap text" do
490
+ text = "Please wrap this text about HERE. More text that should be wrapped"
491
+ expect = "Please wrap this text about\nHERE. More text that should be\nwrapped"
492
+
493
+ @pdf.font "Courier"
494
+ text_box = Prawn::Text::Box.new(text,
495
+ :width => 220,
496
+ :overflow => :expand,
497
+ :document => @pdf)
498
+ text_box.render
499
+ text_box.text.should == expect
500
+ end
501
+
502
+ it "should respect end of line when wrapping text" do
503
+ text = "Please wrap only before\nTHIS word. Don't wrap this"
504
+ expect = text
505
+
506
+ @pdf.font "Courier"
507
+ text_box = Prawn::Text::Box.new(text,
508
+ :width => 220,
509
+ :overflow => :expand,
510
+ :document => @pdf)
511
+ text_box.render
512
+ text_box.text.should == expect
513
+ end
514
+
515
+ it "should respect multiple newlines when wrapping text" do
516
+ text = "Please wrap only before THIS\n\nword. Don't wrap this"
517
+ expect= "Please wrap only before\nTHIS\n\nword. Don't wrap this"
518
+
519
+ @pdf.font "Courier"
520
+ text_box = Prawn::Text::Box.new(text,
521
+ :width => 200,
522
+ :overflow => :expand,
523
+ :document => @pdf)
524
+ text_box.render
525
+ text_box.text.should == expect
526
+ end
527
+
528
+ it "should respect multiple newlines when wrapping text when those newlines coincide with a line break" do
529
+ text = "Please wrap only before\n\nTHIS word. Don't wrap this"
530
+ expect = text
531
+
532
+ @pdf.font "Courier"
533
+ text_box = Prawn::Text::Box.new(text,
534
+ :width => 220,
535
+ :overflow => :expand,
536
+ :document => @pdf)
537
+ text_box.render
538
+ text_box.text.should == expect
539
+ end
540
+
541
+ it "should respect initial newlines" do
542
+ text = "\nThis should be on line 2"
543
+ expect = text
544
+
545
+ @pdf.font "Courier"
546
+ text_box = Prawn::Text::Box.new(text,
547
+ :width => 220,
548
+ :overflow => :expand,
549
+ :document => @pdf)
550
+ text_box.render
551
+ text_box.text.should == expect
552
+ end
553
+
554
+ it "should wrap lines comprised of a single word of the bounds when wrapping text" do
555
+ text = "You_can_wrap_this_text_HERE"
556
+ expect = "You_can_wrap_this_text_HE\nRE"
557
+
558
+ @pdf.font "Courier"
559
+ text_box = Prawn::Text::Box.new(text,
560
+ :width => 180,
561
+ :overflow => :expand,
562
+ :document => @pdf)
563
+ text_box.render
564
+ text_box.text.should == expect
565
+ end
566
+
567
+ it "should wrap lines comprised of a single word of the bounds when wrapping text" do
568
+ text = '©' * 30
569
+
570
+ @pdf.font "Courier"
571
+ text_box = Prawn::Text::Box.new(text, :width => 180,
572
+ :overflow => :expand,
573
+ :document => @pdf)
574
+
575
+ text_box.render
576
+
577
+ expected = '©'*25 + "\n" + '©' * 5
578
+ @pdf.font.normalize_encoding!(expected)
579
+
580
+ text_box.text.should == expected
581
+ end
582
+
583
+ it "should wrap non-unicode strings using single-byte word-wrapping" do
584
+ text = "continúa esforzandote " * 5
585
+ text_box = Prawn::Text::Box.new(text, :width => 180,
586
+ :document => @pdf)
587
+ text_box.render
588
+ results_with_accent = text_box.text
589
+
590
+ text = "continua esforzandote " * 5
591
+ text_box = Prawn::Text::Box.new(text, :width => 180,
592
+ :document => @pdf)
593
+ text_box.render
594
+ results_without_accent = text_box.text
595
+
596
+ results_with_accent.first_line.length.should == results_without_accent.first_line.length
597
+ end
598
+
599
+ end
600
+
601
+ def reduce_precision(float)
602
+ ("%.5f" % float).to_f
603
+ end