prawn 0.13.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,116 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Prawn
4
-
5
- # The Prawn::ExampleFile class is a utility class to ease the manipulation
6
- # and extraction of source code and comments from the actual example files
7
- #
8
- class ExampleFile
9
- attr_reader :package, :filename
10
-
11
- # Stores the file data, filename and parent, which will be either an
12
- # ExampleSection or an ExamplePackage.
13
- #
14
- # Available boolean options are:
15
- #
16
- # <tt>:eval_source</tt>:: Evals the example source code (default: true)
17
- # <tt>:full_source</tt>:: Extract the full source code when true. Extract
18
- # only the code between the generate block when false (default: false)
19
- #
20
- def initialize(parent, filename, options={})
21
- @parent = parent.is_a?(String) ? ExamplePackage.new(parent) : parent
22
-
23
- @filename = filename
24
- @data = read_file(@parent.folder_name, filename)
25
-
26
- @options = {:eval_source => true, :full_source => false}.merge(options)
27
- end
28
-
29
- # Return the example source code excluding the initial comments and
30
- # require calls
31
- #
32
- def full_source
33
- @data.gsub(/# encoding.*?\n.*require.*?\n\n/m, "\n").strip
34
- end
35
-
36
- # Return the example source contained inside the first generate block or
37
- # the full source if no generate block is found
38
- #
39
- def generate_block_source
40
- block = @data.slice(/\w+\.generate.*? do\n(.*)end/m, 1)
41
-
42
- return full_source unless block
43
-
44
- block.gsub(/^( ){2}/, "")
45
- end
46
-
47
- # Return either the full_source or the generate_block_source according
48
- # to the options
49
- #
50
- def source
51
- @options[:full_source] ? full_source : generate_block_source
52
- end
53
-
54
- # Return true if the example source should be evaluated inline within
55
- # the manual according to the options
56
- #
57
- def eval?
58
- @options[:eval_source]
59
- end
60
-
61
- # Retrieve the comments between the encoding declaration and the require
62
- # call for example_helper.rb
63
- #
64
- # Then removes the '#' signs, reflows the line breaks and return the result
65
- #
66
- def introduction_text
67
- intro = @data.slice(/# encoding.*?\n(.*)require File\.expand_path/m, 1)
68
- intro.gsub!(/\n# (?=\S)/m, ' ')
69
- intro.gsub!(/^#/, '')
70
- intro.gsub!("\n", "\n\n")
71
- intro.rstrip!
72
- intro
73
- end
74
-
75
- # Returns a human friendly version of the example file name
76
- #
77
- def name
78
- @name ||= @filename[/(.*)\.rb/, 1].gsub("_", " ").capitalize
79
- end
80
-
81
- # Returns this example's parent original folder name
82
- #
83
- def parent_folder_name
84
- @parent.folder_name
85
- end
86
-
87
- # Returns the human friendly version of this example parent name
88
- #
89
- def parent_name
90
- @parent.name
91
- end
92
-
93
- # Renders this example to a pdf
94
- #
95
- def render(pdf)
96
- pdf.render_example(self)
97
- end
98
-
99
- private
100
-
101
- # Read the data from a file in a given package
102
- #
103
- def read_file(folder_name, filename)
104
- data = File.read(File.expand_path(File.join(
105
- File.dirname(__FILE__), folder_name, filename)))
106
-
107
- # XXX If we ever have manual files with source encodings other than
108
- # UTF-8, we will need to fix this to work on Ruby 1.9.
109
- if data.respond_to?(:encode!)
110
- data.encode!("UTF-8")
111
- end
112
- data
113
- end
114
-
115
- end
116
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Prawn
4
-
5
- # The Prawn::ExamplePackage class is a utility class to handle the packaging
6
- # of individual examples within a hierarchy when building the manual
7
- #
8
- class ExamplePackage
9
- attr_reader :intro_block, :folder_name
10
-
11
- def initialize(folder_name)
12
- @folder_name = folder_name
13
- @hierarchy = []
14
- end
15
-
16
- # Stores a new ExampleSection in the hierarchy and yields it to a block
17
- #
18
- def section(name)
19
- s = ExampleSection.new(self, name)
20
- yield s
21
- @hierarchy << s
22
- end
23
-
24
- # Stores a new ExampleFile in the hierarchy
25
- #
26
- def example(filename, options={})
27
- @hierarchy << ExampleFile.new(self, "#{filename}.rb", options)
28
- end
29
-
30
- # Stores a block with code to be evaluated when rendering the package cover
31
- #
32
- def intro(&block)
33
- @intro_block = block
34
- end
35
-
36
- # Returns a human friendly version of the package name
37
- #
38
- def name
39
- @name ||= @folder_name.gsub("_", " ").capitalize
40
- end
41
-
42
- # Renders a cover page for the package to a pdf and iterates the examples
43
- # hierarchy delegating the examples and sections to be rendered as well
44
- #
45
- def render(pdf)
46
- pdf.render_package_cover(self)
47
-
48
- @hierarchy.each do |node|
49
- node.render(pdf)
50
- end
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Prawn
4
-
5
- # The Prawn::ExampleSection class is a utility class to handle sections
6
- # of related examples within an ExamplePackage
7
- #
8
- class ExampleSection
9
- attr_reader :name
10
-
11
- def initialize(package, name)
12
- @package = package
13
- @name = name
14
- @examples = []
15
- end
16
-
17
- # Stores a new ExampleFile in the examples list
18
- #
19
- def example(filename, options={})
20
- @examples << ExampleFile.new(self, "#{filename}.rb", options)
21
- end
22
-
23
- # Returns this example's package original folder name
24
- #
25
- def folder_name
26
- @package.folder_name
27
- end
28
-
29
- # Returns the human friendly version of this section's package name
30
- #
31
- def package_name
32
- @package.name
33
- end
34
-
35
- # Renders the section to a pdf and iterates the examples list delegating the
36
- # examples to be rendered as well
37
- #
38
- def render(pdf)
39
- pdf.render_section(self)
40
-
41
- @examples.each do |example|
42
- example.render(pdf)
43
- end
44
- end
45
- end
46
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Prawn manual how to read this manual page.
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
9
- Prawn::Example.generate(filename) do
10
- move_down 200
11
-
12
- image "#{Prawn::DATADIR}/images/prawn.png",
13
- :scale => 0.9,
14
- :at => [10, cursor]
15
-
16
- formatted_text_box([ {:text => "Prawn\n",
17
- :styles => [:bold],
18
- :size => 100}
19
- ], :at => [170, cursor - 50])
20
-
21
- formatted_text_box([ {:text => "by example",
22
- :font => 'Courier',
23
- :size => 60}
24
- ], :at => [170, cursor - 160])
25
-
26
- #long git commit hash
27
- #commit = `git show --pretty=%H`
28
- #short git commit hash
29
- commit = `git show --pretty=%h`
30
- formatted_text_box([ {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n
31
- git commit: #{commit}",
32
- :size => 12}
33
- ], :at => [390, cursor - 620])
34
-
35
- end
@@ -1,85 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Prawn manual foreword page.
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__),
6
- %w[.. example_helper]))
7
-
8
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
9
- Prawn::Example.generate(filename) do
10
- header("Foreword, by Gregory Brown")
11
- prose %{
12
- Back in 2008, the state of PDF generation in
13
- Ruby was grim. The best general purpose tool that existed was
14
- Austin Ziegler's PDF::Writer, which was an ambitious but
15
- painfully unsustainable project. Despite years of hard work
16
- from Austin, the code was slow, buggy, and hard to
17
- understand. All of those things made it very difficult
18
- to extend with the many features that its users needed,
19
- and so it gradually turned into abandonware.
20
-
21
- Because I had a lot of work that depended on PDF generation
22
- I eventually volunteered to become the new maintainer of
23
- PDF::Writer. In the first couple months after I got commit bit, I
24
- managed to get out a couple minor releases that fixed
25
- known issues that had been left unresolved for years,
26
- and that made some people happy. However, the cliff
27
- ahead of me was far too steep to climb: without a
28
- major redesign, PDF::Writer would never support proper
29
- internationalization, would not easily be ported to
30
- Ruby 1.9, and would remain painfully slow for many
31
- ordinary tasks.
32
-
33
- Against my better judgement, but out of desperation, I
34
- was convinced that the only way forward was to attempt the
35
- big rewrite. It is good that I didn't realize
36
- how impossible that task would be, because otherwise,
37
- I would have never started working
38
- on Prawn. But with the support of dozens of Ruby community
39
- members who had graciously crowd-funded this project
40
- so that I could take a few months off of work to
41
- kick start it (long before Kickstarter existed!), Prawn
42
- was born.
43
-
44
- The PDF specification is over 1300 pages long, and despite
45
- being the original author and lead maintainer of this
46
- project from 2008-2011, I still know relatively little
47
- about the intricacies of the format. I relied heavily
48
- on the insights of our core team and casual contributors
49
- to educate me on various issues, and to help develop
50
- nearly every feature of this project. From day one,
51
- Prawn was a stone soup in which virtually all of the
52
- tasty bits were provided by the community at large --
53
- my most significant contribution was to simply
54
- keep stirring the pot. Now, the pot mostly stirs itself,
55
- with the occasional nudge from one of the core
56
- team members (usually Brad or James, but everyone
57
- has pitched in at one time or the other.)
58
-
59
- Although Prawn bears no resemblance to PDF::Writer, this library
60
- is most certainly its spiritual successor. That means that between
61
- Austin's efforts and that of the Prawn team, we've been
62
- trying to solve the PDF problem comfortably in Ruby for
63
- nearly a decade now. This manual will help you decide for
64
- yourself whether we've managed to finally overcome that
65
- challenge or not.
66
-
67
- I sincerely hope that a few years down the line, someone else
68
- comes along and makes something brand new and exciting that
69
- blows Prawn out of the water and onto the barbeque. But until
70
- that happens, what you'll find here is a very powerful
71
- PDF generation library that has a great team supporting it,
72
- and I suspect it will stay that way for the forseeable future.
73
-
74
- Happy Hacking!
75
-
76
- -greg
77
-
78
- PS: I cannot be possibly be more grateful for the time, money,
79
- code, and knowledge that the Ruby community has invested in
80
- this project. Whether you're a core team member or someone
81
- who filed a single thoughtful bug report, your efforts are
82
- what kept me motivated throughout the years that I spent working
83
- on this project.
84
- }
85
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Generates the Prawn by example manual.
4
- #
5
-
6
- Encoding.default_external = "UTF-8" if defined? Encoding
7
-
8
- require File.expand_path(File.join(File.dirname(__FILE__),
9
- %w[.. example_helper]))
10
-
11
- Prawn::Example.generate("manual.pdf",
12
- :optimize_objects => true,
13
- :skip_page_creation => true,
14
- :page_size => "FOLIO") do
15
-
16
- load_page "cover"
17
- load_page "foreword"
18
- load_page "how_to_read_this_manual"
19
-
20
- # Core chapters
21
- load_package "basic_concepts"
22
- load_package "graphics"
23
- load_package "text"
24
- load_package "bounding_box"
25
-
26
- # Remaining chapters
27
- load_package "layout"
28
- load_package "images"
29
- load_package "table"
30
- load_package "document_and_page_options"
31
- load_package "outline"
32
- load_package "repeatable_content"
33
- load_package "templates"
34
- load_package "security"
35
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "coderay"
4
-
5
- # Registers a to_prawn method on CodeRay. It returns an array of hashes to be
6
- # used with formatted_text.
7
- #
8
- # Usage:
9
- #
10
- # CodeRay.scan(string, :ruby).to_prawn
11
- #
12
- class PrawnEncoder < CodeRay::Encoders::Encoder
13
- register_for :to_prawn
14
-
15
- COLORS = { :default => "FFFFFF",
16
-
17
- :comment => "AEAEAE",
18
- :constant => "88A5D2",
19
- :instance_variable => "E8ED97",
20
- :integer => "C8FF0E",
21
- :float => "C8FF0E",
22
- :inline_delimiter => "EF804F", # #{} within a string
23
- :keyword => "FEE100",
24
-
25
- # BUG: There appear to be some problem with this token. Method
26
- # definitions are considered as ident tokens
27
- #
28
- :method => "FF5C00",
29
- :string => "56D65E",
30
- :symbol => "C8FF0E"
31
- }
32
-
33
- def setup(options)
34
- super
35
- @out = []
36
- @open = []
37
- end
38
-
39
- def text_token(text, kind)
40
- color = COLORS[kind] || COLORS[@open.last] || COLORS[:default]
41
-
42
- @out << {:text => text, :color => color}
43
- end
44
-
45
- def begin_group(kind)
46
- @open << kind
47
- end
48
-
49
- def end_group(kind)
50
- @open.pop
51
- end
52
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # All of the previous styling options we've seen deal with all the table cells
4
- # at once.
5
- #
6
- # With initializer blocks we may deal with specific cells.
7
- # A block passed to one of the table methods (<code>Prawn::Table.new</code>,
8
- # <code>Prawn::Document#table</code>, <code>Prawn::Document#make_table</code>)
9
- # will be called after cell setup but before layout. This is a very flexible way
10
- # to specify styling and layout constraints.
11
- #
12
- # Just like the <code>Prawn::Document.generate</code> method, the table
13
- # initializer blocks may be used with and without a block argument.
14
- #
15
- # The table class has three methods that are handy within an initializer block:
16
- # <code>cells</code>, <code>rows</code> and <code>columns</code>. All three
17
- # return an instance of <code>Prawn::Table::Cells</code> which represents
18
- # a selection of cells.
19
- #
20
- # <code>cells</code> return all the table cells, while <code>rows</code> and
21
- # <code>columns</code> accept a number or a range as argument which returns a
22
- # single row/column or a range of rows/columns respectively. (<code>rows</code>
23
- # and <code>columns</code> are also aliased as <code>row</code> and
24
- # <code>column</code>)
25
- #
26
- # The <code>Prawn::Table::Cells</code> class also defines <code>rows</code> and
27
- # <code>columns</code> so they may be chained to narrow the selection of cells.
28
- #
29
- # All of the cell styling options we've seen on previous examples may be set as
30
- # properties of the selection of cells.
31
- #
32
- require File.expand_path(File.join(File.dirname(__FILE__),
33
- %w[.. example_helper]))
34
-
35
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
36
- Prawn::Example.generate(filename) do
37
- data = [ ["Header", "A " * 5, "B"],
38
- ["Data row", "C", "D " * 5],
39
- ["Another data row", "E", "F"]]
40
-
41
- table(data) do
42
- cells.padding = 12
43
- cells.borders = []
44
-
45
- row(0).borders = [:bottom]
46
- row(0).border_width = 2
47
- row(0).font_style = :bold
48
-
49
- columns(0..1).borders = [:right]
50
-
51
- row(0).columns(0..1).borders = [:bottom, :right]
52
- end
53
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # <code>Prawn::Table#initialize</code> takes a
4
- # <code>:before_rendering_page</code> argument, to adjust the way an entire page
5
- # of table cells is styled. This allows you to do things like draw a border
6
- # around the entire table as displayed on a page.
7
- #
8
- # The callback is passed a Cells object that is numbered based on the order of
9
- # the cells on the page (e.g., the first row on the page is
10
- # <code>cells.row(0)</code>).
11
- #
12
- require File.expand_path(File.join(File.dirname(__FILE__),
13
- %w[.. example_helper]))
14
-
15
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
16
- Prawn::Example.generate(filename) do
17
- table([["foo", "bar", "baz"]] * 40) do |t|
18
- t.cells.border_width = 1
19
- t.before_rendering_page do |page|
20
- page.row(0).border_top_width = 3
21
- page.row(-1).border_bottom_width = 3
22
- page.column(0).border_left_width = 3
23
- page.column(-1).border_right_width = 3
24
- end
25
- end
26
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # The <code>border_lines</code> option accepts an array with the styles of the
4
- # border sides. The default is <code>[:solid, :solid, :solid, :solid]</code>.
5
- #
6
- # <code>border_lines</code> must be set to an array.
7
- #
8
- require File.expand_path(File.join(File.dirname(__FILE__),
9
- %w[.. example_helper]))
10
-
11
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
12
- Prawn::Example.generate(filename) do
13
- data = [ ["Look at how the cell border lines can be mixed", "", ""],
14
- ["dotted top border", "", ""],
15
- ["solid right border", "", ""],
16
- ["dotted bottom border", "", ""],
17
- ["dashed left border", "", ""]
18
- ]
19
-
20
- text "Cell :border_lines => [:dotted, :solid, :dotted, :dashed]"
21
-
22
- table(data, :cell_style =>
23
- { :border_lines => [:dotted, :solid, :dotted, :dashed] })
24
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # The <code>borders</code> option accepts an array with the border sides that
4
- # will be drawn. The default is <code>[:top, :bottom, :left, :right]</code>.
5
- #
6
- # <code>border_width</code> may be set with a numeric value.
7
- #
8
- # Both <code>border_color</code> and <code>background_color</code> accept an
9
- # HTML like RGB color string ("FF0000")
10
- #
11
- require File.expand_path(File.join(File.dirname(__FILE__),
12
- %w[.. example_helper]))
13
-
14
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
- Prawn::Example.generate(filename) do
16
- data = [ ["Look at how the cells will look when styled", "", ""],
17
- ["They probably won't look the same", "", ""]
18
- ]
19
-
20
- { :borders => [:top, :left],
21
- :border_width => 3,
22
- :border_color => "FF0000"}.each do |property, value|
23
-
24
- text "Cell #{property}: #{value.inspect}"
25
- table(data, :cell_style => {property => value})
26
- move_down 20
27
- end
28
-
29
- text "Cell background_color: FFFFCC"
30
- table(data, :cell_style => {:background_color => "FFFFCC"})
31
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # To style all the table cells you can use the <code>:cell_style</code> option
4
- # with the table methods. It accepts a hash with the cell style options.
5
- #
6
- # Some straightforward options are <code>width</code>, <code>height</code>,
7
- # and <code>padding</code>. All three accept numeric values to set the property.
8
- #
9
- # <code>padding</code> also accepts a four number array that defines the padding
10
- # in a CSS like syntax setting the top, right, bottom, left sequentially. The
11
- # default is 5pt for all sides.
12
- #
13
- require File.expand_path(File.join(File.dirname(__FILE__),
14
- %w[.. example_helper]))
15
-
16
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
17
- Prawn::Example.generate(filename) do
18
- data = [ ["Look at how the cells will look when styled", "", ""],
19
- ["They probably won't look the same", "", ""]
20
- ]
21
-
22
- {:width => 160, :height => 50, :padding => 12}.each do |property, value|
23
- text "Cell's #{property}: #{value}"
24
- table(data, :cell_style => {property => value})
25
- move_down 20
26
- end
27
-
28
- text "Padding can also be set with an array: [0, 0, 0, 30]"
29
- table(data, :cell_style => {:padding => [0, 0, 0, 30]})
30
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Text cells accept the following options: <code>align</code>,
4
- # <code>font</code>, <code>font_style</code>, <code>inline_format</code>,
5
- # <code>kerning</code>, <code>leading</code>, <code>min_font_size</code>,
6
- # <code>overflow</code>, <code>rotate</code>, <code>rotate_around</code>,
7
- # <code>single_line</code>, <code>size</code>, <code>text_color</code>,
8
- # and <code>valign</code>.
9
- #
10
- # Most of these style options are direct translations from the text methods
11
- # styling options.
12
- #
13
- require File.expand_path(File.join(File.dirname(__FILE__),
14
- %w[.. example_helper]))
15
-
16
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
17
- Prawn::Example.generate(filename) do
18
- data = [ ["Look at how the cells will look when styled", "", ""],
19
- ["They probably won't look the same", "", ""]
20
- ]
21
-
22
- table data, :cell_style => { :font => "Times-Roman", :font_style => :italic }
23
- move_down 20
24
-
25
- table data, :cell_style => { :size => 18, :text_color => "346842" }
26
- move_down 20
27
-
28
- table [["Just <font size='18'>some</font> <b><i>inline</i></b>", "", ""],
29
- ["<color rgb='FF00FF'>styles</color> being applied here", "", ""]],
30
- :cell_style => { :inline_format => true }
31
- move_down 20
32
-
33
- table [["1", "2", "3", "rotate"]], :cell_style => { :rotate => 30 }
34
- move_down 20
35
-
36
- table data, :cell_style => { :overflow => :shrink_to_fit, :min_font_size => 8,
37
- :width => 60, :height => 30 }
38
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Prawn will make its best attempt to identify the best width for the columns.
4
- # If the end result isn't good, we can override it with some styling.
5
- #
6
- # Individual column widths can be set with the <code>:column_widths</code>
7
- # option. Just provide an array with the sequential width values for the columns
8
- # or a hash were each key-value pair represents the column 0-based index and its
9
- # width.
10
- #
11
- require File.expand_path(File.join(File.dirname(__FILE__),
12
- %w[.. example_helper]))
13
-
14
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
- Prawn::Example.generate(filename) do
16
- data = [ ["this is not quite as long as the others",
17
- "here we have a line that is long but with smaller words",
18
- "this is so very looooooooooooooooooooooooooooooong"] ]
19
-
20
- text "Prawn trying to guess the column widths"
21
- table(data)
22
- move_down 20
23
-
24
- text "Manually setting all the column widths"
25
- table(data, :column_widths => [100, 200, 240])
26
- move_down 20
27
-
28
- text "Setting only the last column width"
29
- table(data, :column_widths => {2 => 240})
30
- end