origami-docspring 2.2.0 → 2.3.0

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/examples/attachments/attachment.rb +7 -8
  4. data/examples/attachments/nested_document.rb +6 -5
  5. data/examples/encryption/encryption.rb +5 -4
  6. data/examples/events/events.rb +7 -6
  7. data/examples/flash/flash.rb +10 -9
  8. data/examples/forms/javascript.rb +14 -13
  9. data/examples/forms/xfa.rb +67 -66
  10. data/examples/javascript/hello_world.rb +6 -5
  11. data/examples/javascript/js_emulation.rb +26 -26
  12. data/examples/loop/goto.rb +12 -11
  13. data/examples/loop/named.rb +17 -16
  14. data/examples/signature/signature.rb +11 -11
  15. data/examples/uri/javascript.rb +25 -24
  16. data/examples/uri/open-uri.rb +5 -4
  17. data/examples/uri/submitform.rb +11 -10
  18. data/lib/origami/3d.rb +330 -334
  19. data/lib/origami/acroform.rb +267 -268
  20. data/lib/origami/actions.rb +266 -278
  21. data/lib/origami/annotations.rb +659 -670
  22. data/lib/origami/array.rb +192 -196
  23. data/lib/origami/boolean.rb +66 -70
  24. data/lib/origami/catalog.rb +360 -363
  25. data/lib/origami/collections.rb +132 -133
  26. data/lib/origami/compound.rb +125 -129
  27. data/lib/origami/destinations.rb +226 -237
  28. data/lib/origami/dictionary.rb +155 -154
  29. data/lib/origami/encryption.rb +967 -923
  30. data/lib/origami/extensions/fdf.rb +270 -275
  31. data/lib/origami/extensions/ppklite.rb +323 -328
  32. data/lib/origami/filespec.rb +170 -173
  33. data/lib/origami/filters/ascii.rb +162 -167
  34. data/lib/origami/filters/ccitt/tables.rb +248 -252
  35. data/lib/origami/filters/ccitt.rb +309 -312
  36. data/lib/origami/filters/crypt.rb +31 -34
  37. data/lib/origami/filters/dct.rb +47 -50
  38. data/lib/origami/filters/flate.rb +57 -60
  39. data/lib/origami/filters/jbig2.rb +50 -53
  40. data/lib/origami/filters/jpx.rb +40 -43
  41. data/lib/origami/filters/lzw.rb +151 -155
  42. data/lib/origami/filters/predictors.rb +250 -255
  43. data/lib/origami/filters/runlength.rb +111 -115
  44. data/lib/origami/filters.rb +319 -325
  45. data/lib/origami/font.rb +173 -177
  46. data/lib/origami/functions.rb +62 -66
  47. data/lib/origami/graphics/colors.rb +203 -208
  48. data/lib/origami/graphics/instruction.rb +79 -81
  49. data/lib/origami/graphics/path.rb +141 -144
  50. data/lib/origami/graphics/patterns.rb +156 -160
  51. data/lib/origami/graphics/render.rb +51 -47
  52. data/lib/origami/graphics/state.rb +144 -142
  53. data/lib/origami/graphics/text.rb +185 -188
  54. data/lib/origami/graphics/xobject.rb +818 -804
  55. data/lib/origami/graphics.rb +25 -26
  56. data/lib/origami/header.rb +63 -65
  57. data/lib/origami/javascript.rb +718 -651
  58. data/lib/origami/linearization.rb +284 -285
  59. data/lib/origami/metadata.rb +156 -135
  60. data/lib/origami/name.rb +98 -100
  61. data/lib/origami/null.rb +49 -51
  62. data/lib/origami/numeric.rb +133 -135
  63. data/lib/origami/obfuscation.rb +180 -182
  64. data/lib/origami/object.rb +634 -631
  65. data/lib/origami/optionalcontent.rb +147 -149
  66. data/lib/origami/outline.rb +46 -48
  67. data/lib/origami/outputintents.rb +76 -77
  68. data/lib/origami/page.rb +637 -596
  69. data/lib/origami/parser.rb +214 -221
  70. data/lib/origami/parsers/fdf.rb +44 -45
  71. data/lib/origami/parsers/pdf/lazy.rb +147 -154
  72. data/lib/origami/parsers/pdf/linear.rb +104 -109
  73. data/lib/origami/parsers/pdf.rb +109 -107
  74. data/lib/origami/parsers/ppklite.rb +44 -46
  75. data/lib/origami/pdf.rb +886 -896
  76. data/lib/origami/reference.rb +116 -120
  77. data/lib/origami/signature.rb +617 -625
  78. data/lib/origami/stream.rb +560 -558
  79. data/lib/origami/string.rb +366 -368
  80. data/lib/origami/template/patterns.rb +50 -52
  81. data/lib/origami/template/widgets.rb +111 -114
  82. data/lib/origami/trailer.rb +153 -157
  83. data/lib/origami/tree.rb +55 -57
  84. data/lib/origami/version.rb +19 -19
  85. data/lib/origami/webcapture.rb +87 -90
  86. data/lib/origami/xfa/config.rb +409 -414
  87. data/lib/origami/xfa/connectionset.rb +113 -117
  88. data/lib/origami/xfa/datasets.rb +38 -42
  89. data/lib/origami/xfa/localeset.rb +33 -37
  90. data/lib/origami/xfa/package.rb +49 -52
  91. data/lib/origami/xfa/pdf.rb +54 -59
  92. data/lib/origami/xfa/signature.rb +33 -37
  93. data/lib/origami/xfa/sourceset.rb +34 -38
  94. data/lib/origami/xfa/stylesheet.rb +35 -39
  95. data/lib/origami/xfa/template.rb +1630 -1634
  96. data/lib/origami/xfa/xdc.rb +33 -37
  97. data/lib/origami/xfa/xfa.rb +132 -123
  98. data/lib/origami/xfa/xfdf.rb +34 -38
  99. data/lib/origami/xfa/xmpmeta.rb +34 -38
  100. data/lib/origami/xfa.rb +50 -53
  101. data/lib/origami/xreftable.rb +462 -462
  102. data/lib/origami.rb +37 -38
  103. data/test/test_actions.rb +22 -20
  104. data/test/test_annotations.rb +54 -52
  105. data/test/test_forms.rb +23 -21
  106. data/test/test_native_types.rb +82 -78
  107. data/test/test_object_tree.rb +25 -24
  108. data/test/test_pages.rb +43 -41
  109. data/test/test_pdf.rb +2 -0
  110. data/test/test_pdf_attachment.rb +23 -21
  111. data/test/test_pdf_create.rb +16 -15
  112. data/test/test_pdf_encrypt.rb +69 -66
  113. data/test/test_pdf_parse.rb +131 -129
  114. data/test/test_pdf_parse_lazy.rb +53 -53
  115. data/test/test_pdf_sign.rb +67 -67
  116. data/test/test_streams.rb +145 -143
  117. data/test/test_xrefs.rb +46 -45
  118. metadata +64 -8
