Class: PDF::Reader::FontDescriptor

### Home Classes Methods

### In Files

- lib/pdf/reader/font_descriptor.rb

### Parent

Object

### Methods

- ::new
- #glyph_to_pdf_scale_factor
- #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::FontDescriptor

Font descriptors are outlined in Section 9.8, PDF 32000-1:2008, pp 281-288

### Attributes

ascent[R]
avg_width[R]
cap_height[R]
descent[R]
font_bounding_box[R]
font_family[R]
font_flags[R]
font_name[R]
font_stretch[R]
font_weight[R]
italic_angle[R]
leading[R]
max_width[R]
missing_width[R]
stem_v[R]
x_height[R]

### Public Class Methods

new(ohash, fd_hash) click to toggle source

    # File lib/pdf/reader/font_descriptor.rb, line 14
    def initialize(ohash, fd_hash)
      @ascent                = ohash.object(fd_hash[:Ascent])    || 0
      @descent               = ohash.object(fd_hash[:Descent])   || 0
      @missing_width         = ohash.object(fd_hash[:MissingWidth]) || 0
      @font_bounding_box     = ohash.object(fd_hash[:FontBBox])  || [0,0,0,0]
      @avg_width             = ohash.object(fd_hash[:AvgWidth])  || 0
      @cap_height            = ohash.object(fd_hash[:CapHeight]) || 0
      @font_flags            = ohash.object(fd_hash[:Flags])     || 0
      @italic_angle          = ohash.object(fd_hash[:ItalicAngle])
      @font_name             = ohash.object(fd_hash[:FontName]).to_s
      @leading               = ohash.object(fd_hash[:Leading])   || 0
      @max_width             = ohash.object(fd_hash[:MaxWidth])  || 0
      @stem_v                = ohash.object(fd_hash[:StemV])
      @x_height              = ohash.object(fd_hash[:XHeight])
      @font_stretch          = ohash.object(fd_hash[:FontStretch]) || :Normal
      @font_weight           = ohash.object(fd_hash[:FontWeight])  || 400
      @font_family           = ohash.object(fd_hash[:FontFamily])

      # A FontDescriptor may have an embedded font program in FontFile
      # (Type 1 Font Program), FontFile2 (TrueType font program), or
      # FontFile3 (Other font program as defined by Subtype entry)
      # Subtype entries:
      # 1) Type1C:        Type 1 Font Program in Compact Font Format
      # 2) CIDFontType0C: Type 0 Font Program in Compact Font Format
      # 3) OpenType:      OpenType Font Program
      # see Section 9.9, PDF 32000-1:2008, pp 288-292
      @font_program_stream = ohash.object(fd_hash[:FontFile2])
      #TODO handle FontFile and FontFile3

      @is_ttf = true if @font_program_stream
    end

### Public Instance Methods

glyph_to_pdf_scale_factor() click to toggle source

PDF states that a glyph is 1000 units wide, true type doesn't enforce any behavior, but uses units/em to define how wide the 'M' is (the widest letter)

    # File lib/pdf/reader/font_descriptor.rb, line 63
    def glyph_to_pdf_scale_factor
      if @is_ttf
        @glyph_to_pdf_sf ||= (1.0 / ttf_program_stream.header.units_per_em) * 1000.0
      else
        @glyph_to_pdf_sf ||= 1.0
      end
      @glyph_to_pdf_sf
    end

glyph_width(char_code) click to toggle source

    # File lib/pdf/reader/font_descriptor.rb, line 46
    def glyph_width(char_code)
      if @is_ttf
        if ttf_program_stream.cmap.unicode.length > 0
          glyph_id = ttf_program_stream.cmap.unicode.first[char_code]
        else
          glyph_id = char_code
        end
        char_metric = ttf_program_stream.horizontal_metrics.metrics[glyph_id]
        if char_metric
          puts "Char Code: #{char_code} -- Advance Width: #{char_metric.advance_width}" > 0
          return char_metric.advance_width
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.