pdf-core 0.4.0 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7f20557e9a614c10244d01e2b1ed78d4434cef6c
4
- data.tar.gz: 8668979b6592e45d81d8274e8acd387642e5a3fb
2
+ SHA256:
3
+ metadata.gz: 23799dd91a7e3063a84724ecbdea6989de1b7131f1727bc6923c76b1637f0a87
4
+ data.tar.gz: 73538fe3357a195e9c3a39f7dfb1e498d0c3a49fc3c8cc6b4b0e72cc054dbd54
5
5
  SHA512:
6
- metadata.gz: 68d6e43d2579ff909d9cabc4a9d641648e9830685a2d2b76d24fe85046e48ea22fb7bbb4bf005d3442d4595b44b18dddd29dad37f99ecd32a3b9fa515490503e
7
- data.tar.gz: f6f49f285719b0d72d3113bc465db2e588d52c2b1c096c7285cb56f43744a31122d4a0c8338ab88353b29555bb352d4c2cc662eac2c73164948dda3ca5c72933
6
+ metadata.gz: e90a4a8303c8633452743ad491b21c57034551beb284458da03c0c69d135c41bcfe349027ed7ded6bf55e71f8f7dee0997898342cea7f4ed8725bdb1de1182fc
7
+ data.tar.gz: 5d048fdd3adf42181118c0340a2df17ec60e9c32e92f4699bc7e2929d508ee70d5d7888ce7d9a8b12ec06aae8423158ff184321f87aa10449f8ddc721b239f22
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # annotations.rb : Implements low-level annotation support for PDF
4
4
  #
@@ -10,43 +10,81 @@ module PDF
10
10
  module Core
11
11
  # Provides very low-level support for annotations.
12
12
  #
13
- module Annotations #:nodoc:
14
-
15
- # Adds a new annotation (section 8.4 in PDF spec) to the current page.
16
- # +options+ must be a Hash describing the annotation.
13
+ # @api private
14
+ module Annotations
15
+ # Adds a new annotation (section *8.4 Annotations* in PDF 1.7 spec) to the
16
+ # current page.
17
+ #
18
+ # @param options [Hash] Annotation options. This is basically an `Annot`
19
+ # dict as decribed in the PDF spec.
20
+ # @option options [Symbol<:Text, :Link, :FreeText, :Line, :Square,
21
+ # :Circle, :Polygon, :PolyLine, :Highlight, :Underline, :Squiggly,
22
+ # :StrikeOut, :Stamp, :Caret, :Ink, :Popup, :FileAttachment, :Sound,
23
+ # :Movie, :Widget, :Screen, :PrinterMark, :TrapNet, :Watermark, :3D>]
24
+ # :Subtype The type of annotation
25
+ # @option options [Array<Numeric, 4>] :Rect The annotation rectangle
26
+ # @option options [String] :Contents Text to be displayed for the
27
+ # annotation or, if this type of annotation does not display text, an
28
+ # alternate description of the annotation's contents in human-readable
29
+ # form.
30
+ # @option options [PDF::Core::Reference] :P An indirect reference to the
31
+ # page object with which this annotation is associated.
32
+ # @option options [String] :NM The annotation name, a text string uniquely
33
+ # identifying it among all the annotations on its page.
34
+ # @option options [Date, Time, String] :M The date and time when the
35
+ # annotation was most recently modified
36
+ # @option options [Integer] :F A set of flags specifying various
37
+ # characteristics of the annotation
38
+ # @option options [Hash] :AP An appearance dictionary specifying how the
39
+ # annotation is presented visually on the page
40
+ # @option options [Symbol] :AS The annotation's appearance state
41
+ # @option options [Array<(Numeric, Array<Numeric>)>] :Border the
42
+ # characteristics of the annotation's border
43
+ # @option options [Array<Float>] :C Color
44
+ # @option options [Integer] :StructParent The integer key of the
45
+ # annotation's entry in the structural parent tree
46
+ # @option options [Hash] :OC An optional content group or optional content
47
+ # membership dictionary
17
48
  #
