hexapdf 0.20.0 → 0.20.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.
@@ -12,6 +12,8 @@
12
12
  # implied. See the License for the specific language governing
13
13
  # permissions and limitations under the License.
14
14
  # -----------------------------------------------------------
15
+ # Modified for use with HexaPDF
16
+ # -----------------------------------------------------------
15
17
  # Name: ITC Zapf Dingbats Glyph List
16
18
  # Table version: 2.0
17
19
  # Date: September 20, 2002
@@ -21,205 +23,204 @@
21
23
  # (1) glyph name--upper/lowercase letters and digits
22
24
  # (2) Unicode scalar value--four uppercase hexadecimal digits
23
25
  #
24
- a100;275E
25
- a101;2761
26
- a102;2762
27
- a103;2763
28
- a104;2764
29
- a105;2710
30
- a106;2765
31
- a107;2766
32
- a108;2767
33
- a109;2660
34
- a10;2721
35
- a110;2665
36
- a111;2666
37
- a112;2663
38
- a117;2709
39
- a118;2708
40
- a119;2707
41
- a11;261B
42
- a120;2460
43
- a121;2461
44
- a122;2462
45
- a123;2463
46
- a124;2464
47
- a125;2465
48
- a126;2466
49
- a127;2467
50
- a128;2468
51
- a129;2469
52
- a12;261E
53
- a130;2776
54
- a131;2777
55
- a132;2778
56
- a133;2779
57
- a134;277A
58
- a135;277B
59
- a136;277C
60
- a137;277D
61
- a138;277E
62
- a139;277F
63
- a13;270C
64
- a140;2780
65
- a141;2781
66
- a142;2782
67
- a143;2783
68
- a144;2784
69
- a145;2785
70
- a146;2786
71
- a147;2787
72
- a148;2788
73
- a149;2789
74
- a14;270D
75
- a150;278A
76
- a151;278B
77
- a152;278C
78
- a153;278D
79
- a154;278E
80
- a155;278F
81
- a156;2790
82
- a157;2791
83
- a158;2792
84
- a159;2793
85
- a15;270E
86
- a160;2794
87
- a161;2192
88
- a162;27A3
89
- a163;2194
90
- a164;2195
91
- a165;2799
92
- a166;279B
93
- a167;279C
94
- a168;279D
95
- a169;279E
96
- a16;270F
97
- a170;279F
98
- a171;27A0
99
- a172;27A1
100
- a173;27A2
101
- a174;27A4
102
- a175;27A5
103
- a176;27A6
104
- a177;27A7
105
- a178;27A8
106
- a179;27A9
107
- a17;2711
108
- a180;27AB
109
- a181;27AD
110
- a182;27AF
111
- a183;27B2
112
- a184;27B3
113
- a185;27B5
114
- a186;27B8
115
- a187;27BA
116
- a188;27BB
117
- a189;27BC
118
- a18;2712
119
- a190;27BD
120
- a191;27BE
121
- a192;279A
122
- a193;27AA
123
- a194;27B6
124
- a195;27B9
125
- a196;2798
126
- a197;27B4
127
- a198;27B7
128
- a199;27AC
129
- a19;2713
130
- a1;2701
131
- a200;27AE
132
- a201;27B1
133
- a202;2703
134
- a203;2750
135
- a204;2752
136
- a205;276E
137
- a206;2770
138
- a20;2714
139
- a21;2715
140
- a22;2716
141
- a23;2717
142
- a24;2718
143
- a25;2719
144
- a26;271A
145
- a27;271B
146
- a28;271C
147
- a29;2722
148
- a2;2702
149
- a30;2723
150
- a31;2724
151
- a32;2725
152
- a33;2726
153
- a34;2727
154
- a35;2605
155
- a36;2729
156
- a37;272A
157
- a38;272B
158
- a39;272C
159
- a3;2704
160
- a40;272D
161
- a41;272E
162
- a42;272F
163
- a43;2730
164
- a44;2731
165
- a45;2732
166
- a46;2733
167
- a47;2734
168
- a48;2735
169
- a49;2736
170
- a4;260E
171
- a50;2737
172
- a51;2738
173
- a52;2739
174
- a53;273A
175
- a54;273B
176
- a55;273C
177
- a56;273D
178
- a57;273E
179
- a58;273F
180
- a59;2740
181
- a5;2706
182
- a60;2741
183
- a61;2742
184
- a62;2743
185
- a63;2744
186
- a64;2745
187
- a65;2746
188
- a66;2747
189
- a67;2748
190
- a68;2749
191
- a69;274A
192
- a6;271D
193
- a70;274B
194
- a71;25CF
195
- a72;274D
196
- a73;25A0
197
- a74;274F
198
- a75;2751
199
- a76;25B2
200
- a77;25BC
201
- a78;25C6
202
- a79;2756
203
- a7;271E
204
- a81;25D7
205
- a82;2758
206
- a83;2759
207
- a84;275A
208
- a85;276F
209
- a86;2771
210
- a87;2772
211
- a88;2773
212
- a89;2768
213
- a8;271F
214
- a90;2769
215
- a91;276C
216
- a92;276D
217
- a93;276A
218
- a94;276B
219
- a95;2774
220
- a96;2775
221
- a97;275B
222
- a98;275C
223
- a99;275D
224
- a9;2720
225
- #END
26
+ a100;❞
27
+ a101;❡
28
+ a102;❢
29
+ a103;❣
30
+ a104;❤
31
+ a105;✐
32
+ a106;❥
33
+ a107;❦
34
+ a108;❧
35
+ a109;♠
36
+ a10;✡
37
+ a110;♥
38
+ a111;♦
39
+ a112;♣
40
+ a117;✉
41
+ a118;✈
42
+ a119;✇
43
+ a11;☛
44
+ a120;①
45
+ a121;②
46
+ a122;③
47
+ a123;④
48
+ a124;⑤
49
+ a125;⑥
50
+ a126;⑦
51
+ a127;⑧
52
+ a128;⑨
53
+ a129;⑩
54
+ a12;☞
55
+ a130;❶
56
+ a131;❷
57
+ a132;❸
58
+ a133;❹
59
+ a134;❺
60
+ a135;❻
61
+ a136;❼
62
+ a137;❽
63
+ a138;❾
64
+ a139;❿
65
+ a13;✌
66
+ a140;➀
67
+ a141;➁
68
+ a142;➂
69
+ a143;➃
70
+ a144;➄
71
+ a145;➅
72
+ a146;➆
73
+ a147;➇
74
+ a148;➈
75
+ a149;➉
76
+ a14;✍
77
+ a150;➊
78
+ a151;➋
79
+ a152;➌
80
+ a153;➍
81
+ a154;➎
82
+ a155;➏
83
+ a156;➐
84
+ a157;➑
85
+ a158;➒
86
+ a159;➓
87
+ a15;✎
88
+ a160;➔
89
+ a161;→
90
+ a162;➣
91
+ a163;↔
92
+ a164;↕
93
+ a165;➙
94
+ a166;➛
95
+ a167;➜
96
+ a168;➝
97
+ a169;➞
98
+ a16;✏
99
+ a170;➟
100
+ a171;➠
101
+ a172;➡
102
+ a173;➢
103
+ a174;➤
104
+ a175;➥
105
+ a176;➦
106
+ a177;➧
107
+ a178;➨
108
+ a179;➩
109
+ a17;✑
110
+ a180;➫
111
+ a181;➭
112
+ a182;➯
113
+ a183;➲
114
+ a184;➳
115
+ a185;➵
116
+ a186;➸
117
+ a187;➺
118
+ a188;➻
119
+ a189;➼
120
+ a18;✒
121
+ a190;➽
122
+ a191;➾
123
+ a192;➚
124
+ a193;➪
125
+ a194;➶
126
+ a195;➹
127
+ a196;➘
128
+ a197;➴
129
+ a198;➷
130
+ a199;➬
131
+ a19;✓
132
+ a1;✁
133
+ a200;➮
134
+ a201;➱
135
+ a202;✃
136
+ a203;❐
137
+ a204;❒
138
+ a205;❮
139
+ a206;❰
140
+ a20;✔
141
+ a21;✕
142
+ a22;✖
143
+ a23;✗
144
+ a24;✘
145
+ a25;✙
146
+ a26;✚
147
+ a27;✛
148
+ a28;✜
149
+ a29;✢
150
+ a2;✂
151
+ a30;✣
152
+ a31;✤
153
+ a32;✥
154
+ a33;✦
155
+ a34;✧
156
+ a35;★
157
+ a36;✩
158
+ a37;✪
159
+ a38;✫
160
+ a39;✬
161
+ a3;✄
162
+ a40;✭
163
+ a41;✮
164
+ a42;✯
165
+ a43;✰
166
+ a44;✱
167
+ a45;✲
168
+ a46;✳
169
+ a47;✴
170
+ a48;✵
171
+ a49;✶
172
+ a4;☎
173
+ a50;✷
174
+ a51;✸
175
+ a52;✹
176
+ a53;✺
177
+ a54;✻
178
+ a55;✼
179
+ a56;✽
180
+ a57;✾
181
+ a58;✿
182
+ a59;❀
183
+ a5;✆
184
+ a60;❁
185
+ a61;❂
186
+ a62;❃
187
+ a63;❄
188
+ a64;❅
189
+ a65;❆
190
+ a66;❇
191
+ a67;❈
192
+ a68;❉
193
+ a69;❊
194
+ a6;✝
195
+ a70;❋
196
+ a71;●
197
+ a72;❍
198
+ a73;■
199
+ a74;❏
200
+ a75;❑
201
+ a76;▲
202
+ a77;▼
203
+ a78;◆
204
+ a79;❖
205
+ a7;✞
206
+ a81;◗
207
+ a82;❘
208
+ a83;❙
209
+ a84;❚
210
+ a85;❯
211
+ a86;❱
212
+ a87;❲
213
+ a88;❳
214
+ a89;❨
215
+ a8;✟
216
+ a90;❩
217
+ a91;❬
218
+ a92;❭
219
+ a93;❪
220
+ a94;❫
221
+ a95;❴
222
+ a96;❵
223
+ a97;❛
224
+ a98;❜
225
+ a99;❝
226
+ a9;✠
@@ -135,12 +135,20 @@ module HexaPDF
135
135
  concrete_field_type = field.concrete_field_type
