pdfrb 0.7.12 → 0.7.14

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
2
  SHA256:
3
- metadata.gz: 26e34e7b8d5b74f8a2f8a89b36b3ea7ae028b0cf8944707aeed0a3ddde8270fc
4
- data.tar.gz: 9bae4c50eff54052d0cc173559625fb0de3ff782bb567b9ac0bf7f85be951aea
3
+ metadata.gz: 29668fa0363922e98c020c762e0de36fc221ed3667407d70ab68b02bc40bf90e
4
+ data.tar.gz: 10e2c7a8f2f9dd8e43b464cab777ef54e921004ae8a59b89c3c29dfd3c0823db
5
5
  SHA512:
6
- metadata.gz: 3c12a6ae1950e81e8bb5fc181dc35aa63fcb6c0671bf0ab9e3becc92b3ebbb28e2210eb0be966ca4cefb6baf97688b1e7ba8115629d08647493680f5f42c6588
7
- data.tar.gz: 87eb412507356b781a33f96f3d58aa6a14acb5284664091879c23c699e70bd3a2ee4e5f0dbd64c7958361544e1ecc3a23f71b00e2d95b3fe9f2805ab9ad441ed
6
+ metadata.gz: 5b2e9643a1eb44228dccaf6882139060297ebb0bfec23ba33f5e10303d4c477dd562a94b98bc0027ed049f99aac94bf56eae0cf19160cd37ed78825e32422d41
7
+ data.tar.gz: c43041d9ca87df1184b44897a4f5456e3b252e1a3cd604d67d2b6d6d8a1e0c4d4327c6ee01a449f1f16f7b8527098f1b73b7f0132b8aa148393f484617d161e8
@@ -10,10 +10,9 @@ module Pdfrb
10
10
  # needed, but the bytes live in the content stream so they
11
11
  # can't be reused.
12
12
  #
13
- # The serialise path emits the BI dict, ID marker, raw bytes,
14
- # and EI marker. The invoke path is intentionally a no-op; the
15
- # content Parser handles BI/ID/EI as a single bounded block
16
- # rather than via the operator dispatch table.
13
+ # The Parser detects BI ... ID ... EI and yields a single
14
+ # BeginInlineImage invocation with the parsed image Hash as
15
+ # the operand. The invoke hook calls Processor#inline_image.
17
16
  class BeginInlineImage < Base
18
17
  class << self
19
18
  def name; "BI"; end
@@ -27,7 +26,9 @@ module Pdfrb
27
26
  buf
28
27
  end
29
28
 
30
- def invoke(_processor, *_operands); end
29
+ def invoke(processor, image = nil)
30
+ processor.inline_image(image) if image
31
+ end
31
32
  register
32
33
  end
33
34
  end
@@ -36,14 +37,6 @@ module Pdfrb
36
37
  class << self
37
38
  def name; "EI"; end
38
39
 
39
- # The byte payload sits between ID and EI. The serializer
40
- # for inline images writes the payload directly via
41
- # Canvas#inline_image; this method is here so the registry
42
- # knows about EI.
43
- def serialize(_serializer, *_operands)
44
- "EI\n"
45
- end
46
-
47
40
  def invoke(_processor, *_operands); end
48
41
  register
49
42
  end
@@ -76,6 +76,12 @@ module Pdfrb
76
76
  def begin_marked_content(_tag, _properties = nil); end
77
77
  def end_marked_content; end
78
78
  def marked_content_point(_tag, _properties = nil); end
79
+
80
+ # Called when a BI/ID/EI inline image is encountered in the
81
+ # content stream. +image+ is a Hash with :header (the image
82
+ # dict keys, expanded from abbreviations) and :data (the raw
83
+ # byte payload). Subclasses override to render or extract.
84
+ def inline_image(_image); end
79
85
  end
80
86
  end
81
87
  end
@@ -89,7 +89,7 @@ module Pdfrb
89
89
  trusted?: !trusted_certs.empty? && valid,