49
+ # @return [options]
18
50
  def annotate(options)
19
51
  state.page.dictionary.data[:Annots] ||= []
20
52
  options = sanitize_annotation_hash(options)
21
53
  state.page.dictionary.data[:Annots] << ref!(options)
22
- return options
54
+ options
23
55
  end
24
56
 
25
- # A convenience method for creating Text annotations. +rect+ must be an array
26
- # of four numbers, describing the bounds of the annotation. +contents+ should
27
- # be a string, to be shown when the annotation is activated.
57
+ # A convenience method for creating `Text` annotations.
28
58
  #
29
- def text_annotation(rect, contents, options={})
30
- options = options.merge(:Subtype => :Text, :Rect => rect, :Contents => contents)
59
+ # @param rect [Array<Numeric>] An array of four numbers,
60
+ # describing the bounds of the annotation.
61
+ # @param contents [String] Contents of the annotation
62
+ #
63
+ # @return [Hash] Annotation dictionary
64
+ def text_annotation(rect, contents, options = {})
65
+ options = options.merge(Subtype: :Text, Rect: rect, Contents: contents)
31
66
  annotate(options)
32
67
  end
33
68
 
34
- # A convenience method for creating Link annotations. +rect+ must be an array
35
- # of four numbers, describing the bounds of the annotation. The +options+ hash
36
- # should include either :Dest (describing the target destination, usually as a
37
- # string that has been recorded in the document's Dests tree), or :A (describing
38
- # an action to perform on clicking the link), or :PA (for describing a URL to
39
- # link to).
69
+ # A convenience method for creating `Link` annotations.
70
+ #
71
+ # @param rect [Array<Numeric>] An array of four numbers,
72
+ # describing the bounds of the annotation.
73
+ # @param options [Hash] Should include either `:Dest` (describing the target
74
+ # destination, usually as a string that has been recorded in the
75
+ # document's `Dests` tree), or `:A` (describing an action to perform on
76
+ # clicking the link), or `:PA` (for describing a URL to link to).
40
77
  #
41
- def link_annotation(rect, options={})
42
- options = options.merge(:Subtype => :Link, :Rect => rect)
78
+ # @return [Hash] Annotation dictionary
79
+ def link_annotation(rect, options = {})
80
+ options = options.merge(Subtype: :Link, Rect: rect)
43
81
  annotate(options)
44
82
  end
45
83
 
46
84
  private
47
85
 
48
86
  def sanitize_annotation_hash(options)
49
- options = options.merge(:Type => :Annot)
87
+ options = options.merge(Type: :Annot)
50
88
 
51
89
  if options[:Dest].is_a?(String)
52
90
  options[:Dest] = PDF::Core::LiteralString.new(options[:Dest])
@@ -54,7 +92,6 @@ module PDF
54
92
 
55
93
  options
56
94
  end
57
-
58
95
  end
59
96
  end
60
97
  end
@@ -1,9 +1,12 @@
1
- # encoding: utf-8
2
- module PDF
1
+ # frozen_string_literal: true
2
+
3
+ module PDF
3
4
  module Core
4
5
  # This is used to differentiate strings that must be encoded as
5
6
  # a byte string, such as binary data from encrypted strings.
6
- class ByteString < String #:nodoc:
7
+ #
8
+ # @api private
9
+ class ByteString < String
7
10
  end
8
11
  end
9
12
  end
@@ -1,88 +1,131 @@
1
- # encoding: utf-8
2
-
3
- # Implements destination support for PDF
4
- #
5
- # Copyright November 2008, Jamis Buck. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
1
+ # frozen_string_literal: true
8
2
 
9
3
  module PDF
10
4
  module Core
