Class: PDF::Reader::Font
- Inherits:
-
Object
- Object
- PDF::Reader::Font
- Defined in:
- lib/pdf/reader/font.rb
Instance Attribute Summary collapse
-
#ascent ⇒ Object
readonly
Returns the value of attribute ascent.
-
#basefont ⇒ Object
Returns the value of attribute basefont.
-
#bbox ⇒ Object
readonly
Returns the value of attribute bbox.
-
#descendantfonts ⇒ Object
Returns the value of attribute descendantfonts.
-
#descent ⇒ Object
readonly
Returns the value of attribute descent.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#first_char ⇒ Object
readonly
Returns the value of attribute first_char.
-
#label ⇒ Object
Returns the value of attribute label.
-
#missing_width ⇒ Object
readonly
Returns the value of attribute missing_width.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
-
#tounicode ⇒ Object
Returns the value of attribute tounicode.
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Class Method Summary collapse
-
.glyphnames ⇒ Object
returns a hash that maps glyph names to unicode codepoints.
Instance Method Summary collapse
- #glyph_width(c) ⇒ Object
-
#initialize(ohash = nil, obj = nil) ⇒ Font
constructor
A new instance of Font.
- #to_utf8(params) ⇒ Object
Constructor Details
#initialize(ohash = nil, obj = nil) ⇒ Font
Returns a new instance of Font.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pdf/reader/font.rb', line 32 def initialize(ohash = nil, obj = nil) if ohash.nil? || obj.nil? $stderr.puts "DEPREACTION WARNING - PDF::Reader::Font.new should be called with 2 args" return end @ohash = ohash extract_base_info(obj) extract_descriptor(obj) extract_descendants(obj) end |
Instance Attribute Details
#ascent ⇒ Object (readonly)
Returns the value of attribute ascent.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def ascent @ascent end |
#basefont ⇒ Object
Returns the value of attribute basefont.
30 31 32 |
# File 'lib/pdf/reader/font.rb', line 30 def basefont @basefont end |
#bbox ⇒ Object (readonly)
Returns the value of attribute bbox.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def bbox @bbox end |
#descendantfonts ⇒ Object
Returns the value of attribute descendantfonts.
28 29 30 |
# File 'lib/pdf/reader/font.rb', line 28 def descendantfonts @descendantfonts end |
#descent ⇒ Object (readonly)
Returns the value of attribute descent.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def descent @descent end |
#encoding ⇒ Object
Returns the value of attribute encoding.
28 29 30 |
# File 'lib/pdf/reader/font.rb', line 28 def encoding @encoding end |
#first_char ⇒ Object (readonly)
Returns the value of attribute first_char.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def first_char @first_char end |
#label ⇒ Object
Returns the value of attribute label.
28 29 30 |
# File 'lib/pdf/reader/font.rb', line 28 def label @label end |
#missing_width ⇒ Object (readonly)
Returns the value of attribute missing_width.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def missing_width @missing_width end |
#subtype ⇒ Object
Returns the value of attribute subtype.
28 29 30 |
# File 'lib/pdf/reader/font.rb', line 28 def subtype @subtype end |
#tounicode ⇒ Object
Returns the value of attribute tounicode.
28 29 30 |
# File 'lib/pdf/reader/font.rb', line 28 def tounicode @tounicode end |
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
29 30 31 |
# File 'lib/pdf/reader/font.rb', line 29 def widths @widths end |
Class Method Details
.glyphnames ⇒ Object
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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pdf/reader/font.rb', line 47 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
#glyph_width(c) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/pdf/reader/font.rb', line 90 def glyph_width(c) @missing_width ||= 0 if @widths.nil? 0 else @widths.fetch(c.codepoints.first - @first_char, @missing_width) end end |
#to_utf8(params) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pdf/reader/font.rb', line 75 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 |