alphasights-prawn 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/COPYING +340 -0
  2. data/HACKING +50 -0
  3. data/LICENSE +56 -0
  4. data/README +141 -0
  5. data/Rakefile +52 -0
  6. data/data/encodings/win_ansi.txt +29 -0
  7. data/data/fonts/Action Man.dfont +0 -0
  8. data/data/fonts/Activa.ttf +0 -0
  9. data/data/fonts/Chalkboard.ttf +0 -0
  10. data/data/fonts/Courier-Bold.afm +342 -0
  11. data/data/fonts/Courier-BoldOblique.afm +342 -0
  12. data/data/fonts/Courier-Oblique.afm +342 -0
  13. data/data/fonts/Courier.afm +342 -0
  14. data/data/fonts/DejaVuSans.ttf +0 -0
  15. data/data/fonts/Dustismo_Roman.ttf +0 -0
  16. data/data/fonts/Helvetica-Bold.afm +2827 -0
  17. data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  18. data/data/fonts/Helvetica-Oblique.afm +3051 -0
  19. data/data/fonts/Helvetica.afm +3051 -0
  20. data/data/fonts/MustRead.html +19 -0
  21. data/data/fonts/Symbol.afm +213 -0
  22. data/data/fonts/Times-Bold.afm +2588 -0
  23. data/data/fonts/Times-BoldItalic.afm +2384 -0
  24. data/data/fonts/Times-Italic.afm +2667 -0
  25. data/data/fonts/Times-Roman.afm +2419 -0
  26. data/data/fonts/ZapfDingbats.afm +225 -0
  27. data/data/fonts/comicsans.ttf +0 -0
  28. data/data/fonts/gkai00mp.ttf +0 -0
  29. data/data/images/16bit.alpha +0 -0
  30. data/data/images/16bit.dat +0 -0
  31. data/data/images/16bit.png +0 -0
  32. data/data/images/arrow.png +0 -0
  33. data/data/images/arrow2.png +0 -0
  34. data/data/images/barcode_issue.png +0 -0
  35. data/data/images/dice.alpha +0 -0
  36. data/data/images/dice.dat +0 -0
  37. data/data/images/dice.png +0 -0
  38. data/data/images/dice_interlaced.png +0 -0
  39. data/data/images/fractal.jpg +0 -0
  40. data/data/images/letterhead.jpg +0 -0
  41. data/data/images/page_white_text.alpha +0 -0
  42. data/data/images/page_white_text.dat +0 -0
  43. data/data/images/page_white_text.png +0 -0
  44. data/data/images/pigs.jpg +0 -0
  45. data/data/images/rails.dat +0 -0
  46. data/data/images/rails.png +0 -0
  47. data/data/images/ruport.png +0 -0
  48. data/data/images/ruport_data.dat +0 -0
  49. data/data/images/ruport_transparent.png +0 -0
  50. data/data/images/ruport_type0.png +0 -0
  51. data/data/images/stef.jpg +0 -0
  52. data/data/images/tru256.bmp +0 -0
  53. data/data/images/web-links.dat +1 -0
  54. data/data/images/web-links.png +0 -0
  55. data/data/pdfs/complex_template.pdf +0 -0
  56. data/data/pdfs/contains_ttf_font.pdf +0 -0
  57. data/data/pdfs/encrypted.pdf +0 -0
  58. data/data/pdfs/hexagon.pdf +61 -0
  59. data/data/pdfs/indirect_reference.pdf +86 -0
  60. data/data/pdfs/nested_pages.pdf +118 -0
  61. data/data/pdfs/resources_as_indirect_object.pdf +83 -0
  62. data/data/pdfs/two_hexagons.pdf +90 -0
  63. data/data/pdfs/version_1_6.pdf +61 -0
  64. data/data/shift_jis_text.txt +1 -0
  65. data/examples/bounding_box/bounding_boxes.rb +43 -0
  66. data/examples/bounding_box/indentation.rb +34 -0
  67. data/examples/bounding_box/russian_boxes.rb +36 -0
  68. data/examples/bounding_box/stretched_nesting.rb +67 -0
  69. data/examples/builder/simple.rb +28 -0
  70. data/examples/example_helper.rb +4 -0
  71. data/examples/general/background.rb +23 -0
  72. data/examples/general/canvas.rb +15 -0
  73. data/examples/general/context_sensitive_headers.rb +37 -0
  74. data/examples/general/float.rb +11 -0
  75. data/examples/general/margin.rb +36 -0
  76. data/examples/general/measurement_units.rb +51 -0
  77. data/examples/general/metadata-info.rb +16 -0
  78. data/examples/general/multi_page_layout.rb +18 -0
  79. data/examples/general/outlines.rb +50 -0
  80. data/examples/general/page_geometry.rb +31 -0
  81. data/examples/general/page_numbering.rb +15 -0
  82. data/examples/general/repeaters.rb +47 -0
  83. data/examples/general/stamp.rb +41 -0
  84. data/examples/general/templates.rb +13 -0
  85. data/examples/graphics/basic_images.rb +23 -0
  86. data/examples/graphics/chunkable.rb +38 -0
  87. data/examples/graphics/cmyk.rb +12 -0
  88. data/examples/graphics/curves.rb +11 -0
  89. data/examples/graphics/hexagon.rb +13 -0
  90. data/examples/graphics/image_fit.rb +15 -0
  91. data/examples/graphics/image_flow.rb +37 -0
  92. data/examples/graphics/image_position.rb +17 -0
  93. data/examples/graphics/line.rb +32 -0
  94. data/examples/graphics/png_types.rb +22 -0
  95. data/examples/graphics/polygons.rb +16 -0
  96. data/examples/graphics/remote_images.rb +12 -0
  97. data/examples/graphics/rounded_polygons.rb +19 -0
  98. data/examples/graphics/rounded_rectangle.rb +20 -0
  99. data/examples/graphics/ruport_style_helpers.rb +19 -0
  100. data/examples/graphics/stroke_bounds.rb +20 -0
  101. data/examples/graphics/stroke_cap_and_join.rb +45 -0
  102. data/examples/graphics/stroke_dash.rb +42 -0
  103. data/examples/graphics/transformations.rb +52 -0
  104. data/examples/graphics/transparency.rb +26 -0
  105. data/examples/m17n/chinese_text_wrapping.rb +17 -0
  106. data/examples/m17n/euro.rb +15 -0
  107. data/examples/m17n/sjis.rb +28 -0
  108. data/examples/m17n/utf8.rb +13 -0
  109. data/examples/m17n/win_ansi_charset.rb +54 -0
  110. data/examples/security/hello_foo.rb +8 -0
  111. data/examples/table/bill.rb +53 -0
  112. data/examples/table/cell.rb +12 -0
  113. data/examples/table/checkerboard.rb +22 -0
  114. data/examples/table/header.rb +14 -0
  115. data/examples/table/inline_format_table.rb +12 -0
  116. data/examples/table/multi_page_table.rb +9 -0
  117. data/examples/table/simple_table.rb +24 -0
  118. data/examples/table/subtable.rb +12 -0
  119. data/examples/table/widths.rb +20 -0
  120. data/examples/text/alignment.rb +18 -0
  121. data/examples/text/character_spacing.rb +12 -0
  122. data/examples/text/dfont.rb +48 -0
  123. data/examples/text/family_based_styling.rb +24 -0
  124. data/examples/text/font_calculations.rb +91 -0
  125. data/examples/text/font_size.rb +33 -0
  126. data/examples/text/hyphenation.rb +45 -0
  127. data/examples/text/indent_paragraphs.rb +22 -0
  128. data/examples/text/inline_format.rb +103 -0
  129. data/examples/text/kerning.rb +30 -0
  130. data/examples/text/rotated.rb +98 -0
  131. data/examples/text/shaped_text_box.rb +31 -0
  132. data/examples/text/simple_text.rb +17 -0
  133. data/examples/text/simple_text_ttf.rb +17 -0
  134. data/examples/text/text_box.rb +88 -0
  135. data/examples/text/text_box_returning_excess.rb +51 -0
  136. data/examples/text/text_flow.rb +67 -0
  137. data/lib/prawn.rb +27 -0
  138. data/lib/prawn/canvas.rb +119 -0
  139. data/lib/prawn/chunkable.rb +37 -0
  140. data/lib/prawn/compatibility.rb +51 -0
  141. data/lib/prawn/core.rb +85 -0
  142. data/lib/prawn/core/annotations.rb +61 -0
  143. data/lib/prawn/core/byte_string.rb +9 -0
  144. data/lib/prawn/core/chunk.rb +36 -0
  145. data/lib/prawn/core/destinations.rb +90 -0
  146. data/lib/prawn/core/document_state.rb +78 -0
  147. data/lib/prawn/core/literal_string.rb +16 -0
  148. data/lib/prawn/core/name_tree.rb +165 -0
  149. data/lib/prawn/core/object_store.rb +236 -0
  150. data/lib/prawn/core/page.rb +179 -0
  151. data/lib/prawn/core/pdf_object.rb +108 -0
  152. data/lib/prawn/core/reference.rb +112 -0
  153. data/lib/prawn/core/text.rb +140 -0
  154. data/lib/prawn/core/text/formatted/arranger.rb +266 -0
  155. data/lib/prawn/core/text/formatted/line_wrap.rb +127 -0
  156. data/lib/prawn/core/text/formatted/wrap.rb +112 -0
  157. data/lib/prawn/core/text/line_wrap.rb +209 -0
  158. data/lib/prawn/core/text/wrap.rb +80 -0
  159. data/lib/prawn/document.rb +573 -0
  160. data/lib/prawn/document/bounding_box.rb +425 -0
  161. data/lib/prawn/document/graphics_state.rb +48 -0
  162. data/lib/prawn/document/internals.rb +170 -0
  163. data/lib/prawn/document/page_geometry.rb +136 -0
  164. data/lib/prawn/document/snapshot.rb +87 -0
  165. data/lib/prawn/document_builder.rb +51 -0
  166. data/lib/prawn/document_builder/command.rb +38 -0
  167. data/lib/prawn/document_builder/constructs.rb +2 -0
  168. data/lib/prawn/document_builder/constructs/flowing_text_construct.rb +18 -0
  169. data/lib/prawn/document_builder/constructs/path_construct.rb +9 -0
  170. data/lib/prawn/document_builder/layout.rb +25 -0
  171. data/lib/prawn/document_builder/modifications.rb +2 -0
  172. data/lib/prawn/document_builder/modifications/layout_modification.rb +9 -0
  173. data/lib/prawn/document_builder/modifications/path_modification.rb +9 -0
  174. data/lib/prawn/encoding.rb +121 -0
  175. data/lib/prawn/errors.rb +94 -0
  176. data/lib/prawn/font.rb +341 -0
  177. data/lib/prawn/font/afm.rb +225 -0
  178. data/lib/prawn/font/dfont.rb +42 -0
  179. data/lib/prawn/font/ttf.rb +350 -0
  180. data/lib/prawn/graphics.rb +325 -0
  181. data/lib/prawn/graphics/cap_style.rb +38 -0
  182. data/lib/prawn/graphics/color.rb +205 -0
  183. data/lib/prawn/graphics/dash.rb +71 -0
  184. data/lib/prawn/graphics/join_style.rb +38 -0
  185. data/lib/prawn/graphics/transformation.rb +156 -0
  186. data/lib/prawn/graphics/transparency.rb +99 -0
  187. data/lib/prawn/images.rb +348 -0
  188. data/lib/prawn/images/jpg.rb +46 -0
  189. data/lib/prawn/images/png.rb +226 -0
  190. data/lib/prawn/measurement_extensions.rb +46 -0
  191. data/lib/prawn/measurements.rb +71 -0
  192. data/lib/prawn/outline.rb +278 -0
  193. data/lib/prawn/repeater.rb +129 -0
  194. data/lib/prawn/security.rb +262 -0
  195. data/lib/prawn/security/arcfour.rb +51 -0
  196. data/lib/prawn/stamp.rb +126 -0
  197. data/lib/prawn/table.rb +421 -0
  198. data/lib/prawn/table/accessors.rb +180 -0
  199. data/lib/prawn/table/cell.rb +350 -0
  200. data/lib/prawn/table/cell/in_table.rb +27 -0
  201. data/lib/prawn/table/cell/subtable.rb +65 -0
  202. data/lib/prawn/table/cell/text.rb +125 -0
  203. data/lib/prawn/text.rb +449 -0
  204. data/lib/prawn/text/box.rb +392 -0
  205. data/lib/prawn/text/formatted.rb +4 -0
  206. data/lib/prawn/text/formatted/box.rb +228 -0
  207. data/lib/prawn/text/formatted/fragment.rb +181 -0
  208. data/lib/prawn/text/formatted/parser.rb +213 -0
  209. data/spec/annotations_spec.rb +90 -0
  210. data/spec/bounding_box_spec.rb +190 -0
  211. data/spec/cell_spec.rb +348 -0
  212. data/spec/destinations_spec.rb +15 -0
  213. data/spec/document_spec.rb +473 -0
  214. data/spec/font_spec.rb +324 -0
  215. data/spec/formatted_text_arranger_spec.rb +426 -0
  216. data/spec/formatted_text_box_spec.rb +756 -0
  217. data/spec/formatted_text_fragment_spec.rb +211 -0
  218. data/spec/graphics_spec.rb +446 -0
  219. data/spec/images_spec.rb +96 -0
  220. data/spec/inline_formatted_text_parser_spec.rb +502 -0
  221. data/spec/jpg_spec.rb +25 -0
  222. data/spec/line_wrap_spec.rb +341 -0
  223. data/spec/measurement_units_spec.rb +23 -0
  224. data/spec/name_tree_spec.rb +112 -0
  225. data/spec/object_store_spec.rb +160 -0
  226. data/spec/outline_spec.rb +269 -0
  227. data/spec/pdf_object_spec.rb +170 -0
  228. data/spec/png_spec.rb +237 -0
  229. data/spec/reference_spec.rb +82 -0
  230. data/spec/repeater_spec.rb +96 -0
  231. data/spec/security_spec.rb +120 -0
  232. data/spec/snapshot_spec.rb +138 -0
  233. data/spec/spec_helper.rb +26 -0
  234. data/spec/stamp_spec.rb +108 -0
  235. data/spec/stroke_styles_spec.rb +163 -0
  236. data/spec/table_spec.rb +598 -0
  237. data/spec/template_spec.rb +158 -0
  238. data/spec/text_at_spec.rb +119 -0
  239. data/spec/text_box_spec.rb +742 -0
  240. data/spec/text_spacing_spec.rb +75 -0
  241. data/spec/text_spec.rb +333 -0
  242. data/spec/text_with_inline_formatting_spec.rb +193 -0
  243. data/spec/transparency_spec.rb +89 -0
  244. metadata +331 -0
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstrates extending Text::Box
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate "shaped_text_box.pdf" do |pdf|
8
+ module ShapedBox
9
+ def available_width
10
+ height + 25
11
+ end
12
+ end
13
+
14
+ Prawn::Text::Box.extensions << ShapedBox
15
+ pdf.stroke_rectangle([10, pdf.bounds.top - 10], 300, 300)
16
+ pdf.text_box("A" * 500,
17
+ :at => [10, pdf.bounds.top - 10],
18
+ :width => 300,
19
+ :height => 300,
20
+ :align => :center)
21
+
22
+ Prawn::Text::Formatted::Box.extensions << ShapedBox
23
+ pdf.stroke_rectangle([10, pdf.bounds.top - 330], 300, 300)
24
+ pdf.formatted_text_box([:text => "A" * 500,
25
+ :color => "009900"],
26
+ :at => [10, pdf.bounds.top - 330],
27
+ :width => 300,
28
+ :height => 300,
29
+ :align => :center)
30
+ end
31
+
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ #
3
+ # An early example of basic text generation at absolute positions.
4
+ # Mostly kept for nostalgia.
5
+ #
6
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+
8
+ Prawn::Document.generate "simple_text.pdf" do
9
+ fill_color "0000ff"
10
+ draw_text "Hello World", :at => [200,420], :size => 32, :rotate => 45
11
+ font "Times-Roman"
12
+ fill_color "ff0000"
13
+ draw_text "Using Another Font", :at => [5,5]
14
+ start_new_page
15
+ font "Courier"
16
+ draw_text "Goodbye World", :at => [288,50]
17
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ #
3
+ # An early example of TTF font embedding. Mostly kept for nostalgia's sake.
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate "simple_text_ttf.pdf" do
8
+ fill_color "0000ff"
9
+ font "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
10
+ draw_text "Hello World", :at => [200,720], :size => 32
11
+
12
+ font "#{Prawn::BASEDIR}/data/fonts/Chalkboard.ttf"
13
+
14
+ pad(20) do
15
+ text "This is chalkboard wrapping " * 20
16
+ end
17
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ #
3
+
4
+ require 'examples/example_helper'
5
+
6
+ Prawn::Document.generate("text_box.pdf") do
7
+ def get_string(i, j)
8
+ case i
9
+ when 0
10
+ text = "this is left text " * 30
11
+ text.insert(48, "\n\n")
12
+ when 1
13
+ text = "this is center text " * 30
14
+ text.insert(54, "\n\n")
15
+ when 2
16
+ text = "this is right text " * 30
17
+ text.insert(51, "\n\n")
18
+ end
19
+
20
+ case j
21
+ when 0
22
+ text.split(" ").slice(0..47).join(" ")
23
+ when 3
24
+ text.delete(" ")
25
+ else
26
+ text
27
+ end
28
+ end
29
+
30
+ def get_options(i, j)
31
+ options = {
32
+ :width => bounds.width * 0.3,
33
+ :height => bounds.width * 0.3,
34
+ :overflow => :ellipses,
35
+ :at => [0, 0],
36
+ :align => :left,
37
+ :document => self
38
+ }
39
+
40
+ case i
41
+ when 0
42
+ options[:valign] = :top if j == 0
43
+ when 1
44
+ options[:align] = :center
45
+ options[:valign] = :center if j == 0
46
+ when 2
47
+ options[:align] = :right
48
+ options[:valign] = :bottom if j == 0
49
+ end
50
+
51
+ case j
52
+ when 1
53
+ options[:overflow] = :shrink_to_fit
54
+ when 2
55
+ options[:leading] = font.height * 0.5
56
+ options[:overflow] = :truncate
57
+ end
58
+ options
59
+ end
60
+
61
+ stroke_color("555555")
62
+ 3.times do |i|
63
+ 4.times do |j|
64
+ options = get_options(i, j)
65
+ options[:at][0] = (bounds.width - options[:width]) * 0.5 * i
66
+ options[:at][1] = bounds.top - (bounds.height - options[:height]) * 0.33 * j
67
+ box = Prawn::Text::Box.new(get_string(i, j), options)
68
+
69
+ fill_color("ffeeee")
70
+ if i == 1
71
+ # bound with a box of a particular size, regardless of how
72
+ # much text it contains
73
+ fill_and_stroke_rectangle(options[:at],
74
+ options[:width],
75
+ options[:height])
76
+ else
77
+ # bound with a box that exactly fits the printed text using
78
+ # dry_run look-ahead
79
+ box.render(:dry_run => true)
80
+ fill_and_stroke_rectangle(options[:at],
81
+ options[:width],
82
+ box.height)
83
+ end
84
+ fill_color("000000")
85
+ box.render
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ #
3
+ # A text box is positioned by a top-left corner, width, and height and is
4
+ # essentially an invisible rectangle that the text will flow within. If the
5
+ # text exceeds the boundaries, it is either truncated, replaced with some
6
+ # ellipses, or set to expand beyond the bottom boundary.
7
+ #
8
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
9
+
10
+ Prawn::Document.generate("text_box_returning_excess.pdf") do
11
+
12
+ # Note that without the initial space in p_break, newlines may be eaten by
13
+ # the wrap/unwrap process that happens inside the text box.
14
+ p_break = " \n\n"
15
+ callout = "Lorem ipsum dolor sit amet"
16
+ lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.#{p_break}Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.#{p_break}Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
17
+
18
+ box_height = font.height * 5
19
+
20
+ # Add a callout box that the rest of the text should flow around
21
+ font_size(18) do
22
+ text_box callout, {
23
+ :width => 100,
24
+ :height => font.height * 3,
25
+ :overflow => :truncate,
26
+ :at => [100, bounds.top - box_height - 4]
27
+ }
28
+ end
29
+
30
+ excess_text = text_box lorem + p_break + lorem, {
31
+ :width => 300,
32
+ :height => box_height,
33
+ :overflow => :truncate,
34
+ :at => [100, bounds.top],
35
+ }
36
+
37
+ excess_text = text_box excess_text, {
38
+ :width => 200,
39
+ :height => box_height,
40
+ :overflow => :truncate,
41
+ :at => [200, bounds.top - box_height],
42
+ }
43
+
44
+ text_box excess_text, {
45
+ :width => 300,
46
+ :height => box_height,
47
+ :overflow => :expand,
48
+ :at => [100, bounds.top - box_height * 2],
49
+ }
50
+
51
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Basic text flowing example including the use of bounding boxes. A somewhat
4
+ # old example, mostly retained for nostalgia.
5
+ #
6
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+
8
+ content = <<-EOS
9
+ How does
10
+ Prawn deal with
11
+ white
12
+ space
13
+
14
+ and
15
+
16
+ line
17
+ breaks?
18
+ EOS
19
+
20
+ poem = <<-EOS
21
+ GOOD-BYE
22
+
23
+ Good-bye, proud world! I'm going home: Thou art not my friend, and I'm not thine. Long through thy weary crowds I roam; A river-ark on the ocean brine, Long I've been tossed like the driven foam: But now, proud world! I'm going home.
24
+
25
+ Good-bye to Flattery's fawning face; To Grandeur with his wise grimace; To upstart Wealth's averted eye; To supple Office, low and high; To crowded halls, to court and street; To frozen hearts and hasting feet; To those who go, and those who come; Good-bye, proud world! I'm going home.
26
+
27
+ I am going to my own hearth-stone, Bosomed in yon green hills alone,-- secret nook in a pleasant land, Whose groves the frolic fairies planned; Where arches green, the livelong day, Echo the blackbird's roundelay, And vulgar feet have never trod A spot that is sacred to thought and God.
28
+
29
+ O, when I am safe in my sylvan home, I tread on the pride of Greece and Rome; And when I am stretched beneath the pines, Where the evening star so holy shines, I laugh at the lore and the pride of man, At the sophist schools and the learned clan; For what are they all, in their high conceit, When man in the bush with God may meet?
30
+ EOS
31
+
32
+ overflow = "This text should flow gracefully onto the next page, like a stream"+
33
+ " flows elegantly from a mountain lake down into the village below."
34
+
35
+ Prawn::Document.generate("flow.pdf") do |pdf|
36
+
37
+ pdf.font "Times-Roman"
38
+ pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
39
+ [pdf.bounds.right, pdf.bounds.top]
40
+
41
+ pdf.text content, :size => 10
42
+
43
+ pdf.bounding_box([100,600], :width => 200, :height => 525) do
44
+ pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
45
+ [pdf.bounds.right, pdf.bounds.top]
46
+ pdf.text poem, :size => 12
47
+ end
48
+
49
+ pdf.bounding_box([325,600], :width => 200, :height => 525) do
50
+ pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
51
+ [pdf.bounds.right, pdf.bounds.top]
52
+ pdf.text poem.reverse, :size => 12
53
+ end
54
+
55
+ pdf.text overflow * 10, :size => 14
56
+
57
+ pdf.text "Hooray! We've conquered the evil PDF gods", :size => 36
58
+
59
+ pdf.bounding_box([100,450], :width => 300) do
60
+ pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
61
+ [pdf.bounds.right, pdf.bounds.top]
62
+ pdf.text poem, :size => 10, :leading => 5
63
+ end
64
+
65
+ pdf.text "And this text automatically goes below the poem", :size => 18
66
+
67
+ end
@@ -0,0 +1,27 @@
1
+ # Welcome to Prawn, the best PDF Generation library ever.
2
+ # This documentation covers user level functionality.
3
+ #
4
+ # Those looking to contribute code or write extensions should look
5
+ # into the lib/prawn/core/* source tree.
6
+ #
7
+ module Prawn #:nodoc:
8
+ end
9
+
10
+ require "prawn/core"
11
+ require "prawn/chunkable"
12
+ require "prawn/canvas"
13
+ require "prawn/text"
14
+ require "prawn/graphics"
15
+ require "prawn/images"
16
+ require "prawn/images/jpg"
17
+ require "prawn/images/png"
18
+ require "prawn/stamp"
19
+ require "prawn/security"
20
+ require "prawn/document"
21
+ require "prawn/font"
22
+ require "prawn/encoding"
23
+ require "prawn/measurements"
24
+ require "prawn/repeater"
25
+ require "prawn/outline"
26
+ require "prawn/table"
27
+ require "prawn/document_builder"
@@ -0,0 +1,119 @@
1
+ module Prawn
2
+ class Canvas
3
+ include Prawn::Chunkable
4
+
5
+ def initialize
6
+ @chunks = []
7
+ end
8
+
9
+ attr_accessor :chunks
10
+
11
+ chunk_methods :move_to, :line_to, :line, :stroke, :fill,
12
+ :curve_to, :curve, :rectangle, :ellipse, :circle
13
+
14
+ def move_to!(params)
15
+ chunk(:move_to, params) do |c|
16
+ "%.3f %.3f m" % c[:point]
17
+ end
18
+ end
19
+
20
+ def line_to!(params)
21
+ chunk(:line_to, params) do |c|
22
+ "%.3f %.3f l" % c[:point]
23
+ end
24
+ end
25
+
26
+ def curve_to!(params)
27
+ unless params[:bound1] && params[:bound2]
28
+ raise Prawn::Errors::InvalidGraphicsPath
29
+ end
30
+
31
+ chunk(:curve_to, params) do |c|
32
+ "%.3f %.3f %.3f %.3f %.3f %.3f c" % (c[:bound1] + c[:bound2] + c[:point])
33
+ end
34
+ end
35
+
36
+ def curve!(params)
37
+ chunk(:curve, params) do |c|
38
+ [ move_to!(:point => params[:point1]),
39
+ curve_to!(:point => params[:point2],
40
+ :bound1 => params[:bound1],
41
+ :bound2 => params[:bound2]) ]
42
+
43
+ end
44
+ end
45
+
46
+ KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
47
+
48
+ def ellipse!(params)
49
+ chunk(:ellipse, params) do |c|
50
+ x, y = c[:point]
51
+ r1 = c[:x_radius]
52
+ r2 = c[:y_radius]
53
+
54
+ l1 = r1 * KAPPA
55
+ l2 = r2 * KAPPA
56
+
57
+ start = move_to!(:point => [x + r1, y])
58
+
59
+ to_upper_right = curve_to!(:point => [x, y + r2],
60
+ :bound1 => [x + r1, y + l1],
61
+ :bound2 => [x + l2, y + r2])
62
+ to_upper_left = curve_to!(:point => [x - r1, y],
63
+ :bound1 => [x - l2, y + r2],
64
+ :bound2 => [x - r1, y + l1])
65
+
66
+ to_lower_left = curve_to!(:point => [x, y - r2],
67
+ :bound1 => [x - r1, y - l1],
68
+ :bound2 => [x - l2, y - r2])
69
+
70
+ to_lower_right = curve_to!(:point => [x + r1, y],
71
+ :bound1 => [x + l2, y - r2],
72
+ :bound2 => [x + r1, y - l1])
73
+
74
+ back_to_start = move_to!(:point => [x,y])
75
+
76
+ [start, to_upper_right, to_upper_left,
77
+ to_lower_left, to_lower_right, back_to_start]
78
+ end
79
+ end
80
+
81
+ def circle!(params)
82
+ chunk(:circle, params) do
83
+ ellipse!(:point => params[:point],
84
+ :x_radius => params[:radius],
85
+ :y_radius => params[:radius])
86
+
87
+ end
88
+ end
89
+
90
+ def line!(params)
91
+ chunk(:line, params) do |c|
92
+ [ move_to!(:point => c.params[:point1]),
93
+ line_to!(:point => c.params[:point2]) ]
94
+ end
95
+ end
96
+
97
+ def stroke!
98
+ chunk(:stroke) { "S" }
99
+ end
100
+
101
+ def fill!
102
+ chunk(:fill) { "F" }
103
+ end
104
+
105
+ def fill_and_stroke!
106
+ chunk(:fill_and_stroke) { "b" }
107
+ end
108
+
109
+ def rectangle!(params)
110
+ chunk(:rectangle, params) do |c|
111
+ x,y = params[:point]
112
+ y -= params[:height]
113
+
114
+ "%.3f %.3f %.3f %.3f re" % [ x, y, params[:width], params[:height] ]
115
+ end
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,37 @@
1
+ module Prawn
2
+ module Chunkable
3
+ def chunk(*a, &b)
4
+ Prawn::Core::Chunk.new(*a, &b)
5
+ end
6
+
7
+ def find_chunks(params)
8
+ if params[:command]
9
+ chunks.select { |c| c.command == params[:command] }
10
+ end
11
+ end
12
+
13
+ def to_pdf
14
+ rendered = @chunks.map do |chunk|
15
+ chunk.to_pdf
16
+ end
17
+
18
+ rendered.join("\n")
19
+ end
20
+
21
+ module ClassMethods
22
+ def chunk_methods(*names)
23
+ names.each do |name|
24
+ module_eval %{
25
+ def #{name}(*a, &b)
26
+ chunks << #{name}!(*a, &b)
27
+ end
28
+ }
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.included(base)
34
+ base.extend(ClassMethods)
35
+ end
36
+ end
37
+ end