combine_pdf 0.2.5 → 0.2.37

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,98 +5,92 @@
5
5
  ## is subject to the same license.
6
6
  ########################################################
7
7
 
8
-
9
-
10
8
  module CombinePDF
11
- #:nodoc: all
12
-
13
- protected
9
+ #:nodoc: all
14
10
 
15
- # @!visibility private
11
+ protected
16
12
 
17
- # This is an internal class. you don't need it.
18
- module PDFFilter
19
- module_function
13
+ # @!visibility private
20
14
 
21
- # @!visibility private
22
-
23
- # deflate / compress an object.
24
- #
25
- # <b>isn't supported yet!</b>
26
- #
27
- # object:: object to compress.
28
- # filter:: filter to use.
29
- def deflate_object object = nil, filter = :none
30
- false
31
- end
15
+ # This is an internal class. you don't need it.
16
+ module PDFFilter
17
+ module_function
32
18
 
33
- # inflate / decompress an object
34
- #
35
- # object:: object to decompress.
36
- def inflate_object object = nil
37
- return false unless object.is_a?(Hash)
38
- filter_array = object[:Filter]
39
- if filter_array.is_a?(Hash) && filter_array[:is_reference_only]
40
- filter_array = filter_array[:referenced_object]
41
- end
42
- if filter_array.is_a?(Symbol)
43
- filter_array = [filter_array]
44
- end
45
- filter_array = [] if filter_array.nil?
46
- params_array = object[:DecodeParms]
47
- if params_array.is_a?(Hash) && params_array[:is_reference_only]
48
- params_array = params_array[:referenced_object]
49
- end
50
- unless params_array.is_a?(Array)
51
- params_array = [params_array]
52
- end
53
- while filter_array[0]
54
- case filter_array[0]
55
- when :FlateDecode
56
- raise_unsupported_error params_array[0] unless params_array[0].nil?
57
- if params_array[0] && params_array[0][:Predictor].to_i > 1
58
- bits = params_array[0][:BitsPerComponent] || 8
59
- predictor = params_array[0][:Predictor].to_i
60
- columns = params_array[0][:Columns] || 1
61
- if (2..9).include? params_array[0][:Predictor].to_i
62
- ####
63
- # prepare TIFF group
64
- elsif (10..15).include? params_array[0][:Predictor].to_i == 2
65
- ####
66
- # prepare PNG group
67
- end
68
- else
69
- inflator = Zlib::Inflate.new
19
+ # @!visibility private
70
20
 
71
- object[:raw_stream_content] = inflator.inflate object[:raw_stream_content]
72
- begin
73
- inflator.finish
74
- rescue
75
- end
76
- inflator.close
77
- object[:Length] = object[:raw_stream_content].bytesize
78
- end
79
- when nil
80
- true
81
- else
82
- return false
83
- end
84
- params_array.shift
85
- filter_array.shift
86
- end
87
- object.delete(:Filter)
88
- true
89
- end
90
-
91
- protected
21
+ # deflate / compress an object.
22
+ #
23
+ # <b>isn't supported yet!</b>
24
+ #
25
+ # object:: object to compress.
26
+ # filter:: filter to use.
27
+ def deflate_object(_object = nil, _filter = :none)
28
+ false
29
+ end
92
30
 
93
- def raise_unsupported_error (object = {})
94
- raise "Filter #{object} unsupported. couldn't deflate object"
95
- end
96
-
97
- end
98
-
99
- end
31
+ # inflate / decompress an object
32
+ #
33
+ # object:: object to decompress.
34
+ def inflate_object(object = nil)
35
+ return false unless object.is_a?(Hash)
36
+ filter_array = object[:Filter]
37
+ if filter_array.is_a?(Hash) && filter_array[:is_reference_only]
38
+ filter_array = filter_array[:referenced_object]
39
+ end
40
+ filter_array = [filter_array] if filter_array.is_a?(Symbol)
41
+ filter_array = [] if filter_array.nil?
42
+ params_array = object[:DecodeParms]
43
+ if params_array.is_a?(Hash) && params_array[:is_reference_only]
44
+ params_array = params_array[:referenced_object]
45
+ end
46
+ params_array = [params_array] unless params_array.is_a?(Array)
47
+ object[:Filter] = filter_array
48
+ object[:DecodeParms] = params_array
49
+ while filter_array[0]
50
+ case filter_array[0]
51
+ when :FlateDecode
52
+ raise_unsupported_error params_array[0] unless params_array[0].nil?
53
+ if params_array[0] && params_array[0][:Predictor].to_i > 1
54
+ bits = params_array[0][:BitsPerComponent] || 8
55
+ predictor = params_array[0][:Predictor].to_i
56
+ columns = params_array[0][:Columns] || 1
57
+ if (2..9).cover? params_array[0][:Predictor].to_i
58
+ ####
59
+ # prepare TIFF group
60
+ raise_unsupported_error params_array[0]
61
+ elsif (10..15).cover? params_array[0][:Predictor].to_i == 2
62
+ ####
63
+ # prepare PNG group
64
+ raise_unsupported_error params_array[0]
65
+ end
66
+ else
67
+ inflator = Zlib::Inflate.new
100
68
 
69
+ object[:raw_stream_content] = inflator.inflate object[:raw_stream_content]
70
+ begin
71
+ inflator.finish
72
+ rescue
73
+ end
74
+ inflator.close
75
+ object[:Length] = object[:raw_stream_content].bytesize
76
+ end
77
+ when nil
78
+ true
79
+ else
80
+ return false
81
+ end
82
+ params_array.shift
83
+ filter_array.shift
84
+ end
85
+ object.delete :Filter
86
+ object.delete :DecodeParms
87
+ true
88
+ end
101
89
 
90
+ protected
102
91
 
92
+ def raise_unsupported_error(object = {})
93
+ raise "Filter #{object} unsupported. couldn't deflate object"
94
+ end
95
+ end
96
+ end