136
136
  nice_field_type = concrete_field_type.to_s.split('_').map(&:capitalize).join(' ')
137
137
  position = "(#{widget[:Rect].left}, #{widget[:Rect].bottom})"
138
+ field_value = if !field.field_value || concrete_field_type != :signature_field
139
+ field.field_value.inspect
140
+ else
141
+ sig = field.field_value
142
+ temp = "#{sig.signer_name} (#{sig.signing_time})"
143
+ temp << " (#{sig.signing_reason})" if sig.signing_reason
144
+ temp
145
+ end
138
146
 
139
147
  puts " #{field_name}"
140
148
  if command_parser.verbosity_info?
141
149
  printf(" └─ %-22s | %-20s\n", nice_field_type, position)
142
150
  end
143
- puts " └─ #{field.field_value.inspect}"
151
+ puts " └─ #{field_value}"
144
152
  if command_parser.verbosity_info?
145
153
  if field.field_type == :Ch
146
154
  puts " └─ Options: #{field.option_items.map(&:inspect).join(', ')}"
@@ -249,6 +249,10 @@ module HexaPDF
249
249
  @document = document
250
250
  @encrypt_dict_hash = nil
251
251
  @encryption_details = {}
252
+
253
+ @is_encrypt_dict = document.revisions.each.with_object({}) do |rev, hash|
254
+ hash[rev.trailer[:Encrypt]] = true
255
+ end
252
256
  end
