Class: PDF::Reader::Font

### Home Classes Methods

### In Files

- lib/pdf/reader/font.rb

### Parent

Object

### Methods

- ::new
- #basefont=
- #glyph_width
- #to_utf8
- #unpack

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# 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.