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,24 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example demonstrates using the :style option for Document#text.
4
+ # If you are working with TTF fonts, you'll want to check out the
5
+ # documentation for Document#font_families and register your fonts with it.
6
+ #
7
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
8
+
9
+ Prawn::Document.generate("family_style.pdf") do
10
+ ["Courier","Helvetica","Times-Roman"].each do |f|
11
+ [:bold,:bold_italic,:italic,:normal].each do |s|
12
+ font f, :style => s
13
+ text "I'm writing in #{f} (#{s})"
14
+ end
15
+ end
16
+
17
+ font "Helvetica"
18
+
19
+ text "Normal"
20
+ text "Bold", :style => :bold
21
+ text "Bold Italic", :style => :bold_italic
22
+ text "Italic", :style => :italic
23
+ text "Normal"
24
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example is a demonstration of how Prawn does its text positioning,
4
+ # meant to assist those that need to do advanced positioning calculations.
5
+ # Run the example for a clearer picture of how things work
6
+ #
7
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
8
+
9
+ Prawn::Document.generate('font_calculations.pdf') do
10
+
11
+ def demonstration
12
+ font_size 12
13
+ move_down 10
14
+
15
+ stroke_horizontal_rule
16
+
17
+ text "When using flowing text, Prawn will position text\n" +
18
+ "starting font.ascender below the baseline, and leave\n" +
19
+ "the y-cursor at the baseline of the next line of text"
20
+
21
+ stroke_horizontal_rule
22
+
23
+ move_down 20
24
+
25
+ bl = y - bounds.absolute_bottom
26
+
27
+ stroke_horizontal_rule
28
+ draw_text "When using text positioned with :at, the baseline is used", :at => [0, bl]
29
+
30
+ draw_text "(and the Y-cursor is not moved)", :at => [350, bl]
31
+
32
+ colors = { :ascender => "ff0000",
33
+ :descender => "00ff00",
34
+ :line_gap => "0000ff",
35
+ :font_height => "005500" }
36
+
37
+
38
+ pad(20) do
39
+ text "Calculations Demo", :size => 16
40
+ end
41
+
42
+ fill_color colors[:ascender]
43
+ text "ASCENDER"
44
+
45
+ fill_color colors[:descender]
46
+ text "DESCENDER"
47
+
48
+ fill_color colors[:line_gap]
49
+ text "LINEGAP"
50
+
51
+ fill_color colors[:font_height]
52
+ text "FONT_HEIGHT"
53
+
54
+ fill_color "000000"
55
+ font_size 16
56
+
57
+ move_down 40
58
+
59
+ bl = y - bounds.absolute_bottom
60
+ draw_text "The quick brown fox jumps over the lazy dog.", :at => [0, bl]
61
+
62
+ stroke_color colors[:ascender]
63
+ stroke_line [0, bl], [0, bl + font.ascender]
64
+ stroke_line [0, bl + font.ascender], [bounds.width, bl + font.ascender]
65
+
66
+ stroke_color colors[:descender]
67
+ stroke_line [0,bl], [0, bl - font.descender]
68
+ stroke_line [0, bl - font.descender], [bounds.width, bl - font.descender]
69
+
70
+ stroke_color colors[:line_gap]
71
+ stroke_line [0, bl - font.descender], [0,bl - font.descender - font.line_gap]
72
+ stroke_line [0, bl - font.descender - font.line_gap],
73
+ [bounds.width,bl - font.descender - font.line_gap]
74
+
75
+ stroke_color colors[:font_height]
76
+ stroke_line [bounds.width, bl + font.ascender],
77
+ [bounds.width, bl - font.descender - font.line_gap]
78
+
79
+ stroke_color "000000"
80
+ fill_color "000000"
81
+ end
82
+
83
+ text "Using AFM", :size => 20
84
+ demonstration
85
+
86
+ move_down 75
87
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
88
+ text "Using TTF", :size => 20
89
+ demonstration
90
+
91
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example shows the many ways of setting font sizes in Prawn
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
8
+
9
+ # Explicit global changes
10
+ font 'Helvetica'
11
+ self.font_size = 16
12
+
13
+ text 'Font at 16 point'
14
+
15
+ # Transactional changes rolled back after block exit
16
+ font_size 9 do
17
+ text 'Font at 9 point'
18
+ # single line changes, not persisted.
19
+ text 'Font at manual override 20 point', :size => 20
20
+ text 'Font at 9 point'
21
+ end
22
+
23
+ # Transactional changes rolled back after block exit on full fonts.
24
+ font("Times-Roman", :style => :italic, :size => 12) do
25
+ text "Font in times at 12"
26
+ font_size(16) { text "Font in Times at 16" }
27
+ end
28
+
29
+ text 'Font at 16 point'
30
+
31
+ font "Courier", :size => 40
32
+ text "40 pt!"
33
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ #
3
+
4
+ require 'examples/example_helper'
5
+
6
+ Prawn::Document.generate("hyphenation.pdf") do
7
+ def get_string(i)
8
+ case i
9
+ when 0
10
+ text = "this­is­soft­hyphenated­text­" * 30
11
+ when 1
12
+ text = "this-is-hard-hyphenated-text-" * 30
13
+ when 2
14
+ text = "this­-is­-soft­-hard­-hyphenated­-text­-" * 30
15
+ end
16
+ end
17
+
18
+ options = {
19
+ :width => bounds.width * 0.3,
20
+ :height => bounds.width * 0.3,
21
+ :overflow => :ellipses,
22
+ :at => [0, 0],
23
+ :align => :left,
24
+ :document => self
25
+ }
26
+
27
+ stroke_color("555555")
28
+ 3.times do |i|
29
+ options[:at][0] = (bounds.width - options[:width]) * 0.5 * i
30
+ options[:at][1] = bounds.height * 0.5 + options[:height] + 50
31
+ box = Prawn::Text::Box.new(get_string(i), options)
32
+ box.render
33
+ end
34
+
35
+
36
+ font("#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf")
37
+
38
+ stroke_color("555555")
39
+ 3.times do |i|
40
+ options[:at][0] = (bounds.width - options[:width]) * 0.5 * i
41
+ options[:at][1] = bounds.height * 0.5 - 50
42
+ box = Prawn::Text::Box.new(get_string(i), options)
43
+ box.render
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Example of two ways of indenting paragraphs
4
+ #
5
+ #
6
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
7
+
8
+ Prawn::Document.generate "indent_paragraphs.pdf" do |pdf|
9
+ hello = "hello " * 50
10
+ world = "world " * 50
11
+ pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
12
+
13
+ pdf.move_cursor_to(pdf.font.height)
14
+ pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
15
+
16
+ pdf.move_cursor_to(pdf.font.height * 3)
17
+ pdf.text(hello + "\n" + world, :indent_paragraphs => 60)
18
+
19
+ # can also indent using a non-breaking space
20
+ nbsp = Prawn::Text::NBSP
21
+ pdf.text("\n" * 10 + hello + "\n#{nbsp * 10}" + world)
22
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This example shows how to use inline formatting
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate("inline_format.pdf") do |pdf|
8
+
9
+ pdf.text("hello <strikethrough><b>world\nhow <i>are</i></b> you?</strikethrough> world, <u>how are you</u> now?",
10
+ :inline_format => true)
11
+ pdf.text("<font size='14'>left: </font>" + "hello <b>world <font name='Times-Roman' size='28'>how</font> <i>are</i></b> you? <font size='14'><b>Goodbye.</b></font> " * 8,
12
+ :inline_format => true)
13
+ pdf.text("right: " + "hello <b>world how <i>are</i></b> you? " * 2,
14
+ :inline_format => true,
15
+ :align => :right)
16
+ pdf.text("center: " + "hello <b>world how <i>are</i></b> you? " * 2,
17
+ :inline_format => true,
18
+ :align => :center)
19
+ pdf.text("\njustify: " + "hello <b>world <i>goodbye</i></b> " * 12 + "the end ",
20
+ :inline_format => true,
21
+ :align => :justify)
22
+ pdf.text("\njustify: " + "hello world goodbye " * 12 + "the end ",
23
+ :inline_format => true,
24
+ :align => :justify)
25
+ pdf.text("\njustify: " + "hello world goodbye " * 12 + "the end ",
26
+ :align => :justify)
27
+
28
+
29
+ pdf.text("<color rgb='00ff00'>link: <font size='24' character_spacing='7.5'>please make</font> <color rgb='#0000ff'><u><link href='http://wiki.github.com/sandal/prawn/'>this</link></u></color> clickable.</color> Here we have A<color rgb='#0000ff'><sup><link href='http://wiki.github.com/sandal/prawn/'>superscript</link></sup></color> link and A<color rgb='#0000ff'><sub><link href='http://wiki.github.com/sandal/prawn/'> subscript</link></sub></color> link.",
30
+ :inline_format => true)
31
+
32
+ pdf.text("<color c='100' m='0' y='0' k='0'><font size='24'>CMYK</font></color>",
33
+ :inline_format => true)
34
+
35
+ file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
36
+ pdf.font_families["Action Man"] = {
37
+ :normal => { :file => file, :font => "ActionMan" },
38
+ :italic => { :file => file, :font => "ActionMan-Italic" },
39
+ :bold => { :file => file, :font => "ActionMan-Bold" },
40
+ :bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
41
+ }
42
+
43
+ pdf.font("Action Man")
44
+ pdf.text("\nhello <b>world\nhow <i>are</i></b> you?",
45
+ :inline_format => true)
46
+
47
+
48
+ pdf.font("Helvetica")
49
+
50
+
51
+
52
+ class Highlight
53
+ def initialize(options)
54
+ @color = options[:color]
55
+ @document = options[:document]
56
+ end
57
+
58
+ def render_behind(fragment)
59
+ original_color = @document.fill_color
60
+ @document.fill_color = @color
61
+ @document.fill_rectangle(fragment.top_left,
62
+ fragment.width,
63
+ fragment.height)
64
+ @document.fill_color = original_color
65
+ end
66
+ end
67
+
68
+ class FragmentBorder
69
+ def initialize(options)
70
+ @radius = options[:radius]
71
+ @connect_corners = options[:connect_corners]
72
+ @document = options[:document]
73
+ end
74
+
75
+ def render_in_front(fragment)
76
+ box = fragment.bounding_box
77
+ if @connect_corners
78
+ @document.stroke_polygon(fragment.top_left, fragment.top_right,
79
+ fragment.bottom_right, fragment.bottom_left)
80
+ end
81
+ @document.stroke_circle_at(fragment.top_left, :radius => @radius)
82
+ @document.stroke_circle_at(fragment.top_right, :radius => @radius)
83
+ @document.stroke_circle_at(fragment.bottom_right, :radius => @radius)
84
+ @document.stroke_circle_at(fragment.bottom_left, :radius => @radius)
85
+ end
86
+ end
87
+
88
+ highlight_callback = Highlight.new(:color => 'ffff00', :document => pdf)
89
+ border_callback = FragmentBorder.new(:radius => 2.5,
90
+ :connect_corners => true,
91
+ :document => pdf)
92
+ pdf.formatted_text([
93
+ { :text => "\n" },
94
+ { :text => "hello ",
95
+ :callback => highlight_callback },
96
+ { :text => "world",
97
+ :size => 24,
98
+ :character_spacing => 0,
99
+ :callback => [highlight_callback, border_callback] },
100
+ { :text => " hello" }
101
+ ], :indent_paragraphs => 40, :character_spacing => -2)
102
+ end
103
+
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstration of enabling and disabling kerning support
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate "kerning.pdf" do
8
+ draw_text "To kern?", :at => [200,720], :size => 24, :kerning => true
9
+ draw_text "To not kern?", :at => [200,690], :size => 24, :kerning => false
10
+
11
+ move_down 100
12
+
13
+ pad(30) do
14
+ text "To kern and wrap. " * 5, :size => 24, :kerning => true
15
+ end
16
+
17
+ text "To not kern and wrap. " * 5, :size => 24, :kerning => false
18
+
19
+ font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
20
+
21
+ draw_text "To kern?", :at => [200,660], :size => 24, :kerning => true
22
+ draw_text "To not kern?", :at => [200,630], :size => 24, :kerning => false
23
+
24
+ pad(30) do
25
+ text "To kern and wrap. " * 5, :size => 24, :kerning => true
26
+ end
27
+
28
+ text "To not kern and wrap. " * 5, :size => 24, :kerning => false
29
+
30
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Demonstrates transformations
4
+ #
5
+ require "#{File.dirname(__FILE__)}/../example_helper.rb"
6
+
7
+ Prawn::Document.generate "rotated_text.pdf" do |pdf|
8
+ pdf.line_width = 1
9
+ width = 150
10
+ height = 200
11
+ half_width = width / 2
12
+ half_height = height / 2
13
+ angle = 30
14
+
15
+
16
+ # AROUND THE CENTER
17
+
18
+ x = pdf.bounds.width / 2 - half_width
19
+ y = pdf.bounds.height / 2 + half_height
20
+
21
+ pdf.stroke_rectangle([x, y], width, height)
22
+ pdf.rotate(angle, :origin => [x + half_width, y - half_height]) do
23
+ pdf.stroke_rectangle([x, y], width, height)
24
+ end
25
+ pdf.text_box("rotated around the center " * 10,
26
+ :at => [x, y],
27
+ :width => width,
28
+ :height => height,
29
+ :rotate => angle,
30
+ :rotate_around => :center)
31
+
32
+
33
+ # AROUND THE UPPER_LEFT_CORNER
34
+
35
+ x = pdf.bounds.width - width
36
+ y = height
37
+
38
+ pdf.stroke_rectangle([x, y], width, height)
39
+ pdf.rotate(angle, :origin => [x, y]) do
40
+ pdf.stroke_rectangle([x, y], width, height)
41
+ end
42
+ pdf.text_box("rotated around upper left corner " * 10,
43
+ :at => [x, y],
44
+ :width => width,
45
+ :height => height,
46
+ :rotate => angle)
47
+
48
+
49
+ # AROUND THE UPPER_RIGHT_CORNER
50
+
51
+ x = 0
52
+ y = height
53
+
54
+ pdf.stroke_rectangle([x, y], width, height)
55
+ pdf.rotate(angle, :origin => [x + width, y]) do
56
+ pdf.stroke_rectangle([x, y], width, height)
57
+ end
58
+ pdf.text_box("rotated around upper right corner " * 10,
59
+ :at => [x, y],
60
+ :width => width,
61
+ :height => height,
62
+ :rotate => angle,
63
+ :rotate_around => :upper_right)
64
+
65
+
66
+ # AROUND THE LOWER_RIGHT_CORNER
67
+
68
+ x = 0
69
+ y = pdf.bounds.height
70
+
71
+ pdf.stroke_rectangle([x, y], width, height)
72
+ pdf.rotate(angle, :origin => [x + width, y - height]) do
73
+ pdf.stroke_rectangle([x, y], width, height)
74
+ end
75
+ pdf.text_box("rotated around lower right corner " * 10,
76
+ :at => [x, y],
77
+ :width => width,
78
+ :height => height,
79
+ :rotate => angle,
80
+ :rotate_around => :lower_right)
81
+
82
+
83
+ # AROUND THE LOWER_LEFT_CORNER
84
+
85
+ x = pdf.bounds.width - width
86
+ y = pdf.bounds.height
87
+
88
+ pdf.stroke_rectangle([x, y], width, height)
89
+ pdf.rotate(angle, :origin => [x, y - height]) do
90
+ pdf.stroke_rectangle([x, y], width, height)
91
+ end
92
+ pdf.text_box("rotated around lower left corner " * 10,
93
+ :at => [x, y],
94
+ :width => width,
95
+ :height => height,
96
+ :rotate => angle,
97
+ :rotate_around => :lower_left)
98
+ end