253
257
 
254
258
  # Checks if the encryption key computed by this security handler is derived from the
@@ -262,7 +266,7 @@ module HexaPDF
262
266
  #
263
267
  # See: PDF1.7 s7.6.2
264
268
  def decrypt(obj)
265
- return obj if obj == document.trailer[:Encrypt] || obj.type == :XRef
269
+ return obj if @is_encrypt_dict[obj] || obj.type == :XRef
266
270
 
267
271
  key = object_key(obj.oid, obj.gen, string_algorithm)
268
272
  each_string_in_object(obj.value) do |str|
@@ -131,13 +131,12 @@ module HexaPDF
131
131
  def load_file(file)
132
132
  name2uni = {}
133
133
  uni2name = {}
134
- File.open(file, 'rb') do |f|
134
+ File.open(file, 'r:UTF-8') do |f|
135
+ 25.times { f.gets } # Skip comments
135
136
  while (line = f.gets)
136
- next if line.start_with?('#')
137
- index = line.index(';')
138
- name = line[0, index].to_sym
139
- codes = line[index + 1, 50].split(" ").map(&:hex).pack('U*')
140
- name2uni[name] = codes
137
+ name, codes = line.split(';', 2)
138
+ name = name.to_sym
139
+ name2uni[name] = codes.chomp!
141
140
  uni2name[codes] = name unless uni2name.key?(codes)
