poppler 3.1.8-x86-mingw32 → 3.1.9-x86-mingw32

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 (108) 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. data/vendor/local/bin/cjpeg.exe +0 -0
  35. data/vendor/local/bin/djpeg.exe +0 -0
  36. data/vendor/local/bin/jpegtran.exe +0 -0
  37. data/vendor/local/bin/libjpeg-9.dll +0 -0
  38. data/vendor/local/bin/libopenjp2.dll +0 -0
  39. data/vendor/local/bin/libpoppler-59.dll +0 -0
  40. data/vendor/local/bin/libpoppler-cpp-0.dll +0 -0
  41. data/vendor/local/bin/libpoppler-glib-8.dll +0 -0
  42. data/vendor/local/bin/libsqlite3-0.dll +0 -0
  43. data/vendor/local/bin/opj_compress.exe +0 -0
  44. data/vendor/local/bin/opj_decompress.exe +0 -0
  45. data/vendor/local/bin/opj_dump.exe +0 -0
  46. data/vendor/local/bin/pdfdetach.exe +0 -0
  47. data/vendor/local/bin/pdffonts.exe +0 -0
  48. data/vendor/local/bin/pdfimages.exe +0 -0
  49. data/vendor/local/bin/pdfinfo.exe +0 -0
  50. data/vendor/local/bin/pdfseparate.exe +0 -0
  51. data/vendor/local/bin/pdftocairo.exe +0 -0
  52. data/vendor/local/bin/pdftohtml.exe +0 -0
  53. data/vendor/local/bin/pdftoppm.exe +0 -0
  54. data/vendor/local/bin/pdftops.exe +0 -0
  55. data/vendor/local/bin/pdftotext.exe +0 -0
  56. data/vendor/local/bin/pdfunite.exe +0 -0
  57. data/vendor/local/bin/rdjpgcom.exe +0 -0
  58. data/vendor/local/bin/sqlite3.exe +0 -0
  59. data/vendor/local/bin/wrjpgcom.exe +0 -0
  60. data/vendor/local/lib/libjpeg.dll.a +0 -0
  61. data/vendor/local/lib/libopenjp2.dll.a +0 -0
  62. data/vendor/local/lib/libpoppler-cpp.dll.a +0 -0
  63. data/vendor/local/lib/libpoppler-glib.a +0 -0
  64. data/vendor/local/lib/libpoppler-glib.dll.a +0 -0
  65. data/vendor/local/lib/libpoppler.a +0 -0
  66. data/vendor/local/lib/libpoppler.dll.a +0 -0
  67. data/vendor/local/lib/libsqlite3.dll.a +0 -0
  68. metadata +26 -46
  69. data/README +0 -35
  70. data/ext/poppler/depend +0 -6
  71. data/ext/poppler/extconf.rb +0 -73
  72. data/ext/poppler/poppler.def +0 -2
  73. data/ext/poppler/rbpoppler-action.c +0 -402
  74. data/ext/poppler/rbpoppler-annotation-callout-line.c +0 -127
  75. data/ext/poppler/rbpoppler-annotation-free-text.c +0 -46
  76. data/ext/poppler/rbpoppler-annotation-mapping.c +0 -72
  77. data/ext/poppler/rbpoppler-annotation-markup.c +0 -98
  78. data/ext/poppler/rbpoppler-annotation-text.c +0 -53
  79. data/ext/poppler/rbpoppler-annotation.c +0 -74
  80. data/ext/poppler/rbpoppler-attachment.c +0 -124
  81. data/ext/poppler/rbpoppler-button-field.c +0 -56
  82. data/ext/poppler/rbpoppler-choice-field.c +0 -131
  83. data/ext/poppler/rbpoppler-color.c +0 -107
  84. data/ext/poppler/rbpoppler-document.c +0 -224
  85. data/ext/poppler/rbpoppler-font-info.c +0 -59
  86. data/ext/poppler/rbpoppler-fonts-iter.c +0 -127
  87. data/ext/poppler/rbpoppler-form-field-mapping.c +0 -44
  88. data/ext/poppler/rbpoppler-form-field.c +0 -98
  89. data/ext/poppler/rbpoppler-image-mapping.c +0 -48
  90. data/ext/poppler/rbpoppler-index-iter.c +0 -130
  91. data/ext/poppler/rbpoppler-link-mapping.c +0 -47
  92. data/ext/poppler/rbpoppler-page-transition.c +0 -59
  93. data/ext/poppler/rbpoppler-page.c +0 -322
  94. data/ext/poppler/rbpoppler-private.h +0 -77
  95. data/ext/poppler/rbpoppler-ps-file.c +0 -66
  96. data/ext/poppler/rbpoppler-rectangle.c +0 -92
  97. data/ext/poppler/rbpoppler-text-field.c +0 -91
  98. data/ext/poppler/rbpoppler.c +0 -110
  99. data/ext/poppler/rbpoppler.h +0 -61
  100. data/ext/poppler/rbpopplerconversions.h +0 -105
  101. data/extconf.rb +0 -49
  102. data/lib/2.2/poppler.so +0 -0
  103. data/lib/2.3/poppler.so +0 -0
  104. data/lib/2.4/poppler.so +0 -0
  105. data/test/fixtures/image.png +0 -0
  106. data/test/test_annotation.rb +0 -86
  107. data/test/test_constants.rb +0 -30
  108. data/test/test_page.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25c33762435e251fbe3c6ffca839d81f0e2ff2fb
