pdf-wrapper 0.4.1 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -0
- data/README.rdoc +8 -14
- data/Rakefile +6 -67
- data/lib/pdf/wrapper.rb +12 -1
- data/lib/pdf/wrapper/images.rb +0 -6
- data/lib/pdf/wrapper/text.rb +0 -3
- data/{specs → spec}/data/google.png +0 -0
- data/{specs → spec}/data/iso-2022-jp.txt +0 -0
- data/{specs → spec}/data/orc.svg +0 -0
- data/{specs → spec}/data/shift_jis.txt +0 -0
- data/{specs → spec}/data/shipsail.jpg +0 -0
- data/{specs → spec}/data/stef.jpg +0 -0
- data/{specs → spec}/data/utf8-long.pdf +0 -0
- data/{specs → spec}/data/utf8-long.txt +0 -0
- data/{specs → spec}/data/utf8.txt +0 -0
- data/{specs → spec}/data/windmill.jpg +0 -0
- data/{specs → spec}/data/zits.gif +0 -0
- data/{specs → spec}/graphics_spec.rb +13 -13
- data/{specs → spec}/image_spec.rb +6 -6
- data/{specs → spec}/spec_helper.rb +4 -10
- data/{specs → spec}/tables_spec.rb +32 -32
- data/{specs → spec}/text_spec.rb +23 -23
- data/{specs → spec}/wrapper_spec.rb +39 -39
- metadata +198 -29
- data/lib/pdf/wrapper/loading.rb +0 -64
- data/specs/load_spec.rb +0 -33
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
v0.4.4 (19th November 2010)
|
2
|
+
* packaging improvements, switch to bundler for development
|
3
|
+
* require ruby-gnome2 0.90.5 or greater. The gnome2 gems are still
|
4
|
+
fairly new, Kou seems to be improving them rapidly
|
5
|
+
|
6
|
+
v0.4.3 (25th October 2010)
|
7
|
+
* simplify the way I require the various gnome2 gems for maximum bundler
|
8
|
+
compatibility
|
9
|
+
|
10
|
+
v0.4.2 (24th October 2010)
|
11
|
+
* Siwtch back to using the ruby-gnome2 gems to satisfy dependencies
|
12
|
+
* the latest versions can be installed without root permissions
|
13
|
+
|
1
14
|
v0.4.1 (12th October 2010)
|
2
15
|
* Stop using the ruby-gnome2 gems to satisfy dependencies
|
3
16
|
* They can't be installed by non-root users, so don't play nice
|
data/README.rdoc
CHANGED
@@ -50,21 +50,15 @@ James Healy <jimmy@deefa.com>
|
|
50
50
|
|
51
51
|
= Dependencies
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
* ruby/gdkpixbuf[http://ruby-gnome2.sourceforge.jp/] (optional, required for GIF/JPG support)
|
57
|
-
* ruby/poppler[http://ruby-gnome2.sourceforge.jp/] (optional, required for embedding PDF images)
|
58
|
-
|
59
|
-
These are all ruby bindings to C libraries. On Debian/Ubuntu based systems
|
60
|
-
(which I develop on) you can get them by running:
|
61
|
-
|
62
|
-
aptitude install libcairo-ruby libpango1-ruby librsvg2-ruby libpoppler-glib-ruby
|
53
|
+
As of September 2010 all these dependencies are satisfied by gems. All of them are bindings
|
54
|
+
to C libraries, so you will need the libraries and headers installed on your system
|
55
|
+
before installing them.
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
ruby/
|
67
|
-
|
57
|
+
* ruby/cairo[http://cairographics.org/rcairo/]
|
58
|
+
* ruby/pango[http://ruby-gnome2.sourceforge.jp/]
|
59
|
+
* ruby/rsvg2[http://ruby-gnome2.sourceforge.jp/]
|
60
|
+
* ruby/gdkpixbuf[http://ruby-gnome2.sourceforge.jp/]
|
61
|
+
* ruby/poppler[http://ruby-gnome2.sourceforge.jp/]
|
68
62
|
|
69
63
|
= Compatibility
|
70
64
|
|
data/Rakefile
CHANGED
@@ -1,45 +1,20 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
2
5
|
require 'rake'
|
3
|
-
require 'rake/clean'
|
4
6
|
require 'rake/rdoctask'
|
5
|
-
require '
|
6
|
-
require "rake/gempackagetask"
|
7
|
-
require 'spec/rake/spectask'
|
7
|
+
require 'rspec/core/rake_task'
|
8
8
|
require 'roodi'
|
9
9
|
require 'roodi_task'
|
10
10
|
|
11
|
-
|
12
|
-
PKG_VERSION = "0.4.1"
|
13
|
-
PKG_NAME = "pdf-wrapper"
|
14
|
-
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
15
|
-
|
16
11
|
desc "Default Task"
|
17
12
|
task :default => [ :spec ]
|
18
13
|
|
19
14
|
# run all rspecs
|
20
15
|
desc "Run all rspec files"
|
21
|
-
|
22
|
-
|
23
|
-
t.spec_files = ['specs/load_spec.rb','specs/image_spec.rb','specs/graphics_spec.rb','specs/tables_spec.rb','specs/text_spec.rb','specs/wrapper_spec.rb']
|
24
|
-
t.spec_opts = ['-c']
|
25
|
-
t.libs << File.dirname(__FILE__) + "/specs"
|
26
|
-
end
|
27
|
-
|
28
|
-
# generate specdocs
|
29
|
-
desc "Generate Specdocs"
|
30
|
-
Spec::Rake::SpecTask.new("specdocs") do |t|
|
31
|
-
t.spec_files = FileList['specs/**/*.rb']
|
32
|
-
t.spec_opts = ["--format", "rdoc"]
|
33
|
-
t.out = (ENV['CC_BUILD_ARTIFACTS'] || 'doc') + '/specdoc.rd'
|
34
|
-
end
|
35
|
-
|
36
|
-
# generate failing spec report
|
37
|
-
desc "Generate failing spec report"
|
38
|
-
Spec::Rake::SpecTask.new("spec_report") do |t|
|
39
|
-
t.spec_files = FileList['specs/**/*.rb']
|
40
|
-
t.spec_opts = ["--format", "html", "--diff"]
|
41
|
-
t.out = (ENV['CC_BUILD_ARTIFACTS'] || 'doc') + '/spec_report.html'
|
42
|
-
t.fail_on_error = false
|
16
|
+
RSpec::Core::RakeTask.new("spec") do |t|
|
17
|
+
t.rspec_opts = ['-c']
|
43
18
|
end
|
44
19
|
|
45
20
|
# Genereate the RDoc documentation
|
@@ -54,40 +29,4 @@ Rake::RDocTask.new("doc") do |rdoc|
|
|
54
29
|
rdoc.options << "--inline-source"
|
55
30
|
end
|
56
31
|
|
57
|
-
desc "Publish rdocs to rubyforge"
|
58
|
-
task :publish_rdoc => [ :doc ] do
|
59
|
-
rdoc_dir = File.dirname(__FILE__) + "/doc/rdoc/"
|
60
|
-
`scp -r #{rdoc_dir} yob@rubyforge.org:/var/www/gforge-projects/pdf-wrapper/`
|
61
|
-
end
|
62
|
-
|
63
|
-
# a gemspec for packaging this library
|
64
|
-
spec = Gem::Specification.new do |spec|
|
65
|
-
spec.name = PKG_NAME
|
66
|
-
spec.version = PKG_VERSION
|
67
|
-
spec.platform = Gem::Platform::RUBY
|
68
|
-
spec.summary = "A PDF generating library built on top of cairo"
|
69
|
-
spec.files = Dir.glob("{examples,lib,specs}/**/**/*") + ["Rakefile"]
|
70
|
-
spec.require_path = "lib"
|
71
|
-
spec.has_rdoc = true
|
72
|
-
spec.extra_rdoc_files = %w{README.rdoc CHANGELOG TODO}
|
73
|
-
spec.rdoc_options << '--title' << 'PDF::Wrapper Documentation' << '--main' << 'README.rdoc' << '-q'
|
74
|
-
spec.author = "James Healy"
|
75
|
-
spec.homepage = "http://pdf-wrapper.rubyforge.org/"
|
76
|
-
spec.email = "jimmy@deefa.com"
|
77
|
-
spec.rubyforge_project = "pdf-wrapper"
|
78
|
-
spec.description = "A unicode aware PDF writing library that uses the ruby bindings to various c libraries ( like cairo, pango, poppler and rsvg ) to do the heavy lifting."
|
79
|
-
spec.add_dependency("cairo", "~>1.8")
|
80
|
-
#spec.add_dependency("pango")
|
81
|
-
#spec.add_dependency("poppler")
|
82
|
-
#spec.add_dependency("gdkpixbuf")
|
83
|
-
# TODO - add rsvg2
|
84
|
-
end
|
85
|
-
|
86
|
-
# package the library into a gem
|
87
|
-
desc "Generate a gem for pdf-wrapper"
|
88
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
89
|
-
pkg.need_zip = true
|
90
|
-
pkg.need_tar = true
|
91
|
-
end
|
92
|
-
|
93
32
|
RoodiTask.new 'roodi', ['lib/**/*.rb']
|
data/lib/pdf/wrapper.rb
CHANGED
@@ -8,7 +8,6 @@ require 'fileutils'
|
|
8
8
|
|
9
9
|
require "pdf/wrapper/graphics"
|
10
10
|
require "pdf/wrapper/images"
|
11
|
-
require "pdf/wrapper/loading"
|
12
11
|
require "pdf/wrapper/text_cell"
|
13
12
|
require "pdf/wrapper/text_image_cell"
|
14
13
|
require "pdf/wrapper/table"
|
@@ -16,6 +15,18 @@ require "pdf/wrapper/text"
|
|
16
15
|
require "pdf/wrapper/page"
|
17
16
|
|
18
17
|
require 'cairo'
|
18
|
+
require 'pango'
|
19
|
+
require 'gdk_pixbuf2'
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'gtk2'
|
23
|
+
rescue Gtk::InitError
|
24
|
+
# ignore this error, it's thrown when gtk2 is loaded with no xsession available.
|
25
|
+
# as advised at http://www.ruby-forum.com/topic/182949
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'poppler'
|
29
|
+
require 'rsvg2'
|
19
30
|
|
20
31
|
module PDF
|
21
32
|
# Create PDF files by using the cairo and pango libraries.
|
data/lib/pdf/wrapper/images.rb
CHANGED
@@ -125,7 +125,6 @@ module PDF
|
|
125
125
|
|
126
126
|
def draw_pdf(filename, opts = {})
|
127
127
|
# based on a similar function in rabbit. Thanks Kou.
|
128
|
-
load_libpoppler
|
129
128
|
x, y = current_point
|
130
129
|
page = Poppler::Document.new(filename).get_page(0)
|
131
130
|
w, h = page.size
|
@@ -141,7 +140,6 @@ module PDF
|
|
141
140
|
|
142
141
|
def draw_pixbuf(filename, opts = {})
|
143
142
|
# based on a similar function in rabbit. Thanks Kou.
|
144
|
-
load_libpixbuf
|
145
143
|
x, y = current_point
|
146
144
|
pixbuf = Gdk::Pixbuf.new(filename)
|
147
145
|
if opts[:rotate]
|
@@ -181,7 +179,6 @@ module PDF
|
|
181
179
|
|
182
180
|
def draw_svg(filename, opts = {})
|
183
181
|
# based on a similar function in rabbit. Thanks Kou.
|
184
|
-
load_librsvg
|
185
182
|
x, y = current_point
|
186
183
|
handle = RSVG::Handle.new_from_file(filename)
|
187
184
|
width, height = calc_image_dimensions(opts[:width], opts[:height], handle.width, handle.height, opts[:proportional])
|
@@ -200,18 +197,15 @@ module PDF
|
|
200
197
|
|
201
198
|
case detect_image_type(filename)
|
202
199
|
when :pdf then
|
203
|
-
load_libpoppler
|
204
200
|
page = Poppler::Document.new(filename).get_page(0)
|
205
201
|
return page.size
|
206
202
|
when :png then
|
207
203
|
img_surface = Cairo::ImageSurface.from_png(filename)
|
208
204
|
return img_surface.width, img_surface.height
|
209
205
|
when :svg then
|
210
|
-
load_librsvg
|
211
206
|
handle = RSVG::Handle.new_from_file(filename)
|
212
207
|
return handle.width, handle.height
|
213
208
|
else
|
214
|
-
load_libpixbuf
|
215
209
|
begin
|
216
210
|
pixbuf = Gdk::Pixbuf.new(filename)
|
217
211
|
return pixbuf.width, pixbuf.height
|
data/lib/pdf/wrapper/text.rb
CHANGED
File without changes
|
File without changes
|
data/{specs → spec}/data/orc.svg
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
describe "The PDF::Wrapper class" do
|
6
6
|
|
7
7
|
before(:each) { create_pdf }
|
8
8
|
|
9
|
-
|
9
|
+
it "should be able to draw a single line onto the canvas" do
|
10
10
|
x0 = y0 = 100
|
11
11
|
x1 = y1 = 200
|
12
12
|
@pdf.line(x0,y0,x1,y1)
|
@@ -22,7 +22,7 @@ context "The PDF::Wrapper class" do
|
|
22
22
|
receiver.first_occurance_of(:append_line)[:args].should eql([x1, 641.89])
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should be able to draw a single line onto the canvas with a width of 5" do
|
26
26
|
x0 = y0 = 100
|
27
27
|
x1 = y1 = 200
|
28
28
|
width = 5
|
@@ -41,9 +41,9 @@ context "The PDF::Wrapper class" do
|
|
41
41
|
receiver.first_occurance_of(:append_line)[:args].should eql([x1, 641.89])
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
it "should be able to draw a cubic bezier spline onto the canvas"
|
45
45
|
|
46
|
-
|
46
|
+
it "should be able to draw an empty rectangle onto the canvas" do
|
47
47
|
x = y = 100
|
48
48
|
w = h = 200
|
49
49
|
@pdf.rectangle(x,y,w,h)
|
@@ -60,7 +60,7 @@ context "The PDF::Wrapper class" do
|
|
60
60
|
callbacks.shift[:args].should eql([100, 741.89, 200, -200])
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
it "should be able to draw an empty rectangle onto the canvas with a line width of 5" do
|
64
64
|
x = y = 100
|
65
65
|
w = h = 200
|
66
66
|
width = 5
|
@@ -82,7 +82,7 @@ context "The PDF::Wrapper class" do
|
|
82
82
|
callbacks.shift[:args].should eql([100, 741.89, 200, -200])
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
it "should be able to draw a filled rectangle onto the canvas"
|
86
86
|
=begin
|
87
87
|
do
|
88
88
|
x = y = 100
|
@@ -97,7 +97,7 @@ context "The PDF::Wrapper class" do
|
|
97
97
|
end
|
98
98
|
=end
|
99
99
|
|
100
|
-
|
100
|
+
it "should be able to draw an empty rounded rectangle onto the canvas"
|
101
101
|
=begin
|
102
102
|
do
|
103
103
|
x = y = 100
|
@@ -113,7 +113,7 @@ context "The PDF::Wrapper class" do
|
|
113
113
|
end
|
114
114
|
=end
|
115
115
|
|
116
|
-
|
116
|
+
it "should be able to draw an empty rounded rectangle onto the canvas with a line width of 5"
|
117
117
|
=begin
|
118
118
|
do
|
119
119
|
x = y = 100
|
@@ -130,7 +130,7 @@ context "The PDF::Wrapper class" do
|
|
130
130
|
end
|
131
131
|
=end
|
132
132
|
|
133
|
-
|
133
|
+
it "should be able to draw a filled rounded rectangle onto the canvas"
|
134
134
|
=begin
|
135
135
|
do
|
136
136
|
x = y = 100
|
@@ -146,7 +146,7 @@ context "The PDF::Wrapper class" do
|
|
146
146
|
end
|
147
147
|
=end
|
148
148
|
|
149
|
-
|
149
|
+
it "should be able to draw an empty circle onto the canvas"
|
150
150
|
=begin
|
151
151
|
do
|
152
152
|
x = 100
|
@@ -162,7 +162,7 @@ context "The PDF::Wrapper class" do
|
|
162
162
|
end
|
163
163
|
=end
|
164
164
|
|
165
|
-
|
165
|
+
it "should be able to draw an empty circle onto the canvas with a line width of 5"
|
166
166
|
=begin
|
167
167
|
do
|
168
168
|
x = 100
|
@@ -179,7 +179,7 @@ context "The PDF::Wrapper class" do
|
|
179
179
|
end
|
180
180
|
=end
|
181
181
|
|
182
|
-
|
182
|
+
it "should be able to draw a filled circle onto the canvas"
|
183
183
|
=begin
|
184
184
|
do
|
185
185
|
x = 100
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
describe "The PDF::Wrapper class" do
|
6
6
|
|
7
7
|
before(:each) { create_pdf }
|
8
8
|
|
9
|
-
|
9
|
+
it "should be able to detect the filetype of an image" do
|
10
10
|
@pdf.detect_image_type(File.dirname(__FILE__) + "/data/google.png").should eql(:png)
|
11
11
|
@pdf.detect_image_type(File.dirname(__FILE__) + "/data/zits.gif").should eql(:gif)
|
12
12
|
@pdf.detect_image_type(File.dirname(__FILE__) + "/data/orc.svg").should eql(:svg)
|
@@ -14,7 +14,7 @@ context "The PDF::Wrapper class" do
|
|
14
14
|
@pdf.detect_image_type(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql(:jpg)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
it "should be able to determine image dimensions correctly" do
|
18
18
|
@pdf.image_dimensions(File.dirname(__FILE__) + "/data/google.png").should eql([166,55])
|
19
19
|
@pdf.image_dimensions(File.dirname(__FILE__) + "/data/zits.gif").should eql([525,167])
|
20
20
|
@pdf.image_dimensions(File.dirname(__FILE__) + "/data/orc.svg").should eql([734, 772])
|
@@ -22,19 +22,19 @@ context "The PDF::Wrapper class" do
|
|
22
22
|
@pdf.image_dimensions(File.dirname(__FILE__) + "/data/shipsail.jpg").should eql([192,128])
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should be able to calculate scaled image dimensions correctly" do
|
26
26
|
@pdf.calc_image_dimensions(100, 100, 200, 200).should eql([100.0,100.0])
|
27
27
|
@pdf.calc_image_dimensions(nil, nil, 200, 200).should eql([200.0,200.0])
|
28
28
|
@pdf.calc_image_dimensions(150, 200, 200, 200, true).should eql([150.0,150.0])
|
29
29
|
@pdf.calc_image_dimensions(300, 250, 200, 200, true).should eql([250.0,250.0])
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "should be able to draw rotated images correctly" do
|
33
33
|
@pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :clockwise)
|
34
34
|
@pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :counterclockwise)
|
35
35
|
@pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :upsidedown)
|
36
36
|
@pdf.image(File.dirname(__FILE__) + "/data/shipsail.jpg", :rotate => :none)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
it "should be able to draw an image with padding correctly"
|
40
40
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
4
6
|
|
5
7
|
require 'pdf/wrapper'
|
6
|
-
require 'tempfile'
|
7
|
-
require 'rubygems'
|
8
|
-
|
9
|
-
gem "pdf-reader", ">=0.7.3"
|
10
|
-
|
11
8
|
require 'pdf/reader'
|
9
|
+
require 'tempfile'
|
12
10
|
|
13
11
|
def create_pdf
|
14
12
|
@output = StringIO.new
|
@@ -26,10 +24,6 @@ class PDF::Wrapper
|
|
26
24
|
public :draw_png
|
27
25
|
public :draw_svg
|
28
26
|
public :image_dimensions
|
29
|
-
public :load_librsvg
|
30
|
-
public :load_libpixbuf
|
31
|
-
public :load_libpango
|
32
|
-
public :load_libpoppler
|
33
27
|
public :user_x_to_device_x
|
34
28
|
public :user_y_to_device_y
|
35
29
|
public :device_x_to_user_x
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
describe PDF::Wrapper do
|
6
6
|
|
7
7
|
before(:each) { create_pdf }
|
8
8
|
|
9
|
-
|
9
|
+
it "should be able to draw a table on the canvas using an array of data" do
|
10
10
|
data = [%w{data1 data2}, %w{data3 data4}]
|
11
11
|
@pdf.table(data)
|
12
12
|
@pdf.finish
|
@@ -20,7 +20,7 @@ context PDF::Wrapper do
|
|
20
20
|
receiver.content.first.include?("data4").should be_true
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "should be able to draw a table on the canvas using an array of TextCells" do
|
24
24
|
data = [
|
25
25
|
[ PDF::Wrapper::TextCell.new("data1"), PDF::Wrapper::TextCell.new("data2")],
|
26
26
|
[ PDF::Wrapper::TextCell.new("data3"), PDF::Wrapper::TextCell.new("data4")]
|
@@ -37,7 +37,7 @@ context PDF::Wrapper do
|
|
37
37
|
receiver.content.first.include?("data4").should be_true
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
it "should be able to draw a table on the canvas using an array of TextImageCells" do
|
41
41
|
filename = File.dirname(__FILE__) + "/data/orc.svg"
|
42
42
|
data = [
|
43
43
|
[ "data1", PDF::Wrapper::TextImageCell.new("data2", filename, 100, 100)],
|
@@ -55,7 +55,7 @@ context PDF::Wrapper do
|
|
55
55
|
receiver.content.first.include?("data4").should be_true
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
it "should be able to draw a table on the canvas using a PDF::Wrapper::Table object" do
|
59
59
|
table = PDF::Wrapper::Table.new do |t|
|
60
60
|
t.data = [%w{data1 data2}, %w{data3 data4}]
|
61
61
|
end
|
@@ -72,7 +72,7 @@ context PDF::Wrapper do
|
|
72
72
|
receiver.content.first.include?("data4").should be_true
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
it "should be able to draw a table on the canvas with no headings" do
|
76
76
|
|
77
77
|
table = PDF::Wrapper::Table.new do |t|
|
78
78
|
t.data = (1..50).collect { [1,2] }
|
@@ -90,7 +90,7 @@ context PDF::Wrapper do
|
|
90
90
|
receiver.content.first.include?("col2").should be_false
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
it "should be able to draw a table on the canvas with headers on the first page only" do
|
94
94
|
|
95
95
|
table = PDF::Wrapper::Table.new do |t|
|
96
96
|
t.data = (1..50).collect { [1,2] }
|
@@ -110,7 +110,7 @@ context PDF::Wrapper do
|
|
110
110
|
receiver.content[1].include?("col2").should be_false
|
111
111
|
end
|
112
112
|
|
113
|
-
|
113
|
+
it "should be able to draw a table on the canvas with headers on all pages" do
|
114
114
|
|
115
115
|
table = PDF::Wrapper::Table.new do |t|
|
116
116
|
t.data = (1..50).collect { [1,2] }
|
@@ -130,21 +130,21 @@ context PDF::Wrapper do
|
|
130
130
|
receiver.content[1].include?("col2").should be_true
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
it "should leave the cursor in the bottom left when adding a table" do
|
134
134
|
data = [%w{head1 head2},%w{data1 data2}]
|
135
135
|
@pdf.table(data, :left => @pdf.margin_left)
|
136
136
|
x,y = @pdf.current_point
|
137
137
|
x.to_i.should eql(@pdf.margin_left)
|
138
138
|
end
|
139
139
|
|
140
|
-
|
140
|
+
it "should default to using as much available space when adding a table that isn't left aligned with the left margin" do
|
141
141
|
data = [%w{head1 head2},%w{data1 data2}]
|
142
142
|
@pdf.table(data, :left => 100)
|
143
143
|
x,y = @pdf.current_point
|
144
144
|
x.to_i.should eql(100)
|
145
145
|
end
|
146
146
|
|
147
|
-
|
147
|
+
it "should be able to draw a table with escaped content markup on the canvas" do
|
148
148
|
table = PDF::Wrapper::Table.new(:markup => :pango) do |t|
|
149
149
|
t.data = [%w{data1 data2}, %w{data3 data4&5}]
|
150
150
|
end
|
@@ -162,15 +162,15 @@ context PDF::Wrapper do
|
|
162
162
|
|
163
163
|
end
|
164
164
|
|
165
|
-
|
165
|
+
describe PDF::Wrapper, "data= method" do
|
166
166
|
|
167
|
-
|
167
|
+
it "should raise an exception if given rows of uneven size" do
|
168
168
|
data = [%w{head1 head2},%w{data1}]
|
169
169
|
table = PDF::Wrapper::Table.new
|
170
170
|
lambda { table.data = data }.should raise_error(ArgumentError)
|
171
171
|
end
|
172
172
|
|
173
|
-
|
173
|
+
it "should convert all non cell objects to TextCells" do
|
174
174
|
data = [%w{head1 head2},%w{data1 data2}]
|
175
175
|
table = PDF::Wrapper::Table.new
|
176
176
|
table.data = data
|
@@ -179,7 +179,7 @@ context PDF::Wrapper, "data= method" do
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
it "should leave existing TextCells unchanged" do
|
183
183
|
manual_cell_one = PDF::Wrapper::TextCell.new("data1")
|
184
184
|
manual_cell_two = PDF::Wrapper::TextCell.new("data2")
|
185
185
|
data = [[manual_cell_one, manual_cell_two]]
|
@@ -195,7 +195,7 @@ context PDF::Wrapper, "data= method" do
|
|
195
195
|
(cells[1] === manual_cell_two).should be_true
|
196
196
|
end
|
197
197
|
|
198
|
-
|
198
|
+
it "should leave existing TextImageCells unchanged" do
|
199
199
|
manual_cell_one = PDF::Wrapper::TextImageCell.new("data1", "image.png", 100, 100)
|
200
200
|
manual_cell_two = PDF::Wrapper::TextImageCell.new("data2", "image.png", 100, 100)
|
201
201
|
data = [[manual_cell_one, manual_cell_two]]
|
@@ -211,7 +211,7 @@ context PDF::Wrapper, "data= method" do
|
|
211
211
|
(cells[1] === manual_cell_two).should be_true
|
212
212
|
end
|
213
213
|
|
214
|
-
|
214
|
+
it "should set the default table options on all cells" do
|
215
215
|
data = [%w{head1 head2},%w{data1 data2}]
|
216
216
|
table = PDF::Wrapper::Table.new(:markup => :pango)
|
217
217
|
|
@@ -223,9 +223,9 @@ context PDF::Wrapper, "data= method" do
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
-
|
226
|
+
describe PDF::Wrapper, "headers method" do
|
227
227
|
|
228
|
-
|
228
|
+
it "should raise an exception if given cell count does not match existing data" do
|
229
229
|
data = [%w{data1 data2},%w{data1 data2}]
|
230
230
|
headers = %w{head1}
|
231
231
|
|
@@ -235,7 +235,7 @@ context PDF::Wrapper, "headers method" do
|
|
235
235
|
lambda { table.headers(headers) }.should raise_error(ArgumentError)
|
236
236
|
end
|
237
237
|
|
238
|
-
|
238
|
+
it "should wrap non-cell objects in a TextCell" do
|
239
239
|
headers = [["head1","head2"]]
|
240
240
|
|
241
241
|
table = PDF::Wrapper::Table.new
|
@@ -247,7 +247,7 @@ context PDF::Wrapper, "headers method" do
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
|
250
|
+
it "should leave TextCell objects untouched" do
|
251
251
|
manual_cell_one = PDF::Wrapper::TextCell.new("data1")
|
252
252
|
manual_cell_two = PDF::Wrapper::TextCell.new("data2")
|
253
253
|
headers = [manual_cell_one, manual_cell_two]
|
@@ -260,7 +260,7 @@ context PDF::Wrapper, "headers method" do
|
|
260
260
|
(set_headers[1] === manual_cell_two).should be_true
|
261
261
|
end
|
262
262
|
|
263
|
-
|
263
|
+
it "should leave TextImageCell objects untouched" do
|
264
264
|
manual_cell_one = PDF::Wrapper::TextImageCell.new("data1", "image.png", 100, 100)
|
265
265
|
manual_cell_two = PDF::Wrapper::TextImageCell.new("data2", "image.png", 100, 100)
|
266
266
|
headers = [manual_cell_one, manual_cell_two]
|
@@ -273,7 +273,7 @@ context PDF::Wrapper, "headers method" do
|
|
273
273
|
(set_headers[1] === manual_cell_two).should be_true
|
274
274
|
end
|
275
275
|
|
276
|
-
|
276
|
+
it "should set options on all cells" do
|
277
277
|
headers = ["head1","head2"]
|
278
278
|
|
279
279
|
table = PDF::Wrapper::Table.new
|
@@ -285,7 +285,7 @@ context PDF::Wrapper, "headers method" do
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
-
|
288
|
+
it "should set default table options on all cells" do
|
289
289
|
headers = ["head1","head2"]
|
290
290
|
|
291
291
|
table = PDF::Wrapper::Table.new(:markup => :pango)
|
@@ -298,9 +298,9 @@ context PDF::Wrapper, "headers method" do
|
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
|
-
|
301
|
+
describe PDF::Wrapper, "cell method" do
|
302
302
|
|
303
|
-
|
303
|
+
it "should return the appropriate cell" do
|
304
304
|
data = [%w{data1 data2},%w{data3 data4}]
|
305
305
|
headers = %w{head1}
|
306
306
|
|
@@ -315,9 +315,9 @@ context PDF::Wrapper, "cell method" do
|
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
318
|
-
|
318
|
+
describe PDF::Wrapper, "cell_options method" do
|
319
319
|
|
320
|
-
|
320
|
+
it "should set options on the appropriate cell" do
|
321
321
|
data = [%w{data1 data2},%w{data3 data4}]
|
322
322
|
|
323
323
|
table = PDF::Wrapper::Table.new
|
@@ -328,9 +328,9 @@ context PDF::Wrapper, "cell_options method" do
|
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
331
|
-
|
331
|
+
describe PDF::Wrapper, "col_options method" do
|
332
332
|
|
333
|
-
|
333
|
+
it "should set options on all cells in the appropriate column" do
|
334
334
|
data = [%w{data1 data2},%w{data3 data4}]
|
335
335
|
|
336
336
|
table = PDF::Wrapper::Table.new
|
@@ -344,9 +344,9 @@ context PDF::Wrapper, "col_options method" do
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
|
347
|
+
describe PDF::Wrapper, "row_options method" do
|
348
348
|
|
349
|
-
|
349
|
+
it "should set options on all cells in the appropriate row" do
|
350
350
|
data = [%w{data1 data2},%w{data3 data4}]
|
351
351
|
|
352
352
|
table = PDF::Wrapper::Table.new
|