origamindee 3.0.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 (139) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +89 -0
  3. data/COPYING.LESSER +165 -0
  4. data/README.md +131 -0
  5. data/bin/config/pdfcop.conf.yml +236 -0
  6. data/bin/pdf2pdfa +87 -0
  7. data/bin/pdf2ruby +333 -0
  8. data/bin/pdfcop +476 -0
  9. data/bin/pdfdecompress +97 -0
  10. data/bin/pdfdecrypt +91 -0
  11. data/bin/pdfencrypt +113 -0
  12. data/bin/pdfexplode +223 -0
  13. data/bin/pdfextract +277 -0
  14. data/bin/pdfmetadata +143 -0
  15. data/bin/pdfsh +12 -0
  16. data/bin/shell/console.rb +128 -0
  17. data/bin/shell/hexdump.rb +59 -0
  18. data/bin/shell/irbrc +69 -0
  19. data/examples/README.md +34 -0
  20. data/examples/attachments/attachment.rb +38 -0
  21. data/examples/attachments/nested_document.rb +51 -0
  22. data/examples/encryption/encryption.rb +28 -0
  23. data/examples/events/events.rb +72 -0
  24. data/examples/flash/flash.rb +37 -0
  25. data/examples/flash/helloworld.swf +0 -0
  26. data/examples/forms/javascript.rb +54 -0
  27. data/examples/forms/xfa.rb +115 -0
  28. data/examples/javascript/hello_world.rb +22 -0
  29. data/examples/javascript/js_emulation.rb +54 -0
  30. data/examples/loop/goto.rb +32 -0
  31. data/examples/loop/named.rb +33 -0
  32. data/examples/signature/signature.rb +65 -0
  33. data/examples/uri/javascript.rb +56 -0
  34. data/examples/uri/open-uri.rb +21 -0
  35. data/examples/uri/submitform.rb +47 -0
  36. data/lib/origami/3d.rb +364 -0
  37. data/lib/origami/acroform.rb +321 -0
  38. data/lib/origami/actions.rb +318 -0
  39. data/lib/origami/annotations.rb +711 -0
  40. data/lib/origami/array.rb +242 -0
  41. data/lib/origami/boolean.rb +90 -0
  42. data/lib/origami/catalog.rb +418 -0
  43. data/lib/origami/collections.rb +144 -0
  44. data/lib/origami/compound.rb +161 -0
  45. data/lib/origami/destinations.rb +252 -0
  46. data/lib/origami/dictionary.rb +192 -0
  47. data/lib/origami/encryption.rb +1084 -0
  48. data/lib/origami/extensions/fdf.rb +347 -0
  49. data/lib/origami/extensions/ppklite.rb +422 -0
  50. data/lib/origami/filespec.rb +197 -0
  51. data/lib/origami/filters/ascii.rb +211 -0
  52. data/lib/origami/filters/ccitt/tables.rb +267 -0
  53. data/lib/origami/filters/ccitt.rb +357 -0
  54. data/lib/origami/filters/crypt.rb +38 -0
  55. data/lib/origami/filters/dct.rb +54 -0
  56. data/lib/origami/filters/flate.rb +69 -0
  57. data/lib/origami/filters/jbig2.rb +57 -0
  58. data/lib/origami/filters/jpx.rb +47 -0
  59. data/lib/origami/filters/lzw.rb +170 -0
  60. data/lib/origami/filters/predictors.rb +292 -0
  61. data/lib/origami/filters/runlength.rb +129 -0
  62. data/lib/origami/filters.rb +364 -0
  63. data/lib/origami/font.rb +196 -0
  64. data/lib/origami/functions.rb +79 -0
  65. data/lib/origami/graphics/colors.rb +230 -0
  66. data/lib/origami/graphics/instruction.rb +98 -0
  67. data/lib/origami/graphics/path.rb +182 -0
  68. data/lib/origami/graphics/patterns.rb +174 -0
  69. data/lib/origami/graphics/render.rb +62 -0
  70. data/lib/origami/graphics/state.rb +149 -0
  71. data/lib/origami/graphics/text.rb +225 -0
  72. data/lib/origami/graphics/xobject.rb +918 -0
  73. data/lib/origami/graphics.rb +38 -0
  74. data/lib/origami/header.rb +75 -0
  75. data/lib/origami/javascript.rb +713 -0
  76. data/lib/origami/linearization.rb +330 -0
  77. data/lib/origami/metadata.rb +172 -0
  78. data/lib/origami/name.rb +135 -0
  79. data/lib/origami/null.rb +65 -0
  80. data/lib/origami/numeric.rb +181 -0
  81. data/lib/origami/obfuscation.rb +245 -0
  82. data/lib/origami/object.rb +760 -0
  83. data/lib/origami/optionalcontent.rb +183 -0
  84. data/lib/origami/outline.rb +54 -0
  85. data/lib/origami/outputintents.rb +85 -0
  86. data/lib/origami/page.rb +722 -0
  87. data/lib/origami/parser.rb +269 -0
  88. data/lib/origami/parsers/fdf.rb +56 -0
  89. data/lib/origami/parsers/pdf/lazy.rb +176 -0
  90. data/lib/origami/parsers/pdf/linear.rb +122 -0
  91. data/lib/origami/parsers/pdf.rb +118 -0
  92. data/lib/origami/parsers/ppklite.rb +57 -0
  93. data/lib/origami/pdf.rb +1108 -0
  94. data/lib/origami/reference.rb +134 -0
  95. data/lib/origami/signature.rb +702 -0
  96. data/lib/origami/stream.rb +705 -0
  97. data/lib/origami/string.rb +444 -0
  98. data/lib/origami/template/patterns.rb +56 -0
  99. data/lib/origami/template/widgets.rb +151 -0
  100. data/lib/origami/trailer.rb +190 -0
  101. data/lib/origami/tree.rb +62 -0
  102. data/lib/origami/version.rb +23 -0
  103. data/lib/origami/webcapture.rb +100 -0
  104. data/lib/origami/xfa/config.rb +453 -0
  105. data/lib/origami/xfa/connectionset.rb +146 -0
  106. data/lib/origami/xfa/datasets.rb +49 -0
  107. data/lib/origami/xfa/localeset.rb +42 -0
  108. data/lib/origami/xfa/package.rb +59 -0
  109. data/lib/origami/xfa/pdf.rb +73 -0
  110. data/lib/origami/xfa/signature.rb +42 -0
  111. data/lib/origami/xfa/sourceset.rb +43 -0
  112. data/lib/origami/xfa/stylesheet.rb +44 -0
  113. data/lib/origami/xfa/template.rb +1691 -0
  114. data/lib/origami/xfa/xdc.rb +42 -0
  115. data/lib/origami/xfa/xfa.rb +146 -0
  116. data/lib/origami/xfa/xfdf.rb +43 -0
  117. data/lib/origami/xfa/xmpmeta.rb +43 -0
  118. data/lib/origami/xfa.rb +62 -0
  119. data/lib/origami/xreftable.rb +557 -0
  120. data/lib/origami.rb +47 -0
  121. data/test/dataset/calc.pdf +85 -0
  122. data/test/dataset/crypto.pdf +36 -0
  123. data/test/dataset/empty.pdf +49 -0
  124. data/test/test_actions.rb +27 -0
  125. data/test/test_annotations.rb +68 -0
  126. data/test/test_forms.rb +30 -0
  127. data/test/test_native_types.rb +83 -0
  128. data/test/test_object_tree.rb +33 -0
  129. data/test/test_pages.rb +60 -0
  130. data/test/test_pdf.rb +20 -0
  131. data/test/test_pdf_attachment.rb +34 -0
  132. data/test/test_pdf_create.rb +24 -0
  133. data/test/test_pdf_encrypt.rb +102 -0
  134. data/test/test_pdf_parse.rb +134 -0
  135. data/test/test_pdf_parse_lazy.rb +69 -0
  136. data/test/test_pdf_sign.rb +97 -0
  137. data/test/test_streams.rb +184 -0
  138. data/test/test_xrefs.rb +67 -0
  139. metadata +280 -0