4
- data.tar.gz: bccb324f6cebfd70b29a6066dbae98329774501b
3
+ metadata.gz: 65505bccd82fd325cc850807ec87f89223d03ceb
4
+ data.tar.gz: 541577b1c64e45272e926c74b0c46d6eedabc1ac
5
5
  SHA512:
6
- metadata.gz: 7a377037ccaa92e5030966be941ef3b5afb33e3f01b1136cde5958491c7be05c4a87724feac616645e757e0745019a1746b6c4ce7b6fdab5c1167a50d1f7b8e5
7
- data.tar.gz: 82a6010036269b58f95b62af3f40970650ba57f70ce99666d793562258fe92a90476507766b12d2b720b9eb887d65ae0492bbe3795bd02006f0f5018f240cce8
6
+ metadata.gz: ed3a7ae50afdf478b44a76815f854177742ebe3a7759479abbe73b97710b2c2163bd01967845e42a2332d2e9b758de1b5c90f5bb9f3604178453e18dae6494b8
7
+ data.tar.gz: b27cf394dae5c19a24d4a28a2834c747c6be08b1e4aba27967e93bdadb149509d53a7510d15e5b4a1f502f6488f793dbd80ac8a4f1ea78cf977857a90504fa79
@@ -0,0 +1,44 @@
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
+ require "pkg-config"
18
+ require "native-package-installer"
19
+
20
+ if File.exist?(File.join(__dir__, "..", "vendor"))
21
+ task :default => "nothing"
22
+ else
23
+ task :default => "dependency:check"
24
+ end
25
+
26
+ task :nothing do
27
+ end
28
+
29
+ namespace :dependency do
30
+ desc "Check dependency"
31
+ task :check do
32
+ unless PKGConfig.check_version?("poppler", 0, 12, 0)
33
+ unless NativePackageInstaller.install(:alt_linux => "libpoppler-glib-devel",
34
+ :debian => "libpoppler-glib-dev",
35
+ :redhat => "poppler-glib-devel",
36
+ :arch_linux => "poppler",
37
+ :homebrew => "poppler",
38
+ :macports => "poppler",
39
+ :msys2 => "poppler")
40
+ exit(false)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,122 +1,36 @@
1
- # Copyright(C) 2006-2015 Ruby-GNOME2 Project.
1
+ # Copyright (C) 2017 Ruby-GNOME2 Project Team
2
2
  #
