pdf-reader 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +6 -1
  3. data/lib/pdf-reader.rb +1 -0
  4. data/lib/pdf/hash.rb +1 -0
  5. data/lib/pdf/reader.rb +1 -0
  6. data/lib/pdf/reader/buffer.rb +11 -10
  7. data/lib/pdf/reader/cid_widths.rb +2 -0
  8. data/lib/pdf/reader/cmap.rb +1 -0
  9. data/lib/pdf/reader/encoding.rb +1 -0
  10. data/lib/pdf/reader/error.rb +1 -0
  11. data/lib/pdf/reader/filter.rb +1 -0
  12. data/lib/pdf/reader/filter/ascii85.rb +1 -0
  13. data/lib/pdf/reader/filter/ascii_hex.rb +2 -0
  14. data/lib/pdf/reader/filter/depredict.rb +1 -0
  15. data/lib/pdf/reader/filter/flate.rb +1 -0
  16. data/lib/pdf/reader/filter/lzw.rb +2 -0
  17. data/lib/pdf/reader/filter/null.rb +2 -0
  18. data/lib/pdf/reader/filter/run_length.rb +3 -1
  19. data/lib/pdf/reader/font.rb +1 -0
  20. data/lib/pdf/reader/font_descriptor.rb +1 -0
  21. data/lib/pdf/reader/form_xobject.rb +1 -0
  22. data/lib/pdf/reader/glyph_hash.rb +1 -0
  23. data/lib/pdf/reader/lzw.rb +2 -1
  24. data/lib/pdf/reader/null_security_handler.rb +1 -0
  25. data/lib/pdf/reader/object_cache.rb +1 -0
  26. data/lib/pdf/reader/object_hash.rb +1 -0
  27. data/lib/pdf/reader/object_stream.rb +1 -0
  28. data/lib/pdf/reader/orientation_detector.rb +1 -0
  29. data/lib/pdf/reader/page.rb +1 -0
  30. data/lib/pdf/reader/page_layout.rb +1 -0
  31. data/lib/pdf/reader/page_state.rb +1 -0
  32. data/lib/pdf/reader/page_text_receiver.rb +1 -0
  33. data/lib/pdf/reader/pages_strategy.rb +1 -0
  34. data/lib/pdf/reader/parser.rb +5 -4
  35. data/lib/pdf/reader/print_receiver.rb +1 -0
  36. data/lib/pdf/reader/reference.rb +1 -0
  37. data/lib/pdf/reader/register_receiver.rb +1 -0
  38. data/lib/pdf/reader/resource_methods.rb +1 -0
  39. data/lib/pdf/reader/standard_security_handler.rb +1 -0
  40. data/lib/pdf/reader/standard_security_handler_v5.rb +2 -0
  41. data/lib/pdf/reader/stream.rb +1 -0
  42. data/lib/pdf/reader/synchronized_cache.rb +1 -0
  43. data/lib/pdf/reader/text_run.rb +1 -0
  44. data/lib/pdf/reader/token.rb +1 -0
  45. data/lib/pdf/reader/transformation_matrix.rb +1 -0
  46. data/lib/pdf/reader/unimplemented_security_handler.rb +1 -0
  47. data/lib/pdf/reader/width_calculator.rb +1 -0
  48. data/lib/pdf/reader/width_calculator/built_in.rb +1 -0
  49. data/lib/pdf/reader/width_calculator/composite.rb +1 -0
  50. data/lib/pdf/reader/width_calculator/true_type.rb +2 -2
  51. data/lib/pdf/reader/width_calculator/type_one_or_three.rb +1 -0
  52. data/lib/pdf/reader/width_calculator/type_zero.rb +1 -0
  53. data/lib/pdf/reader/xref.rb +4 -1
  54. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1e63414d8a3db12b6ea802fc45893ebf35c09dd37ca02c5cc73137d7d782364
4
- data.tar.gz: afb778860a3dd8aab83d634c393666e159101505aba843262f61f7af49cf30e5
3
+ metadata.gz: cfc4ed13692a51d8b78fc181d67fcf8b5e00fb1679dbca36137961f63365edaf
4
+ data.tar.gz: de5556fabc41642746fd242a2623c92c9424c56da2d845507c49624c312b646b
5
5
  SHA512:
