Class: PDF::Reader::WidthCalculator::BuiltIn

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::new
- #glyph_width

### 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::WidthCalculator::BuiltIn

Type1 fonts can be one of 14 "built in" standard fonts. In these cases, the reader is expected to have it's own copy of the font metrics. see Section 9.6.2.2, PDF 32000-1:2008, pp 256

### Public Class Methods

new(font) click to toggle source

    # File lib/pdf/reader/width_calculator/built_in.rb, line 63
    def initialize(font)
      @font = font
      @@all_metrics ||= PDF::Reader::SynchronizedCache.new

      metrics_path = File.join(File.dirname(__FILE__), "..","afm","#{font.basefont}.afm")

      if File.file?(metrics_path)
        @metrics = @@all_metrics[metrics_path] ||= AFM::Font.new(metrics_path)
      else
        raise ArgumentError, "No built-in metrics for #{font.basefont}"
      end
    end

### Public Instance Methods

glyph_width(code_point) click to toggle source

    # File lib/pdf/reader/width_calculator/built_in.rb, line 76
    def glyph_width(code_point)
      return 0 if code_point.nil? || code_point < 0

      m = @metrics.char_metrics_by_code[code_point]
      if m.nil?
        names = @font.encoding.int_to_name(code_point)
        m = names.map { |name|
          @metrics.char_metrics[name.to_s]
        }.compact.first
      end

      if m
        m[:wx]
      elsif @font.widths[code_point - 1]
        @font.widths[code_point - 1]
      else
        raise ArgumentError, "Unknown glyph width for #{code_point} #{@font.basefont}"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.