3
- # This library is free software: you can redistribute it and/or modify
4
- # it under the terms of the GNU Lesser General Public License as published by
5
- # the Free Software Foundation, either version 2.1 of the License.
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.
6
7
  #
7
- # Foobar is distributed in the hope that it will be useful,
8
+ # This library is distributed in the hope that it will be useful,
8
9
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- # GNU Lesser General Public License for more details.
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
11
12
  #
12
- # You should have received a copy of the GNU Lesser General Public License
13
- # along with Foobar. If not, see <http://www.gnu.org/licenses/>.
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
14
16
 
15
- require "tempfile"
16
- require "date"
17
- require "glib2"
18
- require "gdk_pixbuf2"
19
- require "cairo"
17
+ require "gobject-introspection"
18
+ require "gio2"
19
+ require "cairo-gobject"
20
20
 
21
21
  base_dir = Pathname.new(__FILE__).dirname.dirname.expand_path
22
22
  vendor_dir = base_dir + "vendor" + "local"
23
23
  vendor_bin_dir = vendor_dir + "bin"
24
24
  GLib.prepend_dll_path(vendor_bin_dir)
25
- begin
26
- major, minor, = RUBY_VERSION.split(/\./)
27
- require "#{major}.#{minor}/poppler.so"
28
- rescue LoadError
29
- require "poppler.so"
30
- end
25
+ vendor_girepository_dir = vendor_dir + "lib" + "girepository-1.0"
26
+ GObjectIntrospection.prepend_typelib_path(vendor_girepository_dir)
27
+
28
+ require "poppler/loader"
31
29
 
32
30
  module Poppler
33
31
  LOG_DOMAIN = "Poppler"
32
+ GLib::Log.set_log_domain(LOG_DOMAIN)
34
33
 
35
- VERSION = version.split(".").collect {|x| x.to_i}
36
-
37
- module Version
38
- MAJOR, MINOR, MICRO = BUILD_VERSION
39
- STRING = "#{MAJOR}.#{MINOR}.#{MICRO}"
40
-
41
- class << self
42
- def or_later?(major, minor, micro=nil)
43
- micro || 0
44
- version = [
45
- MAJOR,
46
- MINOR,
47
- MICRO,
48
- ]
49
- (version <=> [major, minor, micro]) >= 0
50
- end
51
- end
52
- end
53
-
54
- class Document
55
- private
56
- def pdf_data?(data)
57
- data.start_with?("%PDF-1.")
58
- end
59
-
60
- def ensure_uri(uri)
61
- if pdf_data?(uri)
62
- @pdf = Tempfile.new("ruby-poppler-pdf")
63
- @pdf.binmode
64
- @pdf.print(uri)
65
- @pdf.close
66
- uri = @pdf.path
67
- end
68
-
69
- if GLib.path_is_absolute?(uri)
70
- GLib.filename_to_uri(uri)
71
- elsif /\A[a-zA-Z][a-zA-Z\d\-+.]*:/.match(uri)
72
- uri
73
- else
74
- GLib.filename_to_uri(File.expand_path(uri))
75
- end
76
- end
77
- end
78
-
79
- if defined?(TextField)
80
- class TextField
81
- def multiline?
82
- type == FormTextType::MULTILINE
83
- end
84
-
85
- def file_select?
86
- type == FormTextType::FILE_SELECT
87
- end
88
-
89
- def normal?
90
- type == FormTextType::NORMAL
91
- end
92
- end
93
- end
94
-
95
- if defined?(ChoiceField)
96
- class ChoiceField
97
- def combo?
98
- type == FormChioceType::COMBO
99
- end
100
-
101
- def list?
102
- type == FormChoiceType::LIST
103
- end
104
- end
105
- end
34
+ loader = Loader.new(self)
35
+ loader.load("Poppler")
106
36
  end
