poppler 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ class TestDocument < Test::Unit::TestCase
2
+ def test_save
3
+ saved_pdf = File.join(tmp_dir, "saved.pdf")
4
+ FileUtils.rm_f(saved_pdf)
5
+
6
+ document = Poppler::Document.new(form_pdf)
7
+ find_first_text_field(document).text = "XXX"
8
+ assert(document.save(saved_pdf))
9
+ assert(File.exist?(saved_pdf))
10
+
11
+ only_poppler_version(0, 8, 2)
12
+ reread_document = Poppler::Document.new(saved_pdf)
13
+ assert_equal("XXX", find_first_text_field(reread_document).text)
14
+ end
15
+
16
+ def test_save_a_copy
17
+ only_poppler_version(0, 7, 2)
18
+ copied_pdf = File.join(tmp_dir, "copied.pdf")
19
+ FileUtils.rm_f(copied_pdf)
20
+
21
+ document = Poppler::Document.new(form_pdf)
22
+ first_text_field = find_first_text_field(document)
23
+ default_text = first_text_field.text
24
+ first_text_field.text = "XXX"
25
+ assert(document.save_a_copy(copied_pdf))
26
+ assert(File.exist?(copied_pdf))
27
+
28
+ reread_document = Poppler::Document.new(copied_pdf)
29
+ assert_equal(default_text, find_first_text_field(reread_document).text)
30
+ end
31
+
32
+ private
33
+ def find_first_text_field(document)
34
+ document.each do |page|
35
+ page.form_field_mapping.each do |mapping|
36
+ field = mapping.field
37
+ return field if field.is_a?(Poppler::TextField)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,78 @@
1
+ class TestPage < Test::Unit::TestCase
2
+ def test_get_image
3
+ document = Poppler::Document.new(image_pdf)
4
+ page, mapping = find_first_image_mapping(document)
5
+ if later_version?(0, 7, 2) and Poppler.cairo_available?
6
+ assert_kind_of(Cairo::ImageSurface, page.get_image(mapping.image_id))
7
+ assert_kind_of(Cairo::ImageSurface, mapping.image)
8
+ else
9
+ assert_kind_of(Gdk::Pixbuf, mapping.image)
10
+ end
11
+ end
12
+
13
+ def test_render_to_pixbuf
14
+ document = Poppler::Document.new(image_pdf)
15
+ page = document[0]
16
+ width, height = page.size
17
+ pixbuf = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB, true, 8,
18
+ width / 2, height / 2)
19
+ pixbuf.fill!(0)
20
+ assert_equal("\0" * 10, pixbuf.pixels[0, 10])
21
+ page.render(0, 0, width, height, 0.5, 0, pixbuf)
22
+ assert_not_equal("\0" * 10, pixbuf.pixels[0, 10])
23
+ end
24
+
25
+ def test_render_to_pixbuf_for_printing
26
+ only_poppler_version(0, 7, 2)
27
+
28
+ document = Poppler::Document.new(image_pdf)
29
+ page = document[0]
30
+ width, height = page.size
31
+ pixbuf = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB, true, 8,
32
+ width / 2, height / 2)
33
+ pixbuf.fill!(0)
34
+ assert_equal("\0" * 10, pixbuf.pixels[0, 10])
35
+ page.render_for_printing(0, 0, width, height, 0.5, 0, pixbuf)
36
+ assert_not_equal("\0" * 10, pixbuf.pixels[0, 10])
37
+ end
38
+
39
+ def test_thumbnail_pixbuf
40
+ omit("We doesn't have a PDF that has a thumbnail...")
41
+ document = Poppler::Document.new(thumbnail_pdf)
42
+ page = document[0]
43
+ assert_kind_of(Gdk::Pixbuf, page.thumbnail_pixbuf)
44
+ end
45
+
46
+ def test_selection_region
47
+ document = Poppler::Document.new(form_pdf)
48
+ page = document[0]
49
+ rectangle = Poppler::Rectangle.new(0, 0, *page.size)
50
+ region = page.get_selection_region(0.5, :word, rectangle)
51
+ if later_version?(0, 7, 2)
52
+ assert_kind_of(Poppler::Rectangle, region[0])
53
+ else
54
+ assert_kind_of(Gdk::Region, region)
55
+ end
56
+ end
57
+
58
+ def test_annotation_mapping
59
+ only_poppler_version(0, 7, 2)
60
+ document = Poppler::Document.new(form_pdf)
61
+ page = document[0]
62
+ assert_equal([Poppler::AnnotationMapping],
63
+ page.annotation_mapping.collect {|mapping| mapping.class}.uniq)
64
+ mapping = page.annotation_mapping[0]
65
+ assert_kind_of(Poppler::Rectangle, mapping.area)
66
+ assert_kind_of(Poppler::Annotation, mapping.annotation)
67
+ end
68
+
69
+ private
70
+ def find_first_image_mapping(document)
71
+ document.each do |page|
72
+ page.image_mapping.each do |mapping|
73
+ return [page, mapping]
74
+ end
75
+ end
76
+ nil
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poppler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 20
8
+ - 0
9
+ version: 0.20.0
10
+ platform: ruby
11
+ authors:
12
+ - ruby-gnome2/AUTHORS
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: glib2
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: cairo
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Ruby/Poppler is a Ruby binding of poppler-glib.
47
+ email: todd.fisher@gmail.com
48
+ executables: []
49
+
50
+ extensions:
51
+ - extconf.rb
52
+ extra_rdoc_files:
53
+ - README
54
+ files:
55
+ - ChangeLog
56
+ - README
57
+ - Rakefile
58
+ - extconf.rb
59
+ - src/lib/poppler.rb
60
+ - src/rbpoppler-action.c
61
+ - src/rbpoppler-annotation.c
62
+ - src/rbpoppler-attachment.c
63
+ - src/rbpoppler-document.c
64
+ - src/rbpoppler-form-field.c
65
+ - src/rbpoppler-page.c
66
+ - src/rbpoppler.c
67
+ - src/rbpoppler-private.h
68
+ - src/rbpoppler.h
69
+ - src/rbpopplerversion.h
70
+ - sample/number-pdf.rb
71
+ - sample/pdf2.rb
72
+ - sample/pdf2svg.rb
73
+ - sample/pdf2text.rb
74
+ - sample/pdfdiv.rb
75
+ - test/poppler-test-utils.rb
76
+ - test/run-test.rb
77
+ - test/test_annotation.rb
78
+ - test/test_color.rb
79
+ - test/test_constants.rb
80
+ - test/test_document.rb
81
+ - test/test_page.rb
82
+ has_rdoc: true
83
+ homepage: http://ruby-gnome2.sourceforge.jp/
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --main
89
+ - README
90
+ require_paths:
91
+ - src
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project: poppler
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Ruby poppler bindings
115
+ test_files:
116
+ - test/poppler-test-utils.rb
117
+ - test/run-test.rb
118
+ - test/test_annotation.rb
119
+ - test/test_color.rb
120
+ - test/test_constants.rb
121
+ - test/test_document.rb
122
+ - test/test_page.rb