pdfrb 0.8.3 → 0.8.4

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: 386ea091bd58d931bc196bd3df335f26043feb5f70e02e33cd076b30566e157d
4
- data.tar.gz: d41d511beef5d357dd5e86f0253cd932f11475dc173e0e29665462bb40fcab61
3
+ metadata.gz: d6ed6487322f48831706d1efa10d78b12bbb0965d8c46232b8d333130fe63e91
4
+ data.tar.gz: f3da7f40c6b4f1e53b454d70eaac66a2fd42d3f73c03802dc01a9bdffbdd3915
5
5
  SHA512:
6
- metadata.gz: 249ca1bde48ee762616405b716b93389fd6eea3950f981a59d8cc18b81620891190c1addae3009b1624065ed7ef3411304761fb1e0cc014bd60c02ba8db01eef
7
- data.tar.gz: 69258188bf5f7cc3a3ffddbb89348b7a3589c54bb5a943fcb46a059c72aded574cdbfb43d212abca82eea0e44375a1f8caf863f51666dc79f95537b3c4f8945d
6
+ metadata.gz: 922050302dd2668bdf08e8fcfb612a02e99e0b8a90c0ce667f2910398a5cbece4fd656b1d2cf615c4e410d368534f31a0071afac6e80b5b81982f65c7b78b9a3
7
+ data.tar.gz: f80c263e29e5b17659e7e9eeef9dbedac5865ffbb38d9871e9687bbbe1cc8ad7a1743c0c9dd9dbb18eb9fcb072c0c9032391983df129b04eb9b15f0d148a1abd
@@ -329,7 +329,7 @@ module Pdfrb
329
329
 
330
330
  max_oid = @xref.entries.keys.max || 0
331
331
  size = @trailer_dict && @trailer_dict[:Size]
332
- size = size.to_i if size.respond_to?(:to_i)
332
+ size = size.to_i if size.is_a?(Numeric)
333
333
  @next_oid = [max_oid + 1, size.to_i, @next_oid].max
334
334
  end
335
335
 
@@ -168,49 +168,23 @@ module Pdfrb
168
168
  # defaults /DefaultGray, /DefaultRGB, /DefaultCMYK.
169
169
  class ColorSpaceMap < Pdfrb::Model::Cos::Dictionary
170
170
  arlington_object "ColorSpaceMap"
171
-
172
- def [](name)
173
- value[name.to_sym] || value[name.to_s]
174
- end
175
-
176
- def add(name, color_space)
177
- value[name.to_sym] = color_space
178
- name.to_sym
179
- end
171
+ include NameMap
180
172
 
181
173
  def default_gray; self[:DefaultGray]; end
182
174
  def default_rgb; self[:DefaultRGB]; end
183
175
  def default_cmyk; self[:DefaultCMYK]; end
184
176
 
185
- def each_color_space(&)
186
- return enum_for(:each_color_space) unless block_given?
187
-
188
- value.each(&)
189
- end
190
-
191
- def names
192
- value.keys
193
- end
177
+ alias each_color_space each_entry
194
178
  end
195
179
 
196
180
  # Colorants dictionary (s8.6.6.5, DeviceN /Colorants). Maps
197
181
  # individual colorant names to Separation spaces.
198
182
  class ColorantsDict < Pdfrb::Model::Cos::Dictionary
199
183
  arlington_object "ColorantsDict"
184
+ include NameMap
200
185
 
201
- def [](name)
202
- value[name.to_sym] || value[name.to_s]
203
- end
204
-
205
- def each_colorant(&)
206
- return enum_for(:each_colorant) unless block_given?
207
-
208
- value.each(&)
209
- end
210
-
211
- def colorant_names
212
- value.keys
213
- end
186
+ alias each_colorant each_entry
187
+ alias colorant_names names
214
188
  end
215
189
 
216
190
  # Box style dictionary (s7.11.4, BoxColorInfo entries). Guides
@@ -29,9 +29,9 @@ module Pdfrb
29
29
  # names to the default CryptFilter used.
30
30
  class CryptFilterMap < Pdfrb::Model::Cos::Dictionary
31
31
  arlington_object "CryptFilterMap"
32
- def filter_for(stream_name)
33
- value[stream_name.to_sym] || value[stream_name.to_s]
34
- end
32
+ include NameMap
33
+
34
+ alias filter_for []
35
35
 
36
36
  def each_filter(&)
37
37
  return enum_for(:each_filter) unless block_given?
@@ -53,9 +53,9 @@ module Pdfrb
53
53
  # public-key crypt filters.
54
54
  class CryptFilterPublicKeyMap < Pdfrb::Model::Cos::Dictionary
55
55
  arlington_object "CryptFilterPublicKeyMap"
56
- def filter_for(stream_name)
57
- value[stream_name.to_sym] || value[stream_name.to_s]
58
- end
56
+ include NameMap
57
+
58
+ alias filter_for []
59
59
  end
60
60
  end
61
61
  end
@@ -111,25 +111,9 @@ module Pdfrb
111
111
  # map living on the (page or) catalog.
