Class: PDF::Reader::Font
- Inherits:
-
Object
- Object
- PDF::Reader::Font
- Defined in:
- lib/pdf/reader/font.rb
Overview
Represents a single font PDF object and provides some useful methods for extracting info. Mainly used for converting text to UTF-8.
Instance Attribute Summary collapse
-
#basefont ⇒ Object
Returns the value of attribute basefont.
-
#cid_default_width ⇒ Object
readonly
Returns the value of attribute cid_default_width.
-
#cid_widths ⇒ Object
readonly
Returns the value of attribute cid_widths.
-
#descendantfonts ⇒ Object
Returns the value of attribute descendantfonts.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#first_char ⇒ Object
readonly
Returns the value of attribute first_char.
-
#font_descriptor ⇒ Object
readonly
Returns the value of attribute font_descriptor.
-
#last_char ⇒ Object
readonly
Returns the value of attribute last_char.
-
#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.
Instance Method Summary collapse
-
#glyph_width(code_point) ⇒ Object
looks up the specified codepoint and returns a value that is in (pdf) glyph space, which is 1000 glyph units = 1 text space unit.
-
#initialize(ohash = nil, obj = nil) ⇒ Font
constructor
A new instance of Font.
- #to_utf8(params) ⇒ Object
- #unpack(data) ⇒ Object
Constructor Details
#initialize(ohash = nil, obj = nil) ⇒ Font
Returns a new instance of Font.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pdf/reader/font.rb', line 39 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 @tounicode = nil extract_base_info(obj) extract_descriptor(obj) extract_descendants(obj) @width_calc = build_width_calculator @encoding ||= PDF::Reader::Encoding.new(:StandardEncoding) end |
Instance Attribute Details
#basefont ⇒ Object
Returns the value of attribute basefont.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def basefont @basefont end |
#cid_default_width ⇒ Object (readonly)
Returns the value of attribute cid_default_width.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def cid_default_width @cid_default_width end |
#cid_widths ⇒ Object (readonly)
Returns the value of attribute cid_widths.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def cid_widths @cid_widths end |
#descendantfonts ⇒ Object
Returns the value of attribute descendantfonts.
35 36 37 |
# File 'lib/pdf/reader/font.rb', line 35 def descendantfonts @descendantfonts end |
#encoding ⇒ Object
Returns the value of attribute encoding.
35 36 37 |
# File 'lib/pdf/reader/font.rb', line 35 def encoding @encoding end |
#first_char ⇒ Object (readonly)
Returns the value of attribute first_char.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def first_char @first_char end |
#font_descriptor ⇒ Object (readonly)
Returns the value of attribute font_descriptor.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def font_descriptor @font_descriptor end |
#last_char ⇒ Object (readonly)
Returns the value of attribute last_char.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def last_char @last_char end |
#subtype ⇒ Object
Returns the value of attribute subtype.
35 36 37 |
# File 'lib/pdf/reader/font.rb', line 35 def subtype @subtype end |
#tounicode ⇒ Object
Returns the value of attribute tounicode.
35 36 37 |
# File 'lib/pdf/reader/font.rb', line 35 def tounicode @tounicode end |
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
36 37 38 |
# File 'lib/pdf/reader/font.rb', line 36 def widths @widths end |
Instance Method Details
#glyph_width(code_point) ⇒ Object
looks up the specified codepoint and returns a value that is in (pdf) glyph space, which is 1000 glyph units = 1 text space unit
74 75 76 77 78 79 80 81 |
# File 'lib/pdf/reader/font.rb', line 74 def glyph_width(code_point) if code_point.is_a?(String) code_point = code_point.unpack(encoding.unpack).first end @cached_widths ||= {} @cached_widths[code_point] ||= @width_calc.glyph_width(code_point) end |
#to_utf8(params) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/pdf/reader/font.rb', line 60 def to_utf8(params) if @tounicode to_utf8_via_cmap(params) else to_utf8_via_encoding(params) end end |
#unpack(data) ⇒ Object
68 69 70 |
# File 'lib/pdf/reader/font.rb', line 68 def unpack(data) data.unpack(encoding.unpack) end |