@@ -1,269 +1,262 @@
1
- =begin
2
-
3
- This file is part of Origami, PDF manipulation framework for Ruby
4
- Copyright (C) 2016 Guillaume Delugré.
5
-
6
- Origami is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- Origami is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with Origami. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- =end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # This file is part of Origami, PDF manipulation framework for Ruby
5
+ # Copyright (C) 2016 Guillaume Delugré.
6
+ #
7
+ # Origami is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Origami is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with Origami. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
20
 
21
21
  require 'colorize'
22
22
  require 'strscan'
23
23
 
24
24
  module Origami
25
+ class Parser # :nodoc:
26
+ class ParsingError < Error # :nodoc:
27
+ end
25
28
 
26
- class Parser #:nodoc:
27
-
28
- class ParsingError < Error #:nodoc:
29
- end
30
-
31
- #
32
- # Do not output debug information.
33
- #
34
- VERBOSE_QUIET = 0
35
-
36
- #
37
- # Output some useful information.
38
- #
39
- VERBOSE_INFO = 1
40
-
41
- #
42
- # Output debug information.
43
- #
44
- VERBOSE_DEBUG = 2
45
-
46
- #
47
- # Output every objects read
48
- #
49
- VERBOSE_TRACE = 3
50
-
51
- attr_accessor :options
52
-
53
- def initialize(options = {}) #:nodoc:
54
- # Type information for indirect objects.
55
- @deferred_casts = {}
56
-
57
- #Default options values
58
- @options =
59
- {
60
- verbosity: VERBOSE_INFO, # Verbose level.
61
- ignore_errors: true, # Try to keep on parsing when errors occur.
62
- callback: Proc.new {}, # Callback procedure whenever a structure is read.
63
- logger: STDERR, # Where to output parser messages.
64
- colorize_log: true # Colorize parser output?
65
- }
66
-
67
- @options.update(options)
68
- @logger = @options[:logger]
69
- @data = nil
70
- end
29
+ #
30
+ # Do not output debug information.
31
+ #
32
+ VERBOSE_QUIET = 0
33
+
34
+ #
35
+ # Output some useful information.
36
+ #
37
+ VERBOSE_INFO = 1
38
+
39
+ #
40
+ # Output debug information.
41
+ #
42
+ VERBOSE_DEBUG = 2
43
+
44
+ #
45
+ # Output every objects read
46
+ #
47
+ VERBOSE_TRACE = 3
48
+
49
+ attr_accessor :options
50
+
51
+ def initialize(options = {}) # :nodoc:
52
+ # Type information for indirect objects.
53
+ @deferred_casts = {}
54
+
55
+ # Default options values
56
+ @options =
57
+ {
58
+ verbosity: VERBOSE_INFO, # Verbose level.
59
+ ignore_errors: true, # Try to keep on parsing when errors occur.
60
+ callback: proc {}, # Callback procedure whenever a structure is read.
61
+ logger: $stderr, # Where to output parser messages.
62
+ colorize_log: true # Colorize parser output?
63
+ }
64
+
65
+ @options.update(options)
66
+ @logger = @options[:logger]
67
+ @data = nil
68
+ end
71
69
 