112
112
  class DestsMap < Pdfrb::Model::Cos::Dictionary
113
113
  arlington_object "DestsMap"
114
+ include NameMap
114
115
 
115
- def [](name)
116
- value[name.to_sym] || value[name.to_s]
117
- end
118
-
119
- def add(name, destination)
120
- value[name.to_sym] = destination
121
- name.to_sym
122
- end
123
-
124
- def each_destination(&)
125
- return enum_for(:each_destination) unless block_given?
126
-
127
- value.each(&)
128
- end
129
-
130
- def names
131
- value.keys
132
- end
116
+ alias each_destination each_entry
133
117
  end
134
118
  end
135
119
  end
@@ -39,19 +39,10 @@ module Pdfrb
39
39
  # Tiling pattern's Resources.
40
40
  class CharProcMap < Pdfrb::Model::Cos::Dictionary
41
41
  arlington_object "CharProcMap"
42
- def entries
43
- value.each
44
- end
45
-
46
- def each_procedure(&block)
47
- return enum_for(:each_procedure) unless block
42
+ include NameMap
48
43
 
49
- value.each(&block)
50
- end
51
-
52
- def procedure_for(char_name)
53
- value[char_name.to_sym] || value[char_name.to_s]
54
- end
44
+ alias each_procedure each_entry
45
+ alias procedure_for []
55
46
 
56
47
  def has_glyph?(char_name)
57
48
  !!procedure_for(char_name)
@@ -208,14 +208,9 @@ module Pdfrb
208
208
  # colorant name -> ink solidity percentage.
209
209
  class Solidities < Pdfrb::Model::Cos::Dictionary
210
210
  arlington_object "Solidities"
211
+ include NameMap
211
212
 
212
- def [](colorant)
213
- value[colorant.to_sym] || value[colorant.to_s]
214
- end
215
-
216
- def colorant_names
217
- value.keys
218
- end
213
+ alias colorant_names names
219
214
  end
220
215
 
221
216
  # Source information (s14.10.2, /SourceInfo): provenance for
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfrb
4
+ module Model
5
+ module Type
6
+ # Shared behaviour for name-keyed maps (Resources
7
+ # sub-dictionaries, role/class maps, VRI entries): lookup
8
+ # accepts Symbol or String, +add+ normalises the key to a
9
+ # Symbol, +names+ lists the keys.
10
+ module NameMap
11
+ def [](name)
12
+ key = name.to_sym
13
+ value.key?(key) ? value[key] : value[name.to_s]
14
+ end
15
+
16
+ def add(name, entry)
17
+ value[name.to_sym] = entry
18
+ name.to_sym
19
+ end
20
+
21
+ def names
22
+ value.keys
23
+ end
24
+
25
+ def each_entry(&)
26
+ return enum_for(:each_entry) unless block_given?
27
+
28
+ value.each(&)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -16,25 +16,9 @@ module Pdfrb
16
16
  # to patterns.
17
17
  class PatternMap < Pdfrb::Model::Cos::Dictionary
18
18
  arlington_object "PatternMap"
19
+ include NameMap
19
20
 
20
- def [](name)
21
- value[name.to_sym] || value[name.to_s]
22
- end
23
-
24
- def add(name, pattern)
25
- value[name.to_sym] = pattern
26
- name.to_sym
27
- end
28
-
29
- def each_pattern(&)
30
- return enum_for(:each_pattern) unless block_given?
31
-
32
- value.each(&)
33
- end
34
-
35
- def names
36
- value.keys
37
- end
21
+ alias each_pattern each_entry
38
22
  end
39
23
  end
40
24
  end
@@ -116,25 +116,9 @@ module Pdfrb
116
116
  # to shadings.
117
117
  class ShadingMap < Pdfrb::Model::Cos::Dictionary
118
118
  arlington_object "ShadingMap"
119
+ include NameMap
119
120
 
120
- def [](name)
121
- value[name.to_sym] || value[name.to_s]
122
- end
123
-
124
- def add(name, shading)
125
- value[name.to_sym] = shading
126
- name.to_sym
127
- end
128
-
129
- def each_shading(&)
130
- return enum_for(:each_shading) unless block_given?
131
-
132
- value.each(&)
133
- end
134
-
135
- def names
136
- value.keys
137
- end
121
+ alias each_shading each_entry
138
122
  end
139
123
  end
140
124
  end
@@ -24,14 +24,9 @@ module Pdfrb
24
24
  # keyed by DN component (CN, O, C, ...).
25
25
  class SubjectDN < Pdfrb::Model::Cos::Dictionary
26
26
  arlington_object "SubjectDN"
27
+ include NameMap
27
28
 
28
- def [](component)
29
- value[component.to_sym] || value[component.to_s]
30
- end
31
-
32
- def components
33
- value.keys
34
- end
29
+ alias components names
35
30
  end
36
31
 
37
32
  # Document timestamp signature (s12.8.1, /DocTimeStamp): an
@@ -88,14 +83,9 @@ module Pdfrb
88
83
  # validation data for one signature.
89
84
  class VRIMap < Pdfrb::Model::Cos::Dictionary
