pdfrb 0.7.42 → 0.7.43
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 +4 -4
- data/lib/pdfrb/content/inline_image.rb +103 -0
- data/lib/pdfrb/content/operator.rb +6 -0
- data/lib/pdfrb/content/operators/inline_image.rb +2 -2
- data/lib/pdfrb/content/operators.rb +0 -1
- data/lib/pdfrb/content/parser.rb +1 -1
- data/lib/pdfrb/content/processor.rb +3 -3
- data/lib/pdfrb/content.rb +1 -0
- data/lib/pdfrb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0b004db58a66ef4268db7138eb13c2813fcceb4e22a492674597f631d6f889e
|
|
4
|
+
data.tar.gz: b29ee27e11e4aea41a482e3eb217c7ddf70a5cdf4b21f70b2d16be01747822df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25dc0c66f65bf454f2ac91c362031c57720d060edaeb54912aba896115216fbe43ce4fd947e21e94a445e521168e1eb629d51db42dc38c9ca5639ca41e8786e5
|
|
7
|
+
data.tar.gz: 3368f119c878bb7bcce11f21a4bd6edb267e4605ae079ca85dafbce6defa1397e9b5f0649bbdfc3a7084d161eb0f6c20da934b5b0f288344538f296703a031c7
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pdfrb
|
|
4
|
+
module Content
|
|
5
|
+
# A BI ... ID ... EI inline image (s8.9.7). Carries the expanded
|
|
6
|
+
# header keys (abbreviations resolved by the parser), the raw
|
|
7
|
+
# encoded byte payload, and decodes on demand via the filter
|
|
8
|
+
# pipeline.
|
|
9
|
+
class InlineImage
|
|
10
|
+
# Filter-name abbreviations permitted in inline images
|
|
11
|
+
# (s8.9.7 Table 89).
|
|
12
|
+
FILTER_ABBREVIATIONS = {
|
|
13
|
+
AHx: :ASCIIHexDecode,
|
|
14
|
+
A85: :ASCII85Decode,
|
|
15
|
+
Fl: :FlateDecode,
|
|
16
|
+
LZW: :LZWDecode,
|
|
17
|
+
CCF: :CCITTFaxDecode,
|
|
18
|
+
DCT: :DCTDecode,
|
|
19
|
+
RL: :RunLengthDecode,
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
# Color-space-name abbreviations (s8.9.7 Table 89).
|
|
23
|
+
COLOR_SPACE_ABBREVIATIONS = {
|
|
24
|
+
G: :DeviceGray,
|
|
25
|
+
RGB: :DeviceRGB,
|
|
26
|
+
CMYK: :DeviceCMYK,
|
|
27
|
+
I: :Indexed,
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
attr_reader :header, :data
|
|
31
|
+
|
|
32
|
+
def initialize(header: {}, data: "")
|
|
33
|
+
@header = header.dup.freeze
|
|
34
|
+
@data = (data || "".b).dup.freeze
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def width; header[:Width]; end
|
|
38
|
+
def height; header[:Height]; end
|
|
39
|
+
def bits_per_component; header[:BitsPerComponent]; end
|
|
40
|
+
|
|
41
|
+
def image_mask?
|
|
42
|
+
[true, 1].include?(header[:ImageMask])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def decode; header[:Decode]; end
|
|
46
|
+
def interpolate?; header[:Interpolate] == true; end
|
|
47
|
+
|
|
48
|
+
# /ColorSpace with the inline abbreviation expanded
|
|
49
|
+
# (/G -> /DeviceGray etc.).
|
|
50
|
+
def color_space
|
|
51
|
+
cs = header[:ColorSpace]
|
|
52
|
+
return nil unless cs.is_a?(::Symbol)
|
|
53
|
+
|
|
54
|
+
COLOR_SPACE_ABBREVIATIONS.fetch(cs, cs)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Decoded filter chain as an array of Symbols; nil when the
|
|
58
|
+
# image data is stored raw.
|
|
59
|
+
def filters
|
|
60
|
+
f = header[:Filter]
|
|
61
|
+
return [] if f.nil?
|
|
62
|
+
|
|
63
|
+
arr = f.is_a?(::Array) ? f : [f]
|
|
64
|
+
arr.map { |name| FILTER_ABBREVIATIONS.fetch(name.to_sym, name.to_sym) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Apply the filter chain to the raw payload. Returns the raw
|
|
68
|
+
# data when no filter is declared.
|
|
69
|
+
def decoded_data
|
|
70
|
+
list = filters
|
|
71
|
+
return @data if list.empty?
|
|
72
|
+
|
|
73
|
+
Pdfrb::Filter.apply(
|
|
74
|
+
@data, filters: list, parms: Array(header[:DecodeParms]),
|
|
75
|
+
direction: :decode
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Number of colour components implied by /ColorSpace.
|
|
80
|
+
def components
|
|
81
|
+
case color_space
|
|
82
|
+
when :DeviceGray, :Indexed then 1
|
|
83
|
+
when :DeviceRGB then 3
|
|
84
|
+
when :DeviceCMYK then 4
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Expected decoded byte count: rows * width * components *
|
|
89
|
+
# bits, packed per row.
|
|
90
|
+
def expected_decoded_size
|
|
91
|
+
return nil if width.nil? || height.nil? || bits_per_component.nil?
|
|
92
|
+
return nil if image_mask?
|
|
93
|
+
|
|
94
|
+
comps = components
|
|
95
|
+
return nil if comps.nil?
|
|
96
|
+
|
|
97
|
+
bits = width * comps * bits_per_component
|
|
98
|
+
bytes_per_row = (bits + 7) / 8
|
|
99
|
+
bytes_per_row * height
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -12,6 +12,12 @@ module Pdfrb
|
|
|
12
12
|
module Operator
|
|
13
13
|
@registry = {}
|
|
14
14
|
|
|
15
|
+
# Referenced directly by the Parser for BI ... ID ... EI
|
|
16
|
+
# sequences; the remaining operator classes load via
|
|
17
|
+
# eager_load! / Operator[].
|
|
18
|
+
autoload :BeginInlineImage, "pdfrb/content/operators/inline_image"
|
|
19
|
+
autoload :EndInlineImage, "pdfrb/content/operators/inline_image"
|
|
20
|
+
|
|
15
21
|
class << self
|
|
16
22
|
attr_reader :registry
|
|
17
23
|
|
|
@@ -29,8 +29,8 @@ module Pdfrb
|
|
|
29
29
|
def invoke(processor, image = nil)
|
|
30
30
|
processor.inline_image(image) if image
|
|
31
31
|
end
|
|
32
|
-
register
|
|
33
32
|
end
|
|
33
|
+
register
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
class EndInlineImage < Base
|
|
@@ -38,8 +38,8 @@ module Pdfrb
|
|
|
38
38
|
def name; "EI"; end
|
|
39
39
|
|
|
40
40
|
def invoke(_processor, *_operands); end
|
|
41
|
-
register
|
|
42
41
|
end
|
|
42
|
+
register
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -16,7 +16,6 @@ module Pdfrb
|
|
|
16
16
|
autoload :GraphicsStateParams, "pdfrb/content/operators/graphics_state_params"
|
|
17
17
|
autoload :MarkedContent, "pdfrb/content/operators/marked_content"
|
|
18
18
|
autoload :Clipping, "pdfrb/content/operators/clipping"
|
|
19
|
-
autoload :InlineImage, "pdfrb/content/operators/inline_image"
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
end
|
data/lib/pdfrb/content/parser.rb
CHANGED
|
@@ -82,7 +82,7 @@ module Pdfrb
|
|
|
82
82
|
# keyword from the data. Read raw bytes until "\nEI" or
|
|
83
83
|
# " EI" terminator.
|
|
84
84
|
data = read_inline_image_data
|
|
85
|
-
|
|
85
|
+
Pdfrb::Content::InlineImage.new(header: header, data: data)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Map inline-image abbreviation keys to full PDF names per
|
|
@@ -78,9 +78,9 @@ module Pdfrb
|
|
|
78
78
|
def marked_content_point(_tag, _properties = nil); end
|
|
79
79
|
|
|
80
80
|
# Called when a BI/ID/EI inline image is encountered in the
|
|
81
|
-
# content stream. +image+ is a
|
|
82
|
-
#
|
|
83
|
-
#
|
|
81
|
+
# content stream. +image+ is a Content::InlineImage with the
|
|
82
|
+
# expanded header keys, the raw payload, and decoded_data /
|
|
83
|
+
# geometry accessors. Subclasses override to render or extract.
|
|
84
84
|
def inline_image(_image); end
|
|
85
85
|
end
|
|
86
86
|
end
|
data/lib/pdfrb/content.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Pdfrb
|
|
|
5
5
|
autoload :GraphicsState, "pdfrb/content/graphics_state"
|
|
6
6
|
autoload :Operator, "pdfrb/content/operator"
|
|
7
7
|
autoload :Parser, "pdfrb/content/parser"
|
|
8
|
+
autoload :InlineImage, "pdfrb/content/inline_image"
|
|
8
9
|
autoload :Processor, "pdfrb/content/processor"
|
|
9
10
|
autoload :ColorSpace, "pdfrb/content/color_space"
|
|
10
11
|
autoload :TransformationMatrix, "pdfrb/content/transformation_matrix"
|
data/lib/pdfrb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pdfrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.43
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -782,6 +782,7 @@ files:
|
|
|
782
782
|
- lib/pdfrb/content/graphic_object/rectangle.rb
|
|
783
783
|
- lib/pdfrb/content/graphics_state.rb
|
|
784
784
|
- lib/pdfrb/content/hidden_text_detector.rb
|
|
785
|
+
- lib/pdfrb/content/inline_image.rb
|
|
785
786
|
- lib/pdfrb/content/operator.rb
|
|
786
787
|
- lib/pdfrb/content/operators.rb
|
|
787
788
|
- lib/pdfrb/content/operators/clipping.rb
|