142
141
  end
143
142
  end
@@ -212,24 +212,23 @@ module HexaPDF
212
212
 
213
213
  # Creates a PDF object representing the wrapped font for the given PDF document.
214
214
  def create_pdf_object(document)
215
- fd = document.wrap({Type: :FontDescriptor,
216
- FontName: @wrapped_font.font_name.intern,
217
- FontWeight: @wrapped_font.weight_class,
218
- FontBBox: @wrapped_font.bounding_box,
219
- ItalicAngle: @wrapped_font.italic_angle || 0,
220
- Ascent: @wrapped_font.ascender || 0,
221
- Descent: @wrapped_font.descender || 0,
222
- CapHeight: @wrapped_font.cap_height,
223
- XHeight: @wrapped_font.x_height,
224
- StemH: @wrapped_font.dominant_horizontal_stem_width,
225
- StemV: @wrapped_font.dominant_vertical_stem_width || 0})
215
+ fd = document.add({Type: :FontDescriptor,
216
+ FontName: @wrapped_font.font_name.intern,
217
+ FontWeight: @wrapped_font.weight_class,
218
+ FontBBox: @wrapped_font.bounding_box,
219
+ ItalicAngle: @wrapped_font.italic_angle || 0,
220
+ Ascent: @wrapped_font.ascender || 0,
221
+ Descent: @wrapped_font.descender || 0,
222
+ CapHeight: @wrapped_font.cap_height,
223
+ XHeight: @wrapped_font.x_height,
224
+ StemH: @wrapped_font.dominant_horizontal_stem_width,
225
+ StemV: @wrapped_font.dominant_vertical_stem_width || 0})
226
226
  fd.flag(:fixed_pitch) if @wrapped_font.metrics.is_fixed_pitch
227
227
  fd.flag(@wrapped_font.metrics.character_set == 'Special' ? :symbolic : :nonsymbolic)
228
- fd.must_be_indirect = true
229
228
 
230
- dict = document.wrap({Type: :Font, Subtype: :Type1,
231
- BaseFont: @wrapped_font.font_name.intern,
232
- FontDescriptor: fd})
229
+ dict = document.add({Type: :Font, Subtype: :Type1,
230
+ BaseFont: @wrapped_font.font_name.intern,
231
+ FontDescriptor: fd})
233
232
  dict.font_wrapper = self
234
233
 
235
234
  document.register_listener(:complete_objects) do
@@ -68,9 +68,9 @@ module HexaPDF
68
68
 
69
69
  def execute #:nodoc:
70
70
  if @object
71
- dereference(@object)
71
+ dereference_all(@object)
72
72
  else
73
- dereference(@doc.trailer)
73
+ dereference_all(@doc.trailer)
74
74
  @result = []
75
75
  @doc.each(only_current: false) do |obj|
76
76
  if !@seen.key?(obj.data) && obj.type != :ObjStm && obj.type != :XRef
@@ -83,6 +83,11 @@ module HexaPDF
83
83
  end
84
84
  end
85
85
 
86
+ def dereference_all(object) # :nodoc:
87
+ @dereference_later = [object]
88
+ dereference(@dereference_later.pop) until @dereference_later.empty?
89
+ end
90
+
86
91
  def dereference(object) #:nodoc:
87
92
  return object if object.nil? || @seen.key?(object.data)
88
93
  @seen[object.data] = true