90
85
  arlington_object "VRIMap"
86
+ include NameMap
91
87
 
92
- def [](signature_hash)
93
- value[signature_hash.to_sym] || value[signature_hash.to_s]
94
- end
95
-
96
- def signature_hashes
97
- value.keys
98
- end
88
+ alias signature_hashes names
99
89
  end
100
90
 
101
91
  # Associated-file embedded-file parameters (PDF 2.0 App Note
@@ -165,14 +155,9 @@ module Pdfrb
165
155
  # developer names to their DevExtensions entries.
166
156
  class Extensions < Pdfrb::Model::Cos::Dictionary
167
157
  arlington_object "Extensions"
158
+ include NameMap
168
159
 
169
- def [](developer)
170
- value[developer.to_sym] || value[developer.to_s]
171
- end
172
-
173
- def developers
174
- value.keys
175
- end
160
+ alias developers names
176
161
  end
177
162
 
178
163
  # GTS Procedural Steps group (prepress): identifies a
@@ -38,19 +38,7 @@ module Pdfrb
38
38
  # ExtGState dictionaries.
39
39
  class GraphicsStateParameterMap < Pdfrb::Model::Cos::Dictionary
40
40
  arlington_object "GraphicsStateParameterMap"
41
-
42
- def [](name)
43
- value[name.to_sym] || value[name.to_s]
44
- end
45
-
46
- def add(name, parameters)
47
- value[name.to_sym] = parameters
48
- name.to_sym
49
- end
50
-
51
- def names
52
- value.keys
53
- end
41
+ include NameMap
54
42
  end
55
43
 
56
44
  # Transparency group /Group dictionary (s11.2.4.5): isolation
@@ -45,24 +45,16 @@ module Pdfrb
45
45
  # names mapped to standard structure types.
46
46
  class RoleMap < Pdfrb::Model::Cos::Dictionary
47
47
  arlington_object "RoleMap"
48
+ include NameMap
48
49
 
49
- def [](custom_name)
50
- value[custom_name.to_sym] || value[custom_name.to_s]
51
- end
52
-
53
- def custom_names
54
- value.keys
55
- end
50
+ alias custom_names names
56
51
  end
57
52
 
58
53
  # Namespaced role map (s14.7.3, /RoleMapNS): per-namespace role
59
54
  # maps keyed by namespace URI.
60
55
  class RoleMapNS < Pdfrb::Model::Cos::Dictionary
61
56
  arlington_object "RoleMapNS"
62
-
63
- def [](namespace)
64
- value[namespace.to_sym] || value[namespace.to_s]
65
- end
57
+ include NameMap
66
58
  end
67
59
 
68
60
  # Style dictionary (s14.9.2, /Styles entries): number-of-style
@@ -77,14 +69,9 @@ module Pdfrb
77
69
  # attribute-owner dictionaries shared by structure elements.
78
70
  class ClassMap < Pdfrb::Model::Cos::Dictionary
79
71
  arlington_object "ClassMap"
72
+ include NameMap
80
73
 
81
- def [](class_name)
82
- value[class_name.to_sym] || value[class_name.to_s]
83
- end
84
-
85
- def class_names
86
- value.keys
87
- end
74
+ alias class_names names
88
75
  end
89
76
 
90
77
  # Reference structure element kid (s14.8.2.4, /Reference):
@@ -89,19 +89,7 @@ module Pdfrb
89
89
  # Resources /XObject dictionary (s7.8.3): name -> XObject.
90
90
  class XObjectMap < Pdfrb::Model::Cos::Dictionary
91
91
  arlington_object "XObjectMap"
92
-
93
- def [](name)
94
- value[name.to_sym] || value[name.to_s]
95
- end
96
-
97
- def add(name, xobject)
98
- value[name.to_sym] = xobject
99
- name.to_sym
100
- end
101
-
102
- def names
103
- value.keys
104
- end
92
+ include NameMap
105
93
  end
106
94
  end
107
95
  end
@@ -40,6 +40,8 @@ module Pdfrb
40
40
  end
41
41
  end
42
42
 
43
+ autoload :NameMap, "pdfrb/model/type/name_map"
44
+
43
45
  # Base semantic types.
44
46
  autoload :FileTrailer, "pdfrb/model/type/file_trailer"
45
47
  autoload :Catalog, "pdfrb/model/type/catalog"
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.8.3"
4
+ VERSION = "0.8.4"
5
5
  end
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.8.3
4
+ version: 0.8.4
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-28 00:00:00.000000000 Z
11
+ date: 2026-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark
@@ -1143,6 +1143,7 @@ files:
1143
1143
  - lib/pdfrb/model/type/misc_helpers.rb
1144
1144
  - lib/pdfrb/model/type/movie.rb
1145
1145
  - lib/pdfrb/model/type/movie_annotation.rb
1146
+ - lib/pdfrb/model/type/name_map.rb
1146
1147
  - lib/pdfrb/model/type/names.rb
1147
1148
  - lib/pdfrb/model/type/namespace.rb
1148
1149
  - lib/pdfrb/model/type/object_reference.rb