prawn 0.1.0 → 0.1.1

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.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'spec/rake/spectask'
4
4
  require "rake/rdoctask"
5
5
  require "rake/gempackagetask"
6
6
 
7
- PRAWN_VERSION = "0.1.0"
7
+ PRAWN_VERSION = "0.1.1"
8
8
 
9
9
  task :default => [:spec]
10
10
 
@@ -33,21 +33,22 @@ end
33
33
  desc "run all examples, and then diff them against reference PDFs"
34
34
  task :examples do
35
35
  mkdir_p "output"
36
- examples = Dir["examples/*.rb"].reject { |e| e =~ /bench|sjis/ }
36
+ examples = Dir["examples/*.rb"].reject { |e| e =~ /bench/ }
37
37
  t = Time.now
38
- puts "Running Examples"
38
+ puts "Running Examples, skipping benchmark"
39
39
  examples.each { |file| `ruby -Ilib #{file}` }
40
40
  puts "Ran in #{Time.now - t} s"
41
41
  `mv *.pdf output`
42
- =begin
43
- # Has some issues
44
- puts "Checking for differences..."
45
- output = Dir["output/*.pdf"]
46
- ref = Dir["reference_pdfs/*.pdf"]
47
- output.zip(ref).each do |o,r|
48
- system "diff -q #{o} #{r}"
49
- end
50
- =end
42
+
43
+ unless RUBY_VERSION < "1.9"
44
+ puts "Checking for differences..."
45
+ output = Dir["output/*.pdf"]
46
+ ref = Dir["reference_pdfs/*.pdf"]
47
+ output.zip(ref).each do |o,r|
48
+ system "diff -q #{o} #{r}"
49
+ end
50
+ end
51
+
51
52
  end
52
53
 
53
54
  spec = Gem::Specification.new do |spec|
@@ -3,10 +3,21 @@
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  require "prawn"
5
5
  require "rubygems"
6
- require "fastercsv"
7
-
8
- headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
6
+
7
+ headers, body = nil, nil
8
+
9
+ ruby_18 do
10
+ require "fastercsv"
11
+ headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
12
+ end
9
13
 
14
+ ruby_19 do
15
+ require "csv"
16
+ headers, *body = CSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
17
+ headers.map! { |e| e.encode("UTF-8") }
18
+ body.map! { |e| e.map! { |x| x.encode("UTF-8") } }
19
+ end
20
+
10
21
  Prawn::Document.generate("fancy_table.pdf", :page_layout => :landscape) do
11
22
 
