Sha256: d7d6bf3f27ea34f5ab9b1b68be5271b601c248c1b5baa8d83f2ed6b89646b2f4

Contents?: true

Size: 943 Bytes

Versions: 7

Compression:

Stored size: 943 Bytes

Contents

# coding: utf-8
# typed: strict
# frozen_string_literal: true

#
class PDF::Reader
  module Filter # :nodoc:
    # implementation of the AsciiHex stream filter
    class AsciiHex

      def initialize(options = {})
        @options = options
      end

      ################################################################################
      # Decode the specified data using the AsciiHex algorithm.
      #
      def filter(data)
        data.chop! if data[-1,1] == ">"
        data = data[1,data.size] if data[0,1] == "<"

        return "" if data.nil?

        data.gsub!(/[^A-Fa-f0-9]/,"")
        data << "0" if data.size % 2 == 1
        data.scan(/.{2}/).flatten.map { |s| s.hex.chr }.join("")
      rescue Exception => e
        # Oops, there was a problem decoding the stream
        raise MalformedPDFError,
            "Error occured while decoding an ASCIIHex stream (#{e.class.to_s}: #{e.to_s})"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pdf-reader-2.13.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.12.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.11.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.10.0 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.9.2 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.9.1 lib/pdf/reader/filter/ascii_hex.rb
pdf-reader-2.9.0 lib/pdf/reader/filter/ascii_hex.rb