72
- def pos
73
- raise RuntimeError, "Cannot get position, parser has no loaded data." if @data.nil?
70
+ def pos
71
+ raise "Cannot get position, parser has no loaded data." if @data.nil?
74
72
 
75
- @data.pos
76
- end
73
+ @data.pos
74
+ end
77
75
 
78
- def pos=(offset)
79
- raise RuntimeError, "Cannot set position, parser has no loaded data." if @data.nil?
76
+ def pos=(offset)
77
+ raise "Cannot set position, parser has no loaded data." if @data.nil?
80
78
 
81
- @data.pos = offset
82
- end
79
+ @data.pos = offset
80
+ end
83
81
 
84
- def parse(stream)
85
- data =
86
- if stream.respond_to? :read
87
- StringScanner.new(stream.read.force_encoding('binary'))
88
- elsif stream.is_a? ::String
89
- @filename = stream
90
- StringScanner.new(File.binread(@filename))
91
- elsif stream.is_a? StringScanner
92
- stream
93
- else
94
- raise TypeError
95
- end
96
-
97
- @data = data
98
- @data.pos = 0
82
+ def parse(stream)
83
+ data =
84
+ if stream.respond_to? :read
85
+ StringScanner.new(stream.read.force_encoding('binary'))
86
+ elsif stream.is_a? ::String
87
+ @filename = stream
88
+ StringScanner.new(File.binread(@filename))
89
+ elsif stream.is_a? StringScanner
90
+ stream
91
+ else
92
+ raise TypeError
99
93
  end
100
94
 
101
- def parse_object(pos = @data.pos) #:nodoc:
102
- @data.pos = pos
103
-
104
- begin
105
- obj = Object.parse(@data, self)
106
- return if obj.nil?
107
-
108
- obj = try_object_promotion(obj)
109
- trace "Read #{obj.type} object, #{obj.reference}"
110
-
111
- @options[:callback].call(obj)
112
- obj
113
-
114
- rescue UnterminatedObjectError
115
- error $!.message
116
- obj = $!.obj
117
-
118
- Object.skip_until_next_obj(@data)
119
- @options[:callback].call(obj)
120
- obj
121
-
122
- rescue
123
- error "Breaking on: #{(@data.peek(10) + "...").inspect} at offset 0x#{@data.pos.to_s(16)}"
124
- error "Last exception: [#{$!.class}] #{$!.message}"
125
- if not @options[:ignore_errors]
126
- error "Manually fix the file or set :ignore_errors parameter."
127
- raise
128
- end
129
-
130
- debug 'Skipping this indirect object.'
131
- raise if not Object.skip_until_next_obj(@data)
95
+ @data = data
96
+ @data.pos = 0
97
+ end
132
98
 
