### Home Classes Methods

### In Files

- lib/prawn/font_metric_cache.rb

### Parent

Object

### Methods

- ::new
- #width_of

### 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::FontMetricCache

Cache used internally by Prawn::Document instances to calculate the width of various strings for layout purposes.

@private

### Constants

CacheEntry

### Public Class Methods

new( document ) click to toggle source

    # File lib/prawn/font_metric_cache.rb, line 19
    def initialize( document )
      @document = document

      @cache = {}
    end

### Public Instance Methods

width_of( string, options ) click to toggle source

    # File lib/prawn/font_metric_cache.rb, line 25
    def width_of( string, options )
      f = if options[:style]
            # override style with :style => :bold
            @document.find_font(@document.font ? @document.font.name : 'Helvetica',
                      :style => options[:style])
          else
            @document.font
          end

      key = CacheEntry.new( f, options, string )

      unless length = @cache[ key ]
        length = @cache[ key ] = f.compute_width_of(string, options)
      end

      length +
        (@document.character_spacing * @document.font.character_count(string))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.