Class: PDF::Reader::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/font.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#basefontObject

Returns the value of attribute basefont.



29
30
31
# File 'lib/pdf/reader/font.rb', line 29

def basefont
  @basefont
end

#descendantfontsObject

Returns the value of attribute descendantfonts.



28
29
30
# File 'lib/pdf/reader/font.rb', line 28

def descendantfonts
  @descendantfonts
end

#encodingObject

Returns the value of attribute encoding.



28
29
30
# File 'lib/pdf/reader/font.rb', line 28

def encoding
  @encoding
end

#labelObject

Returns the value of attribute label.



28
29
30
# File 'lib/pdf/reader/font.rb', line 28

def label
  @label
end

#subtypeObject

Returns the value of attribute subtype.



28
29
30
# File 'lib/pdf/reader/font.rb', line 28

def subtype
  @subtype
end

#tounicodeObject

Returns the value of attribute tounicode.



28
29
30
# File 'lib/pdf/reader/font.rb', line 28

def tounicode
  @tounicode
end

Class Method Details

.glyphnamesObject

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



34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Method Details

#to_utf8(params) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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