133
- retry
134
- end
99
+ def parse_object(pos = @data.pos) # :nodoc:
100
+ @data.pos = pos
101
+
102
+ begin
103
+ obj = Object.parse(@data, self)
104
+ return if obj.nil?
105
+
106
+ obj = try_object_promotion(obj)
107
+ trace "Read #{obj.type} object, #{obj.reference}"
108
+
109
+ @options[:callback].call(obj)
110
+ obj
111
+ rescue UnterminatedObjectError
112
+ error $!.message
113
+ obj = $!.obj
114
+
115
+ Object.skip_until_next_obj(@data)
116
+ @options[:callback].call(obj)
117
+ obj
118
+ rescue
119
+ error "Breaking on: #{(@data.peek(10) + "...").inspect} at offset 0x#{@data.pos.to_s(16)}"
120
+ error "Last exception: [#{$!.class}] #{$!.message}"
121
+ if !@options[:ignore_errors]
122
+ error "Manually fix the file or set :ignore_errors parameter."
123
+ raise
135
124
  end
136
125
 
137
- def parse_xreftable(pos = @data.pos) #:nodoc:
138
- @data.pos = pos
126
+ debug 'Skipping this indirect object.'
127
+ raise if !Object.skip_until_next_obj(@data)
139
128
 
140
- begin
141
- info "...Parsing xref table..."
142
- xreftable = XRef::Section.parse(@data)
143
- @options[:callback].call(xreftable)
129
+ retry
130
+ end
131
+ end
144
132
 
145
- xreftable
133
+ def parse_xreftable(pos = @data.pos) # :nodoc:
134
+ @data.pos = pos
146
135
 
147
- rescue
148
- debug "Exception caught while parsing xref table : " + $!.message
149
- warn "Unable to parse xref table! Xrefs might be stored into an XRef stream."
136
+ begin
137
+ info "...Parsing xref table..."
138
+ xreftable = XRef::Section.parse(@data)
139
+ @options[:callback].call(xreftable)
150
140
 
151
- @data.pos -= 'trailer'.length unless @data.skip_until(/trailer/).nil?
141
+ xreftable
142
+ rescue
143
+ debug "Exception caught while parsing xref table : " + $!.message
144
+ warn "Unable to parse xref table! Xrefs might be stored into an XRef stream."
152
145
 
153
- nil
154
- end
155
- end
146
+ @data.pos -= 'trailer'.length unless @data.skip_until(/trailer/).nil?
156
147
 
157
- def parse_trailer(pos = @data.pos) #:nodoc:
158
- @data.pos = pos
148
+ nil
149
+ end
150
+ end
159
151
 
160
- begin
161
- info "...Parsing trailer..."
162
- trailer = Trailer.parse(@data, self)
152
+ def parse_trailer(pos = @data.pos) # :nodoc:
153
+ @data.pos = pos
163
154
 
164
- @options[:callback].call(trailer)
165
- trailer
155
+ begin
156
+ info "...Parsing trailer..."
157
+ trailer = Trailer.parse(@data, self)
166
158
 
167
- rescue
168
- debug "Exception caught while parsing trailer : " + $!.message
169
- warn "Unable to parse trailer!"
159
+ @options[:callback].call(trailer)
160
+ trailer
161
+ rescue
162
+ debug "Exception caught while parsing trailer : " + $!.message
163
+ warn "Unable to parse trailer!"
170
164
 
171
- raise
172
- end
173
- end
165
+ raise
166
+ end
167
+ end
174
168
 