107
-
108
- if Poppler.cairo_available?
109
- module Cairo
110
- class Context
111
- def render_poppler_page(page, *args, &block)
112
- page.render(self, *args, &block)
113
- end
114
-
115
- def render_poppler_page_selection(page, *args, &block)
116
- page.render_selection(self, *args, &block)
117
- end
118
- end
119
- end
120
- end
121
-
122
- GLib::Log.set_log_domain(Poppler::LOG_DOMAIN)
@@ -0,0 +1,57 @@
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 AnnotCalloutLine
19
+ alias_method :initialize_raw, :initialize
20
+ def initialize(*args)
21
+ initialize_raw
22
+
23
+ return if args.empty?
24
+
25
+ if args.size == 1 and args[0].is_a?(Hash)
26
+ options = args[0]
27
+ self.multiline = options[:multiline]
28
+ self.x1 = options[:x1] || 0.0
29
+ self.y1 = options[:y1] || 0.0
30
+ self.x2 = options[:x2] || 0.0
31
+ self.y2 = options[:y2] || 0.0
32
+ self.x3 = options[:x3] || 0.0
33
+ self.y3 = options[:y3] || 0.0
34
+ elsif args.size == 7
35
+ self.multiline = args[0]
36
+ self.x1 = args[1]
37
+ self.y1 = args[2]
38
+ self.x2 = args[3]
39
+ self.y2 = args[4]
40
+ self.x3 = args[5]
41
+ self.y3 = args[6]
42
+ else
43
+ message =
44
+ "must be " +
45
+ "Hash({:multiline => true/false, :x1 => Float, :y1 => Float, " +
46
+ ":x2 => Float, :y2 => Float, :x3 => Float, :y3 => Float}) or " +
47
+ "Array([multiline(true/false), x1(Float), y1(Float), x2(Float), " +
48
+ "y2(Float), x3(Float), y3(Float)])"
49
+ raise(ArgumentError, message)
50
+ end
51
+ end
52
+
53
+ def to_a
54
+ [multiline?, x1, y1, x2, y2, x3, y3]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
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 Cairo
18
+ class Context
19
+ def render_poppler_page(page, options={})
20
+ page.render(self)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
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 Color
19
+ alias_method :initialize_raw, :initialize
20
+ def initialize(red, green, blue)
21
+ initialize_raw
22
+ self.red = red
23
+ self.green = green
24
+ self.blue = blue
25
+ end
26
+
27
+ def to_a
28
+ [red, green, blue]
29
+ end
30
+
31
+ alias_method :inspect_raw, :inspect
32
+ def inspect
33
+ inspect_raw[0..-2] + ": [#{to_a.join(", ")}]>"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,67 @@
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
+ extend GLib::Deprecatable
19
+
20
+ define_deprecated_singleton_method(:cairo_available?,
21
+ :warn => "cairo is always available") do
22
+ true
23
+ end
24
+
25
+ define_deprecated_const(:Annotation, "Poppler::Annot")
26
+ define_deprecated_const(:AnnotationType, "Poppler::AnnotType")
27
+ define_deprecated_const(:AnnotationFlag, "Poppler::AnnotFlag")
28
+ define_deprecated_const(:AnnotationMarkupReplyType,
29
+ "Poppler::AnnotMarkupReplyType")
30
+ define_deprecated_const(:AnnotationExternalDataType,
31
+ "Poppler::AnnotExternalDataType")
32
+ define_deprecated_const(:AnnotationTextState, "Poppler::AnnotTextSate")
33
+ define_deprecated_const(:AnnotationFreeTextQuadding,
34
+ "Poppler::AnnotFreeTextQuadding")
35
+ define_deprecated_const(:AnnotationMarkup,
36
+ "Poppler::AnnotMarkup")
37
+ define_deprecated_const(:AnnotationText,
38
+ "Poppler::AnnotText")
39
+ define_deprecated_const(:AnnotationFreeText,
40
+ "Poppler::AnnotFreeText")
41
+ define_deprecated_const(:AnnotationMapping,
42
+ "Poppler::AnnotMapping")
43
+
44
+ define_deprecated_const(:ActionURI,
45
+ "Poppler::ActionUri")
46
+ define_deprecated_const(:ActionJavaScript,
47
+ "Poppler::ActionJavascript")
48
+
49
+ class AnnotMapping
50
+ extend GLib::Deprecatable
51
+
52
+ define_deprecated_method(:annotation, :annot)
53
+ end
54
+
55
+ class Page
56
+ extend GLib::Deprecatable
57
+
58
+ define_deprecated_method(:annotation_mapping, :annot_mapping)
59
+ define_deprecated_method_by_hash_args(:get_text,
60
+ "area=nil, style=nil",
61
+ ":area => Poppler::Rectangle, " +
62
+ ":style => Poppler::SelectionStyle"
63
+ ) do |page, *args, &block|
64
+ [{:area => args[0], :style => args[1]}]
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,108 @@
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 Document
19
+ include Enumerable
20
+
21
+ alias_method :initialize_raw, :initialize
22
+ def initialize(*args)
23
+ if args.size == 1 and args[0].is_a?(Hash)
24
+ options = args[0]
25
+ data = options[:data]
26
+ uri = options[:uri]
27
+ path = options[:path]
28
+ stream = options[:stream]
29
+ length = options[:length]
30
+ file = options[:file]
31
+ password = options[:password]
32
+
33
+ if data
34
+ initialize_new_from_data(data, password)
35
+ elsif uri
36
+ initialize_new_from_file(uri, password)
37
+ elsif path
38
+ uri = ensure_uri(path)
39
+ initialize_new_from_file(uri, password)
40
+ elsif stream
41
+ if length.nil?
42
+ raise(ArgumentError,
43
+ "must specify :length for :stream: #{options.inspect}")
44
+ end
45
+ initialize_new_from_stream(stream, length, password)
46
+ elsif file
47
+ if file.is_a?(String)
48
+ initialize(path: file, password: password)
49
+ else
50
+ initialize_new_from_gfile(file, password)
51
+ end
52
+ else
53
+ message =
54
+ "must specify one of :data, :uri, :path, :stream or :file: " +
55
+ options.inspect
56
+ raise(ArgumentError, message)
57
+ end
58
+ else
59
+ uri_or_data, password = args
60
+ if pdf_data?(uri_or_data)
61
+ initialize_new_from_data(uri_or_data, password)
62
+ else
63
+ uri = ensure_uri(uri_or_data)
64
+ initialize_new_from_file(uri, password)
65
+ end
66
+ end
67
+ end
68
+
69
+ alias_method :[], :get_page
70
+
71
+ def each
72
+ return to_enum(__method__) unless block_given?
73
+
74
+ n_pages.times do |i|
75
+ yield get_page(i)
76
+ end
77
+ end
78
+
79
+ alias_method :save_raw, :save
80
+ def save(uri)
81
+ save_raw(ensure_uri(uri))
82
+ end
83
+
84
+ alias_method :save_a_copy_raw, :save_a_copy
85
+ def save_a_copy(uri)
86
+ save_a_copy_raw(ensure_uri(uri))
87
+ end
88
+
89
+ def index_iter
90
+ IndexIter.new(self)
91
+ end
92
+
93
+ private
94
+ def pdf_data?(data)
95
+ data.start_with?("%PDF-1.")
96
+ end
97
+
98
+ def ensure_uri(uri)
99
+ if GLib.path_is_absolute?(uri)
100
+ GLib.filename_to_uri(uri)
101
+ elsif /\A[a-zA-Z][a-zA-Z\d\-+.]*:/.match(uri)
102
+ uri
103
+ else
104
+ GLib.filename_to_uri(File.expand_path(uri))
105
+ end
106
+ end
107
+ end
108
+ end