11
- module Destinations #:nodoc:
12
-
13
- # The maximum number of children to fit into a single node in the Dests tree.
14
- NAME_TREE_CHILDREN_LIMIT = 20 #:nodoc:
5
+ # Implements destination support for PDF
6
+ #
7
+ # @api private
8
+ module Destinations
9
+ # The maximum number of children to fit into a single node in the Dests
10
+ # tree.
11
+ #
12
+ # @private
13
+ NAME_TREE_CHILDREN_LIMIT = 20
15
14
 
16
- # The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names).
17
- # This name tree is used to store named destinations (PDF spec 8.2.1).
18
- # (For more on name trees, see section 3.8.4 in the PDF spec.)
15
+ # The `:Dests` name tree in the Name dictionary. This name tree is used to
16
+ # store named destinations (PDF 1.7 spec 8.2.1). (For more on name trees,
17
+ # see section 3.8.5 in the PDF 1.7 spec.)
19
18
  #
19
+ # @return [PDF::Core::Reference<PDF::Core::NameTree::Node>]
20
+ # @see Prawn::Document::Internal#names
20
21
  def dests
21
- names.data[:Dests] ||= ref!(PDF::Core::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT))
22
+ names.data[:Dests] ||= ref!(
23
+ PDF::Core::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT),
24
+ )
22
25
  end
23
26
 
24
- # Adds a new destination to the dests name tree (see #dests). The
25
- # +reference+ parameter will be converted into a PDF::Core::Reference if
26
- # it is not already one.
27
+ # Adds a new destination to the Dests name tree.
27
28
  #
29
+ # @param name [Symbol] Destination name
30
+ # @param reference [PDF::Core::Reference, Array, Hash] Destination
31
+ # definition, will be converted into a {PDF::Core::Reference} if it is
32
+ # not already one.
33
+ # @return [void]
34
+ # @see #dests
28
35
  def add_dest(name, reference)
29
36
  reference = ref!(reference) unless reference.is_a?(PDF::Core::Reference)
30
37
  dests.data.add(name, reference)
31
38
  end
32
39
 
33
- # Return a Dest specification for a specific location (and optional zoom
40
+ # Builds a Dest specification for a specific location (and optional zoom
34
41
  # level).
35
42
  #
36
- def dest_xyz(left, top, zoom=nil, dest_page=page)
43
+ # @param left [Numeric]
44
+ # @param top [Numeric]
45
+ # @param zoom [Numeric]
46
+ # @param dest_page [PDF::Core::Page]
47
+ # @return [Array(PDF::Core::Reference, :XYZ, Numeric, Numeric, [Numeric, null])] a Dest
48
+ # specification for a specific location
49
+ def dest_xyz(left, top, zoom = nil, dest_page = page)
37
50
  [dest_page.dictionary, :XYZ, left, top, zoom]
38
51
  end
39
52
 
40
- # Return a Dest specification that will fit the given page into the
53
+ # builds a Dest specification that will fit the given page into the
41
54
  # viewport.
42
55
  #
43
- def dest_fit(dest_page=page)
56
+ # @param dest_page [PDF::Core::Page]
57
+ # @return [Array(PDF::Core::Reference, :Fit)] a Dest specification for a page fitting
58
+ # viewport
59
+ def dest_fit(dest_page = page)
44
60
  [dest_page.dictionary, :Fit]
45
61
  end
46
62
 
47
- # Return a Dest specification that will fit the given page horizontally
63
+ # Builds a Dest specification that will fit the given page horizontally
48
64
  # into the viewport, aligned vertically at the given top coordinate.
49
65
  #
50
- def dest_fit_horizontally(top, dest_page=page)
66
+ # @param top [Numeric]
67
+ # @param dest_page [PDF::Core::Page]
68
+ # @return [Array(PDF::Core::Reference, :FitH, Numeric)] a Dest specification for a page
69
+ # content fitting horizontally at a given top coordinate
70
+ def dest_fit_horizontally(top, dest_page = page)
51
71
  [dest_page.dictionary, :FitH, top]
52
72
  end
53
73
 
