poppler 3.1.8 → 3.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/dependency-check/Rakefile +44 -0
  3. data/lib/poppler.rb +21 -107
  4. data/lib/poppler/annot-callout-line.rb +57 -0
  5. data/lib/poppler/cairo.rb +23 -0
  6. data/lib/poppler/color.rb +36 -0
  7. data/lib/poppler/deprecated.rb +67 -0
  8. data/lib/poppler/document.rb +108 -0
  9. data/lib/poppler/image-mapping.rb +25 -0
  10. data/lib/poppler/index-iter.rb +30 -0
  11. data/lib/poppler/loader.rb +139 -0
  12. data/lib/poppler/page.rb +61 -0
  13. data/lib/poppler/rectangle.rb +40 -0
  14. data/lib/poppler/version.rb +35 -0
  15. data/sample/number-pdf.rb +21 -2
  16. data/sample/pdf2.rb +0 -4
  17. data/sample/pdf2svg.rb +1 -1
  18. data/sample/pdf2text.rb +1 -1
  19. data/sample/pdfcrop.rb +1 -1
  20. data/sample/pdfdiv.rb +1 -1
  21. data/test/fixtures/image.odt +0 -0
  22. data/test/fixtures/image.pdf +0 -0
  23. data/test/fixtures/multiple-pages.odt +0 -0
  24. data/test/fixtures/multiple-pages.pdf +0 -0
  25. data/test/fixtures/text-field.odt +0 -0
  26. data/test/fixtures/text-field.pdf +0 -0
  27. data/test/poppler-test-utils.rb +24 -16
  28. data/test/run-test.rb +26 -4
  29. data/test/test-annotation.rb +76 -0
  30. data/test/{test_color.rb → test-color.rb} +0 -3
  31. data/test/test-constants.rb +16 -0
  32. data/test/{test_document.rb → test-document.rb} +26 -10
  33. data/test/test-page.rb +101 -0
  34. metadata +28 -45
  35. data/README +0 -35
  36. data/ext/poppler/depend +0 -6
  37. data/ext/poppler/extconf.rb +0 -73
  38. data/ext/poppler/poppler.def +0 -2
  39. data/ext/poppler/rbpoppler-action.c +0 -402
  40. data/ext/poppler/rbpoppler-annotation-callout-line.c +0 -127
  41. data/ext/poppler/rbpoppler-annotation-free-text.c +0 -46
  42. data/ext/poppler/rbpoppler-annotation-mapping.c +0 -72
  43. data/ext/poppler/rbpoppler-annotation-markup.c +0 -98
  44. data/ext/poppler/rbpoppler-annotation-text.c +0 -53
  45. data/ext/poppler/rbpoppler-annotation.c +0 -74
  46. data/ext/poppler/rbpoppler-attachment.c +0 -124
  47. data/ext/poppler/rbpoppler-button-field.c +0 -56
  48. data/ext/poppler/rbpoppler-choice-field.c +0 -131
  49. data/ext/poppler/rbpoppler-color.c +0 -107
  50. data/ext/poppler/rbpoppler-document.c +0 -224
  51. data/ext/poppler/rbpoppler-font-info.c +0 -59
  52. data/ext/poppler/rbpoppler-fonts-iter.c +0 -127
  53. data/ext/poppler/rbpoppler-form-field-mapping.c +0 -44
  54. data/ext/poppler/rbpoppler-form-field.c +0 -98
  55. data/ext/poppler/rbpoppler-image-mapping.c +0 -48
  56. data/ext/poppler/rbpoppler-index-iter.c +0 -130
  57. data/ext/poppler/rbpoppler-link-mapping.c +0 -47
  58. data/ext/poppler/rbpoppler-page-transition.c +0 -59
  59. data/ext/poppler/rbpoppler-page.c +0 -322
  60. data/ext/poppler/rbpoppler-private.h +0 -77
  61. data/ext/poppler/rbpoppler-ps-file.c +0 -66
  62. data/ext/poppler/rbpoppler-rectangle.c +0 -92
  63. data/ext/poppler/rbpoppler-text-field.c +0 -91
  64. data/ext/poppler/rbpoppler.c +0 -110
  65. data/ext/poppler/rbpoppler.h +0 -61
  66. data/ext/poppler/rbpopplerconversions.h +0 -105
  67. data/extconf.rb +0 -49
  68. data/test/fixtures/image.png +0 -0
  69. data/test/test_annotation.rb +0 -86
  70. data/test/test_constants.rb +0 -30
  71. data/test/test_page.rb +0 -51