12
23
  mask(:y) { table body, :headers => headers,
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require "prawn"
5
+
6
+ Prawn::Document.generate("image-flow.pdf", :page_layout => :landscape) do
7
+ stef = "#{Prawn::BASEDIR}/data/images/stef.jpg"
8
+
9
+ text "o hai"
10
+
11
+ image stef
12
+
13
+ text "flowing text"
14
+
15
+ image stef, :position => :center
16
+
17
+ text "beneath images"
18
+
19
+ image stef, :position => :right
20
+
21
+ text "again"
22
+
23
+ image stef, :position => :left
24
+
25
+ text "and again"
26
+
27
+ image stef, :position => 50
28
+
29
+ end
@@ -1,47 +1,50 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
- require "prawn"
5
- require "rubygems"
6
- require "ruport"
4
+ require "prawn"
5
+
6
+ ruby_18 do
7
+ require "rubygems"
8
+ require "ruport"
9
+
10
+ module Ruport
11
+ class Formatter
12
+ class PrawnPDF < Ruport::Formatter
13
+ renders :pdf, :for => Ruport::Controller::Table
14
+
15
+ def document
16
+ @document ||= (options.document || Prawn::Document.new)
17
+ end
18
+
19
+ def table_body
20
+ data.map { |e| e.to_a }
21
+ end
22
+
23
+ build :table_header do
24
+ @headers = options.headers || data.column_names
25
+ end
26
+
27
+ build :table_body do
28
+ document.table table_body,
29
+ :headers => @headers,
30
+ :row_colors => :pdf_writer,
31
+ :position => :center,
32
+ :font_size => 10,
33
+ :vertical_padding => 2,
34
+ :horizontal_padding => 5
35
+ end
36
+
37
+ def finalize
38
+ output << document.render
39
+ end
7
40
 
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
41
  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
42
  end
40
43
  end
41
- end
42
44
 
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
45
+ if __FILE__ == $PROGRAM_NAME
46
+ t = Table("#{Prawn::BASEDIR}/examples/addressbook.csv")
47
+ headers = t.column_names.map { |c| c.capitalize }
48
+ t.save_as "addressbook_ruport.pdf", :headers => headers
49
+ end
47
50
  end
@@ -10,10 +10,12 @@
10
10
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
11
11
  require "prawn"
12
12
 
13
- datafile = File.join(File.dirname(__FILE__), "..", "data", "shift_jis_text.txt")
14
- sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
13
+ ruby_19 do
14
+ datafile = File.join(File.dirname(__FILE__), "..", "data", "shift_jis_text.txt")
15
+ sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
15
16
 
16
- Prawn::Document.generate("sjis.pdf") do
17
- font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
18
- text sjis_str
17
+ Prawn::Document.generate("sjis.pdf") do
18
+ font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
19
+ text sjis_str
20
+ end
19
21
  end
@@ -1,4 +1,10 @@
1
1
  # encoding: utf-8
2
+ #
3
+ # table.rb : Simple table drawing functionality
4
+ #
5
+ # Copyright June 2008, Gregory Brown. All Rights Reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
2
8
 
3
9
  module Prawn
4
10
  class Document
@@ -159,10 +159,15 @@ module Prawn
159
159
  end
160
160
 
161
161
  def metrics_path
162
- @metrics_path ||= (ENV['METRICS'] ||
163
- "/usr/lib/afm:/usr/local/lib/afm:"+
164
- "/usr/openwin/lib/fonts/afm/:"+
165
- "#{Prawn::BASEDIR+'/data/fonts/'}:.").split(':')
162
+ if m = ENV['METRICS']
163
+ @metrics_path ||= m.split(':')
164
+ else
165
+ @metrics_path ||= [
166
+ "/usr/lib/afm",
167
+ "/usr/local/lib/afm",
168
+ "/usr/openwin/lib/fonts/afm/",
169
+ Prawn::BASEDIR+'/data/fonts/','.']
170
+ end
166
171
  end
167
172
 
168
173
  def has_kerning_data?
@@ -1,5 +1,11 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
+
4
+ # cell.rb : Table support functions
5
+ #
6
+ # Copyright June 2008, Gregory Brown. All Rights Reserved.
7
+ #
8
+ # This is free software. Please see the LICENSE and COPYING files for details.
3
9
  module Prawn
4
10
 
5
11
  class Document
@@ -18,10 +18,11 @@ module Prawn
18
18
  # <tt>filename</tt>:: the path to the file to be embedded
19
19
  #
20
20
  # Options:
21
- # <tt>:at</tt>:: the location of the top left corner of the image [current position]
21
+ # <tt>:at</tt>:: the location of the top left corner of the image.
22
+ # <tt>:position/tt>::
22
23
  # <tt>:height</tt>:: the height of the image [actual height of the image]
23
24
  # <tt>:width</tt>:: the width of the image [actual width of the image]
24
- # <tt>:scale</tt>:: scale the dimensions of the image proportionally
25
+ # <tt>:scale</tt>:: scale the dimensions of the image proportionally
25
26
  #
26
27
  # Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do
27
28
  # pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
@@ -66,9 +67,14 @@ module Prawn
66
67
  image_registry[image_sha1] = {:obj => image_obj, :info => info}
67
68
  end
68
69
 
69
- # find where the image will be placed and how big it will be
70
- x,y = translate(options[:at])
70
+ # find where the image will be placed and how big it will be
71
71
  w,h = calc_image_dimensions(info, options)
72
+ if options[:at]
73
+ x,y = translate(options[:at])
74
+ else
75
+ x,y = image_position(w,h,options)
76
+ move_text_position h
77
+ end
72
78
 
73
79
  # add a reference to the image object to the current page
74
80
  # resource list and give it a label
@@ -80,7 +86,25 @@ module Prawn
80
86
  add_content instruct % [ w, h, x, y - h, label ]
81
87
  end
82
88
 
83
- private
89
+ private
90
+
91
+ def image_position(w,h,options)
92
+ options[:position] ||= :left
93
+ case options[:position]
94
+ when :left
95
+ x,y = bounds.absolute_left, self.y
96
+ when :center
97
+ x = bounds.absolute_left + (bounds.width - w) / 2.0
98
+ y = self.y
99
+ when :right
100
+ x,y = bounds.absolute_right - w, self.y
101
+ when Numeric
102
+ x = options[:position] + bounds.absolute_left
103
+ y = self.y
104
+ end
105
+
106
+ return [x,y]
107
+ end
84
108
 
85
109
  def build_jpg_object(data, jpg)
86
110
  color_space = case jpg.channels
@@ -28,7 +28,7 @@ describe "When reading an RGB PNG file" do
28
28
 
29
29
  it "should read the image data chunk correctly" do
30
30
  png = Prawn::Images::PNG.new(@img_data)
31
- data = File.open(@data_filename) { |f| f.read }
31
+ data = File.open(@data_filename, "rb") { |f| f.read }
32
32
  png.img_data.should eql(data)
33
33
  end
34
34
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: prawn
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2008-08-03 00:00:00 -04:00
6
+ version: 0.1.1
7
+ date: 2008-08-08 00:00:00 -04:00
8
8
  summary: A fast and nimble PDF generator for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -31,9 +31,7 @@ authors:
31
31
  files:
32
32
  - examples/addressbook.csv
33
33
  - examples/alignment.rb
34
- - examples/bounding_boxes.pdf
35
34
  - examples/bounding_boxes.rb
36
- - examples/canvas.pdf
37
35
  - examples/canvas.rb
38
36
  - examples/cell.rb
39
37
  - examples/currency.csv
@@ -41,10 +39,9 @@ files:
41
39
  - examples/fancy_table.rb
42
40
  - examples/font_size.rb
43
41
  - examples/hexagon.rb
44
- - examples/image.pdf
45
42
  - examples/image.rb
46
43
  - examples/image2.rb
47
- - examples/inline_styles.pdf
44
+ - examples/image_flow.rb
48
45
  - examples/kerning.rb
49
46
  - examples/line.rb
50
47
  - examples/multi_page_layout.rb
@@ -1,62 +0,0 @@
1
- %PDF-1.3
2
- ����
3
- 1 0 obj
4
- << /Creator <feff0050007200610077006e>
5
- /Producer <feff0050007200610077006e>
6
- >>
7
- endobj
8
- 2 0 obj
9
- << /Type /Pages
10
- /Count 1
11
- /Kids [5 0 R]
12
- >>
13
- endobj
14
- 3 0 obj
15
- << /Pages 2 0 R
16
- /Type /Catalog
17
- >>
18
- endobj
19
- 4 0 obj
20
- << /Length 354
21
- >>
22
- stream
23
- 0.000 0.000 0.000 rg
24
- 0.000 0.000 0.000 RG
25
- q
26
- 436.000 436.000 m
27
- 436.000 491.228 391.228 536.000 336.000 536.000 c
28
- 280.772 536.000 236.000 491.228 236.000 436.000 c
29
- 236.000 380.772 280.772 336.000 336.000 336.000 c
30
- 391.228 336.000 436.000 380.772 436.000 436.000 c
31
- 336.000 436.000 m
32
- 236.000 536.000 m
33
- 436.000 336.000 l
34
- 436.000 536.000 m
35
- 236.000 336.000 l
36
- Q
37
-
38
- endstream
39
- endobj
40
- 5 0 obj
41
- << /Type /Page
42
- /Parent 2 0 R
43
- /MediaBox [0 0 612.0 792.0]
44
- /Contents 4 0 R
45
- >>
46
- endobj
47
- xref
48
- 0 6
49
- 0000000000 65535 f
50
- 0000000014 00000 n
51
- 0000000108 00000 n
52
- 0000000165 00000 n
53
- 0000000214 00000 n
54
- 0000000619 00000 n
55
- trailer
56
- << /Root 3 0 R
57
- /Info 1 0 R
58
- /Size 6
59
- >>
60
- startxref
61
- 710
62
- %%EOF
@@ -1,81 +0,0 @@
1
- %PDF-1.3
2
- ����
3
- 1 0 obj
4
- << /Creator <507261776e>
5
- /Producer <507261776e>
6
- >>
7
- endobj
8
- 2 0 obj
9
- << /Type /Pages
10
- /Count 1
11
- /Kids [5 0 R]
12
- >>
13
- endobj
14
- 3 0 obj
15
- << /Type /Catalog
16
- /Pages 2 0 R
17
- >>
18
- endobj
19
- 4 0 obj
20
- << /Length 304
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
- 0 780.612 Td
30
-
31
- [<54686973207465> 30 <78742073686f756c642061707065617220617420746865206162736f6c75746520746f70206c656674>] TJ
32
-
33
-
34
- ET
35
-
36
- 0.000 0.000 m
37
- 612.000 792.000 l
38
- S
39
- Q
40
-
41
- endstream
42
- endobj
43
- 5 0 obj
44
- << /Resources << /Font << /F1 7 0 R
45
- >>
46
- >>
47
- /Type /Page
48
- /Parent 2 0 R
49
- /ProcSet 6 0 R
50
- /MediaBox [0 0 612.0 792.0]
51
- /Contents 4 0 R
52
- >>
53
- endobj
54
- 6 0 obj
55
- [/PDF /Text]
56
- endobj
57
- 7 0 obj
58
- << /BaseFont /Helvetica
59
- /Type /Font
60
- /Subtype /Type1
61
- /Encoding /MacRomanEncoding
62
- >>
63
- endobj
64
- xref
65
- 0 8
66
- 0000000000 65535 f
67
- 0000000014 00000 n
68
- 0000000080 00000 n
69
- 0000000137 00000 n
70
- 0000000186 00000 n
71
- 0000000541 00000 n
72
- 0000000686 00000 n
73
- 0000000714 00000 n
74
- trailer
75
- << /Info 1 0 R
76
- /Size 8
77
- /Root 3 0 R
78
- >>
79
- startxref
80
- 812
81
- %%EOF
Binary file
@@ -1,117 +0,0 @@
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