54
- # Return a Dest specification that will fit the given page vertically
74
+ # Build a Dest specification that will fit the given page vertically
55
75
  # into the viewport, aligned horizontally at the given left coordinate.
56
76
  #
57
- def dest_fit_vertically(left, dest_page=page)
77
+ # @param left [Numeric]
78
+ # @param dest_page [PDF::Core::Page]
79
+ # @return [Array(Hash, :FitV, Numeric)] a Dest specification for a page
80
+ # content fitting vertically at a given left coordinate
81
+ def dest_fit_vertically(left, dest_page = page)
58
82
  [dest_page.dictionary, :FitV, left]
59
83
  end
60
84
 
61
- # Return a Dest specification that will fit the given rectangle into the
85
+ # Builds a Dest specification that will fit the given rectangle into the
62
86
  # viewport, for the given page.
63
87
  #
64
- def dest_fit_rect(left, bottom, right, top, dest_page=page)
88
+ # @param left [Numeric]
89
+ # @param bottom [Numeric]
90
+ # @param right [Numeric]
91
+ # @param top [Numeric]
92
+ # @param dest_page [PDF::Core::Page]
93
+ # @return [Array(Hash, :FitR, Numeric, Numeric, Numeric, Numeric)]
94
+ # a Dest specification for a page fitting the given rectangle in the
95
+ # viewport
96
+ def dest_fit_rect(left, bottom, right, top, dest_page = page)
65
97
  [dest_page.dictionary, :FitR, left, bottom, right, top]
66
98
  end
67
99
 
68
- # Return a Dest specfication that will fit the given page's bounding box
100
+ # Builds a Dest specification that will fit the given page's bounding box
69
101
  # into the viewport.
70
102
  #
71
- def dest_fit_bounds(dest_page=page)
103
+ # @param dest_page [PDF::Core::Page]
104
+ # @return [Array(PDF::Core::Reference, :FitB)] a Dest specification for a page fitting
105
+ # bounding box into viewport
106
+ def dest_fit_bounds(dest_page = page)
72
107
  [dest_page.dictionary, :FitB]
73
108
  end
74
109
 
75
- # Same as #dest_fit_horizontally, but works on the page's bounding box
110
+ # Same as {#dest_fit_horizontally}, but works on the page's bounding box
76
111
  # instead of the entire page.
77
112
  #
78
- def dest_fit_bounds_horizontally(top, dest_page=page)
113
+ # @param top [Numeric]
114
+ # @param dest_page [PDF::Core::Page]
115
+ # @return [Array(PDF::Core::Reference, :FitBH, Numeric)] a Dest specification for a page
116
+ # bounding box fitting horizontally at a given top coordinate
117
+ def dest_fit_bounds_horizontally(top, dest_page = page)
79
118
  [dest_page.dictionary, :FitBH, top]
80
119
  end
81
120
 
82
- # Same as #dest_fit_vertically, but works on the page's bounding box
121
+ # Same as {#dest_fit_vertically}, but works on the page's bounding box
83
122
  # instead of the entire page.
84
123
  #
85
- def dest_fit_bounds_vertically(left, dest_page=page)
124
+ # @param left [Numeric]
125
+ # @param dest_page [PDF::Core::Page]
126
+ # @return [Array(PDF::Core::Reference, :FitBV, Numeric)] a Dest specification for a page
127
+ # bounding box fitting vertically at a given top coordinate
128
+ def dest_fit_bounds_vertically(left, dest_page = page)
86
129
  [dest_page.dictionary, :FitBV, left]
87
130
  end
88
131
  end
@@ -1,74 +1,165 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PDF
2
4
  module Core