@@ -0,0 +1,25 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ class ImageMapping
19
+ attr_accessor :page
20
+
21
+ def image
22
+ @page.get_image(image_id)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ class IndexIter
19
+ include Enumerable
20
+
21
+ def each
22
+ return to_enum(__method__) unless block_given?
23
+
24
+ loop do
25
+ yield(self)
26
+ break unless self.next
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,139 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ class Loader < GObjectIntrospection::Loader
19
+ private
20
+ def pre_load(repository, namespace)
21
+ @form_field_classes = {}
22
+ end
23
+
24
+ def post_load(repository, namespace)
25
+ require_libraries
26
+ convert_action_classes
27
+ convert_field_classes
28
+ end
29
+
30
+ def require_libraries
31
+ require "poppler/version"
32
+
33
+ require "poppler/annot-callout-line"
34
+ require "poppler/cairo"
35
+ require "poppler/color"
36
+ require "poppler/document"
37
+ require "poppler/image-mapping"
38
+ require "poppler/index-iter"
39
+ require "poppler/page"
40
+ require "poppler/rectangle"
41
+
42
+ require "poppler/deprecated"
43
+ end
44
+
45
+ def load_enum_info(info)
46
+ case info.name
47
+ when "AnnotType"
48
+ self.class.register_constant_rename_map("3D", "TYPE_3D")
49
+ when "AnnotExternalDataType"
50
+ self.class.register_constant_rename_map("3D", "TYPE_3D")
51
+ when "StructureGlyphOrientation"
52
+ self.class.register_constant_rename_map("0", "DEGREE_0")
53
+ self.class.register_constant_rename_map("90", "DEGREE_90")
54
+ self.class.register_constant_rename_map("180", "DEGREE_180")
55
+ self.class.register_constant_rename_map("270", "DEGREE_270")
56
+ end
57
+ super
58
+ end
59
+
60
+ def load_method_info(info, klass, method_name)
61
+ case klass.name
62
+ when "Poppler::Annot"
63
+ case method_name
64
+ when "annot_type"
65
+ method_name = "type"
66
+ end
67
+ when "Poppler::FormField"
68
+ case method_name
69
+ when /\Abutton_/
70
+ klass = define_field_class("ButtonField")
71
+ method_name = rubyish_method_name(info, prefix: "button_")
72
+ method_name = "type" if method_name == "button_type"
73
+ when /\Atext_/
74
+ klass = define_field_class("TextField")
75
+ method_name = rubyish_method_name(info, prefix: "text_")
76
+ method_name = "type" if method_name == "text_type"
77
+ when /\Achoice_/
78
+ klass = define_field_class("ChoiceField")
79
+ method_name = rubyish_method_name(info, prefix: "choice_")
80
+ method_name = "type" if method_name == "choice_type"
81
+ end
82
+ end
83
+ super(info, klass, method_name)
84
+ end
85
+
86
+ def define_struct(info, options={})
87
+ case info.name
88
+ when /\AAction.+/
89
+ options[:parent] = Action
90
+ end
91
+ super(info, options)
92
+ end
93
+
94
+ def convert_action_classes
95
+ unknown_class = Class.new(Action)
96
+ @base_module.const_set("ActionUnknown", unknown_class)
97
+
98
+ action_map = {
99
+ ActionType::UNKNOWN => unknown_class,
100
+ ActionType::GOTO_DEST => ActionGotoDest,
101
+ ActionType::GOTO_REMOTE => ActionGotoRemote,
102
+ ActionType::LAUNCH => ActionLaunch,
103
+ ActionType::URI => ActionUri,
104
+ ActionType::NAMED => ActionNamed,
105
+ ActionType::MOVIE => ActionMovie,
106
+ ActionType::RENDITION => ActionRendition,
107
+ ActionType::OCG_STATE => ActionOCGState,
108
+ ActionType::JAVASCRIPT => ActionJavascript,
109
+ }
110
+ self.class.register_boxed_class_converter(Action.gtype) do |action|
111
+ action_map[action.type] || Action
112
+ end
113
+ end
114
+
115
+ def define_field_class(name)
116
+ klass = @form_field_classes[name]
117
+ return klass if klass
118
+
119
+ field_class = @base_module.const_get("FormField")
120
+ klass = @form_field_classes[name] = Class.new(field_class)
121
+ @base_module.const_set(name, klass)
122
+ klass
123
+ end
124
+
125
+ def convert_field_classes
126
+ define_field_class("SignatureField")
127
+
128
+ field_map = {
129
+ FormFieldType::BUTTON => ButtonField,
130
+ FormFieldType::TEXT => TextField,
131
+ FormFieldType::CHOICE => ChoiceField,
132
+ FormFieldType::SIGNATURE => SignatureField,
133
+ }
134
+ self.class.register_object_class_converter(FormField.gtype) do |field|
135
+ field_map[field.field_type] || FormField
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ class Page
19
+ alias_method :text_layout_raw, :text_layout
20
+ def text_layout
21
+ success, rectangles = text_layout_raw
22
+ if success
23
+ rectangles
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ alias_method :image_mapping_raw, :image_mapping
30
+ def image_mapping
31
+ mappings = image_mapping_raw
32
+ mappings.each do |mapping|
33
+ mapping.page = self
34
+ end
35
+ mappings
36
+ end
37
+
38
+ def get_text(options={})
39
+ area = options[:area]
40
+ style = options[:style]
41
+ if area
42
+ if style
43
+ get_selected_text(style, area)
44
+ else
45
+ get_text_for_area(area)
46
+ end
47
+ else
48
+ text
49
+ end
50
+ end
51
+
52
+ alias_method :find_text_raw, :find_text
53
+ def find_text(text, options=nil)
54
+ if options.nil?
55
+ find_text_raw(text)
56
+ else
57
+ find_text_with_options(text, options)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ class Rectangle
19
+ alias_method :initialize_raw, :initialize
20
+ def initialize(*args)
21
+ super()
22
+ return if args.empty?
23
+
24
+ self.x1 = args[0]
25
+ self.y1 = args[1]
26
+ self.x2 = args[2]
27
+ self.y2 = args[3]
28
+ end
29
+
30
+ def to_a
31
+ [x1, y1, x2, y2]
32
+ end
33
+
34
+ def inspect
35
+ super.gsub(/>\z/) do
36
+ ": [%g, %g, %g, %g]>" % to_a
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Poppler
18
+ module Version
19
+ MAJOR = MAJOR_VERSION
20
+ MINOR = MINOR_VERSION
21
+ MICRO = MICRO_VERSION
22
+ STRING = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{MICRO_VERSION}"
23
+ class << self
24
+ def or_later?(major, minor, micro=nil)
25
+ micro ||= 0
26
+ version = [
27
+ MAJOR_VERSION,
28
+ MINOR_VERSION,
29
+ MICRO_VERSION,
30
+ ]
31
+ (version <=> [major, minor, micro]) >= 0
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2
17
 