175
- def defer_type_cast(reference, type) #:nodoc:
176
- @deferred_casts[reference] = type
177
- end
169
+ def defer_type_cast(reference, type) # :nodoc:
170
+ @deferred_casts[reference] = type
171
+ end
178
172
 
179
- def target_filename
180
- @filename
181
- end
173
+ def target_filename
174
+ @filename
175
+ end
182
176
 
183
- def target_filesize
184
- @data.string.size if @data
185
- end
177
+ def target_filesize
178
+ @data&.string&.size
179
+ end
186
180
 
187
- def target_data
188
- @data.string.dup if @data
189
- end
181
+ def target_data
182
+ @data.string.dup if @data
183
+ end
190
184
 
191
- def error(msg = "") #:nodoc:
192
- log(VERBOSE_QUIET, 'error', :red, msg)
193
- end
185
+ def error(msg = "") # :nodoc:
186
+ log(VERBOSE_QUIET, 'error', :red, msg)
187
+ end
194
188
 
195
- def warn(msg = "") #:nodoc:
196
- log(VERBOSE_INFO, 'warn ', :yellow, msg)
197
- end
189
+ def warn(msg = "") # :nodoc:
190
+ log(VERBOSE_INFO, 'warn ', :yellow, msg)
191
+ end
198
192
 
199
- def info(msg = "") #:nodoc:
200
- log(VERBOSE_INFO, 'info ', :green, msg)
201
- end
193
+ def info(msg = "") # :nodoc:
194
+ log(VERBOSE_INFO, 'info ', :green, msg)
195
+ end
202
196
 
203
- def debug(msg = "") #:nodoc:
204
- log(VERBOSE_DEBUG, 'debug', :magenta, msg)
205
- end
197
+ def debug(msg = "") # :nodoc:
198
+ log(VERBOSE_DEBUG, 'debug', :magenta, msg)
199
+ end
206
200
 
207
- def trace(msg = "") #:nodoc:
208
- log(VERBOSE_TRACE, 'trace', :cyan, msg)
209
- end
201
+ def trace(msg = "") # :nodoc:
202
+ log(VERBOSE_TRACE, 'trace', :cyan, msg)
203
+ end
210
204
 
211
- def self.init_scanner(stream)
212
- if stream.is_a?(StringScanner)
213
- stream
214
- elsif stream.respond_to?(:to_str)
215
- StringScanner.new(stream.to_str)
216
- else
217
- raise TypeError, "Cannot initialize scanner from #{stream.class}"
218
- end
219
- end
205
+ def self.init_scanner(stream)
206
+ if stream.is_a?(StringScanner)
207
+ stream
208
+ elsif stream.respond_to?(:to_str)
209
+ StringScanner.new(stream.to_str)
210
+ else
211
+ raise TypeError, "Cannot initialize scanner from #{stream.class}"
212
+ end
213
+ end
220
214
 
221
- private
215
+ private
222
216
 
223
- #
224
- # Attempt to promote an object using the deferred casts.
225
- #
226
- def try_object_promotion(obj)
227
- return obj unless Origami::OPTIONS[:enable_type_propagation] and @deferred_casts.key?(obj.reference)
217
+ #
218
+ # Attempt to promote an object using the deferred casts.
219
+ #
220
+ def try_object_promotion(obj)
221
+ return obj unless Origami::OPTIONS[:enable_type_propagation] && @deferred_casts.key?(obj.reference)
228
222
 
229
- types = @deferred_casts[obj.reference]
230
- types = [ types ] unless types.is_a?(::Array)
223
+ types = @deferred_casts[obj.reference]
224
+ types = [types] unless types.is_a?(::Array)
231
225
 
232
- # Promote object if a compatible type is found.
233
- cast_type = types.find {|type| type < obj.class }
234
- if cast_type
235
- obj = obj.cast_to(cast_type, self)
236
- else
237
- obj
238
- end
239
- end
226
+ # Promote object if a compatible type is found.
227
+ cast_type = types.find { |type| type < obj.class }
228
+ if cast_type
229
+ obj = obj.cast_to(cast_type, self)
230
+ else
231
+ obj
232
+ end
233
+ end
240
234
 