3
- class DocumentState #:nodoc:
5
+ # Low-level PDF document representation mostly for keeping intermediate
6
+ # state while document is being constructed.
7
+ #
8
+ # @api private
9
+ class DocumentState
10
+ # @param options [Hash<Symbol, any>]
11
+ # @option options :info [Hash] Document's information dictionary
12
+ # @option options :print_scaling [:none, nil] Viewr preference for
13
+ # printing scaling
14
+ # @option options :trailer [Hash] ({}) File trailer
15
+ # @option options :compress [Boolean] (false) Whether to compress streams
16
+ # @option options :encrypt [Boolean] (false) Whether to encrypt the
17
+ # document
18
+ # @option options :encryption_key [String] (nil) Encryption key. Must be
19
+ # provided if `:encrypt` is `true`
4
20
  def initialize(options)
5
21
  normalize_metadata(options)
6
22
 
7
- if options[:print_scaling]
8
- @store = PDF::Core::ObjectStore.new(:info => options[:info],
9
- :print_scaling => options[:print_scaling])
10
- else
11
- @store = PDF::Core::ObjectStore.new(:info => options[:info])
12
- end
23
+ @store =
24
+ if options[:print_scaling]
25
+ PDF::Core::ObjectStore.new(
26
+ info: options[:info],
27
+ print_scaling: options[:print_scaling],
28
+ )
29
+ else
30
+ PDF::Core::ObjectStore.new(info: options[:info])
31
+ end
13
32
 
14
- @version = 1.3
15
- @pages = []
16
- @page = nil
17
- @trailer = {}
18
- @compress = options.fetch(:compress, false)
19
- @encrypt = options.fetch(:encrypt, false)
20
- @encryption_key = options[:encryption_key]
21
- @skip_encoding = options.fetch(:skip_encoding, false)
33
+ @version = 1.3
34
+ @pages = []
35
+ @page = nil
36
+ @trailer = options.fetch(:trailer, {})
37
+ @compress = options.fetch(:compress, false)
38
+ @encrypt = options.fetch(:encrypt, false)
39
+ @encryption_key = options[:encryption_key]
40
+ @skip_encoding = options.fetch(:skip_encoding, false)
22
41
  @before_render_callbacks = []
23
42
  @on_page_create_callback = nil
24
43
  end
25
44
 
26
- attr_accessor :store, :version, :pages, :page, :trailer, :compress,
27
- :encrypt, :encryption_key, :skip_encoding,
28
- :before_render_callbacks, :on_page_create_callback
45
+ # Object store
46
+ # @return [PDF::Core::ObjectStore]
47
+ attr_accessor :store
48
+
49
+ # PDF version used in this document
50
+ # @return [Float]
51
+ attr_accessor :version
52
+
53
+ # Document pages
54
+ # @return [Array<PDF::Core::Page>]
55
+ attr_accessor :pages
56
+
57
+ # Current page
58
+ # @return [PDF::Core::Page]
59
+ attr_accessor :page
60
+
61
+ # Document trailer dict
62
+ # @return [Hash]
63
+ attr_accessor :trailer
64
+
65
+ # Whether to compress streams
66
+ # @return [Boolean]
67
+ attr_accessor :compress
29
68
 
69
+ # Whether to encrypt document
70
+ # @return [Boolean]
71
+ attr_accessor :encrypt
72
+
73
+ # Encryption key
74
+ # @return [String, nil]
75
+ attr_accessor :encryption_key
76
+
77
+ # @deprecated Unused
78
+ attr_accessor :skip_encoding
79
+
80
+ # Before render callbacks
81
+ # @return [Array<Proc>]
82
+ attr_accessor :before_render_callbacks
83
+
84
+ # A block to call when a new page is created
85
+ # @return [Proc, nil]
86
+ attr_accessor :on_page_create_callback
87
+
88
+ # Loads pages from object store. Only does it when there are no pages
89
+ # loaded and there are some pages in the store.
90
+ #
91
+ # @return [0] if no pages were loaded
92
+ # @return [Array<PDF::Core::Page>] if pages were laded
30
93
  def populate_pages_from_store(document)
31
- return 0 if @store.page_count <= 0 || @pages.size > 0
94
+ return 0 if @store.page_count <= 0 || !@pages.empty?
32
95
 
33
96
  count = (1..@store.page_count)
