### Home Classes Methods

### In Files

- lib/prawn/font.rb
- lib/prawn/font/ttf.rb
- lib/prawn/font/dfont.rb
- lib/prawn/font/afm.rb

### Parent

Object

### Namespace

- CLASS Prawn::Font::AFM
- CLASS Prawn::Font::DFont
- CLASS Prawn::Font::TTF

### Methods

- ::load
- #add_to_current_page
- #ascender
- #descender
- #height
- #height_at
- #line_gap
- #normalize_encoding
- #normalize_encoding!

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Font

Provides font information and helper functions.

### Attributes

family[R]

The current font family

name[R]

The current font name

options[R]

The options hash used to initialize the font

### Public Class Methods

load(document,name,options={}) click to toggle source

Shortcut interface for constructing a font object. Filenames of the form *.ttf will call Font::TTF.new, *.dfont Font::DFont.new, and anything else will be passed through to Font::AFM.new()

    # File lib/prawn/font.rb, line 282
    def self.load(document,name,options={})
      case name.to_s
      when /\.ttf$/   then TTF.new(document, name, options)
      when /\.dfont$/ then DFont.new(document, name, options)
      when /\.afm$/   then AFM.new(document, name, options)
      else                  AFM.new(document, name, options)
      end
    end

### Public Instance Methods

add_to_current_page(subset) click to toggle source

Registers the given subset of the current font with the current PDF page. This is safe to call multiple times for a given font and subset, as it will only add the font the first time it is called.

    # File lib/prawn/font.rb, line 353
    def add_to_current_page(subset)
      @references[subset] ||= register(subset)
      @document.state.page.fonts.merge!(identifier_for(subset) => @references[subset])
    end

ascender() click to toggle source

The size of the font ascender in PDF points

    # File lib/prawn/font.rb, line 305
    def ascender
      @ascender / 1000.0 * size
    end

descender() click to toggle source

The size of the font descender in PDF points

    # File lib/prawn/font.rb, line 311
    def descender
      -@descender / 1000.0 * size
    end

height() click to toggle source

Gets height of current font in PDF points at current font size

    # File lib/prawn/font.rb, line 345
    def height
      height_at(size)
    end

height_at(size) click to toggle source

Gets height of current font in PDF points at the given font size

    # File lib/prawn/font.rb, line 338
    def height_at(size)
      @normalized_height ||= (@ascender - @descender + @line_gap) / 1000.0
      @normalized_height * size
    end

line_gap() click to toggle source

The size of the recommended gap between lines of text in PDF points

    # File lib/prawn/font.rb, line 317
    def line_gap
      @line_gap / 1000.0 * size
    end

normalize_encoding(string) click to toggle source

Normalizes the encoding of the string to an encoding supported by the font. The string is expected to be UTF-8 going in. It will be re-encoded and the new string will be returned. For an in-place (destructive) version, see normalize_encoding!.

    # File lib/prawn/font.rb, line 325
    def normalize_encoding(string)
      raise NotImplementedError, "subclasses of Prawn::Font must implement #normalize_encoding"
    end

normalize_encoding!(str) click to toggle source

Destructive version of normalize_encoding; normalizes the encoding of a string in place.

    # File lib/prawn/font.rb, line 332
    def normalize_encoding!(str)
      str.replace(normalize_encoding(str))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.