Parent

PDF::Reader::Font

Represents a single font PDF object and provides some useful methods for extracting info. Mainly used for converting text to UTF-8.

Attributes

basefont[R]
cid_default_width[R]
cid_widths[R]
descendantfonts[RW]
encoding[RW]
first_char[R]
font_descriptor[R]
last_char[R]
subtype[RW]
tounicode[RW]
widths[R]

Public Class Methods

new(ohash = nil, obj = nil) click to toggle source
# File lib/pdf/reader/font.rb, line 38
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

Public Instance Methods

basefont=(font) click to toggle source
# File lib/pdf/reader/font.rb, line 54
def basefont=(font)
  @encoding ||= default_encoding(font)
  @basefont = font
end
glyph_width(code_point) click to toggle source

looks up the specified codepoint and returns a value that is in (pdf) glyph space, which is 1000 glyph units = 1 text space unit

# File lib/pdf/reader/font.rb, line 73
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) click to toggle source
# File lib/pdf/reader/font.rb, line 59
def to_utf8(params)
  if @tounicode
    to_utf8_via_cmap(params)
  else
    to_utf8_via_encoding(params)
  end
end
unpack(data) click to toggle source
# File lib/pdf/reader/font.rb, line 67
def unpack(data)
  data.unpack(encoding.unpack)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.