@@ -0,0 +1,357 @@
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
20
+
21
+ require 'origami/filters/ccitt/tables'
22
+
23
+ module Origami
24
+
25
+ module Filter
26
+
27
+ class InvalidCCITTFaxDataError < DecodeError #:nodoc:
28
+ end
29
+
30
+ class CCITTFaxFilterError < Error #:nodoc:
31
+ end
32
+
33
+ #
34
+ # Class representing a Filter used to encode and decode data with CCITT-facsimile compression algorithm.
35
+ #
36
+ class CCITTFax
37
+ include Filter
38
+
39
+ class DecodeParms < Dictionary
40
+ include StandardObject
41
+
42
+ field :K, :Type => Integer, :Default => 0
43
+ field :EndOfLine, :Type => Boolean, :Default => false
44
+ field :EncodedByteAlign, :Type => Boolean, :Default => false
45
+ field :Columns, :Type => Integer, :Default => 1728
46
+ field :Rows, :Type => Integer, :Default => 0
47
+ field :EndOfBlock, :Type => Boolean, :Default => true
48
+ field :BlackIs1, :Type => Boolean, :Default => false
49
+ field :DamagedRowsBeforeError, :Type => :Integer, :Default => 0
50
+ end
51
+
52
+ EOL = codeword('000000000001')
53
+ RTC = codeword('000000000001' * 6)
54
+
55
+ #
56
+ # Creates a new CCITT Fax Filter.
57
+ #
58
+ def initialize(parameters = {})
59
+ super(DecodeParms.new(parameters))
60
+ end
61
+
62
+ #
63
+ # Encodes data using CCITT-facsimile compression method.
64
+ #
65
+ def encode(stream)
66
+ mode = @params.key?(:K) ? @params.K.value : 0
67
+ colors = (@params.BlackIs1 == true) ? [0,1] : [1,0]
68
+ use_eob = (@params.EndOfBlock.nil? or @params.EndOfBlock == true)
69
+ use_eol = (@params.EndOfLine == true)
70
+ white, _black = colors
71
+
72
+ bitr = Utils::BitReader.new(stream)
73
+ bitw = Utils::BitWriter.new
74
+
75
+ unless mode.is_a?(::Integer) and mode <= 0
76
+ raise NotImplementedError.new("CCITT encoding scheme not supported", input_data: stream)
77
+ end
78
+
79
+ # Use a single row if no width has been set.
80
+ @params[:Columns] ||= stream.size * 8
81
+ columns = @params.Columns.value
82
+
83
+ unless columns.is_a?(::Integer) and columns >= 0
84
+ raise CCITTFaxFilterError.new("Invalid value for parameter `Columns'", input_data: stream)
85
+ end
86
+
87
+ if columns > 0
88
+ # Group 4 requires an imaginary white line
89
+ if mode < 0
90
+ prev_line = Utils::BitWriter.new
91
+ write_bit_range(prev_line, white, columns)
92
+ prev_line = Utils::BitReader.new(prev_line.final.to_s)
93
+ end
94
+
95
+ until bitr.eod?
96
+ # Emit line synchronization code.
97
+ bitw.write(*EOL) if use_eol
98
+
99
+ case
100
+ when mode == 0
101
+ encode_one_dimensional_line(bitr, bitw, columns, colors)
102
+ when mode < 0
103
+ encode_two_dimensional_line(bitr, bitw, columns, colors, prev_line)
104
+ end
105
+ end
106
+ end
107
+
108
+ # Emit return-to-control code.
109
+ bitw.write(*RTC) if use_eob
110
+
111
+ bitw.final.to_s
112
+ end
113
+
114
+ #
115
+ # Decodes data using CCITT-facsimile compression method.
116
+ #
117
+ def decode(stream)
118
+ mode = @params.key?(:K) ? @params.K.value : 0
119
+
120
+ unless mode.is_a?(::Integer) and mode <= 0
121
+ raise NotImplementedError.new("CCITT encoding scheme not supported", input_data: stream)
122
+ end
123
+
124
+ columns = @params.has_key?(:Columns) ? @params.Columns.value : 1728
125
+ unless columns.is_a?(::Integer) and columns >= 0
126
+ raise CCITTFaxFilterError.new("Invalid value for parameter `Columns'", input_data: stream)
127
+ end
128
+
129
+ colors = (@params.BlackIs1 == true) ? [0,1] : [1,0]
130
+ white, _black = colors
131
+ params =
132
+ {
133
+ is_aligned?: (@params.EncodedByteAlign == true),
134
+ has_eob?: (@params.EndOfBlock.nil? or @params.EndOfBlock == true),
135
+ has_eol?: (@params.EndOfLine == true)
136
+ }
137
+
138
+ unless params[:has_eob?]
139
+ rows = @params.key?(:Rows) ? @params.Rows.value : 0
140
+
141
+ unless rows.is_a?(::Integer) and rows >= 0
142
+ raise CCITTFaxFilterError.new("Invalid value for parameter `Rows'", input_data: stream)
143
+ end
144
+ end
145
+
146
+ bitr = Utils::BitReader.new(stream)
147
+ bitw = Utils::BitWriter.new
148
+
149
+ # Group 4 requires an imaginary white line
150
+ if columns > 0 and mode < 0
151
+ prev_line = Utils::BitWriter.new
152
+ write_bit_range(prev_line, white, columns)
153
+ prev_line = Utils::BitReader.new(prev_line.final.to_s)
154
+ end
155
+
156
+ until bitr.eod? or rows == 0
157
+ # realign the read line on a 8-bit boundary if required
158
+ align_input(bitr) if params[:is_aligned?]
159
+
160
+ # received return-to-control code
161
+ if params[:has_eob?] and bitr.peek(RTC[1]) == RTC[0]
162
+ bitr.pos += RTC[1]
163
+ break
164
+ end
165
+
166
+ break if columns == 0
167
+
168
+ # checking for the presence of EOL
169
+ if bitr.peek(EOL[1]) != EOL[0]
170
+ raise InvalidCCITTFaxDataError.new(
171
+ "No end-of-line pattern found (at bit pos #{bitr.pos}/#{bitr.size}})",
172
+ input_data: stream,
173
+ decoded_data: bitw.final.to_s
174
+ ) if params[:has_eol?]
175
+ else
176
+ bitr.pos += EOL[1]
177
+ end
178
+
179
+ begin
180
+ case
181
+ when mode == 0
182
+ decode_one_dimensional_line(bitr, bitw, columns, colors)
183
+ when mode < 0
184
+ decode_two_dimensional_line(bitr, bitw, columns, colors, prev_line)
185
+ end
186
+ rescue DecodeError => error
187
+ error.input_data = stream
188
+ error.decoded_data = bitw.final.to_s
189
+
190
+ raise error
191
+ end
192
+
193
+ rows -= 1 unless params[:has_eob?]
194
+ end
195
+
196
+ bitw.final.to_s
197
+ end
198
+
199
+ private
200
+
201
+ def encode_one_dimensional_line(input, output, columns, colors) #:nodoc:
202
+ scan_len = 0
203
+ white, _black = colors
204
+ current_color = white
205
+ length = 0
206
+
207
+ return if columns == 0
208
+
209
+ # Process each bit in line.
210
+ loop do
211
+ if input.read(1) == current_color
212
+ scan_len += 1
213
+ else
214
+ if current_color == white
215
+ put_white_bits(output, scan_len)
216
+ else
217
+ put_black_bits(output, scan_len)
218
+ end
219
+
220
+ current_color ^= 1
221
+ scan_len = 1
222
+ end
223
+
224
+ length += 1
225
+ break if length == columns
226
+ end
227
+
228
+ if current_color == white
229
+ put_white_bits(output, scan_len)
230
+ else
231
+ put_black_bits(output, scan_len)
232
+ end
233
+
234
+ # Align encoded lign on a 8-bit boundary.
235
+ align_output(write) if @params.EncodedByteAlign == true
236
+ end
237
+
238
+ # Align input to a byte boundary.
239
+ def align_input(input)
240
+ return if input.pos % 8 == 0
241
+ input.pos += 8 - (input.pos % 8)
242
+ end
243
+
244
+ # Align output to a byte boundary by adding some zeros.
245
+ def align_output(output)
246
+ return if output.pos % 8 == 0
247
+ output.write(0, 8 - (output.pos % 8))
248
+ end
249
+
250
+ def encode_two_dimensional_line(_input, _output, _columns, _colors, _prev_line) #:nodoc:
251
+ raise NotImplementedError "CCITT two-dimensional encoding scheme not supported."
252
+ end
253
+
254
+ def decode_one_dimensional_line(input, output, columns, colors) #:nodoc:
255
+ white, _black = colors
256
+ current_color = white
257
+
258
+ line_length = 0
259
+ while line_length < columns
260
+ if current_color == white
261
+ bit_length = get_white_bits(input)
262
+ else
263
+ bit_length = get_black_bits(input)
264
+ end
265
+
266
+ raise InvalidCCITTFaxDataError, "Unfinished line (at bit pos #{input.pos}/#{input.size}})" if bit_length.nil?
267
+
268
+ line_length += bit_length
269
+
270
+ raise InvalidCCITTFaxDataError, "Line is too long (at bit pos #{input.pos}/#{input.size}})" if line_length > columns
271
+
272
+ write_bit_range(output, current_color, bit_length)
273
+ current_color ^= 1
274
+ end
275
+ end
276
+
277
+ def decode_two_dimensional_line(_input, _output, _columns, _colors, _prev_line) #:nodoc:
278
+ raise NotImplementedError, "CCITT two-dimensional decoding scheme not supported."
279
+ end
280
+
281
+ def get_white_bits(bitr) #:nodoc:
282
+ get_color_bits(bitr, WHITE_CONFIGURATION_DECODE_TABLE, WHITE_TERMINAL_DECODE_TABLE)
283
+ end
284
+
285
+ def get_black_bits(bitr) #:nodoc:
286
+ get_color_bits(bitr, BLACK_CONFIGURATION_DECODE_TABLE, BLACK_TERMINAL_DECODE_TABLE)
287
+ end
288
+
289
+ def get_color_bits(bitr, config_words, term_words) #:nodoc:
290
+ bits = 0
291
+ check_conf = true
292
+
293
+ while check_conf
294
+ check_conf = false
295
+ (2..13).each do |length|
296
+ codeword = bitr.peek(length)
297
+ config_value = config_words[[codeword, length]]
298
+
299
+ if config_value
300
+ bitr.pos += length
301
+ bits += config_value
302
+ check_conf = true if config_value == 2560
303
+ break
304
+ end
305
+ end
306
+ end
307
+
308
+ (2..13).each do |length|
309
+ codeword = bitr.peek(length)
310
+ term_value = term_words[[codeword, length]]
311
+
312
+ if term_value
313
+ bitr.pos += length
314
+ bits += term_value
315
+
316
+ return bits
317
+ end
318
+ end
319
+
320
+ nil
321
+ end
322
+
323
+ def lookup_bits(table, codeword, length)
324
+ table.rassoc [codeword, length]
325
+ end
326
+
327
+ def put_white_bits(bitw, length) #:nodoc:
328
+ put_color_bits(bitw, length, WHITE_CONFIGURATION_ENCODE_TABLE, WHITE_TERMINAL_ENCODE_TABLE)
329
+ end
330
+
331
+ def put_black_bits(bitw, length) #:nodoc:
332
+ put_color_bits(bitw, length, BLACK_CONFIGURATION_ENCODE_TABLE, BLACK_TERMINAL_ENCODE_TABLE)
333
+ end
334
+
335
+ def put_color_bits(bitw, length, config_words, term_words) #:nodoc:
336
+ while length > 2559
337
+ bitw.write(*config_words[2560])
338
+ length -= 2560
339
+ end
340
+
341
+ if length > 63
342
+ conf_length = (length >> 6) << 6
343
+ bitw.write(*config_words[conf_length])
344
+ length -= conf_length
345
+ end
346
+
347
+ bitw.write(*term_words[length])
348
+ end
349
+
350
+ def write_bit_range(bitw, bit_value, length) #:nodoc:
351
+ bitw.write((bit_value << length) - bit_value, length)
352
+ end
353
+ end
354
+ CCF = CCITTFax
355
+
356
+ end
357
+ end
@@ -0,0 +1,38 @@
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
20
+
21
+ module Origami
22
+
23
+ module Filter
24
+
25
+ module Crypt
26
+
27
+ #
28
+ # Parameters for a Crypt Filter.
29
+ #
30
+ class DecodeParms < Dictionary
31
+ include StandardObject
32
+
33
+ field :Type, :Type => Name, :Default => :CryptFilterDecodeParms
34
+ field :Name, :Type => Name, :Default => :Identity
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,54 @@
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
20
+
21
+ module Origami
22
+
23
+ module Filter
24
+
25
+ #
26
+ # Class representing a Filter used to encode and decode data with DCT (JPEG) compression algorithm.
27
+ #
28
+ class DCT
29
+ include Filter
30
+
31
+ class DecodeParms < Dictionary
32
+ include StandardObject
33
+
34
+ field :ColorTransform, :Type => Integer
35
+ end
36
+
37
+ def initialize(parameters = {})
38
+ super(DecodeParms.new(parameters))
39
+ end
40
+
41
+ def encode(stream)
42
+ raise NotImplementedError.new("DCT filter is not supported", input_data: stream)
43
+ end
44
+
45
+ #
46
+ # DCTDecode implies that data is a JPEG image container.
47
+ #
48
+ def decode(stream)
49
+ raise NotImplementedError.new("DCT filter is not supported", input_data: stream)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,69 @@
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
20
+
21
+ require 'zlib'
22
+ require 'origami/filters/predictors'
23
+
24
+ module Origami
25
+
26
+ module Filter
27
+
28
+ class InvalidFlateDataError < DecodeError; end #:nodoc:
29
+
30
+ #
31
+ # Class representing a Filter used to encode and decode data with zlib/Flate compression algorithm.
32
+ #
33
+ class Flate
34
+ include Filter
35
+ include Predictor
36
+
37
+ EOD = 257 #:nodoc:
38
+
39
+ #
40
+ # Encodes data using zlib/Deflate compression method.
41
+ # _stream_:: The data to encode.
42
+ #
43
+ def encode(stream)
44
+ Zlib::Deflate.deflate(pre_prediction(stream), Zlib::BEST_COMPRESSION)
45
+ end
46
+
47
+ #
48
+ # Decodes data using zlib/Inflate decompression method.
49
+ # _stream_:: The data to decode.
50
+ #
51
+ def decode(stream)
52
+ zlib_stream = Zlib::Inflate.new
53
+ begin
54
+ uncompressed = zlib_stream.inflate(stream)
55
+ rescue Zlib::DataError => zlib_except
56
+ uncompressed = zlib_stream.flush_next_out
57
+
58
+ unless Origami::OPTIONS[:ignore_zlib_errors]
59
+ raise InvalidFlateDataError.new(zlib_except.message, input_data: stream, decoded_data: uncompressed)
60
+ end
61
+ end
62
+
63
+ post_prediction(uncompressed)
64
+ end
65
+ end
66
+ Fl = Flate
67
+
68
+ end
69
+ end
@@ -0,0 +1,57 @@
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
20
+
21
+ module Origami
22
+
23
+ module Filter
24
+
25
+ #
26
+ # Class representing a Filter used to encode and decode data with JBIG2 compression algorithm.
27
+ #
28
+ class JBIG2
29
+ include Filter
30
+
31
+ class DecodeParms < Dictionary
32
+ include StandardObject
33
+
34
+ field :JBIG2Globals, :Type => Stream
35
+ end
36
+
37
+ def initialize(parameters = {})
38
+ super(DecodeParms.new(parameters))
39
+ end
40
+
41
+ #
42
+ # Not supported.
43
+ #
44
+ def encode(stream)
45
+ raise NotImplementedError.new("#{self.class} is not yet supported", input_data: stream)
46
+ end
47
+
48
+ #
49
+ # Not supported.
50
+ #
51
+ def decode(stream)
52
+ raise NotImplementedError.new("#{self.class} is not yet supported", input_data: stream)
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,47 @@
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
20
+
21
+ module Origami
22
+
23
+ module Filter
24
+
25
+ #
26
+ # Class representing a Filter used to encode and decode data with JPX compression algorithm.
27
+ #
28
+ class JPX
29
+ include Filter
30
+
31
+ #
32
+ # Not supported.
33
+ #
34
+ def encode(stream)
35
+ raise NotImplementedError.new("#{self.class} is not yet supported", input_data: stream)
36
+ end
37
+
38
+ #
39
+ # Not supported.
40
+ #
41
+ def decode(stream)
42
+ raise NotImplementedError.new("#{self.class} is not yet supported", input_data: stream)
43
+ end
44
+ end
45
+
46
+ end
47
+ end