3
- require 'poppler'
18
+ # usage :
19
+ # ruby number-pdf.rb example.pdf
20
+
21
+ require "poppler"
22
+ require "pango"
4
23
 
5
24
  input = ARGV.first
6
25
  output = input.sub(/\.pdf$/, "-numbered.pdf")
@@ -21,7 +40,7 @@ Cairo::PDFSurface.new(output, *first_page.size) do |surface|
21
40
  layout = context.create_pango_layout
22
41
  layout.text = i.to_s
23
42
  layout.width = width * Pango::SCALE
24
- layout.alignment = Pango::Layout::ALIGN_CENTER
43
+ layout.alignment = :center
25
44
  layout.font_description = Pango::FontDescription.new("Sans 288")
26
45
  context.move_to(0, (height - layout.pixel_size[1]) / 2.0)
27
46
  context.set_source_rgba(0.1, 0.1, 0.1, 0.5)
@@ -118,10 +118,6 @@ def to_pixbuf_with_cairo(input, page_number, scale, rotate)
118
118
  GdkPixbuf::Pixbuf.new(:file => temp.path)
119
119
  end
120
120
 
121
- unless Poppler.cairo_available?
122
- puts "cairo isn't available."
123
- exit(false)
124
- end
125
121
  pixbuf = to_pixbuf_with_cairo(input, page, scale, rotate)
126
122
 
127
123
  if pixbuf.nil?
