Parent

PDF::Reader::Font

Attributes

basefont[R]
descendantfonts[RW]
encoding[RW]
label[RW]
subtype[RW]
tounicode[RW]

Public Class Methods

glyphnames() click to toggle source

returns a hash that maps glyph names to unicode codepoints. The mapping is based on a text file supplied by Adobe at: www.adobe.com/devnet/opentype/archives/glyphlist.txt

# File lib/pdf/reader/font.rb, line 34
def self.glyphnames
  glyphs = {}

  RUBY_VERSION >= "1.9" ? mode = "r:BINARY" : mode = "r"
  File.open(File.dirname(__FILE__) + "/glyphlist.txt",mode) do |f|
    f.each do |l|
      m, name, code = *l.match(/([0-9A-Za-z]+);([0-9A-F]{4})/)
      glyphs[name.to_sym] = "0x#{code}".hex if name
    end
  end

  glyphs
end

Public Instance Methods

basefont=(font) click to toggle source
# File lib/pdf/reader/font.rb, line 48
def basefont=(font)
  # setup a default encoding for the selected font. It can always be overridden
  # with encoding= if required
  case font
  when "Symbol" then
    @encoding = PDF::Reader::Encoding.new("SymbolEncoding")
  when "ZapfDingbats" then
    @encoding = PDF::Reader::Encoding.new("ZapfDingbatsEncoding")
  else
    @encoding = nil
  end
  @basefont = font
end
to_utf8(params) click to toggle source
# File lib/pdf/reader/font.rb, line 62
def to_utf8(params)
  raise UnsupportedFeatureError, "font encoding '#{encoding}' currently unsupported" if encoding.kind_of?(String)

  if params.class == String
    # translate the bytestram into a UTF-8 string.
    # If an encoding hasn't been specified, assume the text using this
    # font is in Adobe Standard Encoding.
    (encoding || PDF::Reader::Encoding.new(:StandardEncoding)).to_utf8(params, tounicode)
  elsif params.class == Array
    params.collect { |param| self.to_utf8(param) }
  else
    params
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.