prawn-git 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +10 -0
  3. data/COPYING +2 -0
  4. data/GPLv2 +340 -0
  5. data/GPLv3 +674 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE +56 -0
  8. data/Rakefile +55 -0
  9. data/data/fonts/Courier-Bold.afm +342 -0
  10. data/data/fonts/Courier-BoldOblique.afm +342 -0
  11. data/data/fonts/Courier-Oblique.afm +342 -0
  12. data/data/fonts/Courier.afm +342 -0
  13. data/data/fonts/Helvetica-Bold.afm +2827 -0
  14. data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  15. data/data/fonts/Helvetica-Oblique.afm +3051 -0
  16. data/data/fonts/Helvetica.afm +3051 -0
  17. data/data/fonts/MustRead.html +19 -0
  18. data/data/fonts/Symbol.afm +213 -0
  19. data/data/fonts/Times-Bold.afm +2588 -0
  20. data/data/fonts/Times-BoldItalic.afm +2384 -0
  21. data/data/fonts/Times-Italic.afm +2667 -0
  22. data/data/fonts/Times-Roman.afm +2419 -0
  23. data/data/fonts/ZapfDingbats.afm +225 -0
  24. data/data/images/16bit.alpha +0 -0
  25. data/data/images/16bit.color +0 -0
  26. data/data/images/16bit.png +0 -0
  27. data/data/images/arrow.png +0 -0
  28. data/data/images/arrow2.png +0 -0
  29. data/data/images/dice.alpha +0 -0
  30. data/data/images/dice.color +0 -0
  31. data/data/images/dice.png +0 -0
  32. data/data/images/dice_interlaced.png +0 -0
  33. data/data/images/fractal.jpg +0 -0
  34. data/data/images/indexed_color.dat +0 -0
  35. data/data/images/indexed_color.png +0 -0
  36. data/data/images/letterhead.jpg +0 -0
  37. data/data/images/license.md +8 -0
  38. data/data/images/page_white_text.alpha +0 -0
  39. data/data/images/page_white_text.color +0 -0
  40. data/data/images/page_white_text.png +0 -0
  41. data/data/images/pal_bk.png +0 -0
  42. data/data/images/pigs.jpg +0 -0
  43. data/data/images/prawn.png +0 -0
  44. data/data/images/ruport.png +0 -0
  45. data/data/images/ruport_data.dat +0 -0
  46. data/data/images/ruport_transparent.png +0 -0
  47. data/data/images/ruport_type0.png +0 -0
  48. data/data/images/stef.jpg +0 -0
  49. data/data/images/tru256.bmp +0 -0
  50. data/data/images/web-links.dat +1 -0
  51. data/data/images/web-links.png +0 -0
  52. data/data/pdfs/complex_template.pdf +0 -0
  53. data/data/pdfs/contains_ttf_font.pdf +0 -0
  54. data/data/pdfs/encrypted.pdf +0 -0
  55. data/data/pdfs/form.pdf +820 -0
  56. data/data/pdfs/hexagon.pdf +61 -0
  57. data/data/pdfs/indirect_reference.pdf +86 -0
  58. data/data/pdfs/multipage_template.pdf +127 -0
  59. data/data/pdfs/nested_pages.pdf +118 -0
  60. data/data/pdfs/page_without_mediabox.pdf +193 -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/lib/prawn.rb +89 -0
  66. data/lib/prawn/document.rb +706 -0
  67. data/lib/prawn/document/bounding_box.rb +539 -0
  68. data/lib/prawn/document/column_box.rb +144 -0
  69. data/lib/prawn/document/internals.rb +58 -0
  70. data/lib/prawn/document/span.rb +57 -0
  71. data/lib/prawn/encoding.rb +87 -0
  72. data/lib/prawn/errors.rb +80 -0
  73. data/lib/prawn/font.rb +413 -0
  74. data/lib/prawn/font/afm.rb +256 -0
  75. data/lib/prawn/font/dfont.rb +43 -0
  76. data/lib/prawn/font/ttf.rb +355 -0
  77. data/lib/prawn/font_metric_cache.rb +46 -0
  78. data/lib/prawn/graphics.rb +646 -0
  79. data/lib/prawn/graphics/cap_style.rb +47 -0
  80. data/lib/prawn/graphics/color.rb +232 -0
  81. data/lib/prawn/graphics/dash.rb +109 -0
  82. data/lib/prawn/graphics/join_style.rb +49 -0
  83. data/lib/prawn/graphics/patterns.rb +126 -0
  84. data/lib/prawn/graphics/transformation.rb +157 -0
  85. data/lib/prawn/graphics/transparency.rb +101 -0
  86. data/lib/prawn/grid.rb +279 -0
  87. data/lib/prawn/image_handler.rb +44 -0
  88. data/lib/prawn/images.rb +199 -0
  89. data/lib/prawn/images/image.rb +49 -0
  90. data/lib/prawn/images/jpg.rb +91 -0
  91. data/lib/prawn/images/png.rb +290 -0
  92. data/lib/prawn/measurement_extensions.rb +50 -0
  93. data/lib/prawn/measurements.rb +77 -0
  94. data/lib/prawn/outline.rb +289 -0
  95. data/lib/prawn/repeater.rb +124 -0
  96. data/lib/prawn/security.rb +288 -0
  97. data/lib/prawn/security/arcfour.rb +54 -0
  98. data/lib/prawn/soft_mask.rb +94 -0
  99. data/lib/prawn/stamp.rb +136 -0
  100. data/lib/prawn/text.rb +437 -0
  101. data/lib/prawn/text/box.rb +141 -0
  102. data/lib/prawn/text/formatted.rb +7 -0
  103. data/lib/prawn/text/formatted/arranger.rb +290 -0
  104. data/lib/prawn/text/formatted/box.rb +614 -0
  105. data/lib/prawn/text/formatted/fragment.rb +264 -0
  106. data/lib/prawn/text/formatted/line_wrap.rb +277 -0
  107. data/lib/prawn/text/formatted/parser.rb +224 -0
  108. data/lib/prawn/text/formatted/wrap.rb +160 -0
  109. data/lib/prawn/utilities.rb +46 -0
  110. data/lib/prawn/version.rb +5 -0
  111. data/lib/prawn/view.rb +91 -0
  112. data/manual/absolute_position.pdf +0 -0
  113. data/manual/basic_concepts/adding_pages.rb +27 -0
  114. data/manual/basic_concepts/basic_concepts.rb +36 -0
  115. data/manual/basic_concepts/creation.rb +39 -0
  116. data/manual/basic_concepts/cursor.rb +33 -0
  117. data/manual/basic_concepts/measurement.rb +25 -0
  118. data/manual/basic_concepts/origin.rb +38 -0
  119. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  120. data/manual/basic_concepts/view.rb +42 -0
  121. data/manual/bounding_box/bounding_box.rb +39 -0
  122. data/manual/bounding_box/bounds.rb +49 -0
  123. data/manual/bounding_box/canvas.rb +24 -0
  124. data/manual/bounding_box/creation.rb +23 -0
  125. data/manual/bounding_box/indentation.rb +46 -0
  126. data/manual/bounding_box/nesting.rb +45 -0
  127. data/manual/bounding_box/russian_boxes.rb +40 -0
  128. data/manual/bounding_box/stretchy.rb +31 -0
  129. data/manual/contents.rb +29 -0
  130. data/manual/cover.rb +39 -0
  131. data/manual/document_and_page_options/background.rb +27 -0
  132. data/manual/document_and_page_options/document_and_page_options.rb +32 -0
  133. data/manual/document_and_page_options/metadata.rb +23 -0
  134. data/manual/document_and_page_options/page_margins.rb +38 -0
  135. data/manual/document_and_page_options/page_size.rb +34 -0
  136. data/manual/document_and_page_options/print_scaling.rb +20 -0
  137. data/manual/example_helper.rb +7 -0
  138. data/manual/graphics/circle_and_ellipse.rb +22 -0
  139. data/manual/graphics/color.rb +24 -0
  140. data/manual/graphics/common_lines.rb +30 -0
  141. data/manual/graphics/fill_and_stroke.rb +42 -0
  142. data/manual/graphics/fill_rules.rb +37 -0
  143. data/manual/graphics/gradients.rb +37 -0
  144. data/manual/graphics/graphics.rb +58 -0
  145. data/manual/graphics/helper.rb +24 -0
  146. data/manual/graphics/line_width.rb +35 -0
  147. data/manual/graphics/lines_and_curves.rb +41 -0
  148. data/manual/graphics/polygon.rb +29 -0
  149. data/manual/graphics/rectangle.rb +21 -0
  150. data/manual/graphics/rotate.rb +28 -0
  151. data/manual/graphics/scale.rb +41 -0
  152. data/manual/graphics/soft_masks.rb +46 -0
  153. data/manual/graphics/stroke_cap.rb +31 -0
  154. data/manual/graphics/stroke_dash.rb +48 -0
  155. data/manual/graphics/stroke_join.rb +30 -0
  156. data/manual/graphics/translate.rb +29 -0
  157. data/manual/graphics/transparency.rb +35 -0
  158. data/manual/how_to_read_this_manual.rb +40 -0
  159. data/manual/images/absolute_position.rb +23 -0
  160. data/manual/images/fit.rb +21 -0
  161. data/manual/images/horizontal.rb +25 -0
  162. data/manual/images/images.rb +40 -0
  163. data/manual/images/plain_image.rb +18 -0
  164. data/manual/images/scale.rb +22 -0
  165. data/manual/images/vertical.rb +28 -0
  166. data/manual/images/width_and_height.rb +25 -0
  167. data/manual/layout/boxes.rb +27 -0
  168. data/manual/layout/content.rb +25 -0
  169. data/manual/layout/layout.rb +28 -0
  170. data/manual/layout/simple_grid.rb +23 -0
  171. data/manual/outline/add_subsection_to.rb +61 -0
  172. data/manual/outline/insert_section_after.rb +47 -0
  173. data/manual/outline/outline.rb +32 -0
  174. data/manual/outline/sections_and_pages.rb +67 -0
  175. data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
  176. data/manual/repeatable_content/page_numbering.rb +54 -0
  177. data/manual/repeatable_content/repeatable_content.rb +32 -0
  178. data/manual/repeatable_content/repeater.rb +55 -0
  179. data/manual/repeatable_content/stamp.rb +41 -0
  180. data/manual/security/encryption.rb +31 -0
  181. data/manual/security/permissions.rb +38 -0
  182. data/manual/security/security.rb +28 -0
  183. data/manual/table.rb +16 -0
  184. data/manual/text/alignment.rb +44 -0
  185. data/manual/text/color.rb +24 -0
  186. data/manual/text/column_box.rb +32 -0
  187. data/manual/text/fallback_fonts.rb +37 -0
  188. data/manual/text/font.rb +41 -0
  189. data/manual/text/font_size.rb +45 -0
  190. data/manual/text/font_style.rb +23 -0
  191. data/manual/text/formatted_callbacks.rb +60 -0
  192. data/manual/text/formatted_text.rb +50 -0
  193. data/manual/text/free_flowing_text.rb +51 -0
  194. data/manual/text/inline.rb +41 -0
  195. data/manual/text/kerning_and_character_spacing.rb +39 -0
  196. data/manual/text/leading.rb +25 -0
  197. data/manual/text/line_wrapping.rb +41 -0
  198. data/manual/text/paragraph_indentation.rb +34 -0
  199. data/manual/text/positioned_text.rb +38 -0
  200. data/manual/text/registering_families.rb +48 -0
  201. data/manual/text/rendering_and_color.rb +37 -0
  202. data/manual/text/right_to_left_text.rb +47 -0
  203. data/manual/text/rotation.rb +43 -0
  204. data/manual/text/single_usage.rb +37 -0
  205. data/manual/text/text.rb +73 -0
  206. data/manual/text/text_box_excess.rb +32 -0
  207. data/manual/text/text_box_extensions.rb +45 -0
  208. data/manual/text/text_box_overflow.rb +48 -0
  209. data/manual/text/utf8.rb +28 -0
  210. data/manual/text/win_ansi_charset.rb +60 -0
  211. data/prawn.gemspec +45 -0
  212. data/spec/acceptance/png.rb +25 -0
  213. data/spec/annotations_spec.rb +74 -0
  214. data/spec/bounding_box_spec.rb +510 -0
  215. data/spec/column_box_spec.rb +65 -0
  216. data/spec/data/curves.pdf +66 -0
  217. data/spec/destinations_spec.rb +15 -0
  218. data/spec/document_spec.rb +748 -0
  219. data/spec/extensions/encoding_helpers.rb +11 -0
  220. data/spec/extensions/mocha.rb +46 -0
  221. data/spec/font_metric_cache_spec.rb +52 -0
  222. data/spec/font_spec.rb +474 -0
  223. data/spec/formatted_text_arranger_spec.rb +421 -0
  224. data/spec/formatted_text_box_spec.rb +705 -0
  225. data/spec/formatted_text_fragment_spec.rb +298 -0
  226. data/spec/graphics_spec.rb +683 -0
  227. data/spec/grid_spec.rb +96 -0
  228. data/spec/image_handler_spec.rb +54 -0
  229. data/spec/images_spec.rb +153 -0
  230. data/spec/inline_formatted_text_parser_spec.rb +564 -0
  231. data/spec/jpg_spec.rb +25 -0
  232. data/spec/line_wrap_spec.rb +367 -0
  233. data/spec/measurement_units_spec.rb +25 -0
  234. data/spec/outline_spec.rb +430 -0
  235. data/spec/png_spec.rb +245 -0
  236. data/spec/reference_spec.rb +25 -0
  237. data/spec/repeater_spec.rb +160 -0
  238. data/spec/security_spec.rb +158 -0
  239. data/spec/soft_mask_spec.rb +79 -0
  240. data/spec/span_spec.rb +44 -0
  241. data/spec/spec_helper.rb +54 -0
  242. data/spec/stamp_spec.rb +160 -0
  243. data/spec/stroke_styles_spec.rb +211 -0
  244. data/spec/text_at_spec.rb +143 -0
  245. data/spec/text_box_spec.rb +1043 -0
  246. data/spec/text_rendering_mode_spec.rb +45 -0
  247. data/spec/text_spacing_spec.rb +93 -0
  248. data/spec/text_spec.rb +557 -0
  249. data/spec/text_with_inline_formatting_spec.rb +35 -0
  250. data/spec/transparency_spec.rb +91 -0
  251. data/spec/view_spec.rb +43 -0
  252. metadata +509 -0
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Rotating text is best avoided on free flowing text, so this example
4
+ # will only use the <code>text_box</code> method as we can have much more
5
+ # control over its output.
6
+ #
7
+ # To rotate text all we need to do is use the <code>:rotate</code> option
8
+ # passing an angle in degrees and an optional <code>:rotate_around</code> to
9
+ # indicate the origin of the rotation (the default is <code>:upper_left</code>).
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::ManualBuilder::Example.generate(filename) do
16
+ width = 100
17
+ height = 60
18
+ angle = 30
19
+ x = 200
20
+ y = cursor - 30
21
+
22
+ stroke_rectangle [0, y], width, height
23
+ text_box("This text was not rotated",
24
+ :at => [0, y], :width => width, :height => height)
25
+
26
+ stroke_rectangle [0, y - 100], width, height
27
+ text_box("This text was rotated around the center",
28
+ :at => [0, y - 100], :width => width, :height => height,
29
+ :rotate => angle, :rotate_around => :center)
30
+
31
+ [:lower_left, :upper_left,
32
+ :lower_right, :upper_right].each_with_index do |corner, index|
33
+
34
+ y = y - 100 if index == 2
35
+ stroke_rectangle [x + (index % 2) * 200, y], width, height
36
+ text_box("This text was rotated around the #{corner} corner.",
37
+ :at => [x + (index % 2) * 200, y],
38
+ :width => width,
39
+ :height => height,
40
+ :rotate => angle,
41
+ :rotate_around => corner)
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ #
3
+ # The PDF format has some built-in font support. If you want to use other fonts
4
+ # in Prawn you need to embed the font file.
5
+ #
6
+ # Doing this for a single font is extremely simple. Remember the Styling font
7
+ # example? Another use of the <code>font</code> method is to provide a font file
8
+ # path and the font will be embedded in the document and set as the current
9
+ # font.
10
+ #
11
+ # This is reasonable if a font is used only once, but, if a font used several
12
+ # times, providing the path each time it is used becomes cumbersome. The example
13
+ # on the next page shows a better way to deal with fonts which are used several
14
+ # times in a document.
15
+ #
16
+ require File.expand_path(File.join(File.dirname(__FILE__),
17
+ %w[.. example_helper]))
18
+
19
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
20
+ Prawn::ManualBuilder::Example.generate(filename) do
21
+ # Using a TTF font file
22
+ font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
23
+ text "Written with the DejaVu Sans TTF font."
24
+ end
25
+ move_down 20
26
+
27
+ text "Written with the default font."
28
+ move_down 20
29
+
30
+ # Using an DFONT font file
31
+ font("#{Prawn::DATADIR}/fonts/Panic+Sans.dfont") do
32
+ text "Written with the Panic Sans DFONT font"
33
+ end
34
+ move_down 20
35
+
36
+ text "Written with the default font once more."
37
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Examples for text rendering.
4
+ #
5
+ require File.expand_path(File.join(File.dirname(__FILE__),
6
+ %w[.. example_helper]))
7
+
8
+ Prawn::ManualBuilder::Example.generate("text.pdf", :page_size => "FOLIO") do
9
+
10
+ package "text" do |p|
11
+
12
+ p.section "Basics" do |s|
13
+ s.example "free_flowing_text"
14
+ s.example "positioned_text"
15
+ s.example "text_box_overflow"
16
+ s.example "text_box_excess"
17
+ s.example "column_box"
18
+ end
19
+
20
+ p.section "Styling" do |s|
21
+ s.example "font"
22
+ s.example "font_size"
23
+ s.example "font_style"
24
+ s.example "color"
25
+ s.example "alignment"
26
+ s.example "leading"
27
+ s.example "kerning_and_character_spacing"
28
+ s.example "paragraph_indentation"
29
+ s.example "rotation"
30
+ end
31
+
32
+ p.section "Advanced Styling" do |s|
33
+ s.example "inline"
34
+ s.example "formatted_text"
35
+ s.example "formatted_callbacks"
36
+ s.example "rendering_and_color"
37
+ s.example "text_box_extensions"
38
+ end
39
+
40
+ p.section "External Fonts" do |s|
41
+ s.example "single_usage"
42
+ s.example "registering_families"
43
+ end
44
+
45
+ p.section "Multilingualization" do |s|
46
+ s.example "utf8"
47
+ s.example "line_wrapping"
48
+ s.example "right_to_left_text"
49
+ s.example "fallback_fonts"
50
+ s.example "win_ansi_charset"
51
+ end
52
+
53
+ p.intro do
54
+ prose("This is probably the feature people will use the most. There is no shortage of options when it comes to text. You'll be hard pressed to find a use case that is not covered by one of the text methods and configurable options.
55
+
56
+ The examples show:")
57
+
58
+ list( "Text that flows from page to page automatically starting new pages when necessary",
59
+ "How to use text boxes and place them on specific positions",
60
+ "What to do when a text box is too small to fit its content",
61
+ "Flowing text in columns",
62
+ "How to change the text style configuring font, size, alignment and many other settings",
63
+ "How to style specific portions of a text with inline styling and formatted text",
64
+ "How to define formatted callbacks to reuse common styling definitions",
65
+ "How to use the different rendering modes available for the text methods",
66
+ "How to create your custom text box extensions",
67
+ "How to use external fonts on your pdfs",
68
+ "What happens when rendering text in different languages"
69
+ )
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Whenever the <code>text_box</code> method truncates text, this truncated bit
4
+ # is not lost, it is the method return value and we can take advantage of that.
5
+ #
6
+ # We just need to take some precautions.
7
+ #
8
+ # This example renders as much of the text as will fit in a larger font inside
9
+ # one text_box and then proceeds to render the remaining text in the default
10
+ # size in a second text_box.
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::ManualBuilder::Example.generate(filename) do
17
+ string = "This is the beginning of the text. It will be cut somewhere and " +
18
+ "the rest of the text will procede to be rendered this time by " +
19
+ "calling another method." + " . " * 50
20
+
21
+ y_position = cursor - 20
22
+ excess_text = text_box string,
23
+ :width => 300,
24
+ :height => 50,
25
+ :overflow => :truncate,
26
+ :at => [100, y_position],
27
+ :size => 18
28
+
29
+ text_box excess_text,
30
+ :width => 300,
31
+ :at => [100, y_position - 100]
32
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ #
3
+ # We've already seen one way of using text boxes with the <code>text_box</code>
4
+ # method. Turns out this method is just a convenience for using the
5
+ # <code>Prawn::Text::Box</code> class as it creates a new object and call
6
+ # <code>render</code> on it.
7
+ #
8
+ # Knowing that any extensions we add to <code>Prawn::Text::Box</code> will take
9
+ # effect when we use the <code>text_box</code> method. To add an extension all
10
+ # we need to do is append the <code>Prawn::Text::Box.extensions</code> array
11
+ # with a module.
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::ManualBuilder::Example.generate(filename) do
18
+ module TriangleBox
19
+ def available_width
20
+ height + 25
21
+ end
22
+ end
23
+
24
+ y_position = cursor - 10
25
+ width = 100
26
+ height = 100
27
+
28
+ Prawn::Text::Box.extensions << TriangleBox
29
+ stroke_rectangle([0, y_position], width, height)
30
+ text_box("A" * 100,
31
+ :at => [0, y_position],
32
+ :width => width,
33
+ :height => height)
34
+
35
+ Prawn::Text::Formatted::Box.extensions << TriangleBox
36
+ stroke_rectangle([200, y_position], width, height)
37
+ formatted_text_box([:text => "A" * 100, :color => "009900"],
38
+ :at => [200, y_position],
39
+ :width => width,
40
+ :height => height)
41
+
42
+ # Here we clear the extensions array
43
+ Prawn::Text::Box.extensions.clear
44
+ Prawn::Text::Formatted::Box.extensions.clear
45
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ #
3
+ # The <code>text_box</code> method accepts both <code>:width</code> and
4
+ # <code>:height</code> options. So what happens if the text doesn't fit the box?
5
+ #
6
+ # The default behavior is to truncate the text but this can be changed with
7
+ # the <code>:overflow</code> option. Available modes are <code>:expand</code>
8
+ # (the box will increase to fit the text) and <code>:shrink_to_fit</code>
9
+ # (the text font size will be shrunk to fit).
10
+ #
11
+ # If <code>:shrink_to_fit</code> mode is used with the
12
+ # <code>:min_font_size</code> option set, the font size will not be reduced to
13
+ # less than the value provided even if it means truncating some text.
14
+ #
15
+ # If the <code>:disable_wrap_by_char</code> is set to <code>true</code>
16
+ # then any text wrapping done while using the <code>:shrink_to_fit</code>
17
+ # mode will not break up the middle of words.
18
+ #
19
+ require File.expand_path(File.join(File.dirname(__FILE__),
20
+ %w[.. example_helper]))
21
+
22
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
23
+ Prawn::ManualBuilder::Example.generate(filename) do
24
+ string = "This is the sample text used for the text boxes. See how it " +
25
+ "behave with the various overflow options used."
26
+
27
+ text string
28
+
29
+ y_position = cursor - 20
30
+ [:truncate, :expand, :shrink_to_fit].each_with_index do |mode, i|
31
+ text_box string, :at => [i * 150, y_position],
32
+ :width => 100, :height => 50,
33
+ :overflow => mode
34
+ end
35
+
36
+ string = "If the box is too small for the text, :shrink_to_fit " +
37
+ "can render the text in a really small font size."
38
+
39
+ move_down 120
40
+ text string
41
+ y_position = cursor - 20
42
+ [nil, 8, 10, 12].each_with_index do |value, index|
43
+ text_box string, :at => [index * 150, y_position],
44
+ :width => 50, :height => 50,
45
+ :overflow => :shrink_to_fit,
46
+ :min_font_size => value
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Multilingualization isn't much of a problem on Prawn as its default encoding
4
+ # is UTF-8. The only thing you need to worry about is if the font support the
5
+ # glyphs of your language.
6
+ #
7
+ require File.expand_path(File.join(File.dirname(__FILE__),
8
+ %w[.. example_helper]))
9
+
10
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
+ Prawn::ManualBuilder::Example.generate(filename) do
12
+ text "Take this example, a simple Euro sign:"
13
+ text "€", :size => 32
14
+ move_down 20
15
+
16
+ text "This works, because € is one of the few "+
17
+ "non-ASCII glyphs supported in PDF built-in fonts."
18
+
19
+ move_down 20
20
+
21
+ text "For full internationalized text support, we need to use TTF fonts:"
22
+ move_down 20
23
+
24
+ font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
25
+ text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει."
26
+ text "There you go."
27
+ end
28
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Prints a list of all of the glyphs that can be rendered by Adobe's built
4
+ # in fonts, along with their character widths and WinAnsi codes. Be sure
5
+ # to pass these glyphs as UTF-8, and Prawn will transcode them for you.
6
+ #
7
+ require File.expand_path(File.join(File.dirname(__FILE__),
8
+ %w[.. example_helper]))
9
+
10
+ filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
+ Prawn::ManualBuilder::Example.generate(filename) do
12
+ FONT_SIZE = 9.5
13
+
14
+ x = 0
15
+ y = bounds.top
16
+
17
+ fields = [[20, :right], [8, :left], [12, :center], [30, :right], [8, :left],
18
+ [0, :left]]
19
+
20
+ font "Helvetica", :size => FONT_SIZE
21
+
22
+ move_down 30
23
+ text "(See next page for WinAnsi table)", :align => :center
24
+ start_new_page
25
+
26
+ Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
27
+ next if name == ".notdef"
28
+ y -= FONT_SIZE
29
+
30
+ if y < FONT_SIZE
31
+ y = bounds.top - FONT_SIZE
32
+ x += 170
33
+ end
34
+
35
+ code = "%d." % index
36
+ char = index.chr
37
+
38
+ width = 1000 * width_of(char, :size => FONT_SIZE) / FONT_SIZE
39
+ size = "%d" % width
40
+
41
+ data = [code, nil, char, size, nil, name]
42
+ dx = x
43
+ fields.zip(data).each do |(total_width, align), field|
44
+ if field
45
+ width = width_of(field, :size => FONT_SIZE)
46
+
47
+ case align
48
+ when :left then offset = 0
49
+ when :right then offset = total_width - width
50
+ when :center then offset = (total_width - width)/2
51
+ end
52
+
53
+ text_box(field.force_encoding("windows-1252").encode("UTF-8"),
54
+ :at => [dx + offset, y])
55
+ end
56
+
57
+ dx += total_width
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,45 @@
1
+ basedir = File.expand_path(File.dirname(__FILE__))
2
+
3
+ require "#{basedir}/lib/prawn/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "prawn-git"
7
+ spec.version = Prawn::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.summary = "A fast and nimble PDF generator for Ruby"
10
+ spec.files = Dir.glob("{examples,lib,spec,manual}/**/**/*") +
11
+ Dir.glob("data/{encodings,images,pdfs}/*") +
12
+ Dir.glob("data/fonts/{MustRead.html,*.afm}") +
13
+ ["data/shift_jis_text.txt"] +
14
+ ["Rakefile", "prawn.gemspec", "Gemfile",
15
+ "COPYING", "LICENSE", "GPLv2", "GPLv3",
16
+ ".yardopts"]
17
+ spec.require_path = "lib"
18
+ spec.required_ruby_version = '>= 2.0.0'
19
+ spec.required_rubygems_version = ">= 1.3.6"
20
+
21
+ spec.test_files = Dir[ "spec/*_spec.rb" ]
22
+ spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
23
+ spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
24
+ spec.rubyforge_project = "prawn"
25
+ spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
26
+
27
+ spec.add_dependency('ttfunk', '~> 1.4.0')
28
+ spec.add_dependency('pdf-core', "~> 0.5.1")
29
+
30
+ spec.add_development_dependency('pdf-inspector', '~> 1.2.0')
31
+ spec.add_development_dependency('yard')
32
+ spec.add_development_dependency('rspec', '2.14.1')
33
+ spec.add_development_dependency('mocha')
34
+ spec.add_development_dependency('rake')
35
+ spec.add_development_dependency('simplecov')
36
+ spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0")
37
+ spec.add_development_dependency('pdf-reader', '~>1.2')
38
+ spec.add_development_dependency('rubocop', '0.28.0')
39
+ spec.add_development_dependency('code_statistics', '0.2.13')
40
+
41
+ spec.homepage = "http://prawn.majesticseacreature.com"
42
+ spec.description = <<END_DESC
43
+ Prawn is a fast, tiny, and nimble PDF generator for Ruby
44
+ END_DESC
45
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../../lib/prawn"
4
+
5
+ images = [
6
+ ["Type 0", "#{Prawn::BASEDIR}/data/images/web-links.png"],
7
+ ["Type 2", "#{Prawn::BASEDIR}/data/images/ruport.png"],
8
+ ["Type 3", "#{Prawn::BASEDIR}/data/images/indexed_color.png"],
9
+ ["Type 4", "#{Prawn::BASEDIR}/data/images/page_white_text.png"],
10
+ ["Type 6", "#{Prawn::BASEDIR}/data/images/dice.png"],
11
+ ]
12
+
13
+ Prawn::Document.generate("png_types.pdf", :page_size => "A5") do
14
+ images.each do |header, file|
15
+ start_new_page unless header.include?("0")
16
+
17
+ fill_color "FF0000"
18
+
19
+ fill_rectangle bounds.top_left, bounds.width, bounds.height
20
+ text header
21
+
22
+ image file, :at => [50,450]
23
+ end
24
+ end
25
+