6
- metadata.gz: 1c32f7ac1b0d9f0d27ec445905af7dce3544d505221d6b940b8f5f37f85eaf95fad81d40850c85788dc459b59dd1f58398b27e9ec8e72bdbb077e94f77e9f332
7
- data.tar.gz: 88bdd1bebe08ad919344788a9a7416e782c7fb5185ef984447ab1f9c968a8fb6a24af2b95dec99da2b43d4d4861a64ba1e8584f0ec25d01c3c13ae4f81f0191c
6
+ metadata.gz: 4074d5dd87f1ad9286f4022ad46a4160f44c6afed2341f9115029770770ae80b248ace9a8d5df0e444046bed662f9aa5a9334822b23222abec9574523d9e7c36
7
+ data.tar.gz: a69837921f7581d2aeb9226d0791b4b0dd5925a9f83e9cb4cee4dbaf43af33e6a7a570292650a14006ffc9d1759f2ea4ef268381e5aa63fc6da5c1a6d38f46a7
data/CHANGELOG CHANGED
@@ -1,4 +1,9 @@
1
- v2.1.0 (15th Februar 2018)
1
+ v2.2.0 (18th December 2018)
2
+ - Support additional XRef Stream variants (thanks Stefan Wienert)
3
+ - Add frozen_strings pragma to reduce object allocations on ruby 2.3+
4
+ - various bug fixes
5
+
6
+ v2.1.0 (15th February 2018)
2
7
  - Support extra encrypted PDF variants (thanks to Gyuchang Jun)
3
8
  - various bug fixes
4
9
 
@@ -1,3 +1,4 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "pdf/reader"
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module PDF
4
5
  # This class is deprecated, please stop using it.
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: ASCII-8BIT
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -225,7 +226,7 @@ class PDF::Reader
225
226
  end
226
227
 
227
228
  def prepare_inline_token
228
- str = ""
229
+ str = "".dup
229
230
 
230
231
  buffer = []
231
232
 
@@ -248,7 +249,7 @@ class PDF::Reader
248
249
  # we find a closing >
249
250
  #
250
251
  def prepare_hex_token
251
- str = ""
252
+ str = "".dup
252
253
  finished = false
253
254
 
254
255
  while !finished
@@ -278,7 +279,7 @@ class PDF::Reader
278
279
  # problem.
279
280
  #
280
281
  def prepare_literal_token
281
- str = ""
282
+ str = "".dup
282
283
  count = 1
283
284
 
284
285
  while count > 0
@@ -308,7 +309,7 @@ class PDF::Reader
308
309
  # to read up on it.
309
310
  #
310
311
  def prepare_regular_token
311
- tok = ""
312
+ tok = "".dup
312
313
 
313
314
  while byte = @io.getbyte
314
315
  case byte
@@ -327,7 +328,7 @@ class PDF::Reader
327
328
  while TOKEN_WHITESPACE.include?(peek_byte) && tok.size == 0
328
329
  @io.getbyte
329
330
  end
330
- tok = ""
331
+ tok = "".dup
331
332
  break
332
333
  when 0x3C
333
334
  # opening delimiter '<', start of new token
@@ -338,7 +339,7 @@ class PDF::Reader
338
339
  else
339
340
  @tokens << "<"
340
341
  end
341
- tok = ""
342
+ tok = "".dup
342
343
  break
343
344
  when 0x3E
344
345
  # closing delimiter '>', start of new token
@@ -349,26 +350,26 @@ class PDF::Reader
349
350
  else
350
351
  @tokens << ">"
351
352
  end
352
- tok = ""
353
+ tok = "".dup
353
354
  break
354
355
  when 0x28, 0x5B, 0x7B
355
356
  # opening delimiter, start of new token
356
357
  @tokens << tok if tok.size > 0
357
358
  @tokens << byte.chr
358
- tok = ""
359
+ tok = "".dup
359
360
  break
360
361
  when 0x29, 0x5D, 0x7D
361
362
  # closing delimiter
362
363
  @tokens << tok if tok.size > 0
363
364
  @tokens << byte.chr
364
- tok = ""
365
+ tok = "".dup
365
366
  break
366
367
  when 0x2F
367
368
  # PDF name, start of new token
368
369
  @tokens << tok if tok.size > 0
369
370
  @tokens << byte.chr
370
371
  @tokens << "" if byte == 0x2F && ([nil, 0x20, 0x0A] + TOKEN_DELIMITER).include?(peek_byte)
371
- tok = ""
372
+ tok = "".dup
372
373
  break
373
374
  else
374
375
  tok << byte
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
 
4
6
  require 'forwardable'
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'ascii85'
4
5
 
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  class PDF::Reader
4
6
  module Filter # :nodoc:
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  module Filter # :nodoc:
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
 
4
5
  require 'zlib'
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  class PDF::Reader
4
6
  module Filter # :nodoc:
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  class PDF::Reader
4
6
  module Filter # :nodoc:
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  class PDF::Reader # :nodoc:
4
6
  module Filter # :nodoc:
@@ -12,7 +14,7 @@ class PDF::Reader # :nodoc:
12
14
  # Decode the specified data with the RunLengthDecode compression algorithm