@@ -97,9 +102,12 @@ module HexaPDF
97
102
  when Array
98
103
  val.map! {|v| recurse(v) }
99
104
  when HexaPDF::Reference
100
- dereference(@doc.object(val))
105
+ val = @doc.object(val)
106
+ @dereference_later.push(val)
107
+ val
101
108
  when HexaPDF::Object
102
- dereference(val)
109
+ @dereference_later.push(val)
110
+ val
103
111
  else
104
112
  val
105
113
  end
@@ -234,7 +234,7 @@ module HexaPDF
234
234
  page.contents = processor.result
235
235
  page[:Contents].set_filter(:FlateDecode)
236
236
  xobjects = page.resources[:XObject]
237
- processor.used_references.each {|ref| used_refs[xobjects[ref]] = true }
237
+ processor.used_references.each {|ref| used_refs[xobjects[ref]] = true } if xobjects
238
238
  end
239
239
  used_refs
240
240
  end
@@ -245,7 +245,7 @@ module HexaPDF
245
245
  unless used_refs
246
246
  used_refs = {}
247
247
  doc.pages.each do |page|
248
- xobjects = page.resources[:XObject]
248
+ next unless (xobjects = page.resources[:XObject])
249
249
  HexaPDF::Content::Parser.parse(page.contents) do |op, operands|
250
250
  used_refs[xobjects[operands[0]]] = true if op == :Do
251
251
  end
@@ -253,7 +253,7 @@ module HexaPDF
253
253
  end
254
254
 
255
255
  doc.pages.each do |page|
256
- xobjects = page.resources[:XObject]
256
+ next unless (xobjects = page.resources[:XObject])
257
257
  xobjects.each do |key, obj|
258
258
  next if used_refs[obj]
259
259
  xobjects.delete(key)
@@ -160,7 +160,7 @@ module HexaPDF
160
160
  end
161
161
  return unless entry.kind_of?(HexaPDF::Stream)
162
162
 
163
- if entry.type == :XObject && entry[:Subtype] == :Form
163
+ if entry.type == :XObject && entry[:Subtype] == :Form && !entry.instance_of?(HexaPDF::Stream)
164
164
  entry
165
165
  elsif (entry[:Type].nil? || entry[:Type] == :XObject) &&
166
166
  (entry[:Subtype].nil? || entry[:Subtype] == :Form) && entry[:BBox]
@@ -78,7 +78,7 @@ module HexaPDF
78
78
 
79
79
  # Verifies the signature using the provided OpenSSL::X509::Store object.
80
80
  def verify(store, allow_self_signed: false)
81
- result = VerificationResult.new
81
+ result = super
82
82
 
83
83
  signer_info = self.signer_info
84
84
  signer_certificate = self.signer_certificate
@@ -104,10 +104,6 @@ module HexaPDF
104
104
  result.log(:error, "Certificate key usage is missing 'Digital Signature'")
105
105
  end
106
106
 
107
- verify_signing_time(result)
108
-
109
- store.verify_callback = store_verification_callback(result,
110
- allow_self_signed: allow_self_signed)
111
107
  if @pkcs7.verify(certificate_chain, store, signature_dict.signed_data,
112
108
  OpenSSL::PKCS7::DETACHED | OpenSSL::PKCS7::BINARY)
113
109
  result.log(:info, "Signature valid")
@@ -60,7 +60,7 @@ module HexaPDF
60
60
 
61
61
  # Verifies the signature using the provided OpenSSL::X509::Store object.
62
62
  def verify(store, allow_self_signed: false)
63
- result = VerificationResult.new
63
+ result = super
64
64
 
65
65
  signer_certificate = self.signer_certificate
66
66
  certificate_chain = self.certificate_chain
@@ -76,10 +76,6 @@ module HexaPDF
76
76
  return result
77
77
  end
78
78
 
79
- verify_signing_time(result)
80
-
81
- store.verify_callback = store_verification_callback(result,
82
- allow_self_signed: allow_self_signed)
83
79
  store.verify(signer_certificate, certificate_chain)
84
80
 
85
81
  if signer_certificate.public_key.verify(OpenSSL::Digest.new('SHA1'),