@@ -14,7 +14,7 @@ output = "#{output}.svg" if input == output
14
14
 
15
15
  doc = Poppler::Document.new(input)
16
16
 
17
- width, height = doc.pages[0].size
17
+ width, height = doc[0].size
18
18
  Cairo::SVGSurface.new(output, width, height) do |surface|
19
19
  surface.restrict_to_version("1_2")
20
20
 
@@ -12,5 +12,5 @@ input_uri = "file://#{File.expand_path(input)}"
12
12
 
13
13
  doc = Poppler::Document.new(input_uri)
14
14
  doc.each do |page|
15
- puts page.get_text
15
+ puts page.text
16
16
  end
@@ -11,7 +11,7 @@ input, output = ARGV
11
11
 
12
12
  doc = Poppler::Document.new(input)
13
13
 
14
- width, height = doc.pages[0].size
14
+ width, height = doc[0].size
15
15
  x_margin = width * 0.1
16
16
  y_margin = height * 0.1
17
17
  croped_width = width - (2 * x_margin)
@@ -11,7 +11,7 @@ input, output = ARGV
11
11
 
12
12
  doc = Poppler::Document.new(input)
13
13
 
14
- width, height = doc.pages[0].size
14
+ width, height = doc[0].size
15
15
  Cairo::PDFSurface.new(output, width / 2, height) do |surface|
16
16
  context = Cairo::Context.new(surface)
17
17
 
Binary file
Binary file
@@ -1,5 +1,5 @@
1
- require 'open-uri'
2
- require 'fileutils'
1
+ require "open-uri"
2
+ require "fileutils"
3
3
 
4
4
  module PopplerTestUtils
5
5
  def ensure_dir(dir)
@@ -15,47 +15,55 @@ module PopplerTestUtils
15
15
  ensure_dir(File.join(test_dir, "fixtures"))
16
16
  end
17
17
 
18
+ def fixture_path(*components)
19
+ File.join(fixtures_dir, *components)
20
+ end
21
+
18
22
  def tmp_dir
19
23
  ensure_dir(File.join(test_dir, "tmp"))
20
24
  end
21
25
 
22
26
  def form_pdf
23
- file = File.join(fixtures_dir, "form.pdf")
24
- return file if File.exist?(file)
25
- pdf = open("https://www.irs.gov/pub/irs-pdf/fw9.pdf").read
26
- File.open(file, "wb") do |output|
27
- output.print(pdf)
27
+ path = fixture_path("form.pdf")
28
+ unless File.exist?(path)
29
+ pdf = open("https://www.irs.gov/pub/irs-pdf/fw9.pdf").read
30
+ File.open(path, "wb") do |output|
31
+ output.print(pdf)
32
+ end
28
33
  end
29
- file
34
+ path
35
+ end
36
+
37
+ def text_field_pdf
38
+ fixture_path("text-field.pdf")
30
39
  end
31
40
 
32
41
  def image_pdf
33
- File.join(fixtures_dir, "image.pdf")
42
+ fixture_path("image.pdf")
34
43
  end
35
44
 
36
45
  def image_png
37
- File.join(fixtures_dir, "image.png")
46
+ fixture_path("image.png")
38
47
  end
39
48
 
40
49
  def outline_pdf
41
- File.join(fixtures_dir, "outline.pdf")
50
+ fixture_path("outline.pdf")
42
51
  end
43
52
 
44
- def later_version?(major, minor, micro=nil)
45
- micro ||= 0
46
- (Poppler::BUILD_VERSION <=> [major, minor, micro]) >= 0
53
+ def multiple_pages_pdf
54
+ fixture_path("multiple-pages.pdf")
47
55
  end
48
56
 
49
57
  def only_poppler_version(major, minor, micro=nil)
50
58
  micro ||= 0
51
- unless later_version?(major, minor, micro)
59
+ unless Poppler::Version.or_later?(major, minor, micro)
52
60
  omit("Require Poppler >= #{major}.#{minor}.#{micro}")
53
61
  end
54
62
  end
55
63
 
56
64
  def only_old_poppler_version(major, minor, micro=nil)
57
65
  micro ||= 0
58
- if later_version?(major, minor, micro)
66
+ if Poppler::Version.or_later?(major, minor, micro)
59
67
  omit("Require Poppler < #{major}.#{minor}.#{micro}")
60
68
  end
61
69
  end