Class: HexaPDF::Font::Type1::PFBParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/font/type1/pfb_parser.rb

Overview

Parses files in the PFB file format.

Note that this implementation isn’t a full PFB parser. It is currently just used for extracting the font encoding.

Class Method Summary collapse

Class Method Details

.encoding(data) ⇒ Object

:call-seq:

PFBParser.encoding(data)       -> encoding

Parses the PFB data given as string and returns the found Encoding.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hexapdf/font/type1/pfb_parser.rb', line 55

def self.encoding(data)
  enc = Encoding::Base.new
  ss = StringScanner.new(data)
  if ss.skip_until(/\/Encoding\s+\d+\s+array.+?(?=\bdup\b)/m)
    while ss.skip(/dup\s+(\d+)\s+\/(\w+)\s+put\s+/)
      enc.code_to_name[ss[1].to_i] = ss[2].intern
    end
  elsif ss.skip_until(/\/Encoding\s+StandardEncoding\s+def/)
    enc = Encoding.for_name(:StandardEncoding)
  else
    raise HexaPDF::Error, "Unknown Type1 encoding"
  end
  enc
end