34
- @pages = count.map do |index|
35
- orig_dict_id = @store.object_id_for_page(index)
36
- PDF::Core::Page.new(document, :object_id => orig_dict_id)
37
- end
38
-
97
+ @pages =
98
+ count.map { |index|
99
+ orig_dict_id = @store.object_id_for_page(index)
100
+ PDF::Core::Page.new(document, object_id: orig_dict_id)
101
+ }
39
102
  end
40
103
 
104
+ # Adds Prawn metadata to document info
105
+ #
106
+ # @param options [Hash]
107
+ # @return [Hash] Document `info` hash
41
108
  def normalize_metadata(options)
42
109
  options[:info] ||= {}
43
- options[:info][:Creator] ||= "Prawn"
44
- options[:info][:Producer] ||= "Prawn"
110
+ options[:info][:Creator] ||= 'Prawn'
111
+ options[:info][:Producer] ||= 'Prawn'
45
112
 
46
113
  options[:info]
47
114
  end
48
115
 
116
+ # Insert a page at the specified position.
117
+ #
118
+ # @param page [PDF::Core::Page]
119
+ # @param page_number [Integer]
120
+ # @return [void]
49
121
  def insert_page(page, page_number)
50
122
  pages.insert(page_number, page)
51
123
  store.pages.data[:Kids].insert(page_number, page.dictionary)
52
124
  store.pages.data[:Count] += 1
53
125
  end
54
126
 
127
+ # Execute page creation callback if one is defined
128
+ #
129
+ # @param doc [Prawn::Document]
130
+ # @return [void]
55
131
  def on_page_create_action(doc)
56
132
  on_page_create_callback[doc] if on_page_create_callback
57
133
  end
58
134
 
59
- def before_render_actions(doc)
60
- before_render_callbacks.each{ |c| c.call(self) }
135
+ # Executes before render callbacks
136
+ #
137
+ # @param _doc [Prawn::Document] Unused
138
+ # @return [void]
139
+ def before_render_actions(_doc)
140
+ before_render_callbacks.each { |c| c.call(self) }
61
141
  end
62
142
 
143
+ # Number of pages in the document
144
+ #
145
+ # @return [Integer]
63
146
  def page_count
64
147
  pages.length
65
148
  end
66
149
 
150
+ # Renders document body to the output
151
+ #
152
+ # @param output [#<<]
153
+ # @return [void]
67
154
  def render_body(output)
68
155
  store.each do |ref|
69
156
  ref.offset = output.size
70
- output << (@encrypt ? ref.encrypted_object(@encryption_key) :
71
- ref.object)
157
+ output <<
158
+ if @encrypt
159
+ ref.encrypted_object(@encryption_key)
160
+ else
161
+ ref.object
162
+ end
72
163
  end
73
164
  end
74
165
  end
@@ -1,10 +1,36 @@
1
- module PDF
1
+ # frozen_string_literal: true
2
+
3
+ module PDF
2
4
  module Core
5
+ # A representation of a list of filters applied to a stream.
3
6
  class FilterList
7
+ # An exception one can expect when adding something to filter list that
8
+ # can not be interpreted as a filter.
9
+ class NotFilter < StandardError
10
+ # Generic default error message
11
+ DEFAULT_MESSAGE = 'Can not interpret input as a filter'
12
+
13
+ # Error message template with more details
14
+ MESSAGE_WITH_FILTER = 'Can not interpret input as a filter: %<filter>s'
15
+
16
+ def initialize(message = DEFAULT_MESSAGE, filter: nil)
17
+ if filter
18
+ super(format(MESSAGE_WITH_FILTER, filter: filter))
19
+ else
20
+ super(message)
21
+ end
22
+ end
23
+ end
24
+
4
25
  def initialize
5
26
  @list = []
6
27
  end
7
28
 
29
+ # Appends a filter to the list
30
+ #
31
+ # @param filter [Symbol, Hash] a filter to append
32
+ # @return [self]
33
+ # @raise [NotFilter]
8
34
  def <<(filter)
