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,314 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require 'iconv'
5
+
6
+ describe "Font behavior" do
7
+
8
+ it "should default to Helvetica if no font is specified" do
9
+ @pdf = Prawn::Document.new
10
+ @pdf.font.name.should == "Helvetica"
11
+ end
12
+
13
+ end
14
+
15
+ describe "#font_size" do
16
+ it "should allow setting font size in DSL style" do
17
+ create_pdf
18
+ @pdf.font_size 20
19
+ @pdf.font_size.should == 20
20
+ end
21
+ end
22
+
23
+ describe "font style support" do
24
+ before(:each) { create_pdf }
25
+
26
+ it "should complain if there is no @current_page" do
27
+ pdf_without_page = Prawn::Document.new(:skip_page_creation => true)
28
+
29
+ lambda{ pdf_without_page.font "Helvetica" }.
30
+ should.raise(Prawn::Errors::NotOnPage)
31
+ end
32
+
33
+ it "should allow specifying font style by style name and font family" do
34
+ @pdf.font "Courier", :style => :bold
35
+ @pdf.text "In Courier bold"
36
+
37
+ @pdf.font "Courier", :style => :bold_italic
38
+ @pdf.text "In Courier bold-italic"
39
+
40
+ @pdf.font "Courier", :style => :italic
41
+ @pdf.text "In Courier italic"
42
+
43
+ @pdf.font "Courier", :style => :normal
44
+ @pdf.text "In Normal Courier"
45
+
46
+ @pdf.font "Helvetica"
47
+ @pdf.text "In Normal Helvetica"
48
+
49
+ text = PDF::Inspector::Text.analyze(@pdf.render)
50
+ text.font_settings.map { |e| e[:name] }.should ==
51
+ [:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
52
+ :Courier, :Helvetica]
53
+ end
54
+
55
+ it "should allow font familes to be defined in a single dfont" do
56
+ file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
57
+ @pdf.font_families["Action Man"] = {
58
+ :normal => { :file => file, :font => "ActionMan" },
59
+ :italic => { :file => file, :font => "ActionMan-Italic" },
60
+ :bold => { :file => file, :font => "ActionMan-Bold" },
61
+ :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
62
+ }
63
+
64
+ @pdf.font "Action Man", :style => :italic
65
+ @pdf.text "In ActionMan-Italic"
66
+
67
+ text = PDF::Inspector::Text.analyze(@pdf.render)
68
+ name = text.font_settings.map { |e| e[:name] }.first.to_s
69
+ name = name.sub(/\w+\+/, "subset+")
70
+ name.should == "subset+ActionMan-Italic"
71
+ end
72
+ end
73
+
74
+ describe "Transactional font handling" do
75
+ before(:each) { create_pdf }
76
+
77
+ it "should allow setting of size directly when font is created" do
78
+ @pdf.font "Courier", :size => 16
79
+ @pdf.font_size.should == 16
80
+ end
81
+
82
+ it "should allow temporary setting of a new font using a transaction" do
83
+ @pdf.font "Helvetica", :size => 12
84
+
85
+ @pdf.font "Courier", :size => 16 do
86
+ @pdf.font.name.should == "Courier"
87
+ @pdf.font_size.should == 16
88
+ end
89
+
90
+ @pdf.font.name.should == "Helvetica"
91
+ @pdf.font_size.should == 12
92
+ end
93
+
94
+ it "should mask font size when using a transacation" do
95
+ @pdf.font "Courier", :size => 16 do
96
+ @pdf.font_size.should == 16
97
+ end
98
+
99
+ @pdf.font "Times-Roman"
100
+ @pdf.font "Courier"
101
+
102
+ @pdf.font_size.should == 12
103
+ end
104
+
105
+ end
106
+
107
+ describe "Document#page_fonts" do
108
+ before(:each) { create_pdf }
109
+
110
+ it "should register fonts properly by page" do
111
+ @pdf.font "Courier"; @pdf.text("hello")
112
+ @pdf.font "Helvetica"; @pdf.text("hello")
113
+ @pdf.font "Times-Roman"; @pdf.text("hello")
114
+ ["Courier","Helvetica","Times-Roman"].each { |f|
115
+ page_should_include_font(f)
116
+ }
117
+
118
+ @pdf.start_new_page
119
+ @pdf.font "Helvetica"; @pdf.text("hello")
120
+ page_should_include_font("Helvetica")
121
+ page_should_not_include_font("Courier")
122
+ page_should_not_include_font("Times-Roman")
123
+ end
124
+
125
+ def page_includes_font?(font)
126
+ @pdf.page.fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
127
+ end
128
+
129
+ def page_should_include_font(font)
130
+ assert_block("Expected page to include font: #{font}") do
131
+ page_includes_font?(font)
132
+ end
133
+ end
134
+
135
+ def page_should_not_include_font(font)
136
+ assert_block("Did not expect page to include font: #{font}") do
137
+ not page_includes_font?(font)
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ describe "AFM fonts" do
144
+
145
+ setup do
146
+ create_pdf
147
+ @times = @pdf.find_font "Times-Roman"
148
+ @iconv = ::Iconv.new('Windows-1252', 'utf-8')
149
+ end
150
+
151
+ it "should calculate string width taking into account accented characters" do
152
+ @times.compute_width_of(@iconv.iconv("é"), :size => 12).should == @times.compute_width_of("e", :size => 12)
153
+ end
154
+
155
+ it "should calculate string width taking into account kerning pairs" do
156
+ @times.compute_width_of(@iconv.iconv("To"), :size => 12).should == 13.332
157
+ @times.compute_width_of(@iconv.iconv("To"), :size => 12, :kerning => true).should == 12.372
158
+ @times.compute_width_of(@iconv.iconv("Tö"), :size => 12, :kerning => true).should == 12.372
159
+ end
160
+
161
+ it "should encode text without kerning by default" do
162
+ @times.encode_text(@iconv.iconv("To")).should == [[0, "To"]]
163
+ @times.encode_text(@iconv.iconv("Télé")).should == [[0, @iconv.iconv("Télé")]]
164
+ @times.encode_text(@iconv.iconv("Technology")).should == [[0, "Technology"]]
165
+ @times.encode_text(@iconv.iconv("Technology...")).should == [[0, "Technology..."]]
166
+ end
167
+
168
+ it "should encode text with kerning if requested" do
169
+ @times.encode_text(@iconv.iconv("To"), :kerning => true).should == [[0, ["T", 80, "o"]]]
170
+ @times.encode_text(@iconv.iconv("Télé"), :kerning => true).should == [[0, ["T", 70, @iconv.iconv("élé")]]]
171
+ @times.encode_text(@iconv.iconv("Technology"), :kerning => true).should == [[0, ["T", 70, "echnology"]]]
172
+ @times.encode_text(@iconv.iconv("Technology..."), :kerning => true).should == [[0, ["T", 70, "echnology", 65, "..."]]]
173
+ end
174
+
175
+ describe "when normalizing encoding" do
176
+
177
+ it "should not modify the original string when normalize_encoding() is used" do
178
+ original = "Foo"
179
+ normalized = @times.normalize_encoding(original)
180
+ assert ! original.equal?(normalized)
181
+ end
182
+
183
+ it "should modify the original string when normalize_encoding!() is used" do
184
+ original = "Foo"
185
+ normalized = @times.normalize_encoding!(original)
186
+ assert original.equal?(normalized)
187
+ end
188
+
189
+ end
190
+
191
+ it "should omit /Encoding for symbolic fonts" do
192
+ zapf = @pdf.find_font "ZapfDingbats"
193
+ font_dict = zapf.send(:register, nil)
194
+ font_dict.data[:Encoding].should == nil
195
+ end
196
+
197
+ end
198
+
199
+ describe "TTF fonts" do
200
+
201
+ setup do
202
+ create_pdf
203
+ @activa = @pdf.find_font "#{Prawn::BASEDIR}/data/fonts/Activa.ttf"
204
+ end
205
+
206
+ it "should calculate string width taking into account accented characters" do
207
+ @activa.compute_width_of("é", :size => 12).should == @activa.compute_width_of("e", :size => 12)
208
+ end
209
+
210
+ it "should calculate string width taking into account kerning pairs" do
211
+ @activa.compute_width_of("To", :size => 12).should == 15.228
212
+ @activa.compute_width_of("To", :size => 12, :kerning => true).should == 12.996
213
+ end
214
+
215
+ it "should encode text without kerning by default" do
216
+ @activa.encode_text("To").should == [[0, "To"]]
217
+ @activa.encode_text("Télé").should == [[0, "T\216l\216"]]
218
+ @activa.encode_text("Technology").should == [[0, "Technology"]]
219
+ @activa.encode_text("Technology...").should == [[0, "Technology..."]]
220
+ @activa.encode_text("Teχnology...").should == [[0, "Te"], [1, "!"], [0, "nology..."]]
221
+ end
222
+
223
+ it "should encode text with kerning if requested" do
224
+ @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
225
+ @activa.encode_text("To", :kerning => true).should == [[0, ["T", 186.0, "o"]]]
226
+ @activa.encode_text("Technology", :kerning => true).should == [[0, ["T", 186.0, "echnology"]]]
227
+ @activa.encode_text("Technology...", :kerning => true).should == [[0, ["T", 186.0, "echnology", 88.0, "..."]]]
228
+ @activa.encode_text("Teχnology...", :kerning => true).should == [[0, ["T", 186.0, "e"]], [1, "!"], [0, ["nology", 88.0, "..."]]]
229
+ end
230
+
231
+ describe "when normalizing encoding" do
232
+
233
+ it "should not modify the original string when normalize_encoding() is used" do
234
+ original = "Foo"
235
+ normalized = @activa.normalize_encoding(original)
236
+ assert ! original.equal?(normalized)
237
+ end
238
+
239
+ it "should modify the original string when normalize_encoding!() is used" do
240
+ original = "Foo"
241
+ normalized = @activa.normalize_encoding!(original)
242
+ assert original.equal?(normalized)
243
+ end
244
+
245
+ end
246
+
247
+ describe "when used with snapshots or transactions" do
248
+
249
+ it "should allow TTF fonts to be used alongside document transactions" do
250
+ lambda {
251
+ Prawn::Document.new do
252
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
253
+ text "Hi there"
254
+ transaction { text "Nice, thank you" }
255
+ end
256
+ }.should.not.raise
257
+ end
258
+
259
+ it "should allow TTF fonts to be used inside transactions" do
260
+ pdf = Prawn::Document.new do
261
+ transaction do
262
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
263
+ text "Hi there"
264
+ end
265
+ end
266
+
267
+ text = PDF::Inspector::Text.analyze(pdf.render)
268
+ name = text.font_settings.map { |e| e[:name] }.first.to_s
269
+ name = name.sub(/\w+\+/, "subset+")
270
+ name.should == "subset+DejaVuSans"
271
+ end
272
+
273
+ end
274
+
275
+ end
276
+
277
+ describe "DFont fonts" do
278
+ setup do
279
+ create_pdf
280
+ @file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
281
+ end
282
+
283
+ it "should list all named fonts" do
284
+ list = Prawn::Font::DFont.named_fonts(@file)
285
+ list.sort.should == %w(ActionMan ActionMan-Italic ActionMan-Bold ActionMan-BoldItalic).sort
286
+ end
287
+
288
+ it "should count the number of fonts in the file" do
289
+ Prawn::Font::DFont.font_count(@file).should == 4
290
+ end
291
+
292
+ it "should default selected font to the first one if not specified" do
293
+ font = @pdf.find_font(@file)
294
+ font.basename.should == "ActionMan"
295
+ end
296
+
297
+ it "should allow font to be selected by index" do
298
+ font = @pdf.find_font(@file, :font => 2)
299
+ font.basename.should == "ActionMan-Italic"
300
+ end
301
+
302
+ it "should allow font to be selected by name" do
303
+ font = @pdf.find_font(@file, :font => "ActionMan-BoldItalic")
304
+ font.basename.should == "ActionMan-BoldItalic"
305
+ end
306
+
307
+ it "should cache font object based on selected font" do
308
+ f1 = @pdf.find_font(@file, :font => "ActionMan")
309
+ f2 = @pdf.find_font(@file, :font => "ActionMan-Bold")
310
+ assert_not_equal f1.object_id, f2.object_id
311
+ assert_equal f1.object_id, @pdf.find_font(@file, :font => "ActionMan").object_id
312
+ assert_equal f2.object_id, @pdf.find_font(@file, :font => "ActionMan-Bold").object_id
313
+ end
314
+ end
@@ -0,0 +1,438 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "When drawing a line" do
6
+
7
+ before(:each) { create_pdf }
8
+
9
+ it "should draw a line from (100,600) to (100,500)" do
10
+ @pdf.line([100,600],[100,500])
11
+
12
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
13
+
14
+ line_drawing.points.should == [[100,600],[100,500]]
15
+ end
16
+
17
+ it "should draw two lines at (100,600) to (100,500) " +
18
+ "and (75,100) to (50,125)" do
19
+ @pdf.line(100,600,100,500)
20
+ @pdf.line(75,100,50,125)
21
+
22
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
23
+
24
+ line_drawing.points.should ==
25
+ [[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
26
+ end
27
+
28
+ it "should properly set line width via line_width=" do
29
+ @pdf.line_width = 10
30
+ line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
31
+ line.widths.first.should == 10
32
+ end
33
+
34
+ it "should properly set line width via line_width(width)" do
35
+ @pdf.line_width(10)
36
+ line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
37
+ line.widths.first.should == 10
38
+ end
39
+
40
+ describe "(Horizontally)" do
41
+ it "should draw from [x1,pdf.y],[x2,pdf.y]" do
42
+ @pdf.horizontal_line(100,150)
43
+ @line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
44
+ @line.points.should == [[100.0 + @pdf.bounds.absolute_left, @pdf.y],
45
+ [150.0 + @pdf.bounds.absolute_left, @pdf.y]]
46
+ end
47
+
48
+ it "should draw a line from (200, 250) to (300, 250)" do
49
+ @pdf.horizontal_line(200,300,:at => 250)
50
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
51
+ line_drawing.points.should == [[200,250],[300,250]]
52
+ end
53
+ end
54
+
55
+ describe "(Vertically)" do
56
+ it "should draw a line from (350, 300) to (350, 400)" do
57
+ @pdf.vertical_line(300,400,:at => 350)
58
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
59
+ line_drawing.points.should == [[350,300],[350,400]]
60
+ end
61
+ it "should require a y coordinate" do
62
+ lambda { @pdf.vertical_line(400,500) }.
63
+ should.raise(ArgumentError)
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ describe "When drawing a polygon" do
70
+
71
+ before(:each) { create_pdf }
72
+
73
+ it "should draw each line passed to polygon()" do
74
+ @pdf.polygon([100,500],[100,400],[200,400])
75
+
76
+ line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
77
+ line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
78
+ end
79
+
80
+ end
81
+
82
+ describe "When drawing a rectangle" do
83
+
84
+ before(:each) { create_pdf }
85
+
86
+ it "should use a point, width, and height for coords" do
87
+ @pdf.rectangle [200,200], 50, 100
88
+
89
+ rectangles = PDF::Inspector::Graphics::Rectangle.
90
+ analyze(@pdf.render).rectangles
91
+ # PDF uses bottom left corner
92
+ rectangles[0][:point].should == [200,100]
93
+ rectangles[0][:width].should == 50
94
+ rectangles[0][:height].should == 100
95
+
96
+ end
97
+
98
+ end
99
+
100
+ describe "When drawing a curve" do
101
+
102
+ before(:each) { create_pdf }
103
+
104
+ it "should draw a bezier curve from 50,50 to 100,100" do
105
+ @pdf.move_to [50,50]
106
+ @pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
107
+ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
108
+ curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
109
+ end
110
+
111
+ it "should draw a bezier curve from 100,100 to 50,50" do
112
+ @pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
113
+ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
114
+ curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
115
+ end
116
+
117
+
118
+ end
119
+
120
+ describe "When drawing a rounded rectangle" do
121
+ before(:each) do
122
+ create_pdf
123
+ @pdf.rounded_rectangle([50, 550], 50, 100, 10)
124
+ curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
125
+ curve_points = []
126
+ curve.coords.each_slice(2) {|p| curve_points << p}
127
+ @original_point = curve_points.shift
128
+ curves = []
129
+ curve_points.each_slice(3) {|c| curves << c}
130
+ line_points = PDF::Inspector::Graphics::Line.analyze(@pdf.render).points
131
+ line_points.shift
132
+ @all_coords = []
133
+ line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p }
134
+ @all_coords.unshift @original_point
135
+ end
136
+
137
+ it "should draw a rectangle by connecting lines with rounded bezier curves" do
138
+ @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0],
139
+ [100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0],
140
+ [60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0],
141
+ [50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]]
142
+ end
143
+
144
+ it "should start and end with the same point" do
145
+ @original_point.should == @all_coords.last
146
+ end
147
+
148
+
149
+ end
150
+
151
+ describe "When drawing an ellipse" do
152
+ before(:each) do
153
+ create_pdf
154
+ @pdf.ellipse_at [100,100], 25, 50
155
+ @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
156
+ end
157
+
158
+ it "should move the pointer to the center of the ellipse after drawing" do
159
+ @curve.coords[-2..-1].should == [100,100]
160
+ end
161
+
162
+ end
163
+
164
+ describe "When drawing a circle" do
165
+ before(:each) do
166
+ create_pdf
167
+ @pdf.circle_at [100,100], :radius => 25
168
+ @pdf.ellipse_at [100,100], 25, 25
169
+ @curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
170
+ end
171
+
172
+ it "should stroke the same path as the equivalent ellipse" do
173
+ middle = @curve.coords.length / 2
174
+ @curve.coords[0...middle].should == @curve.coords[middle..-1]
175
+ end
176
+ end
177
+
178
+ describe "When setting colors" do
179
+
180
+ before(:each) { create_pdf }
181
+
182
+ it "should set stroke colors" do
183
+ @pdf.stroke_color "ffcccc"
184
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
185
+ # 100% red, 80% green, 80% blue
186
+ colors.stroke_color.should == [1.0, 0.8, 0.8]
187
+ end
188
+
189
+ it "should set fill colors" do
190
+ @pdf.fill_color "ccff00"
191
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
192
+ # 80% red, 100% green, 0% blue
193
+ colors.fill_color.should == [0.8,1.0,0]
194
+ end
195
+
196
+ it "should reset the colors on each new page if they have been defined" do
197
+ @pdf.fill_color "ccff00"
198
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
199
+
200
+ colors.fill_color_count.should == 2
201
+ colors.stroke_color_count.should == 1
202
+ @pdf.start_new_page
203
+ @pdf.stroke_color "ff00cc"
204
+
205
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
206
+ colors.fill_color_count.should == 3
207
+ colors.stroke_color_count.should == 3
208
+
209
+ @pdf.start_new_page
210
+ colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
211
+ colors.fill_color_count.should == 4
212
+ colors.stroke_color_count.should == 4
213
+
214
+ colors.fill_color.should == [0.8,1.0,0.0]
215
+ colors.stroke_color.should == [1.0,0.0,0.8]
216
+ end
217
+
218
+ end
219
+
220
+ describe "When using painting shortcuts" do
221
+ before(:each) { create_pdf }
222
+
223
+ it "should convert stroke_some_method(args) into some_method(args); stroke" do
224
+ @pdf.expects(:line_to).with([100,100])
225
+ @pdf.expects(:stroke)
226
+
227
+ @pdf.stroke_line_to [100,100]
228
+ end
229
+
230
+ it "should convert fill_some_method(args) into some_method(args); fill" do
231
+ @pdf.expects(:line_to).with([100,100])
232
+ @pdf.expects(:fill)
233
+
234
+ @pdf.fill_line_to [100,100]
235
+ end
236
+
237
+ it "should not break method_missing" do
238
+ lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
239
+ should.raise(NoMethodError)
240
+ end
241
+ end
242
+
243
+ describe "When using graphics states" do
244
+ before(:each) { create_pdf }
245
+
246
+ it "should add the right content on save_graphics_state" do
247
+ @pdf.expects(:add_content).with('q')
248
+
249
+ @pdf.save_graphics_state
250
+ end
251
+
252
+ it "should add the right content on restore_graphics_state" do
253
+ @pdf.expects(:add_content).with('Q')
254
+
255
+ @pdf.restore_graphics_state
256
+ end
257
+
258
+ it "should save and restore when save_graphics_state is used with a block" do
259
+ state = sequence "state"
260
+ @pdf.expects(:add_content).with('q').in_sequence(state)
261
+ @pdf.expects(:foo).in_sequence(state)
262
+ @pdf.expects(:add_content).with('Q').in_sequence(state)
263
+
264
+ @pdf.save_graphics_state do
265
+ @pdf.foo
266
+ end
267
+ end
268
+ end
269
+
270
+ describe "When using transformation matrix" do
271
+ before(:each) { create_pdf }
272
+
273
+ # Note: The (approximate) number of significant decimal digits of precision in fractional
274
+ # part is 5 (PDF Reference, Third Edition, p. 706)
275
+
276
+ it "should send the right content on transformation_matrix" do
277
+ @pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
278
+ @pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
279
+ end
280
+
281
+ it "should use fixed digits with very small number" do
282
+ values = Array.new(6, 0.000000000001)
283
+ string = Array.new(6, "0.00000").join " "
284
+ @pdf.expects(:add_content).with("#{string} cm")
285
+ @pdf.transformation_matrix *values
286
+ end
287
+
288
+ it "should be received by the inspector" do
289
+ @pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
290
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
291
+ matrices.matrices.should == [[1, 0, 0, -1, 5.5, 20]]
292
+ end
293
+
294
+ it "should save the graphics state inside the given block" do
295
+ values = Array.new(6, 0.000000000001)
296
+ string = Array.new(6, "0.00000").join " "
297
+ process = sequence "process"
298
+
299
+ @pdf.expects(:save_graphics_state).with().in_sequence(process)
300
+ @pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
301
+ @pdf.expects(:do_something).with().in_sequence(process)
302
+ @pdf.expects(:restore_graphics_state).with().in_sequence(process)
303
+ @pdf.transformation_matrix(*values) do
304
+ @pdf.do_something
305
+ end
306
+ end
307
+
308
+ end
309
+
310
+ describe "When using transformations shortcuts" do
311
+ before(:each) do
312
+ create_pdf
313
+ @x, @y = 12, 54.32
314
+ @angle = 12.32
315
+ @cos = Math.cos(@angle * Math::PI / 180)
316
+ @sin = Math.sin(@angle * Math::PI / 180)
317
+ @factor = 0.12
318
+ end
319
+
320
+ describe "#rotate" do
321
+ it "should rotate" do
322
+ @pdf.expects(:transformation_matrix).with(@cos, @sin, -@sin, @cos, 0, 0)
323
+ @pdf.rotate(@angle)
324
+ end
325
+ end
326
+
327
+ describe "#rotate with :origin option" do
328
+ it "should rotate around the origin" do
329
+ x_prime = @x * @cos - @y * @sin
330
+ y_prime = @x * @sin + @y * @cos
331
+
332
+ @pdf.rotate(@angle, :origin => [@x, @y]) { @pdf.text('hello world') }
333
+
334
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
335
+ matrices.matrices[0].should == [1, 0, 0, 1,
336
+ reduce_precision(@x - x_prime),
337
+ reduce_precision(@y - y_prime)]
338
+ matrices.matrices[1].should == [reduce_precision(@cos),
339
+ reduce_precision(@sin),
340
+ reduce_precision(-@sin),
341
+ reduce_precision(@cos), 0, 0]
342
+ end
343
+
344
+ it "should rotate around the origin in a document with a margin" do
345
+ @pdf = Prawn::Document.new
346
+
347
+ @pdf.rotate(@angle, :origin => [@x, @y]) { @pdf.text('hello world') }
348
+
349
+ x = @x + @pdf.bounds.absolute_left
350
+ y = @y + @pdf.bounds.absolute_bottom
351
+ x_prime = x * @cos - y * @sin
352
+ y_prime = x * @sin + y * @cos
353
+
354
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
355
+ matrices.matrices[0].should == [1, 0, 0, 1,
356
+ reduce_precision(x - x_prime),
357
+ reduce_precision(y - y_prime)]
358
+ matrices.matrices[1].should == [reduce_precision(@cos),
359
+ reduce_precision(@sin),
360
+ reduce_precision(-@sin),
361
+ reduce_precision(@cos), 0, 0]
362
+ end
363
+
364
+ it "should raise BlockRequired if no block is given" do
365
+ lambda {
366
+ @pdf.rotate(@angle, :origin => [@x, @y])
367
+ }.should.raise(Prawn::Errors::BlockRequired)
368
+ end
369
+
370
+ def reduce_precision(float)
371
+ ("%.5f" % float).to_f
372
+ end
373
+ end
374
+
375
+ describe "#translate" do
376
+ it "should translate" do
377
+ x, y = 12, 54.32
378
+ @pdf.expects(:transformation_matrix).with(1, 0, 0, 1, x, y)
379
+ @pdf.translate(x, y)
380
+ end
381
+ end
382
+
383
+ describe "#scale" do
384
+ it "should scale" do
385
+ @pdf.expects(:transformation_matrix).with(@factor, 0, 0, @factor, 0, 0)
386
+ @pdf.scale(@factor)
387
+ end
388
+ end
389
+
390
+ describe "#scale with :origin option" do
391
+ it "should scale from the origin" do
392
+ x_prime = @factor * @x
393
+ y_prime = @factor * @y
394
+
395
+ @pdf.scale(@factor, :origin => [@x, @y]) { @pdf.text('hello world') }
396
+
397
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
398
+ matrices.matrices[0].should == [1, 0, 0, 1,
399
+ reduce_precision(@x - x_prime),
400
+ reduce_precision(@y - y_prime)]
401
+ matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
402
+ end
403
+
404
+ it "should scale from the origin in a document with a margin" do
405
+ @pdf = Prawn::Document.new
406
+ x = @x + @pdf.bounds.absolute_left
407
+ y = @y + @pdf.bounds.absolute_bottom
408
+ x_prime = @factor * x
409
+ y_prime = @factor * y
410
+
411
+ @pdf.scale(@factor, :origin => [@x, @y]) { @pdf.text('hello world') }
412
+
413
+ matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
414
+ matrices.matrices[0].should == [1, 0, 0, 1,
415
+ reduce_precision(x - x_prime),
416
+ reduce_precision(y - y_prime)]
417
+ matrices.matrices[1].should == [@factor, 0, 0, @factor, 0, 0]
418
+ end
419
+
420
+ it "should raise BlockRequired if no block is given" do
421
+ lambda {
422
+ @pdf.scale(@factor, :origin => [@x, @y])
423
+ }.should.raise(Prawn::Errors::BlockRequired)
424
+ end
425
+
426
+ def reduce_precision(float)
427
+ ("%.5f" % float).to_f
428
+ end
429
+ end
430
+
431
+ # describe "skew" do
432
+ # it "should skew" do
433
+ # a, b = 30, 50.2
434
+ # @pdf.expects(:transformation_matrix).with(1, Math.tan(a * Math::PI / 180), Math.tan(b * Math::PI / 180), 1, 0, 0)
435
+ # @pdf.skew(a, b)
436
+ # end
437
+ # end
438
+ end