13
15
  def filter(data)
14
16
  pos = 0
15
- out = ""
17
+ out = "".dup
16
18
 
17
19
  while pos < data.length
18
20
  length = data.getbyte(pos)
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'ttfunk'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'digest/md5'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module PDF
4
5
 
@@ -82,7 +83,7 @@ module PDF
82
83
  #
83
84
  def self.decode(data)
84
85
  stream = BitStream.new data.to_s, 9 # size of codes between 9 and 12 bits
85
- result = ''
86
+ result = "".dup
86
87
  until (code = stream.read) == CODE_EOD
87
88
  if code == CODE_CLEAR_TABLE
88
89
  stream.set_bits_in_chunk(9)
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'hashery/lru_hash'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  # Provides low level access to the objects in a PDF file via a hash-like
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  # Small util class for detecting the orientation of a single PDF page. Accounts
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module PDF
4
5
  class Reader
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pdf/reader/transformation_matrix'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'forwardable'
4
5
  require 'pdf/reader/page_layout'
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -132,7 +133,7 @@ class PDF::Reader
132
133
  # reads a PDF name from the buffer and converts it to a Ruby Symbol
133
134
  def pdf_name
134
135
  tok = @buffer.token
135
- tok.gsub!(/#([A-Fa-f0-9]{2})/) do |match|
136
+ tok = tok.dup.gsub(/#([A-Fa-f0-9]{2})/) do |match|
136
137
  match[1, 2].hex.chr
137
138
  end
138
139
  tok.to_sym
@@ -154,7 +155,7 @@ class PDF::Reader
154
155
  ################################################################################
155
156
  # Reads a PDF hex string from the buffer and converts it to a Ruby String
156
157
  def hex_string
157
- str = ""
158
+ str = "".dup
158
159
 
159
160
  loop do
160
161
  token = @buffer.token
@@ -171,11 +172,11 @@ class PDF::Reader
171
172
  # Reads a PDF String from the buffer and converts it to a Ruby String
172
173
  def string
173
174
  str = @buffer.token
174
- return "".force_encoding("binary") if str == ")"
175
+ return "".dup.force_encoding("binary") if str == ")"
175
176
  Error.assert_equal(parse_token, ")")
176
177
 
177
178
  str.gsub!(/\\([nrtbf()\\\n]|\d{1,3})?|\r\n?|\n\r/m) do |match|
178
- MAPPING[match] || ""
179
+ MAPPING[match] || "".dup
179
180
  end
180
181
  str.force_encoding("binary")
181
182
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  # A simple receiver that prints all operaters and parameters in the content
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  # Copyright (C) 2010 James Healy (jimmy@deefa.com)
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module PDF
4
5
  class Reader
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'digest'
3
5
  require 'openssl'
4
6
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  # utilities.rb : General-purpose utility classes which don't fit anywhere else
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  # A value object that represents one or more consecutive characters on a page.
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  # co-ordinate systems in PDF files are specified using a 3x3 matrix that looks
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  # PDF files may define fonts in a number of ways. Each approach means we must
4
5
  # calculate glyph widths differently, so this set of classes conform to an
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'afm'
4
5
  require 'pdf/reader/synchronized_cache'
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  module WidthCalculator
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  module WidthCalculator
@@ -17,8 +18,7 @@ class PDF::Reader
17
18
 
18
19
  def glyph_width(code_point)
19
20
  return 0 if code_point.nil? || code_point < 0
20
-
21
- glyph_width_from_font(code_point) || glyph_width_from_descriptor(code_point)
21
+ glyph_width_from_font(code_point) || glyph_width_from_descriptor(code_point) || 0
22
22
  end
23
23
 
24
24
  private
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  module WidthCalculator
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  class PDF::Reader
4
5
  module WidthCalculator
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -203,8 +204,10 @@ class PDF::Reader
203
204
  ("\x00" + bytes).unpack("N")[0]
204
205
  elsif bytes.size == 4
205
206
  bytes.unpack("N")[0]
207
+ elsif bytes.size == 8
208
+ bytes.unpack("Q>")[0]
206
209
  else
207
- raise UnsupportedFeatureError, "Unable to unpack xref stream entries with more than 4 bytes"
210
+ raise UnsupportedFeatureError, "Unable to unpack xref stream entries of #{bytes.size} bytes"
208
211
  end
209
212
  end
210
213
  ################################################################################
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2018-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -296,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
296
  version: '0'
297
297
  requirements: []
298
298
  rubyforge_project:
299
- rubygems_version: 2.7.3
299
+ rubygems_version: 2.7.6
300
300
  signing_key:
301
301
  specification_version: 4
302
302
  summary: A library for accessing the content of PDF files