9
35
  case filter
10
36
  when Symbol
@@ -14,37 +40,52 @@ module PDF
14
40
  @list << [name, params]
15
41
  end
16
42
  else
17
- raise "Can not interpret input as filter: #{filter.inspect}"
43
+ raise NotFilter.new(filter: filter)
18
44
  end
19
45
 
20
46
  self
21
47
  end
22
48
 
49
+ # A normalized representation of the filter list
50
+ #
51
+ # @return [Array<Array<(Symbol, [Hash, nil])>>]
23
52
  def normalized
24
53
  @list
25
54
  end
26
- alias_method :to_a, :normalized
55
+ alias to_a normalized
27
56
 
57
+ # Names of filters in the list
58
+ #
59
+ # @return [Array<Symbol>]
28
60
  def names
29
61
  @list.map do |(name, _)|
30
62
  name
31
63
  end
32
64
  end
33
65
 
66
+ # Parameters of filters
67
+ #
68
+ # @return [Array<[Hash, nil]>]
34
69
  def decode_params
35
70
  @list.map do |(_, params)|
36
71
  params
37
72
  end
38
73
  end
39
74
 
75
+ # @return [String]
40
76
  def inspect
41
77
  @list.inspect
42
78
  end
43
79
 
80
+ # Iterates over filters
81
+ #
82
+ # @yield [(name, decode_params)] an array of filter name and decode
83
+ # parameters
84
+ # @yieldparam name [Symbol] filter name
85
+ # @yieldparam decode_params [Hash, nil] decode params
86
+ # @return [Array<Array<(Symbol, [Hash, nil])>>] normalized filter list
44
87
  def each(&block)
45
- @list.each do |filter|
46
- block.call(filter)
47
- end
88
+ @list.each(&block)
48
89
  end
49
90
  end
50
91
  end
@@ -1,33 +1,52 @@
1
- # encoding: utf-8
2
-
3
- # prawn/core/filters.rb : Implements stream filters
4
- #
5
- # Copyright February 2013, Alexander Mankuta. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
1
+ # frozen_string_literal: true
8
2
 
9
3
  require 'zlib'
10
4
 
11
5
  module PDF
12
6
  module Core
7
+ # Stream filters
13
8
  module Filters
9
+ # zlib/deflate compression
14
10
  module FlateDecode
15
- def self.encode(stream, params = nil)
11
+ # Encode stream data
12
+ #
13
+ # @param stream [String] stream data
14
+ # @param _params [nil] unused, here for API compatibility
15
+ # @return [String]
16
+ def self.encode(stream, _params = nil)
16
17
  Zlib::Deflate.deflate(stream)
17
18
  end
18
19
 
19
- def self.decode(stream, params = nil)
20
+ # Decode stream data
21
+ #
22
+ # @param stream [String] stream data
23
+ # @param _params [nil] unused, here for API compatibility
24
+ # @return [String]
25
+ def self.decode(stream, _params = nil)
20
26
  Zlib::Inflate.inflate(stream)
21
27
  end
22
28
  end
23
29
 
24
- # Pass through stub
30
+ # Data encoding using DCT (discrete cosine transform) technique based on
31
+ # the JPEG standard.
32
+ #
33
+ # Pass through stub.
25
34
  module DCTDecode
26
- def self.encode(stream, params = nil)
35
+ # Encode stream data
36
+ #
37
+ # @param stream [String] stream data
38
+ # @param _params [nil] unused, here for API compatibility
39
+ # @return [String]
40
+ def self.encode(stream, _params = nil)
27
41
  stream
28
42
  end
29
43
 
30
- def self.decode(stream, params = nil)
44
+ # Decode stream data
45
+ #
46
+ # @param stream [String] stream data
47
+ # @param _params [nil] unused, here for API compatibility
48
+ # @return [String]
49
+ def self.decode(stream, _params = nil)
31
50
  stream
32
51
  end
33
52
  end