Class: AFM::Font

### Home Classes Methods

### In Files

- lib/pdf/reader/width_calculator/built_in.rb

### Parent

Object

### Methods

- ::new

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

# AFM::Font

monkey patch the afm gem to give us access to the metrics by glyph code. I've got a pull request to upstream so hopefully this can be removed soon. See github.com/halfbyte/afm/pull/3

### Attributes

char_metrics_by_code[R]

### Public Class Methods

new(filename) click to toggle source

Loading a Font Metrics file by absolute path (no automatic font path resolution)

    # File lib/pdf/reader/width_calculator/built_in.rb, line 12
    def initialize(filename)
      @metadata = {}
      @char_metrics = {}
      @char_metrics_by_code = {}
      @kern_pairs = []
      File.open(filename) do |file|
        mode = :meta
        file.each_line do |line|
          case(line)
          when /^StartFontMetrics/ ; mode = :meta
          when /^StartCharMetrics/ ; mode = :char_metrics
          when /^EndCharMetrics/ ; mode = :meta
          when /^StartKernData/ ; mode = :kern_data
          when /^StartKernPairs/ ; mode = :kern_pairs
          when /^EndKernPairs/ ; mode = :kern_data
          when /^EndKernData/ ; mode = :meta
          else
            case(mode)
            when :meta
              if match = line.match(/^([\w]+) (.*)$/)
                @metadata[match[1]] = match[2]
              end
            when :char_metrics
              metrics = {}
              metrics[:charcode] = match[1].to_i if match = line.match(/C (-?\d+) *?;/)
              metrics[:wx] = match[1].to_i if match = line.match(/WX (-?\d+) *?;/)
              metrics[:name] = match[1] if match = line.match(/N ([.\w]+) *?;/)
              if match = line.match(/B (-?\d+) (-?\d+) (-?\d+) (-?\d+) *?;/)
                metrics[:boundingbox] = [match[1].to_i, match[2].to_i, match[3].to_i, match[4].to_i]
              end
              @char_metrics[metrics[:name]] = metrics if metrics[:name]
              @char_metrics_by_code[metrics[:charcode]] = metrics if metrics[:charcode] && metrics[:charcode] > 0
            when :kern_pairs
              if match = line.match(/^KPX ([.\w]+) ([.\w]+) (-?\d+)$/)
                @kern_pairs << [match[1], match[2], match[3].to_i]
              end
            end
          end
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.