prawn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. data/COPYING +340 -0
  2. data/LICENSE +56 -0
  3. data/README +30 -0
  4. data/Rakefile +83 -0
  5. data/data/fonts/Activa.ttf +0 -0
  6. data/data/fonts/Chalkboard.ttf +0 -0
  7. data/data/fonts/Courier-Bold.afm +342 -0
  8. data/data/fonts/Courier-BoldOblique.afm +342 -0
  9. data/data/fonts/Courier-Oblique.afm +342 -0
  10. data/data/fonts/Courier.afm +342 -0
  11. data/data/fonts/DejaVuSans.ttf +0 -0
  12. data/data/fonts/Dustismo_Roman.ttf +0 -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/fonts/comicsans.ttf +0 -0
  25. data/data/fonts/gkai00mp.ttf +0 -0
  26. data/data/images/dice.png +0 -0
  27. data/data/images/pigs.jpg +0 -0
  28. data/data/images/ruport.png +0 -0
  29. data/data/images/ruport_data.dat +0 -0
  30. data/data/images/ruport_transparent.png +0 -0
  31. data/data/images/stef.jpg +0 -0
  32. data/data/shift_jis_text.txt +1 -0
  33. data/examples/addressbook.csv +6 -0
  34. data/examples/alignment.rb +16 -0
  35. data/examples/bounding_boxes.pdf +62 -0
  36. data/examples/bounding_boxes.rb +30 -0
  37. data/examples/canvas.pdf +81 -0
  38. data/examples/canvas.rb +12 -0
  39. data/examples/cell.rb +27 -0
  40. data/examples/currency.csv +1834 -0
  41. data/examples/curves.rb +10 -0
  42. data/examples/fancy_table.rb +48 -0
  43. data/examples/font_size.rb +19 -0
  44. data/examples/hexagon.rb +14 -0
  45. data/examples/image.pdf +0 -0
  46. data/examples/image.rb +23 -0
  47. data/examples/image2.rb +13 -0
  48. data/examples/inline_styles.pdf +117 -0
  49. data/examples/kerning.rb +27 -0
  50. data/examples/line.rb +31 -0
  51. data/examples/multi_page_layout.rb +14 -0
  52. data/examples/on_page_start.rb +17 -0
  53. data/examples/page_geometry.rb +28 -0
  54. data/examples/polygons.rb +16 -0
  55. data/examples/ruport_formatter.rb +47 -0
  56. data/examples/ruport_helpers.rb +17 -0
  57. data/examples/russian_boxes.rb +34 -0
  58. data/examples/simple_text.rb +15 -0
  59. data/examples/simple_text_ttf.rb +16 -0
  60. data/examples/sjis.rb +19 -0
  61. data/examples/table.rb +45 -0
  62. data/examples/table_bench.rb +92 -0
  63. data/examples/text_flow.rb +65 -0
  64. data/examples/utf8.rb +12 -0
  65. data/lib/prawn.rb +33 -0
  66. data/lib/prawn/compatibility.rb +33 -0
  67. data/lib/prawn/document.rb +334 -0
  68. data/lib/prawn/document/bounding_box.rb +253 -0
  69. data/lib/prawn/document/page_geometry.rb +78 -0
  70. data/lib/prawn/document/table.rb +253 -0
  71. data/lib/prawn/document/text.rb +346 -0
  72. data/lib/prawn/errors.rb +33 -0
  73. data/lib/prawn/font.rb +5 -0
  74. data/lib/prawn/font/cmap.rb +59 -0
  75. data/lib/prawn/font/metrics.rb +414 -0
  76. data/lib/prawn/font/wrapping.rb +45 -0
  77. data/lib/prawn/graphics.rb +285 -0
  78. data/lib/prawn/graphics/cell.rb +226 -0
  79. data/lib/prawn/images.rb +241 -0
  80. data/lib/prawn/images/jpg.rb +43 -0
  81. data/lib/prawn/images/png.rb +178 -0
  82. data/lib/prawn/pdf_object.rb +64 -0
  83. data/lib/prawn/reference.rb +47 -0
  84. data/spec/bounding_box_spec.rb +120 -0
  85. data/spec/box_calculation_spec.rb +17 -0
  86. data/spec/document_spec.rb +152 -0
  87. data/spec/graphics_spec.rb +250 -0
  88. data/spec/images_spec.rb +42 -0
  89. data/spec/jpg_spec.rb +25 -0
  90. data/spec/metrics_spec.rb +60 -0
  91. data/spec/pdf_object_spec.rb +102 -0
  92. data/spec/png_spec.rb +35 -0
  93. data/spec/reference_spec.rb +29 -0
  94. data/spec/spec_helper.rb +29 -0
  95. data/spec/table_spec.rb +145 -0
  96. data/spec/text_spec.rb +190 -0
  97. data/vendor/font_ttf/ttf.rb +20 -0
  98. data/vendor/font_ttf/ttf/datatypes.rb +189 -0
  99. data/vendor/font_ttf/ttf/encodings.rb +140 -0
  100. data/vendor/font_ttf/ttf/exceptions.rb +28 -0
  101. data/vendor/font_ttf/ttf/file.rb +290 -0
  102. data/vendor/font_ttf/ttf/fontchunk.rb +77 -0
  103. data/vendor/font_ttf/ttf/table/cmap.rb +408 -0
  104. data/vendor/font_ttf/ttf/table/cvt.rb +49 -0
  105. data/vendor/font_ttf/ttf/table/fpgm.rb +48 -0
  106. data/vendor/font_ttf/ttf/table/gasp.rb +88 -0
  107. data/vendor/font_ttf/ttf/table/glyf.rb +452 -0
  108. data/vendor/font_ttf/ttf/table/head.rb +86 -0
  109. data/vendor/font_ttf/ttf/table/hhea.rb +96 -0
  110. data/vendor/font_ttf/ttf/table/hmtx.rb +98 -0
  111. data/vendor/font_ttf/ttf/table/kern.rb +186 -0
  112. data/vendor/font_ttf/ttf/table/loca.rb +75 -0
  113. data/vendor/font_ttf/ttf/table/maxp.rb +81 -0
  114. data/vendor/font_ttf/ttf/table/name.rb +222 -0
  115. data/vendor/font_ttf/ttf/table/os2.rb +172 -0
  116. data/vendor/font_ttf/ttf/table/post.rb +120 -0
  117. data/vendor/font_ttf/ttf/table/prep.rb +27 -0
  118. data/vendor/font_ttf/ttf/table/vhea.rb +45 -0
  119. data/vendor/font_ttf/ttf/table/vmtx.rb +36 -0
  120. metadata +180 -0
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ pdf = Prawn::Document.new
7
+ pdf.move_to [100,100]
8
+ pdf.stroke_curve_to [50,50],:bounds => [[20,90], [90,90]]
9
+ pdf.fill_circle_at [200,200], :radius => 10
10
+ pdf.render_file "curves.pdf"
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+ require "rubygems"
6
+ require "fastercsv"
7
+
8
+ headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
9
+
10
+ Prawn::Document.generate("fancy_table.pdf", :page_layout => :landscape) do
11
+
12
+ mask(:y) { table body, :headers => headers,
13
+ :align => :center,
14
+ :border_style => :grid }
15
+
16
+ table [["This is", "A Test" ],
17
+ [ Prawn::Graphics::Cell.new( :text => "Of tables",
18
+ :background_color => "ffccff" ),
19
+ "Drawn Side"], ["By side", "and stuff" ]],
20
+ :position => 600,
21
+ :headers => ["Col A", "Col B"],
22
+ :border => 1,
23
+ :vertical_padding => 5,
24
+ :horizontal_padding => 3,
25
+ :font_size => 10,
26
+ :row_colors => :pdf_writer,
27
+ :widths => { 1 => 50 }
28
+
29
+ move_down 150
30
+
31
+ table [%w[1 2 3],%w[4 5 6],%w[7 8 9]],
32
+ :position => :center,
33
+ :border => 0,
34
+ :font_size => 40
35
+
36
+ cell [500,300],
37
+ :text => "This free flowing textbox shows how you can use Prawn's "+
38
+ "cells outside of a table with ease. Think of a 'cell' as " +
39
+ "simply a limited purpose bounding box that is meant for laying " +
40
+ "out blocks of text and optionally placing a border around it",
41
+ :width => 225, :padding => 10, :border => 2
42
+
43
+ font_size! 24
44
+ cell [50,75],
45
+ :text => "This document demonstrates a number of Prawn's table features",
46
+ :border_style => :no_top, # :all, :no_bottom, :sides
47
+ :horizontal_padding => 5
48
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
7
+ font 'Helvetica'
8
+ font_size! 16
9
+
10
+ text 'Font at 16 point'
11
+
12
+ font_size 9 do
13
+ text 'Font at 9 point'
14
+ text 'Font at manual override 20 point', :size => 20
15
+ text 'Font at 9 point'
16
+ end
17
+
18
+ text 'Font at 16 point'
19
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ pdf = Prawn::Document.new
7
+
8
+ pdf.fill_color "ff0000"
9
+ pdf.fill_polygon [100, 250], [200, 300], [300, 250],
10
+ [300, 150], [200, 100], [100, 150]
11
+
12
+ pdf.render_file "hexagon.pdf"
13
+
14
+
Binary file
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ Prawn::Document.generate("image.pdf", :page_layout => :landscape) do
7
+ pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
8
+ image pigs, :at => [50,450], :scale => 0.5
9
+
10
+ stef = "#{Prawn::BASEDIR}/data/images/stef.jpg"
11
+ image stef, :at => [75, 75]
12
+
13
+ stef = "#{Prawn::BASEDIR}/data/images/stef.jpg"
14
+ image stef, :at => [500, 400], :width => 200, :height => 200
15
+
16
+ text "Please enjoy the pigs", :size => 36, :at => [200,15]
17
+
18
+ ruport = "#{Prawn::BASEDIR}/data/images/ruport.png"
19
+ image ruport, :at => [400,200], :width => 150
20
+
21
+ ruport = "#{Prawn::BASEDIR}/data/images/ruport_transparent.png"
22
+ image ruport, :at => [50,525]
23
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do
7
+ pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
8
+ image pigs, :at => [50,450], :width => 450
9
+
10
+ dice = "#{Prawn::BASEDIR}/data/images/dice.png"
11
+ image dice, :at => [50, 450], :scale => 0.75
12
+ end
13
+
@@ -0,0 +1,117 @@
1
+ %PDF-1.3
2
+ ����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Count 1
10
+ /Kids [5 0 R]
11
+ /Type /Pages
12
+ >>
13
+ endobj
14
+ 3 0 obj
15
+ << /Pages 2 0 R
16
+ /Type /Catalog
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 644
21
+ >>
22
+ stream
23
+ 0.000 0.000 0.000 rg
24
+ 0.000 0.000 0.000 RG
25
+ q
26
+
27
+ BT
28
+ /F1 12 Tf
29
+ 36 744.612 Td
30
+
31
+ [<5468697320697320736f6d6520706c61696e207465> 30 <7874>] TJ
32
+
33
+
34
+ ET
35
+
36
+
37
+ BT
38
+ /F2 12 Tf
39
+ 36 730.74 Td
40
+
41
+ [<54686973207465> 30 <7874206973206974616c6963>] TJ
42
+
43
+
44
+ ET
45
+
46
+
47
+ BT
48
+ /F2 12 Tf
49
+ 36 716.868 Td
50
+
51
+ [<54686973207465> 30 <787420697320626f6c64>] TJ
52
+
53
+
54
+ ET
55
+
56
+
57
+ BT
58
+ /F2 12 Tf
59
+ 36 702.996 Td
60
+
61
+ [<54686973206973206f7264696e6172> -30 <79207465> 30 <787420616761696e>] TJ
62
+
63
+
64
+ ET
65
+
66
+ Q
67
+
68
+ endstream
69
+ endobj
70
+ 5 0 obj
71
+ << /Contents 4 0 R
72
+ /ProcSet 6 0 R
73
+ /Resources << /Font << /F2 8 0 R
74
+ /F1 7 0 R
75
+ >>
76
+ >>
77
+ /Parent 2 0 R
78
+ /Type /Page
79
+ /MediaBox [0 0 612.0 792.0]
80
+ >>
81
+ endobj
82
+ 6 0 obj
83
+ [/PDF /Text]
84
+ endobj
85
+ 7 0 obj
86
+ << /BaseFont /Helvetica
87
+ /Subtype /Type1
88
+ /Encoding /MacRomanEncoding
89
+ /Type /Font
90
+ >>
91
+ endobj
92
+ 8 0 obj
93
+ << /BaseFont /Helvetica-Oblique
94
+ /Subtype /Type1
95
+ /Encoding /MacRomanEncoding
96
+ /Type /Font
97
+ >>
98
+ endobj
99
+ xref
100
+ 0 9
101
+ 0000000000 65535 f
102
+ 0000000014 00000 n
103
+ 0000000108 00000 n
104
+ 0000000165 00000 n
105
+ 0000000214 00000 n
106
+ 0000000909 00000 n
107
+ 0000001064 00000 n
108
+ 0000001092 00000 n
109
+ 0000001190 00000 n
110
+ trailer
111
+ << /Size 9
112
+ /Root 3 0 R
113
+ /Info 1 0 R
114
+ >>
115
+ startxref
116
+ 1296
117
+ %%EOF
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require "prawn"
3
+
4
+ Prawn::Document.generate "kerning.pdf" do
5
+ text "To kern?", :at => [200,720], :size => 24, :kerning => true
6
+ text "To not kern?", :at => [200,690], :size => 24, :kerning => false
7
+
8
+ move_down 100
9
+
10
+ pad(30) do
11
+ text "To kern and wrap. " * 5, :size => 24, :kerning => true
12
+ end
13
+
14
+ text "To not kern and wrap. " * 5, :size => 24, :kerning => false
15
+
16
+ font "#{Prawn::BASEDIR}/data/fonts/Dustismo_Roman.ttf"
17
+
18
+ text "To kern?", :at => [200,660], :size => 24, :kerning => true
19
+ text "To not kern?", :at => [200,630], :size => 24, :kerning => false
20
+
21
+ pad(30) do
22
+ text "To kern and wrap. " * 5, :size => 24, :kerning => true
23
+ end
24
+
25
+ text "To not kern and wrap. " * 5, :size => 24, :kerning => false
26
+
27
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ pdf = Prawn::Document.new
7
+ pdf.line_width = 10
8
+
9
+ [[100,741,100,641],
10
+ [100,691,150,691],
11
+ [150,741,150,641],
12
+ [200,741,200,641],
13
+ [100,600,100,500],
14
+ [100,600,150,550],
15
+ [100,550,150,550],
16
+ [175,600,175,500],
17
+ [175,600,225,550],
18
+ [175,550,225,550],
19
+ [175,550,225,500],
20
+ [275,600,250,500],
21
+ [275,600,300,500],
22
+ [250,550,300,550],
23
+ [315,600,350,500],
24
+ [350,500,365,550],
25
+ [365,550,380,500],
26
+ [380,500,415,600],
27
+ [430,600,430,500],
28
+ [430,600,465,500],
29
+ [465,600,465,500]].each { |points| pdf.stroke_line(*points) }
30
+
31
+ pdf.render_file "lines.pdf"
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ Prawn::Document.generate("multi-layout.pdf", :page_layout => :landscape) do |pdf|
7
+ pdf.text "This is on a landscaped page"
8
+ pdf.start_new_page(:layout => :portrait)
9
+ pdf.text "This is on a portrait page"
10
+ pdf.start_new_page(:size => "LEGAL")
11
+ pdf.text "This is on legal paper size"
12
+ pdf.start_new_page(:left_margin => 150, :right_margin => 150)
13
+ pdf.text "This page has very wide left and right margins, causing a squeeze"
14
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ page_start = lambda do |doc|
7
+ doc.stroke_line [100,100], [300,300]
8
+ end
9
+
10
+ pdf = Prawn::Document.new(:on_page_start => page_start)
11
+
12
+ pdf.stroke_line [0,0], [100,100]
13
+ pdf.start_new_page
14
+ pdf.stroke_line [300,300],[400,400]
15
+ pdf.start_new_page
16
+ pdf.render_file "page_start_hooks.pdf"
17
+
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ def pdf(*options)
7
+ Prawn::Document.new(*options)
8
+ end
9
+
10
+ # defaults to portrait and US letter
11
+ portrait_letter = pdf
12
+ portrait_letter.render_file "portrait_letter.pdf"
13
+
14
+ landscape_letter = pdf(:page_layout => :landscape)
15
+ landscape_letter.render_file "landscape_letter.pdf"
16
+
17
+ portrait_legal = pdf(:page_size => "LEGAL")
18
+ portrait_legal.render_file "portrait_legal.pdf"
19
+
20
+ landscape_legal = pdf(:page_size => "LEGAL", :page_layout => :landscape)
21
+ landscape_legal.render_file "landscape_legal.pdf"
22
+
23
+ portrait_a4 = pdf(:page_size => "A4")
24
+ portrait_a4.render_file "portrait_a4.pdf"
25
+
26
+ landscape_a4 = pdf(:page_size => "A4", :page_layout => :landscape)
27
+ landscape_a4.render_file("landscape_a4.pdf")
28
+
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ pdf = Prawn::Document.new
7
+
8
+ 10.times do |i|
9
+ pdf.stroke_polygon [ 50 + i*25, 50 + i*25],
10
+ [100 + i*25, 50 + i*25],
11
+ [100 + i*25, 100 + i*25]
12
+ pdf.stroke_rectangle [0,600], 5*i, 10*i
13
+ end
14
+
15
+ pdf.render_file "pretty_polygons.pdf"
16
+
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+ require "rubygems"
6
+ require "ruport"
7
+
8
+ module Ruport
9
+ class Formatter
10
+ class PrawnPDF < Ruport::Formatter
11
+ renders :pdf, :for => Ruport::Controller::Table
12
+
13
+ def document
14
+ @document ||= (options.document || Prawn::Document.new)
15
+ end
16
+
17
+ def table_body
18
+ data.map { |e| e.to_a }
19
+ end
20
+
21
+ build :table_header do
22
+ @headers = options.headers || data.column_names
23
+ end
24
+
25
+ build :table_body do
26
+ document.table table_body,
27
+ :headers => @headers,
28
+ :row_colors => :pdf_writer,
29
+ :position => :center,
30
+ :font_size => 10,
31
+ :vertical_padding => 2,
32
+ :horizontal_padding => 5
33
+ end
34
+
35
+ def finalize
36
+ output << document.render
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+ if __FILE__ == $PROGRAM_NAME
44
+ t = Table("#{Prawn::BASEDIR}/examples/addressbook.csv")
45
+ headers = t.column_names.map { |c| c.capitalize }
46
+ t.save_as "addressbook_ruport.pdf", :headers => headers
47
+ end