90
90
  error: valid ? nil : "signature verification failed",
91
91
  )
92
- rescue OpenSSL::PKCS7::PKCS7Error => e
92
+ rescue OpenSSL::PKCS7::PKCS7Error, ArgumentError => e
93
93
  VerificationResult.new(valid?: false,
94
94
  byte_range_ok?: true,
95
95
  cert_chain: [],
@@ -3,7 +3,9 @@
3
3
  module Pdfrb
4
4
  module Layout
5
5
  # Fits an ordered list of boxes into a Frame, flowing to a new
6
- # Frame (provided by a block) when one fills up.
6
+ # Frame (provided by a block) when one fills up. Delegates area
7
+ # tracking to the Frame (which now properly tracks removed areas
8
+ # and returns non-overlapping positions).
7
9
  class BoxFitter
8
10
  attr_reader :boxes, :frame, :result, :overflow
9
11
 
@@ -16,26 +18,8 @@ module Pdfrb
16
18
 
17
19
  def fit
18
20
  current_frame = @frame
19
- cursor_y = current_frame.top
20
21
  @boxes.each do |box|
21
- loop do
22
- position = current_frame.find_available_area(box.width || current_frame.width, box.height || (cursor_y - current_frame.bottom))
23
- if position && box.fit?(position[2] || current_frame.width, position[3] || (cursor_y - current_frame.bottom))
24
- @result << [box, position]
25
- current_frame.remove_area(position[0], position[1] - box.height, box.width, box.height)
26
- cursor_y = position[1] - box.height
27
- break
28
- else
29
- next_frame = yield if block_given?
30
- if next_frame
31
- current_frame = next_frame
32
- cursor_y = current_frame.top
33
- else
34
- @overflow << box
35
- break
36
- end
37
- end
38
- end
22
+ current_frame = fit_box(box, current_frame)
39
23
  end
40
24
  self
41
25
  end
@@ -49,6 +33,37 @@ module Pdfrb
49
33
  def fit_complete?
50
34
  @overflow.empty?
51
35
  end
36
+
37
+ private
38
+
39
+ def fit_box(box, frame)
40
+ loop do
41
+ return frame if place?(box, frame)
42
+
43
+ next_frame = yield if block_given?
44
+ unless next_frame
45
+ @overflow << box
46
+ return frame
47
+ end
48
+
49
+ frame = next_frame
50
+ end
51
+ end
52
+
53
+ def place?(box, frame)
54
+ box_w = box.width || frame.width
55
+ box_h = box.height || frame.available_height
56
+ position = frame.find_available_area(box_w, box_h)
57
+ return false unless position
58
+
59
+ actual_w = position[2] || frame.width
60
+ actual_h = position[3] || frame.available_height
61
+ return false unless box.fit?(actual_w, actual_h)
62
+
63
+ @result << [box, position]
64
+ frame.remove_area(position[0], position[1], actual_w, box.height || actual_h)
65
+ true
66
+ end
52
67
  end
53
68
  end
54
69
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # Thumbnail image stream (ISO 32000-2 §12.3.4). A small image
7
+ # XObject rendered at reduced resolution for use in viewer
8
+ # navigation panels. Attached to a page via the /Thumb key.
9
+ class Thumbnail < Pdfrb::Model::Cos::Stream
10
+ arlington_object "Thumbnail"
11
+
12
+ # /Width — required.
13
+ def width
14
+ value[:Width]
15
+ end
16
+
17
+ # /Height — required.
18
+ def height
19
+ value[:Height]
20
+ end
21
+
22
+ # /ColorSpace — required unless /ImageMask true.
23
+ def color_space
24
+ value[:ColorSpace]
25
+ end
26
+
27
+ # /BitsPerComponent — required.
28
+ def bits_per_component
29
+ value[:BitsPerComponent]
30
+ end
31
+
32
+ # /Filter — optional; a named filter or array of filters.
33
+ def filter
34
+ value[:Filter]
35
+ end
36
+
37
+ def dimensions
38
+ [width, height]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # Timespan (ISO 32000-2 §12.7.11, PDF 1.5+). A duration with
7
+ # a unit, used in RichMedia timing, 3D animation, and
8
+ # JavaScript-embedded timelines.
9
+ class Timespan < Pdfrb::Model::Cos::Dictionary
10
+ arlington_object "Timespan"
11
+
12
+ # /Type — optional, fixed "Timespan".
13
+ def type
14
+ value[:Type]&.to_sym
15
+ end
16
+
17
+ # /S — required, fixed "S" (seconds).
18
+ def subtype
19
+ value[:S]&.to_sym
20
+ end
21
+
22
+ # /V — required, the numeric duration in seconds.
23
+ def duration
24
+ value[:V]
25
+ end
26
+
27
+ # Convenience: duration in milliseconds.
28
+ def milliseconds
29
+ v = duration
30
+ v ? v.to_f * 1000 : nil
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # UserProperty (ISO 32000-2 §14.7.5). A single property in the
7
+ # /P array of a user property list attached to structure
8
+ # elements for custom metadata.
9
+ class UserProperty < Pdfrb::Model::Cos::Dictionary
10
+ arlington_object "UserProperty"
11
+
12
+ # /N — required, the property name.
13
+ def name
14
+ value[:N]
15
+ end
16
+
17
+ # /V — required, the property value (any COS type).
18
+ def property_value
19
+ value[:V]
20
+ end
21
+
22
+ # /F — optional, a text string with the intended format of
23
+ # the value.
24
+ def format
25
+ value[:F]
26
+ end
27
+
28
+ # /H — optional, whether the property is hidden from the
29
+ # user (default false).
30
+ def hidden?
31
+ value[:H] == true
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # Viewport (ISO 32000-2 §12.7.11, PDF 1.6+). Defines a
7
+ # rectangular region of a page intended for separate display,
8
+ # used for magnifier rectangles, measurement regions, and
9
+ # zoom targets.
10
+ class Viewport < Pdfrb::Model::Cos::Dictionary
11
+ arlington_object "Viewport"
12
+
13
+ # /Type — optional, fixed "Viewport".
14
+ def type
15
+ value[:Type]&.to_sym
16
+ end
17
+
18
+ # /BBox — required, the viewport rectangle.
19
+ def bbox
20
+ value[:BBox]
21
+ end
22
+
23
+ # /Name — optional, human-readable viewport name.
24
+ def name
25
+ value[:Name]
26
+ end
27
+
28
+ # /Measure — optional indirect Measure dict (RL for rulers,
29
+ # GEO for geospatial since PDF 2.0).
30
+ def measure(document = nil)
31
+ ref = value[:Measure]
32
+ return nil unless ref && document
33
+
34
+ ref.is_a?(Pdfrb::Model::Reference) ? document.object(ref) : ref
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # VRI (Validation Related Information) dictionary per ETSI EN
7
+ # 319 142-1 (PAdES) §B.5. Lives in /DSS /VRI map, keyed by the
8
+ # hex-encoded SHA-1 of the signature it validates. Holds the
9
+ # certificates, CRLs, and OCSP responses relevant to one
10
+ # signature.
11
+ class Vri < Pdfrb::Model::Cos::Dictionary
12
+ arlington_object "VRI"
13
+
14
+ # /Type — optional, fixed "VRI".
15
+ def type
16
+ value[:Type]&.to_sym
17
+ end
18
+
19
+ # /Cert — array of indirect streams, each a DER-encoded
20
+ # X.509 certificate relevant to the signature.
21
+ def certificates(document = nil)
22
+ refs = value[:Cert]
23
+ return [] unless refs
24
+
25
+ resolve_refs(refs, document)
26
+ end
27
+
28
+ # /CRL — array of indirect streams, each a DER-encoded
29
+ # certificate revocation list.
30
+ def crls(document = nil)
31
+ refs = value[:CRL]
32
+ return [] unless refs
33
+
34
+ resolve_refs(refs, document)
35
+ end
36
+
37
+ # /OCSP — array of indirect streams, each a DER-encoded
38
+ # OCSP response.
39
+ def ocsp_responses(document = nil)
40
+ refs = value[:OCSP]
41
+ return [] unless refs
42
+
43
+ resolve_refs(refs, document)
44
+ end
45
+
46
+ # /TU — optional string-text with a human-readable timestamp.
47
+ def timestamp_text
48
+ value[:TU]
49
+ end
50
+
51
+ # /TS — optional indirect stream with a timestamp token.
52
+ def timestamp_token(document = nil)
53
+ ref = value[:TS]
54
+ return nil unless ref && document
55
+
56
+ ref.is_a?(Pdfrb::Model::Reference) ? document.object(ref) : ref
57
+ end
58
+
59
+ private
60
+
61
+ def resolve_refs(refs, document)
62
+ return [] unless document
63
+
64
+ arr = refs.is_a?(Pdfrb::Model::PdfArray) ? refs.value : refs
65
+ arr = [arr] unless arr.is_a?(::Array)
66
+ arr.filter_map do |r|
67
+ next r unless r.is_a?(Pdfrb::Model::Reference)
68
+
69
+ document.object(r)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -356,6 +356,21 @@ module Pdfrb
356
356
 
357
357
  # Page-piece dictionary (s14.5).
358
358
  autoload :PagePieceInfo, "pdfrb/model/type/page_piece_info"
359
+
360
+ # PAdES validation-related information (ETSI EN 319 142-1).
361
+ autoload :Vri, "pdfrb/model/type/vri"
362
+
363
+ # Page thumbnails (s12.3.4).
364
+ autoload :Thumbnail, "pdfrb/model/type/thumbnail"
365
+
366
+ # Timespan (s12.7.11, PDF 1.5+).
367
+ autoload :Timespan, "pdfrb/model/type/timespan"
368
+
369
+ # Viewport (s12.7.11, PDF 1.6+).
370
+ autoload :Viewport, "pdfrb/model/type/viewport"
371
+
372
+ # User property (s14.7.5).
373
+ autoload :UserProperty, "pdfrb/model/type/user_property"
359
374
  end
360
375
  end
361
376
  end
data/lib/pdfrb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfrb
4
- VERSION = "0.7.12"
4
+ VERSION = "0.7.14"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -1149,14 +1149,19 @@ files:
1149
1149
  - lib/pdfrb/model/type/three_d_stream.rb
1150
1150
  - lib/pdfrb/model/type/three_d_units.rb
1151
1151
  - lib/pdfrb/model/type/three_d_view.rb
1152
+ - lib/pdfrb/model/type/thumbnail.rb
1153
+ - lib/pdfrb/model/type/timespan.rb
1152
1154
  - lib/pdfrb/model/type/to_unicode_cmap_stream.rb
1153
1155
  - lib/pdfrb/model/type/transition.rb
1154
1156
  - lib/pdfrb/model/type/underline_annotation.rb
1155
1157
  - lib/pdfrb/model/type/ur_transform_parameters.rb
1156
1158
  - lib/pdfrb/model/type/uri_dict.rb
1157
1159
  - lib/pdfrb/model/type/url_alias.rb
1160
+ - lib/pdfrb/model/type/user_property.rb
1158
1161
  - lib/pdfrb/model/type/variable_text_field.rb
1159
1162
  - lib/pdfrb/model/type/viewer_preferences.rb
1163
+ - lib/pdfrb/model/type/viewport.rb
1164
+ - lib/pdfrb/model/type/vri.rb
1160
1165
  - lib/pdfrb/model/type/watermark_annotation.rb
1161
1166
  - lib/pdfrb/model/type/widget_annotation.rb
1162
1167
  - lib/pdfrb/model/type/widget_appearance.rb