241
- def log(level, prefix, color, message) #:nodoc:
242
- return unless @options[:verbosity] >= level
235
+ def log(level, prefix, color, message) # :nodoc:
236
+ return unless @options[:verbosity] >= level
243
237
 
244
- if @options[:colorize_log]
245
- @logger.print "[#{prefix}] ".colorize(color)
246
- @logger.puts message
247
- else
248
- @logger.puts "[#{prefix}] #{message}"
249
- end
250
- end
238
+ if @options[:colorize_log]
239
+ @logger.print "[#{prefix}] ".colorize(color)
240
+ @logger.puts message
241
+ else
242
+ @logger.puts "[#{prefix}] #{message}"
243
+ end
244
+ end
251
245
 
252
- def propagate_types(document)
253
- info "...Propagating types..."
246
+ def propagate_types(document)
247
+ info "...Propagating types..."
254
248
 
255
- current_state = nil
256
- until current_state == @deferred_casts
257
- current_state = @deferred_casts.clone
249
+ current_state = nil
250
+ until current_state == @deferred_casts
251
+ current_state = @deferred_casts.clone
258
252
 
259
- current_state.each_pair do |ref, type|
260
- type = [ type ] unless type.is_a?(::Array)
261
- type.each do |hint|
262
- break if document.cast_object(ref, hint)
263
- end
264
- end
265
- end
253
+ current_state.each_pair do |ref, type|
254
+ type = [type] unless type.is_a?(::Array)
255
+ type.each do |hint|
256
+ break if document.cast_object(ref, hint)
257
+ end
266
258
  end
259
+ end
267
260
  end
268
-
261
+ end
269
262
  end
@@ -1,56 +1,55 @@
1
- =begin
2
-
3
- This file is part of Origami, PDF manipulation framework for Ruby
4
- Copyright (C) 2016 Guillaume Delugré.
5
-
6
- Origami is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- Origami is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with Origami. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- =end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # This file is part of Origami, PDF manipulation framework for Ruby
5
+ # Copyright (C) 2016 Guillaume Delugré.
6
+ #
7
+ # Origami is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Origami is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with Origami. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
20
 
21
21
  require 'origami/parser'
22
22
 
23
23
  module Origami
24
+ class FDF
25
+ class Parser < Origami::Parser
26
+ def parse(stream) # :nodoc:
27
+ super
28
+
29
+ fdf = FDF.new(self)
30
+ fdf.header = FDF::Header.parse(@data)
31
+ @options[:callback].call(fdf.header)
32
+
33
+ loop do
34
+ break if (object = parse_object).nil?
35
+ fdf.insert(object)
36
+ end
24
37
 
25
- class FDF
26
- class Parser < Origami::Parser
27
- def parse(stream) #:nodoc:
28
- super(stream)
29
-
30
- fdf = FDF.new(self)
31
- fdf.header = FDF::Header.parse(@data)
32
- @options[:callback].call(fdf.header)
33
-
34
- loop do
35
- break if (object = parse_object).nil?
36
- fdf.insert(object)
37
- end
38
-
39
- fdf.revisions.first.xreftable = parse_xreftable
40
- fdf.revisions.first.trailer = parse_trailer
41
-
42
- if Origami::OPTIONS[:enable_type_propagation]
43
- trailer = fdf.revisions.first.trailer
38
+ fdf.revisions.first.xreftable = parse_xreftable
39
+ fdf.revisions.first.trailer = parse_trailer
44
40
 
45
- if trailer[:Root].is_a?(Reference)
46
- fdf.cast_object(trailer[:Root], FDF::Catalog)
47
- end
41
+ if Origami::OPTIONS[:enable_type_propagation]
42
+ trailer = fdf.revisions.first.trailer
48
43
 
49
- propagate_types(fdf)
50
- end
44
+ if trailer[:Root].is_a?(Reference)
45
+ fdf.cast_object(trailer[:Root], FDF::Catalog)
46
+ end
51
47
 
52
- fdf
53
- end
48
+ propagate_types(fdf)
54
49
  end
50
+
51
+ fdf
52
+ end
55
53
  end
54
+ end
56
55
  end